cross-spawn-cb 0.5.14 → 0.6.2

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,38 +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
32
- if (stdout) stdout = Buffer.concat(stdout);
33
- if (stderr) stderr = Buffer.concat(stderr);
34
- if ((options.encoding && options.encoding !== 'buffer') || options.stdio === 'string') {
35
- stdout = stdout.toString(options.encoding);
36
- stderr = stderr.toString(options.encoding);
37
- } else if (options.stdout === 'string') {
38
- stdout = stdout.toString(options.encoding);
39
- } else if (options.stderr === 'string') {
40
- stderr = stderr.toString(options.encoding);
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
+ }
41
47
  }
42
48
 
43
49
  // process errors
44
50
  var err = status !== 0 ? new Error('Non-zero exit code: ' + status) : null;
45
51
  if (stderr && stderr.length) {
46
52
  err = err || new Error('stderr has content');
47
- err.stderr = stderr;
53
+ err.stderr = Buffer.isBuffer(stderr) ? stderr.toString('utf8') : stderr;
48
54
  }
49
55
  if (err) return callback(err);
50
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-spawn-cb",
3
- "version": "0.5.14",
3
+ "version": "0.6.2",
4
4
  "description": "Cross spawn with a completion callback",
5
5
  "keywords": [
6
6
  "cross-spawn",