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: Avoid ENOENT on globs with non-existant base paths #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ function walkdir() {
ee.end = function () {
queue.kill();
};
ee.prewalk = prewalk;
ee.walk = walk;
ee.exists = exists;
ee.resolve = resolve;

function prewalk(path) {
queue.push({ action: 'prewalk', path: path });
}

function walk(path) {
queue.push({ action: 'walk', path: path });
}
Expand Down Expand Up @@ -88,6 +93,10 @@ function walkdir() {
}

function onAction(data, cb) {
if (data.action === 'prewalk') {
return fs.stat(data.path, onPrewalkStat);
}

if (data.action === 'walk') {
return fs.readdir(data.path, readdirOpts, onReaddir);
}
Expand All @@ -100,6 +109,17 @@ function walkdir() {
return resolveSymlink(data.path, cb);
}

function onPrewalkStat(err, stat) {
if (err) {
// Ignore errors but also don't walk this route
return cb();
}

ee.walk(data.path);

cb();
}

function onStat(err, stat) {
if (err) {
// Ignore errors but also don't emit the path
Expand Down Expand Up @@ -283,7 +303,7 @@ function globStream(globs, opt) {
// to reduce the amount of files have to check.
if (isPositiveGlob(glob)) {
var base = globParent(glob);
walker.walk(base);
walker.prewalk(base);
}
} else {
// If the strig is not a glob, we just check for the existence of it.
Expand Down