@@ -2,7 +2,18 @@ import { readFileSync } from 'fs-extra';
2
2
import { extname , normalize , resolve } from 'path' ;
3
3
4
4
import 'reflect-metadata' ;
5
- import { CompilerHost , CompilerOptions , ParsedCommandLine , Program , transpileModule , TranspileOptions , TranspileOutput , createProgram } from 'typescript' ;
5
+
6
+ import {
7
+ CompilerHost ,
8
+ CompilerOptions ,
9
+ DiagnosticCategory ,
10
+ ParsedCommandLine ,
11
+ Program ,
12
+ transpileModule ,
13
+ TranspileOptions ,
14
+ TranspileOutput ,
15
+ createProgram
16
+ } from 'typescript' ;
6
17
7
18
import { HybridFileSystem } from '../util/hybrid-file-system' ;
8
19
import { getInstance as getHybridFileSystem } from '../util/hybrid-file-system-factory' ;
@@ -36,7 +47,7 @@ export async function runAot(context: BuildContext, options: AotOptions) {
36
47
clearDiagnostics ( context , DiagnosticsType . TypeScript ) ;
37
48
38
49
if ( isNg5 ( context . angularVersion ) ) {
39
- await runNg5Aot ( tsConfig , aggregateCompilerOption , compilerHost ) ;
50
+ await runNg5Aot ( context , tsConfig , aggregateCompilerOption , compilerHost ) ;
40
51
} else {
41
52
await runNg4Aot ( {
42
53
angularCompilerOptions : aggregateCompilerOption ,
@@ -162,7 +173,7 @@ export async function runNg4Aot(options: CodegenOptions) {
162
173
} ) ;
163
174
}
164
175
165
- export async function runNg5Aot ( tsConfig : TsConfig , aggregateCompilerOptions : CompilerOptions , compilerHost : CompilerHost ) {
176
+ export async function runNg5Aot ( context : BuildContext , tsConfig : TsConfig , aggregateCompilerOptions : CompilerOptions , compilerHost : CompilerHost ) {
166
177
const ngTools2 = await import ( '@angular/compiler-cli/ngtools2' ) ;
167
178
const angularCompilerHost = ngTools2 . createCompilerHost ( { options : aggregateCompilerOptions , tsHost : compilerHost } ) ;
168
179
const program = ngTools2 . createProgram ( {
@@ -180,7 +191,22 @@ export async function runNg5Aot(tsConfig: TsConfig, aggregateCompilerOptions: Co
180
191
beforeTs : transformations
181
192
} ;
182
193
183
- program . emit ( { emitFlags : ngTools2 . EmitFlags . Default , customTransformers : transformers } ) ;
194
+ const result = program . emit ( { emitFlags : ngTools2 . EmitFlags . Default , customTransformers : transformers } ) ;
195
+
196
+ // Report diagnostics.
197
+ const errors = result . diagnostics . filter ( ( diag ) => diag . category === DiagnosticCategory . Error ) ;
198
+ const warnings = result . diagnostics . filter ( ( diag ) => diag . category === DiagnosticCategory . Warning ) ;
199
+
200
+ if ( warnings . length ) {
201
+ const diagnostics = runTypeScriptDiagnostics ( context , warnings ) ;
202
+ printDiagnostics ( context , DiagnosticsType . TypeScript , diagnostics , true , false ) ;
203
+ }
204
+
205
+ if ( errors . length ) {
206
+ const diagnostics = runTypeScriptDiagnostics ( context , errors ) ;
207
+ printDiagnostics ( context , DiagnosticsType . TypeScript , diagnostics , true , false ) ;
208
+ throw new BuildError ( new Error ( 'The Angular AoT build failed. See the issues above' ) ) ;
209
+ }
184
210
}
185
211
186
212
export interface AotOptions {
0 commit comments