fix(compiler-cli): do not emit invalid .metadata.json files
If no metadata is collected the `ngc` would generate file that contained `[null]` instead of eliding the `.metadata.json` file. Fixes: #20479
This commit is contained in:
parent
e4c53f8529
commit
30208759cd
@ -336,9 +336,11 @@ class AngularCompilerProgram implements Program {
|
||||
if (!sf.isDeclarationFile && !GENERATED_FILES.test(sf.fileName)) {
|
||||
metadataJsonCount++;
|
||||
const metadata = this.metadataCache.getMetadata(sf);
|
||||
const metadataText = JSON.stringify([metadata]);
|
||||
const outFileName = srcToOutPath(sf.fileName.replace(/\.tsx?$/, '.metadata.json'));
|
||||
this.writeFile(outFileName, metadataText, false, undefined, undefined, [sf]);
|
||||
if (metadata) {
|
||||
const metadataText = JSON.stringify([metadata]);
|
||||
const outFileName = srcToOutPath(sf.fileName.replace(/\.tsx?$/, '.metadata.json'));
|
||||
this.writeFile(outFileName, metadataText, false, undefined, undefined, [sf]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1474,6 +1474,26 @@ describe('ngc transformer command-line', () => {
|
||||
});
|
||||
|
||||
describe('regressions', () => {
|
||||
//#20479
|
||||
it('should not generate an invalid metadata file', () => {
|
||||
write('src/tsconfig.json', `{
|
||||
"extends": "../tsconfig-base.json",
|
||||
"files": ["lib.ts"],
|
||||
"angularCompilerOptions": {
|
||||
"skipTemplateCodegen": true
|
||||
}
|
||||
}`);
|
||||
write('src/lib.ts', `
|
||||
export namespace A{
|
||||
export class C1 {
|
||||
}
|
||||
export interface I1{
|
||||
}
|
||||
}`);
|
||||
expect(main(['-p', path.join(basePath, 'src/tsconfig.json')])).toBe(0);
|
||||
shouldNotExist('src/lib.metadata.json');
|
||||
});
|
||||
|
||||
//#19544
|
||||
it('should recognize @NgModule() directive with a redundant @Injectable()', () => {
|
||||
write('src/tsconfig.json', `{
|
||||
|
Loading…
x
Reference in New Issue
Block a user