bililive-cli 1.8.0 → 1.9.1

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.
@@ -1,3359 +0,0 @@
1
- 'use strict';
2
-
3
- var os$3 = require('node:os');
4
- var path$5 = require('node:path');
5
- var fs$3 = require('node:fs');
6
- var crypto = require('node:crypto');
7
- var index = require('./index-CEo5tP7w.cjs');
8
- var require$$0$1 = require('fs');
9
- var require$$0 = require('path');
10
- var require$$0$2 = require('child_process');
11
- var require$$1 = require('os');
12
- var require$$1$1 = require('util');
13
- var require$$5 = require('assert');
14
- var require$$0$3 = require('events');
15
- var require$$0$5 = require('buffer');
16
- var require$$0$4 = require('stream');
17
- var process$2 = require('node:process');
18
- require('constants');
19
- require('url');
20
- require('node:child_process');
21
- require('node:fs/promises');
22
- require('node:util');
23
- require('node:events');
24
- require('ntsuspend');
25
- require('node:readline');
26
- require('http');
27
- require('https');
28
- require('zlib');
29
- require('net');
30
- require('dns');
31
- require('crypto');
32
- require('tls');
33
- require('punycode');
34
- require('tty');
35
- require('node:url');
36
- require('@napi-rs/canvas');
37
- require('node:stream');
38
- require('node:stream/promises');
39
- require('vm');
40
- require('node:net');
41
- require('node:https');
42
- require('node:buffer');
43
- require('node:zlib');
44
-
45
- var xdgTrashdir$1 = {exports: {}};
46
-
47
- var df$5 = {exports: {}};
48
-
49
- var execa$2 = {exports: {}};
50
-
51
- var crossSpawn$1 = {exports: {}};
52
-
53
- const isWindows = process.platform === 'win32' ||
54
- process.env.OSTYPE === 'cygwin' ||
55
- process.env.OSTYPE === 'msys';
56
-
57
- const path$4 = require$$0;
58
- const COLON = isWindows ? ';' : ':';
59
- const isexe = index.isexe_1;
60
-
61
- const getNotFoundError = (cmd) =>
62
- Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' });
63
-
64
- const getPathInfo = (cmd, opt) => {
65
- const colon = opt.colon || COLON;
66
-
67
- // If it has a slash, then we don't bother searching the pathenv.
68
- // just check the file itself, and that's it.
69
- const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? ['']
70
- : (
71
- [
72
- // windows always checks the cwd first
73
- ...(isWindows ? [process.cwd()] : []),
74
- ...(opt.path || process.env.PATH ||
75
- /* istanbul ignore next: very unusual */ '').split(colon),
76
- ]
77
- );
78
- const pathExtExe = isWindows
79
- ? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM'
80
- : '';
81
- const pathExt = isWindows ? pathExtExe.split(colon) : [''];
82
-
83
- if (isWindows) {
84
- if (cmd.indexOf('.') !== -1 && pathExt[0] !== '')
85
- pathExt.unshift('');
86
- }
87
-
88
- return {
89
- pathEnv,
90
- pathExt,
91
- pathExtExe,
92
- }
93
- };
94
-
95
- const which$1 = (cmd, opt, cb) => {
96
- if (typeof opt === 'function') {
97
- cb = opt;
98
- opt = {};
99
- }
100
- if (!opt)
101
- opt = {};
102
-
103
- const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
104
- const found = [];
105
-
106
- const step = i => new Promise((resolve, reject) => {
107
- if (i === pathEnv.length)
108
- return opt.all && found.length ? resolve(found)
109
- : reject(getNotFoundError(cmd))
110
-
111
- const ppRaw = pathEnv[i];
112
- const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
113
-
114
- const pCmd = path$4.join(pathPart, cmd);
115
- const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd
116
- : pCmd;
117
-
118
- resolve(subStep(p, i, 0));
119
- });
120
-
121
- const subStep = (p, i, ii) => new Promise((resolve, reject) => {
122
- if (ii === pathExt.length)
123
- return resolve(step(i + 1))
124
- const ext = pathExt[ii];
125
- isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
126
- if (!er && is) {
127
- if (opt.all)
128
- found.push(p + ext);
129
- else
130
- return resolve(p + ext)
131
- }
132
- return resolve(subStep(p, i, ii + 1))
133
- });
134
- });
135
-
136
- return cb ? step(0).then(res => cb(null, res), cb) : step(0)
137
- };
138
-
139
- const whichSync = (cmd, opt) => {
140
- opt = opt || {};
141
-
142
- const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
143
- const found = [];
144
-
145
- for (let i = 0; i < pathEnv.length; i ++) {
146
- const ppRaw = pathEnv[i];
147
- const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
148
-
149
- const pCmd = path$4.join(pathPart, cmd);
150
- const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd
151
- : pCmd;
152
-
153
- for (let j = 0; j < pathExt.length; j ++) {
154
- const cur = p + pathExt[j];
155
- try {
156
- const is = isexe.sync(cur, { pathExt: pathExtExe });
157
- if (is) {
158
- if (opt.all)
159
- found.push(cur);
160
- else
161
- return cur
162
- }
163
- } catch (ex) {}
164
- }
165
- }
166
-
167
- if (opt.all && found.length)
168
- return found
169
-
170
- if (opt.nothrow)
171
- return null
172
-
173
- throw getNotFoundError(cmd)
174
- };
175
-
176
- var which_1 = which$1;
177
- which$1.sync = whichSync;
178
-
179
- var pathKey$1 = {exports: {}};
180
-
181
- const pathKey = (options = {}) => {
182
- const environment = options.env || process.env;
183
- const platform = options.platform || process.platform;
184
-
185
- if (platform !== 'win32') {
186
- return 'PATH';
187
- }
188
-
189
- return Object.keys(environment).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';
190
- };
191
-
192
- pathKey$1.exports = pathKey;
193
- // TODO: Remove this for the next major release
194
- pathKey$1.exports.default = pathKey;
195
-
196
- var pathKeyExports = pathKey$1.exports;
197
-
198
- const path$3 = require$$0;
199
- const which = which_1;
200
- const getPathKey = pathKeyExports;
201
-
202
- function resolveCommandAttempt(parsed, withoutPathExt) {
203
- const env = parsed.options.env || process.env;
204
- const cwd = process.cwd();
205
- const hasCustomCwd = parsed.options.cwd != null;
206
- // Worker threads do not have process.chdir()
207
- const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled;
208
-
209
- // If a custom `cwd` was specified, we need to change the process cwd
210
- // because `which` will do stat calls but does not support a custom cwd
211
- if (shouldSwitchCwd) {
212
- try {
213
- process.chdir(parsed.options.cwd);
214
- } catch (err) {
215
- /* Empty */
216
- }
217
- }
218
-
219
- let resolved;
220
-
221
- try {
222
- resolved = which.sync(parsed.command, {
223
- path: env[getPathKey({ env })],
224
- pathExt: withoutPathExt ? path$3.delimiter : undefined,
225
- });
226
- } catch (e) {
227
- /* Empty */
228
- } finally {
229
- if (shouldSwitchCwd) {
230
- process.chdir(cwd);
231
- }
232
- }
233
-
234
- // If we successfully resolved, ensure that an absolute path is returned
235
- // Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it
236
- if (resolved) {
237
- resolved = path$3.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved);
238
- }
239
-
240
- return resolved;
241
- }
242
-
243
- function resolveCommand$1(parsed) {
244
- return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
245
- }
246
-
247
- var resolveCommand_1 = resolveCommand$1;
248
-
249
- var _escape = {};
250
-
251
- // See http://www.robvanderwoude.com/escapechars.php
252
- const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
253
-
254
- function escapeCommand(arg) {
255
- // Escape meta chars
256
- arg = arg.replace(metaCharsRegExp, '^$1');
257
-
258
- return arg;
259
- }
260
-
261
- function escapeArgument(arg, doubleEscapeMetaChars) {
262
- // Convert to string
263
- arg = `${arg}`;
264
-
265
- // Algorithm below is based on https://qntm.org/cmd
266
- // It's slightly altered to disable JS backtracking to avoid hanging on specially crafted input
267
- // Please see https://github.com/moxystudio/node-cross-spawn/pull/160 for more information
268
-
269
- // Sequence of backslashes followed by a double quote:
270
- // double up all the backslashes and escape the double quote
271
- arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
272
-
273
- // Sequence of backslashes followed by the end of the string
274
- // (which will become a double quote later):
275
- // double up all the backslashes
276
- arg = arg.replace(/(?=(\\+?)?)\1$/, '$1$1');
277
-
278
- // All other backslashes occur literally
279
-
280
- // Quote the whole thing:
281
- arg = `"${arg}"`;
282
-
283
- // Escape meta chars
284
- arg = arg.replace(metaCharsRegExp, '^$1');
285
-
286
- // Double escape meta chars if necessary
287
- if (doubleEscapeMetaChars) {
288
- arg = arg.replace(metaCharsRegExp, '^$1');
289
- }
290
-
291
- return arg;
292
- }
293
-
294
- _escape.command = escapeCommand;
295
- _escape.argument = escapeArgument;
296
-
297
- var shebangRegex$1 = /^#!(.*)/;
298
-
299
- const shebangRegex = shebangRegex$1;
300
-
301
- var shebangCommand$1 = (string = '') => {
302
- const match = string.match(shebangRegex);
303
-
304
- if (!match) {
305
- return null;
306
- }
307
-
308
- const [path, argument] = match[0].replace(/#! ?/, '').split(' ');
309
- const binary = path.split('/').pop();
310
-
311
- if (binary === 'env') {
312
- return argument;
313
- }
314
-
315
- return argument ? `${binary} ${argument}` : binary;
316
- };
317
-
318
- const fs$2 = require$$0$1;
319
- const shebangCommand = shebangCommand$1;
320
-
321
- function readShebang$1(command) {
322
- // Read the first 150 bytes from the file
323
- const size = 150;
324
- const buffer = Buffer.alloc(size);
325
-
326
- let fd;
327
-
328
- try {
329
- fd = fs$2.openSync(command, 'r');
330
- fs$2.readSync(fd, buffer, 0, size, 0);
331
- fs$2.closeSync(fd);
332
- } catch (e) { /* Empty */ }
333
-
334
- // Attempt to extract shebang (null is returned if not a shebang)
335
- return shebangCommand(buffer.toString());
336
- }
337
-
338
- var readShebang_1 = readShebang$1;
339
-
340
- const path$2 = require$$0;
341
- const resolveCommand = resolveCommand_1;
342
- const escape = _escape;
343
- const readShebang = readShebang_1;
344
-
345
- const isWin$2 = process.platform === 'win32';
346
- const isExecutableRegExp = /\.(?:com|exe)$/i;
347
- const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
348
-
349
- function detectShebang(parsed) {
350
- parsed.file = resolveCommand(parsed);
351
-
352
- const shebang = parsed.file && readShebang(parsed.file);
353
-
354
- if (shebang) {
355
- parsed.args.unshift(parsed.file);
356
- parsed.command = shebang;
357
-
358
- return resolveCommand(parsed);
359
- }
360
-
361
- return parsed.file;
362
- }
363
-
364
- function parseNonShell(parsed) {
365
- if (!isWin$2) {
366
- return parsed;
367
- }
368
-
369
- // Detect & add support for shebangs
370
- const commandFile = detectShebang(parsed);
371
-
372
- // We don't need a shell if the command filename is an executable
373
- const needsShell = !isExecutableRegExp.test(commandFile);
374
-
375
- // If a shell is required, use cmd.exe and take care of escaping everything correctly
376
- // Note that `forceShell` is an hidden option used only in tests
377
- if (parsed.options.forceShell || needsShell) {
378
- // Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`
379
- // The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument
380
- // Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,
381
- // we need to double escape them
382
- const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
383
-
384
- // Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\bar)
385
- // This is necessary otherwise it will always fail with ENOENT in those cases
386
- parsed.command = path$2.normalize(parsed.command);
387
-
388
- // Escape command & arguments
389
- parsed.command = escape.command(parsed.command);
390
- parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
391
-
392
- const shellCommand = [parsed.command].concat(parsed.args).join(' ');
393
-
394
- parsed.args = ['/d', '/s', '/c', `"${shellCommand}"`];
395
- parsed.command = process.env.comspec || 'cmd.exe';
396
- parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped
397
- }
398
-
399
- return parsed;
400
- }
401
-
402
- function parse$1(command, args, options) {
403
- // Normalize arguments, similar to nodejs
404
- if (args && !Array.isArray(args)) {
405
- options = args;
406
- args = null;
407
- }
408
-
409
- args = args ? args.slice(0) : []; // Clone array to avoid changing the original
410
- options = Object.assign({}, options); // Clone object to avoid changing the original
411
-
412
- // Build our parsed object
413
- const parsed = {
414
- command,
415
- args,
416
- options,
417
- file: undefined,
418
- original: {
419
- command,
420
- args,
421
- },
422
- };
423
-
424
- // Delegate further parsing to shell or non-shell
425
- return options.shell ? parsed : parseNonShell(parsed);
426
- }
427
-
428
- var parse_1 = parse$1;
429
-
430
- const isWin$1 = process.platform === 'win32';
431
-
432
- function notFoundError(original, syscall) {
433
- return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
434
- code: 'ENOENT',
435
- errno: 'ENOENT',
436
- syscall: `${syscall} ${original.command}`,
437
- path: original.command,
438
- spawnargs: original.args,
439
- });
440
- }
441
-
442
- function hookChildProcess(cp, parsed) {
443
- if (!isWin$1) {
444
- return;
445
- }
446
-
447
- const originalEmit = cp.emit;
448
-
449
- cp.emit = function (name, arg1) {
450
- // If emitting "exit" event and exit code is 1, we need to check if
451
- // the command exists and emit an "error" instead
452
- // See https://github.com/IndigoUnited/node-cross-spawn/issues/16
453
- if (name === 'exit') {
454
- const err = verifyENOENT(arg1, parsed);
455
-
456
- if (err) {
457
- return originalEmit.call(cp, 'error', err);
458
- }
459
- }
460
-
461
- return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params
462
- };
463
- }
464
-
465
- function verifyENOENT(status, parsed) {
466
- if (isWin$1 && status === 1 && !parsed.file) {
467
- return notFoundError(parsed.original, 'spawn');
468
- }
469
-
470
- return null;
471
- }
472
-
473
- function verifyENOENTSync(status, parsed) {
474
- if (isWin$1 && status === 1 && !parsed.file) {
475
- return notFoundError(parsed.original, 'spawnSync');
476
- }
477
-
478
- return null;
479
- }
480
-
481
- var enoent$1 = {
482
- hookChildProcess,
483
- verifyENOENT,
484
- verifyENOENTSync,
485
- notFoundError,
486
- };
487
-
488
- const cp = require$$0$2;
489
- const parse = parse_1;
490
- const enoent = enoent$1;
491
-
492
- function spawn(command, args, options) {
493
- // Parse the arguments
494
- const parsed = parse(command, args, options);
495
-
496
- // Spawn the child process
497
- const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
498
-
499
- // Hook into child process "exit" event to emit an error if the command
500
- // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
501
- enoent.hookChildProcess(spawned, parsed);
502
-
503
- return spawned;
504
- }
505
-
506
- function spawnSync(command, args, options) {
507
- // Parse the arguments
508
- const parsed = parse(command, args, options);
509
-
510
- // Spawn the child process
511
- const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
512
-
513
- // Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
514
- result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
515
-
516
- return result;
517
- }
518
-
519
- crossSpawn$1.exports = spawn;
520
- crossSpawn$1.exports.spawn = spawn;
521
- crossSpawn$1.exports.sync = spawnSync;
522
-
523
- crossSpawn$1.exports._parse = parse;
524
- crossSpawn$1.exports._enoent = enoent;
525
-
526
- var crossSpawnExports = crossSpawn$1.exports;
527
-
528
- var stripFinalNewline$1 = input => {
529
- const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
530
- const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
531
-
532
- if (input[input.length - 1] === LF) {
533
- input = input.slice(0, input.length - 1);
534
- }
535
-
536
- if (input[input.length - 1] === CR) {
537
- input = input.slice(0, input.length - 1);
538
- }
539
-
540
- return input;
541
- };
542
-
543
- var npmRunPath$1 = {exports: {}};
544
-
545
- npmRunPath$1.exports;
546
-
547
- (function (module) {
548
- const path = require$$0;
549
- const pathKey = pathKeyExports;
550
-
551
- const npmRunPath = options => {
552
- options = {
553
- cwd: process.cwd(),
554
- path: process.env[pathKey()],
555
- ...options
556
- };
557
-
558
- let previous;
559
- let cwdPath = path.resolve(options.cwd);
560
- const result = [];
561
-
562
- while (previous !== cwdPath) {
563
- result.push(path.join(cwdPath, 'node_modules/.bin'));
564
- previous = cwdPath;
565
- cwdPath = path.resolve(cwdPath, '..');
566
- }
567
-
568
- // Ensure the running `node` binary is used
569
- result.push(path.dirname(process.execPath));
570
-
571
- return result.concat(options.path).join(path.delimiter);
572
- };
573
-
574
- module.exports = npmRunPath;
575
- // TODO: Remove this for the next major release
576
- module.exports.default = npmRunPath;
577
-
578
- module.exports.env = options => {
579
- options = {
580
- env: process.env,
581
- ...options
582
- };
583
-
584
- const env = {...options.env};
585
- const path = pathKey({env});
586
-
587
- options.path = env[path];
588
- env[path] = module.exports(options);
589
-
590
- return env;
591
- };
592
- } (npmRunPath$1));
593
-
594
- var npmRunPathExports = npmRunPath$1.exports;
595
-
596
- var onetime$2 = {exports: {}};
597
-
598
- var mimicFn$2 = {exports: {}};
599
-
600
- const mimicFn$1 = (to, from) => {
601
- for (const prop of Reflect.ownKeys(from)) {
602
- Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
603
- }
604
-
605
- return to;
606
- };
607
-
608
- mimicFn$2.exports = mimicFn$1;
609
- // TODO: Remove this for the next major release
610
- mimicFn$2.exports.default = mimicFn$1;
611
-
612
- var mimicFnExports = mimicFn$2.exports;
613
-
614
- const mimicFn = mimicFnExports;
615
-
616
- const calledFunctions = new WeakMap();
617
-
618
- const onetime$1 = (function_, options = {}) => {
619
- if (typeof function_ !== 'function') {
620
- throw new TypeError('Expected a function');
621
- }
622
-
623
- let returnValue;
624
- let callCount = 0;
625
- const functionName = function_.displayName || function_.name || '<anonymous>';
626
-
627
- const onetime = function (...arguments_) {
628
- calledFunctions.set(onetime, ++callCount);
629
-
630
- if (callCount === 1) {
631
- returnValue = function_.apply(this, arguments_);
632
- function_ = null;
633
- } else if (options.throw === true) {
634
- throw new Error(`Function \`${functionName}\` can only be called once`);
635
- }
636
-
637
- return returnValue;
638
- };
639
-
640
- mimicFn(onetime, function_);
641
- calledFunctions.set(onetime, callCount);
642
-
643
- return onetime;
644
- };
645
-
646
- onetime$2.exports = onetime$1;
647
- // TODO: Remove this for the next major release
648
- onetime$2.exports.default = onetime$1;
649
-
650
- onetime$2.exports.callCount = function_ => {
651
- if (!calledFunctions.has(function_)) {
652
- throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
653
- }
654
-
655
- return calledFunctions.get(function_);
656
- };
657
-
658
- var onetimeExports = onetime$2.exports;
659
-
660
- const os$2 = require$$1;
661
- const util = require$$1$1;
662
-
663
- const getCode = (error, code) => {
664
- if (error && error.code) {
665
- return [error.code, os$2.constants.errno[error.code]];
666
- }
667
-
668
- if (Number.isInteger(code)) {
669
- return [util.getSystemErrorName(-code), code];
670
- }
671
-
672
- return [];
673
- };
674
-
675
- const getErrorPrefix = ({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled}) => {
676
- if (timedOut) {
677
- return `timed out after ${timeout} milliseconds`;
678
- }
679
-
680
- if (isCanceled) {
681
- return 'was canceled';
682
- }
683
-
684
- if (signal) {
685
- return `was killed with ${signal}`;
686
- }
687
-
688
- if (exitCode !== undefined) {
689
- return `failed with exit code ${exitCode} (${exitCodeName})`;
690
- }
691
-
692
- return 'failed';
693
- };
694
-
695
- const makeError$1 = ({
696
- stdout,
697
- stderr,
698
- all,
699
- error,
700
- signal,
701
- code,
702
- command,
703
- timedOut,
704
- isCanceled,
705
- killed,
706
- parsed: {options: {timeout}}
707
- }) => {
708
- const [exitCodeName, exitCode] = getCode(error, code);
709
-
710
- const prefix = getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled});
711
- const message = `Command ${prefix}: ${command}`;
712
-
713
- if (error instanceof Error) {
714
- error.originalMessage = error.message;
715
- error.message = `${message}\n${error.message}`;
716
- } else {
717
- error = new Error(message);
718
- }
719
-
720
- error.command = command;
721
- delete error.code;
722
- error.exitCode = exitCode;
723
- error.exitCodeName = exitCodeName;
724
- error.stdout = stdout;
725
- error.stderr = stderr;
726
-
727
- if (all !== undefined) {
728
- error.all = all;
729
- }
730
-
731
- if ('bufferedData' in error) {
732
- delete error.bufferedData;
733
- }
734
-
735
- error.failed = true;
736
- error.timedOut = Boolean(timedOut);
737
- error.isCanceled = isCanceled;
738
- error.killed = killed && !timedOut;
739
- // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize
740
- // it to `undefined`
741
- error.signal = signal || undefined;
742
-
743
- return error;
744
- };
745
-
746
- var error = makeError$1;
747
-
748
- var stdio = {exports: {}};
749
-
750
- const aliases = ['stdin', 'stdout', 'stderr'];
751
-
752
- const hasAlias = opts => aliases.some(alias => opts[alias] !== undefined);
753
-
754
- const normalizeStdio$1 = opts => {
755
- if (!opts) {
756
- return;
757
- }
758
-
759
- const {stdio} = opts;
760
-
761
- if (stdio === undefined) {
762
- return aliases.map(alias => opts[alias]);
763
- }
764
-
765
- if (hasAlias(opts)) {
766
- throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
767
- }
768
-
769
- if (typeof stdio === 'string') {
770
- return stdio;
771
- }
772
-
773
- if (!Array.isArray(stdio)) {
774
- throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
775
- }
776
-
777
- const length = Math.max(stdio.length, aliases.length);
778
- return Array.from({length}, (value, index) => stdio[index]);
779
- };
780
-
781
- stdio.exports = normalizeStdio$1;
782
-
783
- // `ipc` is pushed unless it is already present
784
- stdio.exports.node = opts => {
785
- const stdio = normalizeStdio$1(opts);
786
-
787
- if (stdio === 'ipc') {
788
- return 'ipc';
789
- }
790
-
791
- if (stdio === undefined || typeof stdio === 'string') {
792
- return [stdio, stdio, stdio, 'ipc'];
793
- }
794
-
795
- if (stdio.includes('ipc')) {
796
- return stdio;
797
- }
798
-
799
- return [...stdio, 'ipc'];
800
- };
801
-
802
- var stdioExports = stdio.exports;
803
-
804
- var signalExit = {exports: {}};
805
-
806
- var signals$1 = {exports: {}};
807
-
808
- var hasRequiredSignals;
809
-
810
- function requireSignals () {
811
- if (hasRequiredSignals) return signals$1.exports;
812
- hasRequiredSignals = 1;
813
- (function (module) {
814
- // This is not the set of all possible signals.
815
- //
816
- // It IS, however, the set of all signals that trigger
817
- // an exit on either Linux or BSD systems. Linux is a
818
- // superset of the signal names supported on BSD, and
819
- // the unknown signals just fail to register, so we can
820
- // catch that easily enough.
821
- //
822
- // Don't bother with SIGKILL. It's uncatchable, which
823
- // means that we can't fire any callbacks anyway.
824
- //
825
- // If a user does happen to register a handler on a non-
826
- // fatal signal like SIGWINCH or something, and then
827
- // exit, it'll end up firing `process.emit('exit')`, so
828
- // the handler will be fired anyway.
829
- //
830
- // SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
831
- // artificially, inherently leave the process in a
832
- // state from which it is not safe to try and enter JS
833
- // listeners.
834
- module.exports = [
835
- 'SIGABRT',
836
- 'SIGALRM',
837
- 'SIGHUP',
838
- 'SIGINT',
839
- 'SIGTERM'
840
- ];
841
-
842
- if (process.platform !== 'win32') {
843
- module.exports.push(
844
- 'SIGVTALRM',
845
- 'SIGXCPU',
846
- 'SIGXFSZ',
847
- 'SIGUSR2',
848
- 'SIGTRAP',
849
- 'SIGSYS',
850
- 'SIGQUIT',
851
- 'SIGIOT'
852
- // should detect profiler and enable/disable accordingly.
853
- // see #21
854
- // 'SIGPROF'
855
- );
856
- }
857
-
858
- if (process.platform === 'linux') {
859
- module.exports.push(
860
- 'SIGIO',
861
- 'SIGPOLL',
862
- 'SIGPWR',
863
- 'SIGSTKFLT',
864
- 'SIGUNUSED'
865
- );
866
- }
867
- } (signals$1));
868
- return signals$1.exports;
869
- }
870
-
871
- // Note: since nyc uses this module to output coverage, any lines
872
- // that are in the direct sync flow of nyc's outputCoverage are
873
- // ignored, since we can never get coverage for them.
874
- // grab a reference to node's real process object right away
875
- var process$1 = index.commonjsGlobal.process;
876
-
877
- const processOk = function (process) {
878
- return process &&
879
- typeof process === 'object' &&
880
- typeof process.removeListener === 'function' &&
881
- typeof process.emit === 'function' &&
882
- typeof process.reallyExit === 'function' &&
883
- typeof process.listeners === 'function' &&
884
- typeof process.kill === 'function' &&
885
- typeof process.pid === 'number' &&
886
- typeof process.on === 'function'
887
- };
888
-
889
- // some kind of non-node environment, just no-op
890
- /* istanbul ignore if */
891
- if (!processOk(process$1)) {
892
- signalExit.exports = function () {
893
- return function () {}
894
- };
895
- } else {
896
- var assert = require$$5;
897
- var signals = requireSignals();
898
- var isWin = /^win/i.test(process$1.platform);
899
-
900
- var EE = require$$0$3;
901
- /* istanbul ignore if */
902
- if (typeof EE !== 'function') {
903
- EE = EE.EventEmitter;
904
- }
905
-
906
- var emitter;
907
- if (process$1.__signal_exit_emitter__) {
908
- emitter = process$1.__signal_exit_emitter__;
909
- } else {
910
- emitter = process$1.__signal_exit_emitter__ = new EE();
911
- emitter.count = 0;
912
- emitter.emitted = {};
913
- }
914
-
915
- // Because this emitter is a global, we have to check to see if a
916
- // previous version of this library failed to enable infinite listeners.
917
- // I know what you're about to say. But literally everything about
918
- // signal-exit is a compromise with evil. Get used to it.
919
- if (!emitter.infinite) {
920
- emitter.setMaxListeners(Infinity);
921
- emitter.infinite = true;
922
- }
923
-
924
- signalExit.exports = function (cb, opts) {
925
- /* istanbul ignore if */
926
- if (!processOk(index.commonjsGlobal.process)) {
927
- return function () {}
928
- }
929
- assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
930
-
931
- if (loaded === false) {
932
- load();
933
- }
934
-
935
- var ev = 'exit';
936
- if (opts && opts.alwaysLast) {
937
- ev = 'afterexit';
938
- }
939
-
940
- var remove = function () {
941
- emitter.removeListener(ev, cb);
942
- if (emitter.listeners('exit').length === 0 &&
943
- emitter.listeners('afterexit').length === 0) {
944
- unload();
945
- }
946
- };
947
- emitter.on(ev, cb);
948
-
949
- return remove
950
- };
951
-
952
- var unload = function unload () {
953
- if (!loaded || !processOk(index.commonjsGlobal.process)) {
954
- return
955
- }
956
- loaded = false;
957
-
958
- signals.forEach(function (sig) {
959
- try {
960
- process$1.removeListener(sig, sigListeners[sig]);
961
- } catch (er) {}
962
- });
963
- process$1.emit = originalProcessEmit;
964
- process$1.reallyExit = originalProcessReallyExit;
965
- emitter.count -= 1;
966
- };
967
- signalExit.exports.unload = unload;
968
-
969
- var emit = function emit (event, code, signal) {
970
- /* istanbul ignore if */
971
- if (emitter.emitted[event]) {
972
- return
973
- }
974
- emitter.emitted[event] = true;
975
- emitter.emit(event, code, signal);
976
- };
977
-
978
- // { <signal>: <listener fn>, ... }
979
- var sigListeners = {};
980
- signals.forEach(function (sig) {
981
- sigListeners[sig] = function listener () {
982
- /* istanbul ignore if */
983
- if (!processOk(index.commonjsGlobal.process)) {
984
- return
985
- }
986
- // If there are no other listeners, an exit is coming!
987
- // Simplest way: remove us and then re-send the signal.
988
- // We know that this will kill the process, so we can
989
- // safely emit now.
990
- var listeners = process$1.listeners(sig);
991
- if (listeners.length === emitter.count) {
992
- unload();
993
- emit('exit', null, sig);
994
- /* istanbul ignore next */
995
- emit('afterexit', null, sig);
996
- /* istanbul ignore next */
997
- if (isWin && sig === 'SIGHUP') {
998
- // "SIGHUP" throws an `ENOSYS` error on Windows,
999
- // so use a supported signal instead
1000
- sig = 'SIGINT';
1001
- }
1002
- /* istanbul ignore next */
1003
- process$1.kill(process$1.pid, sig);
1004
- }
1005
- };
1006
- });
1007
-
1008
- signalExit.exports.signals = function () {
1009
- return signals
1010
- };
1011
-
1012
- var loaded = false;
1013
-
1014
- var load = function load () {
1015
- if (loaded || !processOk(index.commonjsGlobal.process)) {
1016
- return
1017
- }
1018
- loaded = true;
1019
-
1020
- // This is the number of onSignalExit's that are in play.
1021
- // It's important so that we can count the correct number of
1022
- // listeners on signals, and don't wait for the other one to
1023
- // handle it instead of us.
1024
- emitter.count += 1;
1025
-
1026
- signals = signals.filter(function (sig) {
1027
- try {
1028
- process$1.on(sig, sigListeners[sig]);
1029
- return true
1030
- } catch (er) {
1031
- return false
1032
- }
1033
- });
1034
-
1035
- process$1.emit = processEmit;
1036
- process$1.reallyExit = processReallyExit;
1037
- };
1038
- signalExit.exports.load = load;
1039
-
1040
- var originalProcessReallyExit = process$1.reallyExit;
1041
- var processReallyExit = function processReallyExit (code) {
1042
- /* istanbul ignore if */
1043
- if (!processOk(index.commonjsGlobal.process)) {
1044
- return
1045
- }
1046
- process$1.exitCode = code || /* istanbul ignore next */ 0;
1047
- emit('exit', process$1.exitCode, null);
1048
- /* istanbul ignore next */
1049
- emit('afterexit', process$1.exitCode, null);
1050
- /* istanbul ignore next */
1051
- originalProcessReallyExit.call(process$1, process$1.exitCode);
1052
- };
1053
-
1054
- var originalProcessEmit = process$1.emit;
1055
- var processEmit = function processEmit (ev, arg) {
1056
- if (ev === 'exit' && processOk(index.commonjsGlobal.process)) {
1057
- /* istanbul ignore else */
1058
- if (arg !== undefined) {
1059
- process$1.exitCode = arg;
1060
- }
1061
- var ret = originalProcessEmit.apply(this, arguments);
1062
- /* istanbul ignore next */
1063
- emit('exit', process$1.exitCode, null);
1064
- /* istanbul ignore next */
1065
- emit('afterexit', process$1.exitCode, null);
1066
- /* istanbul ignore next */
1067
- return ret
1068
- } else {
1069
- return originalProcessEmit.apply(this, arguments)
1070
- }
1071
- };
1072
- }
1073
-
1074
- var signalExitExports = signalExit.exports;
1075
-
1076
- var pFinally$1 = async (
1077
- promise,
1078
- onFinally = (() => {})
1079
- ) => {
1080
- let value;
1081
- try {
1082
- value = await promise;
1083
- } catch (error) {
1084
- await onFinally();
1085
- throw error;
1086
- }
1087
-
1088
- await onFinally();
1089
- return value;
1090
- };
1091
-
1092
- const os$1 = require$$1;
1093
- const onExit = signalExitExports;
1094
- const pFinally = pFinally$1;
1095
-
1096
- const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
1097
-
1098
- // Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
1099
- const spawnedKill$1 = (kill, signal = 'SIGTERM', options = {}) => {
1100
- const killResult = kill(signal);
1101
- setKillTimeout(kill, signal, options, killResult);
1102
- return killResult;
1103
- };
1104
-
1105
- const setKillTimeout = (kill, signal, options, killResult) => {
1106
- if (!shouldForceKill(signal, options, killResult)) {
1107
- return;
1108
- }
1109
-
1110
- const timeout = getForceKillAfterTimeout(options);
1111
- setTimeout(() => {
1112
- kill('SIGKILL');
1113
- }, timeout).unref();
1114
- };
1115
-
1116
- const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {
1117
- return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
1118
- };
1119
-
1120
- const isSigterm = signal => {
1121
- return signal === os$1.constants.signals.SIGTERM ||
1122
- (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
1123
- };
1124
-
1125
- const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {
1126
- if (forceKillAfterTimeout === true) {
1127
- return DEFAULT_FORCE_KILL_TIMEOUT;
1128
- }
1129
-
1130
- if (!Number.isInteger(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
1131
- throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
1132
- }
1133
-
1134
- return forceKillAfterTimeout;
1135
- };
1136
-
1137
- // `childProcess.cancel()`
1138
- const spawnedCancel$1 = (spawned, context) => {
1139
- const killResult = spawned.kill();
1140
-
1141
- if (killResult) {
1142
- context.isCanceled = true;
1143
- }
1144
- };
1145
-
1146
- const timeoutKill = (spawned, signal, reject) => {
1147
- spawned.kill(signal);
1148
- reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));
1149
- };
1150
-
1151
- // `timeout` option handling
1152
- const setupTimeout$1 = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => {
1153
- if (timeout === 0 || timeout === undefined) {
1154
- return spawnedPromise;
1155
- }
1156
-
1157
- if (!Number.isInteger(timeout) || timeout < 0) {
1158
- throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
1159
- }
1160
-
1161
- let timeoutId;
1162
- const timeoutPromise = new Promise((resolve, reject) => {
1163
- timeoutId = setTimeout(() => {
1164
- timeoutKill(spawned, killSignal, reject);
1165
- }, timeout);
1166
- });
1167
-
1168
- const safeSpawnedPromise = pFinally(spawnedPromise, () => {
1169
- clearTimeout(timeoutId);
1170
- });
1171
-
1172
- return Promise.race([timeoutPromise, safeSpawnedPromise]);
1173
- };
1174
-
1175
- // `cleanup` option handling
1176
- const setExitHandler$1 = (spawned, {cleanup, detached}, timedPromise) => {
1177
- if (!cleanup || detached) {
1178
- return timedPromise;
1179
- }
1180
-
1181
- const removeExitHandler = onExit(() => {
1182
- spawned.kill();
1183
- });
1184
-
1185
- // TODO: Use native "finally" syntax when targeting Node.js 10
1186
- return pFinally(timedPromise, removeExitHandler);
1187
- };
1188
-
1189
- var kill = {
1190
- spawnedKill: spawnedKill$1,
1191
- spawnedCancel: spawnedCancel$1,
1192
- setupTimeout: setupTimeout$1,
1193
- setExitHandler: setExitHandler$1
1194
- };
1195
-
1196
- const isStream$1 = stream =>
1197
- stream !== null &&
1198
- typeof stream === 'object' &&
1199
- typeof stream.pipe === 'function';
1200
-
1201
- isStream$1.writable = stream =>
1202
- isStream$1(stream) &&
1203
- stream.writable !== false &&
1204
- typeof stream._write === 'function' &&
1205
- typeof stream._writableState === 'object';
1206
-
1207
- isStream$1.readable = stream =>
1208
- isStream$1(stream) &&
1209
- stream.readable !== false &&
1210
- typeof stream._read === 'function' &&
1211
- typeof stream._readableState === 'object';
1212
-
1213
- isStream$1.duplex = stream =>
1214
- isStream$1.writable(stream) &&
1215
- isStream$1.readable(stream);
1216
-
1217
- isStream$1.transform = stream =>
1218
- isStream$1.duplex(stream) &&
1219
- typeof stream._transform === 'function';
1220
-
1221
- var isStream_1 = isStream$1;
1222
-
1223
- var getStream$2 = {exports: {}};
1224
-
1225
- var once$1 = index.onceExports;
1226
-
1227
- var noop$1 = function() {};
1228
-
1229
- var isRequest$1 = function(stream) {
1230
- return stream.setHeader && typeof stream.abort === 'function';
1231
- };
1232
-
1233
- var isChildProcess = function(stream) {
1234
- return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
1235
- };
1236
-
1237
- var eos$1 = function(stream, opts, callback) {
1238
- if (typeof opts === 'function') return eos$1(stream, null, opts);
1239
- if (!opts) opts = {};
1240
-
1241
- callback = once$1(callback || noop$1);
1242
-
1243
- var ws = stream._writableState;
1244
- var rs = stream._readableState;
1245
- var readable = opts.readable || (opts.readable !== false && stream.readable);
1246
- var writable = opts.writable || (opts.writable !== false && stream.writable);
1247
- var cancelled = false;
1248
-
1249
- var onlegacyfinish = function() {
1250
- if (!stream.writable) onfinish();
1251
- };
1252
-
1253
- var onfinish = function() {
1254
- writable = false;
1255
- if (!readable) callback.call(stream);
1256
- };
1257
-
1258
- var onend = function() {
1259
- readable = false;
1260
- if (!writable) callback.call(stream);
1261
- };
1262
-
1263
- var onexit = function(exitCode) {
1264
- callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
1265
- };
1266
-
1267
- var onerror = function(err) {
1268
- callback.call(stream, err);
1269
- };
1270
-
1271
- var onclose = function() {
1272
- process.nextTick(onclosenexttick);
1273
- };
1274
-
1275
- var onclosenexttick = function() {
1276
- if (cancelled) return;
1277
- if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
1278
- if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
1279
- };
1280
-
1281
- var onrequest = function() {
1282
- stream.req.on('finish', onfinish);
1283
- };
1284
-
1285
- if (isRequest$1(stream)) {
1286
- stream.on('complete', onfinish);
1287
- stream.on('abort', onclose);
1288
- if (stream.req) onrequest();
1289
- else stream.on('request', onrequest);
1290
- } else if (writable && !ws) { // legacy streams
1291
- stream.on('end', onlegacyfinish);
1292
- stream.on('close', onlegacyfinish);
1293
- }
1294
-
1295
- if (isChildProcess(stream)) stream.on('exit', onexit);
1296
-
1297
- stream.on('end', onend);
1298
- stream.on('finish', onfinish);
1299
- if (opts.error !== false) stream.on('error', onerror);
1300
- stream.on('close', onclose);
1301
-
1302
- return function() {
1303
- cancelled = true;
1304
- stream.removeListener('complete', onfinish);
1305
- stream.removeListener('abort', onclose);
1306
- stream.removeListener('request', onrequest);
1307
- if (stream.req) stream.req.removeListener('finish', onfinish);
1308
- stream.removeListener('end', onlegacyfinish);
1309
- stream.removeListener('close', onlegacyfinish);
1310
- stream.removeListener('finish', onfinish);
1311
- stream.removeListener('exit', onexit);
1312
- stream.removeListener('end', onend);
1313
- stream.removeListener('error', onerror);
1314
- stream.removeListener('close', onclose);
1315
- };
1316
- };
1317
-
1318
- var endOfStream = eos$1;
1319
-
1320
- var once = index.onceExports;
1321
- var eos = endOfStream;
1322
- var fs$1;
1323
-
1324
- try {
1325
- fs$1 = require('fs'); // we only need fs to get the ReadStream and WriteStream prototypes
1326
- } catch (e) {}
1327
-
1328
- var noop = function () {};
1329
- var ancient = /^v?\.0/.test(process.version);
1330
-
1331
- var isFn = function (fn) {
1332
- return typeof fn === 'function'
1333
- };
1334
-
1335
- var isFS = function (stream) {
1336
- if (!ancient) return false // newer node version do not need to care about fs is a special way
1337
- if (!fs$1) return false // browser
1338
- return (stream instanceof (fs$1.ReadStream || noop) || stream instanceof (fs$1.WriteStream || noop)) && isFn(stream.close)
1339
- };
1340
-
1341
- var isRequest = function (stream) {
1342
- return stream.setHeader && isFn(stream.abort)
1343
- };
1344
-
1345
- var destroyer = function (stream, reading, writing, callback) {
1346
- callback = once(callback);
1347
-
1348
- var closed = false;
1349
- stream.on('close', function () {
1350
- closed = true;
1351
- });
1352
-
1353
- eos(stream, {readable: reading, writable: writing}, function (err) {
1354
- if (err) return callback(err)
1355
- closed = true;
1356
- callback();
1357
- });
1358
-
1359
- var destroyed = false;
1360
- return function (err) {
1361
- if (closed) return
1362
- if (destroyed) return
1363
- destroyed = true;
1364
-
1365
- if (isFS(stream)) return stream.close(noop) // use close for fs streams to avoid fd leaks
1366
- if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want
1367
-
1368
- if (isFn(stream.destroy)) return stream.destroy()
1369
-
1370
- callback(err || new Error('stream was destroyed'));
1371
- }
1372
- };
1373
-
1374
- var call = function (fn) {
1375
- fn();
1376
- };
1377
-
1378
- var pipe = function (from, to) {
1379
- return from.pipe(to)
1380
- };
1381
-
1382
- var pump$1 = function () {
1383
- var streams = Array.prototype.slice.call(arguments);
1384
- var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop;
1385
-
1386
- if (Array.isArray(streams[0])) streams = streams[0];
1387
- if (streams.length < 2) throw new Error('pump requires two streams per minimum')
1388
-
1389
- var error;
1390
- var destroys = streams.map(function (stream, i) {
1391
- var reading = i < streams.length - 1;
1392
- var writing = i > 0;
1393
- return destroyer(stream, reading, writing, function (err) {
1394
- if (!error) error = err;
1395
- if (err) destroys.forEach(call);
1396
- if (reading) return
1397
- destroys.forEach(call);
1398
- callback(error);
1399
- })
1400
- });
1401
-
1402
- return streams.reduce(pipe)
1403
- };
1404
-
1405
- var pump_1 = pump$1;
1406
-
1407
- const {PassThrough: PassThroughStream} = require$$0$4;
1408
-
1409
- var bufferStream$1 = options => {
1410
- options = {...options};
1411
-
1412
- const {array} = options;
1413
- let {encoding} = options;
1414
- const isBuffer = encoding === 'buffer';
1415
- let objectMode = false;
1416
-
1417
- if (array) {
1418
- objectMode = !(encoding || isBuffer);
1419
- } else {
1420
- encoding = encoding || 'utf8';
1421
- }
1422
-
1423
- if (isBuffer) {
1424
- encoding = null;
1425
- }
1426
-
1427
- const stream = new PassThroughStream({objectMode});
1428
-
1429
- if (encoding) {
1430
- stream.setEncoding(encoding);
1431
- }
1432
-
1433
- let length = 0;
1434
- const chunks = [];
1435
-
1436
- stream.on('data', chunk => {
1437
- chunks.push(chunk);
1438
-
1439
- if (objectMode) {
1440
- length = chunks.length;
1441
- } else {
1442
- length += chunk.length;
1443
- }
1444
- });
1445
-
1446
- stream.getBufferedValue = () => {
1447
- if (array) {
1448
- return chunks;
1449
- }
1450
-
1451
- return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
1452
- };
1453
-
1454
- stream.getBufferedLength = () => length;
1455
-
1456
- return stream;
1457
- };
1458
-
1459
- const {constants: BufferConstants} = require$$0$5;
1460
- const pump = pump_1;
1461
- const bufferStream = bufferStream$1;
1462
-
1463
- class MaxBufferError extends Error {
1464
- constructor() {
1465
- super('maxBuffer exceeded');
1466
- this.name = 'MaxBufferError';
1467
- }
1468
- }
1469
-
1470
- async function getStream$1(inputStream, options) {
1471
- if (!inputStream) {
1472
- return Promise.reject(new Error('Expected a stream'));
1473
- }
1474
-
1475
- options = {
1476
- maxBuffer: Infinity,
1477
- ...options
1478
- };
1479
-
1480
- const {maxBuffer} = options;
1481
-
1482
- let stream;
1483
- await new Promise((resolve, reject) => {
1484
- const rejectPromise = error => {
1485
- // Don't retrieve an oversized buffer.
1486
- if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
1487
- error.bufferedData = stream.getBufferedValue();
1488
- }
1489
-
1490
- reject(error);
1491
- };
1492
-
1493
- stream = pump(inputStream, bufferStream(options), error => {
1494
- if (error) {
1495
- rejectPromise(error);
1496
- return;
1497
- }
1498
-
1499
- resolve();
1500
- });
1501
-
1502
- stream.on('data', () => {
1503
- if (stream.getBufferedLength() > maxBuffer) {
1504
- rejectPromise(new MaxBufferError());
1505
- }
1506
- });
1507
- });
1508
-
1509
- return stream.getBufferedValue();
1510
- }
1511
-
1512
- getStream$2.exports = getStream$1;
1513
- // TODO: Remove this for the next major release
1514
- getStream$2.exports.default = getStream$1;
1515
- getStream$2.exports.buffer = (stream, options) => getStream$1(stream, {...options, encoding: 'buffer'});
1516
- getStream$2.exports.array = (stream, options) => getStream$1(stream, {...options, array: true});
1517
- getStream$2.exports.MaxBufferError = MaxBufferError;
1518
-
1519
- var getStreamExports = getStream$2.exports;
1520
-
1521
- const { PassThrough } = require$$0$4;
1522
-
1523
- var mergeStream$1 = function (/*streams...*/) {
1524
- var sources = [];
1525
- var output = new PassThrough({objectMode: true});
1526
-
1527
- output.setMaxListeners(0);
1528
-
1529
- output.add = add;
1530
- output.isEmpty = isEmpty;
1531
-
1532
- output.on('unpipe', remove);
1533
-
1534
- Array.prototype.slice.call(arguments).forEach(add);
1535
-
1536
- return output
1537
-
1538
- function add (source) {
1539
- if (Array.isArray(source)) {
1540
- source.forEach(add);
1541
- return this
1542
- }
1543
-
1544
- sources.push(source);
1545
- source.once('end', remove.bind(null, source));
1546
- source.once('error', output.emit.bind(output, 'error'));
1547
- source.pipe(output, {end: false});
1548
- return this
1549
- }
1550
-
1551
- function isEmpty () {
1552
- return sources.length == 0;
1553
- }
1554
-
1555
- function remove (source) {
1556
- sources = sources.filter(function (it) { return it !== source });
1557
- if (!sources.length && output.readable) { output.end(); }
1558
- }
1559
- };
1560
-
1561
- const isStream = isStream_1;
1562
- const getStream = getStreamExports;
1563
- const mergeStream = mergeStream$1;
1564
-
1565
- // `input` option
1566
- const handleInput$1 = (spawned, input) => {
1567
- // Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
1568
- // TODO: Remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
1569
- if (input === undefined || spawned.stdin === undefined) {
1570
- return;
1571
- }
1572
-
1573
- if (isStream(input)) {
1574
- input.pipe(spawned.stdin);
1575
- } else {
1576
- spawned.stdin.end(input);
1577
- }
1578
- };
1579
-
1580
- // `all` interleaves `stdout` and `stderr`
1581
- const makeAllStream$1 = spawned => {
1582
- if (!spawned.stdout && !spawned.stderr) {
1583
- return;
1584
- }
1585
-
1586
- const mixed = mergeStream();
1587
-
1588
- if (spawned.stdout) {
1589
- mixed.add(spawned.stdout);
1590
- }
1591
-
1592
- if (spawned.stderr) {
1593
- mixed.add(spawned.stderr);
1594
- }
1595
-
1596
- return mixed;
1597
- };
1598
-
1599
- // On failure, `result.stdout|stderr|all` should contain the currently buffered stream
1600
- const getBufferedData = async (stream, streamPromise) => {
1601
- if (!stream) {
1602
- return;
1603
- }
1604
-
1605
- stream.destroy();
1606
-
1607
- try {
1608
- return await streamPromise;
1609
- } catch (error) {
1610
- return error.bufferedData;
1611
- }
1612
- };
1613
-
1614
- const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
1615
- if (!stream) {
1616
- return;
1617
- }
1618
-
1619
- if (!buffer) {
1620
- // TODO: Use `ret = util.promisify(stream.finished)(stream);` when targeting Node.js 10
1621
- return new Promise((resolve, reject) => {
1622
- stream
1623
- .once('end', resolve)
1624
- .once('error', reject);
1625
- });
1626
- }
1627
-
1628
- if (encoding) {
1629
- return getStream(stream, {encoding, maxBuffer});
1630
- }
1631
-
1632
- return getStream.buffer(stream, {maxBuffer});
1633
- };
1634
-
1635
- // Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)
1636
- const getSpawnedResult$1 = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {
1637
- const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});
1638
- const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});
1639
- const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});
1640
-
1641
- try {
1642
- return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
1643
- } catch (error) {
1644
- return Promise.all([
1645
- {error, code: error.code, signal: error.signal, timedOut: error.timedOut},
1646
- getBufferedData(stdout, stdoutPromise),
1647
- getBufferedData(stderr, stderrPromise),
1648
- getBufferedData(all, allPromise)
1649
- ]);
1650
- }
1651
- };
1652
-
1653
- const validateInputSync$1 = ({input}) => {
1654
- if (isStream(input)) {
1655
- throw new TypeError('The `input` option cannot be a stream in sync mode');
1656
- }
1657
- };
1658
-
1659
- var stream = {
1660
- handleInput: handleInput$1,
1661
- makeAllStream: makeAllStream$1,
1662
- getSpawnedResult: getSpawnedResult$1,
1663
- validateInputSync: validateInputSync$1
1664
- };
1665
-
1666
- const mergePromiseProperty = (spawned, promise, property) => {
1667
- // Starting the main `promise` is deferred to avoid consuming streams
1668
- const value = typeof promise === 'function' ?
1669
- (...args) => promise()[property](...args) :
1670
- promise[property].bind(promise);
1671
-
1672
- Object.defineProperty(spawned, property, {
1673
- value,
1674
- writable: true,
1675
- enumerable: false,
1676
- configurable: true
1677
- });
1678
- };
1679
-
1680
- // The return value is a mixin of `childProcess` and `Promise`
1681
- const mergePromise$1 = (spawned, promise) => {
1682
- mergePromiseProperty(spawned, promise, 'then');
1683
- mergePromiseProperty(spawned, promise, 'catch');
1684
-
1685
- // TODO: Remove the `if`-guard when targeting Node.js 10
1686
- if (Promise.prototype.finally) {
1687
- mergePromiseProperty(spawned, promise, 'finally');
1688
- }
1689
-
1690
- return spawned;
1691
- };
1692
-
1693
- // Use promises instead of `child_process` events
1694
- const getSpawnedPromise$1 = spawned => {
1695
- return new Promise((resolve, reject) => {
1696
- spawned.on('exit', (code, signal) => {
1697
- resolve({code, signal});
1698
- });
1699
-
1700
- spawned.on('error', error => {
1701
- reject(error);
1702
- });
1703
-
1704
- if (spawned.stdin) {
1705
- spawned.stdin.on('error', error => {
1706
- reject(error);
1707
- });
1708
- }
1709
- });
1710
- };
1711
-
1712
- var promise = {
1713
- mergePromise: mergePromise$1,
1714
- getSpawnedPromise: getSpawnedPromise$1
1715
- };
1716
-
1717
- const SPACES_REGEXP = / +/g;
1718
-
1719
- const joinCommand$1 = (file, args = []) => {
1720
- if (!Array.isArray(args)) {
1721
- return file;
1722
- }
1723
-
1724
- return [file, ...args].join(' ');
1725
- };
1726
-
1727
- // Allow spaces to be escaped by a backslash if not meant as a delimiter
1728
- const handleEscaping = (tokens, token, index) => {
1729
- if (index === 0) {
1730
- return [token];
1731
- }
1732
-
1733
- const previousToken = tokens[tokens.length - 1];
1734
-
1735
- if (previousToken.endsWith('\\')) {
1736
- return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`];
1737
- }
1738
-
1739
- return [...tokens, token];
1740
- };
1741
-
1742
- // Handle `execa.command()`
1743
- const parseCommand$1 = command => {
1744
- return command
1745
- .trim()
1746
- .split(SPACES_REGEXP)
1747
- .reduce(handleEscaping, []);
1748
- };
1749
-
1750
- var command = {
1751
- joinCommand: joinCommand$1,
1752
- parseCommand: parseCommand$1
1753
- };
1754
-
1755
- const path$1 = require$$0;
1756
- const childProcess$1 = require$$0$2;
1757
- const crossSpawn = crossSpawnExports;
1758
- const stripFinalNewline = stripFinalNewline$1;
1759
- const npmRunPath = npmRunPathExports;
1760
- const onetime = onetimeExports;
1761
- const makeError = error;
1762
- const normalizeStdio = stdioExports;
1763
- const {spawnedKill, spawnedCancel, setupTimeout, setExitHandler} = kill;
1764
- const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = stream;
1765
- const {mergePromise, getSpawnedPromise} = promise;
1766
- const {joinCommand, parseCommand} = command;
1767
-
1768
- const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
1769
-
1770
- const getEnv = ({env: envOption, extendEnv, preferLocal, localDir}) => {
1771
- const env = extendEnv ? {...process.env, ...envOption} : envOption;
1772
-
1773
- if (preferLocal) {
1774
- return npmRunPath.env({env, cwd: localDir});
1775
- }
1776
-
1777
- return env;
1778
- };
1779
-
1780
- const handleArgs = (file, args, options = {}) => {
1781
- const parsed = crossSpawn._parse(file, args, options);
1782
- file = parsed.command;
1783
- args = parsed.args;
1784
- options = parsed.options;
1785
-
1786
- options = {
1787
- maxBuffer: DEFAULT_MAX_BUFFER,
1788
- buffer: true,
1789
- stripFinalNewline: true,
1790
- extendEnv: true,
1791
- preferLocal: false,
1792
- localDir: options.cwd || process.cwd(),
1793
- encoding: 'utf8',
1794
- reject: true,
1795
- cleanup: true,
1796
- ...options,
1797
- windowsHide: true
1798
- };
1799
-
1800
- options.env = getEnv(options);
1801
-
1802
- options.stdio = normalizeStdio(options);
1803
-
1804
- if (process.platform === 'win32' && path$1.basename(file, '.exe') === 'cmd') {
1805
- // #116
1806
- args.unshift('/q');
1807
- }
1808
-
1809
- return {file, args, options, parsed};
1810
- };
1811
-
1812
- const handleOutput = (options, value, error) => {
1813
- if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
1814
- // When `execa.sync()` errors, we normalize it to '' to mimic `execa()`
1815
- return error === undefined ? undefined : '';
1816
- }
1817
-
1818
- if (options.stripFinalNewline) {
1819
- return stripFinalNewline(value);
1820
- }
1821
-
1822
- return value;
1823
- };
1824
-
1825
- const execa$1 = (file, args, options) => {
1826
- const parsed = handleArgs(file, args, options);
1827
- const command = joinCommand(file, args);
1828
-
1829
- let spawned;
1830
- try {
1831
- spawned = childProcess$1.spawn(parsed.file, parsed.args, parsed.options);
1832
- } catch (error) {
1833
- // Ensure the returned error is always both a promise and a child process
1834
- const dummySpawned = new childProcess$1.ChildProcess();
1835
- const errorPromise = Promise.reject(makeError({
1836
- error,
1837
- stdout: '',
1838
- stderr: '',
1839
- all: '',
1840
- command,
1841
- parsed,
1842
- timedOut: false,
1843
- isCanceled: false,
1844
- killed: false
1845
- }));
1846
- return mergePromise(dummySpawned, errorPromise);
1847
- }
1848
-
1849
- const spawnedPromise = getSpawnedPromise(spawned);
1850
- const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
1851
- const processDone = setExitHandler(spawned, parsed.options, timedPromise);
1852
-
1853
- const context = {isCanceled: false};
1854
-
1855
- spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
1856
- spawned.cancel = spawnedCancel.bind(null, spawned, context);
1857
-
1858
- const handlePromise = async () => {
1859
- const [{error, code, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
1860
- const stdout = handleOutput(parsed.options, stdoutResult);
1861
- const stderr = handleOutput(parsed.options, stderrResult);
1862
- const all = handleOutput(parsed.options, allResult);
1863
-
1864
- if (error || code !== 0 || signal !== null) {
1865
- const returnedError = makeError({
1866
- error,
1867
- code,
1868
- signal,
1869
- stdout,
1870
- stderr,
1871
- all,
1872
- command,
1873
- parsed,
1874
- timedOut,
1875
- isCanceled: context.isCanceled,
1876
- killed: spawned.killed
1877
- });
1878
-
1879
- if (!parsed.options.reject) {
1880
- return returnedError;
1881
- }
1882
-
1883
- throw returnedError;
1884
- }
1885
-
1886
- return {
1887
- command,
1888
- exitCode: 0,
1889
- exitCodeName: 'SUCCESS',
1890
- stdout,
1891
- stderr,
1892
- all,
1893
- failed: false,
1894
- timedOut: false,
1895
- isCanceled: false,
1896
- killed: false
1897
- };
1898
- };
1899
-
1900
- const handlePromiseOnce = onetime(handlePromise);
1901
-
1902
- crossSpawn._enoent.hookChildProcess(spawned, parsed.parsed);
1903
-
1904
- handleInput(spawned, parsed.options.input);
1905
-
1906
- spawned.all = makeAllStream(spawned);
1907
-
1908
- return mergePromise(spawned, handlePromiseOnce);
1909
- };
1910
-
1911
- execa$2.exports = execa$1;
1912
-
1913
- execa$2.exports.sync = (file, args, options) => {
1914
- const parsed = handleArgs(file, args, options);
1915
- const command = joinCommand(file, args);
1916
-
1917
- validateInputSync(parsed.options);
1918
-
1919
- let result;
1920
- try {
1921
- result = childProcess$1.spawnSync(parsed.file, parsed.args, parsed.options);
1922
- } catch (error) {
1923
- throw makeError({
1924
- error,
1925
- stdout: '',
1926
- stderr: '',
1927
- all: '',
1928
- command,
1929
- parsed,
1930
- timedOut: false,
1931
- isCanceled: false,
1932
- killed: false
1933
- });
1934
- }
1935
-
1936
- result.stdout = handleOutput(parsed.options, result.stdout, result.error);
1937
- result.stderr = handleOutput(parsed.options, result.stderr, result.error);
1938
-
1939
- if (result.error || result.status !== 0 || result.signal !== null) {
1940
- const error = makeError({
1941
- ...result,
1942
- code: result.status,
1943
- command,
1944
- parsed,
1945
- timedOut: result.error && result.error.code === 'ETIMEDOUT',
1946
- isCanceled: false,
1947
- killed: result.signal !== null
1948
- });
1949
-
1950
- if (!parsed.options.reject) {
1951
- return error;
1952
- }
1953
-
1954
- throw error;
1955
- }
1956
-
1957
- return {
1958
- command,
1959
- exitCode: 0,
1960
- exitCodeName: 'SUCCESS',
1961
- stdout: result.stdout,
1962
- stderr: result.stderr,
1963
- failed: false,
1964
- timedOut: false,
1965
- isCanceled: false,
1966
- killed: false
1967
- };
1968
- };
1969
-
1970
- execa$2.exports.command = (command, options) => {
1971
- const [file, ...args] = parseCommand(command);
1972
- return execa$1(file, args, options);
1973
- };
1974
-
1975
- execa$2.exports.commandSync = (command, options) => {
1976
- const [file, ...args] = parseCommand(command);
1977
- return execa$1.sync(file, args, options);
1978
- };
1979
-
1980
- execa$2.exports.node = (scriptPath, args, options = {}) => {
1981
- if (args && !Array.isArray(args) && typeof args === 'object') {
1982
- options = args;
1983
- args = [];
1984
- }
1985
-
1986
- const stdio = normalizeStdio.node(options);
1987
-
1988
- const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
1989
-
1990
- return execa$1(
1991
- nodePath,
1992
- [
1993
- ...nodeOptions,
1994
- scriptPath,
1995
- ...(Array.isArray(args) ? args : [])
1996
- ],
1997
- {
1998
- ...options,
1999
- stdin: undefined,
2000
- stdout: undefined,
2001
- stderr: undefined,
2002
- stdio,
2003
- shell: false
2004
- }
2005
- );
2006
- };
2007
-
2008
- var execaExports = execa$2.exports;
2009
-
2010
- const execa = execaExports;
2011
-
2012
- const getColumnBoundaries = async header => {
2013
- // Regex captures each individual column
2014
- // ^\S+\s+ -> First column
2015
- // \s*\S+\s*\S+$ -> Last column (combined)
2016
- // \s*\S+ -> Regular columns
2017
- const regex = /^\S+\s+|\s*\S+\s*\S+$|\s*\S+/g;
2018
- const boundaries = [];
2019
- let match;
2020
-
2021
- while ((match = regex.exec(header))) {
2022
- boundaries.push(match[0].length);
2023
- }
2024
-
2025
- // Extend last column boundary
2026
- boundaries[boundaries.length - 1] = -1;
2027
-
2028
- return boundaries;
2029
- };
2030
-
2031
- const parseOutput = async output => {
2032
- const lines = output.trim().split('\n');
2033
- const boundaries = await getColumnBoundaries(lines[0]);
2034
-
2035
- return lines.slice(1).map(line => {
2036
- const cl = boundaries.map(boundary => {
2037
- // Handle extra-long last column
2038
- const column = boundary > 0 ? line.slice(0, boundary) : line;
2039
- line = line.slice(boundary);
2040
- return column.trim();
2041
- });
2042
-
2043
- return {
2044
- filesystem: cl[0],
2045
- size: parseInt(cl[1], 10) * 1024,
2046
- used: parseInt(cl[2], 10) * 1024,
2047
- available: parseInt(cl[3], 10) * 1024,
2048
- capacity: parseInt(cl[4], 10) / 100,
2049
- mountpoint: cl[5]
2050
- };
2051
- });
2052
- };
2053
-
2054
- const run$1 = async args => {
2055
- const {stdout} = await execa('df', args);
2056
- return parseOutput(stdout);
2057
- };
2058
-
2059
- const df$4 = async () => run$1(['-kP']);
2060
-
2061
- df$4.fs = async name => {
2062
- if (typeof name !== 'string') {
2063
- throw new TypeError('The `name` parameter required');
2064
- }
2065
-
2066
- const data = await run$1(['-kP']);
2067
-
2068
- for (const item of data) {
2069
- if (item.filesystem === name) {
2070
- return item;
2071
- }
2072
- }
2073
-
2074
- throw new Error(`The specified filesystem \`${name}\` doesn't exist`);
2075
- };
2076
-
2077
- df$4.file = async file => {
2078
- if (typeof file !== 'string') {
2079
- throw new TypeError('The `file` parameter is required');
2080
- }
2081
-
2082
- let data;
2083
- try {
2084
- data = await run$1(['-kP', file]);
2085
- } catch (error) {
2086
- if (/No such file or directory/.test(error.stderr)) {
2087
- throw new Error(`The specified file \`${file}\` doesn't exist`);
2088
- }
2089
-
2090
- throw error;
2091
- }
2092
-
2093
- return data[0];
2094
- };
2095
-
2096
- df$5.exports = df$4;
2097
- // TODO: remove this in the next major version
2098
- df$5.exports.default = df$4;
2099
-
2100
- if (process.env.NODE_ENV === 'test') {
2101
- df$5.exports._parseOutput = parseOutput;
2102
- }
2103
-
2104
- var dfExports$1 = df$5.exports;
2105
-
2106
- var df$3 = {exports: {}};
2107
-
2108
- var childProcess = require$$0$2;
2109
-
2110
- function run(args, cb) {
2111
- childProcess.execFile('df', args, function (err, stdout) {
2112
- if (err) {
2113
- cb(err);
2114
- return;
2115
- }
2116
-
2117
- cb(null, stdout.trim().split('\n').slice(1).map(function (el) {
2118
- var cl = el.split(/\s+(?=[\d\/])/);
2119
-
2120
- return {
2121
- filesystem: cl[0],
2122
- size: parseInt(cl[1], 10) * 1024,
2123
- used: parseInt(cl[2], 10) * 1024,
2124
- available: parseInt(cl[3], 10) * 1024,
2125
- capacity: parseInt(cl[4], 10) / 100,
2126
- mountpoint: cl[5]
2127
- };
2128
- }));
2129
- });
2130
- }
2131
- var df$2 = df$3.exports = function (cb) {
2132
- run(['-kP'], cb);
2133
- };
2134
-
2135
- df$2.fs = function (name, cb) {
2136
- if (typeof name !== 'string') {
2137
- throw new Error('name required');
2138
- }
2139
-
2140
- run(['-kP'], function (err, data) {
2141
- if (err) {
2142
- cb(err);
2143
- return;
2144
- }
2145
-
2146
- var ret;
2147
-
2148
- data.forEach(function (el) {
2149
- if (el.filesystem === name) {
2150
- ret = el;
2151
- }
2152
- });
2153
-
2154
- cb(null, ret);
2155
- });
2156
- };
2157
-
2158
- df$2.file = function (file, cb) {
2159
- if (typeof file !== 'string') {
2160
- throw new Error('file required');
2161
- }
2162
-
2163
- run(['-kP', file], function (err, data) {
2164
- if (err) {
2165
- cb(err);
2166
- return;
2167
- }
2168
-
2169
- cb(null, data[0]);
2170
- });
2171
- };
2172
-
2173
- var dfExports = df$3.exports;
2174
-
2175
- var pify$2 = {exports: {}};
2176
-
2177
- var processFn = function (fn, P, opts) {
2178
- return function () {
2179
- var that = this;
2180
- var args = new Array(arguments.length);
2181
-
2182
- for (var i = 0; i < arguments.length; i++) {
2183
- args[i] = arguments[i];
2184
- }
2185
-
2186
- return new P(function (resolve, reject) {
2187
- args.push(function (err, result) {
2188
- if (err) {
2189
- reject(err);
2190
- } else if (opts.multiArgs) {
2191
- var results = new Array(arguments.length - 1);
2192
-
2193
- for (var i = 1; i < arguments.length; i++) {
2194
- results[i - 1] = arguments[i];
2195
- }
2196
-
2197
- resolve(results);
2198
- } else {
2199
- resolve(result);
2200
- }
2201
- });
2202
-
2203
- fn.apply(that, args);
2204
- });
2205
- };
2206
- };
2207
-
2208
- var pify$1 = pify$2.exports = function (obj, P, opts) {
2209
- if (typeof P !== 'function') {
2210
- opts = P;
2211
- P = Promise;
2212
- }
2213
-
2214
- opts = opts || {};
2215
- opts.exclude = opts.exclude || [/.+Sync$/];
2216
-
2217
- var filter = function (key) {
2218
- var match = function (pattern) {
2219
- return typeof pattern === 'string' ? key === pattern : pattern.test(key);
2220
- };
2221
-
2222
- return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
2223
- };
2224
-
2225
- var ret = typeof obj === 'function' ? function () {
2226
- if (opts.excludeMain) {
2227
- return obj.apply(this, arguments);
2228
- }
2229
-
2230
- return processFn(obj, P, opts).apply(this, arguments);
2231
- } : {};
2232
-
2233
- return Object.keys(obj).reduce(function (ret, key) {
2234
- var x = obj[key];
2235
-
2236
- ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
2237
-
2238
- return ret;
2239
- }, ret);
2240
- };
2241
-
2242
- pify$1.all = pify$1;
2243
-
2244
- var pifyExports = pify$2.exports;
2245
-
2246
- var pinkie;
2247
- var hasRequiredPinkie;
2248
-
2249
- function requirePinkie () {
2250
- if (hasRequiredPinkie) return pinkie;
2251
- hasRequiredPinkie = 1;
2252
-
2253
- var PENDING = 'pending';
2254
- var SETTLED = 'settled';
2255
- var FULFILLED = 'fulfilled';
2256
- var REJECTED = 'rejected';
2257
- var NOOP = function () {};
2258
- var isNode = typeof index.commonjsGlobal !== 'undefined' && typeof index.commonjsGlobal.process !== 'undefined' && typeof index.commonjsGlobal.process.emit === 'function';
2259
-
2260
- var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
2261
- var asyncQueue = [];
2262
- var asyncTimer;
2263
-
2264
- function asyncFlush() {
2265
- // run promise callbacks
2266
- for (var i = 0; i < asyncQueue.length; i++) {
2267
- asyncQueue[i][0](asyncQueue[i][1]);
2268
- }
2269
-
2270
- // reset async asyncQueue
2271
- asyncQueue = [];
2272
- asyncTimer = false;
2273
- }
2274
-
2275
- function asyncCall(callback, arg) {
2276
- asyncQueue.push([callback, arg]);
2277
-
2278
- if (!asyncTimer) {
2279
- asyncTimer = true;
2280
- asyncSetTimer(asyncFlush, 0);
2281
- }
2282
- }
2283
-
2284
- function invokeResolver(resolver, promise) {
2285
- function resolvePromise(value) {
2286
- resolve(promise, value);
2287
- }
2288
-
2289
- function rejectPromise(reason) {
2290
- reject(promise, reason);
2291
- }
2292
-
2293
- try {
2294
- resolver(resolvePromise, rejectPromise);
2295
- } catch (e) {
2296
- rejectPromise(e);
2297
- }
2298
- }
2299
-
2300
- function invokeCallback(subscriber) {
2301
- var owner = subscriber.owner;
2302
- var settled = owner._state;
2303
- var value = owner._data;
2304
- var callback = subscriber[settled];
2305
- var promise = subscriber.then;
2306
-
2307
- if (typeof callback === 'function') {
2308
- settled = FULFILLED;
2309
- try {
2310
- value = callback(value);
2311
- } catch (e) {
2312
- reject(promise, e);
2313
- }
2314
- }
2315
-
2316
- if (!handleThenable(promise, value)) {
2317
- if (settled === FULFILLED) {
2318
- resolve(promise, value);
2319
- }
2320
-
2321
- if (settled === REJECTED) {
2322
- reject(promise, value);
2323
- }
2324
- }
2325
- }
2326
-
2327
- function handleThenable(promise, value) {
2328
- var resolved;
2329
-
2330
- try {
2331
- if (promise === value) {
2332
- throw new TypeError('A promises callback cannot return that same promise.');
2333
- }
2334
-
2335
- if (value && (typeof value === 'function' || typeof value === 'object')) {
2336
- // then should be retrieved only once
2337
- var then = value.then;
2338
-
2339
- if (typeof then === 'function') {
2340
- then.call(value, function (val) {
2341
- if (!resolved) {
2342
- resolved = true;
2343
-
2344
- if (value === val) {
2345
- fulfill(promise, val);
2346
- } else {
2347
- resolve(promise, val);
2348
- }
2349
- }
2350
- }, function (reason) {
2351
- if (!resolved) {
2352
- resolved = true;
2353
-
2354
- reject(promise, reason);
2355
- }
2356
- });
2357
-
2358
- return true;
2359
- }
2360
- }
2361
- } catch (e) {
2362
- if (!resolved) {
2363
- reject(promise, e);
2364
- }
2365
-
2366
- return true;
2367
- }
2368
-
2369
- return false;
2370
- }
2371
-
2372
- function resolve(promise, value) {
2373
- if (promise === value || !handleThenable(promise, value)) {
2374
- fulfill(promise, value);
2375
- }
2376
- }
2377
-
2378
- function fulfill(promise, value) {
2379
- if (promise._state === PENDING) {
2380
- promise._state = SETTLED;
2381
- promise._data = value;
2382
-
2383
- asyncCall(publishFulfillment, promise);
2384
- }
2385
- }
2386
-
2387
- function reject(promise, reason) {
2388
- if (promise._state === PENDING) {
2389
- promise._state = SETTLED;
2390
- promise._data = reason;
2391
-
2392
- asyncCall(publishRejection, promise);
2393
- }
2394
- }
2395
-
2396
- function publish(promise) {
2397
- promise._then = promise._then.forEach(invokeCallback);
2398
- }
2399
-
2400
- function publishFulfillment(promise) {
2401
- promise._state = FULFILLED;
2402
- publish(promise);
2403
- }
2404
-
2405
- function publishRejection(promise) {
2406
- promise._state = REJECTED;
2407
- publish(promise);
2408
- if (!promise._handled && isNode) {
2409
- index.commonjsGlobal.process.emit('unhandledRejection', promise._data, promise);
2410
- }
2411
- }
2412
-
2413
- function notifyRejectionHandled(promise) {
2414
- index.commonjsGlobal.process.emit('rejectionHandled', promise);
2415
- }
2416
-
2417
- /**
2418
- * @class
2419
- */
2420
- function Promise(resolver) {
2421
- if (typeof resolver !== 'function') {
2422
- throw new TypeError('Promise resolver ' + resolver + ' is not a function');
2423
- }
2424
-
2425
- if (this instanceof Promise === false) {
2426
- throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
2427
- }
2428
-
2429
- this._then = [];
2430
-
2431
- invokeResolver(resolver, this);
2432
- }
2433
-
2434
- Promise.prototype = {
2435
- constructor: Promise,
2436
-
2437
- _state: PENDING,
2438
- _then: null,
2439
- _data: undefined,
2440
- _handled: false,
2441
-
2442
- then: function (onFulfillment, onRejection) {
2443
- var subscriber = {
2444
- owner: this,
2445
- then: new this.constructor(NOOP),
2446
- fulfilled: onFulfillment,
2447
- rejected: onRejection
2448
- };
2449
-
2450
- if ((onRejection || onFulfillment) && !this._handled) {
2451
- this._handled = true;
2452
- if (this._state === REJECTED && isNode) {
2453
- asyncCall(notifyRejectionHandled, this);
2454
- }
2455
- }
2456
-
2457
- if (this._state === FULFILLED || this._state === REJECTED) {
2458
- // already resolved, call callback async
2459
- asyncCall(invokeCallback, subscriber);
2460
- } else {
2461
- // subscribe
2462
- this._then.push(subscriber);
2463
- }
2464
-
2465
- return subscriber.then;
2466
- },
2467
-
2468
- catch: function (onRejection) {
2469
- return this.then(null, onRejection);
2470
- }
2471
- };
2472
-
2473
- Promise.all = function (promises) {
2474
- if (!Array.isArray(promises)) {
2475
- throw new TypeError('You must pass an array to Promise.all().');
2476
- }
2477
-
2478
- return new Promise(function (resolve, reject) {
2479
- var results = [];
2480
- var remaining = 0;
2481
-
2482
- function resolver(index) {
2483
- remaining++;
2484
- return function (value) {
2485
- results[index] = value;
2486
- if (!--remaining) {
2487
- resolve(results);
2488
- }
2489
- };
2490
- }
2491
-
2492
- for (var i = 0, promise; i < promises.length; i++) {
2493
- promise = promises[i];
2494
-
2495
- if (promise && typeof promise.then === 'function') {
2496
- promise.then(resolver(i), reject);
2497
- } else {
2498
- results[i] = promise;
2499
- }
2500
- }
2501
-
2502
- if (!remaining) {
2503
- resolve(results);
2504
- }
2505
- });
2506
- };
2507
-
2508
- Promise.race = function (promises) {
2509
- if (!Array.isArray(promises)) {
2510
- throw new TypeError('You must pass an array to Promise.race().');
2511
- }
2512
-
2513
- return new Promise(function (resolve, reject) {
2514
- for (var i = 0, promise; i < promises.length; i++) {
2515
- promise = promises[i];
2516
-
2517
- if (promise && typeof promise.then === 'function') {
2518
- promise.then(resolve, reject);
2519
- } else {
2520
- resolve(promise);
2521
- }
2522
- }
2523
- });
2524
- };
2525
-
2526
- Promise.resolve = function (value) {
2527
- if (value && typeof value === 'object' && value.constructor === Promise) {
2528
- return value;
2529
- }
2530
-
2531
- return new Promise(function (resolve) {
2532
- resolve(value);
2533
- });
2534
- };
2535
-
2536
- Promise.reject = function (reason) {
2537
- return new Promise(function (resolve, reject) {
2538
- reject(reason);
2539
- });
2540
- };
2541
-
2542
- pinkie = Promise;
2543
- return pinkie;
2544
- }
2545
-
2546
- var pinkiePromise = typeof Promise === 'function' ? Promise : requirePinkie();
2547
-
2548
- var df$1 = dfExports;
2549
- var pify = pifyExports;
2550
- var Promise$1 = pinkiePromise;
2551
-
2552
- var mountPoint$1 = function (file) {
2553
- return pify(df$1.file, Promise$1)(file).then(function (data) {
2554
- return data.mountpoint;
2555
- });
2556
- };
2557
-
2558
- var os = require$$1;
2559
-
2560
- function homedir() {
2561
- var env = process.env;
2562
- var home = env.HOME;
2563
- var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME;
2564
-
2565
- if (process.platform === 'win32') {
2566
- return env.USERPROFILE || env.HOMEDRIVE + env.HOMEPATH || home || null;
2567
- }
2568
-
2569
- if (process.platform === 'darwin') {
2570
- return home || (user ? '/Users/' + user : null);
2571
- }
2572
-
2573
- if (process.platform === 'linux') {
2574
- return home || (process.getuid() === 0 ? '/root' : (user ? '/home/' + user : null));
2575
- }
2576
-
2577
- return home || null;
2578
- }
2579
-
2580
- var osHomedir = typeof os.homedir === 'function' ? os.homedir : homedir;
2581
-
2582
- var userHome$1 = osHomedir();
2583
-
2584
- var xdgBasedir$1 = {};
2585
-
2586
- (function (exports) {
2587
- const os = require$$1;
2588
- const path = require$$0;
2589
-
2590
- const homeDirectory = os.homedir();
2591
- const {env} = process;
2592
-
2593
- exports.data = env.XDG_DATA_HOME ||
2594
- (homeDirectory ? path.join(homeDirectory, '.local', 'share') : undefined);
2595
-
2596
- exports.config = env.XDG_CONFIG_HOME ||
2597
- (homeDirectory ? path.join(homeDirectory, '.config') : undefined);
2598
-
2599
- exports.cache = env.XDG_CACHE_HOME || (homeDirectory ? path.join(homeDirectory, '.cache') : undefined);
2600
-
2601
- exports.runtime = env.XDG_RUNTIME_DIR || undefined;
2602
-
2603
- exports.dataDirs = (env.XDG_DATA_DIRS || '/usr/local/share/:/usr/share/').split(':');
2604
-
2605
- if (exports.data) {
2606
- exports.dataDirs.unshift(exports.data);
2607
- }
2608
-
2609
- exports.configDirs = (env.XDG_CONFIG_DIRS || '/etc/xdg').split(':');
2610
-
2611
- if (exports.config) {
2612
- exports.configDirs.unshift(exports.config);
2613
- }
2614
- } (xdgBasedir$1));
2615
-
2616
- const fs = require$$0$1.promises;
2617
- const path = require$$0;
2618
- const df = dfExports$1;
2619
- const mountPoint = mountPoint$1;
2620
- const userHome = userHome$1;
2621
- const xdgBasedir = xdgBasedir$1;
2622
-
2623
- const check = async filePath => {
2624
- const topuid = `${filePath}-${process.getuid()}`;
2625
- const stickyBitMode = 17407;
2626
-
2627
- try {
2628
- const stats = await fs.lstat(filePath);
2629
-
2630
- if (stats.isSymbolicLink() || stats.mode !== stickyBitMode) {
2631
- return topuid;
2632
- }
2633
-
2634
- return path.join(filePath, String(process.getuid()));
2635
- } catch (error) {
2636
- if (error.code === 'ENOENT') {
2637
- return topuid;
2638
- }
2639
-
2640
- return path.join(xdgBasedir.data, 'Trash');
2641
- }
2642
- };
2643
-
2644
- xdgTrashdir$1.exports = async filePath => {
2645
- if (process.platform !== 'linux') {
2646
- return Promise.reject(new Error('Only Linux systems are supported'));
2647
- }
2648
-
2649
- if (!filePath) {
2650
- return Promise.resolve(path.join(xdgBasedir.data, 'Trash'));
2651
- }
2652
-
2653
- const [homeMountPoint, fileMountPoint] = await Promise.all([
2654
- mountPoint(userHome),
2655
- // Ignore errors in case `file` is a dangling symlink
2656
- mountPoint(filePath).catch(() => {})
2657
- ]);
2658
-
2659
- if (!fileMountPoint || fileMountPoint === homeMountPoint) {
2660
- return path.join(xdgBasedir.data, 'Trash');
2661
- }
2662
-
2663
- return check(path.join(fileMountPoint, '.Trash'));
2664
- };
2665
-
2666
- xdgTrashdir$1.exports.all = async () => {
2667
- if (process.platform !== 'linux') {
2668
- return Promise.reject(new Error('Only Linux systems are supported'));
2669
- }
2670
-
2671
- return Promise.all((await df()).map(fileSystem => {
2672
- if (fileSystem.mountpoint === '/') {
2673
- return path.join(xdgBasedir.data, 'Trash');
2674
- }
2675
-
2676
- return check(path.join(fileSystem.mountpoint, '.Trash'));
2677
- }));
2678
- };
2679
-
2680
- var xdgTrashdirExports = xdgTrashdir$1.exports;
2681
- var xdgTrashdir = /*@__PURE__*/index.getDefaultExportFromCjs(xdgTrashdirExports);
2682
-
2683
- async function pMap(
2684
- iterable,
2685
- mapper,
2686
- {
2687
- concurrency = Number.POSITIVE_INFINITY,
2688
- stopOnError = true,
2689
- signal,
2690
- } = {},
2691
- ) {
2692
- return new Promise((resolve, reject_) => {
2693
- if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
2694
- throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
2695
- }
2696
-
2697
- if (typeof mapper !== 'function') {
2698
- throw new TypeError('Mapper function is required');
2699
- }
2700
-
2701
- if (!((Number.isSafeInteger(concurrency) && concurrency >= 1) || concurrency === Number.POSITIVE_INFINITY)) {
2702
- throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
2703
- }
2704
-
2705
- const result = [];
2706
- const errors = [];
2707
- const skippedIndexesMap = new Map();
2708
- let isRejected = false;
2709
- let isResolved = false;
2710
- let isIterableDone = false;
2711
- let resolvingCount = 0;
2712
- let currentIndex = 0;
2713
- const iterator = iterable[Symbol.iterator] === undefined ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
2714
-
2715
- const reject = reason => {
2716
- isRejected = true;
2717
- isResolved = true;
2718
- reject_(reason);
2719
- };
2720
-
2721
- if (signal) {
2722
- if (signal.aborted) {
2723
- reject(signal.reason);
2724
- }
2725
-
2726
- signal.addEventListener('abort', () => {
2727
- reject(signal.reason);
2728
- });
2729
- }
2730
-
2731
- const next = async () => {
2732
- if (isResolved) {
2733
- return;
2734
- }
2735
-
2736
- const nextItem = await iterator.next();
2737
-
2738
- const index = currentIndex;
2739
- currentIndex++;
2740
-
2741
- // Note: `iterator.next()` can be called many times in parallel.
2742
- // This can cause multiple calls to this `next()` function to
2743
- // receive a `nextItem` with `done === true`.
2744
- // The shutdown logic that rejects/resolves must be protected
2745
- // so it runs only one time as the `skippedIndex` logic is
2746
- // non-idempotent.
2747
- if (nextItem.done) {
2748
- isIterableDone = true;
2749
-
2750
- if (resolvingCount === 0 && !isResolved) {
2751
- if (!stopOnError && errors.length > 0) {
2752
- reject(new AggregateError(errors)); // eslint-disable-line unicorn/error-message
2753
- return;
2754
- }
2755
-
2756
- isResolved = true;
2757
-
2758
- if (skippedIndexesMap.size === 0) {
2759
- resolve(result);
2760
- return;
2761
- }
2762
-
2763
- const pureResult = [];
2764
-
2765
- // Support multiple `pMapSkip`'s.
2766
- for (const [index, value] of result.entries()) {
2767
- if (skippedIndexesMap.get(index) === pMapSkip) {
2768
- continue;
2769
- }
2770
-
2771
- pureResult.push(value);
2772
- }
2773
-
2774
- resolve(pureResult);
2775
- }
2776
-
2777
- return;
2778
- }
2779
-
2780
- resolvingCount++;
2781
-
2782
- // Intentionally detached
2783
- (async () => {
2784
- try {
2785
- const element = await nextItem.value;
2786
-
2787
- if (isResolved) {
2788
- return;
2789
- }
2790
-
2791
- const value = await mapper(element, index);
2792
-
2793
- // Use Map to stage the index of the element.
2794
- if (value === pMapSkip) {
2795
- skippedIndexesMap.set(index, value);
2796
- }
2797
-
2798
- result[index] = value;
2799
-
2800
- resolvingCount--;
2801
- await next();
2802
- } catch (error) {
2803
- if (stopOnError) {
2804
- reject(error);
2805
- } else {
2806
- errors.push(error);
2807
- resolvingCount--;
2808
-
2809
- // In that case we can't really continue regardless of `stopOnError` state
2810
- // since an iterable is likely to continue throwing after it throws once.
2811
- // If we continue calling `next()` indefinitely we will likely end up
2812
- // in an infinite loop of failed iteration.
2813
- try {
2814
- await next();
2815
- } catch (error) {
2816
- reject(error);
2817
- }
2818
- }
2819
- }
2820
- })();
2821
- };
2822
-
2823
- // Create the concurrent runners in a detached (non-awaited)
2824
- // promise. We need this so we can await the `next()` calls
2825
- // to stop creating runners before hitting the concurrency limit
2826
- // if the iterable has already been marked as done.
2827
- // NOTE: We *must* do this for async iterators otherwise we'll spin up
2828
- // infinite `next()` calls by default and never start the event loop.
2829
- (async () => {
2830
- for (let index = 0; index < concurrency; index++) {
2831
- try {
2832
- // eslint-disable-next-line no-await-in-loop
2833
- await next();
2834
- } catch (error) {
2835
- reject(error);
2836
- break;
2837
- }
2838
-
2839
- if (isIterableDone || isRejected) {
2840
- break;
2841
- }
2842
- }
2843
- })();
2844
- });
2845
- }
2846
-
2847
- const pMapSkip = Symbol('skip');
2848
-
2849
- async function pathExists(path) {
2850
- try {
2851
- await fs$3.promises.access(path);
2852
- return true;
2853
- } catch {
2854
- return false;
2855
- }
2856
- }
2857
-
2858
- const resolvePath = (cwd, sourcePath, destinationPath) => {
2859
- sourcePath = path$5.resolve(cwd, sourcePath);
2860
- destinationPath = path$5.resolve(cwd, destinationPath);
2861
-
2862
- return {
2863
- sourcePath,
2864
- destinationPath,
2865
- };
2866
- };
2867
-
2868
- const validatePathsExist = (sourcePath, destinationPath, suffix = 'Path') => {
2869
- if (!sourcePath || !destinationPath) {
2870
- throw new TypeError(`\`source${suffix}\` and \`destination${suffix}\` required`);
2871
- }
2872
- };
2873
-
2874
- const validateSameDirectory = (source, destination) => {
2875
- if (path$5.dirname(source) !== path$5.dirname(destination)) {
2876
- throw new Error('`source` and `destination` must be in the same directory');
2877
- }
2878
- };
2879
-
2880
- const _moveFile = async (sourcePath, destinationPath, {overwrite = true, cwd = process$2.cwd(), directoryMode, validateDirectory = false} = {}) => {
2881
- if (cwd) {
2882
- ({sourcePath, destinationPath} = resolvePath(cwd, sourcePath, destinationPath));
2883
- }
2884
-
2885
- if (validateDirectory) {
2886
- validateSameDirectory(sourcePath, destinationPath);
2887
- }
2888
-
2889
- if (!overwrite && await pathExists(destinationPath)) {
2890
- throw new Error(`The destination file exists: ${destinationPath}`);
2891
- }
2892
-
2893
- await fs$3.promises.mkdir(path$5.dirname(destinationPath), {
2894
- recursive: true,
2895
- mode: directoryMode,
2896
- });
2897
-
2898
- try {
2899
- await fs$3.promises.rename(sourcePath, destinationPath);
2900
- } catch (error) {
2901
- if (error.code === 'EXDEV') {
2902
- await fs$3.promises.copyFile(sourcePath, destinationPath);
2903
- await fs$3.promises.unlink(sourcePath);
2904
- } else {
2905
- throw error;
2906
- }
2907
- }
2908
- };
2909
-
2910
- async function moveFile(sourcePath, destinationPath, options) {
2911
- validatePathsExist(sourcePath, destinationPath);
2912
- return _moveFile(sourcePath, destinationPath, options);
2913
- }
2914
-
2915
- let ProcfsError$1 = class ProcfsError extends Error {
2916
- constructor(code, message, sourceError) {
2917
- super(message);
2918
- this.name = 'ProcfsError';
2919
- this.code = code;
2920
- if (sourceError !== undefined) {
2921
- this.sourceError = sourceError;
2922
- }
2923
- }
2924
- };
2925
-
2926
- ProcfsError$1.ERR_PARSING_FAILED = 'EPARSE';
2927
- ProcfsError$1.ERR_UNKNOWN = 'EUNKNOWN';
2928
- ProcfsError$1.ERR_NOT_FOUND = 'ENOENT';
2929
-
2930
- ProcfsError$1.parsingError = (src, msg) => {
2931
- let e = new ProcfsError$1(ProcfsError$1.ERR_PARSING_FAILED, `Parsing failed: ${msg}`);
2932
- e.sourceText = src;
2933
- return e;
2934
- };
2935
-
2936
- ProcfsError$1.generic = err => {
2937
- /* istanbul ignore next should not ever happen */
2938
- if (err instanceof ProcfsError$1) {
2939
- return err;
2940
- }
2941
-
2942
- switch (err.code) {
2943
- case 'ENOENT':
2944
- return new ProcfsError$1(ProcfsError$1.ERR_NOT_FOUND, 'File not found', err);
2945
- /* istanbul ignore next should not ever happen*/
2946
- default:
2947
- return new ProcfsError$1(ProcfsError$1.ERR_UNKNOWN, `Unknown error: ${err.message}`, err);
2948
- }
2949
- };
2950
-
2951
- var procfsError = ProcfsError$1;
2952
-
2953
- const trim = str => str.trim();
2954
-
2955
- class Parsers {}
2956
-
2957
- const parsers$1 = new Parsers();
2958
-
2959
- for (let name of [
2960
- 'cgroups',
2961
- 'config',
2962
- 'cpuinfo',
2963
- 'devices',
2964
- 'diskstats',
2965
- 'filesystems',
2966
- 'loadavg',
2967
- 'meminfo',
2968
- 'partitions',
2969
- 'processAutogroup',
2970
- 'processCgroups',
2971
- 'processCmdline',
2972
- 'processEnviron',
2973
- 'processes',
2974
- 'processExe',
2975
- 'processFd',
2976
- 'processFdinfo',
2977
- 'processFds',
2978
- 'processGidMap',
2979
- 'processIo',
2980
- 'processLimits',
2981
- 'processMountinfo',
2982
- 'processNetDev',
2983
- 'processNetTcp4',
2984
- 'processNetTcp6',
2985
- 'processNetUdp4',
2986
- 'processNetUdp6',
2987
- 'processNetUnix',
2988
- 'processNetWireless',
2989
- 'processStat',
2990
- 'processStatm',
2991
- 'processStatus',
2992
- 'processThreads',
2993
- 'processUidMap',
2994
- 'stat',
2995
- 'swaps',
2996
- 'uptime',
2997
- ]) {
2998
- Object.defineProperty(Parsers.prototype, name, {
2999
- get: function () { // eslint-disable-line object-shorthand
3000
- let value = index.commonjsRequire(`./parsers/${name}`);
3001
- Object.defineProperty(this, name, {value});
3002
- return value;
3003
- },
3004
- });
3005
- }
3006
-
3007
- parsers$1.cmdline = trim;
3008
- parsers$1.processComm = trim;
3009
- parsers$1.processCpuset = trim;
3010
- parsers$1.processOomScore = src => parseInt(src);
3011
- parsers$1.processTimerslackNs = src => parseInt(src);
3012
- parsers$1.version = trim;
3013
- parsers$1.processCwd = src => src;
3014
- parsers$1.processPersonality = src => parseInt(src, 16);
3015
-
3016
- var parsers_1 = parsers$1;
3017
-
3018
- const {
3019
- readlinkSync,
3020
- readdirSync,
3021
- openSync,
3022
- readSync,
3023
- closeSync,
3024
- readFileSync,
3025
- existsSync,
3026
- } = require$$0$1;
3027
-
3028
- const tmpBufMinLen = 4096 * 2;
3029
- const tmpBufMaxLen = 4096 * 8;
3030
-
3031
- let tmpBuf = Buffer.allocUnsafeSlow(tmpBufMinLen);
3032
-
3033
- const read$1 = path => {
3034
- const fd = openSync(path, 'r', 0o666);
3035
- let pos = 0;
3036
- let bytesRead;
3037
- let buf = tmpBuf;
3038
- let length = buf.length;
3039
- do {
3040
- bytesRead = readSync(fd, buf, pos, buf.length - pos, null);
3041
- pos += bytesRead;
3042
- if (pos === tmpBuf.length) {
3043
- length = length << 1;
3044
- let newBuf = Buffer.allocUnsafeSlow(length);
3045
-
3046
- if (length <= tmpBufMaxLen) {
3047
- tmpBuf = newBuf;
3048
- }
3049
-
3050
- buf.copy(newBuf);
3051
- buf = newBuf;
3052
- }
3053
- } while (bytesRead !== 0);
3054
- closeSync(fd);
3055
- return buf.toString('utf8', 0, pos);
3056
- };
3057
-
3058
- const readIdList = path => {
3059
- let ls = readdirSync(path);
3060
- for (let i = 0; i < ls.length; i++) {
3061
- ls[i] = parseInt(ls[i]);
3062
- }
3063
- return ls;
3064
- };
3065
-
3066
- const readBuffer$1 = readFileSync;
3067
- const exists = existsSync;
3068
- const readdir$1 = readdirSync;
3069
-
3070
- const devIdGetMinor$1 = devId => (((devId >> 20) << 8) | (devId & 0xFF));
3071
- const devIdGetMajor$1 = devId => ((devId >> 8) & 0xFF);
3072
- const devIdFromMajorMinor$1 = (major, minor) => (((minor >> 8) << 20) | ((major & 0xFF) << 8) | (minor & 0xFF));
3073
-
3074
- var utils = {
3075
- read: read$1,
3076
- readLink: readlinkSync,
3077
- readIdList,
3078
- readBuffer: readBuffer$1,
3079
- exists,
3080
- readdir: readdir$1,
3081
-
3082
- devIdGetMinor: devIdGetMinor$1,
3083
- devIdGetMajor: devIdGetMajor$1,
3084
- devIdFromMajorMinor: devIdFromMajorMinor$1,
3085
- };
3086
-
3087
- const ProcfsError = procfsError;
3088
- const parsers = parsers_1;
3089
- const {
3090
- read,
3091
- readLink,
3092
- readBuffer,
3093
- readdir,
3094
- devIdGetMinor,
3095
- devIdGetMajor,
3096
- devIdFromMajorMinor,
3097
- } = utils;
3098
-
3099
- class Procfs {
3100
- constructor(root) {
3101
- if (root === undefined) {
3102
- root = '/proc';
3103
- }
3104
- this.root = root;
3105
- this.rootSlash = `${root}/`;
3106
- }
3107
-
3108
- processes() {
3109
- try {
3110
- return parsers.processes(readdir(this.root));
3111
- } catch (error) {
3112
- /* istanbul ignore next should not ever happen when procfs exists */
3113
- throw ProcfsError.generic(error);
3114
- }
3115
- }
3116
-
3117
- processFds(pid) {
3118
- if (pid !== undefined && (!Number.isInteger(pid) || pid <= 0)) {
3119
- throw new TypeError('pid');
3120
- }
3121
- try {
3122
- return parsers.processFds(readdir(`${this.rootSlash}${pid === undefined ? 'self' : pid}/fd`));
3123
- } catch (error) {
3124
- throw ProcfsError.generic(error);
3125
- }
3126
- }
3127
-
3128
- processThreads(pid) {
3129
- if (pid !== undefined && (!Number.isInteger(pid) || pid <= 0)) {
3130
- throw new TypeError('pid');
3131
- }
3132
- try {
3133
- return parsers.processThreads(readdir(`${this.rootSlash}${pid === undefined ? 'self' : pid}/task`));
3134
- } catch (error) {
3135
- throw ProcfsError.generic(error);
3136
- }
3137
- }
3138
-
3139
- processFdinfo(fd, pid) {
3140
- if (pid !== undefined && !(Number.isInteger(pid) && pid >= 0)) {
3141
- throw new TypeError('pid');
3142
- }
3143
- if (!Number.isInteger(fd) || fd <= 0) {
3144
- throw new TypeError('fd');
3145
- }
3146
- try {
3147
- return parsers.processFdinfo(read(`${this.rootSlash}${pid === undefined ? 'self' : pid}/fdinfo/${fd}`));
3148
- } catch (error) {
3149
- throw ProcfsError.generic(error);
3150
- }
3151
- }
3152
-
3153
- processFd(fd, pid) {
3154
- if (pid !== undefined && !(Number.isInteger(pid) && pid >= 0)) {
3155
- throw new TypeError('pid');
3156
- }
3157
- if (!Number.isInteger(fd) || fd <= 0) {
3158
- throw new TypeError('fd');
3159
- }
3160
- try {
3161
- return parsers.processFd(readLink(`${this.rootSlash}${pid === undefined ? 'self' : pid}/fd/${fd}`));
3162
- } catch (error) {
3163
- throw ProcfsError.generic(error);
3164
- }
3165
- }
3166
-
3167
- config() {
3168
- try {
3169
- return parsers.config(readBuffer(`${this.rootSlash}config.gz`));
3170
- } catch (error) {
3171
- /* istanbul ignore next should not ever happen when procfs exists and kernel properly configured */
3172
- throw ProcfsError.generic(error);
3173
- }
3174
- }
3175
- }
3176
-
3177
- Procfs.prototype.devIdGetMinor = devIdGetMinor;
3178
- Procfs.prototype.devIdGetMajor = devIdGetMajor;
3179
- Procfs.prototype.devIdFromMajorMinor = devIdFromMajorMinor;
3180
-
3181
- for (let [name, path] of [
3182
- ['processExe', '/exe'],
3183
- ['processCwd', '/cwd'],
3184
- ]) {
3185
- Procfs.prototype[name] = function (pid) {
3186
- if (pid !== undefined && !(Number.isInteger(pid) && pid >= 0)) {
3187
- throw new TypeError('pid');
3188
- }
3189
- try {
3190
- return parsers[name](readLink(`${this.rootSlash}${pid === undefined ? 'self' : pid}${path}`));
3191
- } catch (error) {
3192
- throw ProcfsError.generic(error);
3193
- }
3194
- };
3195
- }
3196
-
3197
- for (let [name, path] of [
3198
- ['processMountinfo', '/mountinfo'],
3199
- ['processIo', '/io'],
3200
- ['processUidMap', '/uid_map'],
3201
- ['processGidMap', '/gid_map'],
3202
- ['processEnviron', '/environ'],
3203
- ['processOomScore', '/oom_score'],
3204
- ['processTimerslackNs', '/timerslack_ns'],
3205
- ['processCmdline', '/cmdline'],
3206
- ['processAutogroup', '/autogroup'],
3207
- ['processStatm', '/statm'],
3208
- ['processComm', '/comm'],
3209
- ['processPersonality', '/personality'],
3210
- ['processCgroups', '/cgroup'],
3211
- ['processCpuset', '/cpuset'],
3212
- ['processLimits', '/limits'],
3213
- ['processStat', '/stat'],
3214
- ['processStatus', '/status'],
3215
- ['processNetDev', '/net/dev'],
3216
- ['processNetWireless', '/net/wireless'],
3217
- ['processNetUnix', '/net/unix'],
3218
- ['processNetTcp4', '/net/tcp'],
3219
- ['processNetTcp6', '/net/tcp6'],
3220
- ['processNetUdp4', '/net/udp'],
3221
- ['processNetUdp6', '/net/udp6'],
3222
- ]) {
3223
- Procfs.prototype[name] = function (pid) {
3224
- if (pid !== undefined && !(Number.isInteger(pid) && pid >= 0)) {
3225
- throw new TypeError('pid');
3226
- }
3227
- try {
3228
- return parsers[name](read(`${this.rootSlash}${pid === undefined ? 'self' : pid}${path}`));
3229
- } catch (error) {
3230
- throw ProcfsError.generic(error);
3231
- }
3232
- };
3233
- }
3234
-
3235
- for (let name of [
3236
- 'cpuinfo',
3237
- 'loadavg',
3238
- 'uptime',
3239
- 'version',
3240
- 'cmdline',
3241
- 'swaps',
3242
- 'stat',
3243
- 'devices',
3244
- 'filesystems',
3245
- 'diskstats',
3246
- 'partitions',
3247
- 'meminfo',
3248
- 'cgroups',
3249
- ]) {
3250
- Procfs.prototype[name] = function () {
3251
- try {
3252
- return parsers[name](read(this.rootSlash + name));
3253
- } catch (error) {
3254
- /* istanbul ignore next should not ever happen when procfs exists */
3255
- throw ProcfsError.generic(error);
3256
- }
3257
- };
3258
- }
3259
-
3260
- for (let [name, parser, path] of [
3261
- ['netDev', 'processNetDev', 'net/dev'],
3262
- ['netWireless', 'processNetWireless', 'net/wireless'],
3263
- ['netUnix', 'processNetUnix', 'net/unix'],
3264
- ['netTcp4', 'processNetTcp4', 'net/tcp'],
3265
- ['netTcp6', 'processNetTcp6', 'net/tcp6'],
3266
- ['netUdp4', 'processNetUdp4', 'net/udp'],
3267
- ['netUdp6', 'processNetUdp6', 'net/udp6'],
3268
- ]) {
3269
- Procfs.prototype[name] = function () {
3270
- try {
3271
- return parsers[parser](read(this.rootSlash + path));
3272
- } catch (error) {
3273
- /* istanbul ignore next should not ever happen when procfs exists */
3274
- throw ProcfsError.generic(error);
3275
- }
3276
- };
3277
- }
3278
-
3279
- const procfs = new Procfs();
3280
- var procfs_1 = {
3281
- procfs,
3282
- Procfs,
3283
- ProcfsError,
3284
- };
3285
-
3286
- // Educated guess, values of 16 to 64 seem to be optimal for modern SSD, 8-16 and 64-128 can be a bit slower.
3287
- // We should be ok as long as ssdCount <= cpuCount <= ssdCount*16.
3288
- // For slower media this is not as important and we rely on OS handling it for us.
3289
- const concurrency = os$3.cpus().length * 8;
3290
-
3291
- const pad = number => number < 10 ? '0' + number : number;
3292
-
3293
- const getDeletionDate = date => date.getFullYear()
3294
- + '-' + pad(date.getMonth() + 1)
3295
- + '-' + pad(date.getDate())
3296
- + 'T' + pad(date.getHours())
3297
- + ':' + pad(date.getMinutes())
3298
- + ':' + pad(date.getSeconds());
3299
-
3300
- const trash = async (filePath, trashPaths) => {
3301
- const name = crypto.randomUUID();
3302
- const destination = path$5.join(trashPaths.filesPath, name);
3303
- const trashInfoPath = path$5.join(trashPaths.infoPath, `${name}.trashinfo`);
3304
-
3305
- const trashInfoData = `[Trash Info]\nPath=${filePath.replaceAll(/\s/g, '%20')}\nDeletionDate=${getDeletionDate(new Date())}`;
3306
-
3307
- await fs$3.promises.writeFile(trashInfoPath, trashInfoData);
3308
- await moveFile(filePath, destination);
3309
-
3310
- return {
3311
- path: destination,
3312
- info: trashInfoPath,
3313
- };
3314
- };
3315
-
3316
- async function linux(paths) {
3317
- const mountPointMap = new Map();
3318
-
3319
- for (const mountInfo of Object.values(procfs_1.procfs.processMountinfo())) {
3320
- // Filter out irrelevant drives (that start with `/snap`, `/run`, etc).
3321
- if (/^\/(snap|var\/snap|run|sys|proc|dev)($|\/)/.test(mountInfo.mountPoint)) {
3322
- continue;
3323
- }
3324
-
3325
- // Keep the first one if there are multiple `devId`.
3326
- if (!mountPointMap.has(mountInfo.devId)) {
3327
- mountPointMap.set(mountInfo.devId, mountInfo.mountPoint);
3328
- }
3329
- }
3330
-
3331
- const trashPathsCache = new Map();
3332
-
3333
- const getDeviceTrashPaths = async developmentId => {
3334
- let trashPathsPromise = trashPathsCache.get(developmentId);
3335
- if (trashPathsPromise === undefined) {
3336
- trashPathsPromise = (async () => {
3337
- const trashPath = await xdgTrashdir(mountPointMap.get(developmentId));
3338
- const paths = {
3339
- filesPath: path$5.join(trashPath, 'files'),
3340
- infoPath: path$5.join(trashPath, 'info'),
3341
- };
3342
- await fs$3.promises.mkdir(paths.filesPath, {mode: 0o700, recursive: true});
3343
- await fs$3.promises.mkdir(paths.infoPath, {mode: 0o700, recursive: true});
3344
- return paths;
3345
- })();
3346
- trashPathsCache.set(developmentId, trashPathsPromise);
3347
- }
3348
-
3349
- return trashPathsPromise;
3350
- };
3351
-
3352
- return pMap(paths, async filePath => {
3353
- const stats = await fs$3.promises.lstat(filePath);
3354
- const trashPaths = await getDeviceTrashPaths(stats.dev);
3355
- return trash(filePath, trashPaths);
3356
- }, {concurrency});
3357
- }
3358
-
3359
- exports.default = linux;