Skip to content

Commit 6bdbd6a

Browse files
Merge pull request #34 from jacob-meacham/onhate/develop
Onhate/develop
2 parents ff0bfbb + c9df79a commit 6bdbd6a

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

lib/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ class ServerlessDeployEnvironment {
4343
options: {
4444
command: {
4545
usage: 'The command to run',
46-
shortcut: 'c'
46+
shortcut: 'c',
47+
type: 'string'
4748
},
4849
stage: {
4950
usage: 'The stage to use for stage-specific variables',
50-
shortcut: 's'
51+
shortcut: 's',
52+
type: 'string'
5153
},
5254
args: {
5355
usage: 'Extra arguments to pass through to the subprocess',
54-
shortcut: 'a'
56+
shortcut: 'a',
57+
type: 'multiple'
5558
}
5659
}
5760
}
@@ -125,11 +128,11 @@ class ServerlessDeployEnvironment {
125128
serverless.variables.loadVariableSyntax(); // Explicitly resolve these here, so that we can apply any transformations that we want
126129

127130
const vars = (0, _deasyncPromise.default)(serverless.variables.populateProperty(deployVariables, false));
128-
serverless.service.deployVariables = _lodash.default.merge(vars.default || {}, vars[stage]); // eslint-disable-line
131+
serverless.service.deployVariables = _lodash.default.merge({}, vars.default || {}, vars[stage]); // eslint-disable-line
129132

130133
const envs = (0, _deasyncPromise.default)(serverless.variables.populateProperty(deployEnvironment, false)); // eslint-disable-line
131134

132-
serverless.service.deployEnvironment = _lodash.default.merge(envs.default || {}, envs[stage]); // eslint-disable-line
135+
serverless.service.deployEnvironment = _lodash.default.merge({}, envs.default || {}, envs[stage]); // eslint-disable-line
133136
}
134137

135138
async _resolveDeployEnvironment() {
@@ -145,9 +148,8 @@ class ServerlessDeployEnvironment {
145148

146149
async _runWithEnvironment() {
147150
const deployEnv = await this._resolveDeployEnvironment();
148-
const env = {};
149151

150-
_lodash.default.merge(env, process.env, deployEnv); // Merge the current environment, overridden with the deploy environment
152+
const env = _lodash.default.merge({}, process.env, deployEnv); // Merge the current environment, overridden with the deploy environment
151153

152154

153155
const args = this.options.args || '';

src/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ class ServerlessDeployEnvironment {
3535
options: {
3636
command: {
3737
usage: 'The command to run',
38-
shortcut: 'c'
38+
shortcut: 'c',
39+
type: 'string'
3940
},
4041
stage: {
4142
usage: 'The stage to use for stage-specific variables',
42-
shortcut: 's'
43+
shortcut: 's',
44+
type: 'string'
4345
},
4446
args: {
4547
usage: 'Extra arguments to pass through to the subprocess',
46-
shortcut: 'a'
48+
shortcut: 'a',
49+
type: 'multiple'
4750
}
4851
}
4952
}
@@ -107,9 +110,9 @@ class ServerlessDeployEnvironment {
107110
serverless.variables.loadVariableSyntax()
108111
// Explicitly resolve these here, so that we can apply any transformations that we want
109112
const vars = deasyncPromise(serverless.variables.populateProperty(deployVariables, false))
110-
serverless.service.deployVariables = _.merge(vars.default || { }, vars[stage]) // eslint-disable-line
113+
serverless.service.deployVariables = _.merge({}, vars.default || {}, vars[stage]) // eslint-disable-line
111114
const envs = deasyncPromise(serverless.variables.populateProperty(deployEnvironment, false)) // eslint-disable-line
112-
serverless.service.deployEnvironment = _.merge(envs.default || { }, envs[stage]) // eslint-disable-line
115+
serverless.service.deployEnvironment = _.merge({}, envs.default || {}, envs[stage]) // eslint-disable-line
113116
}
114117

115118
async _resolveDeployEnvironment() {
@@ -125,8 +128,7 @@ class ServerlessDeployEnvironment {
125128

126129
async _runWithEnvironment() {
127130
const deployEnv = await this._resolveDeployEnvironment()
128-
const env = {}
129-
_.merge(env, process.env, deployEnv) // Merge the current environment, overridden with the deploy environment
131+
const env = _.merge({}, process.env, deployEnv) // Merge the current environment, overridden with the deploy environment
130132
const args = this.options.args || ''
131133
const output = childProcess.execSync(`${this.options.command} ${args}`, { env, cwd: process.cwd() }).toString()
132134
for (const line of output.split('\n')) {

test/index.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@ test('deployEnvironments merges defaults', t => {
141141
t.deepEqual(sls.service.deployEnvironment, expectedDeployEnvironment)
142142
})
143143

144+
test('deployEnvironments merges defaults (is not affected by later mutation)', t => {
145+
const sls = new Serverless()
146+
147+
const expectedDeployEnvironment = {
148+
a: 2
149+
}
150+
151+
sls.service.custom = {
152+
defaults: {
153+
stage: 'test'
154+
},
155+
deploy: {
156+
environments: {
157+
default: { a: 1 },
158+
test: { a: 2 }
159+
}
160+
}
161+
}
162+
163+
initServerlessPlugin(sls)
164+
sls.service.custom.deploy.environments.default.a = 'somehow mutated later'
165+
166+
t.deepEqual(sls.service.deployEnvironment, expectedDeployEnvironment)
167+
})
168+
144169
const CREDSTASH_CONFIG = {
145170
defaults: {
146171
stage: 'test'

0 commit comments

Comments
 (0)