@@ -208,20 +208,12 @@ export async function executeBuild(
208208 if ( options . budgets ) {
209209 const compatStats = generateBudgetStats ( metafile , initialFiles ) ;
210210 budgetFailures = [ ...checkBudgets ( options . budgets , compatStats , true ) ] ;
211- if ( budgetFailures . length > 0 ) {
212- const errors = budgetFailures
213- . filter ( ( failure ) => failure . severity === 'error' )
214- . map ( ( { message } ) => message ) ;
215- const warnings = budgetFailures
216- . filter ( ( failure ) => failure . severity !== 'error' )
217- . map ( ( { message } ) => message ) ;
218-
219- await printWarningsAndErrorsToConsoleAndAddToResult (
220- context ,
221- executionResult ,
222- warnings ,
223- errors ,
224- ) ;
211+ for ( const { message, severity } of budgetFailures ) {
212+ if ( severity === 'error' ) {
213+ executionResult . addError ( message ) ;
214+ } else {
215+ executionResult . addWarning ( message ) ;
216+ }
225217 }
226218 }
227219
@@ -234,7 +226,7 @@ export async function executeBuild(
234226 // Check metafile for CommonJS module usage if optimizing scripts
235227 if ( optimizationOptions . scripts ) {
236228 const messages = checkCommonJSModules ( metafile , options . allowedCommonJsDependencies ) ;
237- await logMessages ( context , { warnings : messages } ) ;
229+ executionResult . addWarnings ( messages ) ;
238230 }
239231
240232 // Copy assets
@@ -255,12 +247,10 @@ export async function executeBuild(
255247
256248 // Perform i18n translation inlining if enabled
257249 let prerenderedRoutes : string [ ] ;
258- let errors : string [ ] ;
259- let warnings : string [ ] ;
260250 if ( i18nOptions . shouldInline ) {
261251 const result = await inlineI18n ( options , executionResult , initialFiles ) ;
262- errors = result . errors ;
263- warnings = result . warnings ;
252+ executionResult . addErrors ( result . errors ) ;
253+ executionResult . addWarnings ( result . warnings ) ;
264254 prerenderedRoutes = result . prerenderedRoutes ;
265255 } else {
266256 const result = await executePostBundleSteps (
@@ -272,15 +262,13 @@ export async function executeBuild(
272262 i18nOptions . hasDefinedSourceLocale ? i18nOptions . sourceLocale : undefined ,
273263 ) ;
274264
275- errors = result . errors ;
276- warnings = result . warnings ;
265+ executionResult . addErrors ( result . errors ) ;
266+ executionResult . addWarnings ( result . warnings ) ;
277267 prerenderedRoutes = result . prerenderedRoutes ;
278268 executionResult . outputFiles . push ( ...result . additionalOutputFiles ) ;
279269 executionResult . assetFiles . push ( ...result . additionalAssets ) ;
280270 }
281271
282- await printWarningsAndErrorsToConsoleAndAddToResult ( context , executionResult , warnings , errors ) ;
283-
284272 if ( prerenderOptions ) {
285273 executionResult . addOutputFile (
286274 'prerendered-routes.json' ,
@@ -307,6 +295,8 @@ export async function executeBuild(
307295 estimatedTransferSizes ,
308296 ) ;
309297
298+ await logMessages ( context , executionResult ) ;
299+
310300 // Write metafile if stats option is enabled
311301 if ( options . stats ) {
312302 executionResult . addOutputFile (
@@ -318,20 +308,3 @@ export async function executeBuild(
318308
319309 return executionResult ;
320310}
321-
322- async function printWarningsAndErrorsToConsoleAndAddToResult (
323- context : BuilderContext ,
324- executionResult : ExecutionResult ,
325- warnings : string [ ] ,
326- errors : string [ ] ,
327- ) : Promise < void > {
328- const errorMessages = errors . map ( ( text ) => ( { text, location : null } ) ) ;
329- if ( errorMessages . length ) {
330- executionResult . addErrors ( errorMessages ) ;
331- }
332-
333- await logMessages ( context , {
334- errors : errorMessages ,
335- warnings : warnings . map ( ( text ) => ( { text, location : null } ) ) ,
336- } ) ;
337- }
0 commit comments