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:

committed by
Alex Rickabaugh

parent
e4c53f8529
commit
30208759cd
@ -336,9 +336,11 @@ class AngularCompilerProgram implements Program {
|
|||||||
if (!sf.isDeclarationFile && !GENERATED_FILES.test(sf.fileName)) {
|
if (!sf.isDeclarationFile && !GENERATED_FILES.test(sf.fileName)) {
|
||||||
metadataJsonCount++;
|
metadataJsonCount++;
|
||||||
const metadata = this.metadataCache.getMetadata(sf);
|
const metadata = this.metadataCache.getMetadata(sf);
|
||||||
const metadataText = JSON.stringify([metadata]);
|
if (metadata) {
|
||||||
const outFileName = srcToOutPath(sf.fileName.replace(/\.tsx?$/, '.metadata.json'));
|
const metadataText = JSON.stringify([metadata]);
|
||||||
this.writeFile(outFileName, metadataText, false, undefined, undefined, [sf]);
|
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', () => {
|
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
|
//#19544
|
||||||
it('should recognize @NgModule() directive with a redundant @Injectable()', () => {
|
it('should recognize @NgModule() directive with a redundant @Injectable()', () => {
|
||||||
write('src/tsconfig.json', `{
|
write('src/tsconfig.json', `{
|
||||||
|
Reference in New Issue
Block a user