Skip to content

Commit a4dcfa9

Browse files
clydindgp1130
authored andcommitted
refactor(@angular-devkit/build-angular): move TypeScript diagnostic conversion into compilation base
When using the esbuild-based browser application builder, TypeScript diagnostics are now converted into esbuild messages within the compilation base class instead of the plugin. This helps further isolate the TypeScript details within the compilation classes. Additionally, this provides diagnostic objects that can be more easily serialized earlier in the build process.
1 parent 89e644b commit a4dcfa9

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/angular/compilation/angular-compilation.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
*/
88

99
import type ng from '@angular/compiler-cli';
10-
import type ts from 'typescript';
10+
import type { PartialMessage } from 'esbuild';
11+
import ts from 'typescript';
1112
import { loadEsmModule } from '../../../../utils/load-esm';
1213
import { profileSync } from '../../profiling';
1314
import type { AngularHostOptions } from '../angular-host';
15+
import { convertTypeScriptDiagnostic } from '../diagnostics';
1416

1517
export interface EmitFileResult {
1618
filename: string;
@@ -61,7 +63,24 @@ export abstract class AngularCompilation {
6163
referencedFiles: readonly string[];
6264
}>;
6365

64-
abstract collectDiagnostics(): Iterable<ts.Diagnostic>;
65-
6666
abstract emitAffectedFiles(): Iterable<EmitFileResult>;
67+
68+
protected abstract collectDiagnostics(): Iterable<ts.Diagnostic>;
69+
70+
async diagnoseFiles(): Promise<{ errors?: PartialMessage[]; warnings?: PartialMessage[] }> {
71+
const result: { errors?: PartialMessage[]; warnings?: PartialMessage[] } = {};
72+
73+
profileSync('NG_DIAGNOSTICS_TOTAL', () => {
74+
for (const diagnostic of this.collectDiagnostics()) {
75+
const message = convertTypeScriptDiagnostic(diagnostic);
76+
if (diagnostic.category === ts.DiagnosticCategory.Error) {
77+
(result.errors ??= []).push(message);
78+
} else {
79+
(result.warnings ??= []).push(message);
80+
}
81+
}
82+
});
83+
84+
return result;
85+
}
6786
}

packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
import { BundleStylesheetOptions, bundleComponentStylesheet } from '../stylesheets/bundle-options';
3232
import { AngularHostOptions } from './angular-host';
3333
import { AngularCompilation, AotCompilation, JitCompilation, NoopCompilation } from './compilation';
34-
import { convertTypeScriptDiagnostic } from './diagnostics';
3534
import { setupJitPluginCallbacks } from './jit-plugin-callbacks';
3635

3736
const USING_WINDOWS = platform() === 'win32';
@@ -258,16 +257,13 @@ export function createCompilerPlugin(
258257
return result;
259258
}
260259

261-
profileSync('NG_DIAGNOSTICS_TOTAL', () => {
262-
for (const diagnostic of compilation.collectDiagnostics()) {
263-
const message = convertTypeScriptDiagnostic(diagnostic);
264-
if (diagnostic.category === ts.DiagnosticCategory.Error) {
265-
(result.errors ??= []).push(message);
266-
} else {
267-
(result.warnings ??= []).push(message);
268-
}
269-
}
270-
});
260+
const diagnostics = await compilation.diagnoseFiles();
261+
if (diagnostics.errors) {
262+
(result.errors ??= []).push(...diagnostics.errors);
263+
}
264+
if (diagnostics.warnings) {
265+
(result.warnings ??= []).push(...diagnostics.warnings);
266+
}
271267

272268
// Update TypeScript file output cache for all affected files
273269
profileSync('NG_EMIT_TS', () => {

0 commit comments

Comments
 (0)