From 927964d3942845fe61faa53a8bd77ccf8ca122e3 Mon Sep 17 00:00:00 2001 From: James Bourne Date: Thu, 7 May 2020 13:31:55 +0100 Subject: [PATCH] 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 | 51 +----------------------------------- 3 files changed, 3 insertions(+), 53 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 8ee6323f3..82871d63c 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 ); @@ -329,54 +328,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', () => {