Skip to content

Commit f4a098a

Browse files
authored
refactor: update to NativeScript 6.0 (#220)
* refactor: bump template versions to {N} 6.0 * refactor: set `markingMode` to `none` * refactor: remove `moduleId` from component metadata {N} 6.0 uses only webpack for building. When building Angular apps with Webpack,the `module.id` is inserted automatically and we don't need to set it manually. There's even a loader in `nativescript-dev-webpack` which removes the moduleIds from the source code. In short, the `moduleId: module.id` is useful only for builds without webpack. NativeScript 6.0 doesn't support such builds. That's why we don't need moduleId in the templates anymore.
1 parent 6cb54d3 commit f4a098a

File tree

12 files changed

+23
-94
lines changed

12 files changed

+23
-94
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2+
"main": "<%= main %><%= nsext %>.js",
23
"android": {
3-
"v8Flags": "--expose_gc"
4-
},
5-
"main": "<%= main %><%= nsext %>.js"
4+
"v8Flags": "--expose_gc",
5+
"markingMode": "none"
6+
}
67
}

src/generate-template/master-detail/_files-nsonly/__name__/__detail__-detail/__detail__-detail.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { DataService, Number } from '../data.service';
55

66
@Component({
77
selector: '<%= prefix %>-details',
8-
moduleId: module.id,
98
templateUrl: './<%= detail %>-detail.component.html',
109
})
1110
export class <%= detailClassName %>DetailComponent implements OnInit {

src/generate-template/master-detail/_files-nsonly/__name__/__master__/__master__.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { DataService, Number } from '../data.service';
44

55
@Component({
66
selector: '<%= prefix %>-<%= master %>',
7-
moduleId: module.id,
87
templateUrl: './<%= master %>.component.html',
98
})
109
export class <%= masterClassName %>Component implements OnInit {

src/generate/component/ast-utils.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,9 @@ import * as ts from 'typescript';
33
import { SchematicsException, Tree } from '@angular-devkit/schematics';
44
import { classify } from '@angular-devkit/core/src/utils/strings';
55
import { buildRelativePath } from '@schematics/angular/utility/find-module';
6-
import { InsertChange, Change } from '@schematics/angular/utility/change';
6+
import { InsertChange } from '@schematics/angular/utility/change';
77
import { addEntryComponentToModule, addExportToModule, addDeclarationToModule } from '@schematics/angular/utility/ast-utils';
88
import { Schema as ComponentOptions } from './schema';
9-
import { addSymbolToDecoratorMetadata, getSourceFile } from '../../ts-utils';
10-
11-
export const insertModuleId = (tree: Tree, component: string) => {
12-
const componentSource = getSourceFile(tree, component);
13-
const recorder = tree.beginUpdate(component);
14-
15-
const metadataChange = addSymbolToComponentMetadata(
16-
componentSource, component, 'moduleId', 'module.id');
17-
18-
metadataChange.forEach((change: InsertChange) =>
19-
recorder.insertRight(change.pos, change.toAdd)
20-
);
21-
tree.commitUpdate(recorder);
22-
};
23-
24-
function addSymbolToComponentMetadata(
25-
source: ts.SourceFile,
26-
componentPath: string,
27-
metadataField: string,
28-
symbolName: string,
29-
): Change[] {
30-
return addSymbolToDecoratorMetadata(
31-
source,
32-
componentPath,
33-
metadataField,
34-
symbolName,
35-
'Component',
36-
'@angular/core'
37-
);
38-
}
399

4010
export function addDeclarationToNgModule(tree: Tree, options: ComponentOptions, componentPath: string, modulePath: string) {
4111
const source = readIntoSourceFile(tree, modulePath);

src/generate/component/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Path, TemplateOptions } from '@angular-devkit/core';
2020
import { parseName } from '@schematics/angular/utility/parse-name';
2121

2222
import { Extensions, getExtensions, removeNsSchemaOptions, PlatformUse, getPlatformUse, validateGenerateOptions } from '../utils';
23-
import { addDeclarationToNgModule, insertModuleId } from './ast-utils';
23+
import { addDeclarationToNgModule } from './ast-utils';
2424
import { Schema as ComponentOptions } from './schema';
2525
import { findModule } from './find-module';
2626

@@ -85,12 +85,6 @@ export default function (options: ComponentOptions): Rule {
8585
return tree;
8686
},
8787

88-
(tree: Tree) => {
89-
if (platformUse.nsOnly) {
90-
insertModuleId(tree, componentInfo.classPath);
91-
}
92-
},
93-
9488
(tree: Tree, context: SchematicContext) => {
9589
if (platformUse.useWeb) {
9690
return addWebExtension(tree, componentInfo.templatePath);

src/generate/component/index_spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ describe('Component Schematic', () => {
4040

4141
let appTree: UnitTestTree;
4242

43-
const hasModuleId = () => {
44-
const content = getFileContent(appTree, componentPath);
45-
const matcher = isInComponentMetadata(componentClassName, 'moduleId', 'module.id', false);
46-
return content.match(matcher);
47-
};
48-
4943
const ensureWebTemplate = (tree: UnitTestTree, path: string) => {
5044
expect(tree.exists(path)).toBeTruthy();
5145

@@ -79,8 +73,6 @@ describe('Component Schematic', () => {
7973
it('should not create stylesheet with {N} extension', () =>
8074
expect(appTree.exists(nsStylesheetPath)).toBeFalsy());
8175

82-
it('should add module id', () => expect(hasModuleId()).toBeTruthy());
83-
8476
it('should declare the component in the root NgModule for {N}', () => {
8577
const nsModuleContent = getFileContent(appTree, rootModulePath);
8678
expect(nsModuleContent).toMatch(isInModuleMetadata('AppModule', 'declarations', componentClassName, true));
@@ -129,8 +121,6 @@ describe('Component Schematic', () => {
129121
it('should add {N}-specific stylesheet file', () =>
130122
expect(appTree.exists(nsStylesheetPath)).toBeTruthy());
131123

132-
it('should add module id', () => expect(hasModuleId()).toBeFalsy());
133-
134124
it('should declare the component in the the root NgModule for web', () => {
135125
const webModuleContent = getFileContent(appTree, rootModulePath);
136126
expect(webModuleContent).toMatch(isInModuleMetadata('AppModule', 'declarations', componentClassName, true));
@@ -169,7 +159,6 @@ describe('Component Schematic', () => {
169159
it('should add {N}-specific markup file', () => ensureNsTemplate(appTree, nsTemplatePath));
170160
it('should add {N}-specific stylesheet file', () =>
171161
expect(appTree.exists(nsStylesheetPath)).toBeTruthy());
172-
it('should add module id', () => expect(hasModuleId()).toBeFalsy());
173162

174163
it('should not declare the component in the the root NgModule for web', () => {
175164
const webModuleContent = getFileContent(appTree, rootModulePath);
@@ -191,7 +180,6 @@ describe('Component Schematic', () => {
191180
});
192181

193182
it('should add web-specific markup file', () => ensureWebTemplate(appTree, webTemplatePath));
194-
it('should add module id', () => expect(hasModuleId()).toBeFalsy());
195183

196184
it('should declare the component in the the root NgModule for web', () => {
197185
const webModuleContent = getFileContent(appTree, rootModulePath);

src/ng-new/application/_files/__sourcedir__/home/home.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { Component } from '@angular/core';
33
@Component({
44
selector: '<%= prefix %>-home',
55
templateUrl: './home.component.html',
6-
styleUrls: ['./home.component.<%= style %>'],
7-
moduleId: module.id,
6+
styleUrls: ['./home.component.<%= style %>']
87
})
98
export class HomeComponent {
109
title = '<%= name %>';
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2+
"main": "main.js",
23
"android": {
3-
"v8Flags": "--expose_gc"
4-
},
5-
"main": "main.js"
4+
"v8Flags": "--expose_gc",
5+
"markingMode": "none"
6+
}
67
}

src/ng-new/application/_files/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
"nativescript-angular": "~8.0.1",<% if(theme) { %>
1919
"nativescript-theme-core": "~1.0.4",
2020
<% } %>"reflect-metadata": "~0.1.12",
21-
"rxjs": "~6.4.0",
22-
"tns-core-modules": "~5.4.0",
21+
"rxjs": "~6.5.0",
22+
"tns-core-modules": "~6.0.0",
2323
"zone.js": "~0.9.1"
2424
},
2525
"devDependencies": {
2626
"@angular/cli": "^8.0.3",
2727
"@angular/compiler-cli": "~8.0.1",
2828
"@angular-devkit/core": "~8.0.1",
29-
"@nativescript/schematics": "~0.6.0",<% if(webpack) { %>
30-
"nativescript-dev-webpack": "~0.24.0",
29+
"@nativescript/schematics": "~0.7.0",<% if(webpack) { %>
30+
"nativescript-dev-webpack": "~1.0.0",
3131
"@ngtools/webpack": "~8.0.3",
3232
<% } %>"typescript": "~3.4.3"
3333
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"android": {
3-
"v8Flags": "--expose_gc"
4-
},
52
"main": "main.tns.js",
6-
"name": "migration-ng",
7-
"version": "4.1.0"
3+
"android": {
4+
"v8Flags": "--expose_gc",
5+
"markingMode": "none"
6+
}
87
}

0 commit comments

Comments
 (0)