Skip to content

Commit 7079a2d

Browse files
committed
fixup! perf(@angular/build): cache transformed configuration in TypeScript compilation
1 parent 5e55682 commit 7079a2d

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/angular/build/src/tools/angular/compilation/typescript-compilation.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface TransformedConfiguration {
2525
export abstract class TypeScriptCompilation extends AngularCompilation {
2626
static #angularCompilerCliModule?: typeof ng;
2727
#cachedConfiguration?: TransformedConfiguration;
28+
#cachedRootFiles?: readonly string[];
2829

2930
static async loadCompilerCli(): Promise<typeof ng> {
3031
TypeScriptCompilation.#angularCompilerCliModule ??= await import('@angular/compiler-cli');
@@ -39,7 +40,14 @@ export abstract class TypeScriptCompilation extends AngularCompilation {
3940
): Promise<TransformedConfiguration> {
4041
// When `rootFiles` are explicitly provided (e.g., library builder), avoid re-parsing `tsconfig.json`
4142
// and walking the project directory tree via `readConfiguration` on every watch rebuild (~200-350ms on large libraries).
42-
if (compilerOptionOverrides?.rootFiles?.length && this.#cachedConfiguration) {
43+
const currentRootFiles = compilerOptionOverrides?.rootFiles;
44+
if (
45+
currentRootFiles &&
46+
this.#cachedConfiguration &&
47+
this.#cachedRootFiles &&
48+
this.#cachedRootFiles.length === currentRootFiles.length &&
49+
this.#cachedRootFiles.every((file, index) => file === currentRootFiles[index])
50+
) {
4351
return this.#cachedConfiguration;
4452
}
4553

@@ -96,8 +104,9 @@ export abstract class TypeScriptCompilation extends AngularCompilation {
96104
warnings,
97105
};
98106

99-
if (compilerOptionOverrides?.rootFiles?.length) {
107+
if (currentRootFiles?.length) {
100108
this.#cachedConfiguration = config;
109+
this.#cachedRootFiles = currentRootFiles;
101110
}
102111

103112
return config;
@@ -112,6 +121,7 @@ export abstract class TypeScriptCompilation extends AngularCompilation {
112121
if (/\.json$/i.test(posixFile)) {
113122
// If a tsconfig changes, we need to re-read the configuration.
114123
this.#cachedConfiguration = undefined;
124+
this.#cachedRootFiles = undefined;
115125
}
116126
}
117127
}

0 commit comments

Comments
 (0)