Skip to content

Commit ddd8dd9

Browse files
authored
Merge pull request #834 from CorentinDoue/chore/use-processed-options
chore: use processedOptions
2 parents 3d0f44b + ca53403 commit ddd8dd9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ class ServerlessWebpack {
9090
};
9191

9292
this.hooks = {
93+
initialize: () => {
94+
// serverless.processedInput does not exist in serverless@<2.0.0. This ensure the retrocompatibility with serverless v1
95+
if (this.serverless.processedInput && this.serverless.processedInput.options) {
96+
this.options = this.serverless.processedInput.options;
97+
}
98+
},
9399
'before:package:createDeploymentArtifacts': () =>
94100
BbPromise.bind(this)
95101
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))

index.test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,20 @@ describe('ServerlessWebpack', () => {
134134
);
135135

136136
describe('hooks', () => {
137+
const functionName = 'myFunction';
138+
const rawOptions = {
139+
f: functionName
140+
};
141+
const processedOptions = {
142+
function: functionName
143+
};
137144
let slsw;
138145

139146
before(() => {
140-
slsw = new ServerlessWebpack(serverless, {});
147+
slsw = new ServerlessWebpack(serverless, rawOptions);
148+
if(serverless.processedInput) { // serverless.processedInput does not exist in serverless@<2.0.0
149+
serverless.processedInput.options = processedOptions;
150+
}
141151
sandbox.stub(slsw, 'cleanup').returns(BbPromise.resolve());
142152
sandbox.stub(slsw, 'watch').returns(BbPromise.resolve());
143153
sandbox.stub(slsw, 'wpwatch').returns(BbPromise.resolve());
@@ -461,6 +471,21 @@ describe('ServerlessWebpack', () => {
461471
});
462472
});
463473
}
474+
},
475+
{
476+
name: 'initialize',
477+
test: () => {
478+
it('should override the raw options with the processed ones', () => {
479+
slsw.hooks.initialize();
480+
if(serverless.processedInput) {
481+
expect(slsw.options).to.equal(processedOptions);
482+
} else {
483+
// serverless.processedInput does not exist in serverless@<2.0.0
484+
// The options should not be changed
485+
expect(slsw.options).to.equal(rawOptions);
486+
}
487+
});
488+
}
464489
}
465490
],
466491
hook => {

0 commit comments

Comments
 (0)