cross-spawn-cb 0.6.3 → 0.6.6
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.
- package/lib/constants.js +3 -0
- package/lib/cross-spawn.js +654 -0
- package/lib/index.js +0 -1
- package/lib/polyfills.js +7 -10
- package/lib/spawn-sync.js +8 -0
- package/lib/spawnCallback.js +27 -30
- package/lib/spawnSyncCallback.js +21 -13
- package/package.json +14 -10
- package/lib/cross-spawn-3.0.1.js +0 -1660
package/lib/spawnCallback.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
require('./polyfills');
|
|
1
2
|
var once = require('once');
|
|
2
3
|
var nextTick = require('next-tick');
|
|
4
|
+
var constants = require('./constants');
|
|
3
5
|
|
|
4
|
-
var
|
|
5
|
-
var spawn = major < 8 ? require('./cross-spawn-3.0.1').spawn : require('cross-spawn').spawn;
|
|
6
|
+
var spawn = require('./cross-spawn').spawn;
|
|
6
7
|
|
|
7
8
|
module.exports = function spawnCallback(command, args, options, callback) {
|
|
8
9
|
if (typeof options === 'function') {
|
|
@@ -15,15 +16,15 @@ module.exports = function spawnCallback(command, args, options, callback) {
|
|
|
15
16
|
var cp = spawn(command, args, options);
|
|
16
17
|
|
|
17
18
|
// collect output
|
|
18
|
-
var stdout, stderr;
|
|
19
|
+
var res = { stdout: null, stderr: null };
|
|
19
20
|
if (options.encoding) {
|
|
20
21
|
if (cp.stdout) {
|
|
21
|
-
stdout = [];
|
|
22
|
-
cp.stdout.on('data', stdout.push.bind(stdout));
|
|
22
|
+
res.stdout = [];
|
|
23
|
+
cp.stdout.on('data', res.stdout.push.bind(res.stdout));
|
|
23
24
|
}
|
|
24
25
|
if (cp.stderr) {
|
|
25
|
-
stderr = [];
|
|
26
|
-
cp.stderr.on('data', stderr.push.bind(stderr));
|
|
26
|
+
res.stderr = [];
|
|
27
|
+
cp.stderr.on('data', res.stderr.push.bind(res.stderr));
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -35,34 +36,30 @@ module.exports = function spawnCallback(command, args, options, callback) {
|
|
|
35
36
|
// done
|
|
36
37
|
cp.on('close', function (status, signal) {
|
|
37
38
|
nextTick(function closeNextTick() {
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
// prepare result
|
|
40
|
+
res.pid = cp.pid;
|
|
41
|
+
res.status = status;
|
|
42
|
+
res.signal = signal;
|
|
43
|
+
if (res.stdout) {
|
|
44
|
+
res.stdout = Buffer.concat(res.stdout);
|
|
45
|
+
if (options.encoding !== 'buffer') res.stdout = res.stdout.toString(options.encoding);
|
|
46
|
+
}
|
|
47
|
+
if (res.stderr) {
|
|
48
|
+
res.stderr = Buffer.concat(res.stderr);
|
|
49
|
+
if (options.encoding !== 'buffer') res.stderr = res.stderr.toString(options.encoding);
|
|
47
50
|
}
|
|
51
|
+
res.output = [null, res.stdout, res.stderr];
|
|
48
52
|
|
|
49
53
|
// process errors
|
|
50
|
-
var err = status !== 0 ? new Error('Non-zero exit code: ' + status) : null;
|
|
51
|
-
if (stderr && stderr.length) {
|
|
54
|
+
var err = res.status !== 0 ? new Error('Non-zero exit code: ' + res.status) : null;
|
|
55
|
+
if (res.stderr && res.stderr.length) {
|
|
52
56
|
err = err || new Error('stderr has content');
|
|
53
|
-
|
|
57
|
+
for (var key in res) {
|
|
58
|
+
if (constants.spawnKeys.indexOf(key) < 0) continue;
|
|
59
|
+
err[key] = Buffer.isBuffer(res[key]) ? res[key].toString('utf8') : res[key];
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// non error result
|
|
58
|
-
callback(null, {
|
|
59
|
-
pid: cp.pid,
|
|
60
|
-
output: [null, stdout, stderr],
|
|
61
|
-
stdout: stdout,
|
|
62
|
-
stderr: stderr,
|
|
63
|
-
status: status,
|
|
64
|
-
signal: signal,
|
|
65
|
-
});
|
|
62
|
+
err ? callback(err) : callback(null, res);
|
|
66
63
|
});
|
|
67
64
|
});
|
|
68
65
|
|
package/lib/spawnSyncCallback.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var assign = require('just-extend');
|
|
2
|
+
var constants = require('./constants');
|
|
2
3
|
|
|
3
|
-
var
|
|
4
|
-
var spawnSync = major < 8 ? require('./cross-spawn-3.0.1').sync : require('cross-spawn').sync;
|
|
4
|
+
var spawnSync = require('./cross-spawn').sync;
|
|
5
5
|
|
|
6
6
|
module.exports = function spawnSyncCallback(command, args, options) {
|
|
7
7
|
options = options || {};
|
|
@@ -10,20 +10,28 @@ module.exports = function spawnSyncCallback(command, args, options) {
|
|
|
10
10
|
stdio: 'pipe',
|
|
11
11
|
encoding: 'utf8',
|
|
12
12
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
|
|
14
|
+
var res = spawnSync(command, args, syncOptions);
|
|
15
|
+
|
|
16
|
+
// pipe if inherited
|
|
17
|
+
if (res.stdout && (options.stdout === 'inherit' || options.stdio === 'inherit')) {
|
|
18
|
+
process.stdout.write(res.stdout);
|
|
19
|
+
res.stdout = null;
|
|
17
20
|
}
|
|
18
|
-
if (
|
|
19
|
-
process.stderr.write(
|
|
20
|
-
|
|
21
|
+
if (res.stderr && (options.stderr === 'inherit' || options.stdio === 'inherit')) {
|
|
22
|
+
process.stderr.write(res.stderr);
|
|
23
|
+
res.stderr = null;
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
|
|
26
|
+
// process errors
|
|
27
|
+
var err = res.status !== 0 ? new Error('Non-zero exit code: ' + res.status) : null;
|
|
28
|
+
if (res.stderr && res.stderr.length) {
|
|
24
29
|
err = err || new Error('stderr has content');
|
|
25
|
-
|
|
30
|
+
for (var key in res) {
|
|
31
|
+
if (constants.spawnKeys.indexOf(key) < 0) continue;
|
|
32
|
+
err[key] = Buffer.isBuffer(res[key]) ? res[key].toString('utf8') : res[key];
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
if (err) throw err;
|
|
28
|
-
return
|
|
36
|
+
return res;
|
|
29
37
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-spawn-cb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Cross spawn with a completion callback",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cross-spawn",
|
|
@@ -13,38 +13,42 @@
|
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"main": "lib/index.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"lib"
|
|
18
|
+
],
|
|
16
19
|
"scripts": {
|
|
20
|
+
"build": "",
|
|
21
|
+
"build:spawn": "rollup -c config/rollup.cs.config.js",
|
|
17
22
|
"format": "prettier --write .",
|
|
18
23
|
"lint": "eslint .",
|
|
19
24
|
"prepublishOnly": "npm run lint && depcheck",
|
|
20
25
|
"test": "mocha-compat test/spec/**/*.test.js",
|
|
21
|
-
"
|
|
26
|
+
"test:engines": "nvu engines npm test"
|
|
22
27
|
},
|
|
23
|
-
"files": [
|
|
24
|
-
"lib"
|
|
25
|
-
],
|
|
26
28
|
"dependencies": {
|
|
29
|
+
"buffer-v6-polyfill": "^1.0.5",
|
|
30
|
+
"core-js": "^3.24.0",
|
|
27
31
|
"cross-spawn": "^7.0.3",
|
|
28
|
-
"function-exec-sync": "^0.2.
|
|
32
|
+
"function-exec-sync": "^0.2.4",
|
|
29
33
|
"just-extend": "^6.0.1",
|
|
30
34
|
"next-tick": "^1.1.0",
|
|
31
35
|
"once": "^1.4.0"
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|
|
34
|
-
"@babel/preset-env": "^7.18.
|
|
38
|
+
"@babel/preset-env": "^7.18.9",
|
|
35
39
|
"@rollup/plugin-babel": "^5.3.1",
|
|
36
40
|
"@rollup/plugin-commonjs": "^22.0.1",
|
|
37
41
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
38
|
-
"@typescript-eslint/parser": "^5.30.
|
|
42
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
39
43
|
"depcheck": "^1.4.3",
|
|
40
|
-
"eslint": "^8.
|
|
44
|
+
"eslint": "^8.20.0",
|
|
41
45
|
"eslint-config-prettier": "^8.5.0",
|
|
42
46
|
"eslint-config-standard": "^17.0.0",
|
|
43
47
|
"eslint-plugin-import": "^2.26.0",
|
|
44
48
|
"eslint-plugin-promise": "^6.0.0",
|
|
45
49
|
"mocha-compat": "^3.5.5",
|
|
46
50
|
"prettier": "^2.7.1",
|
|
47
|
-
"rollup": "^2.
|
|
51
|
+
"rollup": "^2.77.0",
|
|
48
52
|
"rollup-plugin-babel": "^4.4.0",
|
|
49
53
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
50
54
|
"rollup-plugin-node-externals": "^4.1.1"
|