buffered-node-process.js
1 const BufferedProcess = require('./buffered-process'); 2 3 // Extended: Like {BufferedProcess}, but accepts a Node script as the command 4 // to run. 5 // 6 // This is necessary on Windows since it doesn't support shebang `#!` lines. 7 // 8 // ## Examples 9 // 10 // ```js 11 // const {BufferedNodeProcess} = require('atom') 12 // ``` 13 module.exports = class BufferedNodeProcess extends BufferedProcess { 14 // Public: Runs the given Node script by spawning a new child process. 15 // 16 // * `options` An {Object} with the following keys: 17 // * `command` The {String} path to the JavaScript script to execute. 18 // * `args` The {Array} of arguments to pass to the script (optional). 19 // * `options` The options {Object} to pass to Node's `ChildProcess.spawn` 20 // method (optional). 21 // * `stdout` The callback {Function} that receives a single argument which 22 // contains the standard output from the command. The callback is 23 // called as data is received but it's buffered to ensure only 24 // complete lines are passed until the source stream closes. After 25 // the source stream has closed all remaining data is sent in a 26 // final call (optional). 27 // * `stderr` The callback {Function} that receives a single argument which 28 // contains the standard error output from the command. The 29 // callback is called as data is received but it's buffered to 30 // ensure only complete lines are passed until the source stream 31 // closes. After the source stream has closed all remaining data 32 // is sent in a final call (optional). 33 // * `exit` The callback {Function} which receives a single argument 34 // containing the exit status (optional). 35 constructor({ command, args, options = {}, stdout, stderr, exit }) { 36 options.env = options.env || Object.create(process.env); 37 options.env.ELECTRON_RUN_AS_NODE = 1; 38 options.env.ELECTRON_NO_ATTACH_CONSOLE = 1; 39 40 args = args ? args.slice() : []; 41 args.unshift(command); 42 args.unshift('--no-deprecation'); 43 44 super({ 45 command: process.execPath, 46 args, 47 options, 48 stdout, 49 stderr, 50 exit 51 }); 52 } 53 };