Skip to content

Commit

Permalink
support filteredErrorDetailsCount/filteredWarningDetailsCount
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Feb 28, 2022
1 parent 022cabe commit d2ec06f
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 45 deletions.
1 change: 1 addition & 0 deletions cspell.json
Expand Up @@ -161,6 +161,7 @@
"opencollective",
"opensource",
"opuuus",
"overlimit",
"overridable",
"overridables",
"parallelism",
Expand Down
104 changes: 74 additions & 30 deletions lib/stats/DefaultStatsFactoryPlugin.js
Expand Up @@ -811,10 +811,24 @@ const SIMPLE_EXTRACTORS = {
},
errors: (object, compilation, context, options, factory) => {
const { type, cachedGetErrors } = context;
object.errors = errorsSpaceLimit(
factory.create(`${type}.errors`, cachedGetErrors(compilation), context),
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 @@ -823,14 +837,24 @@ const SIMPLE_EXTRACTORS = {
},
warnings: (object, compilation, context, options, factory) => {
const { type, cachedGetWarnings } = context;
object.warnings = errorsSpaceLimit(
factory.create(
`${type}.warnings`,
cachedGetWarnings(compilation),
context
),
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 @@ -864,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;
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 @@ -1782,16 +1812,18 @@ const spaceLimited = (
};

const errorsSpaceLimit = (errors, max) => {
if (!Number.isFinite(max)) return errors;
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;
const { details, ...rest } = error;
return { details: "", ...rest };
});

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;

Expand All @@ -1802,23 +1834,35 @@ const errorsSpaceLimit = (errors, max) => {
const len = splitted.length;
fullLength += len;
if (fullLength > max) {
result = errors.slice(0, i);
const { details, ...rest } = errors[i++];
result = i > 0 ? errors.slice(0, i) : [];
const overlimit = fullLength - max;
result.push({
details: splitted.slice(0, len - (fullLength - max)).join("\n"),
...rest
...errors[i++],
details: `${splitted
.slice(0, len - overlimit)
.join("\n")}\n+${overlimit} hidden line${
overlimit === 1 ? "" : "s"
}`
});
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++) {
const { details, ...rest } = errors[i];
if (details === undefined) result.push(errors[i]);
result.push({ details: "", ...rest });
if (errors[i].details === undefined) result.push(errors[i]);
result.push({ ...errors[i], details: "" });
}
break;
}
}
}

return result;
return [result, filtered];
};

const assetGroup = (children, assets) => {
Expand Down
100 changes: 88 additions & 12 deletions test/__snapshots__/StatsTestCases.basictest.js.snap
Expand Up @@ -989,34 +989,110 @@ webpack x.x.x compiled successfully in X ms"

exports[`StatsTestCases should print correct stats for errors-space-error 1`] = `
"assets by status 84 bytes [cached] 1 asset
./loader.js!./index.js 1 bytes [built] [code generated] [1 error]
./loader.js!./index.js 1 bytes [built] [code generated] [2 errors]
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error
Error: loader error
loader error1
webpack x.x.x compiled with 1 error in X ms
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error2
2 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack x.x.x compiled with 2 errors in X ms
assets by status 84 bytes [cached] 1 asset
./loader.js!./index.js 1 bytes [built] [code generated] [1 error]
./loader.js!./index.js 1 bytes [built] [code generated] [2 errors]
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error
loader error1
webpack x.x.x compiled with 1 error in X ms
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error2
2 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack x.x.x compiled with 2 errors in X ms
assets by status 84 bytes [cached] 1 asset
./loader.js!./index.js 1 bytes [built] [code generated] [1 error]
./loader.js!./index.js 1 bytes [built] [code generated] [2 errors]
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error
Error: loader error
at Object.<anonymous>.module.exports (Xdir/errors-space-error/loader.js:4:17)
loader error1
stack1
+2 hidden lines
webpack x.x.x compiled with 1 error in X ms"
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error2
1 error has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack x.x.x compiled with 2 errors in X ms
assets by status 84 bytes [cached] 1 asset
./loader.js!./index.js 1 bytes [built] [code generated] [2 errors]
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error1
stack1
stack2
+1 hidden line
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error2
1 error has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack x.x.x compiled with 2 errors in X ms
assets by status 84 bytes [cached] 1 asset
./loader.js!./index.js 1 bytes [built] [code generated] [2 errors]
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error1
stack1
stack2
stack3
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error2
1 error has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack x.x.x compiled with 2 errors in X ms
assets by status 84 bytes [cached] 1 asset
./loader.js!./index.js 1 bytes [built] [code generated] [2 errors]
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error1
stack1
stack2
stack3
ERROR in ./index.js (./loader.js!./index.js)
Module Error (from ./loader.js):
loader error2
stack1
stack2
webpack x.x.x compiled with 2 errors in X ms"
`;

exports[`StatsTestCases should print correct stats for exclude-with-loader 1`] = `
Expand Down
7 changes: 6 additions & 1 deletion test/statsCases/errors-space-error/loader.js
@@ -1,6 +1,11 @@
"use strict";

module.exports = function (content) {
this.emitError(new Error("loader error"));
let error = new Error("loader error1");
error.stack = "stack1\nstack2\nstack3";
this.emitError(error);
error = new Error("loader error2");
error.stack = "stack1\nstack2";
this.emitError(error);
return content;
}
28 changes: 26 additions & 2 deletions test/statsCases/errors-space-error/webpack.config.js
Expand Up @@ -4,15 +4,39 @@ module.exports = [
entry: "./loader!./index.js",
mode: "production",
stats: {
errorsSpace: 2,
errorsSpace: 0,
errors: true
}
},
{
entry: "./loader!./index.js",
mode: "production",
stats: {
errorsSpace: 0,
errorsSpace: 2, // 2 errors (2 errors without details)
errors: true
}
},
{
entry: "./loader!./index.js",
mode: "production",
stats: {
errorsSpace: 3, // 2 errors (2 errors without details)
errors: true
}
},
{
entry: "./loader!./index.js",
mode: "production",
stats: {
errorsSpace: 4, // 2 errors + 2 lines (2 errors, one with full details)
errors: true
}
},
{
entry: "./loader!./index.js",
mode: "production",
stats: {
errorsSpace: 5, // 2 errors + 3 lines (2 errors, one with full details, one partial)
errors: true
}
},
Expand Down

0 comments on commit d2ec06f

Please sign in to comment.