cross-spawn-cb 0.5.15 → 0.6.3

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.
@@ -13,41 +13,44 @@ module.exports = function spawnCallback(command, args, options, callback) {
13
13
  callback = once(callback);
14
14
 
15
15
  var cp = spawn(command, args, options);
16
+
17
+ // collect output
16
18
  var stdout, stderr;
17
- if (cp.stdout) {
18
- stdout = [];
19
- cp.stdout.on('data', stdout.push.bind(stdout));
20
- }
21
- if (cp.stderr) {
22
- stderr = [];
23
- cp.stderr.on('data', stderr.push.bind(stderr));
19
+ if (options.encoding) {
20
+ if (cp.stdout) {
21
+ stdout = [];
22
+ cp.stdout.on('data', stdout.push.bind(stdout));
23
+ }
24
+ if (cp.stderr) {
25
+ stderr = [];
26
+ cp.stderr.on('data', stderr.push.bind(stderr));
27
+ }
24
28
  }
29
+
30
+ // some versions of node emit both an error and close
25
31
  cp.on('error', function error(err) {
26
- // some versions of node emit both an error and close
27
32
  err.code === 'OK' || callback(err);
28
33
  });
34
+
35
+ // done
29
36
  cp.on('close', function (status, signal) {
30
37
  nextTick(function closeNextTick() {
31
- // format results - buffer
32
- if (stdout) stdout = Buffer.concat(stdout);
33
- if (stderr) stderr = Buffer.concat(stderr);
38
+ // process output
39
+ if (options.encoding) {
40
+ if (stdout) stdout = Buffer.concat(stdout);
41
+ if (stderr) stderr = Buffer.concat(stderr);
34
42
 
35
- // format results - string
36
- var encoding = options.encoding === 'buffer' ? 'utf8' : options.encoding || 'utf8';
37
- if ((options.encoding && options.encoding !== 'buffer') || options.stdio === 'string') {
38
- stdout = stdout.toString(encoding);
39
- stderr = stderr.toString(encoding);
40
- } else if (options.stdout === 'string') {
41
- stdout = stdout.toString(encoding);
42
- } else if (options.stderr === 'string') {
43
- stderr = stderr.toString(encoding);
43
+ if (options.encoding !== 'buffer') {
44
+ if (stdout) stdout = stdout.toString(options.encoding);
45
+ if (stderr) stderr = stderr.toString(options.encoding);
46
+ }
44
47
  }
45
48
 
46
49
  // process errors
47
50
  var err = status !== 0 ? new Error('Non-zero exit code: ' + status) : null;
48
51
  if (stderr && stderr.length) {
49
52
  err = err || new Error('stderr has content');
50
- err.stderr = stderr;
53
+ err.stderr = Buffer.isBuffer(stderr) ? stderr.toString('utf8') : stderr;
51
54
  }
52
55
  if (err) return callback(err);
53
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-spawn-cb",
3
- "version": "0.5.15",
3
+ "version": "0.6.3",
4
4
  "description": "Cross spawn with a completion callback",
5
5
  "keywords": [
6
6
  "cross-spawn",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "format": "prettier --write .",
18
18
  "lint": "eslint .",
19
- "prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
19
+ "prepublishOnly": "npm run lint && depcheck",
20
20
  "test": "mocha-compat test/spec/**/*.test.js",
21
21
  "build": "rollup -c config/rollup.cs.config.js"
22
22
  },
@@ -37,7 +37,6 @@
37
37
  "@rollup/plugin-node-resolve": "^13.3.0",
38
38
  "@typescript-eslint/parser": "^5.30.6",
39
39
  "depcheck": "^1.4.3",
40
- "dis-dat": "^0.1.7",
41
40
  "eslint": "^8.19.0",
42
41
  "eslint-config-prettier": "^8.5.0",
43
42
  "eslint-config-standard": "^17.0.0",