From 84bf1aa29ab236df246c2353975a8d802ef1e60f Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Wed, 1 Jul 2020 17:16:50 -0700 Subject: [PATCH 01/12] feat(angular): support for v10 --- build/pack-scripts/pack-scoped.ts | 24 +- build/pack-scripts/tsconfig.json | 2 +- e2e/animation-examples/app/app.module.ts | 2 +- e2e/animation-examples/app/app.routing.ts | 2 +- .../app/hero/hero-routing.module.ts | 2 +- .../app/hero/hero.module.ts | 2 +- e2e/animation-examples/app/main.aot.ts | 4 - e2e/animation-examples/app/main.ts | 7 +- e2e/animation-examples/app/vendor.ts | 17 - e2e/animation-examples/package.json | 53 +- e2e/modal-navigation-ng/app/main.aot.ts | 9 - e2e/modal-navigation-ng/package.json | 2 +- e2e/nested-router-tab-view/app/main.aot.ts | 7 - e2e/nested-router-tab-view/package.json | 2 +- e2e/renderer/app/main.aot.ts | 4 - e2e/renderer/package.json | 3 +- e2e/routable-animations/app/app.module.ts | 4 +- e2e/routable-animations/app/main.aot.ts | 4 - e2e/routable-animations/package.json | 1 - e2e/router-tab-view/app/main.aot.ts | 7 - e2e/router/package.json | 3 +- e2e/single-page/app/main.aot.ts | 4 - e2e/single-page/package.json | 3 +- e2e/tests-app-ng/app/lazy/lazy.component.ts | 3 +- e2e/tests-app-ng/app/lazy/lazy.module.ts | 4 +- ...iew-nested-segmented-bar-page.component.ts | 4 +- e2e/tests-app-ng/app/main.ts | 4 +- .../modal/lazy/lazy-load-modal.component.ts | 3 +- .../modal-dialogs/modal-dialog.component.ts | 2 +- .../navigation-options.component.ts | 2 +- e2e/tests-app-ng/package.json | 34 +- e2e/tests-app-ng/tsconfig.json | 4 +- nativescript-angular-package/tsconfig.json | 2 +- .../animations/animation-driver.ts | 14 +- .../animations/animation-player.ts | 26 +- nativescript-angular/bin/update-app-ng-deps | 68 - .../bin/update-app-ng-deps.cmd | 1 - nativescript-angular/directives/dialogs.ts | 20 +- nativescript-angular/directives/index.ts | 64 +- nativescript-angular/directives/tab-view.ts | 6 +- .../directives/templated-items-comp.ts | 42 +- nativescript-angular/dom-adapter.ts | 6 +- nativescript-angular/element-registry.ts | 4 +- nativescript-angular/frame.service.ts | 13 + nativescript-angular/index.ts | 17 +- nativescript-angular/modal-dialog.ts | 5 - nativescript-angular/nativescript.module.ts | 13 +- nativescript-angular/package.json | 63 +- nativescript-angular/page.service.ts | 48 + nativescript-angular/platform-common.ts | 66 +- nativescript-angular/platform-providers.ts | 51 - nativescript-angular/platform.ts | 99 +- nativescript-angular/renderer.ts | 106 +- .../router/ns-location-strategy.ts | 181 +- .../router/ns-location-utils.ts | 89 + .../router/ns-platform-location.ts | 6 +- .../router/ns-route-reuse-strategy.ts | 40 +- nativescript-angular/router/ns-router-link.ts | 12 +- .../router/page-router-outlet-utils.ts | 54 + .../router/page-router-outlet.ts | 114 +- .../router/router-extensions.ts | 19 +- nativescript-angular/router/router.module.ts | 2 +- nativescript-angular/testing/src/util.ts | 4 +- nativescript-angular/trace.ts | 117 +- nativescript-angular/tsconfig.json | 14 +- nativescript-angular/tsconfig.typedoc.json | 4 +- nativescript-angular/view-util.ts | 50 +- .../zone-js/dist/zone-nativescript.js | 2845 ++++++++--------- tests/app/tests/detached-loader-tests.ts | 4 +- tests/app/tests/modal-dialog.ts | 4 +- tests/package.json | 3 +- tests/tsconfig.json | 4 +- tsconfig.json | 4 +- 73 files changed, 2108 insertions(+), 2424 deletions(-) delete mode 100644 e2e/animation-examples/app/main.aot.ts delete mode 100644 e2e/animation-examples/app/vendor.ts delete mode 100644 e2e/modal-navigation-ng/app/main.aot.ts delete mode 100644 e2e/nested-router-tab-view/app/main.aot.ts delete mode 100644 e2e/renderer/app/main.aot.ts delete mode 100644 e2e/routable-animations/app/main.aot.ts delete mode 100644 e2e/router-tab-view/app/main.aot.ts delete mode 100644 e2e/single-page/app/main.aot.ts delete mode 100755 nativescript-angular/bin/update-app-ng-deps delete mode 100644 nativescript-angular/bin/update-app-ng-deps.cmd create mode 100644 nativescript-angular/frame.service.ts delete mode 100644 nativescript-angular/modal-dialog.ts create mode 100644 nativescript-angular/page.service.ts create mode 100644 nativescript-angular/router/ns-location-utils.ts create mode 100644 nativescript-angular/router/page-router-outlet-utils.ts diff --git a/build/pack-scripts/pack-scoped.ts b/build/pack-scripts/pack-scoped.ts index fe72a16a4..8d5605b84 100644 --- a/build/pack-scripts/pack-scoped.ts +++ b/build/pack-scripts/pack-scoped.ts @@ -5,27 +5,29 @@ import { execSync } from "child_process"; console.log(`Packing @nativescript/angular package`); const distFolderPath = path.resolve("../../dist"); -const tempFolderPath = path.resolve("./temp-scoped"); const outFileName = "nativescript-angular-scoped.tgz"; const nsAngularPackagePath = path.resolve("../../nativescript-angular"); +const nsAngularPackageDistPath = path.resolve(nsAngularPackagePath + "/dist"); -execSync(`npm install --save-exact`, { - cwd: nsAngularPackagePath -}); +function getFilesFromPath(path, extension) { + let files = fs.readdirSync( path ); + return files.filter(file => file.match(new RegExp(`.*\.(${extension})`, 'ig'))); +} + +// execSync(`npm install --save-exact`, { +// cwd: nsAngularPackagePath +// }); // ensure empty temp and dist folders -fs.emptyDirSync(tempFolderPath); fs.ensureDirSync(distFolderPath); // create .tgz in temp folder -execSync(`npm pack ${nsAngularPackagePath}`, { - cwd: tempFolderPath -}); +execSync(`cd ${nsAngularPackagePath} && npm run build.pack`); // assume we have a single file built in temp folder, take its name -const currentFileName = fs.readdirSync(tempFolderPath)[0]; +const currentFileName = getFilesFromPath(nsAngularPackageDistPath, ".tgz")[0]; +console.log('currentFileName:', currentFileName); // move built file and remove temp folder -fs.moveSync(`${tempFolderPath}/${currentFileName}`, `${distFolderPath}/${outFileName}`, { overwrite: true }); -fs.removeSync(`${tempFolderPath}`); +fs.moveSync(`${nsAngularPackageDistPath}/${currentFileName}`, `${distFolderPath}/${outFileName}`, { overwrite: true }); diff --git a/build/pack-scripts/tsconfig.json b/build/pack-scripts/tsconfig.json index deb92c7ef..0bda36752 100644 --- a/build/pack-scripts/tsconfig.json +++ b/build/pack-scripts/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "commonjs", - "target": "es5", + "target": "es2015", "experimentalDecorators": true, "emitDecoratorMetadata": true, "noEmitHelpers": true, diff --git a/e2e/animation-examples/app/app.module.ts b/e2e/animation-examples/app/app.module.ts index 38de237d5..4a729f4b2 100644 --- a/e2e/animation-examples/app/app.module.ts +++ b/e2e/animation-examples/app/app.module.ts @@ -24,7 +24,7 @@ export function asyncBoot(): Function { return (): Promise => new Promise(resolve => { setTimeout(() => { resolve(); - }, 2000); + }, 5000); }) } diff --git a/e2e/animation-examples/app/app.routing.ts b/e2e/animation-examples/app/app.routing.ts index df70ca363..305e244e9 100644 --- a/e2e/animation-examples/app/app.routing.ts +++ b/e2e/animation-examples/app/app.routing.ts @@ -1,6 +1,6 @@ import { NgModule } from "@angular/core"; import { Routes } from "@angular/router"; -import { NativeScriptRouterModule } from "@nativescript/angular/router"; +import { NativeScriptRouterModule } from "@nativescript/angular"; import { AnimationsListComponent } from "./animations-list.component"; import { AnimationBuilderComponent } from "./animation-builder.component"; diff --git a/e2e/animation-examples/app/hero/hero-routing.module.ts b/e2e/animation-examples/app/hero/hero-routing.module.ts index 57426f197..6f65be89b 100644 --- a/e2e/animation-examples/app/hero/hero-routing.module.ts +++ b/e2e/animation-examples/app/hero/hero-routing.module.ts @@ -1,6 +1,6 @@ import { NgModule } from "@angular/core"; import { Routes } from "@angular/router"; -import { NativeScriptRouterModule } from "@nativescript/angular/router"; +import { NativeScriptRouterModule } from "@nativescript/angular"; import { HeroTeamBuilderComponent } from './hero-team-builder.component'; diff --git a/e2e/animation-examples/app/hero/hero.module.ts b/e2e/animation-examples/app/hero/hero.module.ts index 139da6013..938ec409c 100644 --- a/e2e/animation-examples/app/hero/hero.module.ts +++ b/e2e/animation-examples/app/hero/hero.module.ts @@ -1,5 +1,5 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; -import { NativeScriptCommonModule } from "@nativescript/angular/common"; +import { NativeScriptCommonModule } from "@nativescript/angular"; import { HeroRoutingModule, routedComponents } from "./hero-routing.module"; diff --git a/e2e/animation-examples/app/main.aot.ts b/e2e/animation-examples/app/main.aot.ts deleted file mode 100644 index 015f6e008..000000000 --- a/e2e/animation-examples/app/main.aot.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { platformNativeScript } from "@nativescript/angular/platform-static"; -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/animation-examples/app/main.ts b/e2e/animation-examples/app/main.ts index 6d0342a02..9048ac77c 100644 --- a/e2e/animation-examples/app/main.ts +++ b/e2e/animation-examples/app/main.ts @@ -1,5 +1,4 @@ -import { platformNativeScriptDynamic } from "@nativescript/angular/platform"; -import { animationsTraceCategory } from "@nativescript/angular/trace"; +import { platformNativeScript, NativeScriptDebug } from "@nativescript/angular"; import { setCategories, enable } from "@nativescript/core/trace"; import { GridLayout, @@ -13,7 +12,7 @@ import { import { AppModule } from "./app.module"; -setCategories(animationsTraceCategory); +setCategories(NativeScriptDebug.animationsTraceCategory); enable(); class LaunchAnimation extends GridLayout { @@ -97,7 +96,7 @@ class LaunchAnimation extends GridLayout { } } -platformNativeScriptDynamic({ +platformNativeScript({ launchView: new LaunchAnimation(), // backgroundColor: 'purple' }).bootstrapModule(AppModule); diff --git a/e2e/animation-examples/app/vendor.ts b/e2e/animation-examples/app/vendor.ts deleted file mode 100644 index 3dceebdfa..000000000 --- a/e2e/animation-examples/app/vendor.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Snapshot the ~/app.css and the theme -const application = require("application"); -require("ui/styling/style-scope"); -const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/); -global.registerWebpackModules(appCssContext); -application.loadAppCss(); - -require("reflect-metadata"); -require("@angular/platform-browser"); -require("@angular/core"); -require("@angular/common"); -require("@angular/forms"); -require("@angular/router"); - -require("nativescript-angular/platform-static"); -require("nativescript-angular/forms"); -require("nativescript-angular/router"); diff --git a/e2e/animation-examples/package.json b/e2e/animation-examples/package.json index 7b511f01f..a12fb7527 100644 --- a/e2e/animation-examples/package.json +++ b/e2e/animation-examples/package.json @@ -13,50 +13,49 @@ } }, "dependencies": { - "@angular/animations": "~9.1.0", - "@angular/common": "~9.1.0", - "@angular/compiler": "~9.1.0", - "@angular/core": "~9.1.0", - "@angular/forms": "~9.1.0", - "@angular/platform-browser": "~9.1.0", - "@angular/platform-browser-dynamic": "~9.1.0", - "@angular/router": "~9.1.0", + "@angular/animations": "~10.0.0", + "@angular/common": "~10.0.0", + "@angular/compiler": "~10.0.0", + "@angular/core": "~10.0.0", + "@angular/forms": "~10.0.0", + "@angular/platform-browser": "~10.0.0", + "@angular/platform-browser-dynamic": "~10.0.0", + "@angular/router": "~10.0.0", "@nativescript/angular": "file:../../dist/nativescript-angular-scoped.tgz", "nativescript-theme-core": "~1.0.2", "reflect-metadata": "~0.1.8", "rxjs": "~6.5.5", - "@nativescript/core": "next", + "@nativescript/core": "~6.5.8", "zone.js": "^0.10.3" }, "devDependencies": { - "@angular/compiler-cli": "~9.1.0", - "@ngtools/webpack": "~9.1.0", - "@types/chai": "~4.1.7", - "@types/mocha": "~5.2.5", - "@types/node": "~10.12.18", - "babel-traverse": "6.25.0", - "babel-types": "6.25.0", - "babylon": "6.17.4", + "@angular/compiler-cli": "~10.0.0", + "@ngtools/webpack": "~10.0.0", + "@types/chai": "~4.2.0", + "@types/mocha": "~7.0.0", + "@types/node": "~14.0.0", + "babel-traverse": "~6.26.0", + "babel-types": "~6.26.0", + "babylon": "~6.18.0", "chai": "^4.2.0", - "lazy": "1.0.11", - "mocha": "~5.2.0", - "mochawesome": "~3.1.2", + "copy-webpack-plugin": "~6.0.3", + "lazy": "~1.0.11", + "mocha": "~8.0.1", + "mochawesome": "~6.1.1", "nativescript-css-loader": "~0.26.0", - "nativescript-dev-appium": "^6.0.0", - "nativescript-dev-webpack": "next", - "typescript": "~3.8.3" + "nativescript-dev-appium": "^6.1.0", + "nativescript-dev-webpack": "~1.5.1", + "typescript": "~3.9.0", + "webpack": "~4.43.0" }, "scripts": { "clean": "npx rimraf hooks node_modules platforms package-lock.json", - "setup": "cd ../../nativescript-angular && npm run pack && cd ../e2e/animation-examples && npm run clean", + "setup": "cd ../../nativescript-angular && npm run prep.apps && cd ../e2e/animation-examples && npm run clean", "u": "update-ns-webpack", "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "e2e-watch": "tsc -p e2e --watch", - "update-app-ng-deps": "update-app-ng-deps", "ns-verify-bundle": "ns-verify-bundle", "update-ns-webpack": "update-ns-webpack", - "ngcc": "ngcc --properties es2015 module main --first-only", - "postinstall": "npm run ngcc", "ios": "tns debug ios --env.aot --emulator --no-hmr", "android": "tns debug android --env.aot --emulator --no-hmr" } diff --git a/e2e/modal-navigation-ng/app/main.aot.ts b/e2e/modal-navigation-ng/app/main.aot.ts deleted file mode 100644 index bd0970ba9..000000000 --- a/e2e/modal-navigation-ng/app/main.aot.ts +++ /dev/null @@ -1,9 +0,0 @@ -// this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScript } from "@nativescript/angular/platform-static"; -import { AppModule } from "./app.module"; -import { NativeScriptPlatformRef } from "@nativescript/angular"; -// "./app.module.ngfactory" is a dynamically generated module when compiled with AoT. -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -AppModule.platformRef = platformNativeScript(); -AppModule.platformRef.bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/modal-navigation-ng/package.json b/e2e/modal-navigation-ng/package.json index 8288caf02..0ad335400 100644 --- a/e2e/modal-navigation-ng/package.json +++ b/e2e/modal-navigation-ng/package.json @@ -50,7 +50,7 @@ "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "e2e-watch": "tsc -p e2e --watch", "clean": "npx rimraf hooks node_modules platforms package-lock.json", - "setup": "cd ../../nativescript-angular && npm run pack && cd ../e2e/modal-navigation-ng && npm run clean", + "setup": "cd ../../nativescript-angular && npm run prep.apps && cd ../e2e/modal-navigation-ng && npm run clean", "ngcc": "ngcc --properties es2015 module main --first-only", "postinstall": "npm run ngcc", "ios": "tns debug ios --env.aot --emulator --no-hmr", diff --git a/e2e/nested-router-tab-view/app/main.aot.ts b/e2e/nested-router-tab-view/app/main.aot.ts deleted file mode 100644 index 97a9312ed..000000000 --- a/e2e/nested-router-tab-view/app/main.aot.ts +++ /dev/null @@ -1,7 +0,0 @@ -// this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScript } from "@nativescript/angular/platform-static"; - -// "./app.module.ngfactory" is a dynamically generated module when compiled with AoT. -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/nested-router-tab-view/package.json b/e2e/nested-router-tab-view/package.json index 2739c99d4..791cbc65f 100644 --- a/e2e/nested-router-tab-view/package.json +++ b/e2e/nested-router-tab-view/package.json @@ -47,7 +47,7 @@ "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "e2e-watch": "tsc -p e2e --watch", "clean": "npx rimraf hooks node_modules platforms package-lock.json", - "setup": "cd ../../nativescript-angular && npm run pack && cd ../e2e/nested-router-tab-view && npm run clean", + "setup": "cd ../../nativescript-angular && npm run prep.apps && cd ../e2e/nested-router-tab-view && npm run clean", "ngcc": "ngcc --properties es2015 module main --first-only", "postinstall": "npm run ngcc" } diff --git a/e2e/renderer/app/main.aot.ts b/e2e/renderer/app/main.aot.ts deleted file mode 100644 index 015f6e008..000000000 --- a/e2e/renderer/app/main.aot.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { platformNativeScript } from "@nativescript/angular/platform-static"; -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/renderer/package.json b/e2e/renderer/package.json index f6fe8e90d..3126f8f2e 100644 --- a/e2e/renderer/package.json +++ b/e2e/renderer/package.json @@ -41,7 +41,6 @@ }, "scripts": { "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", - "compile-tests-w": "tsc -p e2e --watch", - "update-app-ng-deps": "update-app-ng-deps" + "compile-tests-w": "tsc -p e2e --watch" } } diff --git a/e2e/routable-animations/app/app.module.ts b/e2e/routable-animations/app/app.module.ts index d0a7e9a6d..a20ebebb1 100644 --- a/e2e/routable-animations/app/app.module.ts +++ b/e2e/routable-animations/app/app.module.ts @@ -7,9 +7,9 @@ import { AppRoutingModule } from './app-routing.module'; import { HomeComponent } from './home/home.component'; import { SupportComponent } from './support/support.component'; -import { animationsTraceCategory } from "@nativescript/angular/trace"; +import { NativeScriptDebug } from "@nativescript/angular/trace"; import { setCategories, enable } from "@nativescript/core/trace"; -setCategories(animationsTraceCategory); +setCategories(NativeScriptDebug.animationsTraceCategory); enable(); @NgModule({ diff --git a/e2e/routable-animations/app/main.aot.ts b/e2e/routable-animations/app/main.aot.ts deleted file mode 100644 index 015f6e008..000000000 --- a/e2e/routable-animations/app/main.aot.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { platformNativeScript } from "@nativescript/angular/platform-static"; -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/routable-animations/package.json b/e2e/routable-animations/package.json index 103d69852..fb02e7d67 100644 --- a/e2e/routable-animations/package.json +++ b/e2e/routable-animations/package.json @@ -45,7 +45,6 @@ "ns-bundle": "ns-bundle", "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "e2e-watch": "tsc -p e2e --watch", - "update-app-ng-deps": "update-app-ng-deps", "ns-verify-bundle": "ns-verify-bundle", "update-ns-webpack": "update-ns-webpack" } diff --git a/e2e/router-tab-view/app/main.aot.ts b/e2e/router-tab-view/app/main.aot.ts deleted file mode 100644 index 97a9312ed..000000000 --- a/e2e/router-tab-view/app/main.aot.ts +++ /dev/null @@ -1,7 +0,0 @@ -// this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScript } from "@nativescript/angular/platform-static"; - -// "./app.module.ngfactory" is a dynamically generated module when compiled with AoT. -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/router/package.json b/e2e/router/package.json index 01537d520..6b1b6c90b 100644 --- a/e2e/router/package.json +++ b/e2e/router/package.json @@ -49,8 +49,7 @@ "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "e2e-watch": "tsc -p e2e --watch", "compile-tests-w": "tsc -p e2e --watch", - "update-app-ng-deps": "update-app-ng-deps", - "setup": "cd ../../nativescript-angular && npm run pack && cd ../e2e/router && npm run clean", + "setup": "cd ../../nativescript-angular && npm run prep.apps && cd ../e2e/router && npm run clean", "u": "update-ns-webpack", "ns-verify-bundle": "ns-verify-bundle", "update-ns-webpack": "update-ns-webpack", diff --git a/e2e/single-page/app/main.aot.ts b/e2e/single-page/app/main.aot.ts deleted file mode 100644 index d0302e23e..000000000 --- a/e2e/single-page/app/main.aot.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { platformNativeScript } from "@nativescript/angular/platform-static"; -import { AppModuleNgFactory } from "./app.module.ngfactory"; - -platformNativeScript({ createFrameOnBootstrap: true }).bootstrapModuleFactory(AppModuleNgFactory); diff --git a/e2e/single-page/package.json b/e2e/single-page/package.json index 493cac330..0ce803aee 100644 --- a/e2e/single-page/package.json +++ b/e2e/single-page/package.json @@ -43,7 +43,6 @@ }, "scripts": { "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", - "compile-tests-w": "tsc -p e2e --watch", - "update-app-ng-deps": "update-app-ng-deps" + "compile-tests-w": "tsc -p e2e --watch" } } diff --git a/e2e/tests-app-ng/app/lazy/lazy.component.ts b/e2e/tests-app-ng/app/lazy/lazy.component.ts index 6bba0b05e..bb8d0e01c 100644 --- a/e2e/tests-app-ng/app/lazy/lazy.component.ts +++ b/e2e/tests-app-ng/app/lazy/lazy.component.ts @@ -1,7 +1,6 @@ import { Component } from "@angular/core"; -import { RouterExtensions } from "@nativescript/angular/router"; -import { ModalDialogParams } from "@nativescript/angular/directives/dialogs"; +import { RouterExtensions, ModalDialogParams } from "@nativescript/angular"; @Component({ selector: "ns-lazy", diff --git a/e2e/tests-app-ng/app/lazy/lazy.module.ts b/e2e/tests-app-ng/app/lazy/lazy.module.ts index 46bff152f..eea1ca005 100644 --- a/e2e/tests-app-ng/app/lazy/lazy.module.ts +++ b/e2e/tests-app-ng/app/lazy/lazy.module.ts @@ -1,6 +1,4 @@ -import { NativeScriptCommonModule } from "@nativescript/angular/common"; -import { NativeScriptRouterModule } from "@nativescript/angular/router"; -import { ModalDialogParams } from "@nativescript/angular/directives/dialogs"; +import { NativeScriptCommonModule, NativeScriptRouterModule, ModalDialogParams } from "@nativescript/angular"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; import { Routes } from "@angular/router"; diff --git a/e2e/tests-app-ng/app/list-view/list-view-nested-segmented-bar-page.component.ts b/e2e/tests-app-ng/app/list-view/list-view-nested-segmented-bar-page.component.ts index ec0d9d963..74e161d7b 100644 --- a/e2e/tests-app-ng/app/list-view/list-view-nested-segmented-bar-page.component.ts +++ b/e2e/tests-app-ng/app/list-view/list-view-nested-segmented-bar-page.component.ts @@ -1,7 +1,5 @@ import { Component, ViewChild, ElementRef, OnInit } from "@angular/core"; -import { SegmentedBarItem, SegmentedBar } from "tns-core-modules/ui/segmented-bar/segmented-bar"; -import { ListView } from "tns-core-modules/ui/list-view/list-view"; -import { EventData } from "tns-core-modules/ui/page/page"; +import { SegmentedBarItem, SegmentedBar, ListView, EventData } from "@nativescript/core"; interface DataItem { id: number; diff --git a/e2e/tests-app-ng/app/main.ts b/e2e/tests-app-ng/app/main.ts index 35bebd4d8..5f52e4652 100644 --- a/e2e/tests-app-ng/app/main.ts +++ b/e2e/tests-app-ng/app/main.ts @@ -1,8 +1,8 @@ -import { platformNativeScriptDynamic } from "@nativescript/angular/platform"; +import { platformNativeScript } from "@nativescript/angular"; import { AppModule } from "./app.module"; import { enable } from "@nativescript/core/trace"; enable(); -platformNativeScriptDynamic().bootstrapModule(AppModule); +platformNativeScript().bootstrapModule(AppModule); diff --git a/e2e/tests-app-ng/app/modal/lazy/lazy-load-modal.component.ts b/e2e/tests-app-ng/app/modal/lazy/lazy-load-modal.component.ts index 3e36efd68..3571090ab 100644 --- a/e2e/tests-app-ng/app/modal/lazy/lazy-load-modal.component.ts +++ b/e2e/tests-app-ng/app/modal/lazy/lazy-load-modal.component.ts @@ -6,8 +6,7 @@ import { ViewContainerRef, } from "@angular/core"; -import { NSModuleFactoryLoader } from "@nativescript/angular/router"; -import { ModalDialogService } from "@nativescript/angular/directives/dialogs"; +import { NSModuleFactoryLoader, ModalDialogService } from "@nativescript/angular"; import { LazyComponent } from "../../lazy/lazy.component"; diff --git a/e2e/tests-app-ng/app/modal/modal-dialogs/modal-dialog.component.ts b/e2e/tests-app-ng/app/modal/modal-dialogs/modal-dialog.component.ts index a83fe6864..1c069021b 100644 --- a/e2e/tests-app-ng/app/modal/modal-dialogs/modal-dialog.component.ts +++ b/e2e/tests-app-ng/app/modal/modal-dialogs/modal-dialog.component.ts @@ -8,7 +8,7 @@ import { ModalDialogService, ModalDialogOptions, ModalDialogParams -} from "@nativescript/angular/directives/dialogs"; +} from "@nativescript/angular"; @Component({ selector: "modal-content", diff --git a/e2e/tests-app-ng/app/navigation-options/navigation-options.component.ts b/e2e/tests-app-ng/app/navigation-options/navigation-options.component.ts index 869173661..06bdc3368 100644 --- a/e2e/tests-app-ng/app/navigation-options/navigation-options.component.ts +++ b/e2e/tests-app-ng/app/navigation-options/navigation-options.component.ts @@ -1,5 +1,5 @@ import { Component } from "@angular/core"; -import { RouterExtensions } from "@nativescript/angular/router"; +import { RouterExtensions } from "@nativescript/angular"; @Component({ selector: "nav-options", diff --git a/e2e/tests-app-ng/package.json b/e2e/tests-app-ng/package.json index 85782a0c2..107d66af5 100644 --- a/e2e/tests-app-ng/package.json +++ b/e2e/tests-app-ng/package.json @@ -13,47 +13,47 @@ } }, "dependencies": { - "@angular/animations": "~9.1.0", - "@angular/common": "~9.1.0", - "@angular/compiler": "~9.1.0", - "@angular/core": "~9.1.0", - "@angular/forms": "~9.1.0", - "@angular/platform-browser": "~9.1.0", - "@angular/platform-browser-dynamic": "~9.1.0", - "@angular/router": "~9.1.0", + "@angular/animations": "~10.0.0", + "@angular/common": "~10.0.0", + "@angular/compiler": "~10.0.0", + "@angular/core": "~10.0.0", + "@angular/forms": "~10.0.0", + "@angular/platform-browser": "~10.0.0", + "@angular/platform-browser-dynamic": "~10.0.0", + "@angular/router": "~10.0.0", "@nativescript/angular": "file:../../dist/nativescript-angular-scoped.tgz", "nativescript-intl": "~3.0.0", "nativescript-theme-core": "^1.0.4", "reflect-metadata": "~0.1.8", "rxjs": "~6.5.5", - "@nativescript/core": "next", + "@nativescript/core": "~6.5.8", "zone.js": "^0.10.3" }, "devDependencies": { - "@angular/compiler-cli": "~9.1.0", - "@ngtools/webpack": "~9.1.0", + "@angular/compiler-cli": "~10.0.0", + "@ngtools/webpack": "~10.0.0", "babel-traverse": "6.24.1", "babel-types": "6.24.1", "babylon": "6.17.0", "codelyzer": "^5.1.0", + "copy-webpack-plugin": "~6.0.3", "filewalker": "^0.1.3", "lazy": "1.0.11", - "nativescript-dev-webpack": "next", + "nativescript-dev-webpack": "~1.5.1", + "terser-webpack-plugin": "~2.2.0", "tslint": "^5.4.3", - "typescript": "~3.8.3" + "typescript": "~3.9.0", + "webpack": "~4.43.0" }, "scripts": { "tslint": "tslint --config tslint.json 'app/**/*.ts'", "clean": "npx rimraf hooks node_modules platforms package-lock.json", - "setup": "cd ../../nativescript-angular && npm run pack && cd ../e2e/tests-app-ng && npm run clean", + "setup": "cd ../../nativescript-angular && npm run prep.apps && cd ../e2e/tests-app-ng && npm run clean", "u": "update-ns-webpack", "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "e2e-watch": "tsc -p e2e --watch", - "update-app-ng-deps": "update-app-ng-deps", "ns-verify-bundle": "ns-verify-bundle", "update-ns-webpack": "update-ns-webpack", - "ngcc": "ngcc --properties es2015 module main --first-only", - "postinstall": "npm run ngcc", "ios": "tns debug ios --env.aot --emulator --no-hmr", "android": "tns debug android --env.aot --emulator --no-hmr" } diff --git a/e2e/tests-app-ng/tsconfig.json b/e2e/tests-app-ng/tsconfig.json index 576a402fa..c0c3b127f 100644 --- a/e2e/tests-app-ng/tsconfig.json +++ b/e2e/tests-app-ng/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "module": "commonjs", - "target": "es5", + "module": "esnext", + "target": "es2015", "experimentalDecorators": true, "emitDecoratorMetadata": true, "noEmitHelpers": true, diff --git a/nativescript-angular-package/tsconfig.json b/nativescript-angular-package/tsconfig.json index 96c60bde6..2ef8c5d93 100644 --- a/nativescript-angular-package/tsconfig.json +++ b/nativescript-angular-package/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2015", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, diff --git a/nativescript-angular/animations/animation-driver.ts b/nativescript-angular/animations/animation-driver.ts index 897763e34..1ff403217 100644 --- a/nativescript-angular/animations/animation-driver.ts +++ b/nativescript-angular/animations/animation-driver.ts @@ -11,7 +11,7 @@ import { dashCaseToCamelCase, } from "./utils"; import { NgView, InvisibleNode } from "../element-registry"; -import { animationsLog as traceLog } from "../trace"; +import { NativeScriptDebug } from "../trace"; interface ViewMatchResult { @@ -75,12 +75,12 @@ export class NativeScriptAnimationDriver implements AnimationDriver { ]; validateStyleProperty(property: string): boolean { - traceLog(`CssAnimationProperty.validateStyleProperty: ${property}`); + NativeScriptDebug.animationsLog(`CssAnimationProperty.validateStyleProperty: ${property}`); return NativeScriptAnimationDriver.validProperties.indexOf(property) !== -1; } matchesElement(element: NgView, rawSelector: string): boolean { - traceLog( + NativeScriptDebug.animationsLog( `NativeScriptAnimationDriver.matchesElement ` + `element: ${element}, selector: ${rawSelector}` ); @@ -91,7 +91,7 @@ export class NativeScriptAnimationDriver implements AnimationDriver { containsElement(elm1: NgView, elm2: NgView): boolean { - traceLog( + NativeScriptDebug.animationsLog( `NativeScriptAnimationDriver.containsElement ` + `element1: ${elm1}, element2: ${elm2}` ); @@ -108,7 +108,7 @@ export class NativeScriptAnimationDriver implements AnimationDriver { } query(element: NgView, rawSelector: string, multi: boolean): NgView[] { - traceLog( + NativeScriptDebug.animationsLog( `NativeScriptAnimationDriver.query ` + `element: ${element}, selector: ${rawSelector} ` + `multi: ${multi}` @@ -122,7 +122,7 @@ export class NativeScriptAnimationDriver implements AnimationDriver { } computeStyle(element: NgView, prop: string): string { - traceLog( + NativeScriptDebug.animationsLog( `NativeScriptAnimationDriver.computeStyle ` + `element: ${element}, prop: ${prop}` ); @@ -138,7 +138,7 @@ export class NativeScriptAnimationDriver implements AnimationDriver { delay: number, easing: string ): AnimationPlayer { - traceLog( + NativeScriptDebug.animationsLog( `NativeScriptAnimationDriver.animate ` + `element: ${element}, keyframes: ${keyframes} ` + `duration: ${duration}, delay: ${delay} ` + diff --git a/nativescript-angular/animations/animation-player.ts b/nativescript-angular/animations/animation-player.ts index 831fa4517..30cc82759 100644 --- a/nativescript-angular/animations/animation-player.ts +++ b/nativescript-angular/animations/animation-player.ts @@ -5,7 +5,7 @@ import { View, EventData } from "@nativescript/core/ui/core/view"; import { Keyframe, createKeyframeAnimation } from "./utils"; import { NgView } from "../element-registry"; -import { animationsLog as traceLog, isLogEnabled } from "../trace"; +import { NativeScriptDebug } from "../trace"; export class NativeScriptAnimationPlayer implements AnimationPlayer { public parentPlayer: AnimationPlayer = null; @@ -42,8 +42,8 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { onDestroy(fn: Function): void { this._doneSubscriptions.push(fn); } play(): void { - if (isLogEnabled()) { - traceLog(`NativeScriptAnimationPlayer.play`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.animationsLog(`NativeScriptAnimationPlayer.play`); } if (!this.animation) { @@ -84,8 +84,8 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { } reset(): void { - if (isLogEnabled()) { - traceLog(`NativeScriptAnimationPlayer.reset`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.animationsLog(`NativeScriptAnimationPlayer.reset`); } if (this.animation && this.animation.isPlaying) { @@ -94,8 +94,8 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { } restart(): void { - if (isLogEnabled()) { - traceLog(`NativeScriptAnimationPlayer.restart`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.animationsLog(`NativeScriptAnimationPlayer.restart`); } this.reset(); @@ -103,8 +103,8 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { } destroy(): void { - if (isLogEnabled()) { - traceLog(`NativeScriptAnimationPlayer.destroy`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.animationsLog(`NativeScriptAnimationPlayer.destroy`); } this.onFinish(); } @@ -118,16 +118,16 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { } private initKeyframeAnimation(keyframes: Keyframe[], duration: number, delay: number, easing: string) { - if (isLogEnabled()) { - traceLog(`NativeScriptAnimationPlayer.initKeyframeAnimation`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.animationsLog(`NativeScriptAnimationPlayer.initKeyframeAnimation`); } this.animation = createKeyframeAnimation(keyframes, duration, delay, easing); } private onFinish() { - if (isLogEnabled()) { - traceLog(`NativeScriptAnimationPlayer.onFinish`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.animationsLog(`NativeScriptAnimationPlayer.onFinish`); } if (this._finished) { diff --git a/nativescript-angular/bin/update-app-ng-deps b/nativescript-angular/bin/update-app-ng-deps deleted file mode 100755 index 043e57edf..000000000 --- a/nativescript-angular/bin/update-app-ng-deps +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env node - -const path = require("path"); -const fs = require("fs"); - -const binPath = __dirname; -const pluginPath = path.dirname(binPath); -const pluginPackageJsonPath = path.join(pluginPath, "package.json"); -const pluginPackageJson = JSON.parse(fs.readFileSync(pluginPackageJsonPath, "utf8")); - -const isNgDependency = name => name.startsWith("@angular") || - name === "rxjs" || - name === "zone.js" || - name === "typescript"; - -function updateDeps(deps, devDeps, newDeps) { - Object.keys(newDeps) - .filter(isNgDependency) - .map(dependencyName => ({ - dependencyName, - version: newDeps[dependencyName] - })) - .forEach(({ dependencyName, version }) => { - if (devDeps[dependencyName]) { - devDeps[dependencyName] = version; - } else { - deps[dependencyName] = version; - } - - logUpdatedDependency(dependencyName, version); - }); - - const ngDep = Object.keys(newDeps).find(dep => dep.startsWith("@angular")); - const version = newDeps[ngDep]; - const animationsDependency = "@angular/animations"; - if (deps[animationsDependency]) { - deps[animationsDependency] = version; - logUpdatedDependency(animationsDependency, version); - } - - const compilerCliDependency = "@angular/compiler-cli"; - if (devDeps[compilerCliDependency]) { - devDeps[compilerCliDependency] = version; - logUpdatedDependency(compilerCliDependency, version); - } - - const ngToolsWebpackDependency = "@ngtools/webpack"; - if (devDeps[ngToolsWebpackDependency]) { - devDeps[ngToolsWebpackDependency] = version; - logUpdatedDependency(ngToolsWebpackDependency, version); - } - - function logUpdatedDependency(dependencyName, version) { - console.log(`Updated dependency ${dependencyName} to version: ${version}.`); - } -} - -const pluginDeps = pluginPackageJson.peerDependencies; -const projectPath = process.env.INIT_CWD || path.dirname(path.dirname(path.dirname(pluginPath))); -const appPackageJsonPath = path.join(projectPath, "package.json"); -const appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, "utf8")); - -const { dependencies, devDependencies } = appPackageJson; -updateDeps(dependencies, devDependencies, pluginDeps); - -fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2)); - -console.log("\nAngular dependencies updated. Don't forget to run `npm install`."); diff --git a/nativescript-angular/bin/update-app-ng-deps.cmd b/nativescript-angular/bin/update-app-ng-deps.cmd deleted file mode 100644 index a5e120718..000000000 --- a/nativescript-angular/bin/update-app-ng-deps.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\update-app-angular-deps %* diff --git a/nativescript-angular/directives/dialogs.ts b/nativescript-angular/directives/dialogs.ts index a7b8e1d62..0ec5dc79e 100644 --- a/nativescript-angular/directives/dialogs.ts +++ b/nativescript-angular/directives/dialogs.ts @@ -28,6 +28,16 @@ export interface ModalDialogOptions extends BaseShowModalOptions { target?: View; } +export interface ShowDialogOptions extends BaseShowModalOptions { + containerRef: ViewContainerRef; + context: any; + doneCallback; + pageFactory: PageFactory; + parentView: ViewBase; + resolver: ComponentFactoryResolver; + type: Type; +} + export class ModalDialogParams { constructor( public context: any = {}, @@ -35,16 +45,6 @@ export class ModalDialogParams { } } -interface ShowDialogOptions extends BaseShowModalOptions { - containerRef: ViewContainerRef; - context: any; - doneCallback; - pageFactory: PageFactory; - parentView: ViewBase; - resolver: ComponentFactoryResolver; - type: Type; -} - @Injectable() export class ModalDialogService { constructor(private location: NSLocationStrategy) { diff --git a/nativescript-angular/directives/index.ts b/nativescript-angular/directives/index.ts index 4b34a877e..4ca4d19ab 100644 --- a/nativescript-angular/directives/index.ts +++ b/nativescript-angular/directives/index.ts @@ -1,41 +1,45 @@ import { ListViewComponent } from "./list-view-comp"; -import { TemplateKeyDirective, TemplatedItemsComponent } from "./templated-items-comp"; +import { + TemplateKeyDirective, + TemplatedItemsComponent, +} from "./templated-items-comp"; import { TabViewDirective, TabViewItemDirective } from "./tab-view"; import { - ActionBarComponent, - ActionBarScope, - ActionItemDirective, - NavigationButtonDirective + ActionBarComponent, + ActionBarScope, + ActionItemDirective, + NavigationButtonDirective, } from "./action-bar"; import { AndroidFilterComponent, IosFilterComponent } from "./platform-filters"; -import { ModalDialogOptions, ModalDialogParams, ModalDialogService } from "./dialogs"; +export { + ModalDialogOptions, + ModalDialogParams, + ModalDialogService, +} from "./dialogs"; export const NS_DIRECTIVES = [ - ListViewComponent, - TemplateKeyDirective, - TabViewDirective, - TabViewItemDirective, - ActionBarComponent, - ActionBarScope, - ActionItemDirective, - NavigationButtonDirective, - AndroidFilterComponent, - IosFilterComponent, + ListViewComponent, + TemplateKeyDirective, + TabViewDirective, + TabViewItemDirective, + ActionBarComponent, + ActionBarScope, + ActionItemDirective, + NavigationButtonDirective, + AndroidFilterComponent, + IosFilterComponent, ]; export { - ListViewComponent, - TemplateKeyDirective, - TemplatedItemsComponent, - TabViewDirective, - TabViewItemDirective, - ActionBarComponent, - ActionBarScope, - ActionItemDirective, - NavigationButtonDirective, - AndroidFilterComponent, - IosFilterComponent, - ModalDialogOptions, - ModalDialogParams, - ModalDialogService + ListViewComponent, + TemplateKeyDirective, + TemplatedItemsComponent, + TabViewDirective, + TabViewItemDirective, + ActionBarComponent, + ActionBarScope, + ActionItemDirective, + NavigationButtonDirective, + AndroidFilterComponent, + IosFilterComponent }; diff --git a/nativescript-angular/directives/tab-view.ts b/nativescript-angular/directives/tab-view.ts index 3c595a37f..750ea1115 100644 --- a/nativescript-angular/directives/tab-view.ts +++ b/nativescript-angular/directives/tab-view.ts @@ -11,7 +11,7 @@ import { TabView, TabViewItem } from "@nativescript/core/ui/tab-view"; import { TextTransform } from "@nativescript/core/ui/text-base"; import { InvisibleNode } from "../element-registry"; -import { rendererLog, isLogEnabled } from "../trace"; +import { NativeScriptDebug } from "../trace"; import { isBlank } from "../lang-facade"; export interface TabViewItemDef { @@ -46,8 +46,8 @@ export class TabViewDirective implements AfterViewInit { ngAfterViewInit() { this.viewInitialized = true; - if (isLogEnabled()) { - rendererLog("this._selectedIndex: " + this._selectedIndex); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog("this._selectedIndex: " + this._selectedIndex); } if (!isBlank(this._selectedIndex)) { this.tabView.selectedIndex = this._selectedIndex; diff --git a/nativescript-angular/directives/templated-items-comp.ts b/nativescript-angular/directives/templated-items-comp.ts index 5113e559c..4be787d36 100644 --- a/nativescript-angular/directives/templated-items-comp.ts +++ b/nativescript-angular/directives/templated-items-comp.ts @@ -17,7 +17,8 @@ import { TemplateRef, ViewChild, ViewContainerRef, - ɵisListLikeIterable as isListLikeIterable + ɵisListLikeIterable as isListLikeIterable, + Injectable } from "@angular/core"; // tslint:disable: max-line-length // TODO: refactor core module imports to allow this to work properly @@ -32,7 +33,7 @@ import { ObservableArray } from "@nativescript/core/data/observable-array"; import { profile } from "@nativescript/core/profiling"; import { getSingleViewRecursive } from "../element-registry"; -import { listViewLog, listViewError, isLogEnabled } from "../trace"; +import { NativeScriptDebug } from "../trace"; const NG_VIEW = "_ngViewRef"; @@ -54,6 +55,7 @@ export interface SetupItemViewArgs { context: ItemContext; } +@Injectable() export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, AfterContentInit { public abstract get nativeElement(): TemplatedItemsView; @@ -97,8 +99,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft } ngAfterContentInit() { - if (isLogEnabled()) { - listViewLog("TemplatedItemsView.ngAfterContentInit()"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog("TemplatedItemsView.ngAfterContentInit()"); } this.setItemTemplates(); @@ -119,8 +121,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft this.itemTemplate = this.itemTemplateQuery; if (this._templateMap) { - if (isLogEnabled()) { - listViewLog("Setting templates"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog("Setting templates"); } const templates: KeyedTemplate[] = []; @@ -132,8 +134,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft } public registerTemplate(key: string, template: TemplateRef) { - if (isLogEnabled()) { - listViewLog(`registerTemplate for key: ${key}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog(`registerTemplate for key: ${key}`); } if (!this._templateMap) { @@ -160,8 +162,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft let viewRef: EmbeddedViewRef; if (args.view) { - if (isLogEnabled()) { - listViewLog(`onItemLoading: ${index} - Reusing existing view`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog(`onItemLoading: ${index} - Reusing existing view`); } viewRef = args.view[NG_VIEW]; @@ -172,8 +174,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft viewRef = args.view.getChildAt(0)[NG_VIEW]; } - if (!viewRef && isLogEnabled()) { - listViewError(`ViewReference not found for item ${index}. View recycling is not working`); + if (!viewRef && NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewError(`ViewReference not found for item ${index}. View recycling is not working`); } // No ng-template is setup, continue with 'defaultTemplate' @@ -183,8 +185,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft } if (!viewRef) { - if (isLogEnabled()) { - listViewLog(`onItemLoading: ${index} - Creating view from template`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog(`onItemLoading: ${index} - Creating view from template`); } viewRef = this.loader.createEmbeddedView(this.itemTemplate, new ItemContext(), 0); @@ -220,8 +222,8 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft @profile private detectChangesOnChild(viewRef: EmbeddedViewRef, index: number) { - if (isLogEnabled()) { - listViewLog(`Manually detect changes in child: ${index}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog(`Manually detect changes in child: ${index}`); } viewRef.markForCheck(); @@ -230,14 +232,14 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft ngDoCheck() { if (this._differ) { - if (isLogEnabled()) { - listViewLog("ngDoCheck() - execute differ"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog("ngDoCheck() - execute differ"); } const changes = this._differ.diff(this._items); if (changes) { - if (isLogEnabled()) { - listViewLog("ngDoCheck() - refresh"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.listViewLog("ngDoCheck() - refresh"); } this.templatedItemsView.refresh(); diff --git a/nativescript-angular/dom-adapter.ts b/nativescript-angular/dom-adapter.ts index 582da2ffc..b0b8f1849 100644 --- a/nativescript-angular/dom-adapter.ts +++ b/nativescript-angular/dom-adapter.ts @@ -1,12 +1,12 @@ /* tslint:disable */ import { Type } from "@angular/core"; import { ɵDomAdapter, ɵsetRootDomAdapter } from "@angular/common"; -import { rendererLog, isLogEnabled } from "./trace"; +import { NativeScriptDebug } from "./trace"; export class NativeScriptDomAdapter implements ɵDomAdapter { static makeCurrent() { - if (isLogEnabled()) { - rendererLog("Setting root DOM adapter..."); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog("Setting root DOM adapter..."); } ɵsetRootDomAdapter(new NativeScriptDomAdapter()); diff --git a/nativescript-angular/element-registry.ts b/nativescript-angular/element-registry.ts index a371e6b6f..1a7dac464 100644 --- a/nativescript-angular/element-registry.ts +++ b/nativescript-angular/element-registry.ts @@ -3,8 +3,6 @@ import { LayoutBase } from "@nativescript/core/ui/layouts/layout-base"; import { Page } from "@nativescript/core/ui/page"; import { Frame } from "@nativescript/core/ui/frame"; -export type NgView = (View & ViewExtensions); - export interface ViewExtensions { meta: ViewClassMeta; nodeType: number; @@ -16,6 +14,8 @@ export interface ViewExtensions { ngCssClasses: Map; } +export type NgView = (View & ViewExtensions); + export interface ViewClass { new(): View; } diff --git a/nativescript-angular/frame.service.ts b/nativescript-angular/frame.service.ts new file mode 100644 index 000000000..4c8e5be2c --- /dev/null +++ b/nativescript-angular/frame.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from "@angular/core"; +import { Frame } from "@nativescript/core/ui/frame"; + +@Injectable({ + providedIn: 'root' +}) +export class FrameService { + // TODO: Add any methods that are needed to handle frame/page navigation + getFrame(): Frame { + let topmostFrame = Frame.topmost(); + return topmostFrame; + } +} \ No newline at end of file diff --git a/nativescript-angular/index.ts b/nativescript-angular/index.ts index 0aa692a4a..d7d673def 100644 --- a/nativescript-angular/index.ts +++ b/nativescript-angular/index.ts @@ -1,9 +1,17 @@ +// Initial imports and polyfills +import "@nativescript/core/globals"; import "@nativescript/core/application"; +import "./zone-js/dist/zone-nativescript"; +// TODO: migrate to standard zone.js if possible +// investigate Ivy with templated-items-comp to allow standard zone below to be used instead of patched {N} zone above +// import 'zone.js/dist/zone'; +// import "./polyfills/array"; +import "./polyfills/console"; export * from "./platform-common"; -export * from "./platform"; -export * from "./platform-static"; +// export * from "./platform-static"; export * from "./platform-providers"; +export * from "./platform"; export * from "./resource-loader"; export * from "./nativescript.module"; @@ -13,8 +21,11 @@ export * from "./animations"; export * from "./file-system"; export * from "./http-client"; export * from "./forms"; -export * from "./directives/dialogs"; +export * from "./directives"; export * from "./router"; +export * from "./frame.service"; +export * from "./page.service"; +export { NativeScriptDebug } from "./trace"; export { ViewClass, diff --git a/nativescript-angular/modal-dialog.ts b/nativescript-angular/modal-dialog.ts deleted file mode 100644 index 0ee522dcb..000000000 --- a/nativescript-angular/modal-dialog.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { - ModalDialogOptions, - ModalDialogParams, - ModalDialogService -} from "./directives/dialogs"; diff --git a/nativescript-angular/nativescript.module.ts b/nativescript-angular/nativescript.module.ts index 71563721a..c1b2ad744 100644 --- a/nativescript-angular/nativescript.module.ts +++ b/nativescript-angular/nativescript.module.ts @@ -1,9 +1,9 @@ -import "@nativescript/core/globals"; +// import "@nativescript/core/globals"; // Require application early to work around a circular import -import "@nativescript/core/application"; +// import "@nativescript/core/application"; -import "./polyfills/array"; -import "./polyfills/console"; +// import "./polyfills/array"; +// import "./polyfills/console"; import { ApplicationModule, @@ -26,13 +26,14 @@ import { NativeScriptCommonModule } from "./common"; import { NativeScriptRendererFactory } from "./renderer"; import { DetachedLoader } from "./common/detached-loader"; import { throwIfAlreadyLoaded } from "./common/utils"; -import { FrameService, PageService } from "./platform-providers"; +import { FrameService } from "./frame.service"; +import { PageService } from "./page.service"; export function errorHandlerFactory() { return new ErrorHandler(); } -export { DetachedLoader }; +export { DetachedLoader } from "./common/detached-loader"; @NgModule({ declarations: [ diff --git a/nativescript-angular/package.json b/nativescript-angular/package.json index a927665eb..264e7a3f6 100644 --- a/nativescript-angular/package.json +++ b/nativescript-angular/package.json @@ -5,6 +5,7 @@ "homepage": "https://www.nativescript.org/", "bugs": "https://github.com/NativeScript/nativescript-angular/issues", "main": "index.js", + "module": "index.js", "types": "index.d.ts", "author": { "name": "NativeScript Team" @@ -25,54 +26,62 @@ "url": "https://github.com/NativeScript/nativescript-angular.git" }, "scripts": { - "setup": "npx rimraf hooks node_modules package-lock.json && npm run pack", + "setup": "npx rimraf hooks node_modules package-lock.json && npm i && npm run prep.apps", + "prep.apps": "npm run build.pack && cd ../build/pack-scripts && npm i && npx ts-node pack-scoped.ts", + "build": "ng-packagr -p package.json", + "build.pack": "npm run tsc && npm run build && cd dist && npm pack", "tslint": "tslint --project tsconfig.json --config tslint.json", "tsc": "tsc -p tsconfig.json", "tsc-w": "tsc -p tsconfig.json -w", "ngc": "ngc", "ngcc": "ngcc", - "prepare": "npm run ngcc && ngc -p tsconfig.json", - "pack": "npm i && tsc && npm run prepare && cd ../build/pack-scripts && npm i && npx ts-node pack-scoped.ts", + "ngcc-run": "npm run ngcc && ngc -p tsconfig.json", "changelog": "conventional-changelog -p angular -i ../CHANGELOG.md -s", "version": "rm -rf package-lock.json && npm run changelog && git add ../CHANGELOG.md", "typedoc": "typedoc --tsconfig \"./tsconfig.typedoc.json\" --out ./bin/dist/ng-api-reference --includeDeclarations --name \"NativeScript Angular\" --theme ./node_modules/nativescript-typedoc-theme --excludeExternals --externalPattern \"**/+(tns-core-modules|module|declarations).d.ts\"" }, - "bin": { - "update-app-ng-deps": "./bin/update-app-ng-deps" + "ngPackage": { + "lib": { + "entryFile": "index.ts" + }, + "whitelistedNonPeerDependencies": [ + "." + ] }, "dependencies": { "nativescript-intl": "^3.0.0" }, "peerDependencies": { - "@angular/platform-browser-dynamic": "~9.1.0", - "@angular/common": "~9.1.0", - "@angular/compiler": "~9.1.0", - "@angular/core": "~9.1.0", - "@angular/forms": "~9.1.0", - "@angular/platform-browser": "~9.1.0", - "@angular/router": "~9.1.0", + "@angular/platform-browser-dynamic": "~10.0.0", + "@angular/common": "~10.0.0", + "@angular/compiler": "~10.0.0", + "@angular/core": "~10.0.0", + "@angular/forms": "~10.0.0", + "@angular/platform-browser": "~10.0.0", + "@angular/router": "~10.0.0", "rxjs": "~6.5.5", - "typescript": "~3.8.3", + "typescript": "~3.9.0", "zone.js": "^0.10.3" }, "devDependencies": { - "@angular/animations": "~9.1.0", - "@angular/common": "~9.1.0", - "@angular/compiler": "~9.1.0", - "@angular/compiler-cli": "~9.1.0", - "@angular/core": "~9.1.0", - "@angular/forms": "~9.1.0", - "@angular/platform-browser": "~9.1.0", - "@angular/platform-browser-dynamic": "~9.1.0", - "@angular/router": "~9.1.0", - "codelyzer": "^5.1.0", - "conventional-changelog-cli": "^1.3.22", + "@angular/animations": "~10.0.0", + "@angular/common": "~10.0.0", + "@angular/compiler": "~10.0.0", + "@angular/compiler-cli": "~10.0.0", + "@angular/core": "~10.0.0", + "@angular/forms": "~10.0.0", + "@angular/platform-browser": "~10.0.0", + "@angular/platform-browser-dynamic": "~10.0.0", + "@angular/router": "~10.0.0", + "codelyzer": "^5.2.0", + "conventional-changelog-cli": "^2.0.34", "rxjs": "~6.5.5", "@nativescript/core": "next", - "tslint": "^5.5.0", - "typescript": "~3.8.3", + "ng-packagr": "~10.0.0", + "tslint": "^6.1.2", + "typescript": "~3.9.0", "zone.js": "^0.10.3", "nativescript-typedoc-theme": "git://github.com/NativeScript/nativescript-typedoc-theme.git#master", - "typedoc": "0.15.0" + "typedoc": "~0.17.0" } } diff --git a/nativescript-angular/page.service.ts b/nativescript-angular/page.service.ts new file mode 100644 index 000000000..f876628da --- /dev/null +++ b/nativescript-angular/page.service.ts @@ -0,0 +1,48 @@ +import { OnDestroy, Injectable } from "@angular/core"; +import { BehaviorSubject, Subject, Observable } from "rxjs"; +import { NavigatedData, Page } from "@nativescript/core/ui/page"; +import { distinctUntilChanged } from "rxjs/operators"; + +@Injectable({ + providedIn: 'root' +}) +export class PageService implements OnDestroy { + private _inPage$ = new BehaviorSubject(false); + private _pageEvents$ = new Subject(); + + get inPage(): boolean { return this._inPage$.value; } + get inPage$(): Observable { return this._inPage$.pipe(distinctUntilChanged()); } + get pageEvents$(): Observable { return this._pageEvents$.asObservable(); } + constructor(public page: Page) { + if (this.page) { + this.page.on("navigatedFrom", this.pageEvent, this); + this.page.on("navigatedTo", this.pageEvent, this); + this.page.on("navigatingFrom", this.pageEvent, this); + this.page.on("navigatingTo", this.pageEvent, this); + } + } + + ngOnDestroy() { + if (this.page) { + this.page.off("navigatedFrom", this.pageEvent, this); + this.page.off("navigatedTo", this.pageEvent, this); + this.page.off("navigatingFrom", this.pageEvent, this); + this.page.off("navigatingTo", this.pageEvent, this); + } + this._inPage$.complete(); + this._pageEvents$.complete(); + } + + private pageEvent(evt: NavigatedData) { + this._pageEvents$.next(evt); + switch (evt.eventName) { + case "navigatedTo": + this._inPage$.next(true); + break; + case "navigatedFrom": + this._inPage$.next(false); + break; + default: + } + } +} \ No newline at end of file diff --git a/nativescript-angular/platform-common.ts b/nativescript-angular/platform-common.ts index 58e995ee9..d17b17eca 100644 --- a/nativescript-angular/platform-common.ts +++ b/nativescript-angular/platform-common.ts @@ -1,13 +1,3 @@ -// Initial imports and polyfills -import "@nativescript/core/globals"; -// Require application early to work around a circular import -import "@nativescript/core/application"; -import "./zone-js/dist/zone-nativescript"; -// TODO: migrate to standard zone.js if possible -// investigate Ivy with templated-items-comp to allow standard zone below to be used instead of patched {N} zone above -// import 'zone.js/dist/zone'; -import "./polyfills/array"; -import "./polyfills/console"; import { profile, uptime } from "@nativescript/core/profiling"; import { getRootView } from "@nativescript/core/application"; import "./dom-adapter"; @@ -32,7 +22,7 @@ import { } from "@angular/core"; import { DOCUMENT } from "@angular/common"; -import { bootstrapLog, bootstrapLogError, isLogEnabled } from "./trace"; +import { NativeScriptDebug } from "./trace"; import { defaultPageFactoryProvider, setRootPage, PageFactory, PAGE_FACTORY, getRootPage } from "./platform-providers"; import { @@ -52,11 +42,11 @@ let lastBootstrappedModule: WeakRef>; type BootstrapperAction = () => Promise>; // Work around a TS bug requiring an import of OpaqueToken without using it -if ((global).___TS_UNUSED) { - (() => { - return InjectionToken; - })(); -} +// if ((global).___TS_UNUSED) { +// (() => { +// return InjectionToken; +// })(); +// } // tslint:disable:max-line-length /** @@ -201,14 +191,14 @@ export class NativeScriptPlatformRef extends PlatformRef { let rootContent: View; let launchView: AppLaunchView; - if (isLogEnabled()) { - bootstrapLog("NativeScriptPlatform bootstrap started."); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog("NativeScriptPlatform bootstrap started."); } const launchCallback = profile( "@nativescript/angular/platform-common.launchCallback", (args: LaunchEventData) => { - if (isLogEnabled()) { - bootstrapLog("Application launch event fired"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog("Application launch event fired"); } if (this.appOptions && this.appOptions.launchView) { @@ -232,8 +222,8 @@ export class NativeScriptPlatformRef extends PlatformRef { } this._bootstrapper().then(moduleRef => { - if (isLogEnabled()) { - bootstrapLog(`Angular bootstrap bootstrap done. uptime: ${uptime()}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog(`Angular bootstrap bootstrap done. uptime: ${uptime()}`); } rootContent = launchView; @@ -247,22 +237,22 @@ export class NativeScriptPlatformRef extends PlatformRef { err => { const errorMessage = err.message + "\n\n" + err.stack; - if (isLogEnabled()) { - bootstrapLogError("ERROR BOOTSTRAPPING ANGULAR"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLogError("ERROR BOOTSTRAPPING ANGULAR"); } - if (isLogEnabled()) { - bootstrapLogError(errorMessage); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLogError(errorMessage); } rootContent = this.createErrorUI(errorMessage); } ); - if (isLogEnabled()) { - bootstrapLog("bootstrapAction called, draining micro tasks queue. Root: " + rootContent); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog("bootstrapAction called, draining micro tasks queue. Root: " + rootContent); } (global).Zone.drainMicroTaskQueue(); - if (isLogEnabled()) { - bootstrapLog("bootstrapAction called, draining micro tasks queue finished! Root: " + rootContent); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog("bootstrapAction called, draining micro tasks queue finished! Root: " + rootContent); } }); } @@ -294,8 +284,8 @@ export class NativeScriptPlatformRef extends PlatformRef { @profile public _livesync() { - if (isLogEnabled()) { - bootstrapLog("Angular livesync started."); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog("Angular livesync started."); } const lastModuleRef = lastBootstrappedModule ? lastBootstrappedModule.get() : null; @@ -306,8 +296,8 @@ export class NativeScriptPlatformRef extends PlatformRef { this._bootstrapper().then( moduleRef => { - if (isLogEnabled()) { - bootstrapLog("Angular livesync done."); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLog("Angular livesync done."); } onAfterLivesync.next({ moduleRef }); @@ -317,12 +307,12 @@ export class NativeScriptPlatformRef extends PlatformRef { }); }, error => { - if (isLogEnabled()) { - bootstrapLogError("ERROR LIVESYNC BOOTSTRAPPING ANGULAR"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLogError("ERROR LIVESYNC BOOTSTRAPPING ANGULAR"); } const errorMessage = error.message + "\n\n" + error.stack; - if (isLogEnabled()) { - bootstrapLogError(errorMessage); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.bootstrapLogError(errorMessage); } applicationRerun({ diff --git a/nativescript-angular/platform-providers.ts b/nativescript-angular/platform-providers.ts index 5941ff7e5..c0e8c7047 100644 --- a/nativescript-angular/platform-providers.ts +++ b/nativescript-angular/platform-providers.ts @@ -64,54 +64,3 @@ export const defaultPageFactory: PageFactory = function (_opts: PageFactoryOptio return new Page(); }; export const defaultPageFactoryProvider = { provide: PAGE_FACTORY, useValue: defaultPageFactory }; - -@Injectable() -export class FrameService { - // TODO: Add any methods that are needed to handle frame/page navigation - getFrame(): Frame { - let topmostFrame = Frame.topmost(); - return topmostFrame; - } -} - -@Injectable() -export class PageService implements OnDestroy { - private _inPage$ = new BehaviorSubject(false); - private _pageEvents$ = new Subject(); - - get inPage(): boolean { return this._inPage$.value; } - get inPage$(): Observable { return this._inPage$.pipe(distinctUntilChanged()); } - get pageEvents$(): Observable { return this._pageEvents$.asObservable(); } - constructor(public page: Page) { - if (this.page) { - this.page.on("navigatedFrom", this.pageEvent, this); - this.page.on("navigatedTo", this.pageEvent, this); - this.page.on("navigatingFrom", this.pageEvent, this); - this.page.on("navigatingTo", this.pageEvent, this); - } - } - - ngOnDestroy() { - if (this.page) { - this.page.off("navigatedFrom", this.pageEvent, this); - this.page.off("navigatedTo", this.pageEvent, this); - this.page.off("navigatingFrom", this.pageEvent, this); - this.page.off("navigatingTo", this.pageEvent, this); - } - this._inPage$.complete(); - this._pageEvents$.complete(); - } - - private pageEvent(evt: NavigatedData) { - this._pageEvents$.next(evt); - switch (evt.eventName) { - case "navigatedTo": - this._inPage$.next(true); - break; - case "navigatedFrom": - this._inPage$.next(false); - break; - default: - } - } -} diff --git a/nativescript-angular/platform.ts b/nativescript-angular/platform.ts index 8dadb4836..78fae36ea 100644 --- a/nativescript-angular/platform.ts +++ b/nativescript-angular/platform.ts @@ -5,16 +5,16 @@ import { COMMON_PROVIDERS } from "./platform-common"; -import { NSFileSystem } from "./file-system/ns-file-system"; +// import { NSFileSystem } from "./file-system/ns-file-system"; -import { - ElementSchemaRegistry, - ResourceLoader, -} from "@angular/compiler"; +// import { +// ElementSchemaRegistry, +// ResourceLoader, +// } from "@angular/compiler"; -import { - ɵplatformCoreDynamic as platformCoreDynamic -} from "@angular/platform-browser-dynamic"; +// import { +// ɵplatformCoreDynamic as platformCoreDynamic +// } from "@angular/platform-browser-dynamic"; import { COMPILER_OPTIONS, @@ -29,41 +29,58 @@ import { // Work around a TS bug requiring an imports of // InjectionToken, ViewEncapsulation and MissingTranslationStrategy // without using them -if ((global).___TS_UNUSED) { - (() => InjectionToken)(); - (() => ViewEncapsulation)(); - (() => MissingTranslationStrategy)(); -} +// if ((global).___TS_UNUSED) { +// (() => InjectionToken)(); +// (() => ViewEncapsulation)(); +// (() => MissingTranslationStrategy)(); +// } + +// import { NativeScriptElementSchemaRegistry } from "./schema-registry"; +// import { FileSystemResourceLoader } from "./resource-loader"; -import { NativeScriptElementSchemaRegistry } from "./schema-registry"; -import { FileSystemResourceLoader } from "./resource-loader"; +// export const NS_COMPILER_PROVIDERS: StaticProvider[] = [ +// { +// provide: COMPILER_OPTIONS, +// useValue: { +// providers: [ +// { provide: NSFileSystem, deps: [] }, +// { provide: ResourceLoader, useClass: FileSystemResourceLoader, deps: [NSFileSystem] }, +// { provide: ElementSchemaRegistry, useClass: NativeScriptElementSchemaRegistry, deps: [] }, +// ] +// }, +// multi: true +// }, +// ]; -export const NS_COMPILER_PROVIDERS: StaticProvider[] = [ - { - provide: COMPILER_OPTIONS, - useValue: { - providers: [ - { provide: NSFileSystem, deps: [] }, - { provide: ResourceLoader, useClass: FileSystemResourceLoader, deps: [NSFileSystem] }, - { provide: ElementSchemaRegistry, useClass: NativeScriptElementSchemaRegistry, deps: [] }, - ] - }, - multi: true - }, -]; +// // Dynamic platform +// const _platformNativeScriptDynamic: PlatformFactory = createPlatformFactory( +// platformCoreDynamic, "nativeScriptDynamic", [...COMMON_PROVIDERS, ...NS_COMPILER_PROVIDERS]); -// Dynamic platform -const _platformNativeScriptDynamic: PlatformFactory = createPlatformFactory( - platformCoreDynamic, "nativeScriptDynamic", [...COMMON_PROVIDERS, ...NS_COMPILER_PROVIDERS]); +// export function platformNativeScriptDynamic( +// options?: AppOptions, +// extraProviders?: any[] +// ): PlatformRef { +// // Return raw platform to advanced users only if explicitly requested +// if (options && options.bootInExistingPage === true) { +// return _platformNativeScriptDynamic(extraProviders); +// } else { +// return new NativeScriptPlatformRef(_platformNativeScriptDynamic(extraProviders), options); +// } +// } -export function platformNativeScriptDynamic( - options?: AppOptions, - extraProviders?: any[] -): PlatformRef { - // Return raw platform to advanced users only if explicitly requested - if (options && options.bootInExistingPage === true) { - return _platformNativeScriptDynamic(extraProviders); - } else { - return new NativeScriptPlatformRef(_platformNativeScriptDynamic(extraProviders), options); - } + +import { platformCore } from "@angular/core"; + +// "Static" platform +const _platformNativeScript: PlatformFactory = createPlatformFactory( + platformCore, "nativeScript", [...COMMON_PROVIDERS]); + +export function platformNativeScript(options?: AppOptions, extraProviders?: any[]): PlatformRef { + // Return raw platform to advanced users only if explicitly requested + if (options && options.bootInExistingPage === true) { + return _platformNativeScript(extraProviders); + } else { + return new NativeScriptPlatformRef(_platformNativeScript(extraProviders), options); + } } + diff --git a/nativescript-angular/renderer.ts b/nativescript-angular/renderer.ts index 508284f36..4b176c85f 100644 --- a/nativescript-angular/renderer.ts +++ b/nativescript-angular/renderer.ts @@ -12,7 +12,7 @@ import { profile } from "@nativescript/core/profiling"; import { APP_ROOT_VIEW, DEVICE, getRootPage } from "./platform-providers"; import { ViewUtil } from "./view-util"; import { NgView, InvisibleNode } from "./element-registry"; -import { rendererLog as traceLog, isLogEnabled } from "./trace"; +import { NativeScriptDebug } from "./trace"; // CONTENT_ATTR not exported from NativeScript_renderer - we need it for styles application. const COMPONENT_REGEX = /%COMP%/g; @@ -79,8 +79,8 @@ export class NativeScriptRendererFactory implements RendererFactory2 { } ngOnDestroy(): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRendererFactory.ngOnDestroy()`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRendererFactory.ngOnDestroy()`); } while (this.rootNgView && this.rootNgView.firstChild) { @@ -98,23 +98,23 @@ export class NativeScriptRenderer extends Renderer2 { private viewUtil: ViewUtil ) { super(); - if (isLogEnabled()) { - traceLog("NativeScriptRenderer created"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog("NativeScriptRenderer created"); } } @profile appendChild(parent: NgView, newChild: NgView): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.appendChild child: ${newChild} parent: ${parent}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.appendChild child: ${newChild} parent: ${parent}`); } this.viewUtil.insertChild(parent, newChild); } @profile insertBefore(parent: NgView, newChild: NgView, { previous, next }: ElementReference): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.insertBefore child: ${newChild} ` + + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.insertBefore child: ${newChild} ` + `parent: ${parent} previous: ${previous} next: ${next}`); } this.viewUtil.insertChild(parent, newChild, previous, next); @@ -122,16 +122,16 @@ export class NativeScriptRenderer extends Renderer2 { @profile removeChild(parent: any, oldChild: NgView): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.removeChild child: ${oldChild} parent: ${parent}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.removeChild child: ${oldChild} parent: ${parent}`); } this.viewUtil.removeChild(parent, oldChild); } @profile selectRootElement(selector: string): NgView { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.selectRootElement: ${selector}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.selectRootElement: ${selector}`); } if (selector && selector[0] === "#") { const result = getViewById(this.rootView, selector.slice(1)); @@ -142,16 +142,16 @@ export class NativeScriptRenderer extends Renderer2 { @profile parentNode(node: NgView): any { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.parentNode for node: ${node} is ${node.parentNode}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.parentNode for node: ${node} is ${node.parentNode}`); } return node.parentNode; } @profile nextSibling(node: NgView): ElementReference { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.nextSibling of ${node} is ${node.nextSibling}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.nextSibling of ${node} is ${node.nextSibling}`); } return { @@ -162,48 +162,48 @@ export class NativeScriptRenderer extends Renderer2 { @profile createComment(_value: any): InvisibleNode { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.createComment ${_value}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.createComment ${_value}`); } return this.viewUtil.createComment(); } @profile createElement(name: any, _namespace: string): NgView { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.createElement: ${name}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.createElement: ${name}`); } return this.viewUtil.createView(name); } @profile createText(_value: string): InvisibleNode { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.createText ${_value}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.createText ${_value}`); } return this.viewUtil.createText(); } @profile createViewRoot(hostElement: NgView): NgView { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.createViewRoot ${hostElement.nodeName}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.createViewRoot ${hostElement.nodeName}`); } return hostElement; } @profile projectNodes(parentElement: NgView, nodes: NgView[]): void { - if (isLogEnabled()) { - traceLog("NativeScriptRenderer.projectNodes"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog("NativeScriptRenderer.projectNodes"); } nodes.forEach((node) => this.viewUtil.insertChild(parentElement, node)); } @profile destroy() { - if (isLogEnabled()) { - traceLog("NativeScriptRenderer.destroy"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog("NativeScriptRenderer.destroy"); } // Seems to be called on component dispose only (router outlet) // TODO: handle this when we resolve routing and navigation. @@ -211,55 +211,55 @@ export class NativeScriptRenderer extends Renderer2 { @profile setAttribute(view: NgView, name: string, value: string, namespace?: string) { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.setAttribute ${view} : ${name} = ${value}, namespace: ${namespace}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.setAttribute ${view} : ${name} = ${value}, namespace: ${namespace}`); } return this.viewUtil.setProperty(view, name, value, namespace); } @profile removeAttribute(_el: NgView, _name: string): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.removeAttribute ${_el}: ${_name}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.removeAttribute ${_el}: ${_name}`); } } @profile setProperty(view: any, name: string, value: any) { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.setProperty ${view} : ${name} = ${value}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.setProperty ${view} : ${name} = ${value}`); } return this.viewUtil.setProperty(view, name, value); } @profile addClass(view: NgView, name: string): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.addClass ${name}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.addClass ${name}`); } this.viewUtil.addClass(view, name); } @profile removeClass(view: NgView, name: string): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.removeClass ${name}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.removeClass ${name}`); } this.viewUtil.removeClass(view, name); } @profile setStyle(view: NgView, styleName: string, value: any, _flags?: RendererStyleFlags2): void { - if (isLogEnabled()) { - traceLog(`NativeScriptRenderer.setStyle: ${styleName} = ${value}`); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog(`NativeScriptRenderer.setStyle: ${styleName} = ${value}`); } this.viewUtil.setStyle(view, styleName, value); } @profile removeStyle(view: NgView, styleName: string, _flags?: RendererStyleFlags2): void { - if (isLogEnabled()) { - traceLog("NativeScriptRenderer.removeStyle: ${styleName}"); + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.rendererLog("NativeScriptRenderer.removeStyle: ${styleName}"); } this.viewUtil.removeStyle(view, styleName); } @@ -268,37 +268,37 @@ export class NativeScriptRenderer extends Renderer2 { // such as