serverless-dotenv-plugin
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -10,2 +10,6 @@ # Changelog | ||
## 3.3.0 | ||
* feat: adding variableExpansion option to turn off variable expansion. ([#116](https://github.com/neverendingqs/serverless-dotenv-plugin/pull/116)) | ||
## 3.2.0 | ||
@@ -12,0 +16,0 @@ |
12
index.js
@@ -24,2 +24,5 @@ 'use strict' | ||
this.required = (this.config && this.config.required) || {} | ||
this.variableExpansion = !( | ||
(this.config && this.config.variableExpansion) === false | ||
) | ||
@@ -79,5 +82,8 @@ this.loadEnv(this.getEnvironment(options)) | ||
parseEnvFiles(envFileNames) { | ||
const envVarsArray = envFileNames.map( | ||
(fileName) => dotenvExpand(dotenv.config({ path: fileName })).parsed, | ||
) | ||
const envVarsArray = envFileNames.map((fileName) => { | ||
const parsed = dotenv.config({ path: fileName }) | ||
return this.variableExpansion | ||
? dotenvExpand(parsed).parsed | ||
: parsed.parsed | ||
}) | ||
@@ -84,0 +90,0 @@ return envVarsArray.reduce((acc, curr) => ({ ...acc, ...curr }), {}) |
{ | ||
"name": "serverless-dotenv-plugin", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Preload environment variables with dotenv into serverless.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -114,2 +114,5 @@ # serverless-dotenv-plugin | ||
file: true | ||
# default: true | ||
variableExpansion: false | ||
``` | ||
@@ -142,3 +145,9 @@ | ||
* variableExpansion: true|false (default true) | ||
* By default, variables can reference other variables | ||
* E.g. `INNER_ENV=innerenv, OUTER_ENV=hi-$INNER_ENV`, would resolve to `INNER_ENV=innerenv, OUTER_ENV=hi-innerenv` | ||
* Setting this to `false` will disable this feature | ||
* E.g. `INNER_ENV=innerenv, OUTER_ENV=hi-$INNER_ENV`, would resolve to `INNER_ENV=innerenv, OUTER_ENV=hi-$INNER_ENV` | ||
## Examples | ||
@@ -145,0 +154,0 @@ |
@@ -400,3 +400,93 @@ const chai = require('chai') | ||
}) | ||
it('does not use `dotenv-expand` when `variableExpansion` is set to `false`', function () { | ||
const fileName = '.env' | ||
const envVars = { | ||
env1: 'env1value', | ||
env2: 'env2value', | ||
env3: 'env3value', | ||
} | ||
const serverless = { | ||
cli: { | ||
log: this.sandbox.stub(), | ||
}, | ||
service: { | ||
custom: { | ||
dotenv: { | ||
variableExpansion: false, | ||
}, | ||
}, | ||
provider: {}, | ||
}, | ||
} | ||
const plugin = new this.ServerlessPlugin(serverless, this.options) | ||
const resolveEnvFileNames = this.sandbox.stub( | ||
plugin, | ||
'resolveEnvFileNames', | ||
) | ||
resolveEnvFileNames.withArgs(this.env).returns([fileName]) | ||
this.requireStubs.dotenv.config | ||
.withArgs({ path: fileName }) | ||
.returns({ parsed: envVars }) | ||
plugin.loadEnv(this.env) | ||
serverless.service.provider.environment.should.deep.equal({ | ||
env1: envVars.env1, | ||
env2: envVars.env2, | ||
env3: envVars.env3, | ||
}) | ||
this.requireStubs['dotenv-expand'].should.not.have.been.called | ||
}) | ||
it('runs with defaults when there are no configs', function () { | ||
const fileName = '.env' | ||
const envVars = { | ||
env1: 'env1value', | ||
env2: 'env2value', | ||
env3: 'env3value', | ||
} | ||
const serverless = { | ||
cli: { | ||
log: this.sandbox.stub(), | ||
}, | ||
service: { | ||
custom: {}, | ||
provider: {}, | ||
}, | ||
} | ||
const plugin = new this.ServerlessPlugin(serverless, this.options) | ||
const resolveEnvFileNames = this.sandbox.stub( | ||
plugin, | ||
'resolveEnvFileNames', | ||
) | ||
resolveEnvFileNames.withArgs(this.env).returns([fileName]) | ||
this.requireStubs.dotenv.config | ||
.withArgs({ path: fileName }) | ||
.returns({ parsed: envVars }) | ||
this.requireStubs['dotenv-expand'] | ||
.withArgs({ parsed: envVars }) | ||
.returns({ parsed: envVars }) | ||
plugin.loadEnv(this.env) | ||
serverless.service.provider.environment.should.deep.equal({ | ||
env1: envVars.env1, | ||
env2: envVars.env2, | ||
env3: envVars.env3, | ||
}) | ||
}) | ||
}) | ||
}) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
38778
550
190
0