Skip to content

Commit

Permalink
update chunk to files mapping when deleting assets
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 15, 2020
1 parent 27796db commit 63ba54c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/Compilation.js
Expand Up @@ -2995,6 +2995,12 @@ This prevents using hashes of each other and should be avoided.`
}
}
}
// TODO If this becomes a performance problem
// store a reverse mapping from asset to chunk
for (const chunk of this.chunks) {
chunk.files.delete(file);
chunk.auxiliaryFiles.delete(file);
}
}

getAssets() {
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/assets/delete-asset/chunk2.js
@@ -0,0 +1,3 @@
/**! Chunk */

console.log("Fail");
5 changes: 5 additions & 0 deletions test/configCases/assets/delete-asset/index.js
Expand Up @@ -6,4 +6,9 @@ it("should fail loading a deleted asset", async () => {
code: "ENOENT"
})
);
await expect(import("./chunk2.js")).rejects.toEqual(
expect.objectContaining({
code: "ENOENT"
})
);
});
20 changes: 19 additions & 1 deletion test/configCases/assets/delete-asset/webpack.config.js
@@ -1,4 +1,4 @@
const { Compilation } = require("../../../../");
const { Compilation, BannerPlugin } = require("../../../../");
const TerserPlugin = require("terser-webpack-plugin");

/** @type {import("../../../../").Configuration} */
Expand All @@ -16,8 +16,20 @@ module.exports = {
},
devtool: "source-map",
plugins: [
new BannerPlugin({
banner: "Test"
}),
compiler => {
compiler.hooks.compilation.tap("Test", compilation => {
compilation.hooks.processAssets.tap(
{
name: "Test",
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
},
() => {
compilation.deleteAsset("chunk2_js.bundle0.js");
}
);
compilation.hooks.processAssets.tap(
{
name: "Test",
Expand Down Expand Up @@ -51,6 +63,12 @@ module.exports = {
expect(compilation.getAsset("chunk_js.bundle0.js.map")).toBe(
undefined
);
expect(compilation.getAsset("chunk2_js.bundle0.js")).toBe(
undefined
);
expect(compilation.getAsset("chunk2_js.bundle0.js.map")).toBe(
undefined
);
expect(compilation.getAsset("LICENSES.txt")).not.toBe(undefined);
}
);
Expand Down

0 comments on commit 63ba54c

Please sign in to comment.