Skip to content

Commit 9d5f49b

Browse files
committed
fixup! perf(@angular/build): optimize library dts bundling and enable dts tree-shaking
1 parent de1df2c commit 9d5f49b

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ async function executeMultiBundle(
360360
cwd: workspaceRoot,
361361
tsconfig: false,
362362
plugins,
363-
treeshake: isDts ? { moduleSideEffects: false } : false,
363+
treeshake: isDts,
364364
resolve: { symlinks: !preserveSymlinks },
365365
checks: { circularDependency: false, pluginTimings: false },
366366
onLog(level, log) {

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,47 @@ describe('bundleEntryPoints', () => {
127127
);
128128
});
129129

130+
it('should preserve declare global and module augmentations in side-effect .d.ts imports', async () => {
131+
const primaryEntry: NormalizedEntryPoint = {
132+
subpath: '.',
133+
name: 'my-lib',
134+
displayName: 'my-lib',
135+
bundleName: 'my-lib',
136+
entryFilePath: `${workspaceRoot}/src/public-api.ts`,
137+
isPrimary: true,
138+
};
139+
const entryPoints = new Map<string, NormalizedEntryPoint>([['my-lib', primaryEntry]]);
140+
141+
const esmFiles = new Map<string, string>([
142+
[`${workspaceRoot}/src/public-api.js`, 'export const a = 1;'],
143+
]);
144+
const dtsFiles = new Map<string, string>([
145+
[
146+
`${workspaceRoot}/src/globals.d.ts`,
147+
'export {};\ndeclare global {\n interface Window {\n myCustomGlobal: boolean;\n }\n}\n',
148+
],
149+
[
150+
`${workspaceRoot}/src/augment.d.ts`,
151+
"declare module '@angular/core' {\n interface Component {\n augmentedProp?: string;\n }\n}\nexport {};\n",
152+
],
153+
[
154+
`${workspaceRoot}/src/public-api.d.ts`,
155+
'import "./globals.js";\nexport * from "./augment.js";\nexport declare const a = 1;\n',
156+
],
157+
]);
158+
159+
const output = await bundleEntryPoints(
160+
[{ entryPoint: primaryEntry, hasEsmChanges: true, hasDtsChanges: true }],
161+
esmFiles,
162+
dtsFiles,
163+
createOptions(entryPoints),
164+
);
165+
166+
const dtsFile = output.filesToEmit.find((f) => f.path === 'types/my-lib.d.ts');
167+
expect(dtsFile?.contents).toContain('myCustomGlobal');
168+
expect(dtsFile?.contents).toContain('augmentedProp');
169+
});
170+
130171
it('should preserve legal comments in emitted FESM2022 .mjs bundles', async () => {
131172
const primaryEntry: NormalizedEntryPoint = {
132173
subpath: '.',

0 commit comments

Comments
 (0)