From 621f5cc9a0b8240f95daf284d5c3a5ee6b4c91da Mon Sep 17 00:00:00 2001 From: Henrik Hall Date: Thu, 2 Jan 2020 13:55:44 +0100 Subject: [PATCH] Delay reading config until package:initialize hook This lets serverless variables be resolved before the config.layerConfig object is parsed. This fixes #3. --- LayerManagerPlugin.js | 14 ++++++++++---- examples/example-layer-service/serverless.yml | 13 +++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/LayerManagerPlugin.js b/LayerManagerPlugin.js index d064fdb..36b41db 100644 --- a/LayerManagerPlugin.js +++ b/LayerManagerPlugin.js @@ -44,17 +44,23 @@ function getConfig(serverless) { class LayerManagerPlugin { constructor(sls, options = {}) { this.level = options.v || options.verbose ? 'verbose' : LOG_LEVEL; - this.config = getConfig(sls); info(this, `Invoking layer-manager plugin`); - verbose(this, `Config: `, this.config); this.hooks = { - 'package:initialize': () => this.installLayers(sls), + 'package:initialize': () => { + this.init(sls); + this.installLayers(sls) + }, 'before:deploy:deploy': () => this.transformLayerResources(sls) }; } + init(sls) { + this.config = getConfig(sls); + verbose(this, `Config: `, this.config); + } + installLayer(path) { const nodeLayerPath = `${path}/nodejs`; @@ -141,4 +147,4 @@ class LayerManagerPlugin { } } -module.exports = LayerManagerPlugin; \ No newline at end of file +module.exports = LayerManagerPlugin; diff --git a/examples/example-layer-service/serverless.yml b/examples/example-layer-service/serverless.yml index cefa60c..da1ccb4 100644 --- a/examples/example-layer-service/serverless.yml +++ b/examples/example-layer-service/serverless.yml @@ -20,10 +20,11 @@ functions: # Note the reference being the TitleCase representation of the layer id followed by "LambdaLayer" - {Ref: MyLibLambdaLayer} -#custom: -# layerConfig: -# installLayers: -# exportLayers: -# upgradeLayerReferences: -# exportPrefix: +custom: + foo: FOO + layerConfig: + installLayers: true + exportLayers: true + upgradeLayerReferences: true + exportPrefix: ${self:service}-${self:custom.foo}- # prefix used for the names of the exported layers