Skip to content

Commit 56131e3

Browse files
committed
Improves performance of glob exclusions by avoiding extra glob IO
- IO is not necessary for exclusions because they exclude file paths that have already been discovered. Using `file.match` / `minimatch` is sufficient. - adds optional `excludeFn` callback to `processPatterns`. If provided, it will be called instead of `fn` for exclusion patterns.
1 parent 8755cdd commit 56131e3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/grunt/file.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ file.setBase = function() {
3838

3939
// Process specified wildcard glob patterns or filenames against a
4040
// callback, excluding and uniquing files in the result set.
41-
var processPatterns = function(patterns, fn) {
41+
var processPatterns = function(patterns, fn, exclusionFn) {
42+
if (typeof exclusionFn === 'undefined') { exclusionFn = fn; }
4243
// Filepaths to return.
4344
var result = [];
4445
// Iterate over flattened patterns array.
@@ -48,7 +49,7 @@ var processPatterns = function(patterns, fn) {
4849
// If the pattern is an exclusion, remove the !
4950
if (exclusion) { pattern = pattern.slice(1); }
5051
// Find all matching files for this pattern.
51-
var matches = fn(pattern);
52+
var matches = (exclusion ? exclusionFn : fn)(pattern, result);
5253
if (exclusion) {
5354
// If an exclusion, remove matching files.
5455
result = grunt.util._.difference(result, matches);
@@ -104,6 +105,8 @@ file.expand = function() {
104105
var matches = processPatterns(patterns, function(pattern) {
105106
// Find all matching files for this pattern.
106107
return file.glob.sync(pattern, globOptions);
108+
}, function(pattern, resultsThusFar) {
109+
return file.match(options, [pattern], resultsThusFar);
107110
});
108111
// Filter result set?
109112
if (options.filter) {

0 commit comments

Comments
 (0)