"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/utils/spawn.js" (7 Feb 2017, 1410 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module.exports = spawn
    2 
    3 var _spawn = require('child_process').spawn
    4 var EventEmitter = require('events').EventEmitter
    5 var npwr = require('./no-progress-while-running.js')
    6 
    7 function willCmdOutput (stdio) {
    8   if (stdio === 'inherit') return true
    9   if (!Array.isArray(stdio)) return false
   10   for (var fh = 1; fh <= 2; ++fh) {
   11     if (stdio[fh] === 'inherit') return true
   12     if (stdio[fh] === 1 || stdio[fh] === 2) return true
   13   }
   14   return false
   15 }
   16 
   17 function spawn (cmd, args, options) {
   18   var cmdWillOutput = willCmdOutput(options && options.stdio)
   19 
   20   if (cmdWillOutput) npwr.startRunning()
   21   var raw = _spawn(cmd, args, options)
   22   var cooked = new EventEmitter()
   23 
   24   raw.on('error', function (er) {
   25     if (cmdWillOutput) npwr.stopRunning()
   26     er.file = cmd
   27     cooked.emit('error', er)
   28   }).on('close', function (code, signal) {
   29     if (cmdWillOutput) npwr.stopRunning()
   30     // Create ENOENT error because Node.js v0.8 will not emit
   31     // an `error` event if the command could not be found.
   32     if (code === 127) {
   33       var er = new Error('spawn ENOENT')
   34       er.code = 'ENOENT'
   35       er.errno = 'ENOENT'
   36       er.syscall = 'spawn'
   37       er.file = cmd
   38       cooked.emit('error', er)
   39     } else {
   40       cooked.emit('close', code, signal)
   41     }
   42   })
   43 
   44   cooked.stdin = raw.stdin
   45   cooked.stdout = raw.stdout
   46   cooked.stderr = raw.stderr
   47   cooked.kill = function (sig) { return raw.kill(sig) }
   48 
   49   return cooked
   50 }