@@ -83,14 +83,23 @@ if (fs.existsSync(npmrcPath)) {
8383
8484// Check for the Rush version
8585let installedVersion = undefined ;
86+ let installedVersionValid = false
8687console . log ( os . EOL + `Expected Rush version is ${ expectedVersion } ` ) ;
8788
8889try {
8990 const spawnResult = child_process . spawnSync ( npmPath , [ 'list' , packageName , 'version' ] ,
9091 { cwd : rushPath , stdio : [ 'pipe' , 'pipe' , 'pipe' ] } ) ;
92+ const output = spawnResult . output . toString ( ) ;
9193 const matches = / @ m i c r o s o f t \/ r u s h \@ ( [ 0 - 9 a - z A - Z . + \- ] + ) / . exec ( spawnResult . output ) ;
92- if ( matches && matches . length === 2 ) {
94+ // If NPM finds the wrong version in node_modules, that version will be in matches[1].
95+ // But if it's not installed at all, then NPM instead uselessly tells us all about
96+ // the version that we DON'T have ("missing:")
97+ if ( matches && matches . length === 2 && ! output . match ( / m i s s i n g \: / g) ) {
9398 installedVersion = matches [ 1 ] ;
99+
100+ if ( spawnResult . status === 0 ) {
101+ installedVersionValid = true
102+ }
94103 }
95104}
96105catch ( error ) {
@@ -103,7 +112,7 @@ if (installedVersion) {
103112 console . log ( os . EOL + 'Rush does not appear to be installed' ) ;
104113}
105114
106- if ( installedVersion !== expectedVersion ) {
115+ if ( ! installedVersionValid || installedVersion !== expectedVersion ) {
107116 console . log ( os . EOL + 'Installing Rush...' ) ;
108117 child_process . execSync ( `"${ npmPath } " install ${ packageName } @${ expectedVersion } ` , { cwd : rushPath } ) ;
109118 console . log ( os . EOL + `Successfully installed Rush ${ expectedVersion } ` ) ;
0 commit comments