From 5e4df1dd655beeb6d7717c244273ebf9e2ea176e Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Thu, 2 Jun 2016 16:40:38 -0700 Subject: [PATCH] feat(build): Added a version stamp in .metadata.json files. Also modified StaticReflector to handle multiple versions in a single .metadata.json file. Fixes #8974 --- .../@angular/compiler-cli/src/static_reflector.ts | 5 +++++ .../compiler-cli/test/static_reflector_spec.ts | 9 ++++++--- tools/@angular/tsc-wrapped/src/collector.ts | 4 ++-- tools/@angular/tsc-wrapped/src/schema.ts | 12 ++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/@angular/compiler-cli/src/static_reflector.ts b/modules/@angular/compiler-cli/src/static_reflector.ts index df1a4a17c96f0a..72e7c4ecf087ef 100644 --- a/modules/@angular/compiler-cli/src/static_reflector.ts +++ b/modules/@angular/compiler-cli/src/static_reflector.ts @@ -22,6 +22,8 @@ import { InjectMetadata, } from "@angular/core"; import {ReflectorReader} from "./core_private"; + +const SUPPORTED_SCHEMA_VERSION = 1; /** * The host of the static resolver is expected to be able to provide module metadata in the form of @@ -379,6 +381,9 @@ export class StaticReflector implements ReflectorReader { let moduleMetadata = this.metadataCache.get(module); if (!moduleMetadata) { moduleMetadata = this.host.getMetadataFor(module); + if (Array.isArray(moduleMetadata)) { + moduleMetadata = (>moduleMetadata).find(element => element.version === SUPPORTED_SCHEMA_VERSION); + } if (!moduleMetadata) { moduleMetadata = {__symbolic: "module", module: module, metadata: {}}; } diff --git a/modules/@angular/compiler-cli/test/static_reflector_spec.ts b/modules/@angular/compiler-cli/test/static_reflector_spec.ts index 79bb24c1e3fcac..566bc36a18425c 100644 --- a/modules/@angular/compiler-cli/test/static_reflector_spec.ts +++ b/modules/@angular/compiler-cli/test/static_reflector_spec.ts @@ -300,8 +300,9 @@ class MockReflectorHost implements StaticReflectorHost { getMetadataFor(moduleId: string): any { let data: {[key: string]: any} = { - '/tmp/angular2/src/common/forms/directives.d.ts': { + '/tmp/angular2/src/common/forms/directives.d.ts': [{ "__symbolic": "module", + "version": 1, "metadata": { "FORM_DIRECTIVES": [ { @@ -311,9 +312,10 @@ class MockReflectorHost implements StaticReflectorHost { } ] } - }, + }], '/tmp/angular2/src/common/directives/ng_for.d.ts': { "__symbolic": "module", + "version": 1, "metadata": { "NgFor": { "__symbolic": "class", @@ -375,6 +377,7 @@ class MockReflectorHost implements StaticReflectorHost { {"metadata": {"ChangeDetectorRef": {"__symbolic": "class"}}}, '/tmp/src/app/hero-detail.component.d.ts': { "__symbolic": "module", + "version": 1, "metadata": { "HeroDetailComponent": { "__symbolic": "class", @@ -422,7 +425,7 @@ class MockReflectorHost implements StaticReflectorHost { } } }, - '/src/extern.d.ts': {"__symbolic": "module", metadata: {s: "s"}} + '/src/extern.d.ts': {"__symbolic": "module", "version": 1, metadata: {s: "s"}}, }; return data[moduleId]; } diff --git a/tools/@angular/tsc-wrapped/src/collector.ts b/tools/@angular/tsc-wrapped/src/collector.ts index a74c52e75667fe..6ca076c0847ed1 100644 --- a/tools/@angular/tsc-wrapped/src/collector.ts +++ b/tools/@angular/tsc-wrapped/src/collector.ts @@ -1,7 +1,7 @@ import * as ts from 'typescript'; import {Evaluator, ImportMetadata, ImportSpecifierMetadata, isPrimitive} from './evaluator'; -import {ClassMetadata, ConstructorMetadata, ModuleMetadata, MemberMetadata, MetadataError, MetadataMap, MetadataSymbolicExpression, MetadataSymbolicReferenceExpression, MetadataValue, MethodMetadata, isMetadataError, isMetadataSymbolicReferenceExpression,} from './schema'; +import {ClassMetadata, ConstructorMetadata, ModuleMetadata, MemberMetadata, MetadataError, MetadataMap, MetadataSymbolicExpression, MetadataSymbolicReferenceExpression, MetadataValue, MethodMetadata, isMetadataError, isMetadataSymbolicReferenceExpression, VERSION} from './schema'; import {Symbols} from './symbols'; /** @@ -207,6 +207,6 @@ export class MetadataCollector { } }); - return metadata && {__symbolic: 'module', metadata}; + return metadata && {__symbolic: 'module', version: VERSION, metadata}; } } diff --git a/tools/@angular/tsc-wrapped/src/schema.ts b/tools/@angular/tsc-wrapped/src/schema.ts index a40a7ebbb3724c..5aa008a9a29577 100644 --- a/tools/@angular/tsc-wrapped/src/schema.ts +++ b/tools/@angular/tsc-wrapped/src/schema.ts @@ -1,5 +1,17 @@ +// Metadata Schema + +// If you make a backwards incompatible change to the schema, increment the VERSION number. + +// If you make a backwards compatible change to the metadata (such as adding an option field) then +// leave VERSION the same. If possible, as many versions of the metadata that can represent the +// semantics of the file in an array. For example, when generating a version 2 file, if version 1 +// can accurately represent the metadata, generate both version 1 and version 2 in an array. + +export const VERSION = 1; + export interface ModuleMetadata { __symbolic: 'module'; + version: number; metadata: {[name: string]: (ClassMetadata | MetadataValue)}; } export function isModuleMetadata(value: any): value is ModuleMetadata {