Skip to content

Commit 3b47b57

Browse files
committed
New: Normalize string ignore to array (closes #77)
1 parent f369978 commit 3b47b57

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function globStream(globs, opt) {
1919
}
2020

2121
var ourOpt = extend({}, opt);
22+
var ignore = ourOpt.ignore;
2223

2324
if (typeof ourOpt.cwd !== 'string') {
2425
ourOpt.cwd = process.cwd();
@@ -38,6 +39,14 @@ function globStream(globs, opt) {
3839
if (ourOpt.cwdbase) {
3940
ourOpt.base = ourOpt.cwd;
4041
}
42+
// Normalize string `ignore` to array
43+
if (typeof ignore === 'string') {
44+
ignore = [ignore];
45+
}
46+
// Ensure `ignore` is an array
47+
if (!Array.isArray(ignore)) {
48+
ignore = [];
49+
}
4150

4251
// Only one glob no need to aggregate
4352
if (!Array.isArray(globs)) {
@@ -80,8 +89,10 @@ function globStream(globs, opt) {
8089
return pumpify.obj(aggregate, uniqueStream);
8190

8291
function streamFromPositive(positive) {
83-
var negativeGlobs = negatives.filter(indexGreaterThan(positive.index))
84-
.map(toGlob);
92+
var negativeGlobs = negatives
93+
.filter(indexGreaterThan(positive.index))
94+
.map(toGlob)
95+
.concat(ignore);
8596
return createStream(positive.glob, negativeGlobs, ourOpt);
8697
}
8798
}
@@ -94,9 +105,6 @@ function createStream(ourGlob, negatives, opt) {
94105
var ourOpt = extend({}, opt);
95106
delete ourOpt.root;
96107

97-
if (Array.isArray(opt.ignore)) {
98-
negatives = opt.ignore.concat(negatives);
99-
}
100108
var ourNegatives = negatives.map(resolveNegatives);
101109
ourOpt.ignore = ourNegatives;
102110

test/main.js

+19
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,25 @@ describe('options', function() {
648648

649649
describe('ignore', function() {
650650

651+
it('accepts a string (in addition to array)', function(done) {
652+
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
653+
var glob = join(__dirname, './fixtures/stuff/*.dmc');
654+
var stream = globStream(glob, { cwd: __dirname, ignore: './fixtures/stuff/test.dmc' });
655+
656+
var files = [];
657+
stream.on('error', done);
658+
stream.on('data', function(file) {
659+
should.exist(file);
660+
should.exist(file.path);
661+
files.push(file);
662+
});
663+
stream.on('end', function() {
664+
files.length.should.equal(1);
665+
files[0].path.should.equal(expectedPath);
666+
done();
667+
});
668+
});
669+
651670
it('should support the ignore option instead of negation', function(done) {
652671
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
653672
var glob = join(__dirname, './fixtures/stuff/*.dmc');

0 commit comments

Comments
 (0)