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:
parent
308fc8e328
commit
04eb80cc2b
@ -192,7 +192,8 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
|||||||
const containingFilePackageName = getPackageName(containingFile);
|
const containingFilePackageName = getPackageName(containingFile);
|
||||||
|
|
||||||
let moduleName: string;
|
let moduleName: string;
|
||||||
if (importedFilePackagName === containingFilePackageName) {
|
if (importedFilePackagName === containingFilePackageName ||
|
||||||
|
GENERATED_FILES.test(originalImportedFile)) {
|
||||||
const rootedContainingFile = relativeToRootDirs(containingFile, this.rootDirs);
|
const rootedContainingFile = relativeToRootDirs(containingFile, this.rootDirs);
|
||||||
const rootedImportedFile = relativeToRootDirs(importedFile, this.rootDirs);
|
const rootedImportedFile = relativeToRootDirs(importedFile, this.rootDirs);
|
||||||
|
|
||||||
|
@ -90,6 +90,14 @@ describe('NgCompilerHost', () => {
|
|||||||
.toBe('./a/child');
|
.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', () => {
|
it('should support multiple rootDirs when accessing a source file form a source file', () => {
|
||||||
const hostWithMultipleRoots = createHost({
|
const hostWithMultipleRoots = createHost({
|
||||||
options: {
|
options: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user