Skip to content

Commit

Permalink
Adds the ability to specify an exclideFiles glob
Browse files Browse the repository at this point in the history
This permits you to tell serverless to ignore files that have
similar names to the route handlers. So ignore index.test.js or
index.ts.

This fixes serverless-heaven#433 and serverless-heaven#405

It makes life better for lots of folks :-)
  • Loading branch information
designfrontier committed Jan 5, 2019
1 parent ffc70bc commit 6a4634a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const _ = require('lodash');

/**
/**
* Plugin defaults
*/
const DefaultConfig = {
Expand Down Expand Up @@ -50,6 +50,10 @@ class Configuration {
return this._config.includeModules;
}

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

get packager() {
return this._config.packager;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ module.exports = {
const getEntryExtension = fileName => {
const files = glob.sync(`${fileName}.*`, {
cwd: this.serverless.config.servicePath,
nodir: true
nodir: true,
ignore: this.configuration.excludeFiles ? this.configuration.excludeFiles : undefined
});

this.serverless.cli.log(files);

if (_.isEmpty(files)) {
// If we cannot find any handler we should terminate with an error
throw new this.serverless.classes.Error(`No matching handler found for '${fileName}' in '${this.serverless.config.servicePath}'. Check your service definition.`);
Expand Down Expand Up @@ -117,7 +120,7 @@ module.exports = {
return BbPromise.reject(err);
}
}

// Intermediate function to handle async webpack config
const processConfig = _config => {
this.webpackConfig = _config;
Expand Down Expand Up @@ -220,7 +223,7 @@ module.exports = {

return BbPromise.resolve();
};

// Webpack config can be a Promise, If it's a Promise wait for resolved config object.
if (this.webpackConfig && _.isFunction(this.webpackConfig.then)) {
return BbPromise.resolve(this.webpackConfig.then(config => processConfig(config)));
Expand Down

0 comments on commit 6a4634a

Please sign in to comment.