build(bazel): generalize fix for AMD name for flat module out file (#26837)

PR Close #26837
This commit is contained in:
Greg Magolan 2018-10-29 13:04:15 -07:00 committed by Matias Niemelä
parent 62b4ff5250
commit 332394d87c
1 changed files with 11 additions and 7 deletions

View File

@ -209,16 +209,20 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
// compilationTargetSrc. // compilationTargetSrc.
// However we still want to give it an AMD module name for devmode. // However we still want to give it an AMD module name for devmode.
// We can't easily tell which file is the synthetic one, so we build up the path we expect // We can't easily tell which file is the synthetic one, so we build up the path we expect
// it to have // it to have and compare against that.
// and compare against that.
if (fileName === if (fileName ===
path.join(compilerOpts.baseUrl, bazelOpts.package, compilerOpts.flatModuleOutFile + '.ts')) path.join(compilerOpts.baseUrl, bazelOpts.package, compilerOpts.flatModuleOutFile + '.ts'))
return true; return true;
// Also handle the case when angular is built from source as an external repository // Also handle the case the target is in an external repository.
if (fileName === // Pull the workspace name from the target which is formatted as `@wksp//package:target`
path.join( // if it the target is from an external workspace. If the target is from the local
compilerOpts.baseUrl, 'external/angular', bazelOpts.package, // workspace then it will be formatted as `//package:target`.
compilerOpts.flatModuleOutFile + '.ts')) const targetWorkspace = bazelOpts.target.split('/')[0].replace(/^@/, '');
if (targetWorkspace &&
fileName ===
path.join(
compilerOpts.baseUrl, 'external', targetWorkspace, bazelOpts.package,
compilerOpts.flatModuleOutFile + '.ts'))
return true; return true;
return origBazelHostShouldNameModule(fileName) || NGC_GEN_FILES.test(fileName); return origBazelHostShouldNameModule(fileName) || NGC_GEN_FILES.test(fileName);
}; };