cross-spawn-cb 0.6.2 → 0.6.5

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/index.js CHANGED
@@ -1,4 +1,18 @@
1
1
  require('./polyfills');
2
+
3
+ // exclude from polyfils to avoid loading in functionExec
4
+ var cp = require('child_process');
5
+ if (!cp.spawnSync) {
6
+ var path = require('path')
7
+ var functionExec = require('function-exec-sync');
8
+
9
+ cp.spawnSync = function spawnSync(command, args, options) {
10
+ options = options || {};
11
+ var filePath = path.resolve(__dirname, 'spawnCallback.js');
12
+ return functionExec({ callbacks: true }, filePath, command, args, options);
13
+ };
14
+ }
15
+
2
16
  module.exports = require('./spawnCallback');
3
17
  module.exports.spawn = require('./spawnCallback');
4
18
  module.exports.sync = require('./spawnSyncCallback');
package/lib/polyfills.js CHANGED
@@ -1,13 +1,4 @@
1
+ require('core-js/actual/object/assign');
2
+
1
3
  var path = require('path');
2
4
  if (typeof path.delimiter === 'undefined') path.delimiter = process.platform === 'win32' ? ';' : ':';
3
-
4
- var cp = require('child_process');
5
- if (!cp.spawnSync) {
6
- var functionExec = require('function-exec-sync');
7
-
8
- cp.spawnSync = function spawnSync(command, args, options) {
9
- options = options || {};
10
- var filePath = path.resolve(__dirname, 'spawnCallback.js');
11
- return functionExec({ callbacks: true }, filePath, command, args, options);
12
- };
13
- }
@@ -1,3 +1,4 @@
1
+ require('./polyfills');
1
2
  var once = require('once');
2
3
  var nextTick = require('next-tick');
3
4
 
@@ -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,29 @@ 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
- // process output
39
- if (options.encoding) {
40
- stdout = Buffer.concat(stdout);
41
- stderr = Buffer.concat(stderr);
42
-
43
- if (options.encoding !== 'buffer') {
44
- stdout = stdout.toString(options.encoding);
45
- stderr = stderr.toString(options.encoding);
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
- err.stderr = Buffer.isBuffer(stderr) ? stderr.toString('utf8') : stderr;
57
+ for (var key in res) {
58
+ err[key] = Buffer.isBuffer(res[key]) ? res[key].toString('utf8') : res[key];
59
+ }
54
60
  }
55
- if (err) return callback(err);
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
- });
61
+ err ? callback(err) : callback(null, res);
66
62
  });
67
63
  });
68
64
 
@@ -10,20 +10,27 @@ module.exports = function spawnSyncCallback(command, args, options) {
10
10
  stdio: 'pipe',
11
11
  encoding: 'utf8',
12
12
  });
13
- var result = spawnSync(command, args, syncOptions);
14
- if (result.stdout && (options.stdout === 'inherit' || options.stdio === 'inherit')) {
15
- process.stdout.write(result.stdout);
16
- result.stdout = null;
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 (result.stderr && (options.stderr === 'inherit' || options.stdio === 'inherit')) {
19
- process.stderr.write(result.stderr);
20
- result.stderr = null;
21
+ if (res.stderr && (options.stderr === 'inherit' || options.stdio === 'inherit')) {
22
+ process.stderr.write(res.stderr);
23
+ res.stderr = null;
21
24
  }
22
- var err = result.status ? new Error('Non-zero exit code: ' + result.status) : null;
23
- if (result.stderr && result.stderr.length) {
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
- err.stderr = result.stderr;
30
+ for (var key in res) {
31
+ err[key] = Buffer.isBuffer(res[key]) ? res[key].toString('utf8') : res[key];
32
+ }
26
33
  }
27
34
  if (err) throw err;
28
- return result;
35
+ return res;
29
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-spawn-cb",
3
- "version": "0.6.2",
3
+ "version": "0.6.5",
4
4
  "description": "Cross spawn with a completion callback",
5
5
  "keywords": [
6
6
  "cross-spawn",
@@ -14,9 +14,10 @@
14
14
  "license": "MIT",
15
15
  "main": "lib/index.js",
16
16
  "scripts": {
17
+ "test:engines": "nvu engines npm test",
17
18
  "format": "prettier --write .",
18
19
  "lint": "eslint .",
19
- "prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
20
+ "prepublishOnly": "npm run lint && depcheck",
20
21
  "test": "mocha-compat test/spec/**/*.test.js",
21
22
  "build": "rollup -c config/rollup.cs.config.js"
22
23
  },
@@ -24,28 +25,28 @@
24
25
  "lib"
25
26
  ],
26
27
  "dependencies": {
28
+ "core-js": "^3.23.5",
27
29
  "cross-spawn": "^7.0.3",
28
- "function-exec-sync": "^0.2.1",
30
+ "function-exec-sync": "^0.2.4",
29
31
  "just-extend": "^6.0.1",
30
32
  "next-tick": "^1.1.0",
31
33
  "once": "^1.4.0"
32
34
  },
33
35
  "devDependencies": {
34
- "@babel/preset-env": "^7.18.6",
36
+ "@babel/preset-env": "^7.18.9",
35
37
  "@rollup/plugin-babel": "^5.3.1",
36
38
  "@rollup/plugin-commonjs": "^22.0.1",
37
39
  "@rollup/plugin-node-resolve": "^13.3.0",
38
- "@typescript-eslint/parser": "^5.30.6",
40
+ "@typescript-eslint/parser": "^5.30.7",
39
41
  "depcheck": "^1.4.3",
40
- "dis-dat": "^0.1.7",
41
- "eslint": "^8.19.0",
42
+ "eslint": "^8.20.0",
42
43
  "eslint-config-prettier": "^8.5.0",
43
44
  "eslint-config-standard": "^17.0.0",
44
45
  "eslint-plugin-import": "^2.26.0",
45
46
  "eslint-plugin-promise": "^6.0.0",
46
47
  "mocha-compat": "^3.5.5",
47
48
  "prettier": "^2.7.1",
48
- "rollup": "^2.76.0",
49
+ "rollup": "^2.77.0",
49
50
  "rollup-plugin-babel": "^4.4.0",
50
51
  "rollup-plugin-commonjs": "^10.1.0",
51
52
  "rollup-plugin-node-externals": "^4.1.1"