Skip to content

Commit

Permalink
Re-add the --no-build CLI option
Browse files Browse the repository at this point in the history
We removed it because it was generating some deprecated message and we introduced the parameter `noBuild` instead.
Now the CLI option is back and the parameter is kept.
  • Loading branch information
j0k3r committed Jul 13, 2022
1 parent 58a4b3d commit e148d35
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,16 @@ On CI systems it is likely that you'll run multiple integration tests with `invo
sequentially. To improve this, you can do one compile and run multiple invokes on the
compiled output - it is not necessary to compile again before each and every invoke.

##### Using the CLI option `--no-build`

```bash
$ serverless webpack
$ serverless invoke local --function <function-name-1> --no-build
$ serverless invoke local --function <function-name-2> --no-build
```

##### Using the parameter `noBuild`

```yaml
custom:
webpack:
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class ServerlessWebpack {
commands: {
local: {
options: {
'no-build': {
usage: 'Skip Webpack compilation',
type: 'boolean'
},
watch: {
usage: 'Flag to watch changes',
type: 'boolean'
Expand Down Expand Up @@ -217,6 +221,10 @@ class ServerlessWebpack {
BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
// --no-build override
if (this.options.build === false) {
this.skipCompile = true;
}
})
.then(this.prepareOfflineInvoke)
.then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())),
Expand All @@ -225,6 +233,10 @@ class ServerlessWebpack {
BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
// --no-build override
if (this.options.build === false) {
this.skipCompile = true;
}
})
.then(this.prepareOfflineInvoke)
.then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())),
Expand Down
2 changes: 1 addition & 1 deletion lib/prepareOfflineInvoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const path = require('path');
module.exports = {
prepareOfflineInvoke() {
this.skipCompile =
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'build') === false;
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'no-build') === true;

// Use service packaging for compile
_.set(this.serverless, 'service.package.individually', false);
Expand Down
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ module.exports = {
}

this.skipCompile =
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'build') === false;
_.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'no-build') === true;

// Skip compilation with --no-build or noBuild
if (this.skipCompile) {
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ describe('ServerlessWebpack', () => {
});
});
it('should skip compiling when requested', () => {
slsw.skipCompile = true;
slsw.skipCompile = false;
slsw.options.build = false;
return expect(slsw.hooks['before:offline:start:init']())
.resolves.toBeUndefined()
Expand Down
8 changes: 4 additions & 4 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ describe('validate', () => {
});

describe('with skipped builds', () => {
it('should set `skipCompile` to true if `options.build` is false', () => {
it('should set `skipCompile` to true if `options.no-build` is true', () => {
const testConfig = {
entry: 'test',
output: {}
Expand All @@ -1197,7 +1197,7 @@ describe('validate', () => {
module.serverless.config.servicePath = testServicePath;
_.set(module.serverless.service, 'custom.webpack.config', testConfig);

module.options.build = false;
module.options['no-build'] = true;

fsExtraMock.pathExistsSync.mockReturnValue(true);
return module.validate().then(() => {
Expand All @@ -1214,7 +1214,7 @@ describe('validate', () => {
const testServicePath = 'testpath';
module.serverless.config.servicePath = testServicePath;
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
module.options.build = false;
module.options['no-build'] = true;
fsExtraMock.pathExistsSync.mockReturnValue(true);
return module.validate().then(() => {
expect(module.keepOutputDirectory).toBe(true);
Expand All @@ -1230,7 +1230,7 @@ describe('validate', () => {
const testServicePath = 'testpath';
module.serverless.config.servicePath = testServicePath;
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
module.options.build = false;
module.options['no-build'] = true;
fsExtraMock.pathExistsSync.mockReturnValue(false);
return expect(module.validate()).rejects.toThrow(/No compiled output found/);
});
Expand Down

0 comments on commit e148d35

Please sign in to comment.