fix: `assetsByChunkName` should also included assets from `chunk.auxiliaryFiles` (#19921)

This commit is contained in:
hai-x 2025-09-24 01:30:13 +08:00 committed by GitHub
parent 19f5693ebc
commit ae52500e95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 54 additions and 1 deletions

View File

@ -805,7 +805,10 @@ const SIMPLE_EXTRACTORS = {
}
object.assetsByChunkName = {};
for (const [file, chunks] of compilationFileToChunks) {
for (const [file, chunks] of [
...compilationFileToChunks,
...compilationAuxiliaryFileToChunks
]) {
for (const chunk of chunks) {
const name = chunk.name;
if (!name) continue;

View File

@ -609,6 +609,12 @@ You can also set it to 'none' to disable any default behavior. Learn more: https
webpack x.x.x compiled with 1 warning in X ms"
`;
exports[`StatsTestCases should print correct stats for chunk-assets 1`] = `
"asset bundle.js X bytes [emitted] (name: main) 1 related asset
./index.js X bytes [built] [code generated]
webpack x.x.x compiled successfully in X ms"
`;
exports[`StatsTestCases should print correct stats for chunk-module-id-range 1`] = `
"PublicPath: auto
asset main1.js X KiB [emitted] (name: main1)

View File

@ -0,0 +1 @@
export default "foo"

View File

@ -0,0 +1,20 @@
"use strict";
module.exports = {
/**
* @param {import("../../../").Stats} stats stats
*/
validate(stats) {
const _stats = stats.toJson({
assets: true
});
let chunks;
expect((chunks = Object.keys(_stats.assetsByChunkName))).toHaveLength(1);
const chunk = chunks[0];
expect(_stats.assetsByChunkName[chunk]).toHaveLength(2);
expect(_stats.assetsByChunkName[chunk]).toEqual([
"bundle.js",
"bundle.js.map"
]);
}
};

View File

@ -0,0 +1,11 @@
"use strict";
/** @type {import("../../../").Configuration} */
module.exports = {
mode: "production",
entry: "./index",
devtool: "source-map",
output: {
filename: "bundle.js"
}
};

View File

@ -1,6 +1,9 @@
"use strict";
module.exports = {
/**
* @param {import("../../../").MultiStats} stats stats
*/
validate(stats) {
for (let i = 0; i < stats.stats.length; i += 2) {
const a = stats.stats[i].compilation.hash;

View File

@ -10,6 +10,9 @@ const hashedFiles = {
};
module.exports = {
/**
* @param {import("../../../").MultiStats} stats stats
*/
validate(stats) {
for (let i = 0; i < 4; i += 2) {
const a = stats.stats[i + 0].toJson({

View File

@ -1,6 +1,9 @@
"use strict";
module.exports = {
/**
* @param {import("../../../").MultiStats} stats stats
*/
validate(stats) {
for (const item of stats.stats) {
const json = item.toJson({ assets: true });

View File

@ -1,6 +1,9 @@
"use strict";
module.exports = {
/**
* @param {import("../../../").Stats} stats stats
*/
validate(stats) {
expect(stats.compilation.modules.size).toBe(246);
}