Skip to content

Commit

Permalink
Merge pull request #469 from jaydp17/master
Browse files Browse the repository at this point in the history
Allow to keep the output directory
  • Loading branch information
HyperBrain authored Apr 7, 2019
2 parents 80c08ba + f53b9ea commit b094a9e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,23 @@ from a local folder (e.g. `"mymodule": "file:../../myOtherProject/mymodule"`).
With that you can do test deployments from the local machine with different
module versions or modules before they are published officially.
#### Keep output directory after packaging
You can keep the output directory (defaults to `.webpack`) from being removed
after build.
Just add `keepOutputDirectory: true`
```yaml
# serverless.yml
custom:
webpack:
keepOutputDirectory: true
```
This can be useful, in case you want to upload the source maps to your Error
reporting system, or just have it available for some post processing.
#### Examples
You can find an example setups in the [`examples`][link-examples] folder.
Expand Down
5 changes: 5 additions & 0 deletions lib/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DefaultConfig = {
includeModules: false,
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
};

Expand Down Expand Up @@ -66,6 +67,10 @@ class Configuration {
return this._hasLegacyConfig;
}

get keepOutputDirectory() {
return this._config.keepOutputDirectory;
}

toJSON() {
return _.omitBy(this._config, _.isNil);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Configuration', () => {
includeModules: false,
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
};
});
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Configuration', () => {
includeModules: { forceInclude: ['mod1'] },
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
});
});
Expand All @@ -85,6 +87,7 @@ describe('Configuration', () => {
includeModules: { forceInclude: ['mod1'] },
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
});
});
Expand All @@ -103,6 +106,7 @@ describe('Configuration', () => {
includeModules: { forceInclude: ['mod1'] },
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
});
});
Expand Down
12 changes: 8 additions & 4 deletions lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ module.exports = {
cleanup() {
const webpackOutputPath = this.webpackOutputPath;

this.options.verbose && this.serverless.cli.log(`Remove ${webpackOutputPath}`);

if (this.serverless.utils.dirExistsSync(webpackOutputPath)) {
fse.removeSync(webpackOutputPath);
const keepOutputDirectory = this.configuration.keepOutputDirectory;
if (!keepOutputDirectory) {
this.options.verbose && this.serverless.cli.log(`Remove ${webpackOutputPath}`);
if (this.serverless.utils.dirExistsSync(webpackOutputPath)) {
fse.removeSync(webpackOutputPath);
}
} else {
this.options.verbose && this.serverless.cli.log(`Keeping ${webpackOutputPath}`);
}

return BbPromise.resolve();
Expand Down
18 changes: 17 additions & 1 deletion tests/cleanup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ describe('cleanup', () => {
module = _.assign({
serverless,
options: {},
webpackOutputPath: 'my/Output/Path'
webpackOutputPath: 'my/Output/Path',
configuration: {}
}, baseModule);
});

Expand Down Expand Up @@ -88,4 +89,19 @@ describe('cleanup', () => {
return null;
});
});

it('should keep output dir if keepOutputDir = true', () => {
dirExistsSyncStub.returns(true);
fseMock.removeSync.reset();

const configuredModule = _.assign({}, module, {
configuration: { keepOutputDirectory: true }
});
return expect(configuredModule.cleanup()).to.be.fulfilled
.then(() => {
expect(dirExistsSyncStub).to.not.have.been.calledOnce;
expect(fseMock.removeSync).to.not.have.been.called;
return null;
});
})
});

0 comments on commit b094a9e

Please sign in to comment.