Skip to content

Commit

Permalink
Skip compile & packaging if --no-build is set (serverless-heaven#560)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and vicary committed Jan 6, 2021
1 parent b8350e9 commit 927964d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 53 deletions.
1 change: 1 addition & 0 deletions lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions tests/cleanup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ describe('cleanup', () => {
module = _.assign(
{
serverless,
options: {
verbose: true
},
options: {},
webpackOutputPath: 'my/Output/Path'
},
baseModule
Expand Down
51 changes: 1 addition & 50 deletions tests/packageModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ describe('packageModules', () => {
{
serverless,
options: {},
webpackOutputPath: '.webpack',
configuration: new Configuration()
webpackOutputPath: '.webpack'
},
baseModule
);
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 927964d

Please sign in to comment.