Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/angular/build/src/builders/library/pipeline/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ function processRolldownOutput(
return { filesToEmit, moduleIdsByBundle, tslibBundles };
}

/**
* Set of Rolldown warning codes that should be ignored.
*/
const IGNORED_ROLLDOWN_WARNING_CODES: ReadonlySet<string> = new Set([
'EMPTY_BUNDLE',
'UNUSED_EXTERNAL_IMPORT',
'THIS_IS_UNDEFINED',
]);

/**
* Executes a Rolldown bundle build across all provided entry inputs.
*
Expand Down Expand Up @@ -341,7 +350,12 @@ async function executeMultiBundle(
resolve: { symlinks: !preserveSymlinks },
checks: { circularDependency: false },
onLog(level, log) {
// Ignore specified warning codes
if (level === 'warn') {
if (log.code && IGNORED_ROLLDOWN_WARNING_CODES.has(log.code)) {
return;
}

warnings.push(log.message);
}
},
Expand All @@ -358,7 +372,7 @@ async function executeMultiBundle(
chunkFileNames: `[name]-[hash].${extension}`,
sourcemap,
hoistTransitiveImports: false,
comments: { jsdoc: isDts, legal: true, annotation: true },
comments: { jsdoc: isDts, legal: true, annotation: !isDts },
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
);
});

it('should not log EMPTY_BUNDLE warnings for type-only entry points', async () => {
await harness.writeFile(
'projects/lib/src/public-api.ts',
`export interface OnlyType { id: string; }`,
);

harness.useTarget('build', {
...BASE_OPTIONS,
});

const { result, logs } = await harness.executeOnce();
expect(result?.success).toBeTrue();
expect(logs.some((l) => l.level === 'warn')).toBeFalse();
});

it('should preserve JSDoc comments in .d.ts and annotation comments in .mjs bundles', async () => {
await harness.writeFile(
'projects/lib/src/public-api.ts',
`
function identity<T>(x: T): T { return x; }
/** Public API JSDoc comment */
export const VALUE = /* @__PURE__ */ identity('test');
`,
);

harness.useTarget('build', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

const fesmContent = harness.readFile('dist/lib/fesm2022/lib.mjs');
expect(fesmContent).toContain('@__PURE__');
expect(fesmContent).not.toContain('Public API JSDoc comment');

const dtsContent = harness.readFile('dist/lib/types/lib.d.ts');
expect(dtsContent).toContain('Public API JSDoc comment');
Comment thread
alan-agius4 marked this conversation as resolved.
expect(dtsContent).not.toContain('@__PURE__');
});

it('should automatically add tslib to dependencies when output chunks import tslib', async () => {
await harness.writeFile(
'projects/lib/src/public-api.ts',
Expand Down
Loading