Skip to content

Commit 432aea0

Browse files
authored
fix(@angular/build): filter Rolldown warnings and disable .d.ts annotation comments in library builder
Suppress noisy Rolldown warnings (`EMPTY_BUNDLE`, `UNUSED_EXTERNAL_IMPORT`, and `THIS_IS_UNDEFINED`) and disable annotation comments in `.d.ts` output bundles to match `ng-packagr` behavior.
1 parent ad48455 commit 432aea0

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ function processRolldownOutput(
300300
return { filesToEmit, moduleIdsByBundle, tslibBundles };
301301
}
302302

303+
/**
304+
* Set of Rolldown warning codes that should be ignored.
305+
*/
306+
const IGNORED_ROLLDOWN_WARNING_CODES: ReadonlySet<string> = new Set([
307+
'EMPTY_BUNDLE',
308+
'UNUSED_EXTERNAL_IMPORT',
309+
'THIS_IS_UNDEFINED',
310+
]);
311+
303312
/**
304313
* Executes a Rolldown bundle build across all provided entry inputs.
305314
*
@@ -341,7 +350,12 @@ async function executeMultiBundle(
341350
resolve: { symlinks: !preserveSymlinks },
342351
checks: { circularDependency: false },
343352
onLog(level, log) {
353+
// Ignore specified warning codes
344354
if (level === 'warn') {
355+
if (log.code && IGNORED_ROLLDOWN_WARNING_CODES.has(log.code)) {
356+
return;
357+
}
358+
345359
warnings.push(log.message);
346360
}
347361
},
@@ -358,7 +372,7 @@ async function executeMultiBundle(
358372
chunkFileNames: `[name]-[hash].${extension}`,
359373
sourcemap,
360374
hoistTransitiveImports: false,
361-
comments: { jsdoc: isDts, legal: true, annotation: true },
375+
comments: { jsdoc: isDts, legal: true, annotation: !isDts },
362376
});
363377

364378
return {

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,47 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
7474
);
7575
});
7676

77+
it('should not log EMPTY_BUNDLE warnings for type-only entry points', async () => {
78+
await harness.writeFile(
79+
'projects/lib/src/public-api.ts',
80+
`export interface OnlyType { id: string; }`,
81+
);
82+
83+
harness.useTarget('build', {
84+
...BASE_OPTIONS,
85+
});
86+
87+
const { result, logs } = await harness.executeOnce();
88+
expect(result?.success).toBeTrue();
89+
expect(logs.some((l) => l.level === 'warn')).toBeFalse();
90+
});
91+
92+
it('should preserve JSDoc comments in .d.ts and annotation comments in .mjs bundles', async () => {
93+
await harness.writeFile(
94+
'projects/lib/src/public-api.ts',
95+
`
96+
function identity<T>(x: T): T { return x; }
97+
/** Public API JSDoc comment */
98+
export const VALUE = /* @__PURE__ */ identity('test');
99+
`,
100+
);
101+
102+
harness.useTarget('build', {
103+
...BASE_OPTIONS,
104+
});
105+
106+
const { result } = await harness.executeOnce();
107+
expect(result?.success).toBeTrue();
108+
109+
const fesmContent = harness.readFile('dist/lib/fesm2022/lib.mjs');
110+
expect(fesmContent).toContain('@__PURE__');
111+
expect(fesmContent).not.toContain('Public API JSDoc comment');
112+
113+
const dtsContent = harness.readFile('dist/lib/types/lib.d.ts');
114+
expect(dtsContent).toContain('Public API JSDoc comment');
115+
expect(dtsContent).not.toContain('@__PURE__');
116+
});
117+
77118
it('should automatically add tslib to dependencies when output chunks import tslib', async () => {
78119
await harness.writeFile(
79120
'projects/lib/src/public-api.ts',

0 commit comments

Comments
 (0)