From c5ec8d952a5f5b953eea06194a047621d7d26ae3 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 8 Feb 2018 08:36:18 -0800 Subject: [PATCH] fix(bazel): improve error message for missing assets (#22096) fixes #22095 PR Close #22096 --- packages/bazel/src/ngc-wrapped/index.ts | 6 ++++++ packages/compiler-cli/src/transformers/compiler_host.ts | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index 0250c981d5..2c066ef22f 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -202,6 +202,12 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true, return path.resolve(bazelBin, workspaceRelative) + '.d.ts'; }; } + // Patch a property on the ngHost that allows the resourceNameToModuleName function to + // report better errors. + (ngHost as any).reportMissingResource = (resourceName: string) => { + console.error(`\nAsset not found:\n ${resourceName}`); + console.error('Check that it\'s included in the `assets` attribute of the `ng_module` rule.\n'); + }; const emitCallback: ng.TsEmitCallback = ({ program, diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index 3cbfc6488f..0d486f963e 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -231,7 +231,12 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos } const filePathWithNgResource = this.moduleNameToFileName(addNgResourceSuffix(resourceName), containingFile); - return filePathWithNgResource ? stripNgResourceSuffix(filePathWithNgResource) : null; + const result = filePathWithNgResource ? stripNgResourceSuffix(filePathWithNgResource) : null; + // Used under Bazel to report more specific error with remediation advice + if (!result && (this.context as any).reportMissingResource) { + (this.context as any).reportMissingResource(resourceName); + } + return result; } toSummaryFileName(fileName: string, referringSrcFileName: string): string {