From f3fb3376cb9cc12cf9f02d559c326e30899757f1 Mon Sep 17 00:00:00 2001 From: Charles Samborski Date: Sun, 12 Aug 2018 10:28:31 +0200 Subject: [PATCH] fix: Remove legacy `spawnSync` feature detection This commit removes the checks used to detect and use `spawnSync` in Node <= 0.10. `spawnSync` is exposed since Node 0.11. --- index.js | 20 +++++--------------- shim.js | 1 - 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 4a2d8d8..b922e2b 100644 --- a/index.js +++ b/index.js @@ -41,11 +41,7 @@ const pathRe = isWindows ? /^PATH=/i : /^PATH=/ const colon = isWindows ? ';' : ':' function wrap (argv, env, workingDir) { - // spawn_sync available since Node v0.11 - let spawnSyncBinding, spawnSync - try { - spawnSyncBinding = process.binding('spawn_sync') - } catch (e) {} + const spawnSyncBinding = process.binding('spawn_sync') // if we're passed in the working dir, then it means that setup // was already done, so no need. @@ -54,23 +50,17 @@ function wrap (argv, env, workingDir) { workingDir = setup(argv, env) } const spawn = ChildProcess.prototype.spawn - if (spawnSyncBinding) { - spawnSync = spawnSyncBinding.spawn - } + const spawnSync = spawnSyncBinding.spawn - function unwrap () { + function unwrap() { if (doSetup && !doDebug) { rimraf.sync(workingDir) } ChildProcess.prototype.spawn = spawn - if (spawnSyncBinding) { - spawnSyncBinding.spawn = spawnSync - } + spawnSyncBinding.spawn = spawnSync } - if (spawnSyncBinding) { - spawnSyncBinding.spawn = wrappedSpawnFunction(spawnSync, workingDir) - } + spawnSyncBinding.spawn = wrappedSpawnFunction(spawnSync, workingDir) ChildProcess.prototype.spawn = wrappedSpawnFunction(spawn, workingDir) return unwrap diff --git a/shim.js b/shim.js index 2656e9f..afe5d75 100644 --- a/shim.js +++ b/shim.js @@ -134,7 +134,6 @@ const pexec = process.execArgv if (JSON.stringify(pexec) !== JSON.stringify(needExecArgv)) { debug('need execArgv for this', pexec, '=>', needExecArgv) - const spawn = require('child_process').spawn const sargs = pexec.concat(needExecArgv).concat(process.argv.slice(1)) foregroundChild(node, sargs) return