Skip to content

Commit 0837158

Browse files
authored
feat: update to Angular 8.0 (#214)
1 parent 7c3d159 commit 0837158

File tree

21 files changed

+302
-273
lines changed

21 files changed

+302
-273
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
},
1616
"schematics": "./src/collection.json",
1717
"dependencies": {
18-
"@angular-devkit/core": "~7.3.9",
19-
"@angular-devkit/schematics": "~7.3.9",
18+
"@angular-devkit/core": "~8.0.0",
19+
"@angular-devkit/schematics": "~8.0.0",
2020
"@nativescript/tslint-rules": "~0.0.1",
2121
"@phenomnomnominal/tsquery": "^3.0.0",
22-
"@schematics/angular": "~7.3.9",
22+
"@schematics/angular": "~8.0.0",
2323
"tslint": "^5.16.0"
2424
},
2525
"devDependencies": {
@@ -28,7 +28,7 @@
2828
"conventional-changelog-cli": "^2.0.1",
2929
"jasmine": "^2.8.0",
3030
"jasmine-spec-reporter": "^4.2.1",
31-
"typescript": "3.2.4"
31+
"typescript": "3.4.5"
3232
},
3333
"repository": {
3434
"type": "git",

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
"android": {
33
"v8Flags": "--expose_gc"
44
},
5-
"main": "<%= main %><%= nsext %>.js",
6-
"name": "migration-ng",
7-
"version": "4.1.0"
5+
"main": "<%= main %><%= nsext %>.js"
86
}

