From 93b224dfef069f7e90ac80238fe51d0426b60523 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Thu, 1 Oct 2026 08:42:01 +0000 Subject: [PATCH] fix(@angular/build): capture and report Rolldown warnings and errors in library builder Updates `bundleEntryPoints` to capture Rolldown warning logs via `onLog` and bundling errors, returning them to `buildAction` so warnings are logged via the builder logger instead of `console.warn` and errors are properly surfaced. --- .../builders/library/pipeline/build-action.ts | 2 +- .../src/builders/library/pipeline/bundler.ts | 29 +++++++++++++++---- .../library/tests/behavior/build_spec.ts | 20 +++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/packages/angular/build/src/builders/library/pipeline/build-action.ts b/packages/angular/build/src/builders/library/pipeline/build-action.ts index 93bbf0ba59a3..b45e8f3b7b07 100644 --- a/packages/angular/build/src/builders/library/pipeline/build-action.ts +++ b/packages/angular/build/src/builders/library/pipeline/build-action.ts @@ -156,7 +156,7 @@ export async function buildAction(actionContext: BuildActionContext): Promise; + + /** Warning messages emitted during bundling. */ + warnings: string[]; } /** @@ -65,6 +68,9 @@ interface MultiBundleOutput { /** Map of bundle entry names to the set of virtual module IDs included in the bundle. */ moduleIdsByBundle: Map>; + + /** Warning messages emitted during the bundle invocation. */ + warnings: string[]; } /** @@ -85,7 +91,7 @@ export async function bundleEntryPoints( ): Promise { const bundleResults = new Map(); if (items.length === 0) { - return { filesToEmit: [], bundleResults }; + return { filesToEmit: [], bundleResults, warnings: [] }; } const esmEntryPoints: NormalizedEntryPoint[] = []; @@ -122,6 +128,7 @@ export async function bundleEntryPoints( return { filesToEmit: [...esmOutput.filesToEmit, ...dtsOutput.filesToEmit], bundleResults, + warnings: [...esmOutput.warnings, ...dtsOutput.warnings], }; } @@ -228,7 +235,10 @@ function createMemoryFileLoaderPlugin( * @param dir The destination output directory prefix. * @returns The processed multi-bundle output. */ -function processRolldownOutput(output: RolldownOutput['output'], dir: string): MultiBundleOutput { +function processRolldownOutput( + output: RolldownOutput['output'], + dir: string, +): Pick { const filesToEmit: MemoryOutputFile[] = []; const moduleIdsByBundle = new Map>(); const chunksByFileName = new Map(); @@ -317,6 +327,7 @@ async function executeMultiBundle( sourcemap = true; } + const warnings: string[] = []; const bundle = await rolldown({ context: 'this', input, @@ -325,6 +336,11 @@ async function executeMultiBundle( treeshake: false, resolve: { symlinks: !preserveSymlinks }, checks: { circularDependency: false }, + onLog(level, log) { + if (level === 'warn') { + warnings.push(log.message); + } + }, experimental: { attachDebugInfo: 'none', }, @@ -341,7 +357,10 @@ async function executeMultiBundle( comments: { jsdoc: isDts, legal: true, annotation: true }, }); - return processRolldownOutput(output, dir); + return { + ...processRolldownOutput(output, dir), + warnings, + }; } finally { await bundle.close(); } @@ -361,7 +380,7 @@ async function bundleAllEsm( options: NormalizedLibraryOptions, ): Promise { if (entryPoints.length === 0) { - return { filesToEmit: [], moduleIdsByBundle: new Map() }; + return { filesToEmit: [], moduleIdsByBundle: new Map(), warnings: [] }; } return executeMultiBundle( @@ -386,7 +405,7 @@ async function bundleAllDts( options: NormalizedLibraryOptions, ): Promise { if (entryPoints.length === 0) { - return { filesToEmit: [], moduleIdsByBundle: new Map() }; + return { filesToEmit: [], moduleIdsByBundle: new Map(), warnings: [] }; } const dtsSourcemap = options.declarationMap; diff --git a/packages/angular/build/src/builders/library/tests/behavior/build_spec.ts b/packages/angular/build/src/builders/library/tests/behavior/build_spec.ts index a7b3828cbbbc..24ada95cda1f 100644 --- a/packages/angular/build/src/builders/library/tests/behavior/build_spec.ts +++ b/packages/angular/build/src/builders/library/tests/behavior/build_spec.ts @@ -52,5 +52,25 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) => }), ); }); + + it('should log Rolldown bundler warnings', async () => { + await harness.writeFile( + 'projects/lib/src/public-api.ts', + `export function runDynamic(code: string) { return eval(code); }`, + ); + + harness.useTarget('build', { + ...BASE_OPTIONS, + }); + + const { result, logs } = await harness.executeOnce(); + expect(result?.success).toBeTrue(); + expect(logs).toContain( + jasmine.objectContaining({ + level: 'warn', + message: jasmine.stringContaining('eval'), + }), + ); + }); }); });