Skip to content

Commit 769d960

Browse files
alexeaglemhevery
authored andcommittedMar 22, 2019
fix(bazel): workaround problem reading summary files from node_modules (#29459)
PR Close #29459
1 parent 21be0fb commit 769d960

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

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

+25
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,31 @@ export function compile({allDepsCompiledWithBazel = true, compilerOpts, tsHost,
311311
// File does not exist or parse error. Ignore this case and continue onto the
312312
// other methods of resolving the module below.
313313
}
314+
315+
// It can happen that the ViewEngine compiler needs to write an import in a factory file,
316+
// and is using an ngsummary file to get the symbols.
317+
// The ngsummary comes from an upstream ng_module rule.
318+
// The upstream rule based its imports on ngsummary file which was generated from a
319+
// metadata.json file that was published to npm in an Angular library.
320+
// However, the ngsummary doesn't propagate the 'importAs' from the original metadata.json
321+
// so we would normally not be able to supply the correct module name for it.
322+
// For example, if the rootDir-relative filePath is
323+
// node_modules/@angular/material/toolbar/typings/index
324+
// we would supply a module name
325+
// @angular/material/toolbar/typings/index
326+
// but there is no JavaScript file to load at this path.
327+
// This is a workaround for https://github.com/angular/angular/issues/29454
328+
if (importedFilePath.indexOf('node_modules') >= 0) {
329+
const maybeMetadataFile = importedFilePath.replace(EXT, '') + '.metadata.json';
330+
if (fs.existsSync(maybeMetadataFile)) {
331+
const moduleName =
332+
JSON.parse(fs.readFileSync(maybeMetadataFile, {encoding: 'utf-8'})).importAs;
333+
if (moduleName) {
334+
return moduleName;
335+
}
336+
}
337+
}
338+
314339
if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
315340
ngHost.amdModuleName) {
316341
return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);

0 commit comments

Comments
 (0)
Please sign in to comment.