@@ -104,23 +104,30 @@ function resolveCLI(cli) {
104104 * Run a command with the given arguments
105105 * @param {string } cli Path of the cli command
106106 * @param {string[] } args The arguments
107- * @param {boolean } dryRun Controls if the cli will be executed or not. If set
107+ * @param {object } options Options to control dryRun and spawn
108+ * - dryRun Controls if the cli will be executed or not. If set
108109 * to true, the command itself will be returned without running it
109110 */
110- function runCLI ( cli , args , dryRun ) {
111+ function runCLI ( cli , args , options ) {
111112 cli = resolveCLI ( cli ) ;
112113 args = [ cli ] . concat ( args ) ;
113114 debug ( '%s' , args . join ( ' ' ) ) ;
114- if ( dryRun ) {
115+ // Keep it backward compatible as dryRun
116+ if ( typeof options === 'boolean' ) options = { dryRun : options } ;
117+ options = options || { } ;
118+ if ( options . dryRun ) {
115119 return util . format ( '%s %s' , process . execPath , args . join ( ' ' ) ) ;
116120 }
117121 var child = spawn (
118122 process . execPath , // Typically '/usr/local/bin/node'
119123 args ,
120- {
121- stdio : 'inherit' ,
122- env : Object . create ( process . env ) ,
123- }
124+ Object . assign (
125+ {
126+ stdio : 'inherit' ,
127+ env : Object . create ( process . env ) ,
128+ } ,
129+ options
130+ )
124131 ) ;
125132 child . on ( 'close' , ( code , signal ) => {
126133 debug ( '%s exits: %d' , cli , code ) ;
@@ -133,23 +140,34 @@ function runCLI(cli, args, dryRun) {
133140 * Run the command in a shell
134141 * @param {string } command The command
135142 * @param {string[] } args The arguments
136- * @param {boolean } dryRun Controls if the cli will be executed or not. If set
143+ * @param {object } options Options to control dryRun and spawn
144+ * - dryRun Controls if the cli will be executed or not. If set
137145 * to true, the command itself will be returned without running it
138146 */
139- function runShell ( command , args , dryRun ) {
147+ function runShell ( command , args , options ) {
140148 args = args . map ( a => JSON . stringify ( a ) ) ;
141149 debug ( '%s %s' , command , args . join ( ' ' ) ) ;
142- if ( dryRun ) {
150+ // Keep it backward compatible as dryRun
151+ if ( typeof options === 'boolean' ) options = { dryRun : options } ;
152+ options = options || { } ;
153+ if ( options . dryRun ) {
143154 return util . format ( '%s %s' , command , args . join ( ' ' ) ) ;
144155 }
145- var child = spawn ( command , args , {
146- stdio : 'inherit' ,
147- env : Object . create ( process . env ) ,
148- // On Windows, npm creates `.cmd` files instead of symlinks in
149- // `node_modules/.bin` folder. These files cannot be executed directly,
150- // only via a shell.
151- shell : true ,
152- } ) ;
156+ var child = spawn (
157+ command ,
158+ args ,
159+ Object . assign (
160+ {
161+ stdio : 'inherit' ,
162+ env : Object . create ( process . env ) ,
163+ // On Windows, npm creates `.cmd` files instead of symlinks in
164+ // `node_modules/.bin` folder. These files cannot be executed directly,
165+ // only via a shell.
166+ shell : true ,
167+ } ,
168+ options
169+ )
170+ ) ;
153171 child . on ( 'close' , ( code , signal ) => {
154172 debug ( '%s exits: %d' , command , code ) ;
155173 process . exitCode = code ;
0 commit comments