Skip to content

Commit 81552cc

Browse files
committed
fix: Do not start and end the stream prematurely (#135)
1 parent 7782659 commit 81552cc

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-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 strig 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,22 @@ function suite(moduleName) {
887887
done
888888
);
889889
});
890+
891+
it('does not end prematurely', function (done) {
892+
var gs = globStream(['./non-existent-file'], { cwd: dir, allowEmpty: true });
893+
894+
function setup() {
895+
stream.pipeline(
896+
[
897+
gs,
898+
concat(),
899+
],
900+
done
901+
);
902+
}
903+
904+
setTimeout(setup, 10);
905+
});
890906
});
891907

892908
describe('options', function () {

0 commit comments

Comments
 (0)