track changes and removals correctly

purge filesystem correctly
This commit is contained in:
Tobias Koppers 2021-05-19 16:18:37 +02:00
parent 11e71ed26b
commit 8e9daad216
6 changed files with 32 additions and 20 deletions

View File

@ -230,6 +230,8 @@ class Compiler {
this.fileTimestamps = undefined;
/** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
this.contextTimestamps = undefined;
/** @type {number} */
this.fsStartTime = undefined;
/** @type {ResolverFactory} */
this.resolverFactory = new ResolverFactory();
@ -952,6 +954,7 @@ ${other}`);
childCompiler.removedFiles = this.removedFiles;
childCompiler.fileTimestamps = this.fileTimestamps;
childCompiler.contextTimestamps = this.contextTimestamps;
childCompiler.fsStartTime = this.fsStartTime;
childCompiler.cache = this.cache;
childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`;

View File

@ -902,7 +902,7 @@ class NormalModule extends Module {
assetsInfo: undefined
};
const startTime = Date.now();
const startTime = compilation.compiler.fsStartTime || Date.now();
return this.doBuild(options, compilation, resolver, fs, err => {
// if we have an error mark module as failed and exit

View File

@ -90,9 +90,13 @@ class Watching {
this.running = true;
if (this.watcher) {
this.pausedWatcher = this.watcher;
this.lastWatcherStartTime = Date.now();
this.watcher.pause();
this.watcher = null;
} else if (!this.lastWatcherStartTime) {
this.lastWatcherStartTime = Date.now();
}
this.compiler.fsStartTime = Date.now();
this._mergeWithCollected(
changedFiles ||
(this.pausedWatcher &&
@ -104,6 +108,19 @@ class Watching {
this.pausedWatcher.getAggregatedRemovals &&
this.pausedWatcher.getAggregatedRemovals()))
);
this.compiler.modifiedFiles = this._collectedChangedFiles;
this._collectedChangedFiles = undefined;
this.compiler.removedFiles = this._collectedRemovedFiles;
this._collectedRemovedFiles = undefined;
this.compiler.fileTimestamps =
fileTimeInfoEntries ||
(this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
this.compiler.contextTimestamps =
contextTimeInfoEntries ||
(this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
const run = () => {
if (this.compiler.idle) {
return this.compiler.cache.endIdle(err => {
@ -120,19 +137,6 @@ class Watching {
run();
});
}
this.compiler.modifiedFiles = this._collectedChangedFiles;
this._collectedChangedFiles = undefined;
this.compiler.removedFiles = this._collectedRemovedFiles;
this._collectedRemovedFiles = undefined;
this.compiler.fileTimestamps =
fileTimeInfoEntries ||
(this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
this.compiler.contextTimestamps =
contextTimeInfoEntries ||
(this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
this.invalid = false;
this._invalidReported = false;
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
@ -295,7 +299,7 @@ class Watching {
files,
dirs,
missing,
this.startTime,
this.lastWatcherStartTime,
this.watchOptions,
(
err,
@ -309,6 +313,7 @@ class Watching {
this.compiler.removedFiles = undefined;
this.compiler.fileTimestamps = undefined;
this.compiler.contextTimestamps = undefined;
this.compiler.fsStartTime = undefined;
return this.handler(err);
}
this._invalidate(
@ -357,6 +362,7 @@ class Watching {
}
if (this.running) {
this._mergeWithCollected(changedFiles, removedFiles);
this.invalid = true;
} else {
this._go(
@ -399,6 +405,7 @@ class Watching {
this.compiler.removedFiles = undefined;
this.compiler.fileTimestamps = undefined;
this.compiler.contextTimestamps = undefined;
this.compiler.fsStartTime = undefined;
const shutdown = () => {
this.compiler.cache.shutdown(err => {
this.compiler.hooks.watchClose.call();

View File

@ -26,7 +26,7 @@
"schema-utils": "^3.0.0",
"tapable": "^2.1.1",
"terser-webpack-plugin": "^5.1.1",
"watchpack": "^2.0.0",
"watchpack": "^2.2.0",
"webpack-sources": "^2.1.1"
},
"peerDependenciesMeta": {

2
types.d.ts vendored
View File

@ -1830,6 +1830,7 @@ declare class Compiler {
removedFiles: Set<string>;
fileTimestamps: Map<string, null | FileSystemInfoEntry | "ignore">;
contextTimestamps: Map<string, null | FileSystemInfoEntry | "ignore">;
fsStartTime: number;
resolverFactory: ResolverFactory;
infrastructureLogger: any;
options: WebpackOptionsNormalized;
@ -11453,6 +11454,7 @@ declare abstract class Watching {
running: boolean;
watcher?: null | Watcher;
pausedWatcher?: null | Watcher;
lastWatcherStartTime?: number;
watch(
files: Iterable<string>,
dirs: Iterable<string>,

View File

@ -6740,10 +6740,10 @@ wast-loader@^1.11.0:
dependencies:
wabt "1.0.0-nightly.20180421"
watchpack@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.1.1.tgz#e99630550fca07df9f90a06056987baa40a689c7"
integrity sha512-Oo7LXCmc1eE1AjyuSBmtC3+Wy4HcV8PxWh2kP6fOl8yTlNS7r0K9l1ao2lrrUza7V39Y3D/BbJgY8VeSlc5JKw==
watchpack@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.2.0.tgz#47d78f5415fe550ecd740f99fe2882323a58b1ce"
integrity sha512-up4YAn/XHgZHIxFBVCdlMiWDj6WaLKpwVeGQk2I5thdYxF/KmF0aaz6TfJZ/hfl1h/XlcDr7k1KH7ThDagpFaA==
dependencies:
glob-to-regexp "^0.4.1"
graceful-fs "^4.1.2"