Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: limit module readable identifier length in stats #16882

Merged
merged 5 commits into from Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/stats/DefaultStatsPrinterPlugin.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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)];
};

Expand Down
9 changes: 8 additions & 1 deletion test/__snapshots__/StatsTestCases.basictest.js.snap
Expand Up @@ -1195,7 +1195,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"
`;

Expand Down Expand Up @@ -1435,6 +1435,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]
Expand Down
@@ -0,0 +1 @@
require("test");
@@ -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"
}
};