Skip to content

Commit

Permalink
feat: drastically improved glob matching performance
Browse files Browse the repository at this point in the history
  • Loading branch information
MacMcIrish committed Dec 6, 2018
1 parent 80f9a25 commit 0f21357
Show file tree
Hide file tree
Showing 3 changed files with 2,125 additions and 1,866 deletions.
18 changes: 14 additions & 4 deletions lib/plugins/package/lib/packageService.js
Expand Up @@ -4,6 +4,7 @@ const BbPromise = require('bluebird');
const path = require('path');
const globby = require('globby');
const _ = require('lodash');
const nanomatch = require('nanomatch');

module.exports = {
defaultExcludes: [
Expand Down Expand Up @@ -172,7 +173,7 @@ module.exports = {
},

resolveFilePathsFromPatterns(params, prefix) {
const patterns = ['**'];
const patterns = [];

params.exclude.forEach((pattern) => {
if (pattern.charAt(0) !== '!') {
Expand All @@ -187,14 +188,23 @@ module.exports = {
params.include.forEach((pattern) => {
patterns.push(pattern);
});

return globby(patterns, {
return globby(['**'], {
cwd: path.join(this.serverless.config.servicePath, prefix || ''),
dot: true,
silent: true,
follow: true,
nodir: true,
}).then(filePaths => {
}).then(allFilePaths => {
const filePathStates = allFilePaths.reduce((p, c) => Object.assign(p, { [c]: true }), {});
patterns.forEach(p => {
const exclude = p.startsWith('!');
const pattern = exclude ? p.slice(1) : p;
nanomatch(allFilePaths, [pattern], { dot: true })
.forEach(key => {
filePathStates[key] = !exclude;
});
});
const filePaths = Object.entries(filePathStates).filter(r => r[1] === true).map(r => r[0]);
if (filePaths.length !== 0) return filePaths;
throw new this.serverless.classes.Error('No file matches include / exclude patterns');
});
Expand Down

0 comments on commit 0f21357

Please sign in to comment.