@@ -14,23 +14,40 @@ const fs = require('fs');
1414const os = require ( 'os' ) ;
1515const path = require ( 'path' ) ;
1616
17- const rushJsonContents = fs . readFileSync ( path . join ( __dirname , '..' , '..' , 'rush.json' ) , 'UTF-8' ) ;
18- const rushJsonMatches = rushJsonContents . match ( / \" r u s h M i n i m u m V e r s i o n \" \s * \: \s * \" ( [ 0 - 9 \. ] + ) \" / ) ;
19- const expectedVersion = rushJsonMatches [ 1 ] ;
2017const packageName = "@microsoft/rush" ;
2118
19+ const rushJsonPath = path . join ( __dirname , '..' , '..' , 'rush.json' ) ;
20+ let expectedVersion ;
21+ try {
22+ const rushJsonContents = fs . readFileSync ( rushJsonPath , 'UTF-8' ) ;
23+ // Use a regular expression to parse out the rushMinimumVersion value because rush.json supports comments,
24+ // but JSON.parse does not and we don't want to pull in more dependencies than we need to in this script.
25+ const rushJsonMatches = rushJsonContents . match ( / \" r u s h M i n i m u m V e r s i o n \" \s * \: \s * \" ( [ 0 - 9 \. ] + ) \" / ) ;
26+ expectedVersion = rushJsonMatches [ 1 ] ;
27+ } catch ( e ) {
28+ console . error ( `Unable to determine the required version of Rush from rush.json (${ rushJsonPath } ). ` +
29+ 'The "rushMinimumVersion" field is either not assigned in rush.json or was specified ' +
30+ 'using an unexpected syntax.' ) ;
31+ return ;
32+ }
33+
2234let npmPath ;
23- if ( process . env . NODIST_PREFIX ) {
24- // Nodist is installed
25- npmPath = path . join ( process . env . NODIST_PREFIX , 'bin' , 'npm.exe' ) ;
26- } else if ( os . platform ( ) === 'win32' ) {
27- // We're on Windows
28- const whereOutput = child_process . execSync ( 'where npm' , { stdio : [ ] } ) . toString ( ) ;
29- const lines = whereOutput . split ( os . EOL ) . filter ( ( line ) => ! ! line ) ;
30- npmPath = lines [ lines . length - 1 ] ;
31- } else {
32- // We aren't on Windows - assume we're on 'NIX or Darwin
33- npmPath = child_process . execSync ( 'which npm' , { stdio : [ ] } ) . toString ( ) ;
35+ try {
36+ if ( process . env . NODIST_PREFIX ) {
37+ // Nodist is installed
38+ npmPath = path . join ( process . env . NODIST_PREFIX , 'bin' , 'npm.exe' ) ;
39+ } else if ( os . platform ( ) === 'win32' ) {
40+ // We're on Windows
41+ const whereOutput = child_process . execSync ( 'where npm' , { stdio : [ ] } ) . toString ( ) ;
42+ const lines = whereOutput . split ( os . EOL ) . filter ( ( line ) => ! ! line ) ;
43+ npmPath = lines [ lines . length - 1 ] ;
44+ } else {
45+ // We aren't on Windows - assume we're on 'NIX or Darwin
46+ npmPath = child_process . execSync ( 'which npm' , { stdio : [ ] } ) . toString ( ) ;
47+ }
48+ } catch ( e ) {
49+ console . error ( `Unable to determine the path to the NPM tool: ${ e } ` ) ;
50+ return ;
3451}
3552
3653npmPath = npmPath . trim ( ) ;
0 commit comments