fix(bazel): only lookup amd module-name tags in .d.ts files (#25710)
PR Close #25710
This commit is contained in:
parent
2194b5a5c3
commit
7aff3641a1
@ -222,6 +222,12 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
|
|||||||
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});
|
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});
|
||||||
|
|
||||||
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => {
|
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => {
|
||||||
|
// Lookup the module name specified in the TypeScript source file, if present
|
||||||
|
// it will look like ///<amd module-name="something"/>
|
||||||
|
// For performance, we only do this for .d.ts files, to avoid parsing lots of
|
||||||
|
// additional files that were not in the program.
|
||||||
|
// (We don't have the ts.Program available in this codepath)
|
||||||
|
if (importedFilePath.endsWith('.d.ts')) {
|
||||||
try {
|
try {
|
||||||
const sourceFile = ngHost.getSourceFile(importedFilePath, ts.ScriptTarget.Latest);
|
const sourceFile = ngHost.getSourceFile(importedFilePath, ts.ScriptTarget.Latest);
|
||||||
if (sourceFile && sourceFile.moduleName) {
|
if (sourceFile && sourceFile.moduleName) {
|
||||||
@ -231,6 +237,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
|
|||||||
// File does not exist or parse error. Ignore this case and continue onto the
|
// File does not exist or parse error. Ignore this case and continue onto the
|
||||||
// other methods of resolving the module below.
|
// other methods of resolving the module below.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
|
if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
|
||||||
ngHost.amdModuleName) {
|
ngHost.amdModuleName) {
|
||||||
return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);
|
return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user