fix(compiler): always use relative paths to refer to generated code

Previously we generated imports like `@angular/material/index.ngfactory`,
which doesn’t make sense as we don’t ship generated code on npm

Closes #20031
This commit is contained in:
Tobias Bosch 2017-10-30 11:54:40 -07:00 committed by Matias Niemelä
parent 308fc8e328
commit 04eb80cc2b
2 changed files with 10 additions and 1 deletions

View File

@ -192,7 +192,8 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
const containingFilePackageName = getPackageName(containingFile);
let moduleName: string;
if (importedFilePackagName === containingFilePackageName) {
if (importedFilePackagName === containingFilePackageName ||
GENERATED_FILES.test(originalImportedFile)) {
const rootedContainingFile = relativeToRootDirs(containingFile, this.rootDirs);
const rootedImportedFile = relativeToRootDirs(importedFile, this.rootDirs);

View File

@ -90,6 +90,14 @@ describe('NgCompilerHost', () => {
.toBe('./a/child');
});
it('should use a relative import when accessing generated files, even if crossing packages',
() => {
expect(host.fileNameToModuleName(
'/tmp/node_modules/mod2/b.ngfactory.d.ts',
'/tmp/node_modules/mod1/a.ngfactory.d.ts'))
.toBe('../mod2/b.ngfactory');
});
it('should support multiple rootDirs when accessing a source file form a source file', () => {
const hostWithMultipleRoots = createHost({
options: {