From f884492be539368d06b8af6e08d5d2485723a103 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Thu, 30 Jan 2025 18:54:13 +0100 Subject: [PATCH] fix: prevent traversing ignored directories --- lib/cli/watch-run.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.js index 3d9eef6aeb..7b23d0fab2 100644 --- a/lib/cli/watch-run.js +++ b/lib/cli/watch-run.js @@ -145,15 +145,23 @@ class GlobFilesTracker { } regenerate() { - let watchIgnoreFlat = []; + const watchIgnoreSet = new Set(); for (const pattern of this.watchIgnore) { - watchIgnoreFlat = watchIgnoreFlat.concat(glob.sync(pattern, { dot: true })); + glob.sync(pattern, { dot: true }).forEach(filePath => watchIgnoreSet.add(filePath)); } + const globOpts = { + dot: true, + ignore: { + ignored: () => false, + childrenIgnored: pathToCheck => watchIgnoreSet.has(pathToCheck.relative()) + } + }; + this.watchFilesSet.clear(); for (const pattern of this.watchFiles) { - glob.sync(pattern, { dot: true }).forEach(pathToCheck => { - for (const watchIgnore of watchIgnoreFlat) { + glob.sync(pattern, globOpts).forEach(pathToCheck => { + for (const watchIgnore of watchIgnoreSet) { if (pathToCheck === watchIgnore) { return; }