From e6a8e6201ff5933bdc51351f65511639ff7b3097 Mon Sep 17 00:00:00 2001 From: XCompWiz Date: Thu, 20 Jun 2024 14:12:55 +0300 Subject: [PATCH] fix: Avoid ENOENT on globs with non-existant base paths --- index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 977b284..641b552 100644 --- a/index.js +++ b/index.js @@ -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 }); } @@ -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); } @@ -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 @@ -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.