Skip to content

Commit

Permalink
refactor errorDetails logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Feb 28, 2022
1 parent 8667b68 commit 9bed6ee
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions lib/stats/DefaultStatsFactoryPlugin.js
Expand Up @@ -811,24 +811,32 @@ const SIMPLE_EXTRACTORS = {
},
errors: (object, compilation, context, options, factory) => {
const { type, cachedGetErrors } = context;
const rawErrors = factory.create(
const rawErrors = cachedGetErrors(compilation);
const factorizedErrors = factory.create(
`${type}.errors`,
cachedGetErrors(compilation),
context
);
let filtered = 0;
if (options.errorDetails === "auto" && rawErrors.length >= 3) {
filtered = rawErrors
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
}
if (
options.errorDetails === true ||
!Number.isFinite(options.errorsSpace)
) {
object.errors = rawErrors;
object.errors = factorizedErrors;
if (filtered) object.filteredErrorDetailsCount = filtered;
return;
}
const [errors, filtered] = errorsSpaceLimit(
rawErrors,
const [errors, filteredBySpace] = errorsSpaceLimit(
factorizedErrors,
options.errorsSpace
);
object.filteredErrorDetailsCount = filtered + filteredBySpace;
object.errors = errors;
if (filtered) object.filteredErrorDetailsCount = filtered;
},
errorsCount: (object, compilation, { cachedGetErrors }) => {
object.errorsCount = countWithChildren(compilation, c =>
Expand All @@ -842,19 +850,26 @@ const SIMPLE_EXTRACTORS = {
cachedGetWarnings(compilation),
context
);
let filtered = 0;
if (options.errorDetails === "auto") {
filtered = cachedGetWarnings(compilation)
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
}
if (
options.errorDetails === true ||
!Number.isFinite(options.warningsSpace)
) {
object.warnings = rawWarnings;
if (filtered) object.filteredWarningDetailsCount = filtered;
return;
}
const [warnings, filtered] = errorsSpaceLimit(
const [warnings, filteredBySpace] = errorsSpaceLimit(
rawWarnings,
options.warningsSpace
);
object.filteredWarningDetailsCount = filtered + filteredBySpace;
object.warnings = warnings;
if (filtered) object.filteredWarningDetailsCount = filtered;
},
warningsCount: (
object,
Expand All @@ -879,35 +894,6 @@ const SIMPLE_EXTRACTORS = {
});
});
},
errorDetails: (
object,
compilation,
{ cachedGetErrors, cachedGetWarnings },
{ errorDetails, errors, warnings }
) => {
if (errorDetails === "auto") {
if (warnings) {
const warnings = cachedGetWarnings(compilation);
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) {
const filtered = object.filteredErrorDetailsCount || 0;
object.filteredErrorDetailsCount =
filtered +
errors
.map(e => typeof e !== "string" && e.details)
.filter(Boolean).length;
}
}
}
},
children: (object, compilation, context, options, factory) => {
const { type } = context;
object.children = factory.create(
Expand Down

0 comments on commit 9bed6ee

Please sign in to comment.