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

Update to use micromatch #40

Open
wants to merge 1 commit into
base: master
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
8 changes: 4 additions & 4 deletions lib/globule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var path = require('path');

var _ = require('lodash');
var glob = require('glob');
var minimatch = require('minimatch');
var micromatch = require('micromatch');

// The module.
var globule = exports;
Expand All @@ -31,7 +31,7 @@ function processPatterns(patterns, options, fn) {
}
// The first character is ! (exclusion). Remove any filepaths from the
// result set that match this pattern, sans leading !.
var filterFn = minimatch.filter(pattern.slice(1), options);
var filterFn = micromatch.matcher(pattern.slice(1), options);
result = _.filter(result, function(filepath) {
return !filterFn(filepath);
});
Expand All @@ -46,7 +46,7 @@ function normalizePath(path) {
}

// Match a filepath or filepaths against one or more wildcard patterns. Returns
// all matching filepaths. This behaves just like minimatch.match, but supports
// all matching filepaths. This behaves just like micromatch.match, but supports
// any number of patterns.
globule.match = function(patterns, filepaths, options) {
// Return empty set if either patterns or filepaths was omitted.
Expand All @@ -58,7 +58,7 @@ globule.match = function(patterns, filepaths, options) {
if (patterns.length === 0 || filepaths.length === 0) { return []; }
// Return all matching filepaths.
return processPatterns(patterns, options, function(pattern) {
return minimatch.match(filepaths, pattern, options || {});
return micromatch.match(filepaths, pattern, options);
});
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"dependencies": {
"glob": "~7.1.1",
"lodash": "~4.17.4",
"minimatch": "~3.0.2"
"micromatch": "^3.1.4"
}
}
3 changes: 2 additions & 1 deletion test/globule_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ exports['match'] = {
test.done();
},
'exclusion': function(test) {
test.expect(5);
test.expect(6);
test.deepEqual(globule.match(['!*.js'], ['foo.js', 'bar.js']), [], 'solitary exclusion should match nothing');
test.deepEqual(globule.match(['*.js', '!*.js'], ['foo.js', 'bar.js']), [], 'exclusion should cancel match');
test.deepEqual(globule.match(['*.js', '!(foo|bar).js'], ['foo.js', 'bar.js', 'baz.js']), ['baz.js'], 'group exlusion should be handled correctly');
test.deepEqual(globule.match(['*.js', '!f*.js'], ['foo.js', 'bar.js', 'baz.js']),
['bar.js', 'baz.js'],
'partial exclusion should partially cancel match');
Expand Down