src/add-ns/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,18 @@ const modifyWebTsconfig = (tree: Tree, context: SchematicContext) => {
251251
const tsConfigPath = projectSettings.tsConfig;
252252
const tsConfig: any = getJsonFile(tree, tsConfigPath);
253253

254+
const srcDir = projectSettings.sourceRoot;
255+
254256
// files
255-
const defaultFiles = ["main.ts", "polyfills.ts"];
257+
const defaultFiles = [
258+
`${srcDir}/main.ts`,
259+
`${srcDir}/polyfills.ts`,
260+
];
261+
256262
tsConfig.files = tsConfig.files || [];
257263
tsConfig.files.push(...defaultFiles);
258264

259265
// paths
260-
const srcDir = projectSettings.sourceRoot;
261266
const webPaths = {
262267
"@src/*": [
263268
`${srcDir}/*.web`,
@@ -302,16 +307,16 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
302307

303308
// @UPGRADE: Update all versions whenever {N} version updates
304309
const depsToAdd = {
305-
'nativescript-angular': '~7.2.0',
310+
'nativescript-angular': '~8.0.1',
306311
'nativescript-theme-core': '~1.0.4',
307312
'reflect-metadata': '~0.1.12',
308-
'tns-core-modules': '~5.2.0'
313+
'tns-core-modules': '~5.4.0'
309314
};
310315
packageJson.dependencies = Object.assign({}, depsToAdd, packageJson.dependencies);
311316

312317
const devDepsToAdd = {
313-
'nativescript-dev-webpack': '^0.20.0',
314-
'@nativescript/schematics': '~0.4.0',
318+
'nativescript-dev-webpack': '~0.24.0',
319+
'@nativescript/schematics': '~0.6.0',
315320
};
316321
packageJson.devDependencies = Object.assign({}, devDepsToAdd, packageJson.devDependencies);
317322

src/add-ns/index_spec.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ describe('Add {N} schematic', () => {
2222

2323
let appTree: UnitTestTree;
2424

25-
beforeEach(() => {
25+
beforeEach(async () => {
2626
appTree = new UnitTestTree(new HostTree);
27-
appTree = setupProject(appTree, schematicRunner, project);
27+
appTree = await setupProject(appTree, schematicRunner, project);
2828
});
2929

3030
describe('when using the default options', () => {
31-
beforeEach(() => {
32-
appTree = schematicRunner.runSchematic('add-ns', defaultOptions, appTree);
31+
beforeEach(async () => {
32+
appTree = await schematicRunner.runSchematicAsync('add-ns', defaultOptions, appTree)
33+
.toPromise();
3334
});
3435

3536
it('should add dependency to NativeScript schematics', () => {
@@ -107,16 +108,16 @@ describe('Add {N} schematic', () => {
107108
expect(nativescript['id']).toEqual('org.nativescript.ngsample');
108109
});
109110

110-
it('should modify the tsconfig.app.json(web) to include files and path mappings', () => {
111-
const webTsConfigPath = '/src/tsconfig.app.json';
111+
it('should modify the tsconfig.app.json (web) to include files and path mappings', () => {
112+
const webTsConfigPath = '/tsconfig.app.json';
112113
expect(appTree.files).toContain(webTsConfigPath);
113114

114115
const webTsconfig = JSON.parse(getFileContent(appTree, webTsConfigPath));
115116
const files = webTsconfig.files;
116117

117118
expect(files).toBeDefined();
118-
expect(files.includes('main.ts')).toBeTruthy();
119-
expect(files.includes('polyfills.ts')).toBeTruthy();
119+
expect(files.includes('src/main.ts')).toBeTruthy();
120+
expect(files.includes('src/polyfills.ts')).toBeTruthy();
120121

121122
const paths = webTsconfig.compilerOptions.paths;
122123
expect(paths).toBeDefined();
@@ -148,7 +149,7 @@ describe('Add {N} schematic', () => {
148149
expect(maps).toContain("src/*.ts");
149150
});
150151

151-
it('should modify the base tsconfig.app.json to include path mappings', () => {
152+
it('should modify the base tsconfig.json to include path mappings', () => {
152153
const baseTsConfigPath = '/tsconfig.json';
153154
expect(appTree.files).toContain(baseTsConfigPath);
154155

@@ -186,13 +187,13 @@ describe('Add {N} schematic', () => {
186187
});
187188

188189
describe('when the skipAutoGeneratedComponent flag is raised', () => {
189-
beforeEach(() => {
190+
beforeEach(async () => {
190191
const options = {
191192
...defaultOptions,
192193
skipAutoGeneratedComponent: true,
193194
};
194195

195-
appTree = schematicRunner.runSchematic('add-ns', options, appTree);
196+
appTree = await schematicRunner.runSchematicAsync('add-ns', options, appTree).toPromise();
196197
});
197198

198199
it('should not add a sample shared component', () => {
@@ -215,13 +216,13 @@ describe('Add {N} schematic', () => {
215216
});
216217

217218
describe('when the sample flag is raised', () => {
218-
beforeEach(() => {
219+
beforeEach(async () => {
219220
const options = {
220221
...defaultOptions,
221222
sample: true,
222223
};
223224

224-
appTree = schematicRunner.runSchematic('add-ns', options, appTree);
225+
appTree = await schematicRunner.runSchematicAsync('add-ns', options, appTree).toPromise();
225226
});
226227

227228
it('should generate sample files', () => {
@@ -251,31 +252,31 @@ describe('Add {N} schematic', () => {
251252
});
252253
});
253254

254-
function setupProject(
255+
async function setupProject(
255256
tree: UnitTestTree,
256257
schematicRunner: SchematicTestRunner,
257258
name: string,
258259
) {
259260

260-
tree = schematicRunner.runExternalSchematic(
261+
tree = await schematicRunner.runExternalSchematicAsync(
261262
'@schematics/angular',
262263
'workspace',
263264
{
264265
name: 'workspace',
265-
version: '7.0.0',
266+
version: '8.0.0',
266267
newProjectRoot: ''
267268
}
268-
);
269+
).toPromise();
269270

270-
tree = schematicRunner.runExternalSchematic(
271+
tree = await schematicRunner.runExternalSchematicAsync(
271272
'@schematics/angular',
272273
'application',
273274
{
274275
name,
275276
projectRoot: ''
276277
},
277278
tree
278-
);
279+
).toPromise();
279280

280281
return tree;
281282
}

src/angular-json/index_spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('Angular JSON Config Schematic', () => {
1818

1919
describe('with default options (name only)', () => {
2020
let tree: UnitTestTree;
21-
beforeAll(() => {
22-
tree = schematicRunner.runSchematic('angular-json', defaultOptions);
21+
beforeAll(async () => {
22+
tree = await schematicRunner.runSchematicAsync('angular-json', defaultOptions).toPromise();
2323
})
2424

2525
it('should create angular.json files', () => {
@@ -35,24 +35,24 @@ describe('Angular JSON Config Schematic', () => {
3535
});
3636
})
3737

38-
it('should insert the prefix option', () => {
38+
it('should insert the prefix option', async () => {
3939
const prefix = 'custom-prefix';
40-
const tree = schematicRunner.runSchematic('angular-json', { ...defaultOptions, prefix });
40+
const tree = await schematicRunner.runSchematicAsync('angular-json', { ...defaultOptions, prefix }).toPromise();
4141
expect(getFileContent(tree, configPath)).toContain(`"prefix": "${prefix}"`);
4242
});
4343

44-
it('should insert the sourceRoot option', () => {
44+
it('should insert the sourceRoot option', async () => {
4545
const sourceRoot = 'src';
46-
const tree = schematicRunner.runSchematic('angular-json', { ...defaultOptions, sourceRoot });
46+
const tree = await schematicRunner.runSchematicAsync('angular-json', { ...defaultOptions, sourceRoot }).toPromise();
4747
expect(getFileContent(tree, configPath)).toContain(`"sourceRoot": "${sourceRoot}"`);
4848
});
4949

50-
it('should create files inside path when specified', () => {
50+
it('should create files inside path when specified', async () => {
5151
const path = '/path/to/my/app';
5252
const appJsonPath = `${path}/angular.json`;
5353
const options = { ...defaultOptions, path };
5454

55-
const tree = schematicRunner.runSchematic('angular-json', options);
55+
const tree = await schematicRunner.runSchematicAsync('angular-json', options).toPromise();
5656
expect(tree.files).toContain(appJsonPath);
5757
});
5858
});

src/convert-relative-imports/index_spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ describe('Convert relative imports to mapped imports', () => {
3131
join(__dirname, '../collection.json')
3232
);
3333

34-
it('should convert the relative imports in a newly generated file', () => {
34+
it('should convert the relative imports in a newly generated file', async () => {
3535
let appTree = createTestProject(projSetup);
3636

3737
appTree.create(aboutModulePath, relativeImportContent);
38-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
38+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
3939
const actual = getFileContent(appTree, aboutModulePath);
4040

4141
expect(actual).toEqual(fixedImportContent);
4242
});
4343

44-
it('should convert the relative imports in a modified file', () => {
44+
it('should convert the relative imports in a modified file', async () => {
4545
const existingContent = `
4646
import { AboutComponent } from '${importPrefix}/about/about.component';
4747
`;
@@ -60,85 +60,85 @@ describe('Convert relative imports to mapped imports', () => {
6060
}]);
6161

6262
appTree.overwrite(aboutModulePath, modifiedContent);
63-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
63+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
6464
const actual = getFileContent(appTree, aboutModulePath);
6565

6666
expect(actual).toEqual(expected);
6767
});
6868

69-
it('should convert the relative imports in a created and then renamed file', () => {
69+
it('should convert the relative imports in a created and then renamed file', async () => {
7070
let appTree = createTestProject(projSetup);
7171

7272
const renamedFilePath = aboutModulePath.replace(".ts", ".tns.ts");
7373

7474
appTree.create(aboutModulePath, relativeImportContent);
7575
appTree.rename(aboutModulePath, renamedFilePath);
7676

77-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
77+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
7878
const actual = getFileContent(appTree, renamedFilePath);
7979

8080
expect(actual).toEqual(fixedImportContent);
8181
});
8282

83-
it('should not modify files that weren\'t modified', () => {
83+
it('should not modify files that weren\'t modified', async () => {
8484
let appTree = createTestProject(projSetup, [{
8585
path: aboutModulePath,
8686
content: relativeImportContent
8787
}]);
8888

89-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
89+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
9090
const actual = getFileContent(appTree, aboutModulePath);
9191

9292
expect(actual).toEqual(relativeImportContent);
9393
});
9494

95-
it('should not modify files with extension other than .ts', () => {
95+
it('should not modify files with extension other than .ts', async () => {
9696
let appTree = createTestProject(projSetup);
9797

9898
const generatedFilePath = `${sourceDirectory}/about/about.component.tsx`;
9999

100100
appTree.create(generatedFilePath, relativeImportContent);
101-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
101+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
102102
const actual = getFileContent(appTree, generatedFilePath);
103103

104104
expect(actual).toEqual(relativeImportContent);
105105
});
106106

107-
it('should not modify files specified as ignored in the invocation options', () => {
107+
it('should not modify files specified as ignored in the invocation options', async () => {
108108
let appTree = createTestProject(projSetup);
109109

110110
appTree.create(aboutModulePath, relativeImportContent);
111111

112112
const options: ConvertRelativeImportsOptions = { ...defaultOptions, filesToIgnore: [aboutModulePath] };
113-
appTree = schematicRunner.runSchematic('convert-relative-imports', options, appTree);
113+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', options, appTree).toPromise();
114114
const actual = getFileContent(appTree, aboutModulePath);
115115

116116
expect(actual).toEqual(relativeImportContent);
117117
});
118118

119-
it('should not modify files that are deleted by previous rules', () => {
119+
it('should not modify files that are deleted by previous rules', async () => {
120120
let appTree = createTestProject(projSetup, [{
121121
path: aboutModulePath,
122122
content: relativeImportContent
123123
}]);
124124

125125
appTree.delete(aboutModulePath);
126-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
126+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
127127

128128
expect(appTree.get(aboutModulePath)).toBeNull();
129129
});
130130

131-
it('should not modify files that were created and then deleted by previous rules', () => {
131+
it('should not modify files that were created and then deleted by previous rules', async () => {
132132
let appTree = createTestProject(projSetup);
133133

134134
appTree.create(aboutModulePath, relativeImportContent);
135135
appTree.delete(aboutModulePath);
136-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
136+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
137137

138138
expect(appTree.get(aboutModulePath)).toBeNull();
139139
});
140140

141-
it('should not modify files that were modified and then deleted by previous rules', () => {
141+
it('should not modify files that were modified and then deleted by previous rules', async () => {
142142

143143
let appTree = createTestProject(projSetup, [{
144144
path: aboutModulePath,
@@ -147,7 +147,7 @@ describe('Convert relative imports to mapped imports', () => {
147147

148148
appTree.overwrite(aboutModulePath, relativeImportContent + '\nconsole.log(\'modified\');\n');
149149
appTree.delete(aboutModulePath);
150-
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
150+
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
151151

152152
expect(appTree.get(aboutModulePath)).toBeNull();
153153
});

0 commit comments

Comments
 (0)