Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bazel): improve error message for missing assets #22096

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/bazel/src/ngc-wrapped/index.ts
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler-cli/src/transformers/compiler_host.ts
Expand Up @@ -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 {
Expand Down