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)) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user