From d9641664dcab329963d2f051bfbbf4b6b90adfb4 Mon Sep 17 00:00:00 2001 From: Andrew Meyer Date: Sat, 17 Oct 2015 19:24:04 -0500 Subject: [PATCH] Allow ignoring directories using non-negated string matchers --- index.js | 3 ++- test/recursive-readdir-test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4cc24b2..d6a3000 100644 --- a/index.js +++ b/index.js @@ -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) } } diff --git a/test/recursive-readdir-test.js b/test/recursive-readdir-test.js index 3a524f5..8cac26e 100644 --- a/test/recursive-readdir-test.js +++ b/test/recursive-readdir-test.js @@ -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'