Skip to content

Commit 70c42d9

Browse files
fix: nothing minifying salts no embedded-source hash either
The tap varies a module's hash on the minimizers, so an instance with none of them renamed files it never rewrote — the same defect the chunk hash had.
1 parent bddb808 commit 70c42d9

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/index.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,10 @@ class MinimizerPlugin {
24132413
/** @type {EmbeddedSourceHooks} */
24142414
(/** @type {unknown} */ (compilation.hooks));
24152415

2416+
// Nothing minifying rewrites no embedded source either, and salting the
2417+
// module hash would rename a file this instance never touches.
24162418
if (
2419+
this.minimizers().length > 0 &&
24172420
embeddedHooks.renderEmbeddedSource &&
24182421
embeddedHooks.embeddedSourceHash
24192422
) {

‎test/embedded-source.test.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,45 @@ describe("embedded source", () => {
273273
);
274274
});
275275

276+
it("leaves the module hash alone where `minify` is an empty list", async () => {
277+
/**
278+
* @param {boolean} withPlugin whether to apply the plugin
279+
* @returns {Promise<string[]>} the emitted names
280+
*/
281+
const namesFrom = async (withPlugin) => {
282+
const compiler = getCompiler({
283+
entry: fixture("entry-css.js"),
284+
target: "node",
285+
output: {
286+
path: path.resolve(__dirname, "./dist"),
287+
filename: "[name].[contenthash].js",
288+
},
289+
experiments: { css: true },
290+
module: {
291+
rules: [
292+
{
293+
test: /\.css$/,
294+
type: "css/auto",
295+
parser: { exportType: "text" },
296+
},
297+
],
298+
},
299+
});
300+
301+
if (withPlugin) {
302+
new MinimizerPlugin({ test: /.*/, minify: [] }).apply(compiler);
303+
}
304+
305+
const stats = await compile(compiler);
306+
307+
return Object.keys(stats.compilation.assets).sort();
308+
};
309+
310+
// The embedded-source tap varies the module hash on the minimizers, and an
311+
// instance with none of them rewrites nothing for it to vary on.
312+
expect(await namesFrom(true)).toEqual(await namesFrom(false));
313+
});
314+
276315
it("dispatches by the language a minimizer declares, not by `test`", async () => {
277316
const compiler = getCompiler({
278317
entry: fixture("entry-css.js"),

0 commit comments

Comments
 (0)