Skip to content

Commit d214cda

Browse files
committed
fix: prevent traversing ignored directories
1 parent 65eee8d commit d214cda

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/cli/watch-run.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,24 @@ class GlobFilesTracker {
145145
}
146146

147147
regenerate() {
148-
let watchIgnoreFlat = [];
148+
const watchIgnoreSet = new Set();
149149
for (const pattern of this.watchIgnore) {
150-
watchIgnoreFlat = watchIgnoreFlat.concat(glob.sync(pattern, { dot: true }));
150+
glob.sync(pattern, { dot: true }).forEach(filePath => watchIgnoreSet.add(filePath));
151151
}
152152

153+
const globOpts = {
154+
dot: true,
155+
ignore: {
156+
ignored: () => false,
157+
childrenIgnored: pathToCheck => watchIgnoreSet.has(pathToCheck.relative())
158+
}
159+
};
160+
153161
this.watchFilesSet.clear();
154162
for (const pattern of this.watchFiles) {
155-
glob.sync(pattern, { dot: true }).forEach(pathToCheck => {
156-
for (const watchIgnore of watchIgnoreFlat) {
157-
if (pathToCheck === watchIgnore) {
158-
return;
159-
}
160-
if (pathToCheck.startsWith(watchIgnore + path.sep)) {
161-
return;
162-
}
163+
glob.sync(pattern, globOpts).forEach(pathToCheck => {
164+
if (watchIgnoreSet.has(pathToCheck)) {
165+
return;
163166
}
164167
this.watchFilesSet.add(pathToCheck);
165168
});

0 commit comments

Comments
 (0)