Skip to content

Commit 8978049

Browse files
authored
fix: pass dirs to built-in watcher to avoid issues (#542)
1 parent bcc2b78 commit 8978049

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/hooks/tapAfterCompileToAddDependencies.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ function tapAfterCompileToAddDependencies(
2121
dependencies.files.forEach((file) => {
2222
compilation.fileDependencies.add(file);
2323
});
24-
dependencies.dirs.forEach((dir) => {
25-
compilation.contextDependencies.add(dir);
26-
});
2724
}
2825
});
2926
}

src/watch/InclusiveNodeWatchFileSystem.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
4242
this.removedFiles.clear();
4343

4444
// use standard watch file system for files and missing
45-
const fileWatcher = this.watchFileSystem.watch(
45+
const standardWatcher = this.watchFileSystem.watch(
4646
files,
47-
[],
47+
dirs,
4848
missing,
4949
startTime,
5050
options,
@@ -53,21 +53,21 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
5353
);
5454

5555
this.watcher?.on('change', (file: string) => {
56-
if (!isIgnored(file)) {
56+
if (typeof file === 'string' && !isIgnored(file)) {
5757
this.changedFiles.add(file);
5858
this.removedFiles.delete(file);
5959
}
6060
});
6161
this.watcher?.on('remove', (file: string) => {
62-
if (!isIgnored(file)) {
62+
if (typeof file === 'string' && !isIgnored(file)) {
6363
this.removedFiles.add(file);
6464
this.changedFiles.delete(file);
6565
}
6666
});
6767

6868
// calculate what to change
6969
const prevDirs = Array.from(this.dirsWatchers.keys());
70-
const nextDirs = Array.from(dirs);
70+
const nextDirs = Array.from(this.pluginState.lastDependencies?.dirs || []);
7171
const dirsToUnwatch = prevDirs.filter((prevDir) => !nextDirs.includes(prevDir));
7272
const dirsToWatch = nextDirs.filter(
7373
(nextDir) => !prevDirs.includes(nextDir) && !isIgnored(nextDir)
@@ -135,13 +135,13 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
135135
this.paused = false;
136136

137137
return {
138-
...fileWatcher,
138+
...standardWatcher,
139139
close: () => {
140140
this.changedFiles.clear();
141141
this.removedFiles.clear();
142142

143-
if (fileWatcher) {
144-
fileWatcher.close();
143+
if (standardWatcher) {
144+
standardWatcher.close();
145145
}
146146
this.dirsWatchers.forEach((dirWatcher) => {
147147
dirWatcher?.close();
@@ -151,8 +151,8 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
151151
this.paused = true;
152152
},
153153
pause: () => {
154-
if (fileWatcher) {
155-
fileWatcher.pause();
154+
if (standardWatcher) {
155+
standardWatcher.pause();
156156
}
157157
this.paused = true;
158158
},

0 commit comments

Comments
 (0)