You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1065 lines
27 KiB
1065 lines
27 KiB
import require$$0$1 from 'child_process';
|
|
import g from 'path';
|
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
|
|
import require$$0 from 'fs';
|
|
import assert$1 from 'assert';
|
|
import require$$2 from 'events';
|
|
import require$$0$3 from 'buffer';
|
|
import require$$0$2 from 'stream';
|
|
import util from 'util';
|
|
|
|
var crossSpawn = {exports: {}};
|
|
|
|
var windows;
|
|
var hasRequiredWindows;
|
|
|
|
function requireWindows () {
|
|
if (hasRequiredWindows) return windows;
|
|
hasRequiredWindows = 1;
|
|
windows = isexe;
|
|
isexe.sync = sync;
|
|
|
|
var fs = require$$0;
|
|
|
|
function checkPathExt (path, options) {
|
|
var pathext = options.pathExt !== undefined ?
|
|
options.pathExt : process.env.PATHEXT;
|
|
|
|
if (!pathext) {
|
|
return true
|
|
}
|
|
|
|
pathext = pathext.split(';');
|
|
if (pathext.indexOf('') !== -1) {
|
|
return true
|
|
}
|
|
for (var i = 0; i < pathext.length; i++) {
|
|
var p = pathext[i].toLowerCase();
|
|
if (p && path.substr(-p.length).toLowerCase() === p) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
function checkStat (stat, path, options) {
|
|
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
return false
|
|
}
|
|
return checkPathExt(path, options)
|
|
}
|
|
|
|
function isexe (path, options, cb) {
|
|
fs.stat(path, function (er, stat) {
|
|
cb(er, er ? false : checkStat(stat, path, options));
|
|
});
|
|
}
|
|
|
|
function sync (path, options) {
|
|
return checkStat(fs.statSync(path), path, options)
|
|
}
|
|
return windows;
|
|
}
|
|
|
|
var mode;
|
|
var hasRequiredMode;
|
|
|
|
function requireMode () {
|
|
if (hasRequiredMode) return mode;
|
|
hasRequiredMode = 1;
|
|
mode = isexe;
|
|
isexe.sync = sync;
|
|
|
|
var fs = require$$0;
|
|
|
|
function isexe (path, options, cb) {
|
|
fs.stat(path, function (er, stat) {
|
|
cb(er, er ? false : checkStat(stat, options));
|
|
});
|
|
}
|
|
|
|
function sync (path, options) {
|
|
return checkStat(fs.statSync(path), options)
|
|
}
|
|
|
|
function checkStat (stat, options) {
|
|
return stat.isFile() && checkMode(stat, options)
|
|
}
|
|
|
|
function checkMode (stat, options) {
|
|
var mod = stat.mode;
|
|
var uid = stat.uid;
|
|
var gid = stat.gid;
|
|
|
|
var myUid = options.uid !== undefined ?
|
|
options.uid : process.getuid && process.getuid();
|
|
var myGid = options.gid !== undefined ?
|
|
options.gid : process.getgid && process.getgid();
|
|
|
|
var u = parseInt('100', 8);
|
|
var g = parseInt('010', 8);
|
|
var o = parseInt('001', 8);
|
|
var ug = u | g;
|
|
|
|
var ret = (mod & o) ||
|
|
(mod & g) && gid === myGid ||
|
|
(mod & u) && uid === myUid ||
|
|
(mod & ug) && myUid === 0;
|
|
|
|
return ret
|
|
}
|
|
return mode;
|
|
}
|
|
|
|
var core;
|
|
if (process.platform === 'win32' || commonjsGlobal.TESTING_WINDOWS) {
|
|
core = requireWindows();
|
|
} else {
|
|
core = requireMode();
|
|
}
|
|
|
|
var isexe_1 = isexe$1;
|
|
isexe$1.sync = sync;
|
|
|
|
function isexe$1 (path, options, cb) {
|
|
if (typeof options === 'function') {
|
|
cb = options;
|
|
options = {};
|
|
}
|
|
|
|
if (!cb) {
|
|
if (typeof Promise !== 'function') {
|
|
throw new TypeError('callback not provided')
|
|
}
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
isexe$1(path, options || {}, function (er, is) {
|
|
if (er) {
|
|
reject(er);
|
|
} else {
|
|
resolve(is);
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
core(path, options || {}, function (er, is) {
|
|
// ignore EACCES because that just means we aren't allowed to run it
|
|
if (er) {
|
|
if (er.code === 'EACCES' || options && options.ignoreErrors) {
|
|
er = null;
|
|
is = false;
|
|
}
|
|
}
|
|
cb(er, is);
|
|
});
|
|
}
|
|
|
|
function sync (path, options) {
|
|
// my kingdom for a filtered catch
|
|
try {
|
|
return core.sync(path, options || {})
|
|
} catch (er) {
|
|
if (options && options.ignoreErrors || er.code === 'EACCES') {
|
|
return false
|
|
} else {
|
|
throw er
|
|
}
|
|
}
|
|
}
|
|
|
|
const isWindows = process.platform === 'win32' ||
|
|
process.env.OSTYPE === 'cygwin' ||
|
|
process.env.OSTYPE === 'msys';
|
|
|
|
const path$2 = g;
|
|
const COLON = isWindows ? ';' : ':';
|
|
const isexe = isexe_1;
|
|
|
|
const getNotFoundError = (cmd) =>
|
|
Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' });
|
|
|
|
const getPathInfo = (cmd, opt) => {
|
|
const colon = opt.colon || COLON;
|
|
|
|
// If it has a slash, then we don't bother searching the pathenv.
|
|
// just check the file itself, and that's it.
|
|
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? ['']
|
|
: (
|
|
[
|
|
// windows always checks the cwd first
|
|
...(isWindows ? [process.cwd()] : []),
|
|
...(opt.path || process.env.PATH ||
|
|
/* istanbul ignore next: very unusual */ '').split(colon),
|
|
]
|
|
);
|
|
const pathExtExe = isWindows
|
|
? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM'
|
|
: '';
|
|
const pathExt = isWindows ? pathExtExe.split(colon) : [''];
|
|
|
|
if (isWindows) {
|
|
if (cmd.indexOf('.') !== -1 && pathExt[0] !== '')
|
|
pathExt.unshift('');
|
|
}
|
|
|
|
return {
|
|
pathEnv,
|
|
pathExt,
|
|
pathExtExe,
|
|
}
|
|
};
|
|
|
|
const which$1 = (cmd, opt, cb) => {
|
|
if (typeof opt === 'function') {
|
|
cb = opt;
|
|
opt = {};
|
|
}
|
|
if (!opt)
|
|
opt = {};
|
|
|
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
const found = [];
|
|
|
|
const step = i => new Promise((resolve, reject) => {
|
|
if (i === pathEnv.length)
|
|
return opt.all && found.length ? resolve(found)
|
|
: reject(getNotFoundError(cmd))
|
|
|
|
const ppRaw = pathEnv[i];
|
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
|
|
const pCmd = path$2.join(pathPart, cmd);
|
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd
|
|
: pCmd;
|
|
|
|
resolve(subStep(p, i, 0));
|
|
});
|
|
|
|
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
if (ii === pathExt.length)
|
|
return resolve(step(i + 1))
|
|
const ext = pathExt[ii];
|
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
if (!er && is) {
|
|
if (opt.all)
|
|
found.push(p + ext);
|
|
else
|
|
return resolve(p + ext)
|
|
}
|
|
return resolve(subStep(p, i, ii + 1))
|
|
});
|
|
});
|
|
|
|
return cb ? step(0).then(res => cb(null, res), cb) : step(0)
|
|
};
|
|
|
|
const whichSync = (cmd, opt) => {
|
|
opt = opt || {};
|
|
|
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
const found = [];
|
|
|
|
for (let i = 0; i < pathEnv.length; i ++) {
|
|
const ppRaw = pathEnv[i];
|
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
|
|
const pCmd = path$2.join(pathPart, cmd);
|
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd
|
|
: pCmd;
|
|
|
|
for (let j = 0; j < pathExt.length; j ++) {
|
|
const cur = p + pathExt[j];
|
|
try {
|
|
const is = isexe.sync(cur, { pathExt: pathExtExe });
|
|
if (is) {
|
|
if (opt.all)
|
|
found.push(cur);
|
|
else
|
|
return cur
|
|
}
|
|
} catch (ex) {}
|
|
}
|
|
}
|
|
|
|
if (opt.all && found.length)
|
|
return found
|
|
|
|
if (opt.nothrow)
|
|
return null
|
|
|
|
throw getNotFoundError(cmd)
|
|
};
|
|
|
|
var which_1 = which$1;
|
|
which$1.sync = whichSync;
|
|
|
|
var pathKey$1 = {exports: {}};
|
|
|
|
const pathKey = (options = {}) => {
|
|
const environment = options.env || process.env;
|
|
const platform = options.platform || process.platform;
|
|
|
|
if (platform !== 'win32') {
|
|
return 'PATH';
|
|
}
|
|
|
|
return Object.keys(environment).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';
|
|
};
|
|
|
|
pathKey$1.exports = pathKey;
|
|
// TODO: Remove this for the next major release
|
|
pathKey$1.exports.default = pathKey;
|
|
|
|
const path$1 = g;
|
|
const which = which_1;
|
|
const getPathKey = pathKey$1.exports;
|
|
|
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
const env = parsed.options.env || process.env;
|
|
const cwd = process.cwd();
|
|
const hasCustomCwd = parsed.options.cwd != null;
|
|
// Worker threads do not have process.chdir()
|
|
const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled;
|
|
|
|
// If a custom `cwd` was specified, we need to change the process cwd
|
|
// because `which` will do stat calls but does not support a custom cwd
|
|
if (shouldSwitchCwd) {
|
|
try {
|
|
process.chdir(parsed.options.cwd);
|
|
} catch (err) {
|
|
/* Empty */
|
|
}
|
|
}
|
|
|
|
let resolved;
|
|
|
|
try {
|
|
resolved = which.sync(parsed.command, {
|
|
path: env[getPathKey({ env })],
|
|
pathExt: withoutPathExt ? path$1.delimiter : undefined,
|
|
});
|
|
} catch (e) {
|
|
/* Empty */
|
|
} finally {
|
|
if (shouldSwitchCwd) {
|
|
process.chdir(cwd);
|
|
}
|
|
}
|
|
|
|
// If we successfully resolved, ensure that an absolute path is returned
|
|
// Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it
|
|
if (resolved) {
|
|
resolved = path$1.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved);
|
|
}
|
|
|
|
return resolved;
|
|
}
|
|
|
|
function resolveCommand$1(parsed) {
|
|
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
|
|
}
|
|
|
|
var resolveCommand_1 = resolveCommand$1;
|
|
|
|
var _escape = {};
|
|
|
|
// See http://www.robvanderwoude.com/escapechars.php
|
|
const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
|
|
|
function escapeCommand(arg) {
|
|
// Escape meta chars
|
|
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
|
|
return arg;
|
|
}
|
|
|
|
function escapeArgument(arg, doubleEscapeMetaChars) {
|
|
// Convert to string
|
|
arg = `${arg}`;
|
|
|
|
// Algorithm below is based on https://qntm.org/cmd
|
|
|
|
// Sequence of backslashes followed by a double quote:
|
|
// double up all the backslashes and escape the double quote
|
|
arg = arg.replace(/(\\*)"/g, '$1$1\\"');
|
|
|
|
// Sequence of backslashes followed by the end of the string
|
|
// (which will become a double quote later):
|
|
// double up all the backslashes
|
|
arg = arg.replace(/(\\*)$/, '$1$1');
|
|
|
|
// All other backslashes occur literally
|
|
|
|
// Quote the whole thing:
|
|
arg = `"${arg}"`;
|
|
|
|
// Escape meta chars
|
|
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
|
|
// Double escape meta chars if necessary
|
|
if (doubleEscapeMetaChars) {
|
|
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
}
|
|
|
|
return arg;
|
|
}
|
|
|
|
_escape.command = escapeCommand;
|
|
_escape.argument = escapeArgument;
|
|
|
|
var shebangRegex$1 = /^#!(.*)/;
|
|
|
|
const shebangRegex = shebangRegex$1;
|
|
|
|
var shebangCommand$1 = (string = '') => {
|
|
const match = string.match(shebangRegex);
|
|
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
|
|
const [path, argument] = match[0].replace(/#! ?/, '').split(' ');
|
|
const binary = path.split('/').pop();
|
|
|
|
if (binary === 'env') {
|
|
return argument;
|
|
}
|
|
|
|
return argument ? `${binary} ${argument}` : binary;
|
|
};
|
|
|
|
const fs = require$$0;
|
|
const shebangCommand = shebangCommand$1;
|
|
|
|
function readShebang$1(command) {
|
|
// Read the first 150 bytes from the file
|
|
const size = 150;
|
|
const buffer = Buffer.alloc(size);
|
|
|
|
let fd;
|
|
|
|
try {
|
|
fd = fs.openSync(command, 'r');
|
|
fs.readSync(fd, buffer, 0, size, 0);
|
|
fs.closeSync(fd);
|
|
} catch (e) { /* Empty */ }
|
|
|
|
// Attempt to extract shebang (null is returned if not a shebang)
|
|
return shebangCommand(buffer.toString());
|
|
}
|
|
|
|
var readShebang_1 = readShebang$1;
|
|
|
|
const path = g;
|
|
const resolveCommand = resolveCommand_1;
|
|
const escape = _escape;
|
|
const readShebang = readShebang_1;
|
|
|
|
const isWin$2 = process.platform === 'win32';
|
|
const isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
|
|
function detectShebang(parsed) {
|
|
parsed.file = resolveCommand(parsed);
|
|
|
|
const shebang = parsed.file && readShebang(parsed.file);
|
|
|
|
if (shebang) {
|
|
parsed.args.unshift(parsed.file);
|
|
parsed.command = shebang;
|
|
|
|
return resolveCommand(parsed);
|
|
}
|
|
|
|
return parsed.file;
|
|
}
|
|
|
|
function parseNonShell(parsed) {
|
|
if (!isWin$2) {
|
|
return parsed;
|
|
}
|
|
|
|
// Detect & add support for shebangs
|
|
const commandFile = detectShebang(parsed);
|
|
|
|
// We don't need a shell if the command filename is an executable
|
|
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
|
|
// If a shell is required, use cmd.exe and take care of escaping everything correctly
|
|
// Note that `forceShell` is an hidden option used only in tests
|
|
if (parsed.options.forceShell || needsShell) {
|
|
// Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`
|
|
// The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument
|
|
// Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,
|
|
// we need to double escape them
|
|
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
|
|
// Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\bar)
|
|
// This is necessary otherwise it will always fail with ENOENT in those cases
|
|
parsed.command = path.normalize(parsed.command);
|
|
|
|
// Escape command & arguments
|
|
parsed.command = escape.command(parsed.command);
|
|
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
|
|
const shellCommand = [parsed.command].concat(parsed.args).join(' ');
|
|
|
|
parsed.args = ['/d', '/s', '/c', `"${shellCommand}"`];
|
|
parsed.command = process.env.comspec || 'cmd.exe';
|
|
parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped
|
|
}
|
|
|
|
return parsed;
|
|
}
|
|
|
|
function parse$1(command, args, options) {
|
|
// Normalize arguments, similar to nodejs
|
|
if (args && !Array.isArray(args)) {
|
|
options = args;
|
|
args = null;
|
|
}
|
|
|
|
args = args ? args.slice(0) : []; // Clone array to avoid changing the original
|
|
options = Object.assign({}, options); // Clone object to avoid changing the original
|
|
|
|
// Build our parsed object
|
|
const parsed = {
|
|
command,
|
|
args,
|
|
options,
|
|
file: undefined,
|
|
original: {
|
|
command,
|
|
args,
|
|
},
|
|
};
|
|
|
|
// Delegate further parsing to shell or non-shell
|
|
return options.shell ? parsed : parseNonShell(parsed);
|
|
}
|
|
|
|
var parse_1 = parse$1;
|
|
|
|
const isWin$1 = process.platform === 'win32';
|
|
|
|
function notFoundError(original, syscall) {
|
|
return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
|
|
code: 'ENOENT',
|
|
errno: 'ENOENT',
|
|
syscall: `${syscall} ${original.command}`,
|
|
path: original.command,
|
|
spawnargs: original.args,
|
|
});
|
|
}
|
|
|
|
function hookChildProcess(cp, parsed) {
|
|
if (!isWin$1) {
|
|
return;
|
|
}
|
|
|
|
const originalEmit = cp.emit;
|
|
|
|
cp.emit = function (name, arg1) {
|
|
// If emitting "exit" event and exit code is 1, we need to check if
|
|
// the command exists and emit an "error" instead
|
|
// See https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
if (name === 'exit') {
|
|
const err = verifyENOENT(arg1, parsed);
|
|
|
|
if (err) {
|
|
return originalEmit.call(cp, 'error', err);
|
|
}
|
|
}
|
|
|
|
return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params
|
|
};
|
|
}
|
|
|
|
function verifyENOENT(status, parsed) {
|
|
if (isWin$1 && status === 1 && !parsed.file) {
|
|
return notFoundError(parsed.original, 'spawn');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function verifyENOENTSync(status, parsed) {
|
|
if (isWin$1 && status === 1 && !parsed.file) {
|
|
return notFoundError(parsed.original, 'spawnSync');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
var enoent$1 = {
|
|
hookChildProcess,
|
|
verifyENOENT,
|
|
verifyENOENTSync,
|
|
notFoundError,
|
|
};
|
|
|
|
const cp = require$$0$1;
|
|
const parse = parse_1;
|
|
const enoent = enoent$1;
|
|
|
|
function spawn(command, args, options) {
|
|
// Parse the arguments
|
|
const parsed = parse(command, args, options);
|
|
|
|
// Spawn the child process
|
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
|
|
// Hook into child process "exit" event to emit an error if the command
|
|
// does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
enoent.hookChildProcess(spawned, parsed);
|
|
|
|
return spawned;
|
|
}
|
|
|
|
function spawnSync(command, args, options) {
|
|
// Parse the arguments
|
|
const parsed = parse(command, args, options);
|
|
|
|
// Spawn the child process
|
|
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
|
|
// Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
|
|
return result;
|
|
}
|
|
|
|
crossSpawn.exports = spawn;
|
|
crossSpawn.exports.spawn = spawn;
|
|
crossSpawn.exports.sync = spawnSync;
|
|
|
|
crossSpawn.exports._parse = parse;
|
|
crossSpawn.exports._enoent = enoent;
|
|
|
|
var signalExit = {exports: {}};
|
|
|
|
var signals$1 = {exports: {}};
|
|
|
|
var hasRequiredSignals;
|
|
|
|
function requireSignals () {
|
|
if (hasRequiredSignals) return signals$1.exports;
|
|
hasRequiredSignals = 1;
|
|
(function (module) {
|
|
// This is not the set of all possible signals.
|
|
//
|
|
// It IS, however, the set of all signals that trigger
|
|
// an exit on either Linux or BSD systems. Linux is a
|
|
// superset of the signal names supported on BSD, and
|
|
// the unknown signals just fail to register, so we can
|
|
// catch that easily enough.
|
|
//
|
|
// Don't bother with SIGKILL. It's uncatchable, which
|
|
// means that we can't fire any callbacks anyway.
|
|
//
|
|
// If a user does happen to register a handler on a non-
|
|
// fatal signal like SIGWINCH or something, and then
|
|
// exit, it'll end up firing `process.emit('exit')`, so
|
|
// the handler will be fired anyway.
|
|
//
|
|
// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
// artificially, inherently leave the process in a
|
|
// state from which it is not safe to try and enter JS
|
|
// listeners.
|
|
module.exports = [
|
|
'SIGABRT',
|
|
'SIGALRM',
|
|
'SIGHUP',
|
|
'SIGINT',
|
|
'SIGTERM'
|
|
];
|
|
|
|
if (process.platform !== 'win32') {
|
|
module.exports.push(
|
|
'SIGVTALRM',
|
|
'SIGXCPU',
|
|
'SIGXFSZ',
|
|
'SIGUSR2',
|
|
'SIGTRAP',
|
|
'SIGSYS',
|
|
'SIGQUIT',
|
|
'SIGIOT'
|
|
// should detect profiler and enable/disable accordingly.
|
|
// see #21
|
|
// 'SIGPROF'
|
|
);
|
|
}
|
|
|
|
if (process.platform === 'linux') {
|
|
module.exports.push(
|
|
'SIGIO',
|
|
'SIGPOLL',
|
|
'SIGPWR',
|
|
'SIGSTKFLT',
|
|
'SIGUNUSED'
|
|
);
|
|
}
|
|
} (signals$1));
|
|
return signals$1.exports;
|
|
}
|
|
|
|
// Note: since nyc uses this module to output coverage, any lines
|
|
// that are in the direct sync flow of nyc's outputCoverage are
|
|
// ignored, since we can never get coverage for them.
|
|
// grab a reference to node's real process object right away
|
|
var process$1 = commonjsGlobal.process;
|
|
|
|
const processOk = function (process) {
|
|
return process &&
|
|
typeof process === 'object' &&
|
|
typeof process.removeListener === 'function' &&
|
|
typeof process.emit === 'function' &&
|
|
typeof process.reallyExit === 'function' &&
|
|
typeof process.listeners === 'function' &&
|
|
typeof process.kill === 'function' &&
|
|
typeof process.pid === 'number' &&
|
|
typeof process.on === 'function'
|
|
};
|
|
|
|
// some kind of non-node environment, just no-op
|
|
/* istanbul ignore if */
|
|
if (!processOk(process$1)) {
|
|
signalExit.exports = function () {
|
|
return function () {}
|
|
};
|
|
} else {
|
|
var assert = assert$1;
|
|
var signals = requireSignals();
|
|
var isWin = /^win/i.test(process$1.platform);
|
|
|
|
var EE = require$$2;
|
|
/* istanbul ignore if */
|
|
if (typeof EE !== 'function') {
|
|
EE = EE.EventEmitter;
|
|
}
|
|
|
|
var emitter;
|
|
if (process$1.__signal_exit_emitter__) {
|
|
emitter = process$1.__signal_exit_emitter__;
|
|
} else {
|
|
emitter = process$1.__signal_exit_emitter__ = new EE();
|
|
emitter.count = 0;
|
|
emitter.emitted = {};
|
|
}
|
|
|
|
// Because this emitter is a global, we have to check to see if a
|
|
// previous version of this library failed to enable infinite listeners.
|
|
// I know what you're about to say. But literally everything about
|
|
// signal-exit is a compromise with evil. Get used to it.
|
|
if (!emitter.infinite) {
|
|
emitter.setMaxListeners(Infinity);
|
|
emitter.infinite = true;
|
|
}
|
|
|
|
signalExit.exports = function (cb, opts) {
|
|
/* istanbul ignore if */
|
|
if (!processOk(commonjsGlobal.process)) {
|
|
return function () {}
|
|
}
|
|
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
|
|
|
|
if (loaded === false) {
|
|
load();
|
|
}
|
|
|
|
var ev = 'exit';
|
|
if (opts && opts.alwaysLast) {
|
|
ev = 'afterexit';
|
|
}
|
|
|
|
var remove = function () {
|
|
emitter.removeListener(ev, cb);
|
|
if (emitter.listeners('exit').length === 0 &&
|
|
emitter.listeners('afterexit').length === 0) {
|
|
unload();
|
|
}
|
|
};
|
|
emitter.on(ev, cb);
|
|
|
|
return remove
|
|
};
|
|
|
|
var unload = function unload () {
|
|
if (!loaded || !processOk(commonjsGlobal.process)) {
|
|
return
|
|
}
|
|
loaded = false;
|
|
|
|
signals.forEach(function (sig) {
|
|
try {
|
|
process$1.removeListener(sig, sigListeners[sig]);
|
|
} catch (er) {}
|
|
});
|
|
process$1.emit = originalProcessEmit;
|
|
process$1.reallyExit = originalProcessReallyExit;
|
|
emitter.count -= 1;
|
|
};
|
|
signalExit.exports.unload = unload;
|
|
|
|
var emit = function emit (event, code, signal) {
|
|
/* istanbul ignore if */
|
|
if (emitter.emitted[event]) {
|
|
return
|
|
}
|
|
emitter.emitted[event] = true;
|
|
emitter.emit(event, code, signal);
|
|
};
|
|
|
|
// { <signal>: <listener fn>, ... }
|
|
var sigListeners = {};
|
|
signals.forEach(function (sig) {
|
|
sigListeners[sig] = function listener () {
|
|
/* istanbul ignore if */
|
|
if (!processOk(commonjsGlobal.process)) {
|
|
return
|
|
}
|
|
// If there are no other listeners, an exit is coming!
|
|
// Simplest way: remove us and then re-send the signal.
|
|
// We know that this will kill the process, so we can
|
|
// safely emit now.
|
|
var listeners = process$1.listeners(sig);
|
|
if (listeners.length === emitter.count) {
|
|
unload();
|
|
emit('exit', null, sig);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', null, sig);
|
|
/* istanbul ignore next */
|
|
if (isWin && sig === 'SIGHUP') {
|
|
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
// so use a supported signal instead
|
|
sig = 'SIGINT';
|
|
}
|
|
/* istanbul ignore next */
|
|
process$1.kill(process$1.pid, sig);
|
|
}
|
|
};
|
|
});
|
|
|
|
signalExit.exports.signals = function () {
|
|
return signals
|
|
};
|
|
|
|
var loaded = false;
|
|
|
|
var load = function load () {
|
|
if (loaded || !processOk(commonjsGlobal.process)) {
|
|
return
|
|
}
|
|
loaded = true;
|
|
|
|
// This is the number of onSignalExit's that are in play.
|
|
// It's important so that we can count the correct number of
|
|
// listeners on signals, and don't wait for the other one to
|
|
// handle it instead of us.
|
|
emitter.count += 1;
|
|
|
|
signals = signals.filter(function (sig) {
|
|
try {
|
|
process$1.on(sig, sigListeners[sig]);
|
|
return true
|
|
} catch (er) {
|
|
return false
|
|
}
|
|
});
|
|
|
|
process$1.emit = processEmit;
|
|
process$1.reallyExit = processReallyExit;
|
|
};
|
|
signalExit.exports.load = load;
|
|
|
|
var originalProcessReallyExit = process$1.reallyExit;
|
|
var processReallyExit = function processReallyExit (code) {
|
|
/* istanbul ignore if */
|
|
if (!processOk(commonjsGlobal.process)) {
|
|
return
|
|
}
|
|
process$1.exitCode = code || /* istanbul ignore next */ 0;
|
|
emit('exit', process$1.exitCode, null);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', process$1.exitCode, null);
|
|
/* istanbul ignore next */
|
|
originalProcessReallyExit.call(process$1, process$1.exitCode);
|
|
};
|
|
|
|
var originalProcessEmit = process$1.emit;
|
|
var processEmit = function processEmit (ev, arg) {
|
|
if (ev === 'exit' && processOk(commonjsGlobal.process)) {
|
|
/* istanbul ignore else */
|
|
if (arg !== undefined) {
|
|
process$1.exitCode = arg;
|
|
}
|
|
var ret = originalProcessEmit.apply(this, arguments);
|
|
/* istanbul ignore next */
|
|
emit('exit', process$1.exitCode, null);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', process$1.exitCode, null);
|
|
/* istanbul ignore next */
|
|
return ret
|
|
} else {
|
|
return originalProcessEmit.apply(this, arguments)
|
|
}
|
|
};
|
|
}
|
|
|
|
var getStream$1 = {exports: {}};
|
|
|
|
const {PassThrough: PassThroughStream} = require$$0$2;
|
|
|
|
var bufferStream$1 = options => {
|
|
options = {...options};
|
|
|
|
const {array} = options;
|
|
let {encoding} = options;
|
|
const isBuffer = encoding === 'buffer';
|
|
let objectMode = false;
|
|
|
|
if (array) {
|
|
objectMode = !(encoding || isBuffer);
|
|
} else {
|
|
encoding = encoding || 'utf8';
|
|
}
|
|
|
|
if (isBuffer) {
|
|
encoding = null;
|
|
}
|
|
|
|
const stream = new PassThroughStream({objectMode});
|
|
|
|
if (encoding) {
|
|
stream.setEncoding(encoding);
|
|
}
|
|
|
|
let length = 0;
|
|
const chunks = [];
|
|
|
|
stream.on('data', chunk => {
|
|
chunks.push(chunk);
|
|
|
|
if (objectMode) {
|
|
length = chunks.length;
|
|
} else {
|
|
length += chunk.length;
|
|
}
|
|
});
|
|
|
|
stream.getBufferedValue = () => {
|
|
if (array) {
|
|
return chunks;
|
|
}
|
|
|
|
return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
|
|
};
|
|
|
|
stream.getBufferedLength = () => length;
|
|
|
|
return stream;
|
|
};
|
|
|
|
const {constants: BufferConstants} = require$$0$3;
|
|
const stream = require$$0$2;
|
|
const {promisify} = util;
|
|
const bufferStream = bufferStream$1;
|
|
|
|
const streamPipelinePromisified = promisify(stream.pipeline);
|
|
|
|
class MaxBufferError extends Error {
|
|
constructor() {
|
|
super('maxBuffer exceeded');
|
|
this.name = 'MaxBufferError';
|
|
}
|
|
}
|
|
|
|
async function getStream(inputStream, options) {
|
|
if (!inputStream) {
|
|
throw new Error('Expected a stream');
|
|
}
|
|
|
|
options = {
|
|
maxBuffer: Infinity,
|
|
...options
|
|
};
|
|
|
|
const {maxBuffer} = options;
|
|
const stream = bufferStream(options);
|
|
|
|
await new Promise((resolve, reject) => {
|
|
const rejectPromise = error => {
|
|
// Don't retrieve an oversized buffer.
|
|
if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
|
|
error.bufferedData = stream.getBufferedValue();
|
|
}
|
|
|
|
reject(error);
|
|
};
|
|
|
|
(async () => {
|
|
try {
|
|
await streamPipelinePromisified(inputStream, stream);
|
|
resolve();
|
|
} catch (error) {
|
|
rejectPromise(error);
|
|
}
|
|
})();
|
|
|
|
stream.on('data', () => {
|
|
if (stream.getBufferedLength() > maxBuffer) {
|
|
rejectPromise(new MaxBufferError());
|
|
}
|
|
});
|
|
});
|
|
|
|
return stream.getBufferedValue();
|
|
}
|
|
|
|
getStream$1.exports = getStream;
|
|
getStream$1.exports.buffer = (stream, options) => getStream(stream, {...options, encoding: 'buffer'});
|
|
getStream$1.exports.array = (stream, options) => getStream(stream, {...options, array: true});
|
|
getStream$1.exports.MaxBufferError = MaxBufferError;
|
|
|
|
const { PassThrough } = require$$0$2;
|
|
|
|
var mergeStream = function (/*streams...*/) {
|
|
var sources = [];
|
|
var output = new PassThrough({objectMode: true});
|
|
|
|
output.setMaxListeners(0);
|
|
|
|
output.add = add;
|
|
output.isEmpty = isEmpty;
|
|
|
|
output.on('unpipe', remove);
|
|
|
|
Array.prototype.slice.call(arguments).forEach(add);
|
|
|
|
return output
|
|
|
|
function add (source) {
|
|
if (Array.isArray(source)) {
|
|
source.forEach(add);
|
|
return this
|
|
}
|
|
|
|
sources.push(source);
|
|
source.once('end', remove.bind(null, source));
|
|
source.once('error', output.emit.bind(output, 'error'));
|
|
source.pipe(output, {end: false});
|
|
return this
|
|
}
|
|
|
|
function isEmpty () {
|
|
return sources.length == 0;
|
|
}
|
|
|
|
function remove (source) {
|
|
sources = sources.filter(function (it) { return it !== source });
|
|
if (!sources.length && output.readable) { output.end(); }
|
|
}
|
|
};
|
|
|
|
export { crossSpawn as c, getStream$1 as g, mergeStream as m, pathKey$1 as p, signalExit as s };
|
|
|