cross-spawn-cb 2.1.13 → 2.1.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.
@@ -8,20 +8,22 @@ Object.defineProperty(exports, "default", {
8
8
  return worker;
9
9
  }
10
10
  });
11
- var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
11
+ var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
12
12
  var _constants = require("../constants.cjs");
13
13
  function _interop_require_default(obj) {
14
14
  return obj && obj.__esModule ? obj : {
15
15
  default: obj
16
16
  };
17
17
  }
18
+ function isError(obj) {
19
+ return Object.prototype.toString.call(obj) === '[object Error]';
20
+ }
18
21
  function worker(cp, options, callback) {
19
22
  if (typeof options === 'function') {
20
23
  callback = options;
21
24
  options = {};
22
25
  }
23
26
  options = options || {};
24
- callback = (0, _calloncefn.default)(callback); // some versions of node emit both an error and close
25
27
  // collect output
26
28
  var res = {
27
29
  pid: 0,
@@ -35,39 +37,43 @@ function worker(cp, options, callback) {
35
37
  var stderr = [];
36
38
  if (options.encoding && cp.stdout) cp.stdout.on('data', stdout.push.bind(stdout));
37
39
  if (options.encoding && cp.stderr) cp.stderr.on('data', stderr.push.bind(stderr));
38
- cp.on('error', function(err) {
39
- return err.code === 'OK' || callback(err);
40
- });
41
- cp.on('close', function(status, signal) {
42
- setTimeout(function close() {
43
- // prepare result
44
- res.pid = cp.pid;
45
- res.status = status;
46
- res.signal = signal;
47
- if (options.encoding && cp.stdout) {
48
- res.stdout = Buffer.concat(stdout);
49
- if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);
50
- }
51
- if (options.encoding && cp.stderr) {
52
- res.stderr = Buffer.concat(stderr);
53
- if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);
54
- }
55
- res.output = [
56
- null,
57
- res.stdout,
58
- res.stderr
59
- ];
60
- if (res.status === null) res.status = 0; // patch: early node on windows could return null
61
- // process errors
62
- var err = res.status !== 0 ? new Error("Non-zero exit code: ".concat(res.status)) : null;
63
- if (err) {
64
- for(var key in res){
65
- if (_constants.spawnKeys.indexOf(key) < 0) continue;
66
- err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];
67
- }
40
+ // some versions of node emit both an error and close
41
+ (0, _onone.default)(cp, [
42
+ 'error',
43
+ 'close'
44
+ ], function(status, signal) {
45
+ if (isError(status)) {
46
+ var err = status;
47
+ if (err.code === 'OK') return; // ignore
48
+ return callback(err);
49
+ }
50
+ // prepare result
51
+ res.pid = cp.pid;
52
+ res.status = status;
53
+ res.signal = signal;
54
+ if (options.encoding && cp.stdout) {
55
+ res.stdout = Buffer.concat(stdout);
56
+ if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);
57
+ }
58
+ if (options.encoding && cp.stderr) {
59
+ res.stderr = Buffer.concat(stderr);
60
+ if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);
61
+ }
62
+ res.output = [
63
+ null,
64
+ res.stdout,
65
+ res.stderr
66
+ ];
67
+ if (res.status === null) res.status = 0; // patch: early node on windows could return null
68
+ // process errors
69
+ var err1 = res.status !== 0 ? new Error("Non-zero exit code: ".concat(res.status)) : null;
70
+ if (err1) {
71
+ for(var key in res){
72
+ if (_constants.spawnKeys.indexOf(key) < 0) continue;
73
+ err1[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];
68
74
  }
69
- err ? callback(err) : callback(null, res);
70
- }, 0);
75
+ }
76
+ err1 ? callback(err1) : callback(null, res);
71
77
  });
72
78
  // pipe input
73
79
  if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/compat/cross-spawn-cb/src/workers/async.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { spawnKeys } from '../constants';\n\nimport type { ChildProcess, SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from '../types';\n\nexport default function worker(cp: ChildProcess, options?: SpawnOptions | SpawnCallback, callback?: SpawnCallback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n callback = once(callback); // some versions of node emit both an error and close\n\n // collect output\n const res = { pid: 0, output: [], stdout: null, stderr: null, status: null, signal: null } as SpawnResult;\n const stdout: Buffer[] = [];\n const stderr: Buffer[] = [];\n if (options.encoding && cp.stdout) cp.stdout.on('data', stdout.push.bind(stdout));\n if (options.encoding && cp.stderr) cp.stderr.on('data', stderr.push.bind(stderr));\n\n cp.on('error', (err: SpawnError) => err.code === 'OK' || callback(err));\n cp.on('close', (status, signal) => {\n setTimeout(function close() {\n // prepare result\n res.pid = cp.pid;\n res.status = status;\n res.signal = signal;\n if (options.encoding && cp.stdout) {\n res.stdout = Buffer.concat(stdout);\n if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);\n }\n if (options.encoding && cp.stderr) {\n res.stderr = Buffer.concat(stderr);\n if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);\n }\n res.output = [null, res.stdout, res.stderr];\n if (res.status === null) res.status = 0; // patch: early node on windows could return null\n\n // process errors\n const err = res.status !== 0 ? new Error(`Non-zero exit code: ${res.status}`) : null;\n if (err) {\n for (const key in res) {\n if (spawnKeys.indexOf(key) < 0) continue;\n err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];\n }\n }\n err ? callback(err) : callback(null, res);\n }, 0);\n });\n\n // pipe input\n if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {\n cp.stdin.end(options.input);\n }\n}\n"],"names":["worker","cp","options","callback","once","res","pid","output","stdout","stderr","status","signal","encoding","on","push","bind","err","code","setTimeout","close","Buffer","concat","toString","Error","key","spawnKeys","indexOf","isBuffer","input","stdin","end"],"mappings":";;;;+BAKA;;;eAAwBA;;;iEALP;yBACS;;;;;;AAIX,SAASA,OAAOC,EAAgB,EAAEC,OAAsC,EAAEC,QAAwB;I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AM,CAACa,QAAQ,CAACpB,QAAQU,QAAQ;YACtF;YACAP,IAAIE,MAAM,GAAG;gBAAC;gBAAMF,IAAIG,MAAM;gBAAEH,IAAII,MAAM;aAAC;YAC3C,IAAIJ,IAAIK,MAAM,KAAK,MAAML,IAAIK,MAAM,GAAG,GAAG,iDAAiD;YAE1F,iBAAiB;YACjB,IAAMM,MAAMX,IAAIK,MAAM,KAAK,IAAI,IAAIa,MAAM,AAAC,uBAAiC,OAAXlB,IAAIK,MAAM,KAAM;YAChF,IAAIM,KAAK;gBACP,IAAK,IAAMQ,OAAOnB,IAAK;oBACrB,IAAIoB,oBAAS,CAACC,OAAO,CAACF,OAAO,GAAG;oBAChCR,GAAG,CAACQ,IAAI,GAAGJ,OAAOO,QAAQ,CAACtB,GAAG,CAACmB,IAAI,IAAInB,GAAG,CAACmB,IAAI,CAACF,QAAQ,CAACpB,QAAQU,QAAQ,IAAI,UAAUP,GAAG,CAACmB,IAAI;gBACjG;YACF;YACAR,MAAMb,SAASa,OAAOb,SAAS,MAAME;QACvC,GAAG;IACL;IAEA,aAAa;IACb,IAAIH,QAAQ0B,KAAK,IAAK,CAAA,OAAO1B,QAAQ0B,KAAK,KAAK,YAAYR,OAAOO,QAAQ,CAACzB,QAAQ0B,KAAK,CAAA,GAAI;QAC1F3B,GAAG4B,KAAK,CAACC,GAAG,CAAC5B,QAAQ0B,KAAK;IAC5B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/compat/cross-spawn-cb/src/workers/async.ts"],"sourcesContent":["import oo from 'on-one';\nimport { spawnKeys } from '../constants';\n\nimport type { ChildProcess, SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from '../types';\n\nfunction isError(obj) {\n return Object.prototype.toString.call(obj) === '[object Error]';\n}\n\nexport default function worker(cp: ChildProcess, options?: SpawnOptions | SpawnCallback, callback?: SpawnCallback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n // collect output\n const res = { pid: 0, output: [], stdout: null, stderr: null, status: null, signal: null } as SpawnResult;\n const stdout: Buffer[] = [];\n const stderr: Buffer[] = [];\n if (options.encoding && cp.stdout) cp.stdout.on('data', stdout.push.bind(stdout));\n if (options.encoding && cp.stderr) cp.stderr.on('data', stderr.push.bind(stderr));\n\n // some versions of node emit both an error and close\n oo(cp, ['error', 'close'], (status, signal) => {\n if (isError(status)) {\n const err = status as SpawnError;\n if (err.code === 'OK') return; // ignore\n return callback(err);\n }\n\n // prepare result\n res.pid = cp.pid;\n res.status = status;\n res.signal = signal;\n if (options.encoding && cp.stdout) {\n res.stdout = Buffer.concat(stdout);\n if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);\n }\n if (options.encoding && cp.stderr) {\n res.stderr = Buffer.concat(stderr);\n if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);\n }\n res.output = [null, res.stdout, res.stderr];\n if (res.status === null) res.status = 0; // patch: early node on windows could return null\n\n // process errors\n const err = res.status !== 0 ? new Error(`Non-zero exit code: ${res.status}`) : null;\n if (err) {\n for (const key in res) {\n if (spawnKeys.indexOf(key) < 0) continue;\n err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];\n }\n }\n err ? callback(err) : callback(null, res);\n });\n\n // pipe input\n if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {\n cp.stdin.end(options.input);\n }\n}\n"],"names":["worker","isError","obj","Object","prototype","toString","call","cp","options","callback","res","pid","output","stdout","stderr","status","signal","encoding","on","push","bind","oo","err","code","Buffer","concat","Error","key","spawnKeys","indexOf","isBuffer","input","stdin","end"],"mappings":";;;;+BASA;;;eAAwBA;;;4DATT;yBACW;;;;;;AAI1B,SAASC,QAAQC,GAAG;IAClB,OAAOC,OAAOC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACJ,SAAS;AACjD;AAEe,SAASF,OAAOO,EAAgB,EAAEC,OAAsC,EAAEC,QAAwB;IAC/G,IAAI,OAAOD,YA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AAQ,CAACG,QAAQS,QAAQ;QACtF;QACAP,IAAIE,MAAM,GAAG;YAAC;YAAMF,IAAIG,MAAM;YAAEH,IAAII,MAAM;SAAC;QAC3C,IAAIJ,IAAIK,MAAM,KAAK,MAAML,IAAIK,MAAM,GAAG,GAAG,iDAAiD;QAE1F,iBAAiB;QACjB,IAAMO,OAAMZ,IAAIK,MAAM,KAAK,IAAI,IAAIW,MAAM,AAAC,uBAAiC,OAAXhB,IAAIK,MAAM,KAAM;QAChF,IAAIO,MAAK;YACP,IAAK,IAAMK,OAAOjB,IAAK;gBACrB,IAAIkB,oBAAS,CAACC,OAAO,CAACF,OAAO,GAAG;gBAChCL,IAAG,CAACK,IAAI,GAAGH,OAAOM,QAAQ,CAACpB,GAAG,CAACiB,IAAI,IAAIjB,GAAG,CAACiB,IAAI,CAACtB,QAAQ,CAACG,QAAQS,QAAQ,IAAI,UAAUP,GAAG,CAACiB,IAAI;YACjG;QACF;QACAL,OAAMb,SAASa,QAAOb,SAAS,MAAMC;IACvC;IAEA,aAAa;IACb,IAAIF,QAAQuB,KAAK,IAAK,CAAA,OAAOvB,QAAQuB,KAAK,KAAK,YAAYP,OAAOM,QAAQ,CAACtB,QAAQuB,KAAK,CAAA,GAAI;QAC1FxB,GAAGyB,KAAK,CAACC,GAAG,CAACzB,QAAQuB,KAAK;IAC5B;AACF"}
@@ -1,12 +1,14 @@
1
- import once from 'call-once-fn';
1
+ import oo from 'on-one';
2
2
  import { spawnKeys } from '../constants.mjs';
3
+ function isError(obj) {
4
+ return Object.prototype.toString.call(obj) === '[object Error]';
5
+ }
3
6
  export default function worker(cp, options, callback) {
4
7
  if (typeof options === 'function') {
5
8
  callback = options;
6
9
  options = {};
7
10
  }
8
11
  options = options || {};
9
- callback = once(callback); // some versions of node emit both an error and close
10
12
  // collect output
11
13
  const res = {
12
14
  pid: 0,
@@ -20,37 +22,43 @@ export default function worker(cp, options, callback) {
20
22
  const stderr = [];
21
23
  if (options.encoding && cp.stdout) cp.stdout.on('data', stdout.push.bind(stdout));
22
24
  if (options.encoding && cp.stderr) cp.stderr.on('data', stderr.push.bind(stderr));
23
- cp.on('error', (err)=>err.code === 'OK' || callback(err));
24
- cp.on('close', (status, signal)=>{
25
- setTimeout(function close() {
26
- // prepare result
27
- res.pid = cp.pid;
28
- res.status = status;
29
- res.signal = signal;
30
- if (options.encoding && cp.stdout) {
31
- res.stdout = Buffer.concat(stdout);
32
- if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);
33
- }
34
- if (options.encoding && cp.stderr) {
35
- res.stderr = Buffer.concat(stderr);
36
- if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);
37
- }
38
- res.output = [
39
- null,
40
- res.stdout,
41
- res.stderr
42
- ];
43
- if (res.status === null) res.status = 0; // patch: early node on windows could return null
44
- // process errors
45
- const err = res.status !== 0 ? new Error(`Non-zero exit code: ${res.status}`) : null;
46
- if (err) {
47
- for(const key in res){
48
- if (spawnKeys.indexOf(key) < 0) continue;
49
- err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];
50
- }
25
+ // some versions of node emit both an error and close
26
+ oo(cp, [
27
+ 'error',
28
+ 'close'
29
+ ], (status, signal)=>{
30
+ if (isError(status)) {
31
+ const err = status;
32
+ if (err.code === 'OK') return; // ignore
33
+ return callback(err);
34
+ }
35
+ // prepare result
36
+ res.pid = cp.pid;
37
+ res.status = status;
38
+ res.signal = signal;
39
+ if (options.encoding && cp.stdout) {
40
+ res.stdout = Buffer.concat(stdout);
41
+ if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);
42
+ }
43
+ if (options.encoding && cp.stderr) {
44
+ res.stderr = Buffer.concat(stderr);
45
+ if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);
46
+ }
47
+ res.output = [
48
+ null,
49
+ res.stdout,
50
+ res.stderr
51
+ ];
52
+ if (res.status === null) res.status = 0; // patch: early node on windows could return null
53
+ // process errors
54
+ const err = res.status !== 0 ? new Error(`Non-zero exit code: ${res.status}`) : null;
55
+ if (err) {
56
+ for(const key in res){
57
+ if (spawnKeys.indexOf(key) < 0) continue;
58
+ err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];
51
59
  }
52
- err ? callback(err) : callback(null, res);
53
- }, 0);
60
+ }
61
+ err ? callback(err) : callback(null, res);
54
62
  });
55
63
  // pipe input
56
64
  if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/compat/cross-spawn-cb/src/workers/async.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { spawnKeys } from '../constants';\n\nimport type { ChildProcess, SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from '../types';\n\nexport default function worker(cp: ChildProcess, options?: SpawnOptions | SpawnCallback, callback?: SpawnCallback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n callback = once(callback); // some versions of node emit both an error and close\n\n // collect output\n const res = { pid: 0, output: [], stdout: null, stderr: null, status: null, signal: null } as SpawnResult;\n const stdout: Buffer[] = [];\n const stderr: Buffer[] = [];\n if (options.encoding && cp.stdout) cp.stdout.on('data', stdout.push.bind(stdout));\n if (options.encoding && cp.stderr) cp.stderr.on('data', stderr.push.bind(stderr));\n\n cp.on('error', (err: SpawnError) => err.code === 'OK' || callback(err));\n cp.on('close', (status, signal) => {\n setTimeout(function close() {\n // prepare result\n res.pid = cp.pid;\n res.status = status;\n res.signal = signal;\n if (options.encoding && cp.stdout) {\n res.stdout = Buffer.concat(stdout);\n if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);\n }\n if (options.encoding && cp.stderr) {\n res.stderr = Buffer.concat(stderr);\n if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);\n }\n res.output = [null, res.stdout, res.stderr];\n if (res.status === null) res.status = 0; // patch: early node on windows could return null\n\n // process errors\n const err = res.status !== 0 ? new Error(`Non-zero exit code: ${res.status}`) : null;\n if (err) {\n for (const key in res) {\n if (spawnKeys.indexOf(key) < 0) continue;\n err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];\n }\n }\n err ? callback(err) : callback(null, res);\n }, 0);\n });\n\n // pipe input\n if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {\n cp.stdin.end(options.input);\n }\n}\n"],"names":["once","spawnKeys","worker","cp","options","callback","res","pid","output","stdout","stderr","status","signal","encoding","on","push","bind","err","code","setTimeout","close","Buffer","concat","toString","Error","key","indexOf","isBuffer","input","stdin","end"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAASC,SAAS,QAAQ,eAAe;AAIzC,eAAe,SAASC,OAAOC,EAAgB,EAAEC,OAAsC,EAAEC,QAAwB;IAC/G,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IACtBC,WAAWL,KAAKK,WAAW,qDAAqD;IAEhF,iBAAiB;IACjB,MAAMC,MAAM;QAAEC,KAAK;QAAGC,QAAQ,EAAE;QAAEC,QAAQ;QAAMC,QAAQ;QAAMC,QAAQ;QAAMC,QAAQ;IAAK;IACzF,MAAMH,SAAmB,EAAE;IAC3B,MAAMC,SAAmB,EAAE;IAC3B,IAAIN,QAAQS,QAAQ,IAAIV,GAAGM,MAAM,EAAEN,GAAGM,MAAM,CAACK,EAAE,CAAC,QAAQL,OAAOM,IAAI,CAACC,IAAI,CAACP;IACzE,IAAIL,QAAQS,QAAQ,IAAIV,GAAGO,MAAM,EAAEP,GAAGO,MAAM,CAACI,EAAE,CAAC,QAAQJ,OAAOK,IAAI,CAACC,IAAI,CAACN;IAEzEP,GAAGW,EAAE,CAAC,SAAS,CAACG,MAAoBA,IAAIC,IAAI,KAAK,QAAQb,SAASY;IAClEd,GAAGW,EAAE,CAAC,SAAS,CAACH,QAAQC;QACtBO,WAAW,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,QAAQwB,KAAK,KAAK,YAAYP,OAAOM,QAAQ,CAACvB,QAAQwB,KAAK,CAAA,GAAI;QAC1FzB,GAAG0B,KAAK,CAACC,GAAG,CAAC1B,QAAQwB,KAAK;IAC5B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/compat/cross-spawn-cb/src/workers/async.ts"],"sourcesContent":["import oo from 'on-one';\nimport { spawnKeys } from '../constants';\n\nimport type { ChildProcess, SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from '../types';\n\nfunction isError(obj) {\n return Object.prototype.toString.call(obj) === '[object Error]';\n}\n\nexport default function worker(cp: ChildProcess, options?: SpawnOptions | SpawnCallback, callback?: SpawnCallback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n // collect output\n const res = { pid: 0, output: [], stdout: null, stderr: null, status: null, signal: null } as SpawnResult;\n const stdout: Buffer[] = [];\n const stderr: Buffer[] = [];\n if (options.encoding && cp.stdout) cp.stdout.on('data', stdout.push.bind(stdout));\n if (options.encoding && cp.stderr) cp.stderr.on('data', stderr.push.bind(stderr));\n\n // some versions of node emit both an error and close\n oo(cp, ['error', 'close'], (status, signal) => {\n if (isError(status)) {\n const err = status as SpawnError;\n if (err.code === 'OK') return; // ignore\n return callback(err);\n }\n\n // prepare result\n res.pid = cp.pid;\n res.status = status;\n res.signal = signal;\n if (options.encoding && cp.stdout) {\n res.stdout = Buffer.concat(stdout);\n if (options.encoding !== 'binary') res.stdout = res.stdout.toString(options.encoding);\n }\n if (options.encoding && cp.stderr) {\n res.stderr = Buffer.concat(stderr);\n if (options.encoding !== 'binary') res.stderr = res.stderr.toString(options.encoding);\n }\n res.output = [null, res.stdout, res.stderr];\n if (res.status === null) res.status = 0; // patch: early node on windows could return null\n\n // process errors\n const err = res.status !== 0 ? new Error(`Non-zero exit code: ${res.status}`) : null;\n if (err) {\n for (const key in res) {\n if (spawnKeys.indexOf(key) < 0) continue;\n err[key] = Buffer.isBuffer(res[key]) ? res[key].toString(options.encoding || 'utf8') : res[key];\n }\n }\n err ? callback(err) : callback(null, res);\n });\n\n // pipe input\n if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {\n cp.stdin.end(options.input);\n }\n}\n"],"names":["oo","spawnKeys","isError","obj","Object","prototype","toString","call","worker","cp","options","callback","res","pid","output","stdout","stderr","status","signal","encoding","on","push","bind","err","code","Buffer","concat","Error","key","indexOf","isBuffer","input","stdin","end"],"mappings":"AAAA,OAAOA,QAAQ,SAAS;AACxB,SAASC,SAAS,QAAQ,eAAe;AAIzC,SAASC,QAAQC,GAAG;IAClB,OAAOC,OAAOC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACJ,SAAS;AACjD;AAEA,eAAe,SAASK,OAAOC,EAAgB,EAAEC,OAAsC,EAAEC,QAAwB;IAC/G,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,iBAAiB;IACjB,MAAME,MAAM;QAAEC,KAAK;QAAGC,QAAQ,EAAE;QAAEC,QAAQ;QAAMC,QAAQ;QAAMC,QAAQ;QAAMC,QAAQ;IAAK;IACzF,MAAMH,SAAmB,EAAE;IAC3B,MAAMC,SAAmB,EAAE;IAC3B,IAAIN,QAAQS,QAAQ,IAAIV,GAAGM,MAAM,EAAEN,GAAGM,MAAM,CAACK,EAAE,CAAC,QAAQL,OAAOM,IAAI,CAACC,IAAI,CAACP;IACzE,IAAIL,QAAQS,QAAQ,IAAIV,GAAGO,MAAM,EAAEP,GAAGO,MAAM,CAACI,EAAE,CAAC,QAAQJ,OAAOK,IAAI,CAACC,IAAI,CAACN;IAEzE,qDAAqD;IACrDhB,GAAGS,IAAI;QAAC;QAAS;KAAQ,EAAE,CAACQ,QAAQC;QAClC,IAAIhB,QAAQe,SAAS;YACnB,MAAMM,MAAMN;YACZ,IAAIM,IAAIC,IAAI,KAAK,MAAM,QAAQ,SAAS;YACxC,OAAOb,S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AAYN,OAAOK,QAAQ,CAACpB,QAAQqB,KAAK,CAAA,GAAI;QAC1FtB,GAAGuB,KAAK,CAACC,GAAG,CAACvB,QAAQqB,KAAK;IAC5B;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-spawn-cb",
3
- "version": "2.1.13",
3
+ "version": "2.1.15",
4
4
  "description": "Cross spawn with a completion callback",
5
5
  "keywords": [
6
6
  "cross-spawn",
@@ -33,9 +33,9 @@
33
33
  "version": "tsds version"
34
34
  },
35
35
  "dependencies": {
36
- "call-once-fn": "^1.0.10",
37
36
  "cross-spawn": "^7.0.6",
38
- "function-exec-sync": "^1.2.12"
37
+ "function-exec-sync": "^1.2.13",
38
+ "on-one": "^0.1.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/mocha": "*",