From c5714ddf336b6a85a669cf427db555c8bf0d8f2b Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Thu, 11 Jun 2020 18:56:37 +0200 Subject: [PATCH 01/11] feat: basic update for @nativescript/angular@9.0.0 --- README.md | 6 +- package.json | 21 +++--- ...yModuleName@dasherize__.module__nsext__.ts | 9 +-- .../app/app-routing.module__nsext__.ts | 2 +- .../_ns-files/__sourceDir__/main__nsext__.ts | 2 +- src/add-ns/_ns-files/tsconfig__nsext__.json | 2 +- .../barcelona/barcelona.module__nsext__.ts | 3 +- src/add-ns/index.ts | 14 ++-- src/add-ns/index_spec.ts | 10 +-- .../__name__/__master__.module.ts | 3 +- .../__name__/__master__.module__nsext__.ts | 3 +- src/generate/module/index.ts | 6 +- src/generate/module/index_spec.ts | 6 +- .../__name@dasherize__.module__nsext__.ts | 2 +- .../__sourcedir__/app-routing.module.ts | 2 +- .../_files/__sourcedir__/app.module.ts | 9 +-- .../application/_files/__sourcedir__/main.ts | 2 +- src/ng-new/application/_files/package.json | 40 +++++------ src/ng-new/application/_files/tsconfig.json | 2 +- src/ng-new/application/index_spec.ts | 4 +- .../app/app-routing.module.tns.ts | 2 +- .../__sourcedir__/app/app.module.tns.ts | 9 +-- .../shared/_files/__sourcedir__/main.tns.ts | 2 +- src/ng-new/shared/_files/package.json | 66 +++++++++---------- src/ng-new/shared/_files/tsconfig.tns.json | 2 +- .../barcelona/barcelona.module.tns.ts | 3 +- src/refactor-nsng-modules/index.ts | 4 +- src/refactor-nsng-modules/index_spec.ts | 26 ++++---- src/test-utils.ts | 6 +- src/ts-utils.ts | 2 +- 30 files changed, 131 insertions(+), 139 deletions(-) diff --git a/README.md b/README.md index 21c5b98e..1d609c46 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository contains schematics for generating components in NativeScript An ### Install Angular CLI -You should be using `@angular/cli@6.1.0` or newer. +You should be using `@angular/cli@9.1.0` or newer. ```bash npm i -g @angular/cli @@ -141,8 +141,8 @@ This includes the following steps: In a code sharing project to build: * a `web` app call: `ng serve`, - * an `iOS` app call: `tns run ios --bundle`, - * an `Android` app call: `tns run android --bundle` + * an `iOS` app call: `tns run ios --bundle --env.aot`, + * an `Android` app call: `tns run android --bundle --env.aot` ## Templates diff --git a/package.json b/package.json index 971ac985..9b19ffce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/schematics", - "version": "1.0.0", + "version": "2.0.0", "description": "Schematics for NativeScript Angular apps.", "scripts": { "build": "tsc -p tsconfig.json", @@ -17,20 +17,21 @@ }, "schematics": "./src/collection.json", "dependencies": { - "@angular-devkit/core": "~8.2.0", - "@angular-devkit/schematics": "~8.2.0", - "@nativescript/tslint-rules": "~0.0.3", + "@angular-devkit/core": "~9.1.0", + "@angular-devkit/schematics": "~9.1.0", + "@nativescript/tslint-rules": "~0.0.5", "@phenomnomnominal/tsquery": "^3.0.0" }, "devDependencies": { - "@schematics/angular": "~8.2.0", - "@types/jasmine": "^2.6.0", - "@types/node": "^8.0.31", + "@schematics/angular": "~9.1.0", + "@types/jasmine": "~3.5.0", + "@types/jasminewd2": "~2.0.3", + "@types/node": "^12.11.1", "conventional-changelog-cli": "^2.0.1", "jasmine": "^2.8.0", "jasmine-spec-reporter": "^4.2.1", - "tslint": "^5.18.0", - "typescript": "3.5.3" + "tslint": "~6.1.0", + "typescript": "~3.8.3" }, "repository": { "type": "git", @@ -55,4 +56,4 @@ "Sebastian Witalec " ], "license": "Apache-2.0" -} \ No newline at end of file +} diff --git a/src/add-ns/_ns-files/__sourceDir__/app/__entryModuleName@dasherize__.module__nsext__.ts b/src/add-ns/_ns-files/__sourceDir__/app/__entryModuleName@dasherize__.module__nsext__.ts index 84ec7550..3fbd7262 100644 --- a/src/add-ns/_ns-files/__sourceDir__/app/__entryModuleName@dasherize__.module__nsext__.ts +++ b/src/add-ns/_ns-files/__sourceDir__/app/__entryModuleName@dasherize__.module__nsext__.ts @@ -1,16 +1,13 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptModule } from 'nativescript-angular/nativescript.module'; +import { NativeScriptModule } from '@nativescript/angular'; import { AppRoutingModule } from './app-routing.module<%= nsext %>'; import { <%= entryComponentClassName %> } from '<%= entryComponentImportPath %>'; <% if (sample) { %> import { BarcelonaModule } from './barcelona/barcelona.module';<% } %> -// Uncomment and add to NgModule imports if you need to use two-way binding -// import { NativeScriptFormsModule } from 'nativescript-angular/forms'; - -// Uncomment and add to NgModule imports if you need to use the HTTP wrapper -// import { NativeScriptHttpClientModule } from 'nativescript-angular/http-client'; +// Uncomment and add to NgModule imports if you need to use two-way binding and/or HTTP wrapper +// import { NativeScriptFormsModule, NativeScriptHttpClientModule } from '@nativescript/angular'; @NgModule({ declarations: [ diff --git a/src/add-ns/_ns-files/__sourceDir__/app/app-routing.module__nsext__.ts b/src/add-ns/_ns-files/__sourceDir__/app/app-routing.module__nsext__.ts index eabfdc1b..ceef2a4a 100644 --- a/src/add-ns/_ns-files/__sourceDir__/app/app-routing.module__nsext__.ts +++ b/src/add-ns/_ns-files/__sourceDir__/app/app-routing.module__nsext__.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptRouterModule } from '@nativescript/angular'; import { Routes } from '@angular/router'; <% if (!skipAutoGeneratedComponent) { %> import { AutoGeneratedComponent } from './auto-generated/auto-generated.component'; diff --git a/src/add-ns/_ns-files/__sourceDir__/main__nsext__.ts b/src/add-ns/_ns-files/__sourceDir__/main__nsext__.ts index 382ce157..bdfe5210 100644 --- a/src/add-ns/_ns-files/__sourceDir__/main__nsext__.ts +++ b/src/add-ns/_ns-files/__sourceDir__/main__nsext__.ts @@ -1,5 +1,5 @@ // this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; +import { platformNativeScriptDynamic } from '@nativescript/angular/platform'; import { <%= entryModuleClassName %> } from '<%= entryModuleImportPath %>'; diff --git a/src/add-ns/_ns-files/tsconfig__nsext__.json b/src/add-ns/_ns-files/tsconfig__nsext__.json index 7b7659ef..cc51f647 100644 --- a/src/add-ns/_ns-files/tsconfig__nsext__.json +++ b/src/add-ns/_ns-files/tsconfig__nsext__.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "es2015", + "module": "ESNext", "moduleResolution": "node", "skipLibCheck": true, "paths": { diff --git a/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts b/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts index 1178e002..573f7a96 100644 --- a/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts +++ b/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts @@ -1,6 +1,5 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptCommonModule } from 'nativescript-angular/common'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; import { componentDeclarations, diff --git a/src/add-ns/index.ts b/src/add-ns/index.ts index 1412297c..27e293af 100644 --- a/src/add-ns/index.ts +++ b/src/add-ns/index.ts @@ -223,10 +223,12 @@ const addRunScriptsToPackageJson = (tree: Tree, context: SchematicContext) => { const packageJson = getPackageJson(tree); const scriptsToAdd = { - android: 'tns run android', - ios: 'tns run ios', + android: 'tns run android --env.aot', + ios: 'tns run ios --env.aot', mobile: 'tns run', preview: 'tns preview', + ngcc: 'ngcc --properties es2015 module main --first-only', + postinstall: 'npm run ngcc' }; packageJson.scripts = {...scriptsToAdd, ...packageJson.scripts}; @@ -362,17 +364,17 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => { // @UPGRADE: Update all versions whenever {N} version updates const depsToAdd = { - 'nativescript-angular': '~8.20.0', + '@nativescript/angular': '~9.0.0', + '@nativescript/core': '~6.5.5', '@nativescript/theme': '~2.2.1', 'reflect-metadata': '~0.1.12', - 'tns-core-modules': '~6.3.0', 'tslib': '1.10.0', }; packageJson.dependencies = {...depsToAdd, ...packageJson.dependencies}; const devDepsToAdd = { - 'nativescript-dev-webpack': '~1.4.0', - '@nativescript/schematics': '~1.0.0', + 'nativescript-dev-webpack': '~1.5.0', + '@nativescript/schematics': '~2.0.0', '@nativescript/tslint-rules': '~0.0.5', }; packageJson.devDependencies = {...devDepsToAdd, ...packageJson.devDependencies}; diff --git a/src/add-ns/index_spec.ts b/src/add-ns/index_spec.ts index 72fec332..8a3fc4fa 100644 --- a/src/add-ns/index_spec.ts +++ b/src/add-ns/index_spec.ts @@ -77,9 +77,9 @@ describe('Add {N} schematic', () => { const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath)); const { dependencies, devDependencies } = packageJson; expect(dependencies).toBeDefined(); - expect(dependencies['nativescript-angular']).toBeDefined(); + expect(dependencies['@nativescript/angular']).toBeDefined(); expect(dependencies['@nativescript/theme']).toBeDefined(); - expect(dependencies['tns-core-modules']).toBeDefined(); + expect(dependencies['@nativescript/core']).toBeDefined(); expect(dependencies['reflect-metadata']).toBeDefined(); expect(devDependencies['nativescript-dev-webpack']).toBeDefined(); @@ -94,8 +94,10 @@ describe('Add {N} schematic', () => { const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath)); const { scripts } = packageJson; expect(scripts).toBeDefined(); - expect(scripts.android).toEqual('tns run android'); - expect(scripts.ios).toEqual('tns run ios'); + expect(scripts.android).toEqual('tns run android --env.aot'); + expect(scripts.ios).toEqual('tns run ios --env.aot'); + expect(scripts.ngcc).toEqual('ngcc --properties es2015 module main --first-only'); + expect(scripts.postinstall).toEqual('npm run ngcc'); }); it('should add NativeScript key to the package json', () => { diff --git a/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts b/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts index e540dace..2c8d02f8 100644 --- a/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts +++ b/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts @@ -1,7 +1,6 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; import { Routes } from '@angular/router'; -import { NativeScriptCommonModule } from 'nativescript-angular/common'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; import { <%= masterClassName %>Component } from './<%= master %>/<%= master %>.component'; import { <%= detailClassName %>DetailComponent } from './<%= detail %>-detail/<%= detail %>-detail.component'; diff --git a/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts b/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts index 1d479476..1d560610 100644 --- a/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts +++ b/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts @@ -1,6 +1,5 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptCommonModule } from 'nativescript-angular/common'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; import { componentDeclarations, diff --git a/src/generate/module/index.ts b/src/generate/module/index.ts index 11bc91ec..1cbb3282 100644 --- a/src/generate/module/index.ts +++ b/src/generate/module/index.ts @@ -228,7 +228,7 @@ const ensureNsRouting = (tree: Tree, path: string) => { const importFrom = `, NativeScriptRouterModule } from '@angular/router';`; const importTo = ` } from '@angular/router'; -import { NativeScriptRouterModule } from 'nativescript-angular/router';`; +import { NativeScriptRouterModule } from '@nativescript/angular';`; const newText = fileText.replace(/RouterModule/g, 'NativeScriptRouterModule') .replace(importFrom, importTo); @@ -270,7 +270,7 @@ const addNSRouterModule = (tree: Tree, routingModulePath: string) => { const addedImport = addSymbolToNgModuleMetadata( moduleSource, routingModulePath, 'imports', `${moduleName}.forChild(routes)`, - 'nativescript-angular/router' + '@nativescript/angular' ); const importRecorder = tree.beginUpdate(routingModulePath); @@ -335,7 +335,7 @@ const addNSCommonModule = (tree: Tree, modulePath: string) => { const metadataChange = addSymbolToNgModuleMetadata( moduleSource, modulePath, 'imports', 'NativeScriptCommonModule', - 'nativescript-angular/common'); + '@nativescript/angular'); metadataChange.forEach((change: InsertChange) => recorder.insertRight(change.pos, change.toAdd), diff --git a/src/generate/module/index_spec.ts b/src/generate/module/index_spec.ts index 9c9144f8..9ab5175a 100644 --- a/src/generate/module/index_spec.ts +++ b/src/generate/module/index_spec.ts @@ -70,7 +70,7 @@ describe('Module Schematic', () => { it('should have NativeScriptCommonModule imported', () => { const content = getFileContent(tree, noExtensionModulePath); - expect(content).toMatch(`import { NativeScriptCommonModule } from 'nativescript-angular/common'`); + expect(content).toMatch(`import { NativeScriptCommonModule } from '@nativescript/angular'`); }); it('should have NO_ERRORS_SCHEMA imported', () => { @@ -102,7 +102,7 @@ describe('Module Schematic', () => { const testTree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const content = getFileContent(testTree, noExtensionModulePath); - expect(content).not.toMatch(`import { NativeScriptCommonModule } from 'nativescript-angular/common'`); + expect(content).not.toMatch(`import { NativeScriptCommonModule } from '@nativescript/angular'`); }); it('should not have RouterModule imported in the routing module', async () => { @@ -124,7 +124,7 @@ describe('Module Schematic', () => { const testTree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const content = getFileContent(testTree, noExtensionRoutingModulePath); - expect(content).toMatch(`import { NativeScriptRouterModule } from 'nativescript-angular/router'`); + expect(content).toMatch(`import { NativeScriptRouterModule } from '@nativescript/angular'`); }); }); diff --git a/src/migrate-module/_ns-files/__name@dasherize__.module__nsext__.ts b/src/migrate-module/_ns-files/__name@dasherize__.module__nsext__.ts index 5ee10a88..6524dbe3 100644 --- a/src/migrate-module/_ns-files/__name@dasherize__.module__nsext__.ts +++ b/src/migrate-module/_ns-files/__name@dasherize__.module__nsext__.ts @@ -1,5 +1,5 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptCommonModule } from 'nativescript-angular/common'; +import { NativeScriptCommonModule } from '@nativescript/angular'; @NgModule({ imports: [ diff --git a/src/ng-new/application/_files/__sourcedir__/app-routing.module.ts b/src/ng-new/application/_files/__sourcedir__/app-routing.module.ts index d6cfb189..2634f0e3 100644 --- a/src/ng-new/application/_files/__sourcedir__/app-routing.module.ts +++ b/src/ng-new/application/_files/__sourcedir__/app-routing.module.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptRouterModule } from '@nativescript/angular'; import { Routes } from '@angular/router'; import { HomeComponent } from './home/home.component'; diff --git a/src/ng-new/application/_files/__sourcedir__/app.module.ts b/src/ng-new/application/_files/__sourcedir__/app.module.ts index 5a983966..581c8314 100644 --- a/src/ng-new/application/_files/__sourcedir__/app.module.ts +++ b/src/ng-new/application/_files/__sourcedir__/app.module.ts @@ -1,15 +1,12 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptModule } from 'nativescript-angular/nativescript.module'; +import { NativeScriptModule } from '@nativescript/angular'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { HomeComponent } from './home/home.component'; -// Uncomment and add to NgModule imports if you need to use two-way binding -// import { NativeScriptFormsModule } from 'nativescript-angular/forms'; - -// Uncomment and add to NgModule imports if you need to use the HTTP wrapper -// import { NativeScriptHttpClientModule } from 'nativescript-angular/http-client'; +// Uncomment and add to NgModule imports if you need to use two-way binding and/or HTTP wrapper +// import { NativeScriptFormsModule, NativeScriptHttpClientModule } from '@nativescript/angular'; @NgModule({ declarations: [ diff --git a/src/ng-new/application/_files/__sourcedir__/main.ts b/src/ng-new/application/_files/__sourcedir__/main.ts index 61686e49..7659c6c3 100644 --- a/src/ng-new/application/_files/__sourcedir__/main.ts +++ b/src/ng-new/application/_files/__sourcedir__/main.ts @@ -1,4 +1,4 @@ -import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; +import { platformNativeScriptDynamic } from '@nativescript/angular/platform'; import { AppModule } from './app.module'; platformNativeScriptDynamic().bootstrapModule(AppModule); diff --git a/src/ng-new/application/_files/package.json b/src/ng-new/application/_files/package.json index b063fa52..280a48ad 100644 --- a/src/ng-new/application/_files/package.json +++ b/src/ng-new/application/_files/package.json @@ -6,30 +6,30 @@ "id": "org.nativescript.<%= utils.sanitize(name) %>" }, "dependencies": { - "@angular/animations": "~8.2.0", - "@angular/common": "~8.2.0", - "@angular/compiler": "~8.2.0", - "@angular/core": "~8.2.0", - "@angular/forms": "~8.2.0", - "@angular/http": "~8.0.0-beta.10", - "@angular/platform-browser": "~8.2.0", - "@angular/platform-browser-dynamic": "~8.2.0", - "@angular/router": "~8.2.0", - "nativescript-angular": "~8.20.0",<% if(theme) { %> + "@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/http": "~9.1.0", + "@angular/platform-browser": "~9.1.0", + "@angular/platform-browser-dynamic": "~9.1.0", + "@angular/router": "~9.1.0", + "@nativescript/angular": "~9.0.0", + "@nativescript/core": "~6.5.5",<% if(theme) { %> "@nativescript/theme": "~2.2.1", <% } %>"reflect-metadata": "~0.1.12", - "rxjs": "~6.4.0", - "tns-core-modules": "~6.3.0", + "rxjs": "~6.5.5", "tslib": "1.10.0", - "zone.js": "~0.9.1" + "zone.js": "~0.10.2" }, "devDependencies": { - "@angular/cli": "~8.3.0", - "@angular/compiler-cli": "~8.2.0", - "@angular-devkit/core": "~8.2.0", - "@nativescript/schematics": "~1.0.0",<% if(webpack) { %> - "nativescript-dev-webpack": "~1.4.0", - "@ngtools/webpack": "~8.2.0", - <% } %>"typescript": "~3.5.3" + "@angular/cli": "~9.1.0", + "@angular/compiler-cli": "~9.1.0", + "@angular-devkit/core": "~9.1.0", + "@nativescript/schematics": "~2.0.0",<% if(webpack) { %> + "nativescript-dev-webpack": "~1.5.0", + "@ngtools/webpack": "~9.1.0", + <% } %>"typescript": "~3.8.3" } } diff --git a/src/ng-new/application/_files/tsconfig.json b/src/ng-new/application/_files/tsconfig.json index d917c3c1..09fd4dcb 100644 --- a/src/ng-new/application/_files/tsconfig.json +++ b/src/ng-new/application/_files/tsconfig.json @@ -15,7 +15,7 @@ "baseUrl": ".", "paths": { "*": [ - "./node_modules/tns-core-modules/*", + "./node_modules/@nativescript/core/*", "./node_modules/*" ] } diff --git a/src/ng-new/application/index_spec.ts b/src/ng-new/application/index_spec.ts index e1f4b916..e2363099 100644 --- a/src/ng-new/application/index_spec.ts +++ b/src/ng-new/application/index_spec.ts @@ -50,7 +50,7 @@ describe('Application Schematic', () => { expect(content).toMatch(isInModuleMetadata('AppModule', 'declarations', 'AppComponent', true)); expect(content).toMatch(isInModuleMetadata('AppModule', 'imports', 'NativeScriptModule', true)); - expect(content).toMatch('import { NativeScriptModule } from \'nativescript-angular/nativescript.module\''); + expect(content).toMatch('import { NativeScriptModule } from \'@nativescript/angular\''); expect(content).toMatch('import { AppComponent } from \'./app.component\''); }); @@ -94,7 +94,7 @@ describe('Application Schematic', () => { const packageJson = '/foo/package.json'; expect(getFileContent(tree, packageJson)) .not - .toMatch(new RegExp('nativescript-dev-webpack')); + .toMatch(new RegExp('@ngtools/webpack')); const files = tree!.files; expect(files).not.toContain('/foo/webpack.config.js'); diff --git a/src/ng-new/shared/_files/__sourcedir__/app/app-routing.module.tns.ts b/src/ng-new/shared/_files/__sourcedir__/app/app-routing.module.tns.ts index 66fdcff7..32e1d211 100644 --- a/src/ng-new/shared/_files/__sourcedir__/app/app-routing.module.tns.ts +++ b/src/ng-new/shared/_files/__sourcedir__/app/app-routing.module.tns.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptRouterModule } from '@nativescript/angular'; import { routes } from '@src/app/app.routes'; @NgModule({ diff --git a/src/ng-new/shared/_files/__sourcedir__/app/app.module.tns.ts b/src/ng-new/shared/_files/__sourcedir__/app/app.module.tns.ts index 429441e7..c4f0366e 100644 --- a/src/ng-new/shared/_files/__sourcedir__/app/app.module.tns.ts +++ b/src/ng-new/shared/_files/__sourcedir__/app/app.module.tns.ts @@ -1,5 +1,5 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptModule } from 'nativescript-angular/nativescript.module'; +import { NativeScriptModule } from '@nativescript/angular'; import { AppRoutingModule } from '@src/app/app-routing.module'; import { AppComponent } from '@src/app/app.component'; @@ -7,11 +7,8 @@ import { HomeComponent } from '@src/app/home/home.component'; <% if (sample) { %> import { BarcelonaModule } from '@src/app/barcelona/barcelona.module';<% } %> -// Uncomment and add to NgModule imports if you need to use two-way binding -// import { NativeScriptFormsModule } from 'nativescript-angular/forms'; - -// Uncomment and add to NgModule imports if you need to use the HTTP wrapper -// import { NativeScriptHttpClientModule } from 'nativescript-angular/http-client'; +// Uncomment and add to NgModule imports if you need to use two-way binding and/or HTTP wrapper +// import { NativeScriptFormsModule, NativeScriptHttpClientModule } from '@nativescript/angular'; @NgModule({ declarations: [ diff --git a/src/ng-new/shared/_files/__sourcedir__/main.tns.ts b/src/ng-new/shared/_files/__sourcedir__/main.tns.ts index 8e72725d..aeebcc1a 100644 --- a/src/ng-new/shared/_files/__sourcedir__/main.tns.ts +++ b/src/ng-new/shared/_files/__sourcedir__/main.tns.ts @@ -1,5 +1,5 @@ // this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; +import { platformNativeScriptDynamic } from '@nativescript/angular/platform'; import { AppModule } from '@src/app/app.module'; diff --git a/src/ng-new/shared/_files/package.json b/src/ng-new/shared/_files/package.json index 41ae9796..811ab203 100644 --- a/src/ng-new/shared/_files/package.json +++ b/src/ng-new/shared/_files/package.json @@ -11,52 +11,52 @@ "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", - "android": "tns run android", - "ios": "tns run ios", + "android": "tns run android --env.aot", + "ios": "tns run ios --env.aot", "mobile": "tns run", "preview": "tns preview" }, "private": true, "dependencies": { - "@angular/animations": "~8.2.0", - "@angular/common": "~8.2.0", - "@angular/compiler": "~8.2.0", - "@angular/core": "~8.2.0", - "@angular/forms": "~8.2.0", - "@angular/http": "~8.0.0-beta.10", - "@angular/platform-browser": "~8.2.0", - "@angular/platform-browser-dynamic": "~8.2.0", - "@angular/router": "~8.2.0", + "@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/http": "~9.1.0", + "@angular/platform-browser": "~9.1.0", + "@angular/platform-browser-dynamic": "~9.1.0", + "@angular/router": "~9.1.0", "core-js": "^2.6.9", - "nativescript-angular": "~8.20.0",<% if(theme) { %> + "@nativescript/angular": "~9.0.0", + "@nativescript/core": "~6.5.5",<% if(theme) { %> "@nativescript/theme": "~2.2.1", <% } %>"reflect-metadata": "~0.1.12", - "rxjs": "~6.4.0", - "tns-core-modules": "~6.3.0", + "rxjs": "~6.5.5", "tslib": "1.10.0", - "zone.js": "~0.9.1" + "zone.js": "~0.10.2" }, "devDependencies": { - "@angular/cli": "~8.3.0", - "@angular/compiler-cli": "~8.2.0", - "@angular-devkit/build-angular": "~0.803.0", - "@nativescript/schematics": "~1.0.0", + "@angular/cli": "~9.1.0", + "@angular/compiler-cli": "~9.1.0", + "@angular-devkit/build-angular": "~0.901.0", + "@nativescript/schematics": "~2.0.0", "@nativescript/tslint-rules": "~0.0.5", - "@types/jasmine": "~3.3.8", + "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", - "@types/node": "~8.9.4", - "codelyzer": "^5.0.0", - "jasmine-core": "~3.4.0", + "@types/node": "^12.11.1", + "codelyzer": "^5.1.2", + "jasmine-core": "~3.5.0", "jasmine-spec-reporter": "~4.2.1", - "karma": "~4.1.0", - "karma-chrome-launcher": "~2.2.0", - "karma-coverage-istanbul-reporter": "~2.0.1", - "karma-jasmine": "~2.0.1", - "karma-jasmine-html-reporter": "^1.4.0", - "nativescript-dev-webpack": "~1.4.0", - "protractor": "~5.4.0", - "ts-node": "~7.0.0", - "tslint": "~5.15.0", - "typescript": "~3.5.3" + "karma": "~4.4.1", + "karma-chrome-launcher": "~3.1.0", + "karma-coverage-istanbul-reporter": "~2.1.0", + "karma-jasmine": "~3.0.1", + "karma-jasmine-html-reporter": "^1.4.2", + "nativescript-dev-webpack": "~1.5.0", + "protractor": "~5.4.3", + "ts-node": "~8.3.0", + "tslint": "~6.1.0", + "typescript": "~3.8.3" } } diff --git a/src/ng-new/shared/_files/tsconfig.tns.json b/src/ng-new/shared/_files/tsconfig.tns.json index 307faca5..89d0f38d 100644 --- a/src/ng-new/shared/_files/tsconfig.tns.json +++ b/src/ng-new/shared/_files/tsconfig.tns.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "es2015", + "module": "ESNext", "moduleResolution": "node", "paths": { "@src/*": [ diff --git a/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts b/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts index 5b555195..bfb65ab9 100644 --- a/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts +++ b/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts @@ -1,6 +1,5 @@ import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; -import { NativeScriptCommonModule } from 'nativescript-angular/common'; -import { NativeScriptRouterModule } from 'nativescript-angular/router'; +import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; import { componentDeclarations, diff --git a/src/refactor-nsng-modules/index.ts b/src/refactor-nsng-modules/index.ts index 3b6b4468..8a68bdb9 100644 --- a/src/refactor-nsng-modules/index.ts +++ b/src/refactor-nsng-modules/index.ts @@ -57,7 +57,7 @@ export default function(options: Schema) { removeImportedNgModule(tree, path, metadataObject, 'NativeScriptModule'); if (nativeScriptModuleRemoved) { metadataObject = refetchMetadata(tree, path, classNode); - importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', 'nativescript-angular/common'); + importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', '@nativescript/angular'); } metadataObject = refetchMetadata(tree, path, classNode); @@ -78,7 +78,7 @@ export default function(options: Schema) { rootModulePath, rootModuleMetadata, 'NativeScriptAnimationsModule', - 'nativescript-angular/animations', + '@nativescript/angular', ); } }, diff --git a/src/refactor-nsng-modules/index_spec.ts b/src/refactor-nsng-modules/index_spec.ts index 18009320..367a2a67 100644 --- a/src/refactor-nsng-modules/index_spec.ts +++ b/src/refactor-nsng-modules/index_spec.ts @@ -54,8 +54,8 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptModule } from "nativescript-angular/nativescript.module"; - import { NativeScriptFormsModule } from "nativescript-angular/forms"; + import { NativeScriptModule } from "@nativescript/angular"; + import { NativeScriptFormsModule } from "@nativescript/angular"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; import { loginRouting } from "./login.routing"; @@ -84,7 +84,7 @@ describe('Refactor NsNg Modules Schematic', () => { it('should remove the NativeScriptModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptModule } from "nativescript-angular/nativescript.module";', + .not.toMatch('import { NativeScriptModule } from "@nativescript/angular";', ); }); @@ -110,7 +110,7 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; + import { NativeScriptAnimationsModule } from "@nativescript/angular"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; @NgModule({ @@ -129,7 +129,7 @@ describe('Refactor NsNg Modules Schematic', () => { it('should remove the NativeScriptAnimationsModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptAnimationsModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', + .not.toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', ); }); @@ -137,7 +137,7 @@ describe('Refactor NsNg Modules Schematic', () => { const newRootModuleContent = getFileContent(tree, rootModulePath); expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', + .toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', ); }); }); @@ -152,9 +152,9 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptModule } from "nativescript-angular/nativescript.module"; + import { NativeScriptModule } from "@nativescript/angular"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; - import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; + import { NativeScriptAnimationsModule } from "@nativescript/angular"; @NgModule({ imports: [ @@ -173,7 +173,7 @@ describe('Refactor NsNg Modules Schematic', () => { it('should remove the NativeScriptAnimationsModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptAnimationsModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', + .not.toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', ); }); @@ -181,7 +181,7 @@ describe('Refactor NsNg Modules Schematic', () => { const newRootModuleContent = getFileContent(tree, rootModulePath); expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', + .toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', ); }); @@ -189,19 +189,19 @@ describe('Refactor NsNg Modules Schematic', () => { const newRootModuleContent = getFileContent(tree, rootModulePath); expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', + .toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', ); }); it('should remove the NativeScriptModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptModule } from "nativescript-angular/nativescript.module";', + .not.toMatch('import { NativeScriptModule } from "@nativescript/angular";', ); }); it('should import the NativeScriptCommonModule to the feature module', () => { - expect(featureModuleContent).toMatch('import { NativeScriptCommonModule } from "nativescript-angular/common"'); + expect(featureModuleContent).toMatch('import { NativeScriptCommonModule } from "@nativescript/angular"'); }); it('should add the NativeScriptCommonModule to the module metadata', () => { diff --git a/src/test-utils.ts b/src/test-utils.ts index be7d88a3..eb8148c2 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -155,10 +155,10 @@ function getPackageJson(setup: TestProjectSetup): VirtualFile { content: JSON.stringify({ nativescript: { id: setup.projectName }, dependencies: { - '@angular/core': '^6.1.0', + '@angular/core': '^9.1.0', }, devDependencies: { - '@angular/cli': '^6.2.0', + '@angular/cli': '^9.1.0', }, }), }; @@ -291,7 +291,7 @@ function getNsEntryPoint(setup: TestProjectSetup): VirtualFile { return { path: `${setup.sourceDirectory}/main.ts`, content: ` - import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; + import { platformNativeScriptDynamic } from '@nativescript/angular/platform'; import { AppModule } from './app/app.module'; platformNativeScriptDynamic().bootstrapModule(AppModule); diff --git a/src/ts-utils.ts b/src/ts-utils.ts index 8a9adb6d..ec429bc5 100644 --- a/src/ts-utils.ts +++ b/src/ts-utils.ts @@ -299,7 +299,7 @@ export function addBootstrapToNgModule(modulePath: string, rootComponentName: st const importChanges = addImportToModule(source, modulePath, 'NativeScriptModule', - 'nativescript-angular/nativescript.module'); + '@nativescript/angular'); const bootstrapChanges = addBootstrapToModule(source, modulePath, From b6f845c31d4046d8b77fd26668fbc156641d53c5 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Thu, 11 Jun 2020 19:12:02 +0200 Subject: [PATCH 02/11] fix: add missing ngcc config files --- src/add-ns/_ns-files/ngcc.config.js | 19 +++++++++++++++++++ src/ng-new/application/_files/ngcc.config.js | 19 +++++++++++++++++++ src/ng-new/shared/_files/ngcc.config.js | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/add-ns/_ns-files/ngcc.config.js create mode 100644 src/ng-new/application/_files/ngcc.config.js create mode 100644 src/ng-new/shared/_files/ngcc.config.js diff --git a/src/add-ns/_ns-files/ngcc.config.js b/src/add-ns/_ns-files/ngcc.config.js new file mode 100644 index 00000000..2d241316 --- /dev/null +++ b/src/add-ns/_ns-files/ngcc.config.js @@ -0,0 +1,19 @@ +module.exports = { + packages: { + "@nativescript/angular": { + entryPoints: { + ".": { + override: { + main: "./index.js", + typings: "./index.d.ts", + }, + ignoreMissingDependencies: true, + } + }, + ignorableDeepImportMatchers: [ + /tns-core-modules\//, + /@nativescript\/core\//, + ] + } + } +}; \ No newline at end of file diff --git a/src/ng-new/application/_files/ngcc.config.js b/src/ng-new/application/_files/ngcc.config.js new file mode 100644 index 00000000..2d241316 --- /dev/null +++ b/src/ng-new/application/_files/ngcc.config.js @@ -0,0 +1,19 @@ +module.exports = { + packages: { + "@nativescript/angular": { + entryPoints: { + ".": { + override: { + main: "./index.js", + typings: "./index.d.ts", + }, + ignoreMissingDependencies: true, + } + }, + ignorableDeepImportMatchers: [ + /tns-core-modules\//, + /@nativescript\/core\//, + ] + } + } +}; \ No newline at end of file diff --git a/src/ng-new/shared/_files/ngcc.config.js b/src/ng-new/shared/_files/ngcc.config.js new file mode 100644 index 00000000..2d241316 --- /dev/null +++ b/src/ng-new/shared/_files/ngcc.config.js @@ -0,0 +1,19 @@ +module.exports = { + packages: { + "@nativescript/angular": { + entryPoints: { + ".": { + override: { + main: "./index.js", + typings: "./index.d.ts", + }, + ignoreMissingDependencies: true, + } + }, + ignorableDeepImportMatchers: [ + /tns-core-modules\//, + /@nativescript\/core\//, + ] + } + } +}; \ No newline at end of file From ea0b08bb7e45ffff63b73e1e75b0b1c3d98d9867 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Thu, 11 Jun 2020 19:15:29 +0200 Subject: [PATCH 03/11] test: check ngcc file exists --- src/add-ns/index_spec.ts | 1 + src/ng-new/application/index_spec.ts | 1 + src/ng-new/shared/index_spec.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/add-ns/index_spec.ts b/src/add-ns/index_spec.ts index 8a3fc4fa..327f9fd8 100644 --- a/src/add-ns/index_spec.ts +++ b/src/add-ns/index_spec.ts @@ -44,6 +44,7 @@ describe('Add {N} schematic', () => { it('should add {N} specific files', () => { const files = appTree.files; + expect(files).toContain('/ngcc.config.js'); expect(files).toContain('/nsconfig.json'); expect(files).toContain('/tsconfig.tns.json'); expect(files).toContain('/src/app.css'); diff --git a/src/ng-new/application/index_spec.ts b/src/ng-new/application/index_spec.ts index e2363099..95e1c6e8 100644 --- a/src/ng-new/application/index_spec.ts +++ b/src/ng-new/application/index_spec.ts @@ -25,6 +25,7 @@ describe('Application Schematic', () => { const tree = await schematicRunner.runSchematicAsync('application', options).toPromise(); const files = tree.files; expect(files).toContain('/foo/angular.json'); + expect(files).toContain('/foo/ngcc.config.js'); expect(files).toContain('/foo/nsconfig.json'); expect(files).toContain('/foo/.gitignore'); expect(files).toContain('/foo/package.json'); diff --git a/src/ng-new/shared/index_spec.ts b/src/ng-new/shared/index_spec.ts index 8c765887..d9d2db7b 100644 --- a/src/ng-new/shared/index_spec.ts +++ b/src/ng-new/shared/index_spec.ts @@ -23,6 +23,7 @@ describe('Shared Application Schematic', () => { const tree = await schematicRunner.runSchematicAsync('shared', options).toPromise(); const files = tree.files; expect(files).toContain('/foo/angular.json'); + expect(files).toContain('/foo/ngcc.config.js'); expect(files).toContain('/foo/nsconfig.json'); expect(files).toContain('/foo/.gitignore'); expect(files).toContain('/foo/package.json'); From 41295cfd43654b3fc7f49dddf0c80228e9c0e383 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Thu, 11 Jun 2020 19:16:36 +0200 Subject: [PATCH 04/11] style: add newline at the end of files --- src/add-ns/_ns-files/ngcc.config.js | 2 +- src/ng-new/application/_files/ngcc.config.js | 2 +- src/ng-new/shared/_files/ngcc.config.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/add-ns/_ns-files/ngcc.config.js b/src/add-ns/_ns-files/ngcc.config.js index 2d241316..895c44b6 100644 --- a/src/add-ns/_ns-files/ngcc.config.js +++ b/src/add-ns/_ns-files/ngcc.config.js @@ -16,4 +16,4 @@ module.exports = { ] } } -}; \ No newline at end of file +}; diff --git a/src/ng-new/application/_files/ngcc.config.js b/src/ng-new/application/_files/ngcc.config.js index 2d241316..895c44b6 100644 --- a/src/ng-new/application/_files/ngcc.config.js +++ b/src/ng-new/application/_files/ngcc.config.js @@ -16,4 +16,4 @@ module.exports = { ] } } -}; \ No newline at end of file +}; diff --git a/src/ng-new/shared/_files/ngcc.config.js b/src/ng-new/shared/_files/ngcc.config.js index 2d241316..895c44b6 100644 --- a/src/ng-new/shared/_files/ngcc.config.js +++ b/src/ng-new/shared/_files/ngcc.config.js @@ -16,4 +16,4 @@ module.exports = { ] } } -}; \ No newline at end of file +}; From 5eecea07690a5fd196a68e5dc4589d1e9cc2d8f5 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Fri, 12 Jun 2020 06:21:23 +0200 Subject: [PATCH 05/11] fix: remove dup module imports --- src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts | 1 - .../master-detail/_files-nsonly/__name__/__master__.module.ts | 1 - .../_files-shared/__name__/__master__.module__nsext__.ts | 1 - .../shared/_sample-files/barcelona/barcelona.module.tns.ts | 1 - 4 files changed, 4 deletions(-) diff --git a/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts b/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts index 573f7a96..850ed36f 100644 --- a/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts +++ b/src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts @@ -10,7 +10,6 @@ import { @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes) ], exports: [ diff --git a/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts b/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts index 2c8d02f8..e6ad93b8 100644 --- a/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts +++ b/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts @@ -13,7 +13,6 @@ export const routes: Routes = [ @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes) ], exports: [ diff --git a/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts b/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts index 1d560610..65563fe3 100644 --- a/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts +++ b/src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts @@ -9,7 +9,6 @@ import { @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes) ], exports: [ diff --git a/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts b/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts index bfb65ab9..1e56c714 100644 --- a/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts +++ b/src/ng-new/shared/_sample-files/barcelona/barcelona.module.tns.ts @@ -10,7 +10,6 @@ import { @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forChild(routes) ], exports: [ From 5522a99bab1df599f491476a5c7b18b12289d368 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Sun, 14 Jun 2020 13:05:33 +0200 Subject: [PATCH 06/11] refactor: rename option "styleext" into "style" to be alinged with the Angular CLI Breaking Change intorduced in 9.0.0. See: https://github.com/angular/angular-cli/releases/tag/v9.0.0 BREAKING CHANGE: use `style` CLI option instead of `styleext` option from now --- src/generate/component/index.ts | 8 ++++---- src/generate/component/index_spec.ts | 10 +++++----- src/generate/component/schema.d.ts | 2 +- src/generate/component/schema.json | 2 +- src/ng-new/shared/_files/angular.json | 2 +- src/refactor-nsng-modules/index.ts | 4 ++-- src/ts-utils.ts | 7 +++++++ 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/generate/component/index.ts b/src/generate/component/index.ts index c854773b..07b0b92a 100644 --- a/src/generate/component/index.ts +++ b/src/generate/component/index.ts @@ -55,10 +55,10 @@ export default function(options: ComponentOptions): Rule { } const projectObject = getProjectObject(tree, options.project); - const styleext = (projectObject && projectObject.schematics && projectObject.schematics['@schematics/angular:component'] + const style = (projectObject && projectObject.schematics && projectObject.schematics['@schematics/angular:component'] && projectObject.schematics['@schematics/angular:component'].style); - if (styleext) { - options.styleext = styleext; + if (style) { + options.style = style; } validateGenerateOptions(platformUse, options); @@ -162,7 +162,7 @@ const parseComponentInfo = (tree: Tree, options: ComponentOptions): ComponentInf const templateName = `/${component.name}.component.html`; component.templatePath = getGeneratedFilePath(templateName); - const stylesheetName = `/${component.name}.component.${options.styleext}`; + const stylesheetName = `/${component.name}.component.${options.style}`; component.stylesheetPath = getGeneratedFilePath(stylesheetName); return component; diff --git a/src/generate/component/index_spec.ts b/src/generate/component/index_spec.ts index 038a624c..ca498781 100644 --- a/src/generate/component/index_spec.ts +++ b/src/generate/component/index_spec.ts @@ -34,8 +34,8 @@ describe('Component Schematic', () => { const nsTemplatePath = getTemplatePath(DEFAULT_SHARED_EXTENSIONS.ns); const webTemplatePath = getTemplatePath(DEFAULT_SHARED_EXTENSIONS.web); - const getStylesheetPath = (extension: string, styleExtension: string = 'css') => - `src/app/${name}/${name}.component${extension}.${styleExtension}`; + const getStylesheetPath = (extension: string, style: string = 'css') => + `src/app/${name}/${name}.component${extension}.${style}`; const noExtensionStylesheetPath = getStylesheetPath(''); const nsStylesheetPath = getStylesheetPath(DEFAULT_SHARED_EXTENSIONS.ns); const webStylesheetPath = getStylesheetPath(DEFAULT_SHARED_EXTENSIONS.web); @@ -217,11 +217,11 @@ describe('Component Schematic', () => { }); it('should respect specified style extension', async () => { - const styleext = 'scss'; - const options = { ...defaultOptions, nsExtension: customExtension, styleext, nativescript: true }; + const style = 'scss'; + const options = { ...defaultOptions, nsExtension: customExtension, style, nativescript: true }; appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); - const componentStylesheetPath = getStylesheetPath(customExtension, styleext); + const componentStylesheetPath = getStylesheetPath(customExtension, style); expect(appTree.exists(componentStylesheetPath)).toBeTruthy(); }); }); diff --git a/src/generate/component/schema.d.ts b/src/generate/component/schema.d.ts index 7b52278e..b04d2d5e 100644 --- a/src/generate/component/schema.d.ts +++ b/src/generate/component/schema.d.ts @@ -60,7 +60,7 @@ export interface Schema { /** * The file extension to be used for style files. */ - styleext?: string; + style?: string; /** * Specifies if a spec file is generated. */ diff --git a/src/generate/component/schema.json b/src/generate/component/schema.json index 041889f8..e0ce21f9 100644 --- a/src/generate/component/schema.json +++ b/src/generate/component/schema.json @@ -84,7 +84,7 @@ } ] }, - "styleext": { + "style": { "description": "The file extension to be used for style files.", "type": "string", "default": "css" diff --git a/src/ng-new/shared/_files/angular.json b/src/ng-new/shared/_files/angular.json index 8b974ee2..d8a872f0 100644 --- a/src/ng-new/shared/_files/angular.json +++ b/src/ng-new/shared/_files/angular.json @@ -13,7 +13,7 @@ "prefix": "<%= prefix %>", "schematics": {<% if(style === 'scss') { %> "@nativescript/schematics:component": { - "styleext": "scss" + "style": "scss" } <% } %>}, "architect": { diff --git a/src/refactor-nsng-modules/index.ts b/src/refactor-nsng-modules/index.ts index 8a68bdb9..3b6b4468 100644 --- a/src/refactor-nsng-modules/index.ts +++ b/src/refactor-nsng-modules/index.ts @@ -57,7 +57,7 @@ export default function(options: Schema) { removeImportedNgModule(tree, path, metadataObject, 'NativeScriptModule'); if (nativeScriptModuleRemoved) { metadataObject = refetchMetadata(tree, path, classNode); - importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', '@nativescript/angular'); + importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', 'nativescript-angular/common'); } metadataObject = refetchMetadata(tree, path, classNode); @@ -78,7 +78,7 @@ export default function(options: Schema) { rootModulePath, rootModuleMetadata, 'NativeScriptAnimationsModule', - '@nativescript/angular', + 'nativescript-angular/animations', ); } }, diff --git a/src/ts-utils.ts b/src/ts-utils.ts index ec429bc5..64ab407e 100644 --- a/src/ts-utils.ts +++ b/src/ts-utils.ts @@ -277,6 +277,13 @@ function normalizeNodeToRemove(node: T, source: ts.Node) const start = nodeStart - source.getFullStart(); const symbolBefore = content.substring(start - 1, start); + console.log('content', content); + console.log('nodeStart', nodeStart); + console.log('nodeEnd', nodeEnd); + console.log('start', start); + console.log('symbolBefore', symbolBefore); + + if (symbolBefore === ',') { return new RemoveContent(nodeStart - 1, nodeEnd); } else { From 3c51c89ab8eb0ba87fd1956fbfd16ecb132b8cd0 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Sun, 14 Jun 2020 13:19:54 +0200 Subject: [PATCH 07/11] fix: cleanup temp changes --- src/refactor-nsng-modules/index.ts | 4 ++-- src/ts-utils.ts | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/refactor-nsng-modules/index.ts b/src/refactor-nsng-modules/index.ts index 3b6b4468..8a68bdb9 100644 --- a/src/refactor-nsng-modules/index.ts +++ b/src/refactor-nsng-modules/index.ts @@ -57,7 +57,7 @@ export default function(options: Schema) { removeImportedNgModule(tree, path, metadataObject, 'NativeScriptModule'); if (nativeScriptModuleRemoved) { metadataObject = refetchMetadata(tree, path, classNode); - importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', 'nativescript-angular/common'); + importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', '@nativescript/angular'); } metadataObject = refetchMetadata(tree, path, classNode); @@ -78,7 +78,7 @@ export default function(options: Schema) { rootModulePath, rootModuleMetadata, 'NativeScriptAnimationsModule', - 'nativescript-angular/animations', + '@nativescript/angular', ); } }, diff --git a/src/ts-utils.ts b/src/ts-utils.ts index 64ab407e..ec429bc5 100644 --- a/src/ts-utils.ts +++ b/src/ts-utils.ts @@ -277,13 +277,6 @@ function normalizeNodeToRemove(node: T, source: ts.Node) const start = nodeStart - source.getFullStart(); const symbolBefore = content.substring(start - 1, start); - console.log('content', content); - console.log('nodeStart', nodeStart); - console.log('nodeEnd', nodeEnd); - console.log('start', start); - console.log('symbolBefore', symbolBefore); - - if (symbolBefore === ',') { return new RemoveContent(nodeStart - 1, nodeEnd); } else { From e2d98b606dc6f4110dab3664b6655c78e8c6c948 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Sun, 14 Jun 2020 13:27:41 +0200 Subject: [PATCH 08/11] test: import from same namespace --- src/refactor-nsng-modules/index_spec.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/refactor-nsng-modules/index_spec.ts b/src/refactor-nsng-modules/index_spec.ts index 367a2a67..0bd5a49e 100644 --- a/src/refactor-nsng-modules/index_spec.ts +++ b/src/refactor-nsng-modules/index_spec.ts @@ -54,8 +54,7 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptModule } from "@nativescript/angular"; - import { NativeScriptFormsModule } from "@nativescript/angular"; + import { NativeScriptModule, NativeScriptFormsModule } from "@nativescript/angular"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; import { loginRouting } from "./login.routing"; @@ -152,9 +151,8 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptModule } from "@nativescript/angular"; + import { NativeScriptModule, NativeScriptAnimationsModule } from "@nativescript/angular"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; - import { NativeScriptAnimationsModule } from "@nativescript/angular"; @NgModule({ imports: [ From 9c7ceb62d3bc83e5f29f5d3ef11ed009fd686104 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Sun, 14 Jun 2020 22:48:38 +0200 Subject: [PATCH 09/11] test: trigger correct new schematics from @nativescript/schematics --- src/add-ns/index_spec.ts | 2 +- src/angular-json/index_spec.ts | 2 +- src/convert-relative-imports/index_spec.ts | 2 +- src/generate-template/master-detail/index_spec.ts | 2 +- src/generate/component/index_spec.ts | 2 +- src/generate/module/index_spec.ts | 2 +- src/generate/utils_spec.ts | 2 +- src/migrate-component/index_spec.ts | 2 +- src/migrate-module/index_spec.ts | 2 +- src/ng-new/application/index_spec.ts | 2 +- src/ng-new/shared/index_spec.ts | 2 +- src/refactor-nsng-modules/index_spec.ts | 2 +- src/styling/index_spec.ts | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/add-ns/index_spec.ts b/src/add-ns/index_spec.ts index 327f9fd8..cb4a6b11 100644 --- a/src/add-ns/index_spec.ts +++ b/src/add-ns/index_spec.ts @@ -8,7 +8,7 @@ import { getFileContent } from '@schematics/angular/utility/test'; describe('Add {N} schematic', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', resolve(__dirname, '../collection.json'), ); const project = 'foo'; diff --git a/src/angular-json/index_spec.ts b/src/angular-json/index_spec.ts index 16a4f4c1..7397edf5 100644 --- a/src/angular-json/index_spec.ts +++ b/src/angular-json/index_spec.ts @@ -5,7 +5,7 @@ import { Schema as angularJsonOptions } from './schema'; describe('Angular JSON Config Schematic', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', path.join(__dirname, '../collection.json'), ); diff --git a/src/convert-relative-imports/index_spec.ts b/src/convert-relative-imports/index_spec.ts index 2483ab72..db740053 100644 --- a/src/convert-relative-imports/index_spec.ts +++ b/src/convert-relative-imports/index_spec.ts @@ -27,7 +27,7 @@ const fixedImportContent = ` describe('Convert relative imports to mapped imports', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../collection.json'), ); diff --git a/src/generate-template/master-detail/index_spec.ts b/src/generate-template/master-detail/index_spec.ts index 200d826a..f5eba421 100644 --- a/src/generate-template/master-detail/index_spec.ts +++ b/src/generate-template/master-detail/index_spec.ts @@ -24,7 +24,7 @@ describe('Master-detail schematic', () => { }; const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../../collection.json'), ); diff --git a/src/generate/component/index_spec.ts b/src/generate/component/index_spec.ts index ca498781..b3a33501 100644 --- a/src/generate/component/index_spec.ts +++ b/src/generate/component/index_spec.ts @@ -21,7 +21,7 @@ describe('Component Schematic', () => { const defaultOptions: ComponentOptions = { name, project }; const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../../collection.json'), ); diff --git a/src/generate/module/index_spec.ts b/src/generate/module/index_spec.ts index 9ab5175a..9bc85e77 100644 --- a/src/generate/module/index_spec.ts +++ b/src/generate/module/index_spec.ts @@ -21,7 +21,7 @@ describe('Module Schematic', () => { name, }; const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../../collection.json'), ); const getModulePath = (extension: string) => `/src/app/${name}/${name}.module${extension}.ts`; diff --git a/src/generate/utils_spec.ts b/src/generate/utils_spec.ts index 8806ca10..5ade1cd3 100644 --- a/src/generate/utils_spec.ts +++ b/src/generate/utils_spec.ts @@ -14,7 +14,7 @@ describe('Validation should trigger', () => { const defaultModuleOptions: ModuleOptions = { name: 'fooModule', project }; const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../collection.json'), ); diff --git a/src/migrate-component/index_spec.ts b/src/migrate-component/index_spec.ts index 514ce42d..acc2739e 100644 --- a/src/migrate-component/index_spec.ts +++ b/src/migrate-component/index_spec.ts @@ -16,7 +16,7 @@ describe('Migrate component schematic', () => { const componentClassName = 'AComponent'; const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../collection.json'), ); diff --git a/src/migrate-module/index_spec.ts b/src/migrate-module/index_spec.ts index 57aafa2b..57a218f7 100644 --- a/src/migrate-module/index_spec.ts +++ b/src/migrate-module/index_spec.ts @@ -22,7 +22,7 @@ describe('Migrate module Schematic', () => { const nsModulePath = '/src/app/admin/admin.module.tns.ts'; const webModulePath = '/src/app/admin/admin.module.ts'; const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', join(__dirname, '../collection.json'), ); diff --git a/src/ng-new/application/index_spec.ts b/src/ng-new/application/index_spec.ts index 95e1c6e8..01e7d0b2 100644 --- a/src/ng-new/application/index_spec.ts +++ b/src/ng-new/application/index_spec.ts @@ -7,7 +7,7 @@ import { isInModuleMetadata } from '../../test-utils'; describe('Application Schematic', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', path.join(__dirname, '../../collection.json'), ); const defaultOptions: ApplicationOptions = { diff --git a/src/ng-new/shared/index_spec.ts b/src/ng-new/shared/index_spec.ts index d9d2db7b..013f0819 100644 --- a/src/ng-new/shared/index_spec.ts +++ b/src/ng-new/shared/index_spec.ts @@ -5,7 +5,7 @@ import { Schema as SharedOptions } from './schema'; describe('Shared Application Schematic', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', path.join(__dirname, '../../collection.json'), ); const defaultOptions: SharedOptions = { diff --git a/src/refactor-nsng-modules/index_spec.ts b/src/refactor-nsng-modules/index_spec.ts index 0bd5a49e..fcf378fe 100644 --- a/src/refactor-nsng-modules/index_spec.ts +++ b/src/refactor-nsng-modules/index_spec.ts @@ -7,7 +7,7 @@ import { Schema } from './schema'; describe('Refactor NsNg Modules Schematic', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', path.join(__dirname, '../collection.json'), ); diff --git a/src/styling/index_spec.ts b/src/styling/index_spec.ts index 446dc266..69f03595 100644 --- a/src/styling/index_spec.ts +++ b/src/styling/index_spec.ts @@ -8,7 +8,7 @@ import { Schema as StylingOptions } from './schema'; describe('Styling Schematic', () => { const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', + '@nativescript/schematics', path.join(__dirname, '../collection.json'), ); From d50594aac7a710f6bdcdbe0356f69c1876d17cdb Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Mon, 15 Jun 2020 20:14:44 +0200 Subject: [PATCH 10/11] fix: revert schedmatic migration script changes --- src/refactor-nsng-modules/index.ts | 4 ++-- src/refactor-nsng-modules/index_spec.ts | 26 +++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/refactor-nsng-modules/index.ts b/src/refactor-nsng-modules/index.ts index 8a68bdb9..3b6b4468 100644 --- a/src/refactor-nsng-modules/index.ts +++ b/src/refactor-nsng-modules/index.ts @@ -57,7 +57,7 @@ export default function(options: Schema) { removeImportedNgModule(tree, path, metadataObject, 'NativeScriptModule'); if (nativeScriptModuleRemoved) { metadataObject = refetchMetadata(tree, path, classNode); - importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', '@nativescript/angular'); + importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', 'nativescript-angular/common'); } metadataObject = refetchMetadata(tree, path, classNode); @@ -78,7 +78,7 @@ export default function(options: Schema) { rootModulePath, rootModuleMetadata, 'NativeScriptAnimationsModule', - '@nativescript/angular', + 'nativescript-angular/animations', ); } }, diff --git a/src/refactor-nsng-modules/index_spec.ts b/src/refactor-nsng-modules/index_spec.ts index fcf378fe..18009320 100644 --- a/src/refactor-nsng-modules/index_spec.ts +++ b/src/refactor-nsng-modules/index_spec.ts @@ -7,7 +7,7 @@ import { Schema } from './schema'; describe('Refactor NsNg Modules Schematic', () => { const schematicRunner = new SchematicTestRunner( - '@nativescript/schematics', + 'nativescript-schematics', path.join(__dirname, '../collection.json'), ); @@ -54,7 +54,8 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptModule, NativeScriptFormsModule } from "@nativescript/angular"; + import { NativeScriptModule } from "nativescript-angular/nativescript.module"; + import { NativeScriptFormsModule } from "nativescript-angular/forms"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; import { loginRouting } from "./login.routing"; @@ -83,7 +84,7 @@ describe('Refactor NsNg Modules Schematic', () => { it('should remove the NativeScriptModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptModule } from "@nativescript/angular";', + .not.toMatch('import { NativeScriptModule } from "nativescript-angular/nativescript.module";', ); }); @@ -109,7 +110,7 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptAnimationsModule } from "@nativescript/angular"; + import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; @NgModule({ @@ -128,7 +129,7 @@ describe('Refactor NsNg Modules Schematic', () => { it('should remove the NativeScriptAnimationsModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptAnimationsModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', + .not.toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', ); }); @@ -136,7 +137,7 @@ describe('Refactor NsNg Modules Schematic', () => { const newRootModuleContent = getFileContent(tree, rootModulePath); expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', + .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', ); }); }); @@ -151,8 +152,9 @@ describe('Refactor NsNg Modules Schematic', () => { beforeEach(() => { const appTree = initAppTree(); appTree.create(featureModulePath, ` - import { NativeScriptModule, NativeScriptAnimationsModule } from "@nativescript/angular"; + import { NativeScriptModule } from "nativescript-angular/nativescript.module"; import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; + import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; @NgModule({ imports: [ @@ -171,7 +173,7 @@ describe('Refactor NsNg Modules Schematic', () => { it('should remove the NativeScriptAnimationsModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptAnimationsModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', + .not.toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', ); }); @@ -179,7 +181,7 @@ describe('Refactor NsNg Modules Schematic', () => { const newRootModuleContent = getFileContent(tree, rootModulePath); expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', + .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', ); }); @@ -187,19 +189,19 @@ describe('Refactor NsNg Modules Schematic', () => { const newRootModuleContent = getFileContent(tree, rootModulePath); expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "@nativescript/angular";', + .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', ); }); it('should remove the NativeScriptModule import', () => { expect(featureModuleContent).not.toMatch(`NativeScriptModule`); expect(featureModuleContent) - .not.toMatch('import { NativeScriptModule } from "@nativescript/angular";', + .not.toMatch('import { NativeScriptModule } from "nativescript-angular/nativescript.module";', ); }); it('should import the NativeScriptCommonModule to the feature module', () => { - expect(featureModuleContent).toMatch('import { NativeScriptCommonModule } from "@nativescript/angular"'); + expect(featureModuleContent).toMatch('import { NativeScriptCommonModule } from "nativescript-angular/common"'); }); it('should add the NativeScriptCommonModule to the module metadata', () => { From e34baad8a6f9361b3ed6d5a7544bb7bc4ec4fffb Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 15 Jun 2020 22:12:38 -0700 Subject: [PATCH 11/11] chore: cleanup --- package.json | 4 +- src/collection.json | 6 - src/refactor-nsng-modules/index.ts | 184 -------------------- src/refactor-nsng-modules/index_spec.ts | 212 ------------------------ src/refactor-nsng-modules/schema.d.ts | 6 - src/refactor-nsng-modules/schema.json | 14 -- 6 files changed, 2 insertions(+), 424 deletions(-) delete mode 100644 src/refactor-nsng-modules/index.ts delete mode 100644 src/refactor-nsng-modules/index_spec.ts delete mode 100644 src/refactor-nsng-modules/schema.d.ts delete mode 100644 src/refactor-nsng-modules/schema.json diff --git a/package.json b/package.json index 9b19ffce..63a6611c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/schematics", - "version": "2.0.0", + "version": "9.0.0", "description": "Schematics for NativeScript Angular apps.", "scripts": { "build": "tsc -p tsconfig.json", @@ -20,7 +20,7 @@ "@angular-devkit/core": "~9.1.0", "@angular-devkit/schematics": "~9.1.0", "@nativescript/tslint-rules": "~0.0.5", - "@phenomnomnominal/tsquery": "^3.0.0" + "@phenomnomnominal/tsquery": "^4.1.0" }, "devDependencies": { "@schematics/angular": "~9.1.0", diff --git a/src/collection.json b/src/collection.json index c53835ea..9b0e15b5 100644 --- a/src/collection.json +++ b/src/collection.json @@ -68,12 +68,6 @@ "schema": "./add-ns/schema.json" }, - "refactor-nsng-modules": { - "factory": "./refactor-nsng-modules", - "description": "Upgrades existing {N} Angular projects.", - "schema": "./refactor-nsng-modules/schema.json" - }, - "class": { "aliases": [ "cl" ], "extends": "@schematics/angular:class" diff --git a/src/refactor-nsng-modules/index.ts b/src/refactor-nsng-modules/index.ts deleted file mode 100644 index 3b6b4468..00000000 --- a/src/refactor-nsng-modules/index.ts +++ /dev/null @@ -1,184 +0,0 @@ -import { join } from 'path'; - -import { - chain, - Tree, -} from '@angular-devkit/schematics'; -import { insertImport } from '../route-utils'; - -import { Schema } from './schema'; -import { getJsonFile, removeNode } from '../utils'; -import { - collectDeepNodes, - filterByChildNode, - findImports, - getDecoratedClasses, - getDecoratorMetadataFromClass, - getNodesToRemoveFromNestedArray, - getSymbolsToAddToObject, - removeImport, - getDecoratedClass, - getSourceFile, -} from '../ts-utils'; - -import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript'; -import { SchematicsException } from '@angular-devkit/schematics/src/exception/exception'; -import { InsertChange } from '@schematics/angular/utility/change'; - -export default function(options: Schema) { - const { sourceDir } = options; - - return chain([ - (tree: Tree) => { - const entry = getEntryModule(tree, sourceDir); - const { rootModule, rootModulePath } = getBootstrappedModule(tree, entry, sourceDir); - - let animationModuleIsUsed = false; - tree.visit((path) => { - if ( - path.startsWith('/node_modules') || - path.startsWith('/platforms') || - !path.endsWith('.ts') || - path === `/${rootModulePath}` - ) { - return; - } - - const ngModules = getDecoratedClasses(tree, path, 'NgModule'); - const metadataObjects = ngModules - .map((m) => ({ - metadataObject: getDecoratorMetadataFromClass(m, 'NgModule') as ts.ObjectLiteralExpression, - classNode: m, - })) - .filter(({ metadataObject }) => !!metadataObject); - - metadataObjects.forEach(({ metadataObject, classNode }) => { - const nativeScriptModuleRemoved = - removeImportedNgModule(tree, path, metadataObject, 'NativeScriptModule'); - if (nativeScriptModuleRemoved) { - metadataObject = refetchMetadata(tree, path, classNode); - importNgModule(tree, path, metadataObject, 'NativeScriptCommonModule', 'nativescript-angular/common'); - } - - metadataObject = refetchMetadata(tree, path, classNode); - const animationsModuleRemoved = - removeImportedNgModule(tree, path, metadataObject, 'NativeScriptAnimationsModule'); - animationModuleIsUsed = animationModuleIsUsed || animationsModuleRemoved; - }); - - return true; - }); - - if (animationModuleIsUsed) { - const rootModuleMetadata = - getDecoratorMetadataFromClass(rootModule !, 'NgModule') as ts.ObjectLiteralExpression; - - importNgModule( - tree, - rootModulePath, - rootModuleMetadata, - 'NativeScriptAnimationsModule', - 'nativescript-angular/animations', - ); - } - }, - ]); -} - -const getEntryModule = (tree: Tree, sourceDir: string) => { - const innerPackageJson = getJsonFile(tree, `${sourceDir}/package.json`); - const entry = innerPackageJson.main; - const tsEntry = entry.replace(/\.js$/i, '.ts'); - - return `${sourceDir}/${tsEntry}`; -}; - -const getBootstrappedModule = (tree: Tree, path: string, sourceDir: string) => { - const entrySource = getSourceFile(tree, path); - const bootstrappedModules = collectDeepNodes(entrySource, ts.SyntaxKind.CallExpression) - .filter((node) => filterByChildNode(node, (child: ts.Node) => - child.kind === ts.SyntaxKind.PropertyAccessExpression && - ['bootstrapModule', 'bootstrapModuleNgFactory'].includes( - (child).name.getFullText(), - ), - ), - ) - .map((node: ts.CallExpression) => node.arguments[0]); - - if (bootstrappedModules.length !== 1) { - throw new SchematicsException(`You should have exactly one bootstrapped module inside ${path}!`); - } - - const moduleName = bootstrappedModules[0].getText(); - const imports = findImports(moduleName, entrySource); - const lastImport = imports[imports.length - 1]; - const moduleSpecifier = lastImport.moduleSpecifier.getText(); - const moduleRelativePath = `${moduleSpecifier.replace(/"|'/g, '')}.ts`; - - const rootModulePath = join(sourceDir, moduleRelativePath); - const rootModule = getDecoratedClasses(tree, rootModulePath, 'NgModule') - .find((c) => !!(c.name && c.name.getText() === moduleName)); - - return { rootModule, rootModulePath }; -}; - -const refetchMetadata = (tree: Tree, path: string, classNode: ts.ClassDeclaration) => { - const newClassNode = getDecoratedClass(tree, path, 'NgModule', classNode.name!.getText())!; - const newMetadataObject = getDecoratorMetadataFromClass(newClassNode, 'NgModule') as ts.ObjectLiteralExpression; - - return newMetadataObject; -}; - -const importNgModule = ( - tree: Tree, - path: string, - metadataObject: ts.ObjectLiteralExpression, - name: string, - importPath: string, -) => { - const nodesToAdd = getSymbolsToAddToObject(path, metadataObject, 'imports', name); - const recorder = tree.beginUpdate(path); - nodesToAdd.forEach((change) => { - recorder.insertRight(change.pos, change.toAdd); - }); - tree.commitUpdate(recorder); - - const source = getSourceFile(tree, path); - const newImport = insertImport(source, path, name, importPath) as InsertChange; - const importRecorder = tree.beginUpdate(path); - if (newImport.toAdd) { - importRecorder.insertLeft(newImport.pos, newImport.toAdd); - } - tree.commitUpdate(importRecorder); -}; - -const removeImportedNgModule = ( - tree: Tree, - path: string, - metadataObject: ts.ObjectLiteralExpression, - name: string, -) => { - const removed = removeNgModuleFromMetadata(tree, path, metadataObject, name); - if (removed) { - removeImport(tree, path, name); - } - - return removed; -}; - -const removeNgModuleFromMetadata = ( - tree: Tree, - path: string, - metadataObject: ts.ObjectLiteralExpression, - name: string, -): boolean => { - const metadataImports = getNodesToRemoveFromNestedArray([metadataObject], 'imports', name); - const isInMetadata = !!metadataImports.length; - if (isInMetadata) { - metadataImports.forEach((declaration) => { - removeNode(declaration, path, tree); - }); - } - - return isInMetadata; -}; diff --git a/src/refactor-nsng-modules/index_spec.ts b/src/refactor-nsng-modules/index_spec.ts deleted file mode 100644 index 18009320..00000000 --- a/src/refactor-nsng-modules/index_spec.ts +++ /dev/null @@ -1,212 +0,0 @@ -import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; -import { getFileContent } from '@schematics/angular/utility/test'; -import * as path from 'path'; - -import { isInModuleMetadata, createEmptyNsOnlyProject, VirtualFile } from '../test-utils'; -import { Schema } from './schema'; - -describe('Refactor NsNg Modules Schematic', () => { - const schematicRunner = new SchematicTestRunner( - 'nativescript-schematics', - path.join(__dirname, '../collection.json'), - ); - - const sourceDir = 'src'; - const defaultOptions: Schema = { sourceDir }; - - const rootModulePath = `${sourceDir}/app/app.module.ts`; - const getRootModuleContent = (tree: UnitTestTree) => { - const buffer = tree.read(rootModulePath) || ''; - - return buffer.toString(); - }; - - const initAppTree = () => { - const appTree = createEmptyNsOnlyProject('project'); - - return appTree; - }; - - describe('when no changes are required', () => { - let appTree; - let rootModuleContent; - beforeEach(() => { - appTree = initAppTree(); - rootModuleContent = getRootModuleContent(appTree); - }); - - it('should not change the tree', async () => { - const tree = await schematicRunner.runSchematicAsync('refactor-nsng-modules', defaultOptions, appTree) - .toPromise(); - expect(tree.exists(rootModulePath)).toEqual(true); - expect(getFileContent(tree, rootModulePath)).toEqual(rootModuleContent); - }); - }); - - describe('when a feature module has NativeScriptModule imported', () => { - const featureModuleName = `LoginModule`; - const featureModulePath = `${sourceDir}/feature.module.ts`; - - let tree; - let featureModuleContent; - let rootModuleContent; - - beforeEach(() => { - const appTree = initAppTree(); - appTree.create(featureModulePath, ` - import { NativeScriptModule } from "nativescript-angular/nativescript.module"; - import { NativeScriptFormsModule } from "nativescript-angular/forms"; - import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; - - import { loginRouting } from "./login.routing"; - import { LoginComponent } from "./login.component"; - - - @NgModule({ - imports: [ - NativeScriptFormsModule, - NativeScriptModule, - loginRouting - ], - declarations: [ - LoginComponent - ], - schemas: [NO_ERRORS_SCHEMA] - }) - export class ${featureModuleName} { } - `); - - rootModuleContent = getRootModuleContent(appTree); - tree = schematicRunner.runSchematic('refactor-nsng-modules', defaultOptions, appTree); - featureModuleContent = getFileContent(tree, featureModulePath); - }); - - it('should remove the NativeScriptModule import', () => { - expect(featureModuleContent).not.toMatch(`NativeScriptModule`); - expect(featureModuleContent) - .not.toMatch('import { NativeScriptModule } from "nativescript-angular/nativescript.module";', - ); - }); - - it('should add the NativeScriptCommonModule to the module metadata', () => { - expect(featureModuleContent) - .toMatch( - isInModuleMetadata(featureModuleName, 'imports', 'NativeScriptCommonModule', true), - ); - }); - - it('should not change the root module', () => { - expect(getFileContent(tree, rootModulePath)).toEqual(rootModuleContent); - }); - }); - - describe('when a feature module has NativeScriptAnimationsModule imported', () => { - const featureModuleName = `SomeModule`; - const featureModulePath = `${sourceDir}/nested/dir/some.module.ts`; - - let tree; - let featureModuleContent; - - beforeEach(() => { - const appTree = initAppTree(); - appTree.create(featureModulePath, ` - import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; - import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; - - @NgModule({ - imports: [ - NativeScriptAnimationsModule, - ], - schemas: [NO_ERRORS_SCHEMA] - }) - export class ${featureModuleName} { } - `); - - tree = schematicRunner.runSchematic('refactor-nsng-modules', defaultOptions, appTree); - featureModuleContent = getFileContent(tree, featureModulePath); - }); - - it('should remove the NativeScriptAnimationsModule import', () => { - expect(featureModuleContent).not.toMatch(`NativeScriptAnimationsModule`); - expect(featureModuleContent) - .not.toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', - ); - }); - - it('should add the animations module to the root module', () => { - const newRootModuleContent = getFileContent(tree, rootModulePath); - expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); - expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', - ); - }); - }); - - describe('when a feature module has both NativeScriptModule and NativeScriptAnimationsModule imported', () => { - const featureModuleName = `FeatureModule`; - const featureModulePath = `${sourceDir}/dir/feature-1.module.ts`; - - let tree; - let featureModuleContent; - - beforeEach(() => { - const appTree = initAppTree(); - appTree.create(featureModulePath, ` - import { NativeScriptModule } from "nativescript-angular/nativescript.module"; - import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; - import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; - - @NgModule({ - imports: [ - NativeScriptModule, - NativeScriptAnimationsModule, - ], - schemas: [NO_ERRORS_SCHEMA] - }) - export class ${featureModuleName} { } - `); - - tree = schematicRunner.runSchematic('refactor-nsng-modules', defaultOptions, appTree); - featureModuleContent = getFileContent(tree, featureModulePath); - }); - - it('should remove the NativeScriptAnimationsModule import', () => { - expect(featureModuleContent).not.toMatch(`NativeScriptAnimationsModule`); - expect(featureModuleContent) - .not.toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', - ); - }); - - it('should add the animations module to the root module', () => { - const newRootModuleContent = getFileContent(tree, rootModulePath); - expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); - expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', - ); - }); - - it('should add the animations module to the root module', () => { - const newRootModuleContent = getFileContent(tree, rootModulePath); - expect(newRootModuleContent).toMatch(`NativeScriptAnimationsModule`); - expect(newRootModuleContent) - .toMatch('import { NativeScriptAnimationsModule } from "nativescript-angular/animations";', - ); - }); - - it('should remove the NativeScriptModule import', () => { - expect(featureModuleContent).not.toMatch(`NativeScriptModule`); - expect(featureModuleContent) - .not.toMatch('import { NativeScriptModule } from "nativescript-angular/nativescript.module";', - ); - }); - - it('should import the NativeScriptCommonModule to the feature module', () => { - expect(featureModuleContent).toMatch('import { NativeScriptCommonModule } from "nativescript-angular/common"'); - }); - - it('should add the NativeScriptCommonModule to the module metadata', () => { - expect(featureModuleContent).toMatch('NativeScriptCommonModule'); - }); - - }); -}); diff --git a/src/refactor-nsng-modules/schema.d.ts b/src/refactor-nsng-modules/schema.d.ts deleted file mode 100644 index d17df766..00000000 --- a/src/refactor-nsng-modules/schema.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Schema { - /** - * The path of the source directory. - */ - sourceDir: string; -} diff --git a/src/refactor-nsng-modules/schema.json b/src/refactor-nsng-modules/schema.json deleted file mode 100644 index a49cd94c..00000000 --- a/src/refactor-nsng-modules/schema.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "id": "SchematicsRefactorNsNgModules", - "title": "Refactor NativeScript Angular Modules Options Schema", - "type": "object", - "properties": { - "sourceDir": { - "type": "string", - "description": "The path of the source directory.", - "default": "app" - } - } -} -