@@ -19,7 +19,7 @@ if (projectDir) {
19
19
createReferenceFile ( ) ;
20
20
}
21
21
22
- installTypescript ( hasModules30 ) ;
22
+ installTypescript ( ) ;
23
23
}
24
24
25
25
function createReferenceFile ( ) {
@@ -63,16 +63,14 @@ function getProjectTypeScriptVersion() {
63
63
}
64
64
}
65
65
66
- function installTypescript ( hasModules30 ) {
66
+ function installTypescript ( ) {
67
67
const installedTypeScriptVersion = getProjectTypeScriptVersion ( ) ;
68
- const force = shouldInstallLatest ( installedTypeScriptVersion , hasModules30 ) ;
68
+ const force = shouldInstallLatest ( installedTypeScriptVersion ) ;
69
69
70
70
if ( installedTypeScriptVersion && ! force ) {
71
71
console . log ( `Project already targets TypeScript ${ installedTypeScriptVersion } ` ) ;
72
72
} 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" ;
76
74
77
75
console . log ( "Installing TypeScript..." ) ;
78
76
@@ -87,16 +85,18 @@ function installTypescript(hasModules30) {
87
85
}
88
86
}
89
87
90
- function shouldInstallLatest ( tsVersion , hasModules30 ) {
91
- if ( ! hasModules30 ) {
92
- return false ;
88
+ function shouldInstallLatest ( tsVersion ) {
89
+ if ( ! tsVersion ) {
90
+ return true ;
93
91
}
94
92
95
93
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
100
100
}
101
101
102
102
function clearPatch ( version ) {
0 commit comments