From 9bcd8c2425fa7a4334adf1a6f6a660d9444d2438 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 23 Aug 2018 19:20:50 -0700 Subject: [PATCH] =?UTF-8?q?build(bazel):=20use=20value=20of=20///=20=20directive=20to=20convert?= =?UTF-8?q?=20fileNameToModuleName=20in=20ngc-wrapped=20(#25650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR Close #25650 --- packages/bazel/src/ngc-wrapped/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index 4e1e92730d..00277b38f7 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -226,6 +226,15 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true, const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost}); ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => { + try { + const sourceFile = ngHost.getSourceFile(importedFilePath, ts.ScriptTarget.Latest); + if (sourceFile && sourceFile.moduleName) { + return sourceFile.moduleName; + } + } catch (err) { + // File does not exist or parse error. Ignore this case and continue onto the + // other methods of resolving the module below. + } if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) && ngHost.amdModuleName) { return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);