Skip to content

Commit 2d3483c

Browse files
yocontraphated
authored andcommitted
Fix: Use stream-combiner to propagate errors
1 parent ba024b5 commit 2d3483c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var es = require('event-stream');
2+
var Combine = require('stream-combiner');
23
var glob = require('glob');
34
var minimatch = require('minimatch');
45
var path = require('path');
@@ -67,9 +68,7 @@ module.exports = us = {
6768

6869
// stream to check against negatives
6970
var filterStream = es.map(function(filename, cb) {
70-
var matcha = function(pattern) {
71-
return isMatch(filename, pattern);
72-
};
71+
var matcha = isMatch.bind(null, filename);
7372
if (!negatives.every(matcha)) return cb(null, filename); // pass
7473
cb(); // ignore
7574
});
@@ -96,10 +95,7 @@ module.exports = us = {
9695
});
9796

9897
// then just pipe them to a single stream and return it
99-
var aggregate = es.pause();
100-
streams.forEach(function(gStream){
101-
gStream.pipe(aggregate);
102-
});
98+
var aggregate = Combine.apply(null, streams);
10399
return aggregate;
104100
}
105101
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"dependencies": {
1010
"glob": "~3.2.7",
1111
"event-stream": "~3.0.18",
12-
"minimatch": "~0.2.12"
12+
"minimatch": "~0.2.12",
13+
"stream-combiner": "0.0.2"
1314
},
1415
"devDependencies": {
1516
"mocha": "*",

test/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,23 @@ describe('glob-stream', function() {
9191
});
9292
});
9393

94+
it('should return a file name stream from two globs and a negative', function(done) {
95+
var stream = gs.create(["./fixtures/*.coffee", "./fixtures/whatsgoingon/*.coffee"], {cwd: __dirname});
96+
should.exist(stream);
97+
stream.on('error', function(err) {
98+
throw err;
99+
});
100+
stream.on('data', function(file) {
101+
should.exist(file);
102+
should.exist(file.path);
103+
should.exist(file.base);
104+
should.exist(file.cwd);
105+
String(file.cwd).should.equal(__dirname);
106+
String(file.base).should.equal("fixtures/");
107+
String(file.path).should.equal(join(__dirname, "./fixtures/test.coffee"));
108+
done();
109+
});
110+
});
111+
94112
});
95113
});

0 commit comments

Comments
 (0)