From 28f57a668d51005908fec8ca7491518724c5edf6 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:30:03 +0800 Subject: [PATCH 01/30] Update compile.js Use `.map(..., { concurrency })` instead of `.mapSeries(...)` --- lib/compile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 683242f7a..9df3716c7 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -39,9 +39,9 @@ function webpackCompile(config, logStats) { }); } -function webpackCompileSerial(configs, logStats) { +function webpackConcurrentCompile(configs, logStats, concurrency) { return BbPromise - .mapSeries(configs, config => webpackCompile(config, logStats)) + .map(configs, config => webpackCompile(config, logStats), { concurrency }) .then(stats => _.flatten(stats)); } @@ -51,8 +51,9 @@ module.exports = { const configs = ensureArray(this.webpackConfig); const logStats = getStatsLogger(configs[0].stats, this.serverless.cli.consoleLog); + const concurrency = this.serializedCompile === true ? 1 : this.serializedCompile; - return (this.serializedCompile ? webpackCompileSerial : webpackCompile)(configs, logStats) + return webpackConcurrentCompile(configs, logStats, concurrency) .then(stats => { this.compileStats = { stats }; return BbPromise.resolve(); From c96f31f155554c9ce59d7442e226d540158a5543 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:44:04 +0800 Subject: [PATCH 02/30] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 017b2f5db..853439330 100644 --- a/README.md +++ b/README.md @@ -541,12 +541,12 @@ if you are trying to override the entry in webpack.config.js with other unsuppor The individual packaging needs more time at the packaging phase, but you'll get that paid back twice at runtime. -#### Individual packaging serializedCompile +#### Individual packaging concurrency ```yaml # serverless.yml custom: webpack: - serializedCompile: true + concurrency: 5 ``` Will run each webpack build one at a time which helps reduce memory usage and in some cases impoves overall build performance. From c3c3134f3a67363da08b793908ff8e4313173526 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:44:53 +0800 Subject: [PATCH 03/30] Rename to concurrency --- lib/Configuration.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index d2fea80c7..84326e074 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -15,7 +15,7 @@ const DefaultConfig = { packagerOptions: {}, keepOutputDirectory: false, config: null, - serializedCompile: false + concurrency: undefined }; class Configuration { @@ -78,8 +78,8 @@ class Configuration { return this._config.keepOutputDirectory; } - get serializedCompile() { - return this._config.serializedCompile; + get concurrency() { + return this._config.concurrency; } toJSON() { From 0e4563924c752e24f3ef779f9d455ac0cebe81ae Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:45:40 +0800 Subject: [PATCH 04/30] Update Configuration.test.js --- lib/Configuration.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Configuration.test.js b/lib/Configuration.test.js index 4324b4bde..1309fdbfd 100644 --- a/lib/Configuration.test.js +++ b/lib/Configuration.test.js @@ -20,7 +20,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - serializedCompile: false + concurrency: undefined }; }); @@ -70,7 +70,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - serializedCompile: false + concurrency: undefined }); }); }); @@ -91,7 +91,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - serializedCompile: false + concurrency: undefined }); }); @@ -111,7 +111,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - serializedCompile: false + concurrency: undefined }); }); }); From b779c2d0b8d95e87dd411d4dd64d1510643a9aa0 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:47:12 +0800 Subject: [PATCH 05/30] Update validate.js --- lib/validate.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index 393eefebd..6d17d2c05 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -190,11 +190,8 @@ module.exports = { // In case of individual packaging we have to create a separate config for each function if (_.has(this.serverless, 'service.package') && this.serverless.service.package.individually) { this.multiCompile = true; - this.serializedCompile = this.configuration.serializedCompile; - this.options.verbose && - this.serverless.cli.log( - `Using ${this.serializedCompile ? 'serialized' : 'multi'}-compile (individual packaging)` - ); + this.concurrency = this.configuration.concurrency; + this.options.verbose && this.serverless.cli.log(`Using ${this.concurrency ? 'concurrent' : 'multi'}-compile (individual packaging)`); if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { return BbPromise.reject( From b26c27e35ae083319b55e158df2a1eeac54a03a3 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:49:03 +0800 Subject: [PATCH 06/30] Update compile.test.js --- tests/compile.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compile.test.js b/tests/compile.test.js index 58f682029..f0de93576 100644 --- a/tests/compile.test.js +++ b/tests/compile.test.js @@ -103,7 +103,7 @@ describe('compile', () => { }); }); - it('should work with serialized compile', () => { + it('should work with concurrent compile', () => { const testWebpackConfig = ['testconfig']; const multiStats = { stats: [{ @@ -119,7 +119,7 @@ describe('compile', () => { }; module.webpackConfig = testWebpackConfig; module.multiCompile = true; - module.serializedCompile = true; + module.concurrency = 1; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); return expect(module.compile()).to.be.fulfilled From 159388d624a790ac477fb9b1687546245eba1882 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 3 Jul 2020 21:55:50 +0800 Subject: [PATCH 07/30] bluebird doesn't like undefined concurrency --- lib/compile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compile.js b/lib/compile.js index 9df3716c7..40e6a298f 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -51,7 +51,7 @@ module.exports = { const configs = ensureArray(this.webpackConfig); const logStats = getStatsLogger(configs[0].stats, this.serverless.cli.consoleLog); - const concurrency = this.serializedCompile === true ? 1 : this.serializedCompile; + const concurrency = this.concurrency === undefined ? Infinity : this.concurrency; return webpackConcurrentCompile(configs, logStats, concurrency) .then(stats => { From ae9794cf38e8c5a66a61492516caafc21bd5e5c5 Mon Sep 17 00:00:00 2001 From: Vicary Archangel Date: Sun, 4 Oct 2020 21:11:23 +0800 Subject: [PATCH 08/30] Support icloud drive --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e701029f9..88ece127c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules +node_modules.nosync dist .webpack .serverless From 17ac8409b5920a5fcac40becedb987e4f4507288 Mon Sep 17 00:00:00 2001 From: Andrew Sprouse Date: Fri, 14 Jun 2019 01:21:23 -0400 Subject: [PATCH 09/30] Serialized compile to address #299 --- lib/Configuration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index 84326e074..09b346856 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -53,7 +53,7 @@ class Configuration { get excludeFiles() { return this._config.excludeFiles; } - + get excludeRegex() { return this._config.excludeRegex; } From e3b1a0ec1c4a50facb640fa7d9854dda7afb57ac Mon Sep 17 00:00:00 2001 From: Andrew Sprouse Date: Fri, 14 Jun 2019 01:41:17 -0400 Subject: [PATCH 10/30] Add serializedCompile documentation --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 853439330..8d08df3ad 100644 --- a/README.md +++ b/README.md @@ -546,7 +546,8 @@ get that paid back twice at runtime. # serverless.yml custom: webpack: - concurrency: 5 + concurrency: 5 # desired concurrency, defaults to the number of available cores + serializedCompile: true # backward compatible, this translates to concurrency: 1 ``` Will run each webpack build one at a time which helps reduce memory usage and in some cases impoves overall build performance. From 13365aa30305028b365fa9d3556edb4a35c8ee35 Mon Sep 17 00:00:00 2001 From: Vicary Date: Sun, 4 Oct 2020 21:26:56 +0800 Subject: [PATCH 11/30] compatible with serialized compile --- lib/Configuration.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index 09b346856..ca9a523eb 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -79,7 +79,11 @@ class Configuration { } get concurrency() { - return this._config.concurrency; + if (this._config.concurrency !== undefined) { + return this._config.concurrency; + } else if (this._config.serializedCompile === true) { + return 1; + } } toJSON() { From e2b86d12057a7ec85f95055424d46df94fcc9bed Mon Sep 17 00:00:00 2001 From: Vicary Date: Sun, 4 Oct 2020 21:39:33 +0800 Subject: [PATCH 12/30] fix tests --- tests/compile.test.js | 98 ++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/tests/compile.test.js b/tests/compile.test.js index f0de93576..957583a85 100644 --- a/tests/compile.test.js +++ b/tests/compile.test.js @@ -44,10 +44,13 @@ describe('compile', () => { consoleLog: sandbox.stub() }; - module = _.assign({ - serverless, - options: {}, - }, baseModule); + module = _.assign( + { + serverless, + options: {} + }, + baseModule + ); }); afterEach(() => { @@ -62,9 +65,8 @@ describe('compile', () => { it('should compile with webpack from a context configuration', () => { const testWebpackConfig = 'testconfig'; module.webpackConfig = testWebpackConfig; - return expect(module.compile()).to.be.fulfilled - .then(() => { - expect(webpackMock).to.have.been.calledWith([testWebpackConfig]); + return expect(module.compile()).to.be.fulfilled.then(() => { + expect(webpackMock).to.have.been.calledWith(testWebpackConfig); expect(webpackMock.compilerMock.run).to.have.been.calledOnce; return null; }); @@ -78,25 +80,26 @@ describe('compile', () => { }); it('should work with multi compile', () => { - const testWebpackConfig = ['testconfig']; + const testWebpackConfig = 'testconfig'; const multiStats = { - stats: [{ - compilation: { - errors: [], - compiler: { - outputPath: 'statsMock-outputPath', + stats: [ + { + compilation: { + errors: [], + compiler: { + outputPath: 'statsMock-outputPath' + } }, - }, - toString: sandbox.stub().returns('testStats'), - hasErrors: _.constant(false) - }] + toString: sandbox.stub().returns('testStats'), + hasErrors: _.constant(false) + } + ] }; module.webpackConfig = testWebpackConfig; module.multiCompile = true; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); - return expect(module.compile()).to.be.fulfilled - .then(() => { + return expect(module.compile()).to.be.fulfilled.then(() => { expect(webpackMock).to.have.been.calledWith(testWebpackConfig); expect(webpackMock.compilerMock.run).to.have.been.calledOnce; return null; @@ -104,30 +107,31 @@ describe('compile', () => { }); it('should work with concurrent compile', () => { - const testWebpackConfig = ['testconfig']; + const testWebpackConfig = 'testconfig'; const multiStats = { - stats: [{ - compilation: { - errors: [], - compiler: { - outputPath: 'statsMock-outputPath', + stats: [ + { + compilation: { + errors: [], + compiler: { + outputPath: 'statsMock-outputPath' + } }, - }, - toString: sandbox.stub().returns('testStats'), - hasErrors: _.constant(false) - }] + toString: sandbox.stub().returns('testStats'), + hasErrors: _.constant(false) + } + ] }; module.webpackConfig = testWebpackConfig; module.multiCompile = true; module.concurrency = 1; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); - return expect(module.compile()).to.be.fulfilled - .then(() => { - expect(webpackMock).to.have.been.calledWith(testWebpackConfig); - expect(webpackMock.compilerMock.run).to.have.been.calledOnce; - return null; - }); + return expect(module.compile()).to.be.fulfilled.then(() => { + expect(webpackMock).to.have.been.calledWith(testWebpackConfig); + expect(webpackMock.compilerMock.run).to.have.been.calledOnce; + return null; + }); }); it('should use correct stats option', () => { @@ -148,17 +152,17 @@ describe('compile', () => { module.webpackConfig = testWebpackConfig; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, mockStats); - return (expect(module.compile()).to.be.fulfilled) - .then(() => { - expect(webpackMock).to.have.been.calledWith([testWebpackConfig]); - expect(mockStats.toString.firstCall.args).to.eql([testWebpackConfig.stats]); - module.webpackConfig = [testWebpackConfig]; - return (expect(module.compile()).to.be.fulfilled); - }) - .then(() => { - expect(webpackMock).to.have.been.calledWith([testWebpackConfig]); - expect(mockStats.toString.args).to.eql([ [testWebpackConfig.stats], [testWebpackConfig.stats] ]); - return null; - }); + return expect(module.compile()) + .to.be.fulfilled.then(() => { + expect(webpackMock).to.have.been.calledWith(testWebpackConfig); + expect(mockStats.toString.firstCall.args).to.eql([testWebpackConfig.stats]); + module.webpackConfig = [testWebpackConfig]; + return expect(module.compile()).to.be.fulfilled; + }) + .then(() => { + expect(webpackMock).to.have.been.calledWith(testWebpackConfig); + expect(mockStats.toString.args).to.eql([ [testWebpackConfig.stats], [testWebpackConfig.stats] ]); + return null; + }); }); }); From 2e65368981aa398d29af00c2e92b9f20848af4eb Mon Sep 17 00:00:00 2001 From: coyoteecd Date: Mon, 6 Jul 2020 17:24:48 +0300 Subject: [PATCH 13/30] Option to override concurrency setting via serverless CLI --- lib/validate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validate.js b/lib/validate.js index 6d17d2c05..5d69e7957 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -190,7 +190,7 @@ module.exports = { // In case of individual packaging we have to create a separate config for each function if (_.has(this.serverless, 'service.package') && this.serverless.service.package.individually) { this.multiCompile = true; - this.concurrency = this.configuration.concurrency; + this.concurrency = +this.options['compile-concurrency'] || this.configuration.concurrency; this.options.verbose && this.serverless.cli.log(`Using ${this.concurrency ? 'concurrent' : 'multi'}-compile (individual packaging)`); if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { From 2d5a9c47539709ce8d5faf507b44a9e098fd13c4 Mon Sep 17 00:00:00 2001 From: coyoteecd Date: Mon, 6 Jul 2020 23:18:44 +0300 Subject: [PATCH 14/30] Remove compile-concurrency option, since the same can be achieved via serverless.yml. Left only number conversion, since CLI options are typed as string --- lib/compile.js | 2 +- lib/validate.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 40e6a298f..46302e4a8 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -51,7 +51,7 @@ module.exports = { const configs = ensureArray(this.webpackConfig); const logStats = getStatsLogger(configs[0].stats, this.serverless.cli.consoleLog); - const concurrency = this.concurrency === undefined ? Infinity : this.concurrency; + const concurrency = this.concurrency === undefined ? Infinity : Number(this.concurrency); return webpackConcurrentCompile(configs, logStats, concurrency) .then(stats => { diff --git a/lib/validate.js b/lib/validate.js index 5d69e7957..6d17d2c05 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -190,7 +190,7 @@ module.exports = { // In case of individual packaging we have to create a separate config for each function if (_.has(this.serverless, 'service.package') && this.serverless.service.package.individually) { this.multiCompile = true; - this.concurrency = +this.options['compile-concurrency'] || this.configuration.concurrency; + this.concurrency = this.configuration.concurrency; this.options.verbose && this.serverless.cli.log(`Using ${this.concurrency ? 'concurrent' : 'multi'}-compile (individual packaging)`); if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { From 6f17d49089f0f0dd6bf83b5eafc26d16ff6447a4 Mon Sep 17 00:00:00 2001 From: coyoteecd Date: Wed, 14 Oct 2020 19:06:19 +0300 Subject: [PATCH 15/30] Move the parsing and default value for concurrency option in Configuration class --- lib/Configuration.js | 23 +++++++++++++++------ lib/Configuration.test.js | 42 +++++++++++++++++++++++++++++++++++---- lib/compile.js | 6 +++++- lib/validate.js | 5 +++-- tests/compile.test.js | 13 +++++++++++- 5 files changed, 75 insertions(+), 14 deletions(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index ca9a523eb..adb07b86d 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -15,7 +15,7 @@ const DefaultConfig = { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: undefined + concurrency: Infinity }; class Configuration { @@ -38,6 +38,21 @@ class Configuration { } } + // Concurrency may be passed via CLI, e.g. + // custom: + // webpack: + // concurrency: ${opt:compile-concurrency, 7} + // In this case it is typed as a string and we have to validate it + if (this._config.concurrency !== undefined) { + this._config.concurrency = Number(this._config.concurrency); + if (isNaN(this._config.concurrency) || this._config.concurrency < 1) { + throw new Error('concurrency option must be a positive number'); + } + } else if (this._config.serializedCompile === true) { + // Backwards compatibility with serializedCompile setting + this._config.concurrency = 1; + } + // Set defaults for all missing properties _.defaults(this._config, DefaultConfig); } @@ -79,11 +94,7 @@ class Configuration { } get concurrency() { - if (this._config.concurrency !== undefined) { - return this._config.concurrency; - } else if (this._config.serializedCompile === true) { - return 1; - } + return this._config.concurrency; } toJSON() { diff --git a/lib/Configuration.test.js b/lib/Configuration.test.js index 1309fdbfd..a4b4f023d 100644 --- a/lib/Configuration.test.js +++ b/lib/Configuration.test.js @@ -20,7 +20,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: undefined + concurrency: Infinity }; }); @@ -70,7 +70,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: undefined + concurrency: Infinity }); }); }); @@ -91,7 +91,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: undefined + concurrency: Infinity }); }); @@ -111,8 +111,42 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: undefined + concurrency: Infinity }); }); + + it('should accept a numeric string as concurrency value', () => { + const testCustom = { + webpack: { + includeModules: { forceInclude: ['mod1'] }, + webpackConfig: 'myWebpackFile.js', + concurrency: '3' + } + }; + const config = new Configuration(testCustom); + expect(config._config.concurrency).to.equal(3); + }); + + it('should not accept an invalid string as concurrency value', () => { + const testCustom = { + webpack: { + includeModules: { forceInclude: ['mod1'] }, + webpackConfig: 'myWebpackFile.js', + concurrency: '3abc' + } + }; + expect(() => new Configuration(testCustom)).throws(); + }); + + it('should not accept a non-positive number as concurrency value', () => { + const testCustom = { + webpack: { + includeModules: { forceInclude: ['mod1'] }, + webpackConfig: 'myWebpackFile.js', + concurrency: 0 + } + }; + expect(() => new Configuration(testCustom)).throws(); + }); }); }); diff --git a/lib/compile.js b/lib/compile.js index 46302e4a8..73902ab56 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -51,7 +51,11 @@ module.exports = { const configs = ensureArray(this.webpackConfig); const logStats = getStatsLogger(configs[0].stats, this.serverless.cli.consoleLog); - const concurrency = this.concurrency === undefined ? Infinity : Number(this.concurrency); + + if (!this.configuration) { + return BbPromise.reject('Missing plugin configuration'); + } + const concurrency = this.configuration.concurrency; return webpackConcurrentCompile(configs, logStats, concurrency) .then(stats => { diff --git a/lib/validate.js b/lib/validate.js index 6d17d2c05..ce666d863 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -190,8 +190,9 @@ module.exports = { // In case of individual packaging we have to create a separate config for each function if (_.has(this.serverless, 'service.package') && this.serverless.service.package.individually) { this.multiCompile = true; - this.concurrency = this.configuration.concurrency; - this.options.verbose && this.serverless.cli.log(`Using ${this.concurrency ? 'concurrent' : 'multi'}-compile (individual packaging)`); + this.options.verbose && this.serverless.cli.log( + `Using ${this.configuration.concurrency !== Infinity ? 'concurrent' : 'multi'}-compile (individual packaging)` + ); if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { return BbPromise.reject( diff --git a/tests/compile.test.js b/tests/compile.test.js index 957583a85..b9104b5b2 100644 --- a/tests/compile.test.js +++ b/tests/compile.test.js @@ -65,6 +65,7 @@ describe('compile', () => { it('should compile with webpack from a context configuration', () => { const testWebpackConfig = 'testconfig'; module.webpackConfig = testWebpackConfig; + module.configuration = { concurrency: Infinity }; return expect(module.compile()).to.be.fulfilled.then(() => { expect(webpackMock).to.have.been.calledWith(testWebpackConfig); expect(webpackMock.compilerMock.run).to.have.been.calledOnce; @@ -72,8 +73,16 @@ describe('compile', () => { }); }); + it('should fail if configuration is missing', () => { + const testWebpackConfig = 'testconfig'; + module.webpackConfig = testWebpackConfig; + module.configuration = undefined; + return expect(module.compile()).to.be.rejectedWith('Missing plugin configuration'); + }); + it('should fail if there are compilation errors', () => { module.webpackConfig = 'testconfig'; + module.configuration = { concurrency: Infinity }; // We stub errors here. It will be reset again in afterEach() sandbox.stub(webpackMock.statsMock.compilation, 'errors').value(['error']); return expect(module.compile()).to.be.rejectedWith(/compilation error/); @@ -97,6 +106,7 @@ describe('compile', () => { }; module.webpackConfig = testWebpackConfig; module.multiCompile = true; + module.configuration = { concurrency: Infinity }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); return expect(module.compile()).to.be.fulfilled.then(() => { @@ -124,7 +134,7 @@ describe('compile', () => { }; module.webpackConfig = testWebpackConfig; module.multiCompile = true; - module.concurrency = 1; + module.configuration = { concurrency: 1 }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); return expect(module.compile()).to.be.fulfilled.then(() => { @@ -150,6 +160,7 @@ describe('compile', () => { }; module.webpackConfig = testWebpackConfig; + module.configuration = { concurrency: Infinity }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, mockStats); return expect(module.compile()) From 4d8ff2375c301e7a99f0d501e0ad796c170908b1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 3 Sep 2020 13:42:23 +0200 Subject: [PATCH 16/30] Upgrade deps Mostly to fix security issue but also to keep them updated. Also: - fix an ESLint error: `8:16 error Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins` - run prettier (following update) - update `format` script with `$(pwd)` to fix issue with higher version of ESLint (>5) - prettier now run on every js files --- package-lock.json | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0e6e99583..256566b84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9573,6 +9573,14 @@ "util-deprecate": "^1.0.1" } }, + "readdir-glob": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/readdir-glob/-/readdir-glob-1.0.0.tgz", + "integrity": "sha512-km0DIcwQVZ1ZUhXhMWpF74/Wm5aFEd5/jDiVWF1Hkw2myPQovG8vCQ8+FQO2KXE9npQQvCnAMZhhWuUee4WcCQ==", + "requires": { + "minimatch": "^3.0.4" + } + }, "readdirp": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.4.0.tgz", @@ -11045,17 +11053,6 @@ "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", - "dev": true, - "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - } - }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", From 33e3a97295b78b8a3078a28fcdb0dfc3f99fd924 Mon Sep 17 00:00:00 2001 From: James Bourne Date: Thu, 7 May 2020 13:31:55 +0100 Subject: [PATCH 17/30] Skip compile & packaging if --no-build is set (#560) * Add copyExistingArtifacts to packageModules * Refactor packageModules * Set service path * Generate artifact name from service * Output artifacts to .webpack before copying * Set artifact name for service packaging * Skip webpack:compile if --no-build is set * Add webpack:package:copyExistingArtifacts hook * Make packageModules & packExternalModules no-op if skipCompile is set * Refactor packageModules * Remove artifact location setting from packageModules * Update cleanup to check this.keepOutputDirectory * Fix path join on Windows Co-authored-by: Miguel A. Calles MBA <44813512+miguel-a-calles-mba@users.noreply.github.com> --- lib/cleanup.js | 1 + tests/cleanup.test.js | 4 +--- tests/packageModules.test.js | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/cleanup.js b/lib/cleanup.js index 9664c9bb5..6130f8173 100644 --- a/lib/cleanup.js +++ b/lib/cleanup.js @@ -10,6 +10,7 @@ module.exports = { const keepOutputDirectory = this.keepOutputDirectory; const cli = this.options.verbose ? this.serverless.cli : { log: _.noop }; + const keepOutputDirectory = this.keepOutputDirectory; if (!keepOutputDirectory) { cli.log(`Remove ${webpackOutputPath}`); if (this.serverless.utils.dirExistsSync(webpackOutputPath)) { diff --git a/tests/cleanup.test.js b/tests/cleanup.test.js index dec18893a..027a92d13 100644 --- a/tests/cleanup.test.js +++ b/tests/cleanup.test.js @@ -55,9 +55,7 @@ describe('cleanup', () => { module = _.assign( { serverless, - options: { - verbose: true - }, + options: {}, webpackOutputPath: 'my/Output/Path' }, baseModule diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index d9c0329f8..161580bf6 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -74,8 +74,7 @@ describe('packageModules', () => { { serverless, options: {}, - webpackOutputPath: '.webpack', - configuration: new Configuration() + webpackOutputPath: '.webpack' }, baseModule ); From b580a0e0db8e1a0aac21a1bc0f4e5d61614d6c49 Mon Sep 17 00:00:00 2001 From: "Miguel A. Calles MBA" <44813512+miguel-a-calles-mba@users.noreply.github.com> Date: Sun, 12 Jul 2020 15:56:17 -0700 Subject: [PATCH 18/30] Update README.md --- README.md | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/README.md b/README.md index 8d08df3ad..353f7b4ac 100644 --- a/README.md +++ b/README.md @@ -825,3 +825,123 @@ See [CHANGELOG.md](./CHANGELOG.md) [link-serverless-dynamodb-local]: https://www.npmjs.com/package/serverless-dynamodb-local [link-step-functions-offline]: https://www.npmjs.com/package/serverless-step-functions-offline [ico-step-functions-offline]: https://img.shields.io/npm/v/serverless-step-functions-offline.svg + +[comment]: # (Referenced issues) + +[link-135]: https://github.com/serverless-heaven/serverless-webpack/issues/135 + +[link-83]: https://github.com/serverless-heaven/serverless-webpack/pull/83 +[link-88]: https://github.com/serverless-heaven/serverless-webpack/pull/88 +[link-127]: https://github.com/serverless-heaven/serverless-webpack/pull/127 +[link-131]: https://github.com/serverless-heaven/serverless-webpack/pull/131 +[link-132]: https://github.com/serverless-heaven/serverless-webpack/pull/132 +[link-140]: https://github.com/serverless-heaven/serverless-webpack/pull/140 +[link-141]: https://github.com/serverless-heaven/serverless-webpack/issues/141 +[link-144]: https://github.com/serverless-heaven/serverless-webpack/issues/144 + +[link-11]: https://github.com/serverless-heaven/serverless-webpack/issues/11 +[link-107]: https://github.com/serverless-heaven/serverless-webpack/issues/107 +[link-129]: https://github.com/serverless-heaven/serverless-webpack/pull/129 +[link-154]: https://github.com/serverless-heaven/serverless-webpack/issues/154 +[link-159]: https://github.com/serverless-heaven/serverless-webpack/issues/159 + +[link-158]: https://github.com/serverless-heaven/serverless-webpack/issues/158 +[link-165]: https://github.com/serverless-heaven/serverless-webpack/issues/165 + +[link-193]: https://github.com/serverless-heaven/serverless-webpack/issues/193 + +[link-116]: https://github.com/serverless-heaven/serverless-webpack/issues/116 +[link-117]: https://github.com/serverless-heaven/serverless-webpack/issues/117 +[link-120]: https://github.com/serverless-heaven/serverless-webpack/issues/120 +[link-145]: https://github.com/serverless-heaven/serverless-webpack/issues/145 +[link-151]: https://github.com/serverless-heaven/serverless-webpack/issues/151 +[link-152]: https://github.com/serverless-heaven/serverless-webpack/issues/152 +[link-173]: https://github.com/serverless-heaven/serverless-webpack/issues/173 +[link-179]: https://github.com/serverless-heaven/serverless-webpack/pull/179 +[link-185]: https://github.com/serverless-heaven/serverless-webpack/pull/185 +[link-186]: https://github.com/serverless-heaven/serverless-webpack/pull/186 + +[link-202]: https://github.com/serverless-heaven/serverless-webpack/issues/202 + +[link-215]: https://github.com/serverless-heaven/serverless-webpack/issues/215 +[link-217]: https://github.com/serverless-heaven/serverless-webpack/issues/217 +[link-221]: https://github.com/serverless-heaven/serverless-webpack/pull/221 +[link-223]: https://github.com/serverless-heaven/serverless-webpack/issues/223 +[link-227]: https://github.com/serverless-heaven/serverless-webpack/pull/227 +[link-234]: https://github.com/serverless-heaven/serverless-webpack/pull/234 + +[link-245]: https://github.com/serverless-heaven/serverless-webpack/issues/245 + +[link-251]: https://github.com/serverless-heaven/serverless-webpack/issues/251 + +[link-126]: https://github.com/serverless-heaven/serverless-webpack/issues/126 +[link-247]: https://github.com/serverless-heaven/serverless-webpack/issues/247 +[link-250]: https://github.com/serverless-heaven/serverless-webpack/issues/250 +[link-254]: https://github.com/serverless-heaven/serverless-webpack/pull/254 +[link-260]: https://github.com/serverless-heaven/serverless-webpack/issues/260 +[link-264]: https://github.com/serverless-heaven/serverless-webpack/pull/264 +[link-265]: https://github.com/serverless-heaven/serverless-webpack/pull/265 + +[link-272]: https://github.com/serverless-heaven/serverless-webpack/issues/272 +[link-278]: https://github.com/serverless-heaven/serverless-webpack/pull/278 +[link-279]: https://github.com/serverless-heaven/serverless-webpack/issues/279 +[link-276]: https://github.com/serverless-heaven/serverless-webpack/issues/276 +[link-269]: https://github.com/serverless-heaven/serverless-webpack/issues/269 + +[link-263]: https://github.com/serverless-heaven/serverless-webpack/issues/263 + +[link-286]: https://github.com/serverless-heaven/serverless-webpack/issues/286 + +[link-315]: https://github.com/serverless-heaven/serverless-webpack/issues/315 +[link-316]: https://github.com/serverless-heaven/serverless-webpack/issues/316 +[link-253]: https://github.com/serverless-heaven/serverless-webpack/issues/253 +[link-317]: https://github.com/serverless-heaven/serverless-webpack/pull/317 +[link-321]: https://github.com/serverless-heaven/serverless-webpack/pull/321 + +[link-313]: https://github.com/serverless-heaven/serverless-webpack/pull/313 +[link-326]: https://github.com/serverless-heaven/serverless-webpack/pull/326 +[link-329]: https://github.com/serverless-heaven/serverless-webpack/issues/329 + +[link-232]: https://github.com/serverless-heaven/serverless-webpack/issues/232 +[link-331]: https://github.com/serverless-heaven/serverless-webpack/issues/331 +[link-328]: https://github.com/serverless-heaven/serverless-webpack/pull/328 +[link-336]: https://github.com/serverless-heaven/serverless-webpack/pull/336 +[link-337]: https://github.com/serverless-heaven/serverless-webpack/pull/337 + +[link-275]: https://github.com/serverless-heaven/serverless-webpack/issues/275 +[link-286]: https://github.com/serverless-heaven/serverless-webpack/issues/286 +[link-341]: https://github.com/serverless-heaven/serverless-webpack/issues/341 +[link-342]: https://github.com/serverless-heaven/serverless-webpack/issues/342 +[link-343]: https://github.com/serverless-heaven/serverless-webpack/issues/343 + +[link-349]: https://github.com/serverless-heaven/serverless-webpack/issues/349 +[link-354]: https://github.com/serverless-heaven/serverless-webpack/pull/354 +[link-355]: https://github.com/serverless-heaven/serverless-webpack/pull/355 + +[link-309]: https://github.com/serverless-heaven/serverless-webpack/issues/309 +[link-365]: https://github.com/serverless-heaven/serverless-webpack/pull/365 +[link-373]: https://github.com/serverless-heaven/serverless-webpack/pull/373 + +[link-370]: https://github.com/serverless-heaven/serverless-webpack/issues/370 + +[link-379]: https://github.com/serverless-heaven/serverless-webpack/issues/379 +[link-382]: https://github.com/serverless-heaven/serverless-webpack/pull/382 +[link-384]: https://github.com/serverless-heaven/serverless-webpack/pull/384 + +[link-393]: https://github.com/serverless-heaven/serverless-webpack/issues/393 +[link-412]: https://github.com/serverless-heaven/serverless-webpack/issues/412 +[link-418]: https://github.com/serverless-heaven/serverless-webpack/issues/418 + +[link-453]: https://github.com/serverless-heaven/serverless-webpack/issues/453 +[link-467]: https://github.com/serverless-heaven/serverless-webpack/issues/467 +[link-449]: https://github.com/serverless-heaven/serverless-webpack/issues/449 +[link-465]: https://github.com/serverless-heaven/serverless-webpack/issues/465 +[link-480]: https://github.com/serverless-heaven/serverless-webpack/issues/480 +[link-429]: https://github.com/serverless-heaven/serverless-webpack/pull/429 +[link-433]: https://github.com/serverless-heaven/serverless-webpack/issues/433 +[link-471]: https://github.com/serverless-heaven/serverless-webpack/issues/471 +[link-472]: https://github.com/serverless-heaven/serverless-webpack/pull/472 + +[link-505]: https://github.com/serverless-heaven/serverless-webpack/issues/505 +[link-499]: https://github.com/serverless-heaven/serverless-webpack/issues/499 +[link-496]: https://github.com/serverless-heaven/serverless-webpack/pull/496 From d55d96bf4574a46b16f5a09fbfa03dc6ebfeb389 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 24 Jul 2020 11:15:22 +0200 Subject: [PATCH 19/30] Add some tests & fix linter --- tests/packageModules.test.js | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index 161580bf6..12f02cf08 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -74,7 +74,8 @@ describe('packageModules', () => { { serverless, options: {}, - webpackOutputPath: '.webpack' + webpackOutputPath: '.webpack', + configuration: new Configuration() }, baseModule ); @@ -358,6 +359,54 @@ describe('packageModules', () => { module.compileStats = stats; return expect(module.packageModules()).to.be.rejectedWith('Packaging: No files found'); }); + + it('should reject if no files are found because all files are excluded using regex', () => { + module.configuration = new Configuration({ + webpack: { + excludeRegex: /.*/ + } + }); + + // Test data + const stats = { + stats: [ + { + compilation: { + compiler: { + outputPath: '/my/Service/Path/.webpack/service' + } + } + } + ] + }; + const files = [ 'README.md', 'src/handler1.js', 'src/handler1.js.map', 'src/handler2.js', 'src/handler2.js.map' ]; + const allFunctions = [ 'func1', 'func2' ]; + const func1 = { + handler: 'src/handler1', + events: [] + }; + const func2 = { + handler: 'src/handler2', + events: [] + }; + // Serverless behavior + sandbox.stub(serverless.config, 'servicePath').value('/my/Service/Path'); + getVersionStub.returns('1.18.0'); + getServiceObjectStub.returns({ + name: 'test-service' + }); + getAllFunctionsStub.returns(allFunctions); + getFunctionStub.withArgs('func1').returns(func1); + getFunctionStub.withArgs('func2').returns(func2); + // Mock behavior + globMock.sync.returns(files); + fsMock._streamMock.on.withArgs('open').yields(); + fsMock._streamMock.on.withArgs('close').yields(); + fsMock._statMock.isDirectory.returns(false); + + module.compileStats = stats; + return expect(module.packageModules()).to.be.rejectedWith('Packaging: No files found'); + }); }); describe('with individual packaging', () => { From eecb07bce761152fa37cba1022aa82366f03583c Mon Sep 17 00:00:00 2001 From: Andrew Sprouse Date: Fri, 14 Jun 2019 01:21:23 -0400 Subject: [PATCH 20/30] Serialized compile to address #299 --- lib/Configuration.test.js | 20 ++++++++++++++----- lib/compile.js | 41 ++++++++++++++++++--------------------- lib/validate.js | 9 +++------ tests/compile.test.js | 2 +- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/lib/Configuration.test.js b/lib/Configuration.test.js index a4b4f023d..90410e58c 100644 --- a/lib/Configuration.test.js +++ b/lib/Configuration.test.js @@ -26,13 +26,17 @@ describe('Configuration', () => { it('should set default configuration without custom', () => { const config = new Configuration(); - expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults); + expect(config) + .to.have.a.property('_config') + .that.deep.equals(expectedDefaults); expect(config).to.have.a.property('hasLegacyConfig').that.is.false; }); it('should set default configuration without webpack property', () => { const config = new Configuration({}); - expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults); + expect(config) + .to.have.a.property('_config') + .that.deep.equals(expectedDefaults); expect(config).to.have.a.property('hasLegacyConfig').that.is.false; }); }); @@ -41,13 +45,17 @@ describe('Configuration', () => { it('should use custom.webpackIncludeModules', () => { const testCustom = { webpackIncludeModules: { forceInclude: ['mod1'] } }; const config = new Configuration(testCustom); - expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules); + expect(config) + .to.have.a.property('includeModules') + .that.deep.equals(testCustom.webpackIncludeModules); }); it('should use custom.webpack as string', () => { const testCustom = { webpack: 'myWebpackFile.js' }; const config = new Configuration(testCustom); - expect(config).to.have.a.property('webpackConfig').that.equals('myWebpackFile.js'); + expect(config) + .to.have.a.property('webpackConfig') + .that.equals('myWebpackFile.js'); }); it('should detect it', () => { @@ -62,7 +70,9 @@ describe('Configuration', () => { webpack: 'myWebpackFile.js' }; const config = new Configuration(testCustom); - expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules); + expect(config) + .to.have.a.property('includeModules') + .that.deep.equals(testCustom.webpackIncludeModules); expect(config._config).to.deep.equal({ webpackConfig: 'myWebpackFile.js', includeModules: { forceInclude: ['mod1'] }, diff --git a/lib/compile.js b/lib/compile.js index 73902ab56..aa6d2aa5b 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -22,27 +22,25 @@ function getStatsLogger(statsConfig, consoleLog) { } function webpackCompile(config, logStats) { - return BbPromise - .fromCallback(cb => webpack(config).run(cb)) - .then(stats => { - // ensure stats in any array in the case of multiCompile - stats = stats.stats ? stats.stats : [stats]; - - _.forEach(stats, compileStats => { - logStats(compileStats); - if (compileStats.hasErrors()) { - throw new Error('Webpack compilation error, see stats above'); - } - }); - - return stats; + return BbPromise.fromCallback(cb => webpack(config).run(cb)).then(stats => { + // ensure stats in any array in the case of multiCompile + stats = stats.stats ? stats.stats : [stats]; + + _.forEach(stats, compileStats => { + logStats(compileStats); + if (compileStats.hasErrors()) { + throw new Error('Webpack compilation error, see stats above'); + } }); + + return stats; + }); } function webpackConcurrentCompile(configs, logStats, concurrency) { - return BbPromise - .map(configs, config => webpackCompile(config, logStats), { concurrency }) - .then(stats => _.flatten(stats)); + return BbPromise.map(configs, config => webpackCompile(config, logStats), { concurrency }).then(stats => + _.flatten(stats) + ); } module.exports = { @@ -57,10 +55,9 @@ module.exports = { } const concurrency = this.configuration.concurrency; - return webpackConcurrentCompile(configs, logStats, concurrency) - .then(stats => { - this.compileStats = { stats }; - return BbPromise.resolve(); - }); + return webpackConcurrentCompile(configs, logStats, concurrency).then(stats => { + this.compileStats = { stats }; + return BbPromise.resolve(); + }); } }; diff --git a/lib/validate.js b/lib/validate.js index ce666d863..80516c298 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -13,7 +13,7 @@ const Configuration = require('./Configuration'); * This should cover most of the cases. For complex setups the user should * build his own entries with help of the other exports. */ -const preferredExtensions = [ '.js', '.ts', '.jsx', '.tsx' ]; +const preferredExtensions = ['.js', '.ts', '.jsx', '.tsx']; module.exports = { validate() { @@ -42,10 +42,7 @@ module.exports = { // Move preferred file extensions to the beginning const sortedFiles = _.uniq( _.concat( - _.sortBy( - _.filter(files, file => _.includes(preferredExtensions, path.extname(file))), - a => _.size(a) - ), + _.sortBy(_.filter(files, file => _.includes(preferredExtensions, path.extname(file))), a => _.size(a)), files ) ); @@ -226,7 +223,7 @@ module.exports = { const entry = path.relative('.', value); const entryFile = _.replace(entry, new RegExp(`${path.extname(entry)}$`), ''); - const entryFuncs = _.filter(allEntryFunctions, [ 'handlerFile', entryFile ]); + const entryFuncs = _.filter(allEntryFunctions, ['handlerFile', entryFile]); if (_.isEmpty(entryFuncs)) { // We have to make sure that for each entry there is an entry function item. entryFuncs.push({}); diff --git a/tests/compile.test.js b/tests/compile.test.js index b9104b5b2..f9b6b9298 100644 --- a/tests/compile.test.js +++ b/tests/compile.test.js @@ -172,7 +172,7 @@ describe('compile', () => { }) .then(() => { expect(webpackMock).to.have.been.calledWith(testWebpackConfig); - expect(mockStats.toString.args).to.eql([ [testWebpackConfig.stats], [testWebpackConfig.stats] ]); + expect(mockStats.toString.args).to.eql([[testWebpackConfig.stats], [testWebpackConfig.stats]]); return null; }); }); From 3e31d7c5369889880571ac16501faafb4e9c638e Mon Sep 17 00:00:00 2001 From: Vicary Date: Sun, 4 Oct 2020 21:26:56 +0800 Subject: [PATCH 21/30] compatible with serialized compile --- lib/Configuration.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index adb07b86d..3243d173a 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -94,7 +94,11 @@ class Configuration { } get concurrency() { - return this._config.concurrency; + if (this._config.concurrency !== undefined) { + return this._config.concurrency; + } else if (this._config.serializedCompile === true) { + return 1; + } } toJSON() { From 0ec8200e6ac06ee2ef165fd24799c9f6b3bbab18 Mon Sep 17 00:00:00 2001 From: coyoteecd Date: Mon, 6 Jul 2020 17:24:48 +0300 Subject: [PATCH 22/30] Option to override concurrency setting via serverless CLI --- lib/validate.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index 80516c298..1bfd026f8 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -42,7 +42,10 @@ module.exports = { // Move preferred file extensions to the beginning const sortedFiles = _.uniq( _.concat( - _.sortBy(_.filter(files, file => _.includes(preferredExtensions, path.extname(file))), a => _.size(a)), + _.sortBy( + _.filter(files, file => _.includes(preferredExtensions, path.extname(file))), + a => _.size(a) + ), files ) ); @@ -187,9 +190,12 @@ module.exports = { // In case of individual packaging we have to create a separate config for each function if (_.has(this.serverless, 'service.package') && this.serverless.service.package.individually) { this.multiCompile = true; - this.options.verbose && this.serverless.cli.log( - `Using ${this.configuration.concurrency !== Infinity ? 'concurrent' : 'multi'}-compile (individual packaging)` - ); + this.options.verbose && + this.serverless.cli.log( + `Using ${ + this.configuration.concurrency !== Infinity ? 'concurrent' : 'multi' + }-compile (individual packaging)` + ); if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { return BbPromise.reject( From 7164e8cfb041e56b9d0f0c0f8130b2b85dc2d57c Mon Sep 17 00:00:00 2001 From: coyoteecd Date: Wed, 14 Oct 2020 19:06:19 +0300 Subject: [PATCH 23/30] Move the parsing and default value for concurrency option in Configuration class --- lib/Configuration.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index 3243d173a..adb07b86d 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -94,11 +94,7 @@ class Configuration { } get concurrency() { - if (this._config.concurrency !== undefined) { - return this._config.concurrency; - } else if (this._config.serializedCompile === true) { - return 1; - } + return this._config.concurrency; } toJSON() { From 04f02aa355e3d14685b82fe56fc7051e11298940 Mon Sep 17 00:00:00 2001 From: Vicary Date: Wed, 13 Jan 2021 14:27:57 +0800 Subject: [PATCH 24/30] fix rebase artifact --- lib/cleanup.js | 1 - tests/cleanup.test.js | 4 +++- tests/packageModules.test.js | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cleanup.js b/lib/cleanup.js index 6130f8173..9664c9bb5 100644 --- a/lib/cleanup.js +++ b/lib/cleanup.js @@ -10,7 +10,6 @@ module.exports = { const keepOutputDirectory = this.keepOutputDirectory; const cli = this.options.verbose ? this.serverless.cli : { log: _.noop }; - const keepOutputDirectory = this.keepOutputDirectory; if (!keepOutputDirectory) { cli.log(`Remove ${webpackOutputPath}`); if (this.serverless.utils.dirExistsSync(webpackOutputPath)) { diff --git a/tests/cleanup.test.js b/tests/cleanup.test.js index 027a92d13..dec18893a 100644 --- a/tests/cleanup.test.js +++ b/tests/cleanup.test.js @@ -55,7 +55,9 @@ describe('cleanup', () => { module = _.assign( { serverless, - options: {}, + options: { + verbose: true + }, webpackOutputPath: 'my/Output/Path' }, baseModule diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index 12f02cf08..8713a650d 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -158,7 +158,6 @@ describe('packageModules', () => { fsMock._statMock.isDirectory.returns(false); module.compileStats = stats; - return expect(module.packageModules()).to.be.fulfilled.then(() => BbPromise.all([])); }); From 9f6e3d2436149444869910efa671ad915ade403f Mon Sep 17 00:00:00 2001 From: Vicary Date: Wed, 13 Jan 2021 14:58:16 +0800 Subject: [PATCH 25/30] fix rebase artifacts --- README.md | 120 ------------------------------------------ lib/validate.js | 4 +- tests/compile.test.js | 11 ++-- 3 files changed, 8 insertions(+), 127 deletions(-) diff --git a/README.md b/README.md index 353f7b4ac..8d08df3ad 100644 --- a/README.md +++ b/README.md @@ -825,123 +825,3 @@ See [CHANGELOG.md](./CHANGELOG.md) [link-serverless-dynamodb-local]: https://www.npmjs.com/package/serverless-dynamodb-local [link-step-functions-offline]: https://www.npmjs.com/package/serverless-step-functions-offline [ico-step-functions-offline]: https://img.shields.io/npm/v/serverless-step-functions-offline.svg - -[comment]: # (Referenced issues) - -[link-135]: https://github.com/serverless-heaven/serverless-webpack/issues/135 - -[link-83]: https://github.com/serverless-heaven/serverless-webpack/pull/83 -[link-88]: https://github.com/serverless-heaven/serverless-webpack/pull/88 -[link-127]: https://github.com/serverless-heaven/serverless-webpack/pull/127 -[link-131]: https://github.com/serverless-heaven/serverless-webpack/pull/131 -[link-132]: https://github.com/serverless-heaven/serverless-webpack/pull/132 -[link-140]: https://github.com/serverless-heaven/serverless-webpack/pull/140 -[link-141]: https://github.com/serverless-heaven/serverless-webpack/issues/141 -[link-144]: https://github.com/serverless-heaven/serverless-webpack/issues/144 - -[link-11]: https://github.com/serverless-heaven/serverless-webpack/issues/11 -[link-107]: https://github.com/serverless-heaven/serverless-webpack/issues/107 -[link-129]: https://github.com/serverless-heaven/serverless-webpack/pull/129 -[link-154]: https://github.com/serverless-heaven/serverless-webpack/issues/154 -[link-159]: https://github.com/serverless-heaven/serverless-webpack/issues/159 - -[link-158]: https://github.com/serverless-heaven/serverless-webpack/issues/158 -[link-165]: https://github.com/serverless-heaven/serverless-webpack/issues/165 - -[link-193]: https://github.com/serverless-heaven/serverless-webpack/issues/193 - -[link-116]: https://github.com/serverless-heaven/serverless-webpack/issues/116 -[link-117]: https://github.com/serverless-heaven/serverless-webpack/issues/117 -[link-120]: https://github.com/serverless-heaven/serverless-webpack/issues/120 -[link-145]: https://github.com/serverless-heaven/serverless-webpack/issues/145 -[link-151]: https://github.com/serverless-heaven/serverless-webpack/issues/151 -[link-152]: https://github.com/serverless-heaven/serverless-webpack/issues/152 -[link-173]: https://github.com/serverless-heaven/serverless-webpack/issues/173 -[link-179]: https://github.com/serverless-heaven/serverless-webpack/pull/179 -[link-185]: https://github.com/serverless-heaven/serverless-webpack/pull/185 -[link-186]: https://github.com/serverless-heaven/serverless-webpack/pull/186 - -[link-202]: https://github.com/serverless-heaven/serverless-webpack/issues/202 - -[link-215]: https://github.com/serverless-heaven/serverless-webpack/issues/215 -[link-217]: https://github.com/serverless-heaven/serverless-webpack/issues/217 -[link-221]: https://github.com/serverless-heaven/serverless-webpack/pull/221 -[link-223]: https://github.com/serverless-heaven/serverless-webpack/issues/223 -[link-227]: https://github.com/serverless-heaven/serverless-webpack/pull/227 -[link-234]: https://github.com/serverless-heaven/serverless-webpack/pull/234 - -[link-245]: https://github.com/serverless-heaven/serverless-webpack/issues/245 - -[link-251]: https://github.com/serverless-heaven/serverless-webpack/issues/251 - -[link-126]: https://github.com/serverless-heaven/serverless-webpack/issues/126 -[link-247]: https://github.com/serverless-heaven/serverless-webpack/issues/247 -[link-250]: https://github.com/serverless-heaven/serverless-webpack/issues/250 -[link-254]: https://github.com/serverless-heaven/serverless-webpack/pull/254 -[link-260]: https://github.com/serverless-heaven/serverless-webpack/issues/260 -[link-264]: https://github.com/serverless-heaven/serverless-webpack/pull/264 -[link-265]: https://github.com/serverless-heaven/serverless-webpack/pull/265 - -[link-272]: https://github.com/serverless-heaven/serverless-webpack/issues/272 -[link-278]: https://github.com/serverless-heaven/serverless-webpack/pull/278 -[link-279]: https://github.com/serverless-heaven/serverless-webpack/issues/279 -[link-276]: https://github.com/serverless-heaven/serverless-webpack/issues/276 -[link-269]: https://github.com/serverless-heaven/serverless-webpack/issues/269 - -[link-263]: https://github.com/serverless-heaven/serverless-webpack/issues/263 - -[link-286]: https://github.com/serverless-heaven/serverless-webpack/issues/286 - -[link-315]: https://github.com/serverless-heaven/serverless-webpack/issues/315 -[link-316]: https://github.com/serverless-heaven/serverless-webpack/issues/316 -[link-253]: https://github.com/serverless-heaven/serverless-webpack/issues/253 -[link-317]: https://github.com/serverless-heaven/serverless-webpack/pull/317 -[link-321]: https://github.com/serverless-heaven/serverless-webpack/pull/321 - -[link-313]: https://github.com/serverless-heaven/serverless-webpack/pull/313 -[link-326]: https://github.com/serverless-heaven/serverless-webpack/pull/326 -[link-329]: https://github.com/serverless-heaven/serverless-webpack/issues/329 - -[link-232]: https://github.com/serverless-heaven/serverless-webpack/issues/232 -[link-331]: https://github.com/serverless-heaven/serverless-webpack/issues/331 -[link-328]: https://github.com/serverless-heaven/serverless-webpack/pull/328 -[link-336]: https://github.com/serverless-heaven/serverless-webpack/pull/336 -[link-337]: https://github.com/serverless-heaven/serverless-webpack/pull/337 - -[link-275]: https://github.com/serverless-heaven/serverless-webpack/issues/275 -[link-286]: https://github.com/serverless-heaven/serverless-webpack/issues/286 -[link-341]: https://github.com/serverless-heaven/serverless-webpack/issues/341 -[link-342]: https://github.com/serverless-heaven/serverless-webpack/issues/342 -[link-343]: https://github.com/serverless-heaven/serverless-webpack/issues/343 - -[link-349]: https://github.com/serverless-heaven/serverless-webpack/issues/349 -[link-354]: https://github.com/serverless-heaven/serverless-webpack/pull/354 -[link-355]: https://github.com/serverless-heaven/serverless-webpack/pull/355 - -[link-309]: https://github.com/serverless-heaven/serverless-webpack/issues/309 -[link-365]: https://github.com/serverless-heaven/serverless-webpack/pull/365 -[link-373]: https://github.com/serverless-heaven/serverless-webpack/pull/373 - -[link-370]: https://github.com/serverless-heaven/serverless-webpack/issues/370 - -[link-379]: https://github.com/serverless-heaven/serverless-webpack/issues/379 -[link-382]: https://github.com/serverless-heaven/serverless-webpack/pull/382 -[link-384]: https://github.com/serverless-heaven/serverless-webpack/pull/384 - -[link-393]: https://github.com/serverless-heaven/serverless-webpack/issues/393 -[link-412]: https://github.com/serverless-heaven/serverless-webpack/issues/412 -[link-418]: https://github.com/serverless-heaven/serverless-webpack/issues/418 - -[link-453]: https://github.com/serverless-heaven/serverless-webpack/issues/453 -[link-467]: https://github.com/serverless-heaven/serverless-webpack/issues/467 -[link-449]: https://github.com/serverless-heaven/serverless-webpack/issues/449 -[link-465]: https://github.com/serverless-heaven/serverless-webpack/issues/465 -[link-480]: https://github.com/serverless-heaven/serverless-webpack/issues/480 -[link-429]: https://github.com/serverless-heaven/serverless-webpack/pull/429 -[link-433]: https://github.com/serverless-heaven/serverless-webpack/issues/433 -[link-471]: https://github.com/serverless-heaven/serverless-webpack/issues/471 -[link-472]: https://github.com/serverless-heaven/serverless-webpack/pull/472 - -[link-505]: https://github.com/serverless-heaven/serverless-webpack/issues/505 -[link-499]: https://github.com/serverless-heaven/serverless-webpack/issues/499 -[link-496]: https://github.com/serverless-heaven/serverless-webpack/pull/496 diff --git a/lib/validate.js b/lib/validate.js index 1bfd026f8..26290e980 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -13,7 +13,7 @@ const Configuration = require('./Configuration'); * This should cover most of the cases. For complex setups the user should * build his own entries with help of the other exports. */ -const preferredExtensions = ['.js', '.ts', '.jsx', '.tsx']; +const preferredExtensions = [ '.js', '.ts', '.jsx', '.tsx' ]; module.exports = { validate() { @@ -229,7 +229,7 @@ module.exports = { const entry = path.relative('.', value); const entryFile = _.replace(entry, new RegExp(`${path.extname(entry)}$`), ''); - const entryFuncs = _.filter(allEntryFunctions, ['handlerFile', entryFile]); + const entryFuncs = _.filter(allEntryFunctions, [ 'handlerFile', entryFile ]); if (_.isEmpty(entryFuncs)) { // We have to make sure that for each entry there is an entry function item. entryFuncs.push({}); diff --git a/tests/compile.test.js b/tests/compile.test.js index f9b6b9298..4fc21eacd 100644 --- a/tests/compile.test.js +++ b/tests/compile.test.js @@ -117,7 +117,7 @@ describe('compile', () => { }); it('should work with concurrent compile', () => { - const testWebpackConfig = 'testconfig'; + const testWebpackConfig = [ 'testconfig', 'testconfig2' ]; const multiStats = { stats: [ { @@ -134,12 +134,13 @@ describe('compile', () => { }; module.webpackConfig = testWebpackConfig; module.multiCompile = true; - module.configuration = { concurrency: 1 }; + module.configuration = { concurrency: 2 }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); return expect(module.compile()).to.be.fulfilled.then(() => { - expect(webpackMock).to.have.been.calledWith(testWebpackConfig); - expect(webpackMock.compilerMock.run).to.have.been.calledOnce; + expect(webpackMock).to.have.been.calledWith(testWebpackConfig[0]); + expect(webpackMock).to.have.been.calledWith(testWebpackConfig[1]); + expect(webpackMock.compilerMock.run).to.have.been.calledTwice; return null; }); }); @@ -172,7 +173,7 @@ describe('compile', () => { }) .then(() => { expect(webpackMock).to.have.been.calledWith(testWebpackConfig); - expect(mockStats.toString.args).to.eql([[testWebpackConfig.stats], [testWebpackConfig.stats]]); + expect(mockStats.toString.args).to.eql([ [testWebpackConfig.stats], [testWebpackConfig.stats] ]); return null; }); }); From 4bae141d67e19d851bb2359dee620525360ef5eb Mon Sep 17 00:00:00 2001 From: Vicary Date: Mon, 1 Mar 2021 20:11:35 +0800 Subject: [PATCH 26/30] fix test coverage --- lib/Configuration.test.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Configuration.test.js b/lib/Configuration.test.js index 90410e58c..5a0e737b5 100644 --- a/lib/Configuration.test.js +++ b/lib/Configuration.test.js @@ -26,17 +26,13 @@ describe('Configuration', () => { it('should set default configuration without custom', () => { const config = new Configuration(); - expect(config) - .to.have.a.property('_config') - .that.deep.equals(expectedDefaults); + expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults); expect(config).to.have.a.property('hasLegacyConfig').that.is.false; }); it('should set default configuration without webpack property', () => { const config = new Configuration({}); - expect(config) - .to.have.a.property('_config') - .that.deep.equals(expectedDefaults); + expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults); expect(config).to.have.a.property('hasLegacyConfig').that.is.false; }); }); @@ -45,17 +41,13 @@ describe('Configuration', () => { it('should use custom.webpackIncludeModules', () => { const testCustom = { webpackIncludeModules: { forceInclude: ['mod1'] } }; const config = new Configuration(testCustom); - expect(config) - .to.have.a.property('includeModules') - .that.deep.equals(testCustom.webpackIncludeModules); + expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules); }); it('should use custom.webpack as string', () => { const testCustom = { webpack: 'myWebpackFile.js' }; const config = new Configuration(testCustom); - expect(config) - .to.have.a.property('webpackConfig') - .that.equals('myWebpackFile.js'); + expect(config).to.have.a.property('webpackConfig').that.equals('myWebpackFile.js'); }); it('should detect it', () => { @@ -70,9 +62,7 @@ describe('Configuration', () => { webpack: 'myWebpackFile.js' }; const config = new Configuration(testCustom); - expect(config) - .to.have.a.property('includeModules') - .that.deep.equals(testCustom.webpackIncludeModules); + expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules); expect(config._config).to.deep.equal({ webpackConfig: 'myWebpackFile.js', includeModules: { forceInclude: ['mod1'] }, @@ -134,7 +124,7 @@ describe('Configuration', () => { } }; const config = new Configuration(testCustom); - expect(config._config.concurrency).to.equal(3); + expect(config.concurrency).to.equal(3); }); it('should not accept an invalid string as concurrency value', () => { @@ -158,5 +148,15 @@ describe('Configuration', () => { }; expect(() => new Configuration(testCustom)).throws(); }); + + it('should be backward compatible with serializedCompile', () => { + const testCustom = { + webpack: { + serializedCompile: true + } + }; + const config = new Configuration(testCustom); + expect(config.concurrency).to.equal(1); + }); }); }); From 1cf851d94bded664f21c4d0ae256d8130e040e46 Mon Sep 17 00:00:00 2001 From: Vicary Date: Mon, 1 Mar 2021 20:27:44 +0800 Subject: [PATCH 27/30] remove rebase artifacts --- tests/packageModules.test.js | 84 ++++-------------------------------- 1 file changed, 9 insertions(+), 75 deletions(-) diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index 8713a650d..32fc6ae83 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -358,54 +358,6 @@ describe('packageModules', () => { module.compileStats = stats; return expect(module.packageModules()).to.be.rejectedWith('Packaging: No files found'); }); - - it('should reject if no files are found because all files are excluded using regex', () => { - module.configuration = new Configuration({ - webpack: { - excludeRegex: /.*/ - } - }); - - // Test data - const stats = { - stats: [ - { - compilation: { - compiler: { - outputPath: '/my/Service/Path/.webpack/service' - } - } - } - ] - }; - const files = [ 'README.md', 'src/handler1.js', 'src/handler1.js.map', 'src/handler2.js', 'src/handler2.js.map' ]; - const allFunctions = [ 'func1', 'func2' ]; - const func1 = { - handler: 'src/handler1', - events: [] - }; - const func2 = { - handler: 'src/handler2', - events: [] - }; - // Serverless behavior - sandbox.stub(serverless.config, 'servicePath').value('/my/Service/Path'); - getVersionStub.returns('1.18.0'); - getServiceObjectStub.returns({ - name: 'test-service' - }); - getAllFunctionsStub.returns(allFunctions); - getFunctionStub.withArgs('func1').returns(func1); - getFunctionStub.withArgs('func2').returns(func2); - // Mock behavior - globMock.sync.returns(files); - fsMock._streamMock.on.withArgs('open').yields(); - fsMock._streamMock.on.withArgs('close').yields(); - fsMock._statMock.isDirectory.returns(false); - - module.compileStats = stats; - return expect(module.packageModules()).to.be.rejectedWith('Packaging: No files found'); - }); }); describe('with individual packaging', () => { @@ -532,12 +484,8 @@ describe('packageModules', () => { expect(fsMock.copyFileSync).to.be.calledWith(expectedArtifactSource, expectedArtifactDestination), // Should set package artifact for each function to the single artifact - expect(func1) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedArtifactDestination), - expect(func2) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedArtifactDestination) + expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactDestination), + expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactDestination) ]) ); }); @@ -586,12 +534,8 @@ describe('packageModules', () => { getVersionStub.returns(version); return expect(module.copyExistingArtifacts()).to.be.fulfilled.then(() => BbPromise.all([ - expect(func1) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedArtifactPath), - expect(func2) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedArtifactPath) + expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath), + expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath) ]) ); }).then(() => @@ -599,12 +543,8 @@ describe('packageModules', () => { getVersionStub.returns(version); return expect(module.copyExistingArtifacts()).to.be.fulfilled.then(() => BbPromise.all([ - expect(func1) - .to.have.a.nested.property('artifact') - .that.equals(expectedArtifactPath), - expect(func2) - .to.have.a.nested.property('artifact') - .that.equals(expectedArtifactPath), + expect(func1).to.have.a.nested.property('artifact').that.equals(expectedArtifactPath), + expect(func2).to.have.a.nested.property('artifact').that.equals(expectedArtifactPath), expect(func1).to.have.a.nested.property('package.disable').that.is.true, expect(func2).to.have.a.nested.property('package.disable').that.is.true ]) @@ -657,9 +597,7 @@ describe('packageModules', () => { const expectedArtifactPath = path.join('.serverless', 'test-service.zip'); return expect(module.copyExistingArtifacts()).to.be.fulfilled.then(() => - expect(serverless.service) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedArtifactPath) + expect(serverless.service).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath) ); }); }); @@ -694,12 +632,8 @@ describe('packageModules', () => { expect(fsMock.copyFileSync).to.be.calledWith(path.join('.webpack', 'func2.zip'), expectedFunc2Destination), // Should set package artifact locations - expect(func1) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedFunc1Destination), - expect(func2) - .to.have.a.nested.property('package.artifact') - .that.equals(expectedFunc2Destination) + expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedFunc1Destination), + expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedFunc2Destination) ]) ); }); From a5e620af2b8236ab7e248e81a9af5ffdbf1deca5 Mon Sep 17 00:00:00 2001 From: Vicary Date: Wed, 3 Mar 2021 21:57:37 +0800 Subject: [PATCH 28/30] defaults to number of cores --- lib/Configuration.js | 3 ++- lib/Configuration.test.js | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Configuration.js b/lib/Configuration.js index adb07b86d..d14cdd2eb 100644 --- a/lib/Configuration.js +++ b/lib/Configuration.js @@ -4,6 +4,7 @@ */ const _ = require('lodash'); +const os = require('os'); /** * Plugin defaults @@ -15,7 +16,7 @@ const DefaultConfig = { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: Infinity + concurrency: os.cpus().length }; class Configuration { diff --git a/lib/Configuration.test.js b/lib/Configuration.test.js index 5a0e737b5..2ef1acdc1 100644 --- a/lib/Configuration.test.js +++ b/lib/Configuration.test.js @@ -3,6 +3,7 @@ * Unit tests for Configuration. */ +const os = require('os'); const chai = require('chai'); const Configuration = require('./Configuration'); @@ -20,7 +21,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: Infinity + concurrency: os.cpus().length }; }); @@ -70,7 +71,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: Infinity + concurrency: os.cpus().length }); }); }); @@ -91,7 +92,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: Infinity + concurrency: os.cpus().length }); }); @@ -111,7 +112,7 @@ describe('Configuration', () => { packagerOptions: {}, keepOutputDirectory: false, config: null, - concurrency: Infinity + concurrency: os.cpus().length }); }); From 9f4fcfeeb50e9b56e61f893f1b349743b6c210ca Mon Sep 17 00:00:00 2001 From: Vicary Date: Thu, 4 Mar 2021 15:39:24 +0800 Subject: [PATCH 29/30] change test concurrency to reduce ambiguity --- tests/compile.test.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/compile.test.js b/tests/compile.test.js index 4fc21eacd..7e1ecd8b8 100644 --- a/tests/compile.test.js +++ b/tests/compile.test.js @@ -65,7 +65,7 @@ describe('compile', () => { it('should compile with webpack from a context configuration', () => { const testWebpackConfig = 'testconfig'; module.webpackConfig = testWebpackConfig; - module.configuration = { concurrency: Infinity }; + module.configuration = { concurrency: 1 }; return expect(module.compile()).to.be.fulfilled.then(() => { expect(webpackMock).to.have.been.calledWith(testWebpackConfig); expect(webpackMock.compilerMock.run).to.have.been.calledOnce; @@ -82,7 +82,7 @@ describe('compile', () => { it('should fail if there are compilation errors', () => { module.webpackConfig = 'testconfig'; - module.configuration = { concurrency: Infinity }; + module.configuration = { concurrency: 1 }; // We stub errors here. It will be reset again in afterEach() sandbox.stub(webpackMock.statsMock.compilation, 'errors').value(['error']); return expect(module.compile()).to.be.rejectedWith(/compilation error/); @@ -105,8 +105,7 @@ describe('compile', () => { ] }; module.webpackConfig = testWebpackConfig; - module.multiCompile = true; - module.configuration = { concurrency: Infinity }; + module.configuration = { concurrency: 1 }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); return expect(module.compile()).to.be.fulfilled.then(() => { @@ -133,7 +132,6 @@ describe('compile', () => { ] }; module.webpackConfig = testWebpackConfig; - module.multiCompile = true; module.configuration = { concurrency: 2 }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, multiStats); @@ -161,7 +159,7 @@ describe('compile', () => { }; module.webpackConfig = testWebpackConfig; - module.configuration = { concurrency: Infinity }; + module.configuration = { concurrency: 1 }; webpackMock.compilerMock.run.reset(); webpackMock.compilerMock.run.yields(null, mockStats); return expect(module.compile()) From b583a8dc325ec6a8afde6e25f0827d41a95b4713 Mon Sep 17 00:00:00 2001 From: Vicary Date: Thu, 4 Mar 2021 18:02:37 +0800 Subject: [PATCH 30/30] remove multiCompile and simplify concurrent log --- lib/compile.js | 2 +- lib/validate.js | 5 +---- tests/validate.test.js | 13 ------------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index aa6d2aa5b..cdb9b6d61 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -23,7 +23,7 @@ function getStatsLogger(statsConfig, consoleLog) { function webpackCompile(config, logStats) { return BbPromise.fromCallback(cb => webpack(config).run(cb)).then(stats => { - // ensure stats in any array in the case of multiCompile + // ensure stats in any array in the case of concurrent build. stats = stats.stats ? stats.stats : [stats]; _.forEach(stats, compileStats => { diff --git a/lib/validate.js b/lib/validate.js index 26290e980..8209ec8e2 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -189,12 +189,9 @@ module.exports = { // In case of individual packaging we have to create a separate config for each function if (_.has(this.serverless, 'service.package') && this.serverless.service.package.individually) { - this.multiCompile = true; this.options.verbose && this.serverless.cli.log( - `Using ${ - this.configuration.concurrency !== Infinity ? 'concurrent' : 'multi' - }-compile (individual packaging)` + `Individually packaging with concurrency at ${this.configuration.concurrency} entries a time.` ); if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { diff --git a/tests/validate.test.js b/tests/validate.test.js index a99da798d..ee4210b99 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -686,19 +686,6 @@ describe('validate', () => { _.unset(module.serverless, 'service.package.individually'); }); - it('should enable multiCompile', () => { - _.set(module.serverless.service, 'custom.webpack.config', testConfig); - module.serverless.service.functions = testFunctionsConfig; - globSyncStub.callsFake(filename => [_.replace(filename, '*', 'js')]); - - expect(module.multiCompile).to.be.undefined; - return expect(module.validate()).to.be.fulfilled.then(() => { - expect(module.multiCompile).to.be.true; - - return null; - }); - }); - it('should fail if webpackConfig.entry is customised', () => { _.set( module.serverless.service,