Skip to content

Commit 7aff364

Browse files
alexeaglematsko
authored andcommitted
fix(bazel): only lookup amd module-name tags in .d.ts files (#25710)
PR Close #25710
1 parent 2194b5a commit 7aff364

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,21 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
222222
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});
223223

224224
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => {
225-
try {
226-
const sourceFile = ngHost.getSourceFile(importedFilePath, ts.ScriptTarget.Latest);
227-
if (sourceFile && sourceFile.moduleName) {
228-
return sourceFile.moduleName;
225+
// Lookup the module name specified in the TypeScript source file, if present
226+
// it will look like ///<amd module-name="something"/>
227+
// For performance, we only do this for .d.ts files, to avoid parsing lots of
228+
// additional files that were not in the program.
229+
// (We don't have the ts.Program available in this codepath)
230+
if (importedFilePath.endsWith('.d.ts')) {
231+
try {
232+
const sourceFile = ngHost.getSourceFile(importedFilePath, ts.ScriptTarget.Latest);
233+
if (sourceFile && sourceFile.moduleName) {
234+
return sourceFile.moduleName;
235+
}
236+
} catch (err) {
237+
// File does not exist or parse error. Ignore this case and continue onto the
238+
// other methods of resolving the module below.
229239
}
230-
} catch (err) {
231-
// File does not exist or parse error. Ignore this case and continue onto the
232-
// other methods of resolving the module below.
233240
}
234241
if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
235242
ngHost.amdModuleName) {

0 commit comments

Comments
 (0)