fix cache invalidation in progress plugin

This commit is contained in:
Ivan Kopeykin 2022-04-15 13:48:17 +03:00
parent a72548f970
commit bb7ed40f46
6 changed files with 34 additions and 1 deletions

View File

@ -331,6 +331,7 @@ class ProgressPlugin {
.getItemCache("counts", null);
let cacheGetPromise;
let invalidatedCache = false;
compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
if (!cacheGetPromise) {
@ -348,10 +349,16 @@ class ProgressPlugin {
}
);
}
invalidatedCache = false;
});
compiler.cache.hooks.store.tap("ProgressPlugin", () => {
invalidatedCache = true;
});
compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
if (compilation.compiler.isChild()) return Promise.resolve();
if (compilation.compiler.isChild() || !invalidatedCache)
return Promise.resolve();
return cacheGetPromise.then(async oldData => {
if (
!oldData ||

View File

@ -0,0 +1 @@
data

View File

@ -0,0 +1,5 @@
import url from "./loader!!";
it("should compile and run", () => {
expect(url).toBe("webpack:///a.txt");
});

View File

@ -0,0 +1,8 @@
/** @type {import("../../../../").LoaderDefinitionFunction} */
module.exports = function () {
const callback = this.async();
this.importModule("./module1", { baseUri: "webpack://" }, (err, exports) => {
if (err) return callback(err);
callback(null, `module.exports = ${JSON.stringify(exports.url)}`);
});
};

View File

@ -0,0 +1,3 @@
const url = new URL("./a.txt", import.meta.url);
export { url }

View File

@ -0,0 +1,9 @@
const webpack = require("../../../../");
/** @type {import("../../../../").Configuration} */
module.exports = {
output: {
assetModuleFilename: "[name][ext]"
},
plugins: [new webpack.ProgressPlugin(() => {})]
};