Skip to content

Commit 96c5d21

Browse files
authored
Merge pull request #16882 from snitin315/limit-identifier-length
fix: limit module readable identifier length in stats
2 parents 7f08e4d + 132ebd5 commit 96c5d21

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/stats/DefaultStatsPrinterPlugin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
1111

1212
const DATA_URI_CONTENT_LENGTH = 16;
13+
const MAX_MODULE_IDENTIFIER_LENGTH = 80;
1314

1415
const plural = (n, singular, plural) => (n === 1 ? singular : plural);
1516

@@ -42,6 +43,19 @@ const getResourceName = resource => {
4243

4344
const getModuleName = name => {
4445
const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
46+
47+
if (resource.length > MAX_MODULE_IDENTIFIER_LENGTH) {
48+
const truncatedResource = `${resource.slice(
49+
0,
50+
Math.min(
51+
resource.length - /* '...(truncated)'.length */ 14,
52+
MAX_MODULE_IDENTIFIER_LENGTH
53+
)
54+
)}...(truncated)`;
55+
56+
return [prefix, getResourceName(truncatedResource)];
57+
}
58+
4559
return [prefix, getResourceName(resource)];
4660
};
4761

test/__snapshots__/StatsTestCases.basictest.js.snap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ built modules 724 bytes [built]
11931193
./templates/baz.js 38 bytes [optional] [built] [code generated]
11941194
./templates/foo.js 38 bytes [optional] [built] [code generated]
11951195
./entry.js 450 bytes [built] [code generated]
1196-
./templates/ lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ namespace object 160 bytes [optional] [built] [code generated]
1196+
./templates/ lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ na...(truncated) 160 bytes [optional] [built] [code generated]
11971197
webpack x.x.x compiled successfully in X ms"
11981198
`;
11991199

@@ -1433,6 +1433,13 @@ asset <CLR=32,BOLD>main.js</CLR> 84 bytes <CLR=32,BOLD>[emitted]</CLR> (name: ma
14331433
webpack x.x.x compiled <CLR=32,BOLD>successfully</CLR> in X ms"
14341434
`;
14351435

1436+
exports[`StatsTestCases should print correct stats for max-external-module-readable-identifier 1`] = `
1437+
"asset main.js 1.45 KiB [emitted] (name: main)
1438+
./index.js 17 bytes [built] [code generated]
1439+
external \\"very-very-very-very-long-external-module-readable-identifier-it-should...(truncated) 42 bytes [built] [code generated]
1440+
webpack x.x.x compiled successfully in X ms"
1441+
`;
1442+
14361443
exports[`StatsTestCases should print correct stats for max-modules 1`] = `
14371444
"asset main.js 5.47 KiB [emitted] (name: main)
14381445
./index.js 181 bytes [built] [code generated]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("test");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import("../../../types").Configuration} */
2+
module.exports = {
3+
mode: "production",
4+
entry: "./index",
5+
externals: {
6+
test: "commonjs very-very-very-very-long-external-module-readable-identifier-it-should-be-truncated"
7+
}
8+
};

0 commit comments

Comments
 (0)