From 724ca373e7adae2d405ada16217292fffecfbe2b Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Wed, 15 Feb 2017 13:30:40 -0800 Subject: [PATCH] build: produce metadata bundles for @angular modules (#14509) Closes #14509 --- integration/hello_world__closure/bundle.sh | 1 + modules/@angular/animation/index.ts | 12 +-- modules/@angular/animation/public_api.ts | 14 ++++ .../@angular/animation/tsconfig-build.json | 6 +- modules/@angular/common/index.ts | 12 ++- modules/@angular/common/public_api.ts | 16 ++++ modules/@angular/common/src/common.ts | 2 +- modules/@angular/common/src/common_module.ts | 4 +- modules/@angular/common/tsconfig-build.json | 6 +- .../integrationtest/test/test_summaries.ts | 5 +- .../@angular/compiler-cli/src/ngtools_impl.ts | 2 +- .../compiler/src/aot/static_reflector.ts | 81 ++++++++----------- .../src/aot/static_symbol_resolver.ts | 15 +++- .../compiler/test/aot/compiler_spec.ts | 62 ++++++++++++-- .../test/aot/static_reflector_spec.ts | 64 +++++++-------- .../@angular/compiler/test/aot/test_util.ts | 22 ++++- modules/@angular/core/index.ts | 12 ++- modules/@angular/core/public_api.ts | 16 ++++ modules/@angular/core/tsconfig-build.json | 6 +- modules/@angular/forms/index.ts | 12 ++- modules/@angular/forms/public_api.ts | 16 ++++ modules/@angular/forms/tsconfig-build.json | 6 +- modules/@angular/http/index.ts | 12 ++- modules/@angular/http/public_api.ts | 16 ++++ modules/@angular/http/tsconfig-build.json | 6 +- modules/@angular/router/index.ts | 12 ++- modules/@angular/router/public_api.ts | 16 ++++ modules/@angular/router/src/index.ts | 2 + .../router/src/router_config_loader.ts | 1 + modules/@angular/router/tsconfig-build.json | 6 +- modules/@angular/upgrade/public_api_static.ts | 21 +++++ modules/@angular/upgrade/static.ts | 17 ++-- modules/@angular/upgrade/tsconfig-build.json | 7 +- tools/public_api_guard/common/index.d.ts | 4 + tools/public_api_guard/router/index.d.ts | 3 + 35 files changed, 349 insertions(+), 166 deletions(-) create mode 100644 modules/@angular/animation/public_api.ts create mode 100644 modules/@angular/common/public_api.ts create mode 100644 modules/@angular/core/public_api.ts create mode 100644 modules/@angular/forms/public_api.ts create mode 100644 modules/@angular/http/public_api.ts create mode 100644 modules/@angular/router/public_api.ts create mode 100644 modules/@angular/upgrade/public_api_static.ts diff --git a/integration/hello_world__closure/bundle.sh b/integration/hello_world__closure/bundle.sh index 03dec2970e734..62383ec9b1c65 100755 --- a/integration/hello_world__closure/bundle.sh +++ b/integration/hello_world__closure/bundle.sh @@ -35,6 +35,7 @@ CLOSURE_ARGS=( node_modules/zone.js/dist/zone.js $(find -L vendor/rxjs -name *.js) node_modules/@angular/{core,common,compiler,platform-browser}/index.js + node_modules/@angular/{core,common}/public_api.js $(find node_modules/@angular/{core,common,compiler,platform-browser}/src -name *.js) "built/src/*.js" "--entry_point=./built/src/main" diff --git a/modules/@angular/animation/index.ts b/modules/@angular/animation/index.ts index fc890095d3039..05e6b19532d9e 100644 --- a/modules/@angular/animation/index.ts +++ b/modules/@angular/animation/index.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the animation package. - */ -export * from './src/animation'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production index.ts when it rewrites private symbol +// names. + +export * from './public_api'; diff --git a/modules/@angular/animation/public_api.ts b/modules/@angular/animation/public_api.ts new file mode 100644 index 0000000000000..fc890095d3039 --- /dev/null +++ b/modules/@angular/animation/public_api.ts @@ -0,0 +1,14 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the animation package. + */ +export * from './src/animation'; diff --git a/modules/@angular/animation/tsconfig-build.json b/modules/@angular/animation/tsconfig-build.json index 9ebb4ef4bf30c..c6e81e351c12d 100644 --- a/modules/@angular/animation/tsconfig-build.json +++ b/modules/@angular/animation/tsconfig-build.json @@ -20,12 +20,14 @@ "types": [] }, "files": [ - "index.ts", + "public_api.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts", "../../system.d.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "index", + "importAs": "@angular/animation" } } diff --git a/modules/@angular/common/index.ts b/modules/@angular/common/index.ts index a55ca93ed3a2e..05e6b19532d9e 100644 --- a/modules/@angular/common/index.ts +++ b/modules/@angular/common/index.ts @@ -6,11 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the common package. - */ -export * from './src/common'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production index.ts when it rewrites private symbol +// names. -// This file only reexports content of the `src` folder. Keep it that way. +export * from './public_api'; diff --git a/modules/@angular/common/public_api.ts b/modules/@angular/common/public_api.ts new file mode 100644 index 0000000000000..a55ca93ed3a2e --- /dev/null +++ b/modules/@angular/common/public_api.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the common package. + */ +export * from './src/common'; + +// This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/common/src/common.ts b/modules/@angular/common/src/common.ts index 822e288f5e096..22fb35d7aea47 100644 --- a/modules/@angular/common/src/common.ts +++ b/modules/@angular/common/src/common.ts @@ -13,7 +13,7 @@ */ export * from './location/index'; export {NgLocaleLocalization, NgLocalization} from './localization'; -export {CommonModule} from './common_module'; +export {CommonModule, DeprecatedCommonModule} from './common_module'; export {NgClass, NgFor, NgForOf, NgIf, NgPlural, NgPluralCase, NgStyle, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NgComponentOutlet} from './directives/index'; export {AsyncPipe, DatePipe, I18nPluralPipe, I18nSelectPipe, JsonPipe, LowerCasePipe, CurrencyPipe, DecimalPipe, PercentPipe, SlicePipe, UpperCasePipe, TitleCasePipe} from './pipes/index'; export {VERSION} from './version'; diff --git a/modules/@angular/common/src/common_module.ts b/modules/@angular/common/src/common_module.ts index 7c4bc29d10404..097e413e75920 100644 --- a/modules/@angular/common/src/common_module.ts +++ b/modules/@angular/common/src/common_module.ts @@ -32,7 +32,9 @@ export class CommonModule { /** * A module to contain deprecated directives. + * + * @deprecated */ @NgModule({declarations: [COMMON_DEPRECATED_DIRECTIVES], exports: [COMMON_DEPRECATED_DIRECTIVES]}) -export class CommonDeprecatedModule { +export class DeprecatedCommonModule { } \ No newline at end of file diff --git a/modules/@angular/common/tsconfig-build.json b/modules/@angular/common/tsconfig-build.json index 8c953c1d5985d..cfac872df33d9 100644 --- a/modules/@angular/common/tsconfig-build.json +++ b/modules/@angular/common/tsconfig-build.json @@ -20,11 +20,13 @@ "types": [] }, "files": [ - "index.ts", + "public_api.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "index", + "importAs": "@angular/common" } } diff --git a/modules/@angular/compiler-cli/integrationtest/test/test_summaries.ts b/modules/@angular/compiler-cli/integrationtest/test/test_summaries.ts index 4f064f2f9ce2a..1accf362741b2 100644 --- a/modules/@angular/compiler-cli/integrationtest/test/test_summaries.ts +++ b/modules/@angular/compiler-cli/integrationtest/test/test_summaries.ts @@ -31,8 +31,9 @@ function main() { class AssertingHostContext extends NodeCompilerHostContext { readFile(fileName: string): string { - if (/.*\/node_modules\/.*/.test(fileName) && !/.*ngsummary\.json$/.test(fileName)) { - // Only allow to read summaries from node_modules + if (/.*\/node_modules\/.*/.test(fileName) && !/.*ngsummary\.json$/.test(fileName) && + !/package\.json$/.test(fileName)) { + // Only allow to read summaries and package.json files from node_modules return null; } readFiles.push(path.relative(basePath, fileName)); diff --git a/modules/@angular/compiler-cli/src/ngtools_impl.ts b/modules/@angular/compiler-cli/src/ngtools_impl.ts index b956c6cb178c4..80be64a271283 100644 --- a/modules/@angular/compiler-cli/src/ngtools_impl.ts +++ b/modules/@angular/compiler-cli/src/ngtools_impl.ts @@ -17,7 +17,7 @@ import {NgModule} from '@angular/core'; // We cannot depend directly to @angular/router. type Route = any; -const ROUTER_MODULE_PATH = '@angular/router/src/router_config_loader'; +const ROUTER_MODULE_PATH = '@angular/router'; const ROUTER_ROUTES_SYMBOL_NAME = 'ROUTES'; diff --git a/modules/@angular/compiler/src/aot/static_reflector.ts b/modules/@angular/compiler/src/aot/static_reflector.ts index 6a0cc62496a0d..2e95c7dca15d3 100644 --- a/modules/@angular/compiler/src/aot/static_reflector.ts +++ b/modules/@angular/compiler/src/aot/static_reflector.ts @@ -14,15 +14,7 @@ import {syntaxError} from '../util'; import {StaticSymbol} from './static_symbol'; import {StaticSymbolResolver} from './static_symbol_resolver'; -const ANGULAR_IMPORT_LOCATIONS = { - coreDecorators: '@angular/core/src/metadata', - diDecorators: '@angular/core/src/di/metadata', - diMetadata: '@angular/core/src/di/metadata', - diInjectionToken: '@angular/core/src/di/injection_token', - diOpaqueToken: '@angular/core/src/di/injection_token', - animationMetadata: '@angular/core/src/animation/metadata', - provider: '@angular/core/src/di/provider' -}; +const ANGULAR_CORE = '@angular/core'; const HIDDEN_KEY = /^\$.*\$$/; @@ -241,56 +233,53 @@ export class StaticReflector implements ReflectorReader { } private initializeConversionMap(): void { - const {coreDecorators, diDecorators, diMetadata, diInjectionToken, - diOpaqueToken, animationMetadata, provider} = ANGULAR_IMPORT_LOCATIONS; - this.injectionToken = this.findDeclaration(diInjectionToken, 'InjectionToken'); - this.opaqueToken = this.findDeclaration(diInjectionToken, 'OpaqueToken'); + this.injectionToken = this.findDeclaration(ANGULAR_CORE, 'InjectionToken'); + this.opaqueToken = this.findDeclaration(ANGULAR_CORE, 'OpaqueToken'); - this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'Host'), Host); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), Host); this._registerDecoratorOrConstructor( - this.findDeclaration(diDecorators, 'Injectable'), Injectable); - this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'Self'), Self); - this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'SkipSelf'), SkipSelf); - this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'Inject'), Inject); - this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'Optional'), Optional); + this.findDeclaration(ANGULAR_CORE, 'Injectable'), Injectable); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), Self); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), SkipSelf); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Inject'), Inject); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Optional'), Optional); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'Attribute'), Attribute); + this.findDeclaration(ANGULAR_CORE, 'Attribute'), Attribute); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'ContentChild'), ContentChild); + this.findDeclaration(ANGULAR_CORE, 'ContentChild'), ContentChild); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'ContentChildren'), ContentChildren); + this.findDeclaration(ANGULAR_CORE, 'ContentChildren'), ContentChildren); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'ViewChild'), ViewChild); + this.findDeclaration(ANGULAR_CORE, 'ViewChild'), ViewChild); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'ViewChildren'), ViewChildren); - this._registerDecoratorOrConstructor(this.findDeclaration(coreDecorators, 'Input'), Input); - this._registerDecoratorOrConstructor(this.findDeclaration(coreDecorators, 'Output'), Output); - this._registerDecoratorOrConstructor(this.findDeclaration(coreDecorators, 'Pipe'), Pipe); + this.findDeclaration(ANGULAR_CORE, 'ViewChildren'), ViewChildren); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Input'), Input); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Output'), Output); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Pipe'), Pipe); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'HostBinding'), HostBinding); + this.findDeclaration(ANGULAR_CORE, 'HostBinding'), HostBinding); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'HostListener'), HostListener); + this.findDeclaration(ANGULAR_CORE, 'HostListener'), HostListener); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'Directive'), Directive); + this.findDeclaration(ANGULAR_CORE, 'Directive'), Directive); this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'Component'), Component); - this._registerDecoratorOrConstructor( - this.findDeclaration(coreDecorators, 'NgModule'), NgModule); + this.findDeclaration(ANGULAR_CORE, 'Component'), Component); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'NgModule'), NgModule); // Note: Some metadata classes can be used directly with Provider.deps. - this._registerDecoratorOrConstructor(this.findDeclaration(diMetadata, 'Host'), Host); - this._registerDecoratorOrConstructor(this.findDeclaration(diMetadata, 'Self'), Self); - this._registerDecoratorOrConstructor(this.findDeclaration(diMetadata, 'SkipSelf'), SkipSelf); - this._registerDecoratorOrConstructor(this.findDeclaration(diMetadata, 'Optional'), Optional); - - this._registerFunction(this.findDeclaration(animationMetadata, 'trigger'), trigger); - this._registerFunction(this.findDeclaration(animationMetadata, 'state'), state); - this._registerFunction(this.findDeclaration(animationMetadata, 'transition'), transition); - this._registerFunction(this.findDeclaration(animationMetadata, 'style'), style); - this._registerFunction(this.findDeclaration(animationMetadata, 'animate'), animate); - this._registerFunction(this.findDeclaration(animationMetadata, 'keyframes'), keyframes); - this._registerFunction(this.findDeclaration(animationMetadata, 'sequence'), sequence); - this._registerFunction(this.findDeclaration(animationMetadata, 'group'), group); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), Host); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), Self); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), SkipSelf); + this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Optional'), Optional); + + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'trigger'), trigger); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'state'), state); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'transition'), transition); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'style'), style); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'animate'), animate); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'keyframes'), keyframes); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'sequence'), sequence); + this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'group'), group); } /** diff --git a/modules/@angular/compiler/src/aot/static_symbol_resolver.ts b/modules/@angular/compiler/src/aot/static_symbol_resolver.ts index 3ba04262084e8..de8079499526a 100644 --- a/modules/@angular/compiler/src/aot/static_symbol_resolver.ts +++ b/modules/@angular/compiler/src/aot/static_symbol_resolver.ts @@ -202,9 +202,16 @@ export class StaticSymbolResolver { new Set(Object.keys(metadata['metadata']).map(unescapeIdentifier)); Object.keys(metadata['metadata']).forEach((metadataKey) => { const symbolMeta = metadata['metadata'][metadataKey]; - resolvedSymbols.push(this.createResolvedSymbol( - this.getStaticSymbol(filePath, unescapeIdentifier(metadataKey)), topLevelSymbolNames, - symbolMeta)); + const name = unescapeIdentifier(metadataKey); + const canonicalSymbol = this.getStaticSymbol(filePath, name); + if (metadata['importAs']) { + // Index bundle indexes should use the importAs module name instead of a reference + // to the .d.ts file directly. + const importSymbol = this.getStaticSymbol(metadata['importAs'], name); + this.recordImportAs(canonicalSymbol, importSymbol); + } + resolvedSymbols.push( + this.createResolvedSymbol(canonicalSymbol, topLevelSymbolNames, symbolMeta)); }); } @@ -372,7 +379,7 @@ export class StaticSymbolResolver { return this.host.moduleNameToFileName(module, containingFile); } catch (e) { console.error(`Could not resolve module '${module}' relative to file ${containingFile}`); - this.reportError(new e, null, containingFile); + this.reportError(e, null, containingFile); } } } diff --git a/modules/@angular/compiler/test/aot/compiler_spec.ts b/modules/@angular/compiler/test/aot/compiler_spec.ts index 144fd32d388ed..8196a6c04cce9 100644 --- a/modules/@angular/compiler/test/aot/compiler_spec.ts +++ b/modules/@angular/compiler/test/aot/compiler_spec.ts @@ -9,15 +9,18 @@ import {AotCompiler, AotCompilerHost, createAotCompiler} from '@angular/compiler'; import {RenderComponentType} from '@angular/core'; import {async} from '@angular/core/testing'; +import {MetadataBundler, MetadataCollector, ModuleMetadata, privateEntriesToIndex} from '@angular/tsc-wrapped'; import * as path from 'path'; import * as ts from 'typescript'; import {ReflectionCapabilities, reflector} from './private_import_core'; -import {EmittingCompilerHost, MockAotCompilerHost, MockCompilerHost, MockData, settings} from './test_util'; +import {EmittingCompilerHost, MockAotCompilerHost, MockCompilerHost, MockData, MockMetadataBundlerHost, settings} from './test_util'; const DTS = /\.d\.ts$/; const minCoreIndex = ` + export * from './src/application_module'; + export * from './src/change_detection'; export * from './src/metadata'; export * from './src/di/metadata'; export * from './src/di/injector'; @@ -28,7 +31,7 @@ const minCoreIndex = ` export * from './src/codegen_private_exports'; `; -describe('compiler', () => { +describe('compiler (unbundled Angular)', () => { let angularFiles: Map; beforeAll(() => { @@ -55,17 +58,64 @@ describe('compiler', () => { it('should compile', async(() => compile(host, aotHost, expectNoDiagnostics).then(generatedFiles => { expect(generatedFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileUrl))) - .not.toBeUndefined(); + .toBeDefined(); expect(generatedFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileUrl))) - .not.toBeUndefined(); + .toBeDefined(); }))); it('should compile using summaries', async(() => summaryCompile(host, aotHost).then(generatedFiles => { expect(generatedFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileUrl))) - .not.toBeUndefined(); + .toBeDefined(); expect(generatedFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileUrl))) - .not.toBeUndefined(); + .toBeDefined(); + }))); + }); +}); + +describe('compiler (bundled Angular)', () => { + let angularFiles: Map; + + beforeAll(() => { + const emittingHost = new EmittingCompilerHost(['@angular/core/index'], {emitMetadata: false}); + + // Create the metadata bundled + const indexModule = emittingHost.effectiveName('@angular/core/index'); + const bundler = new MetadataBundler( + indexModule, '@angular/core', new MockMetadataBundlerHost(emittingHost)); + const bundle = bundler.getMetadataBundle(); + const metadata = JSON.stringify(bundle.metadata, null, ' '); + const bundleIndexSource = privateEntriesToIndex('./index', bundle.privates); + emittingHost.override('@angular/core/bundle_index.ts', bundleIndexSource); + emittingHost.addWrittenFile( + '@angular/core/package.json', JSON.stringify({typings: 'bundle_index.d.ts'})); + emittingHost.addWrittenFile('@angular/core/bundle_index.metadata.json', metadata); + + // Emit the sources + const bundleIndexName = emittingHost.effectiveName('@angular/core/bundle_index.ts'); + const emittingProgram = ts.createProgram([bundleIndexName], settings, emittingHost); + emittingProgram.emit(); + angularFiles = emittingHost.written; + }); + + describe('Quickstart', () => { + let host: MockCompilerHost; + let aotHost: MockAotCompilerHost; + + beforeEach(() => { + host = new MockCompilerHost(QUICKSTART, FILES, angularFiles); + aotHost = new MockAotCompilerHost(host); + }); + + // Restore reflector since AoT compiler will update it with a new static reflector + afterEach(() => { reflector.updateCapabilities(new ReflectionCapabilities()); }); + + it('should compile', + async(() => compile(host, aotHost, expectNoDiagnostics).then(generatedFiles => { + expect(generatedFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileUrl))) + .toBeDefined(); + expect(generatedFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileUrl))) + .toBeDefined(); }))); }); }); diff --git a/modules/@angular/compiler/test/aot/static_reflector_spec.ts b/modules/@angular/compiler/test/aot/static_reflector_spec.ts index 037969c5eb039..0c6832780d5d1 100644 --- a/modules/@angular/compiler/test/aot/static_reflector_spec.ts +++ b/modules/@angular/compiler/test/aot/static_reflector_spec.ts @@ -44,14 +44,10 @@ describe('StaticReflector', () => { it('should get constructor for NgFor', () => { const NgFor = reflector.findDeclaration('@angular/common/src/directives/ng_for', 'NgFor'); - const ViewContainerRef = reflector.findDeclaration( - '@angular/core/src/linker/view_container_ref', 'ViewContainerRef'); - const TemplateRef = - reflector.findDeclaration('@angular/core/src/linker/template_ref', 'TemplateRef'); - const IterableDiffers = reflector.findDeclaration( - '@angular/core/src/change_detection/differs/iterable_differs', 'IterableDiffers'); - const ChangeDetectorRef = reflector.findDeclaration( - '@angular/core/src/change_detection/change_detector_ref', 'ChangeDetectorRef'); + const ViewContainerRef = reflector.findDeclaration('@angular/core', 'ViewContainerRef'); + const TemplateRef = reflector.findDeclaration('@angular/core', 'TemplateRef'); + const IterableDiffers = reflector.findDeclaration('@angular/core', 'IterableDiffers'); + const ChangeDetectorRef = reflector.findDeclaration('@angular/core', 'ChangeDetectorRef'); const parameters = reflector.parameters(NgFor); expect(parameters).toEqual([ @@ -732,7 +728,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic': 'reference', 'name': 'Directive', - 'module': '@angular/core/src/metadata' + 'module': '@angular/core' }, 'arguments': [ { @@ -749,22 +745,22 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'parameters': [ { '__symbolic': 'reference', - 'module': '@angular/core/src/linker/view_container_ref', + 'module': '@angular/core', 'name': 'ViewContainerRef' }, { '__symbolic': 'reference', - 'module': '@angular/core/src/linker/template_ref', + 'module': '@angular/core', 'name': 'TemplateRef' }, { '__symbolic': 'reference', - 'module': '@angular/core/src/change_detection/differs/iterable_differs', + 'module': '@angular/core', 'name': 'IterableDiffers' }, { '__symbolic': 'reference', - 'module': '@angular/core/src/change_detection/change_detector_ref', + 'module': '@angular/core', 'name': 'ChangeDetectorRef' } ] @@ -794,7 +790,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic': 'reference', 'name': 'Component', - 'module': '@angular/core/src/metadata' + 'module': '@angular/core' }, 'arguments': [ { @@ -806,7 +802,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic': 'reference', 'name': 'trigger', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments': [ 'myAnimation', @@ -814,7 +810,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic': 'reference', 'name': 'state', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments': [ 'state1', @@ -822,7 +818,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic': 'reference', 'name': 'style', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments': [ { 'background':'white' } @@ -834,7 +830,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic':'reference', 'name':'transition', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments': [ '* => *', @@ -843,20 +839,20 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression':{ '__symbolic':'reference', 'name':'sequence', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments':[[{ '__symbolic': 'call', 'expression': { '__symbolic':'reference', 'name':'group', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments':[[{ '__symbolic': 'call', 'expression': { '__symbolic':'reference', 'name':'animate', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments':[ '1s 0.5s', @@ -864,13 +860,13 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic':'reference', 'name':'keyframes', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments':[[{ '__symbolic': 'call', 'expression': { '__symbolic':'reference', 'name':'style', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments':[ { 'background': 'blue'} ] }, { @@ -878,7 +874,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic':'reference', 'name':'style', - 'module': '@angular/core/src/animation/metadata' + 'module': '@angular/core' }, 'arguments':[ { 'background': 'red'} ] }]] @@ -904,7 +900,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { 'expression': { '__symbolic': 'reference', 'name': 'Input', - 'module': '@angular/core/src/metadata' + 'module': '@angular/core' } } ] @@ -918,7 +914,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { '__symbolic': 'call', 'expression': { '__symbolic': 'reference', - 'module': '@angular/core/src/metadata', + 'module': '@angular/core', 'name': 'HostListener' }, 'arguments': [ @@ -948,7 +944,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { expression: { __symbolic: 'reference', name: 'Component', - module: '@angular/core/src/metadata' + module: '@angular/core' }, arguments: [ { @@ -1149,7 +1145,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { `, '/tmp/src/invalid-calls.ts': ` import {someFunction} from './nvalid-calll-definitions.ts'; - import {Component} from '@angular/core/src/metadata'; + import {Component} from '@angular/core'; import {NgIf} from '@angular/common'; @Component({ @@ -1193,7 +1189,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { } `, '/tmp/src/static-method-call.ts': ` - import {Component} from '@angular/core/src/metadata'; + import {Component} from '@angular/core'; import {MyModule} from './static-method'; @Component({ @@ -1225,7 +1221,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { } `, '/tmp/src/static-field-reference.ts': ` - import {Component} from '@angular/core/src/metadata'; + import {Component} from '@angular/core'; import {MyModule} from './static-field'; @Component({ @@ -1239,7 +1235,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { } `, '/tmp/src/static-method-ref.ts': ` - import {Component} from '@angular/core/src/metadata'; + import {Component} from '@angular/core'; import {ClassWithStatics} from './static-method-def'; @Component({ @@ -1250,7 +1246,7 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { } `, '/tmp/src/invalid-metadata.ts': ` - import {Component} from '@angular/core/src/metadata'; + import {Component} from '@angular/core'; @Component({ providers: [ { provider: 'a', useValue: (() => 1)() }] @@ -1259,8 +1255,8 @@ const DEFAULT_TEST_DATA: {[key: string]: any} = { `, '/tmp/src/forward-ref.ts': ` import {forwardRef} from '@angular/core'; - import {Component} from '@angular/core/src/metadata'; - import {Inject} from '@angular/core/src/di/metadata'; + import {Component} from '@angular/core'; + import {Inject} from '@angular/core'; @Component({}) export class Forward { constructor(@Inject(forwardRef(() => Dep)) d: Dep) {} diff --git a/modules/@angular/compiler/test/aot/test_util.ts b/modules/@angular/compiler/test/aot/test_util.ts index 21297cf70467c..6c3173aaddf12 100644 --- a/modules/@angular/compiler/test/aot/test_util.ts +++ b/modules/@angular/compiler/test/aot/test_util.ts @@ -7,7 +7,7 @@ */ import {AotCompilerHost} from '@angular/compiler'; -import {MetadataCollector} from '@angular/tsc-wrapped'; +import {MetadataBundlerHost, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped'; import * as fs from 'fs'; import * as path from 'path'; import * as ts from 'typescript'; @@ -216,12 +216,15 @@ export class MockCompilerHost implements ts.CompilerHost { } const effectiveName = this.getEffectiveName(fileName); if (effectiveName == fileName) { - return open(fileName, this.data) != null; + let result = open(fileName, this.data) != null; + return result; } else { if (fileName.match(rxjs)) { - return fs.existsSync(effectiveName); + let result = fs.existsSync(effectiveName); + return result; } - return this.angular.has(effectiveName); + let result = this.angular.has(effectiveName); + return result; } } @@ -389,6 +392,17 @@ export class MockAotCompilerHost implements AotCompilerHost { } } +export class MockMetadataBundlerHost implements MetadataBundlerHost { + private collector = new MetadataCollector(); + + constructor(private host: ts.CompilerHost) {} + + getMetadataFor(moduleName: string): ModuleMetadata { + const source = this.host.getSourceFile(moduleName + '.ts', ts.ScriptTarget.Latest); + return this.collector.getMetadata(source); + } +} + function find(fileName: string, data: MockData): MockData|undefined { let names = fileName.split('/'); if (names.length && !names[0].length) names.shift(); diff --git a/modules/@angular/core/index.ts b/modules/@angular/core/index.ts index ede07620542ff..05e6b19532d9e 100644 --- a/modules/@angular/core/index.ts +++ b/modules/@angular/core/index.ts @@ -6,11 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the core package. - */ -export * from './src/core'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production index.ts when it rewrites private symbol +// names. -// This file only reexports content of the `src` folder. Keep it that way. +export * from './public_api'; diff --git a/modules/@angular/core/public_api.ts b/modules/@angular/core/public_api.ts new file mode 100644 index 0000000000000..ede07620542ff --- /dev/null +++ b/modules/@angular/core/public_api.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the core package. + */ +export * from './src/core'; + +// This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/core/tsconfig-build.json b/modules/@angular/core/tsconfig-build.json index 5df46a0390426..c95f8fbdd7a00 100644 --- a/modules/@angular/core/tsconfig-build.json +++ b/modules/@angular/core/tsconfig-build.json @@ -20,12 +20,14 @@ "types": [] }, "files": [ - "index.ts", + "public_api.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts", "../../system.d.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "index", + "importAs": "@angular/core" } } diff --git a/modules/@angular/forms/index.ts b/modules/@angular/forms/index.ts index 31f3a8859895d..05e6b19532d9e 100644 --- a/modules/@angular/forms/index.ts +++ b/modules/@angular/forms/index.ts @@ -6,11 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the forms package. - */ -export * from './src/forms'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production index.ts when it rewrites private symbol +// names. -// This file only reexports content of the `src` folder. Keep it that way. +export * from './public_api'; diff --git a/modules/@angular/forms/public_api.ts b/modules/@angular/forms/public_api.ts new file mode 100644 index 0000000000000..31f3a8859895d --- /dev/null +++ b/modules/@angular/forms/public_api.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the forms package. + */ +export * from './src/forms'; + +// This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/forms/tsconfig-build.json b/modules/@angular/forms/tsconfig-build.json index fc43e15c1df04..18572944984cc 100644 --- a/modules/@angular/forms/tsconfig-build.json +++ b/modules/@angular/forms/tsconfig-build.json @@ -25,11 +25,13 @@ "types": [] }, "files": [ - "index.ts", + "public_api.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "index", + "importAs": "@angular/forms" } } diff --git a/modules/@angular/http/index.ts b/modules/@angular/http/index.ts index 80106781e7fc7..05e6b19532d9e 100644 --- a/modules/@angular/http/index.ts +++ b/modules/@angular/http/index.ts @@ -6,11 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the http package. - */ -export * from './src/index'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production index.ts when it rewrites private symbol +// names. -// This file only reexports content of the `src` folder. Keep it that way. +export * from './public_api'; diff --git a/modules/@angular/http/public_api.ts b/modules/@angular/http/public_api.ts new file mode 100644 index 0000000000000..80106781e7fc7 --- /dev/null +++ b/modules/@angular/http/public_api.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the http package. + */ +export * from './src/index'; + +// This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/http/tsconfig-build.json b/modules/@angular/http/tsconfig-build.json index 588945c8adc35..dd4fb45d72fd1 100644 --- a/modules/@angular/http/tsconfig-build.json +++ b/modules/@angular/http/tsconfig-build.json @@ -20,11 +20,13 @@ "lib": ["es2015", "dom"] }, "files": [ - "index.ts", + "public_api.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "index", + "importAs": "@angular/http" } } diff --git a/modules/@angular/router/index.ts b/modules/@angular/router/index.ts index ca4239ecf2baa..05e6b19532d9e 100644 --- a/modules/@angular/router/index.ts +++ b/modules/@angular/router/index.ts @@ -6,11 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the router package. - */ -export * from './src/index'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production index.ts when it rewrites private symbol +// names. -// This file only reexports content of the `src` folder. Keep it that way. +export * from './public_api'; diff --git a/modules/@angular/router/public_api.ts b/modules/@angular/router/public_api.ts new file mode 100644 index 0000000000000..ca4239ecf2baa --- /dev/null +++ b/modules/@angular/router/public_api.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the router package. + */ +export * from './src/index'; + +// This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/router/src/index.ts b/modules/@angular/router/src/index.ts index 85b2f112be1ee..ff8d5ebd8b611 100644 --- a/modules/@angular/router/src/index.ts +++ b/modules/@angular/router/src/index.ts @@ -14,6 +14,7 @@ export {RouterOutlet} from './directives/router_outlet'; export {CanActivate, CanActivateChild, CanDeactivate, CanLoad, Resolve} from './interfaces'; export {DetachedRouteHandle, RouteReuseStrategy} from './route_reuse_strategy'; export {Event, NavigationCancel, NavigationEnd, NavigationError, NavigationExtras, NavigationStart, Router, RoutesRecognized} from './router'; +export {ROUTES} from './router_config_loader'; export {ExtraOptions, ROUTER_CONFIGURATION, ROUTER_INITIALIZER, RouterModule, provideRoutes} from './router_module'; export {RouterOutletMap} from './router_outlet_map'; export {NoPreloading, PreloadAllModules, PreloadingStrategy, RouterPreloader} from './router_preloader'; @@ -22,4 +23,5 @@ export {PRIMARY_OUTLET, Params} from './shared'; export {UrlHandlingStrategy} from './url_handling_strategy'; export {DefaultUrlSerializer, UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree} from './url_tree'; export {VERSION} from './version'; + export * from './private_export' diff --git a/modules/@angular/router/src/router_config_loader.ts b/modules/@angular/router/src/router_config_loader.ts index 361e8127001ea..e05ffd32a81f6 100644 --- a/modules/@angular/router/src/router_config_loader.ts +++ b/modules/@angular/router/src/router_config_loader.ts @@ -18,6 +18,7 @@ import {flatten, wrapIntoObservable} from './utils/collection'; /** + * @docsNotRequired * @experimental */ export const ROUTES = new InjectionToken('ROUTES'); diff --git a/modules/@angular/router/tsconfig-build.json b/modules/@angular/router/tsconfig-build.json index cc73e83d247e6..2f8a57f1b7114 100644 --- a/modules/@angular/router/tsconfig-build.json +++ b/modules/@angular/router/tsconfig-build.json @@ -24,10 +24,12 @@ "skipLibCheck": true }, "files": [ - "index.ts" + "public_api.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "index", + "importAs": "@angular/router" } } diff --git a/modules/@angular/upgrade/public_api_static.ts b/modules/@angular/upgrade/public_api_static.ts new file mode 100644 index 0000000000000..57b16cedc64c4 --- /dev/null +++ b/modules/@angular/upgrade/public_api_static.ts @@ -0,0 +1,21 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * @module + * @description + * Entry point for all public APIs of the upgrade/static package, allowing + * Angular 1 and Angular 2+ to run side by side in the same application. + */ +export {downgradeComponent} from './src/common/downgrade_component'; +export {downgradeInjectable} from './src/common/downgrade_injectable'; +export {VERSION} from './src/common/version'; +export {UpgradeComponent} from './src/static/upgrade_component'; +export {UpgradeModule} from './src/static/upgrade_module'; + +// This file only re-exports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/upgrade/static.ts b/modules/@angular/upgrade/static.ts index 57b16cedc64c4..30dcc522fceb9 100644 --- a/modules/@angular/upgrade/static.ts +++ b/modules/@angular/upgrade/static.ts @@ -6,16 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -/** - * @module - * @description - * Entry point for all public APIs of the upgrade/static package, allowing - * Angular 1 and Angular 2+ to run side by side in the same application. - */ -export {downgradeComponent} from './src/common/downgrade_component'; -export {downgradeInjectable} from './src/common/downgrade_injectable'; -export {VERSION} from './src/common/version'; -export {UpgradeComponent} from './src/static/upgrade_component'; -export {UpgradeModule} from './src/static/upgrade_module'; +// This file is not used to build this module. It is only used during editing +// by the TypeScript language serivce and during build for verifcation. `ngc` +// replaces this file with production static.ts when it rewrites private symbol +// names. -// This file only re-exports content of the `src` folder. Keep it that way. +export * from './public_api_static'; diff --git a/modules/@angular/upgrade/tsconfig-build.json b/modules/@angular/upgrade/tsconfig-build.json index 521c759061552..4a3c22b70314b 100644 --- a/modules/@angular/upgrade/tsconfig-build.json +++ b/modules/@angular/upgrade/tsconfig-build.json @@ -24,12 +24,15 @@ "types": [] }, "files": [ + "public_api_static.ts", "index.ts", - "static.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts" ], "angularCompilerOptions": { "annotateForClosureCompiler": true, - "strictMetadataEmit": true + "strictMetadataEmit": true, + "bundleIndex": "static", + "libraryIndex": "./public_api_static", + "importAs": "@angular/upgrade/static" } } diff --git a/tools/public_api_guard/common/index.d.ts b/tools/public_api_guard/common/index.d.ts index 5a81a9b079df9..28b42cdda2f4b 100644 --- a/tools/public_api_guard/common/index.d.ts +++ b/tools/public_api_guard/common/index.d.ts @@ -32,6 +32,10 @@ export declare class DecimalPipe implements PipeTransform { transform(value: any, digits?: string): string; } +/** @deprecated */ +export declare class DeprecatedCommonModule { +} + /** @stable */ export declare class HashLocationStrategy extends LocationStrategy { constructor(_platformLocation: PlatformLocation, _baseHref?: string); diff --git a/tools/public_api_guard/router/index.d.ts b/tools/public_api_guard/router/index.d.ts index c1a716109f949..586486d80db41 100644 --- a/tools/public_api_guard/router/index.d.ts +++ b/tools/public_api_guard/router/index.d.ts @@ -345,6 +345,9 @@ export declare class RouterStateSnapshot extends Tree { /** @stable */ export declare type Routes = Route[]; +/** @experimental */ +export declare const ROUTES: InjectionToken; + /** @stable */ export declare class RoutesRecognized { id: number;