Skip to content

Commit 8d913e7

Browse files
authored
chore: Angular 10.1 and NativeScript 7 (#296)
1 parent 605b24a commit 8d913e7

File tree

32 files changed

+196
-184
lines changed

32 files changed

+196
-184
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/schematics",
3-
"version": "10.0.2",
3+
"version": "10.1.0",
44
"description": "Schematics for NativeScript Angular apps.",
55
"scripts": {
66
"clean": "npx rimraf node_modules package-lock.json && npm i",
@@ -25,15 +25,15 @@
2525
},
2626
"schematics": "./src/collection.json",
2727
"dependencies": {
28-
"@angular-devkit/core": "~10.0.0",
29-
"@angular-devkit/schematics": "~10.0.0",
28+
"@angular-devkit/core": "~10.1.0",
29+
"@angular-devkit/schematics": "~10.1.0",
3030
"@nativescript/tslint-rules": "~0.0.5",
3131
"@phenomnomnominal/tsquery": "^4.1.0",
3232
"strip-json-comments": "~3.1.1"
3333
},
3434
"devDependencies": {
35-
"@angular/cli": "~10.0.0",
36-
"@schematics/angular": "~10.0.0",
35+
"@angular/cli": "~10.1.0",
36+
"@schematics/angular": "~10.1.0",
3737
"@types/jasmine": "~3.5.0",
3838
"@types/jasminewd2": "~2.0.3",
3939
"@types/node": "^12.11.1",

src/add-ns/_ns-files/__sourceDir__/package.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NativeScriptConfig } from '@nativescript/core';
2+
3+
export default {
4+
id: 'org.nativescript.ngsample',
5+
appResourcesPath: 'App_Resources',
6+
android: {
7+
v8Flags: '--expose_gc',
8+
markingMode: 'none',
9+
},
10+
appPath: '<%= sourceDir %>'
11+
} as NativeScriptConfig;

src/add-ns/_ns-files/nsconfig.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/add-ns/index.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function(options: MigrationOptions): Rule {
4949
addAppResources(),
5050
mergeGitIgnore,
5151
addRunScriptsToPackageJson,
52-
addNativeScriptProjectId,
52+
// addNativeScriptProjectId,
5353

5454
modifyWebTsconfig,
5555
modifyTsLintConfig,
@@ -223,12 +223,12 @@ const addRunScriptsToPackageJson = (tree: Tree, context: SchematicContext) => {
223223
const packageJson = getPackageJson(tree);
224224

225225
const scriptsToAdd = {
226-
android: 'tns run android --no-hmr',
227-
ios: 'tns run ios --no-hmr',
228-
mobile: 'tns run',
229-
preview: 'tns preview',
230-
ngcc: 'ngcc --properties es2015 module main --first-only',
231-
postinstall: 'npm run ngcc',
226+
android: 'ns run android --no-hmr',
227+
ios: 'ns run ios --no-hmr',
228+
mobile: 'ns run',
229+
// preview: 'ns preview',
230+
// ngcc: 'ngcc --properties es2015 module main --first-only',
231+
// postinstall: 'npm run ngcc',
232232
};
233233
packageJson.scripts = {...scriptsToAdd, ...packageJson.scripts};
234234

@@ -362,18 +362,21 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
362362
context.logger.info('Adding npm dependencies');
363363
const packageJson = getPackageJson(tree);
364364

365+
// add {N} 7 main key
366+
(<any>packageJson).main = 'main.tns.js';
367+
365368
// @UPGRADE: Update all versions whenever {N} version updates
366369
const depsToAdd = {
367-
'@nativescript/angular': '~10.0.0',
368-
'@nativescript/core': 'rc',
369-
'@nativescript/theme': '~2.2.1',
370+
'@nativescript/angular': '~10.1.0',
371+
'@nativescript/core': '~7.0.0',
372+
'@nativescript/theme': '~2.5.0',
370373
'reflect-metadata': '~0.1.12',
371374
tslib: '1.10.0',
372375
};
373376
packageJson.dependencies = {...depsToAdd, ...packageJson.dependencies};
374377

375378
const devDepsToAdd = {
376-
'@nativescript/webpack': '~2.0.0',
379+
'@nativescript/webpack': '~3.0.0',
377380
'@nativescript/tslint-rules': '~0.0.5',
378381
};
379382
packageJson.devDependencies = {...devDepsToAdd, ...packageJson.devDependencies};

src/add-ns/index_spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Add {N} schematic', () => {
4545
it('should add {N} specific files', () => {
4646
const files = appTree.files;
4747

48-
expect(files).toContain('/nsconfig.json');
48+
expect(files).toContain('/nativescript.config.ts');
4949
expect(files).toContain('/tsconfig.tns.json');
5050
expect(files).toContain('/src/app.css');
5151
expect(files).toContain('/src/main.tns.ts');
@@ -94,22 +94,22 @@ describe('Add {N} schematic', () => {
9494
const packageJson = JSON.parse(stripJsonComments(getFileContent(appTree, packageJsonPath)));
9595
const { scripts } = packageJson;
9696
expect(scripts).toBeDefined();
97-
expect(scripts.android).toEqual('tns run android --no-hmr');
98-
expect(scripts.ios).toEqual('tns run ios --no-hmr');
99-
expect(scripts.ngcc).toEqual('ngcc --properties es2015 module main --first-only');
100-
expect(scripts.postinstall).toEqual('npm run ngcc');
97+
expect(scripts.android).toEqual('ns run android --no-hmr');
98+
expect(scripts.ios).toEqual('ns run ios --no-hmr');
99+
// expect(scripts.ngcc).toEqual('ngcc --properties es2015 module main --first-only');
100+
// expect(scripts.postinstall).toEqual('npm run ngcc');
101101
});
102102

103-
it('should add NativeScript key to the package json', () => {
104-
const packageJsonPath = '/package.json';
105-
expect(appTree.files).toContain(packageJsonPath);
103+
// it('should add NativeScript key to the package json', () => {
104+
// const packageJsonPath = '/package.json';
105+
// expect(appTree.files).toContain(packageJsonPath);
106106

107-
const packageJson = JSON.parse(stripJsonComments(getFileContent(appTree, packageJsonPath)));
108-
const { nativescript } = packageJson;
107+
// const packageJson = JSON.parse(stripJsonComments(getFileContent(appTree, packageJsonPath)));
108+
// const { nativescript } = packageJson;
109109

110-
expect(nativescript).toBeDefined();
111-
expect(nativescript.id).toEqual('org.nativescript.ngsample');
112-
});
110+
// expect(nativescript).toBeDefined();
111+
// expect(nativescript.id).toEqual('org.nativescript.ngsample');
112+
// });
113113

114114
it('should modify the tsconfig.app.json (web) to include files and path mappings', () => {
115115
const webTsConfigPath = '/tsconfig.app.json';
@@ -294,7 +294,7 @@ async function setupProject(
294294
'workspace',
295295
{
296296
name: 'workspace',
297-
version: '10.0.0',
297+
version: '10.1.0',
298298
newProjectRoot: '',
299299
},
300300
).toPromise();

src/angular-project-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
1+
import * as ts from 'typescript';
22
import { basename } from 'path';
33
import { Tree, SchematicsException } from '@angular-devkit/schematics';
44
import { getWorkspace } from '@schematics/angular/utility/config';

src/convert-relative-imports/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
1+
import * as ts from 'typescript';
22
import { IRule, Replacement } from 'tslint';
33
import { tsquery } from '@phenomnomnominal/tsquery';
44
import { Tree, SchematicContext, isContentAction } from '@angular-devkit/schematics';

src/decorator-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
1+
import * as ts from 'typescript';
22
import { Tree } from '@angular-devkit/schematics';
33

44
import { findNode, findMatchingNodes, findImportPath, getSourceFile } from './ts-utils';

src/generate-template/master-detail/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import {
1313
import { dasherize, classify } from '@angular-devkit/core/src/utils/strings';
1414

1515
import { Schema as MasterDetailSchema } from './schema';
16-
import { getNsConfig } from '../../utils';
16+
// import { getNsConfig } from '../../utils';
1717
import { join } from 'path';
1818
import { Schema as ConvertRelativeImportsSchema } from '../../convert-relative-imports/schema';
19+
import { DEFAULT_SHARED_EXTENSIONS } from '../../generate/utils';
1920

2021
let projectParams: ProjectInfo;
2122

@@ -69,13 +70,13 @@ interface ProjectInfo {
6970
nsext: string;
7071
}
7172
const getProjectInfo = (tree: Tree): ProjectInfo => {
72-
if (tree.exists('nsconfig.json')) {
73-
const nsconfig = getNsConfig(tree);
73+
if (tree.exists('nativescript.config.ts')) {
74+
// const nsconfig = getNsConfig(tree);
7475

7576
return {
76-
shared: nsconfig.shared,
77-
appPath: join(nsconfig.appPath, 'app'),
78-
nsext: nsconfig.nsext,
77+
shared: true,//nsconfig.shared,
78+
appPath: join(tree.exists('app') ? 'app' : 'src', 'app'), //join(nsconfig.appPath, 'app'),
79+
nsext: DEFAULT_SHARED_EXTENSIONS.ns,// nsconfig.nsext,
7980
};
8081
}
8182

src/generate/component/ast-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
1+
import * as ts from 'typescript';
22

33
import { SchematicsException, Tree } from '@angular-devkit/schematics';
44
import { classify } from '@angular-devkit/core/src/utils/strings';
@@ -20,7 +20,7 @@ export function addDeclarationToNgModule(
2020
const source = readIntoSourceFile(tree, modulePath);
2121
const relativePath = buildRelativePath(modulePath, componentPath);
2222
const classifiedName = classify(`${options.name}Component`);
23-
const declarationChanges = addDeclarationToModule(source, modulePath, classifiedName, relativePath);
23+
const declarationChanges = addDeclarationToModule(<any>source, modulePath, classifiedName, relativePath);
2424
const declarationRecorder = tree.beginUpdate(modulePath);
2525
for (const change of declarationChanges) {
2626
if (change instanceof InsertChange) {
@@ -32,7 +32,7 @@ export function addDeclarationToNgModule(
3232
// Need to refresh the AST because we overwrote the file in the host.
3333
const src = readIntoSourceFile(tree, modulePath);
3434
const exportRecorder = tree.beginUpdate(modulePath);
35-
const exportChanges = addExportToModule(src, modulePath, classify(`${options.name}Component`), relativePath);
35+
const exportChanges = addExportToModule(<any>src, modulePath, classify(`${options.name}Component`), relativePath);
3636
for (const change of exportChanges) {
3737
if (change instanceof InsertChange) {
3838
exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -45,7 +45,7 @@ export function addDeclarationToNgModule(
4545
const src = readIntoSourceFile(tree, modulePath);
4646
const entryComponentRecorder = tree.beginUpdate(modulePath);
4747
const entryComponentChanges = addEntryComponentToModule(
48-
src,
48+
<any>src,
4949
modulePath,
5050
classify(`${options.name}Component`),
5151
relativePath,

src/generate/module/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const addSchema = (modulePath: string) =>
308308
const recorder = tree.beginUpdate(modulePath);
309309

310310
const metadataChange = addSymbolToNgModuleMetadata(
311-
moduleSource, modulePath,
311+
<any>moduleSource, modulePath,
312312
'schemas', 'NO_ERRORS_SCHEMA',
313313
'@angular/core');
314314

@@ -333,7 +333,7 @@ const addNSCommonModule = (tree: Tree, modulePath: string) => {
333333
const recorder = tree.beginUpdate(modulePath);
334334

335335
const metadataChange = addSymbolToNgModuleMetadata(
336-
moduleSource, modulePath,
336+
<any>moduleSource, modulePath,
337337
'imports', 'NativeScriptCommonModule',
338338
'@nativescript/angular');
339339

src/generate/utils.ts

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getNsConfig, getPackageJson } from '../utils';
1+
import { getPackageJson } from '../utils'; //getNsConfig
22
import { Tree, SchematicsException } from '@angular-devkit/schematics';
33
import { extname } from 'path';
44
import { Schema as ComponentOptions } from './component/schema';
@@ -18,20 +18,28 @@ export const DEFAULT_SHARED_EXTENSIONS: Extensions = {
1818

1919
const isNs = (tree: Tree) => {
2020
const packageJson = getPackageJson(tree);
21-
22-
return !!packageJson.nativescript;
21+
const coreNs = '@nativescript/core';
22+
const legacyNs = 'tns-core-modules';
23+
24+
if (packageJson.dependencies && (packageJson.dependencies[coreNs] || packageJson.dependencies[legacyNs])) {
25+
return true;
26+
} else if (packageJson.devDependencies && (packageJson.devDependencies[coreNs] || packageJson.devDependencies[legacyNs])) {
27+
return true;
28+
} else {
29+
return tree.exists('nativescript.config.ts');
30+
}
2331
};
2432

2533
const isWeb = (tree: Tree) => {
26-
if (!tree.exists('nsconfig.json')) {
27-
console.log(`nsconfig.json not found. Assuming this is a {N} only project`);
34+
if (!tree.exists('nativescript.config.ts')) {
35+
console.log(`nativescript.config.ts not found. Assuming this is a {N} only project`);
2836

2937
return false;
3038
}
3139

32-
const config = getNsConfig(tree);
40+
// const config = getNsConfig(tree);
3341

34-
return config.webext != null;
42+
return true;//config.webext != null;
3543
};
3644

3745
export interface PlatformUse {
@@ -69,24 +77,24 @@ export const getPlatformUse = (tree: Tree, options: Options): PlatformUse => {
6977
};
7078

7179
export const getExtensions = (tree: Tree, options: Options): Extensions => {
72-
let ns = options.nsExtension;
73-
let web = options.webExtension;
80+
// let ns = options.nsExtension;
81+
// let web = options.webExtension;
7482

75-
if (isWeb(tree)) {
76-
const nsconfig = getNsConfig(tree);
83+
// if (isWeb(tree)) {
84+
// const nsconfig = getNsConfig(tree);
7785

78-
ns = ns || nsconfig.nsext;
79-
web = web || nsconfig.webext;
86+
// ns = ns || nsconfig.nsext;
87+
// web = web || nsconfig.webext;
8088

81-
if (ns === web) {
82-
ns = DEFAULT_SHARED_EXTENSIONS.ns;
83-
web = DEFAULT_SHARED_EXTENSIONS.web;
84-
}
85-
}
89+
// if (ns === web) {
90+
// ns = DEFAULT_SHARED_EXTENSIONS.ns;
91+
// web = DEFAULT_SHARED_EXTENSIONS.web;
92+
// }
93+
// }
8694

8795
return {
88-
ns: parseExtension(ns || ''),
89-
web: parseExtension(web || ''),
96+
ns: DEFAULT_SHARED_EXTENSIONS.ns,// parseExtension(ns || ''),
97+
web: DEFAULT_SHARED_EXTENSIONS.web //parseExtension(web || ''),
9098
};
9199
};
92100

@@ -100,21 +108,21 @@ const parseExtension = (ext: string): string => {
100108
};
101109

102110
export const getNsConfigExtension = (tree: Tree): Extensions => {
103-
if (!tree.exists('nsconfig.json')) {
104-
console.warn('nsconfig not found, using .tns as a default extension for NativeScript files');
111+
// if (!tree.exists('nsconfig.json')) {
112+
// console.warn('nsconfig not found, using .tns as a default extension for NativeScript files');
105113

106114
return {
107115
ns: '.tns',
108116
web: '',
109117
};
110-
}
118+
// }
111119

112-
const nsconfig = getNsConfig(tree);
120+
// const nsconfig = getNsConfig(tree);
113121

114-
return {
115-
ns: nsconfig.nsext || '.tns',
116-
web: nsconfig.webext || '',
117-
};
122+
// return {
123+
// ns: nsconfig.nsext || '.tns',
124+
// web: nsconfig.webext || '',
125+
// };
118126
};
119127

120128
export const removeNsSchemaOptions = (options: Options) => {

src/mapped-imports-rule-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
1+
import * as ts from 'typescript';
22
import {
33
PreferMappedImportsRule,
44
RuleArgs,

src/migrate-component/component-info-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Schema as MigrateComponentSchema } from './schema';
33
import { dasherize, classify } from '@angular-devkit/core/src/utils/strings';
44
import { SchematicsException, Tree, SchematicContext } from '@angular-devkit/schematics';
55
import { join, dirname } from 'path';
6-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
6+
import * as ts from 'typescript';
77

88
import { AngularProjectSettings, getAngularProjectSettings } from '../angular-project-parser';
99
import { findImportPath, findMatchingNodes, getSourceFile } from '../ts-utils';

src/migrate-component/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const addComponentToNsModuleProviders = (
112112

113113
// Get the changes required to update the @NgModule
114114
const changes = addDeclarationToModule(
115-
getSourceFile(tree, nsModulePath),
115+
<any>getSourceFile(tree, nsModulePath),
116116
nsModulePath, // <- this doesn't look like it is in use
117117
componentInfo.className,
118118
findRelativeImportPath(nsModulePath, componentInfo.componentPath),

0 commit comments

Comments
 (0)