Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore functions within patterns #1236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/grunt/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var processPatterns = function(patterns, fn) {
var result = [];
// Iterate over flattened patterns array.
grunt.util._.flatten(patterns).forEach(function(pattern) {
// If the pattern is a function, ignore it
if (typeof pattern === 'function') {
return;
}
// If the first character is ! it should be omitted
var exclusion = pattern.indexOf('!') === 0;
// If the pattern is an exclusion, remove the !
Expand Down
5 changes: 5 additions & 0 deletions test/grunt/file_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ exports['file.expand*'] = {
test.deepEqual(grunt.file.expand(opts, ['js/foo.js', 'js/bar.js', 'js/baz.js']), ['js/foo.js', 'js/bar.js', 'js/baz.js'], 'non-matching filenames should be returned in result set.');
test.done();
},
'ignore functions within patterns': function(test) {
test.expect(1);
test.deepEqual(grunt.file.expand(['**/*.js', function() {}]), ['js/bar.js', 'js/foo.js'], 'functions passed in with patterns should be ignored.');
test.done();
},
};

exports['file.expandMapping'] = {
Expand Down