Skip to content
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