Merge pull request #16882 from snitin315/limit-identifier-length

fix: limit module readable identifier length in stats
This commit is contained in:
Sean Larkin 2023-04-12 07:36:56 -07:00 committed by GitHub
commit 96c5d21a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 1 deletions

View File

@ -10,6 +10,7 @@
/** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
const DATA_URI_CONTENT_LENGTH = 16;
const MAX_MODULE_IDENTIFIER_LENGTH = 80;
const plural = (n, singular, plural) => (n === 1 ? singular : plural);
@ -42,6 +43,19 @@ const getResourceName = resource => {
const getModuleName = name => {
const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
if (resource.length > MAX_MODULE_IDENTIFIER_LENGTH) {
const truncatedResource = `${resource.slice(
0,
Math.min(
resource.length - /* '...(truncated)'.length */ 14,
MAX_MODULE_IDENTIFIER_LENGTH
)
)}...(truncated)`;
return [prefix, getResourceName(truncatedResource)];
}
return [prefix, getResourceName(resource)];
};

View File

@ -1193,7 +1193,7 @@ built modules 724 bytes [built]
./templates/baz.js 38 bytes [optional] [built] [code generated]
./templates/foo.js 38 bytes [optional] [built] [code generated]
./entry.js 450 bytes [built] [code generated]
./templates/ lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ namespace object 160 bytes [optional] [built] [code generated]
./templates/ lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ na...(truncated) 160 bytes [optional] [built] [code generated]
webpack x.x.x compiled successfully in X ms"
`;
@ -1433,6 +1433,13 @@ asset <CLR=32,BOLD>main.js</CLR> 84 bytes <CLR=32,BOLD>[emitted]</CLR> (name: ma
webpack x.x.x compiled <CLR=32,BOLD>successfully</CLR> in X ms"
`;
exports[`StatsTestCases should print correct stats for max-external-module-readable-identifier 1`] = `
"asset main.js 1.45 KiB [emitted] (name: main)
./index.js 17 bytes [built] [code generated]
external \\"very-very-very-very-long-external-module-readable-identifier-it-should...(truncated) 42 bytes [built] [code generated]
webpack x.x.x compiled successfully in X ms"
`;
exports[`StatsTestCases should print correct stats for max-modules 1`] = `
"asset main.js 5.47 KiB [emitted] (name: main)
./index.js 181 bytes [built] [code generated]

View File

@ -0,0 +1 @@
require("test");

View File

@ -0,0 +1,8 @@
/** @type {import("../../../types").Configuration} */
module.exports = {
mode: "production",
entry: "./index",
externals: {
test: "commonjs very-very-very-very-long-external-module-readable-identifier-it-should-be-truncated"
}
};