From e81dea695c92e31c8a3a9fb1cdcfc143c9787e38 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 28 Jun 2016 20:07:00 -0700 Subject: [PATCH] fix(compiler): report not existing files as errors Closes #9690 --- modules/@angular/compiler-cli/src/codegen.ts | 10 +++++++++- modules/@angular/compiler-cli/src/extract_i18n.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/@angular/compiler-cli/src/codegen.ts b/modules/@angular/compiler-cli/src/codegen.ts index 85e2ab5901..950086bfa7 100644 --- a/modules/@angular/compiler-cli/src/codegen.ts +++ b/modules/@angular/compiler-cli/src/codegen.ts @@ -131,7 +131,15 @@ export class CodeGenerator { static create( options: AngularCompilerOptions, program: ts.Program, compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext): CodeGenerator { - const xhr: compiler.XHR = {get: (s: string) => Promise.resolve(compilerHost.readFile(s))}; + const xhr: compiler.XHR = { + get: (s: string) => { + if (!compilerHost.fileExists(s)) { + // TODO: We should really have a test for error cases like this! + throw new Error(`Compilation failed. Resource file not found: ${s}`); + } + return Promise.resolve(compilerHost.readFile(s)); + } + }; const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver(); const reflectorHost = new ReflectorHost(program, compilerHost, options, reflectorHostContext); const staticReflector = new StaticReflector(reflectorHost); diff --git a/modules/@angular/compiler-cli/src/extract_i18n.ts b/modules/@angular/compiler-cli/src/extract_i18n.ts index 6c8dbec307..8106f8ccb0 100644 --- a/modules/@angular/compiler-cli/src/extract_i18n.ts +++ b/modules/@angular/compiler-cli/src/extract_i18n.ts @@ -141,7 +141,15 @@ class Extractor { static create( options: tsc.AngularCompilerOptions, program: ts.Program, compilerHost: ts.CompilerHost): Extractor { - const xhr: compiler.XHR = {get: (s: string) => Promise.resolve(compilerHost.readFile(s))}; + const xhr: compiler.XHR = { + get: (s: string) => { + if (!compilerHost.fileExists(s)) { + // TODO: We should really have a test for error cases like this! + throw new Error(`Compilation failed. Resource file not found: ${s}`); + } + return Promise.resolve(compilerHost.readFile(s)); + } + }; const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver(); const reflectorHost = new ReflectorHost(program, compilerHost, options); const staticReflector = new StaticReflector(reflectorHost);