Skip to content

Commit c5ec8d9

Browse files
alexeaglemhevery
authored andcommitted
fix(bazel): improve error message for missing assets (#22096)
fixes #22095 PR Close #22096
1 parent de561f3 commit c5ec8d9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/bazel/src/ngc-wrapped/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
202202
return path.resolve(bazelBin, workspaceRelative) + '.d.ts';
203203
};
204204
}
205+
// Patch a property on the ngHost that allows the resourceNameToModuleName function to
206+
// report better errors.
207+
(ngHost as any).reportMissingResource = (resourceName: string) => {
208+
console.error(`\nAsset not found:\n ${resourceName}`);
209+
console.error('Check that it\'s included in the `assets` attribute of the `ng_module` rule.\n');
210+
};
205211

206212
const emitCallback: ng.TsEmitCallback = ({
207213
program,

packages/compiler-cli/src/transformers/compiler_host.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
231231
}
232232
const filePathWithNgResource =
233233
this.moduleNameToFileName(addNgResourceSuffix(resourceName), containingFile);
234-
return filePathWithNgResource ? stripNgResourceSuffix(filePathWithNgResource) : null;
234+
const result = filePathWithNgResource ? stripNgResourceSuffix(filePathWithNgResource) : null;
235+
// Used under Bazel to report more specific error with remediation advice
236+
if (!result && (this.context as any).reportMissingResource) {
237+
(this.context as any).reportMissingResource(resourceName);
238+
}
239+
return result;
235240
}
236241

237242
toSummaryFileName(fileName: string, referringSrcFileName: string): string {

0 commit comments

Comments
 (0)