Skip to content

Commit d5b5b83

Browse files
author
Alexander Vakrilov
authored
Merge pull request #68 from NativeScript/ts-update-patch
chore: TS force install patches
2 parents 814d533 + 7424564 commit d5b5b83

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

postinstall.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (projectDir) {
1919
createReferenceFile();
2020
}
2121

22-
installTypescript(hasModules30);
22+
installTypescript();
2323
}
2424

2525
function createReferenceFile() {
@@ -63,16 +63,14 @@ function getProjectTypeScriptVersion() {
6363
}
6464
}
6565

66-
function installTypescript(hasModules30) {
66+
function installTypescript() {
6767
const installedTypeScriptVersion = getProjectTypeScriptVersion();
68-
const force = shouldInstallLatest(installedTypeScriptVersion, hasModules30);
68+
const force = shouldInstallLatest(installedTypeScriptVersion);
6969

7070
if (installedTypeScriptVersion && !force) {
7171
console.log(`Project already targets TypeScript ${installedTypeScriptVersion}`);
7272
} else {
73-
const command = force ?
74-
"npm install -D typescript@latest" :
75-
"npm install -D -E [email protected]"; // install exactly 2.1.6
73+
const command = "npm install -D typescript@latest";
7674

7775
console.log("Installing TypeScript...");
7876

@@ -87,16 +85,18 @@ function installTypescript(hasModules30) {
8785
}
8886
}
8987

90-
function shouldInstallLatest(tsVersion, hasModules30) {
91-
if (!hasModules30) {
92-
return false;
88+
function shouldInstallLatest(tsVersion) {
89+
if (!tsVersion) {
90+
return true;
9391
}
9492

9593
const justVersion = clearPatch(tsVersion);
96-
return !tsVersion ||
97-
tsVersion === "2.2.0" ||
98-
justVersion[0] < 2 || // ex. 1.8.10
99-
justVersion[2] < 2; // ex. 2.1.6
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
100100
}
101101

102102
function clearPatch(version) {

0 commit comments

Comments
 (0)