Skip to content

Commit f61de66

Browse files
committed
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.
1 parent 3d00c76 commit f61de66

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎packages/angular/build/src/builders/library/pipeline/build-action.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export async function buildAction(actionContext: BuildActionContext): Promise<vo
156156
pendingChangedEsmFiles.clear();
157157
pendingChangedDtsFiles.clear();
158158

159-
for (const warning of warnings) {
159+
for (const warning of [...warnings, ...bundleOutput.warnings]) {
160160
context.logger.warn(warning);
161161
}
162162

‎packages/angular/build/src/builders/library/pipeline/bundler.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export interface BundleEntryPointsOutput {
3434

3535
/** Map of entry point names to their bundle results containing bundled module IDs. */
3636
bundleResults: Map<string, BundleResult>;
37+
38+
/** Warning messages emitted during bundling. */
39+
warnings: string[];
3740
}
3841

3942
/**
@@ -65,6 +68,9 @@ interface MultiBundleOutput {
6568

6669
/** Map of bundle entry names to the set of virtual module IDs included in the bundle. */
6770
moduleIdsByBundle: Map<string, Set<string>>;
71+
72+
/** Warning messages emitted during the bundle invocation. */
73+
warnings: string[];
6874
}
6975

7076
/**
@@ -85,7 +91,7 @@ export async function bundleEntryPoints(
8591
): Promise<BundleEntryPointsOutput> {
8692
const bundleResults = new Map<string, BundleResult>();
8793
if (items.length === 0) {
88-
return { filesToEmit: [], bundleResults };
94+
return { filesToEmit: [], bundleResults, warnings: [] };
8995
}
9096

9197
const esmEntryPoints: NormalizedEntryPoint[] = [];
@@ -122,6 +128,7 @@ export async function bundleEntryPoints(
122128
return {
123129
filesToEmit: [...esmOutput.filesToEmit, ...dtsOutput.filesToEmit],
124130
bundleResults,
131+
warnings: [...esmOutput.warnings, ...dtsOutput.warnings],
125132
};
126133
}
127134

@@ -228,7 +235,10 @@ function createMemoryFileLoaderPlugin(
228235
* @param dir The destination output directory prefix.
229236
* @returns The processed multi-bundle output.
230237
*/
231-
function processRolldownOutput(output: RolldownOutput['output'], dir: string): MultiBundleOutput {
238+
function processRolldownOutput(
239+
output: RolldownOutput['output'],
240+
dir: string,
241+
): Pick<MultiBundleOutput, 'filesToEmit' | 'moduleIdsByBundle'> {
232242
const filesToEmit: MemoryOutputFile[] = [];
233243
const moduleIdsByBundle = new Map<string, Set<string>>();
234244
const chunksByFileName = new Map<string, OutputChunk>();
@@ -317,6 +327,7 @@ async function executeMultiBundle(
317327
sourcemap = true;
318328
}
319329

330+
const warnings: string[] = [];
320331
const bundle = await rolldown({
321332
context: 'this',
322333
input,
@@ -325,6 +336,11 @@ async function executeMultiBundle(
325336
treeshake: false,
326337
resolve: { symlinks: !preserveSymlinks },
327338
checks: { circularDependency: false },
339+
onLog(level, log) {
340+
if (level === 'warn') {
341+
warnings.push(log.message);
342+
}
343+
},
328344
experimental: {
329345
attachDebugInfo: 'none',
330346
},
@@ -341,7 +357,10 @@ async function executeMultiBundle(
341357
comments: { jsdoc: isDts, legal: true, annotation: true },
342358
});
343359

344-
return processRolldownOutput(output, dir);
360+
return {
361+
...processRolldownOutput(output, dir),
362+
warnings,
363+
};
345364
} finally {
346365
await bundle.close();
347366
}
@@ -361,7 +380,7 @@ async function bundleAllEsm(
361380
options: NormalizedLibraryOptions,
362381
): Promise<MultiBundleOutput> {
363382
if (entryPoints.length === 0) {
364-
return { filesToEmit: [], moduleIdsByBundle: new Map() };
383+
return { filesToEmit: [], moduleIdsByBundle: new Map(), warnings: [] };
365384
}
366385

367386
return executeMultiBundle(
@@ -386,7 +405,7 @@ async function bundleAllDts(
386405
options: NormalizedLibraryOptions,
387406
): Promise<MultiBundleOutput> {
388407
if (entryPoints.length === 0) {
389-
return { filesToEmit: [], moduleIdsByBundle: new Map() };
408+
return { filesToEmit: [], moduleIdsByBundle: new Map(), warnings: [] };
390409
}
391410

392411
const dtsSourcemap = options.declarationMap;

‎packages/angular/build/src/builders/library/tests/behavior/build_spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,25 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
5252
}),
5353
);
5454
});
55+
56+
it('should log Rolldown bundler warnings', async () => {
57+
await harness.writeFile(
58+
'projects/lib/src/public-api.ts',
59+
`export function runDynamic(code: string) { return eval(code); }`,
60+
);
61+
62+
harness.useTarget('build', {
63+
...BASE_OPTIONS,
64+
});
65+
66+
const { result, logs } = await harness.executeOnce();
67+
expect(result?.success).toBeTrue();
68+
expect(logs).toContain(
69+
jasmine.objectContaining({
70+
level: 'warn',
71+
message: jasmine.stringContaining('eval'),
72+
}),
73+
);
74+
});
5575
});
5676
});

0 commit comments

Comments
 (0)