cross-spawn-cb 0.6.13 → 0.6.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +0,0 @@
1
- require('./polyfills');
2
- var once = require('once');
3
- var nextTick = require('next-tick');
4
- var constants = require('./constants');
5
-
6
- var major = +process.versions.node.split('.')[0];
7
- var spawn = major <= 7 ? require('./cross-spawn-6.0.5').spawn : require('cross-spawn').spawn;
8
-
9
- module.exports = function spawnCallback(command, args, options, callback) {
10
- if (typeof options === 'function') {
11
- callback = options;
12
- options = {};
13
- }
14
- options = options || {};
15
- callback = once(callback);
16
-
17
- var cp = spawn(command, args, options);
18
-
19
- // collect output
20
- var res = { stdout: null, stderr: null };
21
- if (options.encoding) {
22
- if (cp.stdout) {
23
- res.stdout = [];
24
- cp.stdout.on('data', res.stdout.push.bind(res.stdout));
25
- }
26
- if (cp.stderr) {
27
- res.stderr = [];
28
- cp.stderr.on('data', res.stderr.push.bind(res.stderr));
29
- }
30
- }
31
-
32
- // some versions of node emit both an error and close
33
- cp.on('error', function error(err) {
34
- err.code === 'OK' || callback(err);
35
- });
36
-
37
- // done
38
- cp.on('close', function (status, signal) {
39
- nextTick(function closeNextTick() {
40
- // prepare result
41
- res.pid = cp.pid;
42
- res.status = status;
43
- res.signal = signal;
44
- if (res.stdout) {
45
- res.stdout = Buffer.concat(res.stdout);
46
- if (options.encoding !== 'buffer') res.stdout = res.stdout.toString(options.encoding);
47
- }
48
- if (res.stderr) {
49
- res.stderr = Buffer.concat(res.stderr);
50
- if (options.encoding !== 'buffer') res.stderr = res.stderr.toString(options.encoding);
51
- }
52
- res.output = [null, res.stdout, res.stderr];
53
-
54
- // patch: early node on windows could return null
55
- if (res.status === null) console.log('spawnCallback null status code', res);
56
- // res.status = res.status === null ? 0 : res.status;
57
-
58
- // process errors
59
- var err = res.status !== 0 ? new Error('Non-zero exit code: ' + res.status) : null;
60
- if (res.stderr && res.stderr.length) {
61
- err = err || new Error('stderr has content');
62
- for (var key in res) {
63
- if (constants.spawnKeys.indexOf(key) < 0) continue;
64
- err[key] = Buffer.isBuffer(res[key]) ? res[key].toString('utf8') : res[key];
65
- }
66
- }
67
- err ? callback(err) : callback(null, res);
68
- });
69
- });
70
-
71
- // pipe input
72
- if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {
73
- cp.stdin.end(options.input);
74
- }
75
- };
@@ -1,41 +0,0 @@
1
- var constants = require('./constants');
2
-
3
- var major = +process.versions.node.split('.')[0];
4
- var spawnSync = major <= 7 ? require('./cross-spawn-6.0.5').sync : require('cross-spawn').sync;
5
-
6
- module.exports = function spawnSyncCallback(command, args, options) {
7
- options = options || {};
8
- var syncOptions = Object.assign({}, options || {}, {
9
- env: options.env || process.env,
10
- stdio: 'pipe',
11
- encoding: 'utf8',
12
- });
13
-
14
- var res = spawnSync(command, args, syncOptions);
15
-
16
- // patch: early node on windows could return null
17
- if (res.status === null) console.log('spawnSyncCallback null status code', res);
18
- // res.status = res.status === null ? 0 : res.status;
19
-
20
- // pipe if inherited
21
- if (res.stdout && (options.stdout === 'inherit' || options.stdio === 'inherit')) {
22
- process.stdout.write(res.stdout);
23
- res.stdout = null;
24
- }
25
- if (res.stderr && (options.stderr === 'inherit' || options.stdio === 'inherit')) {
26
- process.stderr.write(res.stderr);
27
- res.stderr = null;
28
- }
29
-
30
- // process errors
31
- var err = res.status !== 0 ? new Error('Non-zero exit code: ' + res.status) : null;
32
- if (res.stderr && res.stderr.length) {
33
- err = err || new Error('stderr has content');
34
- for (var key in res) {
35
- if (constants.spawnKeys.indexOf(key) < 0) continue;
36
- err[key] = Buffer.isBuffer(res[key]) ? res[key].toString('utf8') : res[key];
37
- }
38
- }
39
- if (err) throw err;
40
- return res;
41
- };