Skip to content

Commit 9d36482

Browse files
pavelhoralphated
andauthored
fix: Do not start and end the stream prematurely (#136)
--------- Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
1 parent 74a1bee commit 9d36482

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ function globStream(globs, opt) {
261261
var stream = new Readable({
262262
highWaterMark: ourOpt.highWaterMark,
263263
read: read,
264+
open: open,
264265
predestroy: predestroy,
265266
});
266267

@@ -277,19 +278,23 @@ function globStream(globs, opt) {
277278
walker.on('path', onPath);
278279
walker.once('end', onEnd);
279280
walker.once('error', onError);
280-
ourGlobs.forEach(function (glob) {
281-
if (isGlob(glob)) {
282-
// We only want to walk the glob-parent directories of any positive glob
283-
// to reduce the amount of files have to check.
284-
if (isPositiveGlob(glob)) {
285-
var base = globParent(glob);
286-
walker.walk(base);
281+
282+
function open(cb) {
283+
ourGlobs.forEach(function (glob) {
284+
if (isGlob(glob)) {
285+
// We only want to walk the glob-parent directories of any positive glob
286+
// to reduce the amount of files have to check.
287+
if (isPositiveGlob(glob)) {
288+
var base = globParent(glob);
289+
walker.walk(base);
290+
}
291+
} else {
292+
// If the string is not a glob, we just check for the existence of it.
293+
walker.exists(glob);
287294
}
288-
} else {
289-
// If the strig is not a glob, we just check for the existence of it.
290-
walker.exists(glob);
291-
}
292-
});
295+
});
296+
cb();
297+
}
293298

294299
function read(cb) {
295300
walker.resume();

test/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,31 @@ function suite(moduleName) {
887887
done
888888
);
889889
});
890+
891+
it('does not end prematurely', function (done) {
892+
var gs = globStream(['./fixtures/*.js'], { cwd: dir });
893+
894+
function delayed() {
895+
stream.pipeline(
896+
[
897+
gs,
898+
new stream.Transform({
899+
objectMode: true,
900+
transform: function(data, enc, cb) {
901+
if (typeof enc === 'function') {
902+
cb = enc;
903+
}
904+
cb(null, data);
905+
}
906+
}),
907+
concat(),
908+
],
909+
done
910+
);
911+
}
912+
913+
setTimeout(delayed, 10);
914+
});
890915
});
891916

892917
describe('options', function () {

0 commit comments

Comments
 (0)