UNPKG

1.65 kBJavaScriptView Raw
1'use strict';
2
3var sync = require('spawn-sync');
4var crossSpawn = require('cross-spawn-async');
5var parse = require('cross-spawn-async/lib/parse');
6var enoent = require('cross-spawn-async/lib/enoent');
7var resolveCommand = require('cross-spawn-async/lib/resolveCommand');
8
9var isWin = process.platform === 'win32';
10var isNode10 = process.version.indexOf('v0.10.') === 0;
11
12function verifySyncENOENT(status, parsed) {
13 // First check against the standard enoent.verifyENOENT
14 var err = enoent.verifyENOENT(status, parsed, 'spawnSync');
15
16 if (err) {
17 return err;
18 }
19
20 // If we are in node 10, then we are using spawn-sync; if it exited
21 // with -1 it probably means that the command does not exist
22 if (isNode10 && status === -1) {
23 parsed.file = isWin ? parsed.file : resolveCommand(parsed.original);
24
25 if (!parsed.file) {
26 err = enoent.notFoundError(parsed.original, 'spawnSync');
27 }
28 }
29
30 return err;
31}
32
33function spawn(command, args, options) {
34 return crossSpawn.spawn(command, args, options);
35}
36
37function spawnSync(command, args, options) {
38 var parsed;
39 var result;
40
41 // Parse the arguments
42 parsed = parse(command, args, options);
43
44 // Spawn the child process
45 result = sync(parsed.command, parsed.args, parsed.options);
46
47 // Analyze if the command does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
48 result.error = result.error || verifySyncENOENT(result.status, parsed);
49
50 return result;
51}
52
53module.exports = spawn;
54module.exports.spawn = spawn;
55module.exports.sync = spawnSync;