cross-spawn-cb 0.3.2 → 0.5.0

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.
@@ -0,0 +1,654 @@
1
+ 'use strict';
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+
7
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
8
+
9
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
+
11
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
+
13
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+
17
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
+
19
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
+
21
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
22
+
23
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
24
+
25
+ Object.defineProperty(exports, '__esModule', {
26
+ value: true
27
+ });
28
+
29
+ var require$$0$2 = require('child_process');
30
+
31
+ var require$$0$1 = require('path');
32
+
33
+ var require$$0 = require('fs');
34
+
35
+ function _interopDefaultLegacy(e) {
36
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
37
+ 'default': e
38
+ };
39
+ }
40
+
41
+ var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
42
+
43
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
44
+
45
+ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
46
+
47
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
48
+ var crossSpawn = {
49
+ exports: {}
50
+ };
51
+ var windows;
52
+ var hasRequiredWindows;
53
+
54
+ function requireWindows() {
55
+ if (hasRequiredWindows) return windows;
56
+ hasRequiredWindows = 1;
57
+ windows = isexe;
58
+ isexe.sync = sync;
59
+ var fs = require$$0__default["default"];
60
+
61
+ function checkPathExt(path, options) {
62
+ var pathext = options.pathExt !== undefined ? options.pathExt : process.env.PATHEXT;
63
+
64
+ if (!pathext) {
65
+ return true;
66
+ }
67
+
68
+ pathext = pathext.split(';');
69
+
70
+ if (pathext.indexOf('') !== -1) {
71
+ return true;
72
+ }
73
+
74
+ for (var i = 0; i < pathext.length; i++) {
75
+ var p = pathext[i].toLowerCase();
76
+
77
+ if (p && path.substr(-p.length).toLowerCase() === p) {
78
+ return true;
79
+ }
80
+ }
81
+
82
+ return false;
83
+ }
84
+
85
+ function checkStat(stat, path, options) {
86
+ if (!stat.isSymbolicLink() && !stat.isFile()) {
87
+ return false;
88
+ }
89
+
90
+ return checkPathExt(path, options);
91
+ }
92
+
93
+ function isexe(path, options, cb) {
94
+ fs.stat(path, function (er, stat) {
95
+ cb(er, er ? false : checkStat(stat, path, options));
96
+ });
97
+ }
98
+
99
+ function sync(path, options) {
100
+ return checkStat(fs.statSync(path), path, options);
101
+ }
102
+
103
+ return windows;
104
+ }
105
+
106
+ var mode;
107
+ var hasRequiredMode;
108
+
109
+ function requireMode() {
110
+ if (hasRequiredMode) return mode;
111
+ hasRequiredMode = 1;
112
+ mode = isexe;
113
+ isexe.sync = sync;
114
+ var fs = require$$0__default["default"];
115
+
116
+ function isexe(path, options, cb) {
117
+ fs.stat(path, function (er, stat) {
118
+ cb(er, er ? false : checkStat(stat, options));
119
+ });
120
+ }
121
+
122
+ function sync(path, options) {
123
+ return checkStat(fs.statSync(path), options);
124
+ }
125
+
126
+ function checkStat(stat, options) {
127
+ return stat.isFile() && checkMode(stat, options);
128
+ }
129
+
130
+ function checkMode(stat, options) {
131
+ var mod = stat.mode;
132
+ var uid = stat.uid;
133
+ var gid = stat.gid;
134
+ var myUid = options.uid !== undefined ? options.uid : process.getuid && process.getuid();
135
+ var myGid = options.gid !== undefined ? options.gid : process.getgid && process.getgid();
136
+ var u = parseInt('100', 8);
137
+ var g = parseInt('010', 8);
138
+ var o = parseInt('001', 8);
139
+ var ug = u | g;
140
+ var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
141
+ return ret;
142
+ }
143
+
144
+ return mode;
145
+ }
146
+
147
+ var core;
148
+
149
+ if (process.platform === 'win32' || commonjsGlobal.TESTING_WINDOWS) {
150
+ core = requireWindows();
151
+ } else {
152
+ core = requireMode();
153
+ }
154
+
155
+ var isexe_1 = isexe$1;
156
+ isexe$1.sync = sync$1;
157
+
158
+ function isexe$1(path, options, cb) {
159
+ if (typeof options === 'function') {
160
+ cb = options;
161
+ options = {};
162
+ }
163
+
164
+ if (!cb) {
165
+ if (typeof Promise !== 'function') {
166
+ throw new TypeError('callback not provided');
167
+ }
168
+
169
+ return new Promise(function (resolve, reject) {
170
+ isexe$1(path, options || {}, function (er, is) {
171
+ if (er) {
172
+ reject(er);
173
+ } else {
174
+ resolve(is);
175
+ }
176
+ });
177
+ });
178
+ }
179
+
180
+ core(path, options || {}, function (er, is) {
181
+ // ignore EACCES because that just means we aren't allowed to run it
182
+ if (er) {
183
+ if (er.code === 'EACCES' || options && options.ignoreErrors) {
184
+ er = null;
185
+ is = false;
186
+ }
187
+ }
188
+
189
+ cb(er, is);
190
+ });
191
+ }
192
+
193
+ function sync$1(path, options) {
194
+ // my kingdom for a filtered catch
195
+ try {
196
+ return core.sync(path, options || {});
197
+ } catch (er) {
198
+ if (options && options.ignoreErrors || er.code === 'EACCES') {
199
+ return false;
200
+ } else {
201
+ throw er;
202
+ }
203
+ }
204
+ }
205
+
206
+ var isWindows = process.platform === 'win32' || process.env.OSTYPE === 'cygwin' || process.env.OSTYPE === 'msys';
207
+ var path$2 = require$$0__default$1["default"];
208
+ var COLON = isWindows ? ';' : ':';
209
+ var isexe = isexe_1;
210
+
211
+ var getNotFoundError = function getNotFoundError(cmd) {
212
+ return Object.assign(new Error("not found: ".concat(cmd)), {
213
+ code: 'ENOENT'
214
+ });
215
+ };
216
+
217
+ var getPathInfo = function getPathInfo(cmd, opt) {
218
+ var colon = opt.colon || COLON; // If it has a slash, then we don't bother searching the pathenv.
219
+ // just check the file itself, and that's it.
220
+
221
+ var pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [''] : [].concat(_toConsumableArray(isWindows ? [process.cwd()] : []), _toConsumableArray((opt.path || process.env.PATH ||
222
+ /* istanbul ignore next: very unusual */
223
+ '').split(colon)));
224
+ var pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM' : '';
225
+ var pathExt = isWindows ? pathExtExe.split(colon) : [''];
226
+
227
+ if (isWindows) {
228
+ if (cmd.indexOf('.') !== -1 && pathExt[0] !== '') pathExt.unshift('');
229
+ }
230
+
231
+ return {
232
+ pathEnv: pathEnv,
233
+ pathExt: pathExt,
234
+ pathExtExe: pathExtExe
235
+ };
236
+ };
237
+
238
+ var which$1 = function which$1(cmd, opt, cb) {
239
+ if (typeof opt === 'function') {
240
+ cb = opt;
241
+ opt = {};
242
+ }
243
+
244
+ if (!opt) opt = {};
245
+
246
+ var _getPathInfo = getPathInfo(cmd, opt),
247
+ pathEnv = _getPathInfo.pathEnv,
248
+ pathExt = _getPathInfo.pathExt,
249
+ pathExtExe = _getPathInfo.pathExtExe;
250
+
251
+ var found = [];
252
+
253
+ var step = function step(i) {
254
+ return new Promise(function (resolve, reject) {
255
+ if (i === pathEnv.length) return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
256
+ var ppRaw = pathEnv[i];
257
+ var pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
258
+ var pCmd = path$2.join(pathPart, cmd);
259
+ var p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
260
+ resolve(subStep(p, i, 0));
261
+ });
262
+ };
263
+
264
+ var subStep = function subStep(p, i, ii) {
265
+ return new Promise(function (resolve, reject) {
266
+ if (ii === pathExt.length) return resolve(step(i + 1));
267
+ var ext = pathExt[ii];
268
+ isexe(p + ext, {
269
+ pathExt: pathExtExe
270
+ }, function (er, is) {
271
+ if (!er && is) {
272
+ if (opt.all) found.push(p + ext);else return resolve(p + ext);
273
+ }
274
+
275
+ return resolve(subStep(p, i, ii + 1));
276
+ });
277
+ });
278
+ };
279
+
280
+ return cb ? step(0).then(function (res) {
281
+ return cb(null, res);
282
+ }, cb) : step(0);
283
+ };
284
+
285
+ var whichSync = function whichSync(cmd, opt) {
286
+ opt = opt || {};
287
+
288
+ var _getPathInfo2 = getPathInfo(cmd, opt),
289
+ pathEnv = _getPathInfo2.pathEnv,
290
+ pathExt = _getPathInfo2.pathExt,
291
+ pathExtExe = _getPathInfo2.pathExtExe;
292
+
293
+ var found = [];
294
+
295
+ for (var i = 0; i < pathEnv.length; i++) {
296
+ var ppRaw = pathEnv[i];
297
+ var pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
298
+ var pCmd = path$2.join(pathPart, cmd);
299
+ var p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
300
+
301
+ for (var j = 0; j < pathExt.length; j++) {
302
+ var cur = p + pathExt[j];
303
+
304
+ try {
305
+ var is = isexe.sync(cur, {
306
+ pathExt: pathExtExe
307
+ });
308
+
309
+ if (is) {
310
+ if (opt.all) found.push(cur);else return cur;
311
+ }
312
+ } catch (ex) {}
313
+ }
314
+ }
315
+
316
+ if (opt.all && found.length) return found;
317
+ if (opt.nothrow) return null;
318
+ throw getNotFoundError(cmd);
319
+ };
320
+
321
+ var which_1 = which$1;
322
+ which$1.sync = whichSync;
323
+ var pathKey$1 = {
324
+ exports: {}
325
+ };
326
+
327
+ var pathKey = function pathKey() {
328
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
329
+ var environment = options.env || process.env;
330
+ var platform = options.platform || process.platform;
331
+
332
+ if (platform !== 'win32') {
333
+ return 'PATH';
334
+ }
335
+
336
+ return Object.keys(environment).reverse().find(function (key) {
337
+ return key.toUpperCase() === 'PATH';
338
+ }) || 'Path';
339
+ };
340
+
341
+ pathKey$1.exports = pathKey; // TODO: Remove this for the next major release
342
+
343
+ pathKey$1.exports["default"] = pathKey;
344
+ var path$1 = require$$0__default$1["default"];
345
+ var which = which_1;
346
+ var getPathKey = pathKey$1.exports;
347
+
348
+ function resolveCommandAttempt(parsed, withoutPathExt) {
349
+ var env = parsed.options.env || process.env;
350
+ var cwd = process.cwd();
351
+ var hasCustomCwd = parsed.options.cwd != null; // Worker threads do not have process.chdir()
352
+
353
+ var shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled; // If a custom `cwd` was specified, we need to change the process cwd
354
+ // because `which` will do stat calls but does not support a custom cwd
355
+
356
+ if (shouldSwitchCwd) {
357
+ try {
358
+ process.chdir(parsed.options.cwd);
359
+ } catch (err) {
360
+ /* Empty */
361
+ }
362
+ }
363
+
364
+ var resolved;
365
+
366
+ try {
367
+ resolved = which.sync(parsed.command, {
368
+ path: env[getPathKey({
369
+ env: env
370
+ })],
371
+ pathExt: withoutPathExt ? path$1.delimiter : undefined
372
+ });
373
+ } catch (e) {
374
+ /* Empty */
375
+ } finally {
376
+ if (shouldSwitchCwd) {
377
+ process.chdir(cwd);
378
+ }
379
+ } // If we successfully resolved, ensure that an absolute path is returned
380
+ // Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it
381
+
382
+
383
+ if (resolved) {
384
+ resolved = path$1.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved);
385
+ }
386
+
387
+ return resolved;
388
+ }
389
+
390
+ function resolveCommand$1(parsed) {
391
+ return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
392
+ }
393
+
394
+ var resolveCommand_1 = resolveCommand$1;
395
+ var _escape = {}; // See http://www.robvanderwoude.com/escapechars.php
396
+
397
+ var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
398
+
399
+ function escapeCommand(arg) {
400
+ // Escape meta chars
401
+ arg = arg.replace(metaCharsRegExp, '^$1');
402
+ return arg;
403
+ }
404
+
405
+ function escapeArgument(arg, doubleEscapeMetaChars) {
406
+ // Convert to string
407
+ arg = "".concat(arg); // Algorithm below is based on https://qntm.org/cmd
408
+ // Sequence of backslashes followed by a double quote:
409
+ // double up all the backslashes and escape the double quote
410
+
411
+ arg = arg.replace(/(\\*)"/g, '$1$1\\"'); // Sequence of backslashes followed by the end of the string
412
+ // (which will become a double quote later):
413
+ // double up all the backslashes
414
+
415
+ arg = arg.replace(/(\\*)$/, '$1$1'); // All other backslashes occur literally
416
+ // Quote the whole thing:
417
+
418
+ arg = "\"".concat(arg, "\""); // Escape meta chars
419
+
420
+ arg = arg.replace(metaCharsRegExp, '^$1'); // Double escape meta chars if necessary
421
+
422
+ if (doubleEscapeMetaChars) {
423
+ arg = arg.replace(metaCharsRegExp, '^$1');
424
+ }
425
+
426
+ return arg;
427
+ }
428
+
429
+ _escape.command = escapeCommand;
430
+ _escape.argument = escapeArgument;
431
+ var shebangRegex$1 = /^#!(.*)/;
432
+ var shebangRegex = shebangRegex$1;
433
+
434
+ var shebangCommand$1 = function shebangCommand$1() {
435
+ var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
436
+ var match = string.match(shebangRegex);
437
+
438
+ if (!match) {
439
+ return null;
440
+ }
441
+
442
+ var _match$0$replace$spli = match[0].replace(/#! ?/, '').split(' '),
443
+ _match$0$replace$spli2 = _slicedToArray(_match$0$replace$spli, 2),
444
+ path = _match$0$replace$spli2[0],
445
+ argument = _match$0$replace$spli2[1];
446
+
447
+ var binary = path.split('/').pop();
448
+
449
+ if (binary === 'env') {
450
+ return argument;
451
+ }
452
+
453
+ return argument ? "".concat(binary, " ").concat(argument) : binary;
454
+ };
455
+
456
+ var fs = require$$0__default["default"];
457
+ var shebangCommand = shebangCommand$1;
458
+
459
+ function readShebang$1(command) {
460
+ // Read the first 150 bytes from the file
461
+ var size = 150;
462
+ var buffer = Buffer.alloc(size);
463
+ var fd;
464
+
465
+ try {
466
+ fd = fs.openSync(command, 'r');
467
+ fs.readSync(fd, buffer, 0, size, 0);
468
+ fs.closeSync(fd);
469
+ } catch (e) {
470
+ /* Empty */
471
+ } // Attempt to extract shebang (null is returned if not a shebang)
472
+
473
+
474
+ return shebangCommand(buffer.toString());
475
+ }
476
+
477
+ var readShebang_1 = readShebang$1;
478
+ var path = require$$0__default$1["default"];
479
+ var resolveCommand = resolveCommand_1;
480
+ var escape = _escape;
481
+ var readShebang = readShebang_1;
482
+ var isWin$1 = process.platform === 'win32';
483
+ var isExecutableRegExp = /\.(?:com|exe)$/i;
484
+ var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
485
+
486
+ function detectShebang(parsed) {
487
+ parsed.file = resolveCommand(parsed);
488
+ var shebang = parsed.file && readShebang(parsed.file);
489
+
490
+ if (shebang) {
491
+ parsed.args.unshift(parsed.file);
492
+ parsed.command = shebang;
493
+ return resolveCommand(parsed);
494
+ }
495
+
496
+ return parsed.file;
497
+ }
498
+
499
+ function parseNonShell(parsed) {
500
+ if (!isWin$1) {
501
+ return parsed;
502
+ } // Detect & add support for shebangs
503
+
504
+
505
+ var commandFile = detectShebang(parsed); // We don't need a shell if the command filename is an executable
506
+
507
+ var needsShell = !isExecutableRegExp.test(commandFile); // If a shell is required, use cmd.exe and take care of escaping everything correctly
508
+ // Note that `forceShell` is an hidden option used only in tests
509
+
510
+ if (parsed.options.forceShell || needsShell) {
511
+ // Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`
512
+ // The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument
513
+ // Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,
514
+ // we need to double escape them
515
+ var needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile); // Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\bar)
516
+ // This is necessary otherwise it will always fail with ENOENT in those cases
517
+
518
+ parsed.command = path.normalize(parsed.command); // Escape command & arguments
519
+
520
+ parsed.command = escape.command(parsed.command);
521
+ parsed.args = parsed.args.map(function (arg) {
522
+ return escape.argument(arg, needsDoubleEscapeMetaChars);
523
+ });
524
+ var shellCommand = [parsed.command].concat(parsed.args).join(' ');
525
+ parsed.args = ['/d', '/s', '/c', "\"".concat(shellCommand, "\"")];
526
+ parsed.command = process.env.comspec || 'cmd.exe';
527
+ parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped
528
+ }
529
+
530
+ return parsed;
531
+ }
532
+
533
+ function parse$1(command, args, options) {
534
+ // Normalize arguments, similar to nodejs
535
+ if (args && !Array.isArray(args)) {
536
+ options = args;
537
+ args = null;
538
+ }
539
+
540
+ args = args ? args.slice(0) : []; // Clone array to avoid changing the original
541
+
542
+ options = Object.assign({}, options); // Clone object to avoid changing the original
543
+ // Build our parsed object
544
+
545
+ var parsed = {
546
+ command: command,
547
+ args: args,
548
+ options: options,
549
+ file: undefined,
550
+ original: {
551
+ command: command,
552
+ args: args
553
+ }
554
+ }; // Delegate further parsing to shell or non-shell
555
+
556
+ return options.shell ? parsed : parseNonShell(parsed);
557
+ }
558
+
559
+ var parse_1 = parse$1;
560
+ var isWin = process.platform === 'win32';
561
+
562
+ function notFoundError(original, syscall) {
563
+ return Object.assign(new Error("".concat(syscall, " ").concat(original.command, " ENOENT")), {
564
+ code: 'ENOENT',
565
+ errno: 'ENOENT',
566
+ syscall: "".concat(syscall, " ").concat(original.command),
567
+ path: original.command,
568
+ spawnargs: original.args
569
+ });
570
+ }
571
+
572
+ function hookChildProcess(cp, parsed) {
573
+ if (!isWin) {
574
+ return;
575
+ }
576
+
577
+ var originalEmit = cp.emit;
578
+
579
+ cp.emit = function (name, arg1) {
580
+ // If emitting "exit" event and exit code is 1, we need to check if
581
+ // the command exists and emit an "error" instead
582
+ // See https://github.com/IndigoUnited/node-cross-spawn/issues/16
583
+ if (name === 'exit') {
584
+ var err = verifyENOENT(arg1, parsed);
585
+
586
+ if (err) {
587
+ return originalEmit.call(cp, 'error', err);
588
+ }
589
+ }
590
+
591
+ return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params
592
+ };
593
+ }
594
+
595
+ function verifyENOENT(status, parsed) {
596
+ if (isWin && status === 1 && !parsed.file) {
597
+ return notFoundError(parsed.original, 'spawn');
598
+ }
599
+
600
+ return null;
601
+ }
602
+
603
+ function verifyENOENTSync(status, parsed) {
604
+ if (isWin && status === 1 && !parsed.file) {
605
+ return notFoundError(parsed.original, 'spawnSync');
606
+ }
607
+
608
+ return null;
609
+ }
610
+
611
+ var enoent$1 = {
612
+ hookChildProcess: hookChildProcess,
613
+ verifyENOENT: verifyENOENT,
614
+ verifyENOENTSync: verifyENOENTSync,
615
+ notFoundError: notFoundError
616
+ };
617
+ var cp = require$$0__default$2["default"];
618
+ var parse = parse_1;
619
+ var enoent = enoent$1;
620
+
621
+ function spawn(command, args, options) {
622
+ // Parse the arguments
623
+ var parsed = parse(command, args, options); // Spawn the child process
624
+
625
+ var spawned = cp.spawn(parsed.command, parsed.args, parsed.options); // Hook into child process "exit" event to emit an error if the command
626
+ // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
627
+
628
+ enoent.hookChildProcess(spawned, parsed);
629
+ return spawned;
630
+ }
631
+
632
+ function spawnSync(command, args, options) {
633
+ // Parse the arguments
634
+ var parsed = parse(command, args, options); // Spawn the child process
635
+
636
+ var result = cp.spawnSync(parsed.command, parsed.args, parsed.options); // Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
637
+
638
+ result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
639
+ return result;
640
+ }
641
+
642
+ crossSpawn.exports = spawn;
643
+ var spawn_1 = crossSpawn.exports.spawn = spawn;
644
+ var sync = crossSpawn.exports.sync = spawnSync;
645
+
646
+ var _parse = crossSpawn.exports._parse = parse;
647
+
648
+ var _enoent = crossSpawn.exports._enoent = enoent;
649
+
650
+ exports._enoent = _enoent;
651
+ exports._parse = _parse;
652
+ exports["default"] = crossSpawn.exports;
653
+ exports.spawn = spawn_1;
654
+ exports.sync = sync;
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ module.exports = require('./spawnCallback');
2
+ module.exports.sync = require('./spawnSyncCallback');
@@ -0,0 +1,7 @@
1
+ if (!Object.assign) Object.assign = require('just-extend');
2
+
3
+ var path = require('path');
4
+ if (typeof path.delimiter === 'undefined') path.delimiter = process.platform === 'win32' ? ';' : ':';
5
+
6
+ var cp = require('child_process');
7
+ if (!cp.spawnSync) cp.spawnSync = require('./spawn-sync/spawn-sync.js');
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Forbes Lindesay
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ Code based on https://github.com/ForbesLindesay/spawn-sync but adapted to use cross-spawn
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+ /* eslint-disable */
3
+
4
+ var path = require('path');
5
+ var fs = require('fs');
6
+ var tmpdir = require('os').tmpdir || require('os-shim').tmpdir;
7
+ var cp = require('child_process');
8
+ var sleep = function () {};
9
+ var JSON = require('spawn-sync/lib/json-buffer');
10
+
11
+ var temp = path.normalize(path.join(tmpdir(), 'spawn-sync'));
12
+
13
+ function randomFileName(name) {
14
+ function randomHash(count) {
15
+ if (count === 1) return parseInt(16 * Math.random(), 10).toString(16);
16
+ else {
17
+ var hash = '';
18
+ for (var i = 0; i < count; i++) hash += randomHash(1);
19
+ return hash;
20
+ }
21
+ }
22
+
23
+ return temp + '_' + name + '_' + String(process.pid) + randomHash(20);
24
+ }
25
+ function unlink(filename) {
26
+ try {
27
+ fs.unlinkSync(filename);
28
+ } catch (ex) {
29
+ if (ex.code !== 'ENOENT') throw ex;
30
+ }
31
+ }
32
+ function tryUnlink(filename) {
33
+ // doesn't matter too much if we fail to delete temp files
34
+ try {
35
+ fs.unlinkSync(filename);
36
+ } catch (e) {}
37
+ }
38
+
39
+ function invoke(cmd) {
40
+ // location to keep flag for busy waiting fallback
41
+ var finished = randomFileName('finished');
42
+ unlink(finished);
43
+ if (process.platform === 'win32') {
44
+ cmd = cmd + '& echo "finished" > ' + finished;
45
+ } else {
46
+ cmd = cmd + '; echo "finished" > ' + finished;
47
+ }
48
+ cp.exec(cmd);
49
+
50
+ while (!fs.existsSync(finished)) {
51
+ // busy wait
52
+ sleep(200);
53
+ }
54
+
55
+ tryUnlink(finished);
56
+
57
+ return 0;
58
+ }
59
+
60
+ module.exports = spawnSyncFallback;
61
+ function spawnSyncFallback(cmd, commandArgs, options) {
62
+ var args = [];
63
+ for (var i = 0; i < arguments.length; i++) {
64
+ args.push(arguments[i]);
65
+ }
66
+
67
+ // node.js script to run the command
68
+ var worker = path.normalize(__dirname + '/worker.js');
69
+ // location to store arguments
70
+ var input = randomFileName('input');
71
+ var output = randomFileName('output');
72
+ unlink(output);
73
+
74
+ fs.writeFileSync(input, JSON.stringify(args));
75
+ invoke('"' + process.execPath + '" "' + worker + '" "' + input + '" "' + output + '"');
76
+ var res = JSON.parse(fs.readFileSync(output, 'utf8'));
77
+ tryUnlink(input);
78
+ tryUnlink(output);
79
+ return res;
80
+ }
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+ /* eslint-disable */
3
+
4
+ require('../polyfills');
5
+
6
+ var spawn = require('../cross-spawn.js').spawn;
7
+ var fs = require('fs');
8
+ var concat = require('concat-stream');
9
+ var JSON = require('spawn-sync/lib/json-buffer');
10
+
11
+ var inputFile = process.argv[2];
12
+ var outputFile = process.argv[3];
13
+
14
+ var args = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
15
+ function output(result) {
16
+ fs.writeFileSync(outputFile, JSON.stringify(result));
17
+ }
18
+
19
+ var child = spawn.apply(null, args);
20
+ var options = args[2] && typeof args[2] === 'object' ? args[2] : args[1] && typeof args[1] === 'object' && !Array.isArray(args[1]) ? args[1] : {};
21
+
22
+ var stdout, stderr;
23
+ child.stdout &&
24
+ child.stdout.pipe(
25
+ concat(function (buf) {
26
+ stdout = buf.length ? buf : new Buffer(0);
27
+ })
28
+ );
29
+ child.stderr &&
30
+ child.stderr.pipe(
31
+ concat(function (buf) {
32
+ stderr = buf.length ? buf : new Buffer(0);
33
+ })
34
+ );
35
+ child.on('error', function (err) {
36
+ output({ pid: child.pid, error: err.message });
37
+ });
38
+ child.on('close', function (status, signal) {
39
+ if (options.encoding && options.encoding !== 'buffer') {
40
+ stdout = stdout.toString(options.encoding);
41
+ stderr = stderr.toString(options.encoding);
42
+ }
43
+ output({
44
+ pid: child.pid,
45
+ output: [null, stdout, stderr],
46
+ stdout: stdout,
47
+ stderr: stderr,
48
+ status: status,
49
+ signal: signal,
50
+ });
51
+ });
52
+
53
+ if (options.timeout && typeof options.timeout === 'number') {
54
+ setTimeout(function () {
55
+ child.kill(options.killSignal || 'SIGTERM');
56
+ }, options.timeout);
57
+ }
58
+ if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {
59
+ child.stdin.end(options.input);
60
+ }
@@ -1,13 +1,12 @@
1
- var path = require('path');
2
- var spawn = require('cross-spawn');
3
- var assign = require('object-assign');
1
+ require('./polyfills');
2
+
3
+ var assign = require('just-extend');
4
4
  var once = require('once');
5
5
  var nextTick = require('next-tick');
6
6
 
7
- // patch for legacy versions of node
8
- if (typeof path.delimiter === 'undefined') path.delimiter = process.platform === 'win32' ? ';' : ':';
7
+ var spawn = require('./cross-spawn').spawn;
9
8
 
10
- module.exports = function crossSpawnCallback(command, args, options, callback) {
9
+ module.exports = function spawnCallback(command, args, options, callback) {
11
10
  if (typeof options === 'function') {
12
11
  callback = options;
13
12
  options = {};
@@ -56,5 +55,3 @@ module.exports = function crossSpawnCallback(command, args, options, callback) {
56
55
  });
57
56
  });
58
57
  };
