Skip to content

Commit

Permalink
Merge pull request #29 from Ajedi32/match_directories
Browse files Browse the repository at this point in the history
Allow ignoring directories using non-negated string matchers
  • Loading branch information
jergason committed Oct 28, 2015
2 parents 45abf8f + d964166 commit eebc91c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var minimatch = require('minimatch')

function patternMatcher(pattern) {
return function(path, stats) {
return stats.isFile() && minimatch(path, pattern, {matchBase: true})
var minimatcher = new minimatch.Minimatch(pattern, {matchBase: true})
return (!minimatcher.negate || stats.isFile()) && minimatcher.match(path)
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/recursive-readdir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ describe('readdir', function() {
})
})

it('ignores the directories listed in the ignores array', function(done) {
var notExpectedFiles = getAbsolutePaths([
'/testdir/a/a', '/testdir/a/beans'
])

readdir(p.join(__dirname, 'testdir'), ['**/testdir/a'], function(err, list) {
assert.ifError(err)
list.forEach(function(file) {
assert.equal(notExpectedFiles.indexOf(file), -1,
'Failed to ignore file "' + file + '".')
})
done()
})
})

it('supports ignoring files with just basename globbing', function(done) {
var notExpectedFiles = getAbsolutePaths([
'/testdir/d.txt', '/testdir/a/beans'
Expand Down

0 comments on commit eebc91c

Please sign in to comment.