serverless-plugin-env-stage-config 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +13 -2
  2. package/index.js +13 -12
  3. package/package.json +10 -17
package/README.md CHANGED
@@ -26,6 +26,13 @@ name: my-service
26
26
 
27
27
  useDotenv: true
28
28
 
29
+ resources:
30
+ Resources:
31
+ MyQueue:
32
+ Type: AWS::SQS::Queue
33
+ Properties:
34
+ QueueName: some-queue
35
+
29
36
  provider:
30
37
  name: aws
31
38
 
@@ -37,12 +44,13 @@ functions:
37
44
  run-something:
38
45
  handler: handler.run
39
46
  environment:
47
+ QUEUE_URL: ${esc:QUEUE_URL}
40
48
  SECRET_TOKEN: ${esc:SECRET_TOKEN}
41
49
  ```
42
50
 
43
51
  ## Local stages
44
52
 
45
- In a local environment, the variables resolved with the `esc:` prefix will be equivalent to using `env:`. Using `useDotenv: true` alongside a `.env` file will alow you to define your environement variables in the environement.
53
+ In a local environment, the variables resolved with the `esc:` prefix will be equivalent to using `env:`. Using `useDotenv: true` alongside a `.env` file will alow you to define your environement variables.
46
54
 
47
55
  The support local stages are:
48
56
  - local
@@ -57,13 +65,16 @@ For example, if you’re using AWS SSM Parameter Store, you could create the fol
57
65
 
58
66
  ```yaml
59
67
  MYSQL_HOST: ${ssm:/my-service/prod/MYSQL_HOST~true}
68
+ QUEUE_URL: !Ref MyQueue
60
69
  SECRET_TOKEN: ${ssm:/my-service/prod/SECRET_TOKEN~true}
61
70
  ```
62
71
 
63
72
  Any variable that is not included in the `serverless.env.prod.yml` file will produce a warning and fallback to using `env:`.
64
73
  In this case, you will get the following warning:
65
74
 
66
- > Serverless: env-stage-config: WARNING: the MYSQL_PORT variable is not defined in serverless.env.prod.yml, defaulting to ${env:MYSQL_PORT}.
75
+ > Serverless: env-stage-config: WARNING: the MYSQL_PORT variable is not defined in serverless.env.prod.yml, defaulting to ${env:MYSQL_PORT, null}.
76
+
77
+ If a variable is not defined in the stage environment configuration file, or the environment (`process.env`), it will default to `null`.
67
78
 
68
79
  ## License
69
80
 
package/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  const path = require('path')
2
2
  const {readFileSync} = require('fs')
3
3
  const yaml = require('js-yaml')
4
+ const cloudformationSchema = require('@serverless/utils/cloudformation-schema')
4
5
 
5
6
  const developmentStages = new Set([
6
7
  'local',
7
8
  'development',
8
- 'dev'
9
+ 'dev',
9
10
  ])
10
11
 
11
12
  class EnvStageConfigServerlessPlugin {
@@ -16,16 +17,16 @@ class EnvStageConfigServerlessPlugin {
16
17
 
17
18
  this.configurationVariablesSources = {
18
19
  esc: {
19
- resolve: this.resolveConfigVariable.bind(this)
20
- }
20
+ resolve: this.resolveConfigVariable.bind(this),
21
+ },
21
22
  }
22
23
 
23
24
  if (!developmentStages.has(this.stage)) {
24
- this.stageVariables = yaml.load(
25
- readFileSync(
26
- path.join(this.serverless.serviceDir, `serverless.env.${this.stage}.yml`)
27
- )
28
- )
25
+ const stageConfigYaml = readFileSync(path.join(this.serverless.serviceDir, `serverless.env.${this.stage}.yml`))
26
+
27
+ this.stageVariables = yaml.load(stageConfigYaml, {
28
+ schema: cloudformationSchema,
29
+ })
29
30
  }
30
31
  }
31
32
 
@@ -33,19 +34,19 @@ class EnvStageConfigServerlessPlugin {
33
34
  if (this.stageVariables) {
34
35
  if (address in this.stageVariables) {
35
36
  return {
36
- value: this.stageVariables[address]
37
+ value: this.stageVariables[address],
37
38
  }
38
39
  }
39
40
 
40
41
  this.serverless.cli.log(
41
- `env-stage-config: WARNING: the ${address} variable is not defined in serverless.env.${this.stage}.yml, defaulting to \${env:${address}}.`,
42
+ `env-stage-config: WARNING: the ${address} variable is not defined in serverless.env.${this.stage}.yml, defaulting to \${env:${address}, null}.`,
42
43
  null,
43
- {color: 'orange'}
44
+ {color: 'orange'},
44
45
  )
45
46
  }
46
47
 
47
48
  return {
48
- value: `\${env:${address}}`
49
+ value: `\${env:${address}, null}`,
49
50
  }
50
51
  }
51
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-plugin-env-stage-config",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "author": "Bertrand Marron <bertrand.marron@gmail.com>",
5
5
  "description": "Serverless plugin to define environment variables files for stages",
6
6
  "main": "index.js",
@@ -20,29 +20,22 @@
20
20
  "serverless-plugin"
21
21
  ],
22
22
  "dependencies": {
23
+ "@serverless/utils": "^6.0.0",
23
24
  "js-yaml": "^4.1.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@semantic-release/git": "^9.0.0",
27
- "semantic-release": "^17.4.4",
28
- "xo": "^0.39.1"
27
+ "@bizon/semantic-release-config": "^1.0.1",
28
+ "semantic-release": "^19.0.2",
29
+ "xo": "^0.47.0"
29
30
  },
30
31
  "xo": {
31
32
  "semicolon": false,
32
- "space": 2
33
+ "space": 2,
34
+ "rules": {
35
+ "unicorn/prefer-module": "off"
36
+ }
33
37
  },
34
38
  "release": {
35
- "plugins": [
36
- "@semantic-release/commit-analyzer",
37
- "@semantic-release/release-notes-generator",
38
- "@semantic-release/github",
39
- "@semantic-release/npm",
40
- [
41
- "@semantic-release/git",
42
- {
43
- "message": "chore(release): ${nextRelease.gitTag}"
44
- }
45
- ]
46
- ]
39
+ "extends": "@bizon/semantic-release-config"
47
40
  }
48
41
  }