From 9bed6ee1ffd40c95003299f08781deca41af253c Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Mon, 28 Feb 2022 21:35:43 +0300 Subject: [PATCH] refactor errorDetails logic --- lib/stats/DefaultStatsFactoryPlugin.js | 58 ++++++++++---------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 9c784461f63..2fe68906aa8 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -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 => @@ -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, @@ -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(