Fix: override wildcard glob pattern (**) in resolveFilePathsFromPatterns by svlapin · Pull Request #5825 · serverless/serverless

What did you implement:

Ability to override wildcard glob pattern by a negative params.include to avoid unnecessary traversal and get much faster glob matching during packaging in some cases.

When globby is provided with an array of patterns, it adds all subsequent negative patterns as ignore option of a particular task (source code here). However, that is not useful when the wildcard comes the last (as it is now) - ignore for the relevant matching task is always empty.

Putting the least specific pattern first makes it possible to override it with a subsequent negative one and avoid unnecessary traversal in e.g. node_modules, .git, etc.

Related to #4263, #5574.

How did you implement it:

Put wildcard pattern ** first in resolveFilePathsFromPatterns.

How can we verify it:

Minimal example

Without this PR:

svl@sergeys-laptop:~/dev/serverless-package-example$ time ./node_modules/.bin/serverless package 
Serverless: Packaging service...

real	1m28,677s
user	1m32,756s
sys	0m1,412s

With this PR:

svl@sergeys-laptop:~/dev/serverless-package-example$ time ./node_modules/.bin/serverless package 
Serverless: Packaging service...

real	0m0,898s
user	0m1,017s
sys	0m0,090s

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO