Skip to content

chore: TS force install patches #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (projectDir) {
createReferenceFile();
}

installTypescript(hasModules30);
installTypescript();
}

function createReferenceFile() {
Expand Down Expand Up @@ -63,16 +63,14 @@ function getProjectTypeScriptVersion() {
}
}

function installTypescript(hasModules30) {
function installTypescript() {
const installedTypeScriptVersion = getProjectTypeScriptVersion();
const force = shouldInstallLatest(installedTypeScriptVersion, hasModules30);
const force = shouldInstallLatest(installedTypeScriptVersion);

if (installedTypeScriptVersion && !force) {
console.log(`Project already targets TypeScript ${installedTypeScriptVersion}`);
} else {
const command = force ?
"npm install -D typescript@latest" :
"npm install -D -E typescript@2.1.6"; // install exactly 2.1.6
const command = "npm install -D typescript@latest";

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

Expand All @@ -87,16 +85,18 @@ function installTypescript(hasModules30) {
}
}

function shouldInstallLatest(tsVersion, hasModules30) {
if (!hasModules30) {
return false;
function shouldInstallLatest(tsVersion) {
if (!tsVersion) {
return true;
}

const justVersion = clearPatch(tsVersion);
return !tsVersion ||
tsVersion === "2.2.0" ||
justVersion[0] < 2 || // ex. 1.8.10
justVersion[2] < 2; // ex. 2.1.6
const majorVer = justVersion[0];
const minorVer = justVersion[2];

return tsVersion === "2.2.0" ||
majorVer < 2 || // ex. 1.8.10
(majorVer === "2" && minorVer < 2); // ex. 2.1.6
}

function clearPatch(version) {
Expand Down