diff --git a/packages/compiler-cli/src/compiler_host.ts b/packages/compiler-cli/src/compiler_host.ts index b3def2a01a..1d760b476a 100644 --- a/packages/compiler-cli/src/compiler_host.ts +++ b/packages/compiler-cli/src/compiler_host.ts @@ -207,7 +207,11 @@ export class CompilerHost implements AotCompilerHost { return metadatas; } try { - const metadataOrMetadatas = JSON.parse(this.context.readFile(filePath)); + let metadataOrMetadatas = JSON.parse(this.context.readFile(filePath)); + while (metadataOrMetadatas.alias) { + filePath = path.join(path.dirname(filePath), metadataOrMetadatas.alias); + metadataOrMetadatas = JSON.parse(this.context.readFile(filePath)); + } const metadatas: ModuleMetadata[] = metadataOrMetadatas ? (Array.isArray(metadataOrMetadatas) ? metadataOrMetadatas : [metadataOrMetadatas]) : []; diff --git a/packages/compiler-cli/test/aot_host_spec.ts b/packages/compiler-cli/test/aot_host_spec.ts index aad08036c3..e7611822f7 100644 --- a/packages/compiler-cli/test/aot_host_spec.ts +++ b/packages/compiler-cli/test/aot_host_spec.ts @@ -202,6 +202,10 @@ describe('CompilerHost', () => { {__symbolic: 'module', version: 3, metadata: {}, exports: [{from: './lib/utils'}]} ]); }); + + it('should follow metadata aliases', () => { + expect(hostNestedGenDir.getMetadataFor('alias/file.d.ts')).toEqual([dummyMetadata]); + }); }); const dummyModule = 'export let foo: any[];'; @@ -237,6 +241,13 @@ const FILES: Entry = { 'empty.metadata.json': '[]', } }, + 'alias': { + 'file.d.ts': dummyModule, + 'file.metadata.json': '{ "alias": "sub/index.metadata.json"}', + 'sub': { + 'index.metadata.json': JSON.stringify(dummyMetadata) + } + }, 'metadata_versions': { 'v1.d.ts': ` import {ReExport} from './lib/utils2';