From a26dd28bdb6ad3e5ac07080a629cdf9ea7980aee Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 20 Oct 2016 19:35:35 -0700 Subject: [PATCH] refactor(upgrade): re-export the new static upgrade APIs on new entry Add upgrade-static.umd.js bundles This allows depending on it without getting a transitive dependency on compiler. BREAKING CHANGE: Four newly added APIs in 2.2.0-beta: downgradeComponent, downgradeInjectable, UpgradeComponent, and UpgradeModule are no longer exported by @angular/upgrade. Import these from @angular/upgrade/static instead. --- build.sh | 14 +++++++++++ gulpfile.js | 1 + modules/@angular/upgrade/index.ts | 1 - .../@angular/upgrade/rollup-static.config.js | 15 ++++++++++++ modules/@angular/upgrade/src/aot.ts | 12 ---------- modules/@angular/upgrade/static.ts | 13 +++++++++++ .../aot/integration/change_detection_spec.ts | 4 ++-- .../integration/content_projection_spec.ts | 2 +- .../integration/downgrade_component_spec.ts | 4 ++-- .../test/aot/integration/examples_spec.ts | 4 ++-- .../test/aot/integration/injection_spec.ts | 4 ++-- .../test/aot/integration/testability_spec.ts | 4 ++-- .../aot/integration/upgrade_component_spec.ts | 4 ++-- .../@angular/upgrade/test/aot/test_helpers.ts | 2 +- modules/@angular/upgrade/tsconfig-build.json | 1 + modules/playground/src/bootstrap.ts | 1 + tools/public_api_guard/upgrade/index.d.ts | 23 ------------------- tools/public_api_guard/upgrade/static.d.ts | 22 ++++++++++++++++++ 18 files changed, 81 insertions(+), 50 deletions(-) create mode 100644 modules/@angular/upgrade/rollup-static.config.js delete mode 100644 modules/@angular/upgrade/src/aot.ts create mode 100644 modules/@angular/upgrade/static.ts create mode 100644 tools/public_api_guard/upgrade/static.d.ts diff --git a/build.sh b/build.sh index 98c2cc17ce..17c7c63b11 100755 --- a/build.sh +++ b/build.sh @@ -101,7 +101,9 @@ do DESTDIR=${PWD}/dist/packages-dist/${PACKAGE} UMD_ES5_PATH=${DESTDIR}/bundles/${PACKAGE}.umd.js UMD_TESTING_ES5_PATH=${DESTDIR}/bundles/${PACKAGE}-testing.umd.js + UMD_STATIC_ES5_PATH=${DESTDIR}/bundles/${PACKAGE}-static.umd.js UMD_ES5_MIN_PATH=${DESTDIR}/bundles/${PACKAGE}.umd.min.js + UMD_STATIC_ES5_MIN_PATH=${DESTDIR}/bundles/${PACKAGE}-static.umd.min.js LICENSE_BANNER=${PWD}/modules/@angular/license-banner.txt rm -rf ${DESTDIR} @@ -157,6 +159,18 @@ do cat ${UMD_TESTING_ES5_PATH} >> ${UMD_TESTING_ES5_PATH}.tmp mv ${UMD_TESTING_ES5_PATH}.tmp ${UMD_TESTING_ES5_PATH} fi + + if [[ -e rollup-static.config.js ]]; then + echo "====== Rollup ${PACKAGE} static" + ../../../node_modules/.bin/rollup -c rollup-static.config.js + # create dir because it doesn't exist yet, we should move the src code here and remove this line + mkdir ${DESTDIR}/static + echo "{\"main\": \"../bundles/${PACKAGE}-static.umd.js\"}" > ${DESTDIR}/static/package.json + cat ${LICENSE_BANNER} > ${UMD_STATIC_ES5_PATH}.tmp + cat ${UMD_STATIC_ES5_PATH} >> ${UMD_STATIC_ES5_PATH}.tmp + mv ${UMD_STATIC_ES5_PATH}.tmp ${UMD_STATIC_ES5_PATH} + $UGLIFYJS -c --screw-ie8 --comments -o ${UMD_STATIC_ES5_MIN_PATH} ${UMD_STATIC_ES5_PATH} + fi ) 2>&1 | grep -v "as external dependency" fi diff --git a/gulpfile.js b/gulpfile.js index ce41eeeb29..cd536663cc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -58,6 +58,7 @@ const entrypoints = [ //'dist/packages-dist/compiler/index.d.ts', //'dist/packages-dist/compiler/testing.d.ts', 'dist/packages-dist/upgrade/index.d.ts', + 'dist/packages-dist/upgrade/static.d.ts', 'dist/packages-dist/platform-browser/index.d.ts', 'dist/packages-dist/platform-browser/testing/index.d.ts', 'dist/packages-dist/platform-browser-dynamic/index.d.ts', diff --git a/modules/@angular/upgrade/index.ts b/modules/@angular/upgrade/index.ts index cc37fbd7fe..f051a03df0 100644 --- a/modules/@angular/upgrade/index.ts +++ b/modules/@angular/upgrade/index.ts @@ -12,5 +12,4 @@ * Entry point for all public APIs of the upgrade package. */ export * from './src/upgrade'; -export * from './src/aot'; // This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/upgrade/rollup-static.config.js b/modules/@angular/upgrade/rollup-static.config.js new file mode 100644 index 0000000000..a69138c84e --- /dev/null +++ b/modules/@angular/upgrade/rollup-static.config.js @@ -0,0 +1,15 @@ +/** + * @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 + */ + +export default { + entry: '../../../dist/packages-dist/upgrade/static.js', + dest: '../../../dist/packages-dist/upgrade/bundles/upgrade-static.umd.js', + format: 'umd', + moduleName: 'ng.upgrade.static', + globals: {'@angular/core': 'ng.core'} +}; diff --git a/modules/@angular/upgrade/src/aot.ts b/modules/@angular/upgrade/src/aot.ts deleted file mode 100644 index b50bda36cb..0000000000 --- a/modules/@angular/upgrade/src/aot.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @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 - */ - -export {downgradeComponent} from './aot/downgrade_component'; -export {downgradeInjectable} from './aot/downgrade_injectable'; -export {UpgradeComponent} from './aot/upgrade_component'; -export {UpgradeModule} from './aot/upgrade_module'; diff --git a/modules/@angular/upgrade/static.ts b/modules/@angular/upgrade/static.ts new file mode 100644 index 0000000000..2962deb867 --- /dev/null +++ b/modules/@angular/upgrade/static.ts @@ -0,0 +1,13 @@ +/** + * @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 + */ + +export {downgradeComponent} from './src/aot/downgrade_component'; +export {downgradeInjectable} from './src/aot/downgrade_injectable'; +export {UpgradeComponent} from './src/aot/upgrade_component'; +export {UpgradeModule} from './src/aot/upgrade_module'; +// This file only reexports content of the `src` folder. Keep it that way. diff --git a/modules/@angular/upgrade/test/aot/integration/change_detection_spec.ts b/modules/@angular/upgrade/test/aot/integration/change_detection_spec.ts index 876e20ecf6..39aa1125df 100644 --- a/modules/@angular/upgrade/test/aot/integration/change_detection_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/change_detection_spec.ts @@ -10,8 +10,8 @@ import {Component, Directive, ElementRef, Injector, NgModule, destroyPlatform} f import {async} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static'; import {bootstrap, html} from '../test_helpers'; @@ -77,4 +77,4 @@ export function main() { }); })); }); -} \ No newline at end of file +} diff --git a/modules/@angular/upgrade/test/aot/integration/content_projection_spec.ts b/modules/@angular/upgrade/test/aot/integration/content_projection_spec.ts index 4a37258be6..7c48ac8b46 100644 --- a/modules/@angular/upgrade/test/aot/integration/content_projection_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/content_projection_spec.ts @@ -10,8 +10,8 @@ import {Component, Directive, ElementRef, Injector, NgModule, destroyPlatform} f import {async} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static'; import {bootstrap, html} from '../test_helpers'; diff --git a/modules/@angular/upgrade/test/aot/integration/downgrade_component_spec.ts b/modules/@angular/upgrade/test/aot/integration/downgrade_component_spec.ts index 861c8ba418..d06455c66e 100644 --- a/modules/@angular/upgrade/test/aot/integration/downgrade_component_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/downgrade_component_spec.ts @@ -10,8 +10,8 @@ import {Component, EventEmitter, NgModule, OnChanges, OnDestroy, SimpleChanges, import {async} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeModule, downgradeComponent} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeModule, downgradeComponent} from '@angular/upgrade/static'; import {bootstrap, html, multiTrim} from '../test_helpers'; @@ -256,4 +256,4 @@ export function main() { }); })); }); -} \ No newline at end of file +} diff --git a/modules/@angular/upgrade/test/aot/integration/examples_spec.ts b/modules/@angular/upgrade/test/aot/integration/examples_spec.ts index 6c847c4a31..16668c821d 100644 --- a/modules/@angular/upgrade/test/aot/integration/examples_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/examples_spec.ts @@ -10,8 +10,8 @@ import {Component, Directive, ElementRef, Injector, Input, NgModule, destroyPlat import {async} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static'; import {bootstrap, html, multiTrim} from '../test_helpers'; @@ -86,4 +86,4 @@ export function main() { }); })); }); -} \ No newline at end of file +} diff --git a/modules/@angular/upgrade/test/aot/integration/injection_spec.ts b/modules/@angular/upgrade/test/aot/integration/injection_spec.ts index 7a818c4fde..f41c723dba 100644 --- a/modules/@angular/upgrade/test/aot/integration/injection_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/injection_spec.ts @@ -10,8 +10,8 @@ import {NgModule, OpaqueToken, destroyPlatform} from '@angular/core'; import {async} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeModule, downgradeInjectable} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeModule, downgradeInjectable} from '@angular/upgrade/static'; import {bootstrap, html} from '../test_helpers'; @@ -77,4 +77,4 @@ export function main() { }); })); }); -} \ No newline at end of file +} diff --git a/modules/@angular/upgrade/test/aot/integration/testability_spec.ts b/modules/@angular/upgrade/test/aot/integration/testability_spec.ts index 991b84882e..11cfb065a3 100644 --- a/modules/@angular/upgrade/test/aot/integration/testability_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/testability_spec.ts @@ -10,8 +10,8 @@ import {NgModule, Testability, destroyPlatform} from '@angular/core'; import {fakeAsync, tick} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeModule} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeModule} from '@angular/upgrade/static'; import {bootstrap, html} from '../test_helpers'; @@ -68,4 +68,4 @@ export function main() { }); })); }); -} \ No newline at end of file +} diff --git a/modules/@angular/upgrade/test/aot/integration/upgrade_component_spec.ts b/modules/@angular/upgrade/test/aot/integration/upgrade_component_spec.ts index c489529859..a1db845dfa 100644 --- a/modules/@angular/upgrade/test/aot/integration/upgrade_component_spec.ts +++ b/modules/@angular/upgrade/test/aot/integration/upgrade_component_spec.ts @@ -10,8 +10,8 @@ import {Component, Directive, ElementRef, EventEmitter, Injector, Input, NO_ERRO import {async, fakeAsync, tick} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; -import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static'; import {bootstrap, html, multiTrim} from '../test_helpers'; @@ -1561,4 +1561,4 @@ export function main() { // }); // })); }); -} \ No newline at end of file +} diff --git a/modules/@angular/upgrade/test/aot/test_helpers.ts b/modules/@angular/upgrade/test/aot/test_helpers.ts index ac9e271549..202f4f098b 100644 --- a/modules/@angular/upgrade/test/aot/test_helpers.ts +++ b/modules/@angular/upgrade/test/aot/test_helpers.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ import {PlatformRef, Type} from '@angular/core'; -import {UpgradeModule} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; +import {UpgradeModule} from '@angular/upgrade/static'; export function bootstrap( platform: PlatformRef, Ng2Module: Type<{}>, element: Element, ng1Module: angular.IModule) { diff --git a/modules/@angular/upgrade/tsconfig-build.json b/modules/@angular/upgrade/tsconfig-build.json index 7692373f4a..00eddc703e 100644 --- a/modules/@angular/upgrade/tsconfig-build.json +++ b/modules/@angular/upgrade/tsconfig-build.json @@ -23,6 +23,7 @@ }, "files": [ "index.ts", + "static.ts", "../../../node_modules/zone.js/dist/zone.js.d.ts" ], "angularCompilerOptions": { diff --git a/modules/playground/src/bootstrap.ts b/modules/playground/src/bootstrap.ts index b93fac0fd4..7f5824e7e9 100644 --- a/modules/playground/src/bootstrap.ts +++ b/modules/playground/src/bootstrap.ts @@ -39,6 +39,7 @@ '/packages-dist/platform-webworker-dynamic/bundles/platform-webworker-dynamic.umd.js', '@angular/router': '/packages-dist/router/bundles/router.umd.js', '@angular/upgrade': '/packages-dist/upgrade/bundles/upgrade.umd.js', + '@angular/upgrade/static': '/packages-dist/upgrade/bundles/upgrade-static.umd.js', 'rxjs': '/all/playground/vendor/rxjs', // TODO(i): remove once playground apps no longer use facades directly diff --git a/tools/public_api_guard/upgrade/index.d.ts b/tools/public_api_guard/upgrade/index.d.ts index 3e82448ee0..33ef4ab993 100644 --- a/tools/public_api_guard/upgrade/index.d.ts +++ b/tools/public_api_guard/upgrade/index.d.ts @@ -1,9 +1,3 @@ -/** @experimental */ -export declare function downgradeComponent(info: ComponentInfo): angular.IInjectable; - -/** @experimental */ -export declare function downgradeInjectable(token: any): (string | ((i: Injector) => any))[]; - /** @stable */ export declare class UpgradeAdapter { constructor(ng2AppModule: Type, compilerOptions?: CompilerOptions); @@ -25,20 +19,3 @@ export declare class UpgradeAdapterRef { dispose(): void; ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void): void; } - -/** @experimental */ -export declare class UpgradeComponent implements OnInit, OnChanges, DoCheck { - constructor(name: string, elementRef: ElementRef, injector: Injector); - ngDoCheck(): void; - ngOnChanges(changes: SimpleChanges): void; - ngOnInit(): void; -} - -/** @experimental */ -export declare class UpgradeModule { - $injector: angular.IInjectorService; - injector: Injector; - ngZone: NgZone; - constructor(injector: Injector, ngZone: NgZone); - bootstrap(element: Element, modules?: string[], config?: angular.IAngularBootstrapConfig): void; -} diff --git a/tools/public_api_guard/upgrade/static.d.ts b/tools/public_api_guard/upgrade/static.d.ts new file mode 100644 index 0000000000..49ff6cdf48 --- /dev/null +++ b/tools/public_api_guard/upgrade/static.d.ts @@ -0,0 +1,22 @@ +/** @experimental */ +export declare function downgradeComponent(info: ComponentInfo): angular.IInjectable; + +/** @experimental */ +export declare function downgradeInjectable(token: any): (string | ((i: Injector) => any))[]; + +/** @experimental */ +export declare class UpgradeComponent implements OnInit, OnChanges, DoCheck { + constructor(name: string, elementRef: ElementRef, injector: Injector); + ngDoCheck(): void; + ngOnChanges(changes: SimpleChanges): void; + ngOnInit(): void; +} + +/** @experimental */ +export declare class UpgradeModule { + $injector: angular.IInjectorService; + injector: Injector; + ngZone: NgZone; + constructor(injector: Injector, ngZone: NgZone); + bootstrap(element: Element, modules?: string[], config?: angular.IAngularBootstrapConfig): void; +}