1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642 |
- import path$2 from 'path';
- import fs$2 from 'fs';
- import util from 'util';
- import childProcess$1 from 'child_process';
- import { p as pathKey, m as mergeStream$1, g as getStream$1, c as crossSpawn$1 } from './vendor-index.2ae8040a.mjs';
- import { o as onetime$1 } from './vendor-index.9d9196cc.mjs';
- import require$$0 from 'os';
- import { s as signalExit } from './vendor-index.29636037.mjs';
- import './vendor-_commonjsHelpers.4da45ef5.mjs';
- import 'buffer';
- import 'stream';
- import 'assert';
- import 'events';
- var findUp$1 = {exports: {}};
- var locatePath = {exports: {}};
- class Node {
- /// value;
- /// next;
- constructor(value) {
- this.value = value;
- // TODO: Remove this when targeting Node.js 12.
- this.next = undefined;
- }
- }
- class Queue$1 {
- // TODO: Use private class fields when targeting Node.js 12.
- // #_head;
- // #_tail;
- // #_size;
- constructor() {
- this.clear();
- }
- enqueue(value) {
- const node = new Node(value);
- if (this._head) {
- this._tail.next = node;
- this._tail = node;
- } else {
- this._head = node;
- this._tail = node;
- }
- this._size++;
- }
- dequeue() {
- const current = this._head;
- if (!current) {
- return;
- }
- this._head = this._head.next;
- this._size--;
- return current.value;
- }
- clear() {
- this._head = undefined;
- this._tail = undefined;
- this._size = 0;
- }
- get size() {
- return this._size;
- }
- * [Symbol.iterator]() {
- let current = this._head;
- while (current) {
- yield current.value;
- current = current.next;
- }
- }
- }
- var yoctoQueue = Queue$1;
- const Queue = yoctoQueue;
- const pLimit$1 = concurrency => {
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
- }
- const queue = new Queue();
- let activeCount = 0;
- const next = () => {
- activeCount--;
- if (queue.size > 0) {
- queue.dequeue()();
- }
- };
- const run = async (fn, resolve, ...args) => {
- activeCount++;
- const result = (async () => fn(...args))();
- resolve(result);
- try {
- await result;
- } catch {}
- next();
- };
- const enqueue = (fn, resolve, ...args) => {
- queue.enqueue(run.bind(null, fn, resolve, ...args));
- (async () => {
- // This function needs to wait until the next microtask before comparing
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
- // when the run function is dequeued and called. The comparison in the if-statement
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
- await Promise.resolve();
- if (activeCount < concurrency && queue.size > 0) {
- queue.dequeue()();
- }
- })();
- };
- const generator = (fn, ...args) => new Promise(resolve => {
- enqueue(fn, resolve, ...args);
- });
- Object.defineProperties(generator, {
- activeCount: {
- get: () => activeCount
- },
- pendingCount: {
- get: () => queue.size
- },
- clearQueue: {
- value: () => {
- queue.clear();
- }
- }
- });
- return generator;
- };
- var pLimit_1 = pLimit$1;
- const pLimit = pLimit_1;
- class EndError extends Error {
- constructor(value) {
- super();
- this.value = value;
- }
- }
- // The input can also be a promise, so we await it
- const testElement = async (element, tester) => tester(await element);
- // The input can also be a promise, so we `Promise.all()` them both
- const finder = async element => {
- const values = await Promise.all(element);
- if (values[1] === true) {
- throw new EndError(values[0]);
- }
- return false;
- };
- const pLocate$1 = async (iterable, tester, options) => {
- options = {
- concurrency: Infinity,
- preserveOrder: true,
- ...options
- };
- const limit = pLimit(options.concurrency);
- // Start all the promises concurrently with optional limit
- const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
- // Check the promises either serially or concurrently
- const checkLimit = pLimit(options.preserveOrder ? 1 : Infinity);
- try {
- await Promise.all(items.map(element => checkLimit(finder, element)));
- } catch (error) {
- if (error instanceof EndError) {
- return error.value;
- }
- throw error;
- }
- };
- var pLocate_1 = pLocate$1;
- const path$1 = path$2;
- const fs$1 = fs$2;
- const {promisify: promisify$1} = util;
- const pLocate = pLocate_1;
- const fsStat = promisify$1(fs$1.stat);
- const fsLStat = promisify$1(fs$1.lstat);
- const typeMappings = {
- directory: 'isDirectory',
- file: 'isFile'
- };
- function checkType({type}) {
- if (type in typeMappings) {
- return;
- }
- throw new Error(`Invalid type specified: ${type}`);
- }
- const matchType = (type, stat) => type === undefined || stat[typeMappings[type]]();
- locatePath.exports = async (paths, options) => {
- options = {
- cwd: process.cwd(),
- type: 'file',
- allowSymlinks: true,
- ...options
- };
- checkType(options);
- const statFn = options.allowSymlinks ? fsStat : fsLStat;
- return pLocate(paths, async path_ => {
- try {
- const stat = await statFn(path$1.resolve(options.cwd, path_));
- return matchType(options.type, stat);
- } catch {
- return false;
- }
- }, options);
- };
- locatePath.exports.sync = (paths, options) => {
- options = {
- cwd: process.cwd(),
- allowSymlinks: true,
- type: 'file',
- ...options
- };
- checkType(options);
- const statFn = options.allowSymlinks ? fs$1.statSync : fs$1.lstatSync;
- for (const path_ of paths) {
- try {
- const stat = statFn(path$1.resolve(options.cwd, path_));
- if (matchType(options.type, stat)) {
- return path_;
- }
- } catch {}
- }
- };
- var pathExists = {exports: {}};
- const fs = fs$2;
- const {promisify} = util;
- const pAccess = promisify(fs.access);
- pathExists.exports = async path => {
- try {
- await pAccess(path);
- return true;
- } catch (_) {
- return false;
- }
- };
- pathExists.exports.sync = path => {
- try {
- fs.accessSync(path);
- return true;
- } catch (_) {
- return false;
- }
- };
- (function (module) {
- const path = path$2;
- const locatePath$1 = locatePath.exports;
- const pathExists$1 = pathExists.exports;
- const stop = Symbol('findUp.stop');
- module.exports = async (name, options = {}) => {
- let directory = path.resolve(options.cwd || '');
- const {root} = path.parse(directory);
- const paths = [].concat(name);
- const runMatcher = async locateOptions => {
- if (typeof name !== 'function') {
- return locatePath$1(paths, locateOptions);
- }
- const foundPath = await name(locateOptions.cwd);
- if (typeof foundPath === 'string') {
- return locatePath$1([foundPath], locateOptions);
- }
- return foundPath;
- };
- // eslint-disable-next-line no-constant-condition
- while (true) {
- // eslint-disable-next-line no-await-in-loop
- const foundPath = await runMatcher({...options, cwd: directory});
- if (foundPath === stop) {
- return;
- }
- if (foundPath) {
- return path.resolve(directory, foundPath);
- }
- if (directory === root) {
- return;
- }
- directory = path.dirname(directory);
- }
- };
- module.exports.sync = (name, options = {}) => {
- let directory = path.resolve(options.cwd || '');
- const {root} = path.parse(directory);
- const paths = [].concat(name);
- const runMatcher = locateOptions => {
- if (typeof name !== 'function') {
- return locatePath$1.sync(paths, locateOptions);
- }
- const foundPath = name(locateOptions.cwd);
- if (typeof foundPath === 'string') {
- return locatePath$1.sync([foundPath], locateOptions);
- }
- return foundPath;
- };
- // eslint-disable-next-line no-constant-condition
- while (true) {
- const foundPath = runMatcher({...options, cwd: directory});
- if (foundPath === stop) {
- return;
- }
- if (foundPath) {
- return path.resolve(directory, foundPath);
- }
- if (directory === root) {
- return;
- }
- directory = path.dirname(directory);
- }
- };
- module.exports.exists = pathExists$1;
- module.exports.sync.exists = pathExists$1.sync;
- module.exports.stop = stop;
- } (findUp$1));
- var findUp = findUp$1.exports;
- var execa$1 = {exports: {}};
- var stripFinalNewline$1 = input => {
- const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
- const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
- if (input[input.length - 1] === LF) {
- input = input.slice(0, input.length - 1);
- }
- if (input[input.length - 1] === CR) {
- input = input.slice(0, input.length - 1);
- }
- return input;
- };
- var npmRunPath$1 = {exports: {}};
- (function (module) {
- const path = path$2;
- const pathKey$1 = pathKey.exports;
- const npmRunPath = options => {
- options = {
- cwd: process.cwd(),
- path: process.env[pathKey$1()],
- execPath: process.execPath,
- ...options
- };
- let previous;
- let cwdPath = path.resolve(options.cwd);
- const result = [];
- while (previous !== cwdPath) {
- result.push(path.join(cwdPath, 'node_modules/.bin'));
- previous = cwdPath;
- cwdPath = path.resolve(cwdPath, '..');
- }
- // Ensure the running `node` binary is used
- const execPathDir = path.resolve(options.cwd, options.execPath, '..');
- result.push(execPathDir);
- return result.concat(options.path).join(path.delimiter);
- };
- module.exports = npmRunPath;
- // TODO: Remove this for the next major release
- module.exports.default = npmRunPath;
- module.exports.env = options => {
- options = {
- env: process.env,
- ...options
- };
- const env = {...options.env};
- const path = pathKey$1({env});
- options.path = env[path];
- env[path] = module.exports(options);
- return env;
- };
- } (npmRunPath$1));
- var main = {};
- var signals = {};
- var core = {};
- Object.defineProperty(core,"__esModule",{value:true});core.SIGNALS=void 0;
- const SIGNALS=[
- {
- name:"SIGHUP",
- number:1,
- action:"terminate",
- description:"Terminal closed",
- standard:"posix"},
- {
- name:"SIGINT",
- number:2,
- action:"terminate",
- description:"User interruption with CTRL-C",
- standard:"ansi"},
- {
- name:"SIGQUIT",
- number:3,
- action:"core",
- description:"User interruption with CTRL-\\",
- standard:"posix"},
- {
- name:"SIGILL",
- number:4,
- action:"core",
- description:"Invalid machine instruction",
- standard:"ansi"},
- {
- name:"SIGTRAP",
- number:5,
- action:"core",
- description:"Debugger breakpoint",
- standard:"posix"},
- {
- name:"SIGABRT",
- number:6,
- action:"core",
- description:"Aborted",
- standard:"ansi"},
- {
- name:"SIGIOT",
- number:6,
- action:"core",
- description:"Aborted",
- standard:"bsd"},
- {
- name:"SIGBUS",
- number:7,
- action:"core",
- description:
- "Bus error due to misaligned, non-existing address or paging error",
- standard:"bsd"},
- {
- name:"SIGEMT",
- number:7,
- action:"terminate",
- description:"Command should be emulated but is not implemented",
- standard:"other"},
- {
- name:"SIGFPE",
- number:8,
- action:"core",
- description:"Floating point arithmetic error",
- standard:"ansi"},
- {
- name:"SIGKILL",
- number:9,
- action:"terminate",
- description:"Forced termination",
- standard:"posix",
- forced:true},
- {
- name:"SIGUSR1",
- number:10,
- action:"terminate",
- description:"Application-specific signal",
- standard:"posix"},
- {
- name:"SIGSEGV",
- number:11,
- action:"core",
- description:"Segmentation fault",
- standard:"ansi"},
- {
- name:"SIGUSR2",
- number:12,
- action:"terminate",
- description:"Application-specific signal",
- standard:"posix"},
- {
- name:"SIGPIPE",
- number:13,
- action:"terminate",
- description:"Broken pipe or socket",
- standard:"posix"},
- {
- name:"SIGALRM",
- number:14,
- action:"terminate",
- description:"Timeout or timer",
- standard:"posix"},
- {
- name:"SIGTERM",
- number:15,
- action:"terminate",
- description:"Termination",
- standard:"ansi"},
- {
- name:"SIGSTKFLT",
- number:16,
- action:"terminate",
- description:"Stack is empty or overflowed",
- standard:"other"},
- {
- name:"SIGCHLD",
- number:17,
- action:"ignore",
- description:"Child process terminated, paused or unpaused",
- standard:"posix"},
- {
- name:"SIGCLD",
- number:17,
- action:"ignore",
- description:"Child process terminated, paused or unpaused",
- standard:"other"},
- {
- name:"SIGCONT",
- number:18,
- action:"unpause",
- description:"Unpaused",
- standard:"posix",
- forced:true},
- {
- name:"SIGSTOP",
- number:19,
- action:"pause",
- description:"Paused",
- standard:"posix",
- forced:true},
- {
- name:"SIGTSTP",
- number:20,
- action:"pause",
- description:"Paused using CTRL-Z or \"suspend\"",
- standard:"posix"},
- {
- name:"SIGTTIN",
- number:21,
- action:"pause",
- description:"Background process cannot read terminal input",
- standard:"posix"},
- {
- name:"SIGBREAK",
- number:21,
- action:"terminate",
- description:"User interruption with CTRL-BREAK",
- standard:"other"},
- {
- name:"SIGTTOU",
- number:22,
- action:"pause",
- description:"Background process cannot write to terminal output",
- standard:"posix"},
- {
- name:"SIGURG",
- number:23,
- action:"ignore",
- description:"Socket received out-of-band data",
- standard:"bsd"},
- {
- name:"SIGXCPU",
- number:24,
- action:"core",
- description:"Process timed out",
- standard:"bsd"},
- {
- name:"SIGXFSZ",
- number:25,
- action:"core",
- description:"File too big",
- standard:"bsd"},
- {
- name:"SIGVTALRM",
- number:26,
- action:"terminate",
- description:"Timeout or timer",
- standard:"bsd"},
- {
- name:"SIGPROF",
- number:27,
- action:"terminate",
- description:"Timeout or timer",
- standard:"bsd"},
- {
- name:"SIGWINCH",
- number:28,
- action:"ignore",
- description:"Terminal window size changed",
- standard:"bsd"},
- {
- name:"SIGIO",
- number:29,
- action:"terminate",
- description:"I/O is available",
- standard:"other"},
- {
- name:"SIGPOLL",
- number:29,
- action:"terminate",
- description:"Watched event",
- standard:"other"},
- {
- name:"SIGINFO",
- number:29,
- action:"ignore",
- description:"Request for process information",
- standard:"other"},
- {
- name:"SIGPWR",
- number:30,
- action:"terminate",
- description:"Device running out of power",
- standard:"systemv"},
- {
- name:"SIGSYS",
- number:31,
- action:"core",
- description:"Invalid system call",
- standard:"other"},
- {
- name:"SIGUNUSED",
- number:31,
- action:"terminate",
- description:"Invalid system call",
- standard:"other"}];core.SIGNALS=SIGNALS;
- var realtime = {};
- Object.defineProperty(realtime,"__esModule",{value:true});realtime.SIGRTMAX=realtime.getRealtimeSignals=void 0;
- const getRealtimeSignals=function(){
- const length=SIGRTMAX-SIGRTMIN+1;
- return Array.from({length},getRealtimeSignal);
- };realtime.getRealtimeSignals=getRealtimeSignals;
- const getRealtimeSignal=function(value,index){
- return {
- name:`SIGRT${index+1}`,
- number:SIGRTMIN+index,
- action:"terminate",
- description:"Application-specific signal (realtime)",
- standard:"posix"};
- };
- const SIGRTMIN=34;
- const SIGRTMAX=64;realtime.SIGRTMAX=SIGRTMAX;
- Object.defineProperty(signals,"__esModule",{value:true});signals.getSignals=void 0;var _os$1=require$$0;
- var _core=core;
- var _realtime$1=realtime;
- const getSignals=function(){
- const realtimeSignals=(0, _realtime$1.getRealtimeSignals)();
- const signals=[..._core.SIGNALS,...realtimeSignals].map(normalizeSignal);
- return signals;
- };signals.getSignals=getSignals;
- const normalizeSignal=function({
- name,
- number:defaultNumber,
- description,
- action,
- forced=false,
- standard})
- {
- const{
- signals:{[name]:constantSignal}}=
- _os$1.constants;
- const supported=constantSignal!==undefined;
- const number=supported?constantSignal:defaultNumber;
- return {name,number,description,supported,action,forced,standard};
- };
- Object.defineProperty(main,"__esModule",{value:true});main.signalsByNumber=main.signalsByName=void 0;var _os=require$$0;
- var _signals=signals;
- var _realtime=realtime;
- const getSignalsByName=function(){
- const signals=(0, _signals.getSignals)();
- return signals.reduce(getSignalByName,{});
- };
- const getSignalByName=function(
- signalByNameMemo,
- {name,number,description,supported,action,forced,standard})
- {
- return {
- ...signalByNameMemo,
- [name]:{name,number,description,supported,action,forced,standard}};
- };
- const signalsByName$1=getSignalsByName();main.signalsByName=signalsByName$1;
- const getSignalsByNumber=function(){
- const signals=(0, _signals.getSignals)();
- const length=_realtime.SIGRTMAX+1;
- const signalsA=Array.from({length},(value,number)=>
- getSignalByNumber(number,signals));
- return Object.assign({},...signalsA);
- };
- const getSignalByNumber=function(number,signals){
- const signal=findSignalByNumber(number,signals);
- if(signal===undefined){
- return {};
- }
- const{name,description,supported,action,forced,standard}=signal;
- return {
- [number]:{
- name,
- number,
- description,
- supported,
- action,
- forced,
- standard}};
- };
- const findSignalByNumber=function(number,signals){
- const signal=signals.find(({name})=>_os.constants.signals[name]===number);
- if(signal!==undefined){
- return signal;
- }
- return signals.find(signalA=>signalA.number===number);
- };
- const signalsByNumber=getSignalsByNumber();main.signalsByNumber=signalsByNumber;
- const {signalsByName} = main;
- const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {
- if (timedOut) {
- return `timed out after ${timeout} milliseconds`;
- }
- if (isCanceled) {
- return 'was canceled';
- }
- if (errorCode !== undefined) {
- return `failed with ${errorCode}`;
- }
- if (signal !== undefined) {
- return `was killed with ${signal} (${signalDescription})`;
- }
- if (exitCode !== undefined) {
- return `failed with exit code ${exitCode}`;
- }
- return 'failed';
- };
- const makeError$1 = ({
- stdout,
- stderr,
- all,
- error,
- signal,
- exitCode,
- command,
- escapedCommand,
- timedOut,
- isCanceled,
- killed,
- parsed: {options: {timeout}}
- }) => {
- // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
- // We normalize them to `undefined`
- exitCode = exitCode === null ? undefined : exitCode;
- signal = signal === null ? undefined : signal;
- const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;
- const errorCode = error && error.code;
- const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
- const execaMessage = `Command ${prefix}: ${command}`;
- const isError = Object.prototype.toString.call(error) === '[object Error]';
- const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
- const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');
- if (isError) {
- error.originalMessage = error.message;
- error.message = message;
- } else {
- error = new Error(message);
- }
- error.shortMessage = shortMessage;
- error.command = command;
- error.escapedCommand = escapedCommand;
- error.exitCode = exitCode;
- error.signal = signal;
- error.signalDescription = signalDescription;
- error.stdout = stdout;
- error.stderr = stderr;
- if (all !== undefined) {
- error.all = all;
- }
- if ('bufferedData' in error) {
- delete error.bufferedData;
- }
- error.failed = true;
- error.timedOut = Boolean(timedOut);
- error.isCanceled = isCanceled;
- error.killed = killed && !timedOut;
- return error;
- };
- var error = makeError$1;
- var stdio = {exports: {}};
- const aliases = ['stdin', 'stdout', 'stderr'];
- const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
- const normalizeStdio$1 = options => {
- if (!options) {
- return;
- }
- const {stdio} = options;
- if (stdio === undefined) {
- return aliases.map(alias => options[alias]);
- }
- if (hasAlias(options)) {
- throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
- }
- if (typeof stdio === 'string') {
- return stdio;
- }
- if (!Array.isArray(stdio)) {
- throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
- }
- const length = Math.max(stdio.length, aliases.length);
- return Array.from({length}, (value, index) => stdio[index]);
- };
- stdio.exports = normalizeStdio$1;
- // `ipc` is pushed unless it is already present
- stdio.exports.node = options => {
- const stdio = normalizeStdio$1(options);
- if (stdio === 'ipc') {
- return 'ipc';
- }
- if (stdio === undefined || typeof stdio === 'string') {
- return [stdio, stdio, stdio, 'ipc'];
- }
- if (stdio.includes('ipc')) {
- return stdio;
- }
- return [...stdio, 'ipc'];
- };
- const os = require$$0;
- const onExit = signalExit.exports;
- const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
- // Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
- const spawnedKill$1 = (kill, signal = 'SIGTERM', options = {}) => {
- const killResult = kill(signal);
- setKillTimeout(kill, signal, options, killResult);
- return killResult;
- };
- const setKillTimeout = (kill, signal, options, killResult) => {
- if (!shouldForceKill(signal, options, killResult)) {
- return;
- }
- const timeout = getForceKillAfterTimeout(options);
- const t = setTimeout(() => {
- kill('SIGKILL');
- }, timeout);
- // Guarded because there's no `.unref()` when `execa` is used in the renderer
- // process in Electron. This cannot be tested since we don't run tests in
- // Electron.
- // istanbul ignore else
- if (t.unref) {
- t.unref();
- }
- };
- const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {
- return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
- };
- const isSigterm = signal => {
- return signal === os.constants.signals.SIGTERM ||
- (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
- };
- const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {
- if (forceKillAfterTimeout === true) {
- return DEFAULT_FORCE_KILL_TIMEOUT;
- }
- if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
- throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
- }
- return forceKillAfterTimeout;
- };
- // `childProcess.cancel()`
- const spawnedCancel$1 = (spawned, context) => {
- const killResult = spawned.kill();
- if (killResult) {
- context.isCanceled = true;
- }
- };
- const timeoutKill = (spawned, signal, reject) => {
- spawned.kill(signal);
- reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));
- };
- // `timeout` option handling
- const setupTimeout$1 = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => {
- if (timeout === 0 || timeout === undefined) {
- return spawnedPromise;
- }
- let timeoutId;
- const timeoutPromise = new Promise((resolve, reject) => {
- timeoutId = setTimeout(() => {
- timeoutKill(spawned, killSignal, reject);
- }, timeout);
- });
- const safeSpawnedPromise = spawnedPromise.finally(() => {
- clearTimeout(timeoutId);
- });
- return Promise.race([timeoutPromise, safeSpawnedPromise]);
- };
- const validateTimeout$1 = ({timeout}) => {
- if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
- throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
- }
- };
- // `cleanup` option handling
- const setExitHandler$1 = async (spawned, {cleanup, detached}, timedPromise) => {
- if (!cleanup || detached) {
- return timedPromise;
- }
- const removeExitHandler = onExit(() => {
- spawned.kill();
- });
- return timedPromise.finally(() => {
- removeExitHandler();
- });
- };
- var kill = {
- spawnedKill: spawnedKill$1,
- spawnedCancel: spawnedCancel$1,
- setupTimeout: setupTimeout$1,
- validateTimeout: validateTimeout$1,
- setExitHandler: setExitHandler$1
- };
- const isStream$1 = stream =>
- stream !== null &&
- typeof stream === 'object' &&
- typeof stream.pipe === 'function';
- isStream$1.writable = stream =>
- isStream$1(stream) &&
- stream.writable !== false &&
- typeof stream._write === 'function' &&
- typeof stream._writableState === 'object';
- isStream$1.readable = stream =>
- isStream$1(stream) &&
- stream.readable !== false &&
- typeof stream._read === 'function' &&
- typeof stream._readableState === 'object';
- isStream$1.duplex = stream =>
- isStream$1.writable(stream) &&
- isStream$1.readable(stream);
- isStream$1.transform = stream =>
- isStream$1.duplex(stream) &&
- typeof stream._transform === 'function';
- var isStream_1 = isStream$1;
- const isStream = isStream_1;
- const getStream = getStream$1.exports;
- const mergeStream = mergeStream$1;
- // `input` option
- const handleInput$1 = (spawned, input) => {
- // Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
- // @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
- if (input === undefined || spawned.stdin === undefined) {
- return;
- }
- if (isStream(input)) {
- input.pipe(spawned.stdin);
- } else {
- spawned.stdin.end(input);
- }
- };
- // `all` interleaves `stdout` and `stderr`
- const makeAllStream$1 = (spawned, {all}) => {
- if (!all || (!spawned.stdout && !spawned.stderr)) {
- return;
- }
- const mixed = mergeStream();
- if (spawned.stdout) {
- mixed.add(spawned.stdout);
- }
- if (spawned.stderr) {
- mixed.add(spawned.stderr);
- }
- return mixed;
- };
- // On failure, `result.stdout|stderr|all` should contain the currently buffered stream
- const getBufferedData = async (stream, streamPromise) => {
- if (!stream) {
- return;
- }
- stream.destroy();
- try {
- return await streamPromise;
- } catch (error) {
- return error.bufferedData;
- }
- };
- const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
- if (!stream || !buffer) {
- return;
- }
- if (encoding) {
- return getStream(stream, {encoding, maxBuffer});
- }
- return getStream.buffer(stream, {maxBuffer});
- };
- // Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)
- const getSpawnedResult$1 = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {
- const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});
- const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});
- const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});
- try {
- return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
- } catch (error) {
- return Promise.all([
- {error, signal: error.signal, timedOut: error.timedOut},
- getBufferedData(stdout, stdoutPromise),
- getBufferedData(stderr, stderrPromise),
- getBufferedData(all, allPromise)
- ]);
- }
- };
- const validateInputSync$1 = ({input}) => {
- if (isStream(input)) {
- throw new TypeError('The `input` option cannot be a stream in sync mode');
- }
- };
- var stream = {
- handleInput: handleInput$1,
- makeAllStream: makeAllStream$1,
- getSpawnedResult: getSpawnedResult$1,
- validateInputSync: validateInputSync$1
- };
- const nativePromisePrototype = (async () => {})().constructor.prototype;
- const descriptors = ['then', 'catch', 'finally'].map(property => [
- property,
- Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property)
- ]);
- // The return value is a mixin of `childProcess` and `Promise`
- const mergePromise$1 = (spawned, promise) => {
- for (const [property, descriptor] of descriptors) {
- // Starting the main `promise` is deferred to avoid consuming streams
- const value = typeof promise === 'function' ?
- (...args) => Reflect.apply(descriptor.value, promise(), args) :
- descriptor.value.bind(promise);
- Reflect.defineProperty(spawned, property, {...descriptor, value});
- }
- return spawned;
- };
- // Use promises instead of `child_process` events
- const getSpawnedPromise$1 = spawned => {
- return new Promise((resolve, reject) => {
- spawned.on('exit', (exitCode, signal) => {
- resolve({exitCode, signal});
- });
- spawned.on('error', error => {
- reject(error);
- });
- if (spawned.stdin) {
- spawned.stdin.on('error', error => {
- reject(error);
- });
- }
- });
- };
- var promise = {
- mergePromise: mergePromise$1,
- getSpawnedPromise: getSpawnedPromise$1
- };
- const normalizeArgs = (file, args = []) => {
- if (!Array.isArray(args)) {
- return [file];
- }
- return [file, ...args];
- };
- const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
- const DOUBLE_QUOTES_REGEXP = /"/g;
- const escapeArg = arg => {
- if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
- return arg;
- }
- return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`;
- };
- const joinCommand$1 = (file, args) => {
- return normalizeArgs(file, args).join(' ');
- };
- const getEscapedCommand$1 = (file, args) => {
- return normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' ');
- };
- const SPACES_REGEXP = / +/g;
- // Handle `execa.command()`
- const parseCommand$1 = command => {
- const tokens = [];
- for (const token of command.trim().split(SPACES_REGEXP)) {
- // Allow spaces to be escaped by a backslash if not meant as a delimiter
- const previousToken = tokens[tokens.length - 1];
- if (previousToken && previousToken.endsWith('\\')) {
- // Merge previous token with current one
- tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
- } else {
- tokens.push(token);
- }
- }
- return tokens;
- };
- var command = {
- joinCommand: joinCommand$1,
- getEscapedCommand: getEscapedCommand$1,
- parseCommand: parseCommand$1
- };
- const path = path$2;
- const childProcess = childProcess$1;
- const crossSpawn = crossSpawn$1.exports;
- const stripFinalNewline = stripFinalNewline$1;
- const npmRunPath = npmRunPath$1.exports;
- const onetime = onetime$1.exports;
- const makeError = error;
- const normalizeStdio = stdio.exports;
- const {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} = kill;
- const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = stream;
- const {mergePromise, getSpawnedPromise} = promise;
- const {joinCommand, parseCommand, getEscapedCommand} = command;
- const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
- const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => {
- const env = extendEnv ? {...process.env, ...envOption} : envOption;
- if (preferLocal) {
- return npmRunPath.env({env, cwd: localDir, execPath});
- }
- return env;
- };
- const handleArguments = (file, args, options = {}) => {
- const parsed = crossSpawn._parse(file, args, options);
- file = parsed.command;
- args = parsed.args;
- options = parsed.options;
- options = {
- maxBuffer: DEFAULT_MAX_BUFFER,
- buffer: true,
- stripFinalNewline: true,
- extendEnv: true,
- preferLocal: false,
- localDir: options.cwd || process.cwd(),
- execPath: process.execPath,
- encoding: 'utf8',
- reject: true,
- cleanup: true,
- all: false,
- windowsHide: true,
- ...options
- };
- options.env = getEnv(options);
- options.stdio = normalizeStdio(options);
- if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {
- // #116
- args.unshift('/q');
- }
- return {file, args, options, parsed};
- };
- const handleOutput = (options, value, error) => {
- if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
- // When `execa.sync()` errors, we normalize it to '' to mimic `execa()`
- return error === undefined ? undefined : '';
- }
- if (options.stripFinalNewline) {
- return stripFinalNewline(value);
- }
- return value;
- };
- const execa = (file, args, options) => {
- const parsed = handleArguments(file, args, options);
- const command = joinCommand(file, args);
- const escapedCommand = getEscapedCommand(file, args);
- validateTimeout(parsed.options);
- let spawned;
- try {
- spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
- } catch (error) {
- // Ensure the returned error is always both a promise and a child process
- const dummySpawned = new childProcess.ChildProcess();
- const errorPromise = Promise.reject(makeError({
- error,
- stdout: '',
- stderr: '',
- all: '',
- command,
- escapedCommand,
- parsed,
- timedOut: false,
- isCanceled: false,
- killed: false
- }));
- return mergePromise(dummySpawned, errorPromise);
- }
- const spawnedPromise = getSpawnedPromise(spawned);
- const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
- const processDone = setExitHandler(spawned, parsed.options, timedPromise);
- const context = {isCanceled: false};
- spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
- spawned.cancel = spawnedCancel.bind(null, spawned, context);
- const handlePromise = async () => {
- const [{error, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
- const stdout = handleOutput(parsed.options, stdoutResult);
- const stderr = handleOutput(parsed.options, stderrResult);
- const all = handleOutput(parsed.options, allResult);
- if (error || exitCode !== 0 || signal !== null) {
- const returnedError = makeError({
- error,
- exitCode,
- signal,
- stdout,
- stderr,
- all,
- command,
- escapedCommand,
- parsed,
- timedOut,
- isCanceled: context.isCanceled,
- killed: spawned.killed
- });
- if (!parsed.options.reject) {
- return returnedError;
- }
- throw returnedError;
- }
- return {
- command,
- escapedCommand,
- exitCode: 0,
- stdout,
- stderr,
- all,
- failed: false,
- timedOut: false,
- isCanceled: false,
- killed: false
- };
- };
- const handlePromiseOnce = onetime(handlePromise);
- handleInput(spawned, parsed.options.input);
- spawned.all = makeAllStream(spawned, parsed.options);
- return mergePromise(spawned, handlePromiseOnce);
- };
- execa$1.exports = execa;
- execa$1.exports.sync = (file, args, options) => {
- const parsed = handleArguments(file, args, options);
- const command = joinCommand(file, args);
- const escapedCommand = getEscapedCommand(file, args);
- validateInputSync(parsed.options);
- let result;
- try {
- result = childProcess.spawnSync(parsed.file, parsed.args, parsed.options);
- } catch (error) {
- throw makeError({
- error,
- stdout: '',
- stderr: '',
- all: '',
- command,
- escapedCommand,
- parsed,
- timedOut: false,
- isCanceled: false,
- killed: false
- });
- }
- const stdout = handleOutput(parsed.options, result.stdout, result.error);
- const stderr = handleOutput(parsed.options, result.stderr, result.error);
- if (result.error || result.status !== 0 || result.signal !== null) {
- const error = makeError({
- stdout,
- stderr,
- error: result.error,
- signal: result.signal,
- exitCode: result.status,
- command,
- escapedCommand,
- parsed,
- timedOut: result.error && result.error.code === 'ETIMEDOUT',
- isCanceled: false,
- killed: result.signal !== null
- });
- if (!parsed.options.reject) {
- return error;
- }
- throw error;
- }
- return {
- command,
- escapedCommand,
- exitCode: 0,
- stdout,
- stderr,
- failed: false,
- timedOut: false,
- isCanceled: false,
- killed: false
- };
- };
- execa$1.exports.command = (command, options) => {
- const [file, ...args] = parseCommand(command);
- return execa(file, args, options);
- };
- execa$1.exports.commandSync = (command, options) => {
- const [file, ...args] = parseCommand(command);
- return execa.sync(file, args, options);
- };
- execa$1.exports.node = (scriptPath, args, options = {}) => {
- if (args && !Array.isArray(args) && typeof args === 'object') {
- options = args;
- args = [];
- }
- const stdio = normalizeStdio.node(options);
- const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect'));
- const {
- nodePath = process.execPath,
- nodeOptions = defaultExecArgv
- } = options;
- return execa(
- nodePath,
- [
- ...nodeOptions,
- scriptPath,
- ...(Array.isArray(args) ? args : [])
- ],
- {
- ...options,
- stdin: undefined,
- stdout: undefined,
- stderr: undefined,
- stdio,
- shell: false
- }
- );
- };
- // src/detect.ts
- var LOCKS = {
- "pnpm-lock.yaml": "pnpm",
- "yarn.lock": "yarn",
- "package-lock.json": "npm"
- };
- async function detectPackageManager(cwd = process.cwd()) {
- const result = await findUp(Object.keys(LOCKS), { cwd });
- const agent = result ? LOCKS[path$2.basename(result)] : null;
- return agent;
- }
- async function installPackage(names, options = {}) {
- const agent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
- if (!Array.isArray(names))
- names = [names];
- const args = options.additionalArgs || [];
- if (options.preferOffline)
- args.unshift("--prefer-offline");
- return execa$1.exports(agent, [
- agent === "yarn" ? "add" : "install",
- options.dev ? "-D" : "",
- ...args,
- ...names
- ].filter(Boolean), {
- stdio: options.silent ? "ignore" : "inherit",
- cwd: options.cwd
- });
- }
- export { detectPackageManager, installPackage };
|