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

Commit

Permalink
fix(AoT): properly check for ngmodule declaration errors from the AoT…
Browse files Browse the repository at this point in the history
… build
  • Loading branch information
danbucholtz committed Nov 13, 2017
1 parent 3655f68 commit a47f120
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/aot/aot-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ import { readFileSync } from 'fs-extra';
import { extname, normalize, resolve } from 'path';

import 'reflect-metadata';
import { CompilerHost, CompilerOptions, ParsedCommandLine, Program, transpileModule, TranspileOptions, TranspileOutput, createProgram } from 'typescript';

import {
CompilerHost,
CompilerOptions,
DiagnosticCategory,
ParsedCommandLine,
Program,
transpileModule,
TranspileOptions,
TranspileOutput,
createProgram
} from 'typescript';

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

if (isNg5(context.angularVersion)) {
await runNg5Aot(tsConfig, aggregateCompilerOption, compilerHost);
await runNg5Aot(context, tsConfig, aggregateCompilerOption, compilerHost);
} else {
await runNg4Aot({
angularCompilerOptions: aggregateCompilerOption,
Expand Down Expand Up @@ -162,7 +173,7 @@ export async function runNg4Aot(options: CodegenOptions) {
});
}

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

program.emit({ emitFlags: ngTools2.EmitFlags.Default, customTransformers: transformers });
const result = program.emit({ emitFlags: ngTools2.EmitFlags.Default, customTransformers: transformers });

// Report diagnostics.
const errors = result.diagnostics.filter((diag) => diag.category === DiagnosticCategory.Error);
const warnings = result.diagnostics.filter((diag) => diag.category === DiagnosticCategory.Warning);

if (warnings.length) {
const diagnostics = runTypeScriptDiagnostics(context, warnings);
printDiagnostics(context, DiagnosticsType.TypeScript, diagnostics, true, false);
}

if (errors.length) {
const diagnostics = runTypeScriptDiagnostics(context, errors);
printDiagnostics(context, DiagnosticsType.TypeScript, diagnostics, true, false);
throw new BuildError(new Error('The Angular AoT build failed. See the issues above'));
}
}

export interface AotOptions {
Expand Down

0 comments on commit a47f120

Please sign in to comment.