feat(compiler-cli): support metadata file aliases

This commit is contained in:
Chuck Jazdzewski 2017-03-15 18:54:54 -07:00
parent 994089d36b
commit 0ab49d4cec
2 changed files with 16 additions and 1 deletions

View File

@ -207,7 +207,11 @@ export class CompilerHost implements AotCompilerHost {
return metadatas; return metadatas;
} }
try { 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 ? const metadatas: ModuleMetadata[] = metadataOrMetadatas ?
(Array.isArray(metadataOrMetadatas) ? metadataOrMetadatas : [metadataOrMetadatas]) : (Array.isArray(metadataOrMetadatas) ? metadataOrMetadatas : [metadataOrMetadatas]) :
[]; [];

View File

@ -202,6 +202,10 @@ describe('CompilerHost', () => {
{__symbolic: 'module', version: 3, metadata: {}, exports: [{from: './lib/utils'}]} {__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[];'; const dummyModule = 'export let foo: any[];';
@ -237,6 +241,13 @@ const FILES: Entry = {
'empty.metadata.json': '[]', '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': { 'metadata_versions': {
'v1.d.ts': ` 'v1.d.ts': `
import {ReExport} from './lib/utils2'; import {ReExport} from './lib/utils2';