Skip to content

Commit 4fa5d18

Browse files
devversionAndrewKushnir
authored andcommitted
feat(bazel): support bundling .d.ts with code splitting (angular#60321)
Instead of relying on Microsoft's API extractor for `d.ts` bundling, we are switching to Rollup-based `.d.ts` bundling. This allows us to support code spliting, even for `.d.ts` files, allowing for relative imports to be used between entry-points, without ending up duplicating `.d.ts` definitions in two files. This would otherwise cause problems with assignability of types. It also nicely integrates into our existing rollup configuration, and overall simplifies the `ng_package` rule even further! Notably `tsup` also uses this rollup plugin, and it seems to work well. Keep in mind that Microsoft's API extractor is pretty hard to integrate, caused many problems in the past, and isn't capable of code splitting. This aligns our d.ts bundling with the .mjs bundling (great alignment). PR Close angular#60321
1 parent 526268c commit 4fa5d18

File tree

43 files changed

+375
-661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+375
-661
lines changed

adev/shared-docs/utils/analytics.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
declare global {
1010
interface Window {
11-
gtag: (...args: any[]) => void;
11+
gtag?(...args: any[]): void;
1212
}
1313
}
1414

adev/src/content/tools/libraries/angular-package-format.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ The Angular CLI down-levels the bundle to a language level that is supported by
270270

271271
### d.ts bundling / type definition flattening
272272

273-
As of APF v8 it is now preferred to run [API Extractor](https://api-extractor.com), to bundle TypeScript definitions so that the entire API appears in a single file.
273+
As of APF v8, it is recommended to bundle TypeScript definitions.
274+
Bundling of type definitions can significantly speed up compilations for users, especially if there are many individual `.ts` source files in your library.
274275

275-
In prior APF versions each entry point would have a `src` directory next to the .d.ts entry point and this directory contained individual d.ts files matching the structure of the original source code.
276-
While this distribution format is still allowed and supported, it is highly discouraged because it confuses tools like IDEs that then offer incorrect autocompletion, and allows users to depend on deep-import paths which are typically not considered to be public API of a library or a package.
276+
Angular uses [`rollup-plugin-dts`](https://github.com/Swatinem/rollup-plugin-dts) to flatten `.d.ts` files (using `rollup`, similar to how FESM files are created).
277+
278+
Using rollup for `.d.ts` bundling is beneficial as it supports code splitting between entry-points.
279+
For example, consider you have multiple entrypoints relying on the same shared type, a shared `.d.ts` file would be created along with the larger flattened `.d.ts` files.
280+
This is desirable and avoids duplication of types.
277281

278282
### Tslib
279283

goldens/public-api/common/http/index.api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { EnvironmentInjector } from '@angular/core';
88
import { EnvironmentProviders } from '@angular/core';
99
import * as i0 from '@angular/core';
1010
import { InjectionToken } from '@angular/core';
11-
import type { Injector } from '@angular/core';
11+
import { Injector } from '@angular/core';
1212
import { ModuleWithProviders } from '@angular/core';
1313
import { Observable } from 'rxjs';
1414
import { Provider } from '@angular/core';
15-
import type { ResourceRef } from '@angular/core';
16-
import type { Signal } from '@angular/core';
17-
import type { ValueEqualityFn } from '@angular/core';
18-
import type { WritableResource } from '@angular/core';
15+
import { ResourceRef } from '@angular/core';
16+
import { Signal } from '@angular/core';
17+
import { ValueEqualityFn } from '@angular/core';
18+
import { WritableResource } from '@angular/core';
1919
import { XhrFactory } from '@angular/common';
2020

2121
// @public

goldens/public-api/common/index.api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class CommonModule {
101101
// (undocumented)
102102
static ɵinj: i0.ɵɵInjectorDeclaration<CommonModule>;
103103
// (undocumented)
104-
static ɵmod: i0.ɵɵNgModuleDeclaration<CommonModule, never, [typeof i1.NgClass, typeof i2.NgComponentOutlet, typeof i3.NgForOf, typeof i4.NgIf, typeof i5.NgTemplateOutlet, typeof i6.NgStyle, typeof i7.NgSwitch, typeof i7.NgSwitchCase, typeof i7.NgSwitchDefault, typeof i8.NgPlural, typeof i8.NgPluralCase, typeof i9.AsyncPipe, typeof i10.UpperCasePipe, typeof i10.LowerCasePipe, typeof i11.JsonPipe, typeof i12.SlicePipe, typeof i13.DecimalPipe, typeof i13.PercentPipe, typeof i10.TitleCasePipe, typeof i13.CurrencyPipe, typeof i14.DatePipe, typeof i15.I18nPluralPipe, typeof i16.I18nSelectPipe, typeof i17.KeyValuePipe], [typeof i1.NgClass, typeof i2.NgComponentOutlet, typeof i3.NgForOf, typeof i4.NgIf, typeof i5.NgTemplateOutlet, typeof i6.NgStyle, typeof i7.NgSwitch, typeof i7.NgSwitchCase, typeof i7.NgSwitchDefault, typeof i8.NgPlural, typeof i8.NgPluralCase, typeof i9.AsyncPipe, typeof i10.UpperCasePipe, typeof i10.LowerCasePipe, typeof i11.JsonPipe, typeof i12.SlicePipe, typeof i13.DecimalPipe, typeof i13.PercentPipe, typeof i10.TitleCasePipe, typeof i13.CurrencyPipe, typeof i14.DatePipe, typeof i15.I18nPluralPipe, typeof i16.I18nSelectPipe, typeof i17.KeyValuePipe]>;
104+
static ɵmod: i0.ɵɵNgModuleDeclaration<CommonModule, never, [typeof NgClass, typeof NgComponentOutlet, typeof NgForOf, typeof NgIf, typeof NgTemplateOutlet, typeof NgStyle, typeof NgSwitch, typeof NgSwitchCase, typeof NgSwitchDefault, typeof NgPlural, typeof NgPluralCase, typeof AsyncPipe, typeof UpperCasePipe, typeof LowerCasePipe, typeof JsonPipe, typeof SlicePipe, typeof DecimalPipe, typeof PercentPipe, typeof TitleCasePipe, typeof CurrencyPipe, typeof DatePipe, typeof I18nPluralPipe, typeof I18nSelectPipe, typeof KeyValuePipe], [typeof NgClass, typeof NgComponentOutlet, typeof NgForOf, typeof NgIf, typeof NgTemplateOutlet, typeof NgStyle, typeof NgSwitch, typeof NgSwitchCase, typeof NgSwitchDefault, typeof NgPlural, typeof NgPluralCase, typeof AsyncPipe, typeof UpperCasePipe, typeof LowerCasePipe, typeof JsonPipe, typeof SlicePipe, typeof DecimalPipe, typeof PercentPipe, typeof TitleCasePipe, typeof CurrencyPipe, typeof DatePipe, typeof I18nPluralPipe, typeof I18nSelectPipe, typeof KeyValuePipe]>;
105105
}
106106

107107
// @public
@@ -874,16 +874,16 @@ export { PopStateEvent_2 as PopStateEvent }
874874
export const PRECONNECT_CHECK_BLOCKLIST: InjectionToken<(string | string[])[]>;
875875

876876
// @public
877-
export const provideCloudflareLoader: (path: string) => Provider[];
877+
export const provideCloudflareLoader: (path: string) => i0.Provider[];
878878

879879
// @public
880-
export const provideCloudinaryLoader: (path: string) => Provider[];
880+
export const provideCloudinaryLoader: (path: string) => i0.Provider[];
881881

882882
// @public
883-
export const provideImageKitLoader: (path: string) => Provider[];
883+
export const provideImageKitLoader: (path: string) => i0.Provider[];
884884

885885
// @public
886-
export const provideImgixLoader: (path: string) => Provider[];
886+
export const provideImgixLoader: (path: string) => i0.Provider[];
887887

888888
// @public
889889
export function provideNetlifyLoader(path?: string): Provider[];

goldens/public-api/core/index.api.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
import { EnvironmentProviders as EnvironmentProviders_2 } from '@angular/core';
7+
import * as _angular_core from '@angular/core';
88
import { Observable } from 'rxjs';
99
import { SIGNAL } from '@angular/core/primitives/signals';
1010
import { SignalNode } from '@angular/core/primitives/signals';
@@ -116,20 +116,20 @@ export class ApplicationInitStatus {
116116
// (undocumented)
117117
readonly donePromise: Promise<any>;
118118
// (undocumented)
119-
static ɵfac: i0.ɵɵFactoryDeclaration<ApplicationInitStatus, never>;
119+
static ɵfac: ɵɵFactoryDeclaration<ApplicationInitStatus, never>;
120120
// (undocumented)
121-
static ɵprov: i0.ɵɵInjectableDeclaration<ApplicationInitStatus>;
121+
static ɵprov: ɵɵInjectableDeclaration<ApplicationInitStatus>;
122122
}
123123

124124
// @public
125125
export class ApplicationModule {
126126
constructor(appRef: ApplicationRef);
127127
// (undocumented)
128-
static ɵfac: i0.ɵɵFactoryDeclaration<ApplicationModule, never>;
128+
static ɵfac: ɵɵFactoryDeclaration<ApplicationModule, never>;
129129
// (undocumented)
130-
static ɵinj: i0.ɵɵInjectorDeclaration<ApplicationModule>;
130+
static ɵinj: ɵɵInjectorDeclaration<ApplicationModule>;
131131
// (undocumented)
132-
static ɵmod: i0.ɵɵNgModuleDeclaration<ApplicationModule, never, never, never>;
132+
static ɵmod: ɵɵNgModuleDeclaration<ApplicationModule, never, never, never>;
133133
}
134134

135135
// @public
@@ -152,9 +152,9 @@ export class ApplicationRef {
152152
// (undocumented)
153153
whenStable(): Promise<void>;
154154
// (undocumented)
155-
static ɵfac: i0.ɵɵFactoryDeclaration<ApplicationRef, never>;
155+
static ɵfac: ɵɵFactoryDeclaration<ApplicationRef, never>;
156156
// (undocumented)
157-
static ɵprov: i0.ɵɵInjectableDeclaration<ApplicationRef>;
157+
static ɵprov: ɵɵInjectableDeclaration<ApplicationRef>;
158158
}
159159

160160
// @public (undocumented)
@@ -241,9 +241,9 @@ export class Compiler {
241241
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T>;
242242
getModuleId(moduleType: Type<any>): string | undefined;
243243
// (undocumented)
244-
static ɵfac: i0.ɵɵFactoryDeclaration<Compiler, never>;
244+
static ɵfac: ɵɵFactoryDeclaration<Compiler, never>;
245245
// (undocumented)
246-
static ɵprov: i0.ɵɵInjectableDeclaration<Compiler>;
246+
static ɵprov: ɵɵInjectableDeclaration<Compiler>;
247247
}
248248

249249
// @public
@@ -1029,7 +1029,7 @@ export interface InputSignalWithTransform<T, TransformT> extends Signal<T> {
10291029
// (undocumented)
10301030
INPUT_SIGNAL_BRAND_WRITE_TYPE]: TransformT;
10311031
// (undocumented)
1032-
[SIGNAL]: ɵInputSignalNode<T, TransformT>;
1032+
[SIGNAL]: InputSignalNode<T, TransformT>;
10331033
}
10341034

10351035
// @public
@@ -1196,7 +1196,7 @@ export interface ModelOptions {
11961196
// @public
11971197
export interface ModelSignal<T> extends WritableSignal<T>, InputSignal<T>, OutputRef<T> {
11981198
// (undocumented)
1199-
[SIGNAL]: ɵInputSignalNode<T, T>;
1199+
[SIGNAL]: InputSignalNode<T, T>;
12001200
}
12011201

12021202
// @public @deprecated
@@ -1434,9 +1434,9 @@ export class PlatformRef {
14341434
get injector(): Injector;
14351435
onDestroy(callback: () => void): void;
14361436
// (undocumented)
1437-
static ɵfac: i0.ɵɵFactoryDeclaration<PlatformRef, never>;
1437+
static ɵfac: ɵɵFactoryDeclaration<PlatformRef, never>;
14381438
// (undocumented)
1439-
static ɵprov: i0.ɵɵInjectableDeclaration<PlatformRef>;
1439+
static ɵprov: ɵɵInjectableDeclaration<PlatformRef>;
14401440
}
14411441

14421442
// @public
@@ -1459,7 +1459,7 @@ export function provideExperimentalCheckNoChangesForDebug(options: {
14591459
interval?: number;
14601460
useNgZoneOnStable?: boolean;
14611461
exhaustive?: boolean;
1462-
}): EnvironmentProviders_2;
1462+
}): _angular_core.EnvironmentProviders;
14631463

14641464
// @public
14651465
export function provideExperimentalZonelessChangeDetection(): EnvironmentProviders;
@@ -1790,9 +1790,9 @@ export class Testability implements PublicTestability {
17901790
isStable(): boolean;
17911791
whenStable(doneCb: Function, timeout?: number, updateCb?: Function): void;
17921792
// (undocumented)
1793-
static ɵfac: i0.ɵɵFactoryDeclaration<Testability, never>;
1793+
static ɵfac: ɵɵFactoryDeclaration<Testability, never>;
17941794
// (undocumented)
1795-
static ɵprov: i0.ɵɵInjectableDeclaration<Testability>;
1795+
static ɵprov: ɵɵInjectableDeclaration<Testability>;
17961796
}
17971797

17981798
// @public
@@ -1805,9 +1805,9 @@ export class TestabilityRegistry {
18051805
unregisterAllApplications(): void;
18061806
unregisterApplication(token: any): void;
18071807
// (undocumented)
1808-
static ɵfac: i0.ɵɵFactoryDeclaration<TestabilityRegistry, never>;
1808+
static ɵfac: ɵɵFactoryDeclaration<TestabilityRegistry, never>;
18091809
// (undocumented)
1810-
static ɵprov: i0.ɵɵInjectableDeclaration<TestabilityRegistry>;
1810+
static ɵprov: ɵɵInjectableDeclaration<TestabilityRegistry>;
18111811
}
18121812

18131813
// @public

goldens/public-api/core/primitives/di/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
// @public
7+
// @public (undocumented)
88
export function getCurrentInjector(): Injector | undefined | null;
99

1010
// @public

goldens/public-api/core/primitives/event-dispatch/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
// @public (undocumented)
7+
// @public
88
export const Attribute: {
99
JSACTION: "jsaction";
1010
};
@@ -35,7 +35,7 @@ export class EventContract implements UnrenamedEventContract {
3535
// (undocumented)
3636
static MOUSE_SPECIAL_SUPPORT: boolean;
3737
registerDispatcher(dispatcher: Dispatcher, restriction: Restriction): void;
38-
replayEarlyEventInfos(earlyEventInfos: eventInfoLib.EventInfo[]): void;
38+
replayEarlyEventInfos(earlyEventInfos: EventInfo[]): void;
3939
replayEarlyEvents(earlyJsactionData?: EarlyJsactionData | undefined): void;
4040
}
4141

goldens/public-api/core/primitives/signals/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
// @public
7+
// @public (undocumented)
88
export type ComputationFn<S, D> = (source: S, previous?: {
99
source: S;
1010
value: D;
@@ -137,7 +137,7 @@ export function runPostSignalSetFn(): void;
137137
// @public (undocumented)
138138
export function setActiveConsumer(consumer: ReactiveNode | null): ReactiveNode | null;
139139

140-
// @public (undocumented)
140+
// @public
141141
export function setAlternateWeakRefImpl(impl: unknown): void;
142142

143143
// @public (undocumented)

goldens/public-api/forms/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ export class FormsModule {
580580
// (undocumented)
581581
static ɵinj: i0.ɵɵInjectorDeclaration<FormsModule>;
582582
// (undocumented)
583-
static ɵmod: i0.ɵɵNgModuleDeclaration<FormsModule, [typeof i1_2.NgModel, typeof i2_2.NgModelGroup, typeof i3_2.NgForm], never, [typeof i4_2.ɵInternalFormsSharedModule, typeof i1_2.NgModel, typeof i2_2.NgModelGroup, typeof i3_2.NgForm]>;
583+
static ɵmod: i0.ɵɵNgModuleDeclaration<FormsModule, [typeof NgModel, typeof NgModelGroup, typeof NgForm], never, [typeof ɵInternalFormsSharedModule, typeof NgModel, typeof NgModelGroup, typeof NgForm]>;
584584
}
585585

586586
// @public
@@ -847,7 +847,7 @@ export class ReactiveFormsModule {
847847
// (undocumented)
848848
static ɵinj: i0.ɵɵInjectorDeclaration<ReactiveFormsModule>;
849849
// (undocumented)
850-
static ɵmod: i0.ɵɵNgModuleDeclaration<ReactiveFormsModule, [typeof i5_2.FormControlDirective, typeof i6_2.FormGroupDirective, typeof i7_2.FormControlName, typeof i8_2.FormGroupName, typeof i8_2.FormArrayName], never, [typeof i4_2.ɵInternalFormsSharedModule, typeof i5_2.FormControlDirective, typeof i6_2.FormGroupDirective, typeof i7_2.FormControlName, typeof i8_2.FormGroupName, typeof i8_2.FormArrayName]>;
850+
static ɵmod: i0.ɵɵNgModuleDeclaration<ReactiveFormsModule, [typeof FormControlDirective, typeof FormGroupDirective, typeof FormControlName, typeof FormGroupName, typeof FormArrayName], never, [typeof ɵInternalFormsSharedModule, typeof FormControlDirective, typeof FormGroupDirective, typeof FormControlName, typeof FormGroupName, typeof FormArrayName]>;
851851
}
852852

853853
// @public

goldens/public-api/platform-browser-dynamic/index.api.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import { Compiler } from '@angular/core';
88
import { CompilerFactory } from '@angular/core';
99
import { CompilerOptions } from '@angular/core';
10-
import { PlatformRef } from '@angular/core';
11-
import { StaticProvider } from '@angular/core';
10+
import * as i0 from '@angular/core';
1211
import { Version } from '@angular/core';
1312

1413
// @public @deprecated (undocumented)
@@ -18,7 +17,7 @@ export class JitCompilerFactory implements CompilerFactory {
1817
}
1918

2019
// @public (undocumented)
21-
export const platformBrowserDynamic: (extraProviders?: StaticProvider[]) => PlatformRef;
20+
export const platformBrowserDynamic: (extraProviders?: i0.StaticProvider[]) => i0.PlatformRef;
2221

2322
// @public (undocumented)
2423
export const VERSION: Version;

0 commit comments

Comments
 (0)