Skip to content

Commit

Permalink
fix: Do not start and end the stream prematurely (gulpjs#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelhoral committed Jun 14, 2024
1 parent 7782659 commit f022a1c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
36 changes: 23 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,32 @@ 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);

var started = false;

function start() {
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);
}
});
});
}

function read(cb) {
walker.resume();
if (!started) {
started = true;
start();
} else {
walker.resume();
}
cb();
}

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

0 comments on commit f022a1c

Please sign in to comment.