@@ -35,23 +35,25 @@ import { GlobalScriptAction } from './scriptActions/GlobalScriptAction';
3535import { Telemetry } from '../logic/Telemetry' ;
3636import { AlreadyReportedError } from '../utilities/AlreadyReportedError' ;
3737import { RushGlobalFolder } from '../api/RushGlobalFolder' ;
38+ import { NodeJsCompatibility } from '../logic/NodeJsCompatibility' ;
3839
3940/**
4041 * Options for `RushCommandLineParser`.
4142 */
4243export interface IRushCommandLineParserOptions {
43- cwd ?: string ; // Defaults to `cwd`
44+ cwd : string ; // Defaults to `cwd`
45+ alreadyReportedNodeTooNewError : boolean ;
4446}
4547
4648export class RushCommandLineParser extends CommandLineParser {
4749 public telemetry : Telemetry | undefined ;
48- public rushConfiguration : RushConfiguration ;
4950 public rushGlobalFolder : RushGlobalFolder ;
51+ public rushConfiguration : RushConfiguration ;
5052
5153 private _debugParameter : CommandLineFlagParameter ;
5254 private _rushOptions : IRushCommandLineParserOptions ;
5355
54- constructor ( options ?: IRushCommandLineParserOptions ) {
56+ constructor ( options ?: Partial < IRushCommandLineParserOptions > ) {
5557 super ( {
5658 toolFilename : 'rush' ,
5759 toolDescription : 'Rush makes life easier for JavaScript developers who develop, build, and publish'
@@ -63,10 +65,27 @@ export class RushCommandLineParser extends CommandLineParser {
6365 + ' automation tools. If you are looking for a proven turnkey solution for monorepo management,'
6466 + ' Rush is for you.'
6567 } ) ;
66- const optionsIn : IRushCommandLineParserOptions = options || { } ;
67- this . _rushOptions = {
68- cwd : optionsIn . cwd || process . cwd ( )
69- } ;
68+
69+ this . _rushOptions = this . _normalizeOptions ( options || { } ) ;
70+
71+ try {
72+ const rushJsonFilename : string | undefined = RushConfiguration . tryFindRushJsonLocation ( {
73+ startingFolder : this . _rushOptions . cwd ,
74+ showVerbose : true
75+ } ) ;
76+ if ( rushJsonFilename ) {
77+ this . rushConfiguration = RushConfiguration . loadFromConfigurationFile ( rushJsonFilename ) ;
78+ }
79+ } catch ( error ) {
80+ this . _reportErrorAndSetExitCode ( error ) ;
81+ }
82+
83+ NodeJsCompatibility . warnAboutCompatibilityIssues ( {
84+ isRushLib : true ,
85+ alreadyReportedNodeTooNewError : this . _rushOptions . alreadyReportedNodeTooNewError ,
86+ rushConfiguration : this . rushConfiguration
87+ } ) ;
88+
7089 this . _populateActions ( ) ;
7190 }
7291
@@ -90,8 +109,8 @@ export class RushCommandLineParser extends CommandLineParser {
90109
91110 protected onExecute ( ) : Promise < void > {
92111 // Defensively set the exit code to 1 so if Rush crashes for whatever reason, we'll have a nonzero exit code.
93- // For example, NodeJS currently has the inexcusable design of terminating with zero exit code when
94- // there is an uncaught promise exception. This will supposedly be fixed in NodeJS 9.
112+ // For example, Node.js currently has the inexcusable design of terminating with zero exit code when
113+ // there is an uncaught promise exception. This will supposedly be fixed in Node.js 9.
95114 // Ideally we should do this for all the Rush actions, but "rush build" is the most critical one
96115 // -- if it falsely appears to succeed, we could merge bad PRs, publish empty packages, etc.
97116 process . exitCode = 1 ;
@@ -108,6 +127,13 @@ export class RushCommandLineParser extends CommandLineParser {
108127 } ) ;
109128 }
110129
130+ private _normalizeOptions ( options : Partial < IRushCommandLineParserOptions > ) : IRushCommandLineParserOptions {
131+ return {
132+ cwd : options . cwd || process . cwd ( ) ,
133+ alreadyReportedNodeTooNewError : options . alreadyReportedNodeTooNewError || false
134+ } ;
135+ }
136+
111137 private _wrapOnExecute ( ) : Promise < void > {
112138 try {
113139 if ( this . rushConfiguration ) {
@@ -125,14 +151,6 @@ export class RushCommandLineParser extends CommandLineParser {
125151
126152 private _populateActions ( ) : void {
127153 try {
128- const rushJsonFilename : string | undefined = RushConfiguration . tryFindRushJsonLocation ( {
129- startingFolder : this . _rushOptions . cwd ,
130- showVerbose : true
131- } ) ;
132- if ( rushJsonFilename ) {
133- this . rushConfiguration = RushConfiguration . loadFromConfigurationFile ( rushJsonFilename ) ;
134- }
135-
136154 this . rushGlobalFolder = new RushGlobalFolder ( ) ;
137155
138156 this . addAction ( new AddAction ( this ) ) ;
@@ -163,7 +181,8 @@ export class RushCommandLineParser extends CommandLineParser {
163181 // command-line help
164182 if ( this . rushConfiguration ) {
165183 const commandLineConfigFile : string = path . join (
166- this . rushConfiguration . commonRushConfigFolder , RushConstants . commandLineFilename
184+ this . rushConfiguration . commonRushConfigFolder ,
185+ RushConstants . commandLineFilename
167186 ) ;
168187
169188 commandLineConfiguration = CommandLineConfiguration . loadFromFileOrDefault ( commandLineConfigFile ) ;
@@ -320,7 +339,7 @@ export class RushCommandLineParser extends CommandLineParser {
320339 }
321340
322341 if ( this . _debugParameter . value ) {
323- // If catchSyncErrors() called this, then show a call stack similar to what NodeJS
342+ // If catchSyncErrors() called this, then show a call stack similar to what Node.js
324343 // would show for an uncaught error
325344 console . error ( os . EOL + error . stack ) ;
326345 }
0 commit comments