1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
const cp = require('child_process');
|
4 |
|
|
const parse = require('./lib/parse');
|
5 |
|
|
const enoent = require('./lib/enoent');
|
6 |
|
|
|
7 |
|
|
function spawn(command, args, options) {
|
8 |
|
|
// Parse the arguments
|
9 |
|
|
const parsed = parse(command, args, options);
|
10 |
|
|
|
11 |
|
|
// Spawn the child process
|
12 |
|
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
13 |
|
|
|
14 |
|
|
// Hook into child process "exit" event to emit an error if the command
|
15 |
|
|
// does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
16 |
|
|
enoent.hookChildProcess(spawned, parsed);
|
17 |
|
|
|
18 |
|
|
return spawned;
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
function spawnSync(command, args, options) {
|
22 |
|
|
// Parse the arguments
|
23 |
|
|
const parsed = parse(command, args, options);
|
24 |
|
|
|
25 |
|
|
// Spawn the child process
|
26 |
|
|
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
27 |
|
|
|
28 |
|
|
// Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
29 |
|
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
30 |
|
|
|
31 |
|
|
return result;
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
module.exports = spawn;
|
35 |
|
|
module.exports.spawn = spawn;
|
36 |
|
|
module.exports.sync = spawnSync;
|
37 |
|
|
|
38 |
|
|
module.exports._parse = parse;
|
39 |
|
|
module.exports._enoent = enoent;
|