Skip to content

Commit

Permalink
fix: prevent traversing ignored directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Jan 30, 2025
1 parent 65eee8d commit d214cda
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/cli/watch-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,24 @@ 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) {
if (pathToCheck === watchIgnore) {
return;
}
if (pathToCheck.startsWith(watchIgnore + path.sep)) {
return;
}
glob.sync(pattern, globOpts).forEach(pathToCheck => {
if (watchIgnoreSet.has(pathToCheck)) {
return;
}
this.watchFilesSet.add(pathToCheck);
});
Expand Down

0 comments on commit d214cda

Please sign in to comment.