From 81552cc1a024f597dd72da813ae8ef48a751577a Mon Sep 17 00:00:00 2001 From: Pavel Horal Date: Fri, 14 Jun 2024 09:29:52 +0200 Subject: [PATCH] fix: Do not start and end the stream prematurely (#135) --- index.js | 29 +++++++++++++++++------------ test/index.js | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 977b284..f85dbe2 100644 --- a/index.js +++ b/index.js @@ -261,6 +261,7 @@ function globStream(globs, opt) { var stream = new Readable({ highWaterMark: ourOpt.highWaterMark, read: read, + open: open, predestroy: predestroy, }); @@ -277,19 +278,23 @@ function globStream(globs, opt) { walker.on('path', onPath); walker.once('end', onEnd); walker.once('error', onError); - ourGlobs.forEach(function (glob) { - if (isGlob(glob)) { - // We only want to walk the glob-parent directories of any positive glob - // to reduce the amount of files have to check. - if (isPositiveGlob(glob)) { - var base = globParent(glob); - walker.walk(base); + + function open(cb) { + ourGlobs.forEach(function (glob) { + if (isGlob(glob)) { + // We only want to walk the glob-parent directories of any positive glob + // to reduce the amount of files have to check. + if (isPositiveGlob(glob)) { + var base = globParent(glob); + walker.walk(base); + } + } else { + // If the strig is not a glob, we just check for the existence of it. + walker.exists(glob); } - } else { - // If the strig is not a glob, we just check for the existence of it. - walker.exists(glob); - } - }); + }); + cb(); + } function read(cb) { walker.resume(); diff --git a/test/index.js b/test/index.js index 4943370..5fbbbec 100644 --- a/test/index.js +++ b/test/index.js @@ -887,6 +887,22 @@ function suite(moduleName) { done ); }); + + it('does not end prematurely', function (done) { + var gs = globStream(['./non-existent-file'], { cwd: dir, allowEmpty: true }); + + function setup() { + stream.pipeline( + [ + gs, + concat(), + ], + done + ); + } + + setTimeout(setup, 10); + }); }); describe('options', function () {