Skip to content

Commit

Permalink
Update doc about excludeRegex
Browse files Browse the repository at this point in the history
Also:
- dump a message to log how files were excluded (might be good for debugging)
- update unit test to actually match the type of `excludeRegex` from the configuration (which is not a regex but a string)
  • Loading branch information
j0k3r committed Apr 9, 2021
1 parent 2b34778 commit 058c8dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ regex you want to exclude).
# serverless.yml
custom:
webpack:
excludeRegex: /\.ts|test|\.map/
excludeRegex: \.ts|test|\.map
```

#### Keep output directory after packaging
Expand Down
23 changes: 12 additions & 11 deletions lib/packageModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ function zip(directory, name) {
nodir: true
});

const files = this.configuration.excludeRegex
? _.filter(globFiles, f => f.match(this.configuration.excludeRegex) === null)
: globFiles;
if (files.length < globFiles.length && this.options.verbose) {
this.serverless.cli.log(`Excluded ${globFiles.length - files.length} file(s) based on excludeRegex`);
let files = globFiles;
if (this.configuration.excludeRegex) {
files = _.filter(globFiles, f => f.match(this.configuration.excludeRegex) === null);

if (this.options.verbose) {
this.serverless.cli.log(`Excluded ${globFiles.length - files.length} file(s) based on excludeRegex`);
}
}

if (_.isEmpty(files)) {
const error = new this.serverless.classes.Error('Packaging: No files found');

return BbPromise.reject(error);
}

Expand All @@ -52,14 +55,12 @@ function zip(directory, name) {
const artifactFilePath = path.join(this.webpackOutputPath, name);
this.serverless.utils.writeFileDir(artifactFilePath);

const cwd = directory;
const source = files;
const destination = path.relative(cwd, artifactFilePath);
const zipArgs = {
source,
cwd,
destination
source: files,
cwd: directory,
destination: path.relative(directory, artifactFilePath)
};

return new BbPromise((resolve, reject) => {
bestzip(zipArgs)
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion tests/packageModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ describe('packageModules', () => {
it('should reject if no files are found because all files are excluded using regex', () => {
module.configuration = new Configuration({
webpack: {
excludeRegex: /.*/
excludeRegex: '.*'
}
});

Expand Down

0 comments on commit 058c8dc

Please sign in to comment.