Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not start and end the stream prematurely (#135) #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ function globStream(globs, opt) {
var stream = new Readable({
highWaterMark: ourOpt.highWaterMark,
read: read,
open: open,
predestroy: predestroy,
});

Expand All @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down