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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature errorsSpace, warningsSpace #15450

Merged
merged 10 commits into from Apr 19, 2023
1 change: 1 addition & 0 deletions cspell.json
Expand Up @@ -161,6 +161,7 @@
"opencollective",
"opensource",
"opuuus",
"overlimit",
vankop marked this conversation as resolved.
Show resolved Hide resolved
"overridable",
"overridables",
"parallelism",
Expand Down
8 changes: 8 additions & 0 deletions declarations/WebpackOptions.d.ts
Expand Up @@ -2456,6 +2456,10 @@ export interface StatsOptions {
* Add errors count.
*/
errorsCount?: boolean;
/**
* Space to display errors (value is in number of lines).
*/
errorsSpace?: number;
/**
* Please use excludeModules instead.
*/
Expand Down Expand Up @@ -2640,6 +2644,10 @@ export interface StatsOptions {
* Suppress listing warnings that match the specified filters (they will still be counted). Filters can be Strings, RegExps or Functions.
*/
warningsFilter?: WarningFilterTypes;
/**
* Space to display warnings (value is in number of lines).
*/
warningsSpace?: number;
}
/**
* Options for the watcher.
Expand Down
102 changes: 94 additions & 8 deletions lib/stats/DefaultStatsFactoryPlugin.js
Expand Up @@ -811,11 +811,24 @@ const SIMPLE_EXTRACTORS = {
},
errors: (object, compilation, context, options, factory) => {
const { type, cachedGetErrors } = context;
object.errors = factory.create(
const rawErrors = factory.create(
`${type}.errors`,
cachedGetErrors(compilation),
context
);
if (
options.errorDetails === true ||
!Number.isFinite(options.errorsSpace)
) {
object.errors = rawErrors;
return;
}
const [errors, filtered] = errorsSpaceLimit(
rawErrors,
options.errorsSpace
);
object.errors = errors;
if (filtered) object.filteredErrorDetailsCount = filtered;
},
errorsCount: (object, compilation, { cachedGetErrors }) => {
object.errorsCount = countWithChildren(compilation, c =>
Expand All @@ -824,11 +837,24 @@ const SIMPLE_EXTRACTORS = {
},
warnings: (object, compilation, context, options, factory) => {
const { type, cachedGetWarnings } = context;
object.warnings = factory.create(
const rawWarnings = factory.create(
`${type}.warnings`,
cachedGetWarnings(compilation),
context
);
if (
options.errorDetails === true ||
!Number.isFinite(options.warningsSpace)
) {
object.warnings = rawWarnings;
return;
}
const [warnings, filtered] = errorsSpaceLimit(
rawWarnings,
options.warningsSpace
);
object.warnings = warnings;
if (filtered) object.filteredWarningDetailsCount = filtered;
},
warningsCount: (
object,
Expand Down Expand Up @@ -862,16 +888,22 @@ const SIMPLE_EXTRACTORS = {
if (errorDetails === "auto") {
if (warnings) {
const warnings = cachedGetWarnings(compilation);
object.filteredWarningDetailsCount = warnings
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
const filtered = object.filteredWarningDetailsCount || 0;
vankop marked this conversation as resolved.
Show resolved Hide resolved
object.filteredWarningDetailsCount =
filtered +
warnings
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
}
if (errors) {
const errors = cachedGetErrors(compilation);
if (errors.length >= 3) {
object.filteredErrorDetailsCount = errors
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
const filtered = object.filteredErrorDetailsCount || 0;
object.filteredErrorDetailsCount =
filtered +
errors
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
}
}
}
Expand Down Expand Up @@ -1779,6 +1811,60 @@ const spaceLimited = (
};
};

const errorsSpaceLimit = (errors, max) => {
let filtered = 0;
// Can not fit into limit
// print only messages
if (errors.length >= max)
return [
errors.map(error => {
if (error.details === undefined) return error;
filtered++;
return { ...error, details: "" };
}),
filtered
];
let fullLength = errors.length;
let result = errors;

let i = 0;
for (; i < errors.length; i++) {
if (errors[i].details) {
const splitted = errors[i].details.split("\n");
const len = splitted.length;
fullLength += len;
if (fullLength > max) {
result = i > 0 ? errors.slice(0, i) : [];
const overlimit = fullLength - max;
result.push({
...errors[i++],
details: `${splitted
.slice(0, len - overlimit)
.join("\n")}\n+${overlimit} hidden line${
overlimit === 1 ? "" : "s"
}`
vankop marked this conversation as resolved.
Show resolved Hide resolved
});
filtered = errors.length - i;
for (; i < errors.length; i++) {
if (errors[i].details === undefined) result.push(errors[i]);
result.push({ ...errors[i], details: "" });
}
break;
} else if (fullLength === max) {
result = errors.slice(0, ++i);
filtered = errors.length - i;
for (; i < errors.length; i++) {
if (errors[i].details === undefined) result.push(errors[i]);
result.push({ ...errors[i], details: "" });
}
break;
}
}
}

return [result, filtered];
};

const assetGroup = (children, assets) => {
let size = 0;
for (const asset of children) {
Expand Down
9 changes: 9 additions & 0 deletions lib/stats/DefaultStatsPresetPlugin.js
Expand Up @@ -47,6 +47,8 @@ const NAMED_PRESETS = {
orphanModules: true,
runtimeModules: true,
exclude: false,
errorsSpace: Infinity,
warningsSpace: Infinity,
modulesSpace: Infinity,
chunkModulesSpace: Infinity,
assetsSpace: Infinity,
Expand All @@ -73,6 +75,8 @@ const NAMED_PRESETS = {
logging: true,
runtimeModules: true,
exclude: false,
errorsSpace: 1000,
warningsSpace: 1000,
modulesSpace: 1000,
assetsSpace: 1000,
reasonsSpace: 1000
Expand All @@ -82,6 +86,8 @@ const NAMED_PRESETS = {
version: true,
timings: true,
modules: true,
errorsSpace: 0,
warningsSpace: 0,
modulesSpace: 0,
assets: true,
assetsSpace: 0,
Expand All @@ -95,15 +101,18 @@ const NAMED_PRESETS = {
all: false,
errors: true,
errorsCount: true,
errorsSpace: Infinity,
moduleTrace: true,
logging: "error"
},
"errors-warnings": {
all: false,
errors: true,
errorsCount: true,
errorsSpace: Infinity,
warnings: true,
warningsCount: true,
warningsSpace: Infinity,
logging: "warn"
},
summary: {
Expand Down
2 changes: 1 addition & 1 deletion schemas/WebpackOptions.check.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions schemas/WebpackOptions.json
Expand Up @@ -4619,6 +4619,10 @@
"description": "Add errors count.",
"type": "boolean"
},
"errorsSpace": {
"description": "Space to display errors (value is in number of lines).",
"type": "number"
},
"exclude": {
"description": "Please use excludeModules instead.",
"cli": {
Expand Down Expand Up @@ -4851,6 +4855,10 @@
"$ref": "#/definitions/WarningFilterTypes"
}
]
},
"warningsSpace": {
"description": "Space to display warnings (value is in number of lines).",
"type": "number"
}
}
},
Expand Down
26 changes: 26 additions & 0 deletions test/__snapshots__/Cli.basictest.js.snap
Expand Up @@ -8244,6 +8244,19 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"stats-errors-space": Object {
"configs": Array [
Object {
"description": "Space to display errors (value is in number of lines).",
"multiple": false,
"path": "stats.errorsSpace",
"type": "number",
},
],
"description": "Space to display errors (value is in number of lines).",
"multiple": false,
"simpleType": "number",
},
"stats-exclude-assets": Object {
"configs": Array [
Object {
Expand Down Expand Up @@ -8937,6 +8950,19 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"stats-warnings-space": Object {
"configs": Array [
Object {
"description": "Space to display warnings (value is in number of lines).",
"multiple": false,
"path": "stats.warningsSpace",
"type": "number",
},
],
"description": "Space to display warnings (value is in number of lines).",
"multiple": false,
"simpleType": "number",
},
"target": Object {
"configs": Array [
Object {
Expand Down