Skip to content

Commit 5a2c387

Browse files
author
Dimitar Tachev
authored
Merge pull request #71 from NativeScript/tachev/fix-ts-install-issues
Fix Typescript installation issues
2 parents 2597643 + 0728654 commit 5a2c387

File tree

2 files changed

+3
-60
lines changed

2 files changed

+3
-60
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-dev-typescript",
3-
"version": "0.7.7",
3+
"version": "0.7.8",
44
"description": "TypeScript support for NativeScript projects. Install using `tns install typescript`.",
55
"scripts": {
66
"test": "exit 0",
@@ -41,6 +41,7 @@
4141
},
4242
"dependencies": {
4343
"nativescript-hook": "^0.2.0",
44-
"semver": "5.5.0"
44+
"semver": "5.5.0",
45+
"typescript": "~3.1.1"
4546
}
4647
}

postinstall.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ if (projectDir) {
1818
if (!hasModules30) {
1919
createReferenceFile();
2020
}
21-
22-
installTypescript();
2321
}
2422

2523
function createReferenceFile() {
@@ -48,59 +46,3 @@ function createTsconfig(tsconfigPath) {
4846

4947
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
5048
}
51-
52-
function getProjectTypeScriptVersion() {
53-
try {
54-
var packageJsonPath = path.join(projectDir, "package.json"),
55-
packageJsonContent = fs.readFileSync(packageJsonPath, "utf8"),
56-
jsonContent = JSON.parse(packageJsonContent);
57-
58-
return (jsonContent.dependencies && jsonContent.dependencies.typescript) ||
59-
(jsonContent.devDependencies && jsonContent.devDependencies.typescript);
60-
} catch (err) {
61-
console.error(err);
62-
return null;
63-
}
64-
}
65-
66-
function installTypescript() {
67-
const installedTypeScriptVersion = getProjectTypeScriptVersion();
68-
const force = shouldInstallLatest(installedTypeScriptVersion);
69-
70-
if (installedTypeScriptVersion && !force) {
71-
console.log(`Project already targets TypeScript ${installedTypeScriptVersion}`);
72-
} else {
73-
const command = "npm install -D typescript@latest";
74-
75-
console.log("Installing TypeScript...");
76-
77-
require("child_process").exec(command, { cwd: projectDir }, (err, stdout, stderr) => {
78-
if (err) {
79-
console.warn(`npm: ${err.toString()}`);
80-
}
81-
82-
process.stdout.write(stdout);
83-
process.stderr.write(stderr);
84-
});
85-
}
86-
}
87-
88-
function shouldInstallLatest(tsVersion) {
89-
if (!tsVersion) {
90-
return true;
91-
}
92-
93-
const justVersion = clearPatch(tsVersion);
94-
const majorVer = justVersion[0];
95-
const minorVer = justVersion[2];
96-
97-
return tsVersion === "2.2.0" ||
98-
majorVer < 2 || // ex. 1.8.10
99-
(majorVer === "2" && minorVer < 2); // ex. 2.1.6
100-
}
101-
102-
function clearPatch(version) {
103-
return version && (version.startsWith("~") || version.startsWith("^")) ?
104-
version.substring(1) :
105-
version;
106-
}

0 commit comments

Comments
 (0)