Skip to content

Commit ad48c69

Browse files
authored
chore: update to Angular 4.1 and TypeScript 2.3 (#775)
* chore(deps): update to Angular 4.1.0 * chore(lint): update tslint to ^5.1.0 and codelyzer to ^3.0.1 * refactor: fix lint errors * fix: make update-app-ng-deps work with peerDeps
1 parent 152899b commit ad48c69

File tree

11 files changed

+471
-80
lines changed

11 files changed

+471
-80
lines changed

Diff for: nativescript-angular/bin/update-app-ng-deps

+39-29
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
#!/usr/bin/env node
22

3-
var path = require("path");
4-
var fs = require("fs");
5-
6-
var binPath = __dirname;
7-
var pluginPath = path.dirname(binPath);
8-
var pluginPackageJsonPath = path.join(pluginPath, "package.json");
9-
var projectPath = path.dirname(path.dirname(pluginPath));
10-
var appPackageJsonPath = path.join(projectPath, "package.json");
11-
12-
var appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, "utf8"));
13-
var pluginPackageJson = JSON.parse(fs.readFileSync(pluginPackageJsonPath, "utf8"));
14-
15-
Object.keys(pluginPackageJson.dependencies).forEach(function(dependencyName) {
16-
var version = pluginPackageJson.dependencies[dependencyName];
17-
if (dependencyName.startsWith("@angular") || dependencyName === "rxjs") {
18-
appPackageJson.dependencies[dependencyName] = version;
19-
console.log("Updated dependency '" + dependencyName + "' to version: " + version + ".");
20-
}
21-
});
22-
23-
Object.keys(pluginPackageJson.devDependencies).forEach(function(dependencyName) {
24-
var version = pluginPackageJson.devDependencies[dependencyName];
25-
if (dependencyName.startsWith("@angular") || dependencyName === "zone.js") {
26-
appPackageJson.devDependencies[dependencyName] = version;
27-
console.log("Updated dev dependency '" + dependencyName + "' to version: " + version + ".");
28-
}
29-
});
30-
31-
fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2));
3+
const path = require("path");
4+
const fs = require("fs");
5+
6+
const binPath = __dirname;
7+
const pluginPath = path.dirname(binPath);
8+
const pluginPackageJsonPath = path.join(pluginPath, "package.json");
9+
const pluginPackageJson = JSON.parse(fs.readFileSync(pluginPackageJsonPath, "utf8"));
10+
const pluginPeerDeps = pluginPackageJson.peerDependencies;
11+
12+
const projectPath = path.dirname(path.dirname(pluginPath));
13+
const appPackageJsonPath = path.join(projectPath, "package.json");
14+
const appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, "utf8"));
15+
16+
const shouldUpdateDependency = name => name.startsWith("@angular") ||
17+
name === "rxjs" ||
18+
name === "zone.js";
19+
20+
let updatedDependencies = appPackageJson.dependencies;
21+
22+
// set app dependencies to ones required from plugin (peer)
23+
Object.keys(pluginPeerDeps)
24+
.filter(shouldUpdateDependency)
25+
.forEach(dependencyName => {
26+
const version = pluginPackageJson.peerDependencies[dependencyName];
27+
updatedDependencies[dependencyName] = version;
28+
console.log(`Updated dependency ${dependencyName} to version: ${version}.`);
29+
});
30+
31+
// remove platform-browser-dynamic if present
32+
const browserDynamicDependency = "@angular/platform-browser-dynamic";
33+
if (updatedDependencies.hasOwnProperty(browserDynamicDependency)) {
34+
delete updatedDependencies[browserDynamicDependency];
35+
console.log(`Removed ${browserDynamicDependency}`);
36+
}
37+
38+
let updatedPackageJson = appPackageJson;
39+
updatedPackageJson.dependencies = updatedDependencies;
40+
41+
fs.writeFileSync(appPackageJsonPath, JSON.stringify(updatedPackageJson, null, 2));
3242

3343
console.log("\nAngular dependencies updated. Don't forget to run `npm install`.");

Diff for: nativescript-angular/directives/list-view-comp.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit {
168168
if (!viewRef) {
169169
listViewError("ViewReference not found for item " + index + ". View recycling is not working");
170170
}
171-
};
171+
}
172172

173173
if (!viewRef) {
174174
listViewLog("onItemLoading: " + index + " - Creating view from template");
@@ -234,7 +234,8 @@ function getSingleViewRecursive(nodes: Array<any>, nestLevel: number): View {
234234
export interface ComponentView {
235235
rootNodes: Array<any>;
236236
destroy(): void;
237-
};
237+
}
238+
238239
export type RootLocator = (nodes: Array<any>, nestLevel: number) => View;
239240

240241
export function getItemViewRoot(viewRef: ComponentView, rootLocator: RootLocator = getSingleViewRecursive): View {

Diff for: nativescript-angular/http.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export { NSHttp } from "./http/ns-http";
1111

1212
export function nsHttpFactory(backend, options, nsFileSystem) {
1313
return new NSHttp(backend, options, nsFileSystem);
14-
};
14+
}
1515

1616
export function nsXSRFStrategyFactory() {
1717
return new NSXSRFStrategy();
18-
};
18+
}
1919

