all files / lib/ respawn.js

50% Statements 10/20
10% Branches 2/20
100% Functions 2/2
50% Lines 10/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                12× 12×                                                              
// ## respawn.js
//
// Backport of node 5+ behavior on spawn() and spawnSync() to
// 0.11.13 <= node_version < 5.
//
var spawn = require('child_process').spawn
  , spawnSync = require('child_process').spawnSync
  ;
 
 
// Node v4.x.x (LTS) and below:
//
//   1. `child_process.spawn` did not support the `shell` option, so a
//      platform-specific shell has to be manually prefixed to the command line.
//
var NODE_MAJOR = parseInt(process.version.replace(/\..+/, '').substr(1), 10);
var LEGACY_NODE = NODE_MAJOR < 5;
var IS_WINDOWS = process.platform === 'win32';
 
 
exports.spawn = function(commandLine, spawnOpt) {
  Eif (!LEGACY_NODE) {
    return spawn(commandLine, spawnOpt);
  }
 
  // If the `shell` option is not set, pass through to spawn.
  if (!spawnOpt || !spawnOpt.shell) {
    return spawn(commandLine, spawnOpt);
  }
 
  // Node 4 (LTS) and below: polyfill the `shell` option.
  var childArgs = IS_WINDOWS ?
                    ['/A', '/C', commandLine] :
                    ['-c', commandLine];
  var shellBin = IS_WINDOWS ? 'cmd.exe' : '/bin/sh';
  return spawn(shellBin, childArgs, spawnOpt);
};
 
 
exports.spawnSync = function(commandLine, spawnOpt) {
  Eif (!LEGACY_NODE) {
    return spawnSync(commandLine, spawnOpt);
  }
 
  // If the `shell` option is not set, pass through to spawn.
  if (!spawnOpt || !spawnOpt.shell) {
    return spawnSync(commandLine, spawnOpt);
  }
 
  // Node 4 (LTS) and below: polyfill the `shell` option.
  var childArgs = IS_WINDOWS ?
                    ['/A', '/C', commandLine] :
                    ['-c', commandLine];
  var shellBin = IS_WINDOWS ? 'cmd.exe' : '/bin/sh';
  return spawnSync(shellBin, childArgs, spawnOpt);
};