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..63a6611c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/schematics", - "version": "1.0.0", + "version": "9.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", - "@phenomnomnominal/tsquery": "^3.0.0" + "@angular-devkit/core": "~9.1.0", + "@angular-devkit/schematics": "~9.1.0", + "@nativescript/tslint-rules": "~0.0.5", + "@phenomnomnominal/tsquery": "^4.1.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/ngcc.config.js b/src/add-ns/_ns-files/ngcc.config.js new file mode 100644 index 00000000..895c44b6 --- /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\//, + ] + } + } +}; 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..850ed36f 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, @@ -11,7 +10,6 @@ import { @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes) ], exports: [ 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..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'; @@ -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'); @@ -77,9 +78,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 +95,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/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/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/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/_files-nsonly/__name__/__master__.module.ts b/src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts index e540dace..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 @@ -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'; @@ -14,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 1d479476..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 @@ -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, @@ -10,7 +9,6 @@ import { @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes) ], exports: [ 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.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..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'), ); @@ -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/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..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`; @@ -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/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/_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/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/_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/ngcc.config.js b/src/ng-new/application/_files/ngcc.config.js new file mode 100644 index 00000000..895c44b6 --- /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\//, + ] + } + } +}; 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..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 = { @@ -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'); @@ -50,7 +51,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 +95,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/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/ng-new/shared/_files/ngcc.config.js b/src/ng-new/shared/_files/ngcc.config.js new file mode 100644 index 00000000..895c44b6 --- /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\//, + ] + } + } +}; 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..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 @@ -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, @@ -11,7 +10,6 @@ import { @NgModule({ imports: [ NativeScriptCommonModule, - NativeScriptRouterModule, NativeScriptRouterModule.forChild(routes) ], exports: [ diff --git a/src/ng-new/shared/index_spec.ts b/src/ng-new/shared/index_spec.ts index 8c765887..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 = { @@ -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'); 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" - } - } -} - 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'), ); 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,