diff --git a/lib/globule.js b/lib/globule.js index 5a3eeac..5044a75 100644 --- a/lib/globule.js +++ b/lib/globule.js @@ -31,7 +31,12 @@ 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 patt = pattern.slice(1); + if(patt.indexOf('(') === 0){//if next character in the glob is a ( assume grouping pattern, and make a positive match all in group by prefixing with a * + patt = '*'+patt; + } + var filterFn = minimatch.filter(patt, options); + result = _.filter(result, function(filepath) { return !filterFn(filepath); }); diff --git a/test/globule_test.js b/test/globule_test.js index 4b921ea..8e1a5a7 100644 --- a/test/globule_test.js +++ b/test/globule_test.js @@ -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'); @@ -188,7 +189,7 @@ exports['find'] = { 'exclusion': function(test) { test.expect(8); test.deepEqual(globule.find(['!js/*.js']), [], 'solitary exclusion should match nothing'); - test.deepEqual(globule.find(['js/bar.js','!js/bar.js']), [], 'exclusion should negate match'); + test.deepEqual(globule.find(['js/bar.js','!js/bar.js']), [], 'exclusion should negate match'); test.deepEqual(globule.find(['**/*.js', '!js/foo.js']), ['js/bar.js'], 'should omit single file from matched set');