8000 Merge pull request #29 from Ajedi32/match_directories · jergason/recursive-readdir@eebc91c · GitHub
[go: up one dir, main page]

Skip to content

Commit eebc91c

Browse files
committed
Merge pull request #29 from Ajedi32/match_directories
Allow ignoring directories using non-negated string matchers
2 parents 45abf8f + d964166 commit eebc91c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var minimatch = require('minimatch')
44

55
function patternMatcher(pattern) {
66
return function(path, stats) {
7-
return stats.isFile() && minimatch(path, pattern, {matchBase: true})
7+
var minimatcher = new minimatch.Minimatch(pattern, {matchBase: true})
8+
return (!minimatcher.negate || stats.isFile()) && minimatcher.match(path)
89
}
910
}
1011

test/recursive-readdir-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ describe('readdir', function() {
4141
})
4242
})
4343

44+
it('ignores the directories listed in the ignores array', function(done) {
45+
var notExpectedFiles = getAbsolutePaths([
46+
'/testdir/a/a', '/testdir/a/beans'
47+
])
48+
49+
readdir(p.join(__dirname, 'testdir'), ['**/testdir/a'], function(err, list) {
50+
assert.ifError(err)
51+
list.forEach(function(file) {
52+
assert.equal(notExpectedFiles.indexOf(file), -1,
53+
'Failed to ignore file "' + file + '".')
54+
})
55+
done()
56+
})
57+
})
58+
4459
it('supports ignoring files with just basename globbing', function(done) {
4560
var notExpectedFiles = getAbsolutePaths([
4661
'/testdir/d.txt', '/testdir/a/beans'

0 commit comments

Comments
 (0)
0