diff options
Diffstat (limited to 'lib/child_process.js')
-rw-r--r-- | lib/child_process.js | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/lib/child_process.js b/lib/child_process.js index 0fd372e311..d5037d96fc 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -460,16 +460,14 @@ function normalizeSpawnArguments(file, args, options) { } // Validate windowsVerbatimArguments, if present. - if (options.windowsVerbatimArguments != null && - typeof options.windowsVerbatimArguments !== 'boolean') { + let { windowsVerbatimArguments } = options; + if (windowsVerbatimArguments != null && + typeof windowsVerbatimArguments !== 'boolean') { throw new ERR_INVALID_ARG_TYPE('options.windowsVerbatimArguments', 'boolean', - options.windowsVerbatimArguments); + windowsVerbatimArguments); } - // Make a shallow copy so we don't clobber the user's options object. - options = { ...options }; - if (options.shell) { const command = [file].concat(args).join(' '); // Set the shell, switches, and commands. @@ -481,7 +479,7 @@ function normalizeSpawnArguments(file, args, options) { // '/d /s /c' is used only for cmd.exe. if (/^(?:.*\\)?cmd(?:\.exe)?$/i.test(file)) { args = ['/d', '/s', '/c', `"${command}"`]; - options.windowsVerbatimArguments = true; + windowsVerbatimArguments = true; } else { args = ['-c', command]; } @@ -521,47 +519,35 @@ function normalizeSpawnArguments(file, args, options) { } return { - file: file, - args: args, - options: options, - envPairs: envPairs + // Make a shallow copy so we don't clobber the user's options object. + ...options, + args, + detached: !!options.detached, + envPairs, + file, + windowsHide: !!options.windowsHide, + windowsVerbatimArguments: !!windowsVerbatimArguments }; } var spawn = exports.spawn = function spawn(file, args, options) { - const opts = normalizeSpawnArguments(file, args, options); const child = new ChildProcess(); - options = opts.options; - debug('spawn', opts.args, options); - - child.spawn({ - file: opts.file, - args: opts.args, - cwd: options.cwd, - windowsHide: !!options.windowsHide, - windowsVerbatimArguments: !!options.windowsVerbatimArguments, - detached: !!options.detached, - envPairs: opts.envPairs, - stdio: options.stdio, - uid: options.uid, - gid: options.gid - }); + options = normalizeSpawnArguments(file, args, options); + debug('spawn', options); + child.spawn(options); return child; }; function spawnSync(file, args, options) { - const opts = normalizeSpawnArguments(file, args, options); - - const defaults = { + options = { maxBuffer: MAX_BUFFER, - ...opts.options + ...normalizeSpawnArguments(file, args, options) }; - options = opts.options = defaults; - debug('spawnSync', opts.args, options); + debug('spawnSync', options); // Validate the timeout, if present. validateTimeout(options.timeout); @@ -569,10 +555,6 @@ function spawnSync(file, args, options) { // Validate maxBuffer, if present. validateMaxBuffer(options.maxBuffer); - options.file = opts.file; - options.args = opts.args; - options.envPairs = opts.envPairs; - // Validate and translate the kill signal, if present. options.killSignal = sanitizeKillSignal(options.killSignal); @@ -603,7 +585,7 @@ function spawnSync(file, args, options) { } } - return child_process.spawnSync(opts); + return child_process.spawnSync(options); } exports.spawnSync = spawnSync; @@ -628,15 +610,15 @@ function checkExecSyncError(ret, args, cmd) { function execFileSync(command, args, options) { - const opts = normalizeSpawnArguments(command, args, options); - const inheritStderr = !opts.options.stdio; + options = normalizeSpawnArguments(command, args, options); - const ret = spawnSync(opts.file, opts.args.slice(1), opts.options); + const inheritStderr = !options.stdio; + const ret = spawnSync(options.file, options.args.slice(1), options); if (inheritStderr && ret.stderr) process.stderr.write(ret.stderr); - const err = checkExecSyncError(ret, opts.args, undefined); + const err = checkExecSyncError(ret, options.args, undefined); if (err) throw err; |