123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793 |
- import childProcess from 'child_process';
- import path$3 from 'path';
- import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
- import fs$1 from 'fs';
- import require$$0$1 from 'buffer';
- import require$$0 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 = fs$1;
- 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 = fs$1;
- 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 = path$3;
- 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 = path$3;
- 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 = fs$1;
- 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 = path$3;
- const resolveCommand = resolveCommand_1;
- const escape = _escape;
- const readShebang = readShebang_1;
- const isWin$1 = 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$1) {
- 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 = 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) {
- 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 && status === 1 && !parsed.file) {
- return notFoundError(parsed.original, 'spawn');
- }
- return null;
- }
- function verifyENOENTSync(status, parsed) {
- if (isWin && status === 1 && !parsed.file) {
- return notFoundError(parsed.original, 'spawnSync');
- }
- return null;
- }
- var enoent$1 = {
- hookChildProcess,
- verifyENOENT,
- verifyENOENTSync,
- notFoundError,
- };
- const cp = childProcess;
- 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 getStream$1 = {exports: {}};
- const {PassThrough: PassThroughStream} = require$$0;
- 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$1;
- const stream = require$$0;
- 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;
- 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 };
|