|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import type * as ng from '@angular/compiler-cli'; |
9 | 10 | import type { PartialMessage } from 'esbuild'; |
10 | 11 | import ts from 'typescript'; |
11 | 12 | import { toPosixPath } from '../../../utils/path'; |
12 | | -import { profileAsync } from '../../esbuild/profiling'; |
| 13 | +import { profileAsync, profileSync } from '../../esbuild/profiling'; |
13 | 14 | import { AngularCompilation, DiagnosticModes } from './angular-compilation'; |
14 | 15 | import { convertTypeScriptDiagnostic } from './diagnostics'; |
15 | 16 |
|
16 | 17 | export abstract class TypeScriptCompilation extends AngularCompilation { |
| 18 | + static #angularCompilerCliModule?: typeof ng; |
| 19 | + |
| 20 | + static async loadCompilerCli(): Promise<typeof ng> { |
| 21 | + TypeScriptCompilation.#angularCompilerCliModule ??= await import('@angular/compiler-cli'); |
| 22 | + |
| 23 | + return TypeScriptCompilation.#angularCompilerCliModule; |
| 24 | + } |
| 25 | + |
| 26 | + protected async loadConfiguration(tsconfig: string): Promise<ng.ParsedConfiguration> { |
| 27 | + const { readConfiguration } = await TypeScriptCompilation.loadCompilerCli(); |
| 28 | + |
| 29 | + return profileSync('NG_READ_CONFIG', () => |
| 30 | + readConfiguration(tsconfig, { |
| 31 | + // Angular specific configuration defaults and overrides to ensure a functioning compilation. |
| 32 | + suppressOutputPathCheck: true, |
| 33 | + outDir: undefined, |
| 34 | + sourceMap: false, |
| 35 | + declaration: false, |
| 36 | + declarationMap: false, |
| 37 | + allowEmptyCodegenFiles: false, |
| 38 | + annotationsAs: 'decorators', |
| 39 | + enableResourceInlining: false, |
| 40 | + supportTestBed: false, |
| 41 | + supportJitMode: false, |
| 42 | + // Disable removing of comments as TS is quite aggressive with these and can |
| 43 | + // remove important annotations, such as /* @__PURE__ */ and comments like /* vite-ignore */. |
| 44 | + removeComments: false, |
| 45 | + }), |
| 46 | + ); |
| 47 | + } |
| 48 | + |
17 | 49 | protected readonly sourceFiles = new Map<string, ts.SourceFile>(); |
18 | 50 |
|
19 | 51 | protected invalidateFiles(files: Iterable<string>): void { |
|
0 commit comments