2020
@NgModule({
2121
providers: [

Diff for: nativescript-angular/nativescript.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { NS_DIRECTIVES } from "./directives";
2626

2727
export function errorHandlerFactory() {
2828
return new ErrorHandler(true);
29-
};
29+
}
3030

3131
@NgModule({
3232
declarations: [

Diff for: nativescript-angular/package.json

+22-22
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"url": "https://github.com/NativeScript/nativescript-angular.git"
3030
},
3131
"scripts": {
32-
"tslint": "tslint --project tsconfig.json --config tslint.json",
32+
"tslint": "tslint --project tsconfig.json --config tslint.json --type-check",
3333
"postinstall": "node postinstall.js",
3434
"tsc": "tsc -p tsconfig.json",
3535
"ngc": "ngc -p tsconfig.json",
@@ -43,32 +43,32 @@
4343
"reflect-metadata": "^0.1.8"
4444
},
4545
"peerDependencies": {
46-
"@angular/core": "~4.0.0",
47-
"@angular/common": "~4.0.0",
48-
"@angular/compiler": "~4.0.0",
49-
"@angular/platform-browser": "~4.0.0",
50-
"@angular/router": "~4.0.0",
51-
"@angular/forms": "~4.0.0",
52-
"@angular/http": "~4.0.0",
53-
"tns-core-modules": "^3.0.0 || ^3.0.0-rc.1",
46+
"@angular/common": "~4.0.0 || ~4.1.0",
47+
"@angular/compiler": "~4.0.0 || ~4.1.0",
48+
"@angular/core": "~4.0.0 || ~4.1.0",
49+
"@angular/forms": "~4.0.0 || ~4.1.0",
50+
"@angular/http": "~4.0.0 || ~4.1.0",
51+
"@angular/platform-browser": "~4.0.0 || ~4.1.0",
52+
"@angular/router": "~4.0.0 || ~4.1.0",
5453
"rxjs": "^5.0.1",
54+
"tns-core-modules": "^3.0.0 || ^3.0.0-rc.1",
5555
"zone.js": "^0.8.4"
5656
},
5757
"devDependencies": {
58-
"@angular/core": "~4.0.0",
59-
"@angular/common": "~4.0.0",
60-
"@angular/compiler": "~4.0.0",
61-
"@angular/compiler-cli": "~4.0.0",
62-
"@angular/platform-browser": "~4.0.0",
63-
"@angular/animations": "~4.0.0",
64-
"@angular/router": "~4.0.0",
65-
"@angular/forms": "~4.0.0",
66-
"@angular/http": "~4.0.0",
67-
"codelyzer": "~3.0.0-beta.4",
68-
"tns-core-modules": "internal-preview",
69-
"tslint": "~4.5.0",
70-
"typescript": "~2.2.1",
58+
"@angular/animations": "~4.0.0 || ~4.1.0",
59+
"@angular/common": "~4.0.0 || ~4.1.0",
60+
"@angular/compiler": "~4.0.0 || ~4.1.0",
61+
"@angular/compiler-cli": "~4.0.0 || ~4.1.0",
62+
"@angular/core": "~4.0.0 || ~4.1.0",
63+
"@angular/forms": "~4.0.0 || ~4.1.0",
64+
"@angular/http": "~4.0.0 || ~4.1.0",
65+
"@angular/platform-browser": "~4.0.0 || ~4.1.0",
66+
"@angular/router": "~4.0.0 || ~4.1.0",
67+
"codelyzer": "^3.0.1",
7168
"rxjs": "^5.0.1",
69+
"tns-core-modules": "internal-preview",
70+
"tslint": "^5.1.0",
71+
"typescript": "^2.3.2",
7272
"zone.js": "^0.8.4"
7373
}
7474
}

Diff for: nativescript-angular/platform-common.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
129129

130130
get injector(): Injector {
131131
return this.platform.injector;
132-
};
132+
}
133133

134134
destroy(): void {
135135
this.platform.destroy();

Diff for: nativescript-angular/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"genDir": ".",
3232
"skipMetadataEmit": false,
3333
"skipTemplateCodegen": true,
34-
"debug": true
34+
"strictMetadataEmit": true
3535
}
3636
}

Diff for: nativescript-angular/tslint.json

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"no-string-literal": false,
6363
"no-switch-case-fall-through": true,
6464
"no-unused-expression": true,
65-
"no-use-before-declare": true,
6665
"no-var-keyword": true,
6766
"radix": false,
6867
"switch-default": true,

0 commit comments

Comments
 (0)