@@ -75,6 +75,7 @@ export function createCompilerPlugin(
7575 // eslint-disable-next-line max-lines-per-function
7676 async setup ( build : PluginBuild ) : Promise < void > {
7777 let setupWarnings : PartialMessage [ ] | undefined = [ ] ;
78+ let diagnosticsPromise : ReturnType < AngularCompilation [ 'diagnoseFiles' ] > | undefined ;
7879 const preserveSymlinks = build . initialOptions . preserveSymlinks ;
7980
8081 // Initialize a worker pool for JavaScript transformations.
@@ -157,6 +158,7 @@ export function createCompilerPlugin(
157158
158159 // eslint-disable-next-line max-lines-per-function
159160 build . onStart ( async ( ) => {
161+ hasCompilationErrors = true ;
160162 await initializeHash ( ) ;
161163
162164 const result : OnStartResult = {
@@ -400,16 +402,22 @@ export function createCompilerPlugin(
400402 ] ,
401403 } ) ;
402404 }
403- }
404405
405- const diagnostics = await compilation . diagnoseFiles (
406- useTypeChecking ? DiagnosticModes . All : DiagnosticModes . All & ~ DiagnosticModes . Semantic ,
407- ) ;
408- if ( diagnostics . errors ?. length ) {
409- ( result . errors ??= [ ] ) . push ( ...diagnostics . errors ) ;
410- }
411- if ( diagnostics . warnings ?. length ) {
412- ( result . warnings ??= [ ] ) . push ( ...diagnostics . warnings ) ;
406+ const diagnosticModes = useTypeChecking
407+ ? DiagnosticModes . All
408+ : DiagnosticModes . All & ~ DiagnosticModes . Semantic ;
409+ diagnosticsPromise = compilation . diagnoseFiles ( diagnosticModes ) . catch ( ( error ) => ( {
410+ errors : [
411+ {
412+ text : 'Angular compilation diagnostics failed.' ,
413+ notes : [
414+ {
415+ text : error instanceof Error ? ( error . stack ?? error . message ) : String ( error ) ,
416+ } ,
417+ ] ,
418+ } ,
419+ ] ,
420+ } ) ) ;
413421 }
414422
415423 // Add errors from failed additional results.
@@ -617,7 +625,7 @@ export function createCompilerPlugin(
617625 ) ;
618626 }
619627
620- build . onEnd ( ( result ) => {
628+ build . onEnd ( async ( result ) => {
621629 // Ensure other compilations are unblocked if the main compilation throws during start
622630 if ( angularCompilationContext . isPrimary ( ) ) {
623631 angularCompilationContext . markAsReady ( hasCompilationErrors ) ;
@@ -640,6 +648,20 @@ export function createCompilerPlugin(
640648 }
641649
642650 logCumulativeDurations ( ) ;
651+
652+ if ( diagnosticsPromise ) {
653+ try {
654+ const diagnostics = await diagnosticsPromise ;
655+ const errors = diagnostics . errors ?. length ? diagnostics . errors : undefined ;
656+ const warnings = diagnostics . warnings ?. length ? diagnostics . warnings : undefined ;
657+
658+ if ( errors || warnings ) {
659+ return { errors, warnings } ;
660+ }
661+ } finally {
662+ diagnosticsPromise = undefined ;
663+ }
664+ }
643665 } ) ;
644666
645667 build . onDispose ( ( ) => {
0 commit comments