Skip to content

Commit 2132777

Browse files
committed
Re-add the --no-build CLI option as --skip-build
We removed it because it was generating some deprecated message and we introduced the parameter `noBuild` instead. Now the CLI option is back as a new name (see below) and the parameter is kept. Serverless add an extra CLI option prefixed with `--no-` in case we add a new CLI option (ie: `--build`). But we don't need the `--build` option, only the `--no-build` which isn't possible. So we renamed it to `--skip-build`
1 parent 544e5ee commit 2132777

8 files changed

+45
-21
lines changed

.huskyrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"hooks": {
3-
"pre-commit": "lint-staged && npm test"
3+
"pre-commit": "npx lint-staged"
44
}
55
}

.lintstagedrc.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
"*.js":
2-
- "prettier-eslint --write" # Run Prettier
3-
- "eslint" # Run TSLint
4-
- "git add"
2+
- "eslint"

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,16 @@ On CI systems it is likely that you'll run multiple integration tests with `invo
662662
sequentially. To improve this, you can do one compile and run multiple invokes on the
663663
compiled output - it is not necessary to compile again before each and every invoke.
664664

665+
##### Using the CLI option `--skip-build`
666+
667+
```bash
668+
$ serverless webpack
669+
$ serverless invoke local --function <function-name-1> --skip-build
670+
$ serverless invoke local --function <function-name-2> --skip-build
671+
```
672+
673+
##### Using the parameter `noBuild`
674+
665675
```yaml
666676
custom:
667677
webpack:
@@ -736,7 +746,7 @@ e.g. a mounted volume in a Docker container, you can enable polling with the
736746
`--webpack-use-polling=<time in ms>` option. If you omit the value, it defaults
737747
to 3000 ms.
738748

739-
If you don't want the plugin to build when using `serverless-offline`, select the `--no-build` option.
749+
If you don't want the plugin to build when using `serverless-offline`, select the `--skip-build` option.
740750

741751
#### Custom paths
742752

index.js

+20
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class ServerlessWebpack {
9797
commands: {
9898
local: {
9999
options: {
100+
'skip-build': {
101+
usage: 'Skip Webpack compilation',
102+
type: 'boolean'
103+
},
100104
watch: {
101105
usage: 'Flag to watch changes',
102106
type: 'boolean'
@@ -113,6 +117,10 @@ class ServerlessWebpack {
113117
'webpack-no-watch': {
114118
usage: 'Disable automatic watch mode from Serverless Webpack',
115119
type: 'boolean'
120+
},
121+
'skip-build': {
122+
usage: 'Skip Webpack compilation',
123+
type: 'boolean'
116124
}
117125
},
118126
commands: {
@@ -121,6 +129,10 @@ class ServerlessWebpack {
121129
'webpack-no-watch': {
122130
usage: 'Disable automatic watch mode from Serverless Webpack',
123131
type: 'boolean'
132+
},
133+
'skip-build': {
134+
usage: 'Skip Webpack compilation',
135+
type: 'boolean'
124136
}
125137
}
126138
}
@@ -217,6 +229,10 @@ class ServerlessWebpack {
217229
BbPromise.bind(this)
218230
.tap(() => {
219231
lib.webpack.isLocal = true;
232+
// --skip-build override
233+
if (this.options['skip-build'] === false) {
234+
this.skipCompile = true;
235+
}
220236
})
221237
.then(this.prepareOfflineInvoke)
222238
.then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())),
@@ -225,6 +241,10 @@ class ServerlessWebpack {
225241
BbPromise.bind(this)
226242
.tap(() => {
227243
lib.webpack.isLocal = true;
244+
// --skip-build override
245+
if (this.options['skip-build'] === false) {
246+
this.skipCompile = true;
247+
}
228248
})
229249
.then(this.prepareOfflineInvoke)
230250
.then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())),

lib/prepareOfflineInvoke.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = require('path');
1010
module.exports = {
1111
prepareOfflineInvoke() {
1212
this.skipCompile =
13-
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'build') === false;
13+
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'skip-build') === true;
1414

1515
// Use service packaging for compile
1616
_.set(this.serverless, 'service.package.individually', false);

lib/validate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ module.exports = {
223223
}
224224

225225
this.skipCompile =
226-
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'build') === false;
226+
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'skip-build') === true;
227227

228-
// Skip compilation with --no-build or noBuild
228+
// Skip compilation with --skip-build or noBuild
229229
if (this.skipCompile) {
230230
if (this.log) {
231231
this.log('Skipping build and using existing compiled output');

tests/index.test.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe('ServerlessWebpack', () => {
219219
});
220220

221221
it('should skip compile if requested', () => {
222-
slsw.options.build = false;
222+
slsw.options['skip-build'] = false;
223223
slsw.skipCompile = true;
224224
return expect(slsw.hooks['before:invoke:local:invoke']())
225225
.resolves.toBeUndefined()
@@ -377,8 +377,7 @@ describe('ServerlessWebpack', () => {
377377
name: 'before:offline:start',
378378
test: () => {
379379
it('should prepare offline', () => {
380-
slsw.skipCompile = false;
381-
slsw.options.build = true;
380+
slsw.options['skip-build'] = true;
382381
return expect(slsw.hooks['before:offline:start']())
383382
.resolves.toBeUndefined()
384383
.then(() => {
@@ -389,8 +388,7 @@ describe('ServerlessWebpack', () => {
389388
});
390389
});
391390
it('should skip compiling when requested', () => {
392-
slsw.skipCompile = true;
393-
slsw.options.build = false;
391+
slsw.options['skip-build'] = false;
394392
return expect(slsw.hooks['before:offline:start']())
395393
.resolves.toBeUndefined()
396394
.then(() => {
@@ -406,8 +404,7 @@ describe('ServerlessWebpack', () => {
406404
name: 'before:offline:start:init',
407405
test: () => {
408406
it('should prepare offline', () => {
409-
slsw.skipCompile = false;
410-
slsw.options.build = true;
407+
slsw.options['skip-build'] = true;
411408
return expect(slsw.hooks['before:offline:start:init']())
412409
.resolves.toBeUndefined()
413410
.then(() => {
@@ -418,8 +415,7 @@ describe('ServerlessWebpack', () => {
418415
});
419416
});
420417
it('should skip compiling when requested', () => {
421-
slsw.skipCompile = true;
422-
slsw.options.build = false;
418+
slsw.options['skip-build'] = false;
423419
return expect(slsw.hooks['before:offline:start:init']())
424420
.resolves.toBeUndefined()
425421
.then(() => {

tests/validate.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ describe('validate', () => {
11881188
});
11891189

11901190
describe('with skipped builds', () => {
1191-
it('should set `skipCompile` to true if `options.build` is false', () => {
1191+
it('should set `skipCompile` to true if `options.skip-build` is true', () => {
11921192
const testConfig = {
11931193
entry: 'test',
11941194
output: {}
@@ -1197,7 +1197,7 @@ describe('validate', () => {
11971197
module.serverless.config.servicePath = testServicePath;
11981198
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
11991199

1200-
module.options.build = false;
1200+
module.options['skip-build'] = true;
12011201

12021202
fsExtraMock.pathExistsSync.mockReturnValue(true);
12031203
return module.validate().then(() => {
@@ -1214,7 +1214,7 @@ describe('validate', () => {
12141214
const testServicePath = 'testpath';
12151215
module.serverless.config.servicePath = testServicePath;
12161216
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
1217-
module.options.build = false;
1217+
module.options['skip-build'] = true;
12181218
fsExtraMock.pathExistsSync.mockReturnValue(true);
12191219
return module.validate().then(() => {
12201220
expect(module.keepOutputDirectory).toBe(true);
@@ -1230,7 +1230,7 @@ describe('validate', () => {
12301230
const testServicePath = 'testpath';
12311231
module.serverless.config.servicePath = testServicePath;
12321232
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
1233-
module.options.build = false;
1233+
module.options['skip-build'] = true;
12341234
fsExtraMock.pathExistsSync.mockReturnValue(false);
12351235
return expect(module.validate()).rejects.toThrow(/No compiled output found/);
12361236
});

0 commit comments

Comments
 (0)