Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit a47f120

Browse files
committed
fix(AoT): properly check for ngmodule declaration errors from the AoT build
1 parent 3655f68 commit a47f120

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/aot/aot-compiler.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ import { readFileSync } from 'fs-extra';
22
import { extname, normalize, resolve } from 'path';
33

44
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';
617

718
import { HybridFileSystem } from '../util/hybrid-file-system';
819
import { getInstance as getHybridFileSystem } from '../util/hybrid-file-system-factory';
@@ -36,7 +47,7 @@ export async function runAot(context: BuildContext, options: AotOptions) {
3647
clearDiagnostics(context, DiagnosticsType.TypeScript);
3748

3849
if (isNg5(context.angularVersion)) {
39-
await runNg5Aot(tsConfig, aggregateCompilerOption, compilerHost);
50+
await runNg5Aot(context, tsConfig, aggregateCompilerOption, compilerHost);
4051
} else {
4152
await runNg4Aot({
4253
angularCompilerOptions: aggregateCompilerOption,
@@ -162,7 +173,7 @@ export async function runNg4Aot(options: CodegenOptions) {
162173
});
163174
}
164175

165-
export async function runNg5Aot(tsConfig: TsConfig, aggregateCompilerOptions: CompilerOptions, compilerHost: CompilerHost) {
176+
export async function runNg5Aot(context: BuildContext, tsConfig: TsConfig, aggregateCompilerOptions: CompilerOptions, compilerHost: CompilerHost) {
166177
const ngTools2 = await import('@angular/compiler-cli/ngtools2');
167178
const angularCompilerHost = ngTools2.createCompilerHost({options: aggregateCompilerOptions, tsHost: compilerHost});
168179
const program = ngTools2.createProgram({
@@ -180,7 +191,22 @@ export async function runNg5Aot(tsConfig: TsConfig, aggregateCompilerOptions: Co
180191
beforeTs: transformations
181192
};
182193

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+
}
184210
}
185211

186212
export interface AotOptions {

0 commit comments

Comments
 (0)