fix(compiler): update to metadata version 3 (#13464)
This change retracts support for metadata version 2. The collector used to produce version 2 metadata was incomplete and can cause the AOT compiler to fail to resolve symbols or produce other spurious errors. All libraries compiled and published with 2.3.0 ngc will need to be recompiled and updated with this change.
This commit is contained in:

committed by
Victor Berchet

parent
a72a002a8d
commit
b9b557cdb0
@ -110,7 +110,8 @@ export class TsickleCompilerHost extends DelegatingHost {
|
||||
const IGNORED_FILES = /\.ngfactory\.js$|\.ngstyle\.js$/;
|
||||
|
||||
export class MetadataWriterHost extends DelegatingHost {
|
||||
private metadataCollector = new MetadataCollector();
|
||||
private metadataCollector = new MetadataCollector({quotedNames: true});
|
||||
private metadataCollector1 = new MetadataCollector({version: 1});
|
||||
constructor(delegate: ts.CompilerHost, private ngOptions: NgOptions) { super(delegate); }
|
||||
|
||||
private writeMetadata(emitFilePath: string, sourceFile: ts.SourceFile) {
|
||||
@ -120,18 +121,9 @@ export class MetadataWriterHost extends DelegatingHost {
|
||||
const path = emitFilePath.replace(/*DTS*/ /\.js$/, '.metadata.json');
|
||||
const metadata =
|
||||
this.metadataCollector.getMetadata(sourceFile, !!this.ngOptions.strictMetadataEmit);
|
||||
const metadatas: ModuleMetadata[] = [metadata];
|
||||
if (metadata && metadata.metadata) {
|
||||
if (metadata.version === 2) {
|
||||
// Also emit a version 1 so that older clients can consume new metadata files as well.
|
||||
// We can write the same data as version 2 is a strict super set.
|
||||
metadatas.push({
|
||||
__symbolic: metadata.__symbolic,
|
||||
exports: metadata.exports,
|
||||
metadata: metadata.metadata,
|
||||
version: 1
|
||||
});
|
||||
}
|
||||
const metadata1 = this.metadataCollector1.getMetadata(sourceFile, false);
|
||||
const metadatas: ModuleMetadata[] = [metadata, metadata1].filter(e => !!e);
|
||||
if (metadatas.length) {
|
||||
const metadataText = JSON.stringify(metadatas);
|
||||
writeFileSync(path, metadataText, {encoding: 'utf-8'});
|
||||
}
|
||||
|
Reference in New Issue
Block a user