Code coverage report for index.js

Statements: 71.43% (20 / 28)      Branches: 64.29% (9 / 14)      Functions: 83.33% (5 / 6)      Lines: 71.43% (20 / 28)      Ignored: none     

All files » __root__/ » index.js
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 4820 20   20   11       11       11         11 6     11   11 11 11     11 9 9 9           3 3   6       11    
var signalExit = require('signal-exit')
var spawn = require('child_process').spawn
 
module.exports = function (program, args, cb) {
 
  Iif (Array.isArray(program)) {
    cb = args
    args = program.slice(1)
    program = program[0]
  } else Iif (!Array.isArray(args)) {
    args = [].slice.call(arguments, 1)
    if (typeof args[args.length - 1] === 'function')
      cb = args.pop()
  } else Iif (typeof args === 'function') {
    cb = args
    args = []
  }
 
  cb = cb || function (done) {
    return done()
  }
 
  var child = spawn(program, args, { stdio: 'inherit' })
 
  var childExited = false
  signalExit(function (code, signal) {
    child.kill(signal || 'SIGHUP')
  })
 
  child.on('close', function (code, signal) {
    cb(function () {
      childExited = true
      if (signal) {
        // If there is nothing else keeping the event loop alive,
        // then there's a race between a graceful exit and getting
        // the signal to this process.  Put this timeout here to
        // make sure we're still alive to get the signal, and thus
        // exit with the intended signal code.
        setTimeout(function () {}, 200)
        process.kill(process.pid, signal)
      } else
        process.exit(code)
    })
  })
 
  return child
}