59
-
60
- module.exports.sync = require('./lib/sync');
@@ -0,0 +1,25 @@
1
+ var spawnSync = require('./cross-spawn').sync;
2
+
3
+ module.exports = function spawnSyncCallback(command, args, options) {
4
+ options = options || {};
5
+
6
+ var result = spawnSync(command, args, {
7
+ stdio: 'pipe',
8
+ encoding: 'utf-8',
9
+ });
10
+ if (result.stdout && (options.stdout === 'inherit' || options.stdio === 'inherit')) {
11
+ process.stdout.write(result.stdout);
12
+ result.stdout = null;
13
+ }
14
+ if (result.stderr && (options.stderr === 'inherit' || options.stdio === 'inherit')) {
15
+ process.stderr.write(result.stderr);
16
+ result.stderr = null;
17
+ }
18
+ var err = result.status ? new Error('Non-zero exit code: ' + result.status) : null;
19
+ if (result.stderr && result.stderr.length) {
20
+ err = err || new Error('stderr has content');
21
+ err.stderr = result.stderr;
22
+ }
23
+ if (err) throw err;
24
+ return result;
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-spawn-cb",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
4
4
  "description": "Cross spawn with a completion callback",
5
5
  "keywords": [
6
6
  "cross-spawn",
@@ -12,35 +12,47 @@
12
12
  "url": "git@github.com:kmalakoff/cross-spawn-cb.git"
13
13
  },
14
14
  "license": "MIT",
15
- "main": "index.js",
15
+ "main": "lib/index.js",
16
16
  "scripts": {
17
17
  "format": "prettier --write .",
18
18
  "lint": "eslint .",
19
19
  "prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
20
20
  "test": "mocha-compat test/spec/**/*.test.js",
21
- "test:engines": "nvu engines npm test"
21
+ "test:engines": "nvu engines npm test",
22
+ "build": "rollup -c rollup.config.js"
22
23
  },
24
+ "files": [
25
+ "lib"
26
+ ],
23
27
  "dependencies": {
24
- "cross-spawn": "^5.1.0",
28
+ "cross-spawn": "^7.0.3",
29
+ "just-extend": "^6.0.1",
25
30
  "next-tick": "^1.1.0",
26
- "object-assign": "^4.1.1",
27
31
  "once": "^1.4.0",
28
- "spawn-sync": "^1.0.15"
32
+ "spawn-sync": "^2.0.0"
29
33
  },
30
34
  "devDependencies": {
31
- "babel-eslint": "^10.1.0",
32
- "depcheck": "^1.4.2",
33
- "dis-dat": "^0.1.3",
34
- "eslint": "^6.8.0",
35
- "eslint-config-prettier": "^6.11.0",
36
- "eslint-config-standard": "^14.1.1",
37
- "eslint-plugin-import": "^2.22.0",
35
+ "@babel/preset-env": "^7.18.6",
36
+ "@rollup/plugin-babel": "^5.3.1",
37
+ "@rollup/plugin-commonjs": "^22.0.1",
38
+ "@rollup/plugin-node-resolve": "^13.3.0",
39
+ "@typescript-eslint/parser": "^5.30.0",
40
+ "depcheck": "^1.4.3",
41
+ "dis-dat": "^0.1.4",
42
+ "eslint": "^8.18.0",
43
+ "eslint-config-prettier": "^8.5.0",
44
+ "eslint-config-standard": "^17.0.0",
45
+ "eslint-plugin-import": "^2.26.0",
38
46
  "eslint-plugin-node": "^11.1.0",
39
- "eslint-plugin-promise": "^4.2.1",
40
- "eslint-plugin-standard": "^4.0.1",
47
+ "eslint-plugin-promise": "^6.0.0",
48
+ "eslint-plugin-standard": "^4.1.0",
41
49
  "mocha-compat": "^3.5.5",
42
- "node-version-use": "^0.2.0",
43
- "prettier": "^2.4.1"
50
+ "node-version-use": "^0.2.2",
51
+ "prettier": "^2.7.1",
52
+ "rollup": "^2.75.7",
53
+ "rollup-plugin-babel": "^4.4.0",
54
+ "rollup-plugin-commonjs": "^10.1.0",
55
+ "rollup-plugin-node-externals": "^4.1.0"
44
56
  },
45
57
  "engines": {
46
58
  "node": ">=0.8"
@@ -1,11 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: npm
4
- directory: '/'
5
- schedule:
6
- interval: daily
7
- - package-ecosystem: 'github-actions'
8
- directory: '/'
9
- schedule:
10
- # Check for updates to GitHub Actions every weekday
11
- interval: 'daily'
@@ -1,22 +0,0 @@
1
- name: CI
2
- on:
3
- - push
4
- - pull_request
5
- jobs:
6
- test:
7
- name: Node.js ${{ matrix.node-version }} ${{ matrix.os }}
8
- runs-on: ${{ matrix.os }}
9
- strategy:
10
- matrix:
11
- node: ['latest']
12
- os: [ubuntu-latest, windows-latest, macOS-latest]
13
- steps:
14
- - uses: actions/checkout@v2
15
- - uses: actions/setup-node@v2.4.1
16
- with:
17
- node-version: ${{ matrix.node-version }}
18
- - run: git config --global user.name "Github Actions"
19
- - run: git config --global user.email "actions@users.noreply.github.com"
20
- - run: npm ci
21
- - run: npm run lint
22
- - run: npm run test:engines
package/lib/sync.js DELETED
@@ -1,29 +0,0 @@
1
- var assign = require('object-assign');
2
-
3
- var warn = console.warn;
4
- console.warn = function () {};
5
- var spawnSync = require('spawn-sync');
6
- console.warn = warn;
7
-
8
- module.exports = function crossSpawnSync(command, args, options) {
9
- if (!options) options = {};
10
- else options = assign({}, options);
11
- if (options.stdio === 'string') {
12
- options.stdio = 'pipe';
13
- options.encoding = 'utf-8';
14
- } else if (options.stdout === 'string') {
15
- options.stdout = 'pipe';
16
- options.encoding = 'utf-8';
17
- } else if (options.stderr === 'string') {
18
- options.stderr = 'pipe';
19
- options.encoding = 'utf-8';
20
- }
21
- var result = spawnSync(command, args, options);
22
- var err = result.status ? new Error('Non-zero exit code: ' + result.status) : null;
23
- if (result.stderr && result.stderr.length) {
24
- err = err || new Error('stderr has content');
25
- err.stderr = result.stderr;
26
- }
27
- if (err) throw err;
28
- return result;
29
- };