Skip to content

Commit

Permalink
New: Normalize string ignore to array (closes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Feb 21, 2017
1 parent f369978 commit 3b47b57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function globStream(globs, opt) {
}

var ourOpt = extend({}, opt);
var ignore = ourOpt.ignore;

if (typeof ourOpt.cwd !== 'string') {
ourOpt.cwd = process.cwd();
Expand All @@ -38,6 +39,14 @@ function globStream(globs, opt) {
if (ourOpt.cwdbase) {
ourOpt.base = ourOpt.cwd;
}
// Normalize string `ignore` to array
if (typeof ignore === 'string') {
ignore = [ignore];
}
// Ensure `ignore` is an array
if (!Array.isArray(ignore)) {
ignore = [];
}

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

function streamFromPositive(positive) {
var negativeGlobs = negatives.filter(indexGreaterThan(positive.index))
.map(toGlob);
var negativeGlobs = negatives
.filter(indexGreaterThan(positive.index))
.map(toGlob)
.concat(ignore);
return createStream(positive.glob, negativeGlobs, ourOpt);
}
}
Expand All @@ -94,9 +105,6 @@ function createStream(ourGlob, negatives, opt) {
var ourOpt = extend({}, opt);
delete ourOpt.root;

if (Array.isArray(opt.ignore)) {
negatives = opt.ignore.concat(negatives);
}
var ourNegatives = negatives.map(resolveNegatives);
ourOpt.ignore = ourNegatives;

Expand Down
19 changes: 19 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,25 @@ describe('options', function() {

describe('ignore', function() {

it('accepts a string (in addition to array)', function(done) {
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
var glob = join(__dirname, './fixtures/stuff/*.dmc');
var stream = globStream(glob, { cwd: __dirname, ignore: './fixtures/stuff/test.dmc' });

var files = [];
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
files.push(file);
});
stream.on('end', function() {
files.length.should.equal(1);
files[0].path.should.equal(expectedPath);
done();
});
});

it('should support the ignore option instead of negation', function(done) {
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
var glob = join(__dirname, './fixtures/stuff/*.dmc');
Expand Down

0 comments on commit 3b47b57

Please sign in to comment.