Skip to content

Commit 74a8c45

Browse files
committed
add getContext/FileTimestamps to watcher
get timestamps on invalidate fixes webpack#5970
1 parent e9f1ad2 commit 74a8c45

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/WatchIgnorePlugin.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class IgnoringWatchFileSystem {
3636
const ignoredFiles = files.filter(ignored);
3737
const ignoredDirs = dirs.filter(ignored);
3838

39-
this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => {
39+
const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => {
4040
if(err) return callback(err);
4141

4242
ignoredFiles.forEach(path => {
@@ -49,5 +49,24 @@ class IgnoringWatchFileSystem {
4949

5050
callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);
5151
}, callbackUndelayed);
52+
53+
return {
54+
close: () => watcher.close(),
55+
pause: () => watcher.pause(),
56+
getContextTimestamps: () => {
57+
const dirTimestamps = watcher.getContextTimestamps();
58+
ignoredDirs.forEach(path => {
59+
dirTimestamps[path] = 1;
60+
});
61+
return dirTimestamps;
62+
},
63+
getFileTimestamps: () => {
64+
const fileTimestamps = watcher.getFileTimestamps();
65+
ignoredFiles.forEach(path => {
66+
fileTimestamps[path] = 1;
67+
});
68+
return fileTimestamps;
69+
}
70+
};
5271
}
5372
}

lib/Watching.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Watching {
111111

112112
this.compiler.fileTimestamps = fileTimestamps;
113113
this.compiler.contextTimestamps = contextTimestamps;
114-
this.invalidate();
114+
this._invalidate();
115115
}, (fileName, changeTime) => {
116116
this.compiler.hooks.invalid.call(fileName, changeTime);
117117
});
@@ -121,6 +121,14 @@ class Watching {
121121
if(callback) {
122122
this.callbacks.push(callback);
123123
}
124+
if(this.watcher) {
125+
this.compiler.fileTimestamps = this.watcher.getFileTimestamps();
126+
this.compiler.contextTimestamps = this.watcher.getContextTimestamps();
127+
}
128+
return this._invalidate();
129+
}
130+
131+
_invalidate() {
124132
if(this.watcher) {
125133
this.pausedWatcher = this.watcher;
126134
this.watcher.pause();

lib/node/NodeWatchFileSystem.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ class NodeWatchFileSystem {
6464
if(this.watcher) {
6565
this.watcher.pause();
6666
}
67+
},
68+
getFileTimestamps: () => {
69+
if(this.watcher)
70+
return this.watcher.getTimes();
71+
else
72+
return {};
73+
},
74+
getContextTimestamps: () => {
75+
if(this.watcher)
76+
return this.watcher.getTimes();
77+
else
78+
return {};
6779
}
6880
};
6981
}

0 commit comments

Comments
 (0)