UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

1,572 lines (1,542 loc) 82.4 kB
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // ../../node_modules/isexe/windows.js var require_windows = __commonJS({ "../../node_modules/isexe/windows.js"(exports, module2) { "use strict"; module2.exports = isexe; isexe.sync = sync; var fs = require("fs"); function checkPathExt(path3, options) { var pathext = options.pathExt !== void 0 ? 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 && path3.substr(-p.length).toLowerCase() === p) { return true; } } return false; } function checkStat(stat, path3, options) { if (!stat.isSymbolicLink() && !stat.isFile()) { return false; } return checkPathExt(path3, options); } function isexe(path3, options, cb) { fs.stat(path3, function(er, stat) { cb(er, er ? false : checkStat(stat, path3, options)); }); } function sync(path3, options) { return checkStat(fs.statSync(path3), path3, options); } } }); // ../../node_modules/isexe/mode.js var require_mode = __commonJS({ "../../node_modules/isexe/mode.js"(exports, module2) { "use strict"; module2.exports = isexe; isexe.sync = sync; var fs = require("fs"); function isexe(path3, options, cb) { fs.stat(path3, function(er, stat) { cb(er, er ? false : checkStat(stat, options)); }); } function sync(path3, options) { return checkStat(fs.statSync(path3), 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 !== void 0 ? options.uid : process.getuid && process.getuid(); var myGid = options.gid !== void 0 ? 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; } } }); // ../../node_modules/isexe/index.js var require_isexe = __commonJS({ "../../node_modules/isexe/index.js"(exports, module2) { "use strict"; var fs = require("fs"); var core; if (process.platform === "win32" || global.TESTING_WINDOWS) { core = require_windows(); } else { core = require_mode(); } module2.exports = isexe; isexe.sync = sync; function isexe(path3, 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(path3, options || {}, function(er, is) { if (er) { reject(er); } else { resolve(is); } }); }); } core(path3, options || {}, function(er, is) { if (er) { if (er.code === "EACCES" || options && options.ignoreErrors) { er = null; is = false; } } cb(er, is); }); } function sync(path3, options) { try { return core.sync(path3, options || {}); } catch (er) { if (options && options.ignoreErrors || er.code === "EACCES") { return false; } else { throw er; } } } } }); // ../../node_modules/which/which.js var require_which = __commonJS({ "../../node_modules/which/which.js"(exports, module2) { "use strict"; var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys"; var path3 = require("path"); var COLON = isWindows ? ";" : ":"; var isexe = require_isexe(); var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" }); var getPathInfo = (cmd, opt) => { const colon = opt.colon || COLON; 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 }; }; var which = (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 = path3.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); }; var 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 = path3.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); }; module2.exports = which; which.sync = whichSync; } }); // ../../node_modules/path-key/index.js var require_path_key = __commonJS({ "../../node_modules/path-key/index.js"(exports, module2) { "use strict"; var pathKey2 = (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"; }; module2.exports = pathKey2; module2.exports.default = pathKey2; } }); // ../../node_modules/cross-spawn/lib/util/resolveCommand.js var require_resolveCommand = __commonJS({ "../../node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module2) { "use strict"; var path3 = require("path"); var which = require_which(); var getPathKey = require_path_key(); function resolveCommandAttempt(parsed, withoutPathExt) { const env = parsed.options.env || process.env; const cwd = process.cwd(); const hasCustomCwd = parsed.options.cwd != null; const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled; if (shouldSwitchCwd) { try { process.chdir(parsed.options.cwd); } catch (err) { } } let resolved; try { resolved = which.sync(parsed.command, { path: env[getPathKey({ env })], pathExt: withoutPathExt ? path3.delimiter : void 0 }); } catch (e) { } finally { if (shouldSwitchCwd) { process.chdir(cwd); } } if (resolved) { resolved = path3.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved); } return resolved; } function resolveCommand(parsed) { return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true); } module2.exports = resolveCommand; } }); // ../../node_modules/cross-spawn/lib/util/escape.js var require_escape = __commonJS({ "../../node_modules/cross-spawn/lib/util/escape.js"(exports, module2) { "use strict"; var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g; function escapeCommand(arg) { arg = arg.replace(metaCharsRegExp, "^$1"); return arg; } function escapeArgument(arg, doubleEscapeMetaChars) { arg = `${arg}`; arg = arg.replace(/(\\*)"/g, '$1$1\\"'); arg = arg.replace(/(\\*)$/, "$1$1"); arg = `"${arg}"`; arg = arg.replace(metaCharsRegExp, "^$1"); if (doubleEscapeMetaChars) { arg = arg.replace(metaCharsRegExp, "^$1"); } return arg; } module2.exports.command = escapeCommand; module2.exports.argument = escapeArgument; } }); // ../../node_modules/cross-spawn/node_modules/shebang-regex/index.js var require_shebang_regex = __commonJS({ "../../node_modules/cross-spawn/node_modules/shebang-regex/index.js"(exports, module2) { "use strict"; module2.exports = /^#!(.*)/; } }); // ../../node_modules/cross-spawn/node_modules/shebang-command/index.js var require_shebang_command = __commonJS({ "../../node_modules/cross-spawn/node_modules/shebang-command/index.js"(exports, module2) { "use strict"; var shebangRegex = require_shebang_regex(); module2.exports = (string = "") => { const match = string.match(shebangRegex); if (!match) { return null; } const [path3, argument] = match[0].replace(/#! ?/, "").split(" "); const binary = path3.split("/").pop(); if (binary === "env") { return argument; } return argument ? `${binary} ${argument}` : binary; }; } }); // ../../node_modules/cross-spawn/lib/util/readShebang.js var require_readShebang = __commonJS({ "../../node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) { "use strict"; var fs = require("fs"); var shebangCommand = require_shebang_command(); function readShebang(command) { 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) { } return shebangCommand(buffer.toString()); } module2.exports = readShebang; } }); // ../../node_modules/cross-spawn/lib/parse.js var require_parse = __commonJS({ "../../node_modules/cross-spawn/lib/parse.js"(exports, module2) { "use strict"; var path3 = require("path"); var resolveCommand = require_resolveCommand(); var escape = require_escape(); var readShebang = require_readShebang(); var isWin = process.platform === "win32"; var isExecutableRegExp = /\.(?:com|exe)$/i; var 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) { return parsed; } const commandFile = detectShebang(parsed); const needsShell = !isExecutableRegExp.test(commandFile); if (parsed.options.forceShell || needsShell) { const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile); parsed.command = path3.normalize(parsed.command); 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; } return parsed; } function parse(command, args, options) { if (args && !Array.isArray(args)) { options = args; args = null; } args = args ? args.slice(0) : []; options = Object.assign({}, options); const parsed = { command, args, options, file: void 0, original: { command, args } }; return options.shell ? parsed : parseNonShell(parsed); } module2.exports = parse; } }); // ../../node_modules/cross-spawn/lib/enoent.js var require_enoent = __commonJS({ "../../node_modules/cross-spawn/lib/enoent.js"(exports, module2) { "use strict"; var 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 (name === "exit") { const err = verifyENOENT(arg1, parsed, "spawn"); if (err) { return originalEmit.call(cp, "error", err); } } return originalEmit.apply(cp, arguments); }; } 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; } module2.exports = { hookChildProcess, verifyENOENT, verifyENOENTSync, notFoundError }; } }); // ../../node_modules/cross-spawn/index.js var require_cross_spawn = __commonJS({ "../../node_modules/cross-spawn/index.js"(exports, module2) { "use strict"; var cp = require("child_process"); var parse = require_parse(); var enoent = require_enoent(); function spawn(command, args, options) { const parsed = parse(command, args, options); const spawned = cp.spawn(parsed.command, parsed.args, parsed.options); enoent.hookChildProcess(spawned, parsed); return spawned; } function spawnSync(command, args, options) { const parsed = parse(command, args, options); const result = cp.spawnSync(parsed.command, parsed.args, parsed.options); result.error = result.error || enoent.verifyENOENTSync(result.status, parsed); return result; } module2.exports = spawn; module2.exports.spawn = spawn; module2.exports.sync = spawnSync; module2.exports._parse = parse; module2.exports._enoent = enoent; } }); // ../../node_modules/execa/node_modules/strip-final-newline/index.js function stripFinalNewline(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, -1); } if (input[input.length - 1] === CR) { input = input.slice(0, -1); } return input; } var init_strip_final_newline = __esm({ "../../node_modules/execa/node_modules/strip-final-newline/index.js"() { "use strict"; } }); // ../../node_modules/execa/node_modules/path-key/index.js function pathKey(options = {}) { const { env = process.env, platform = process.platform } = options; if (platform !== "win32") { return "PATH"; } return Object.keys(env).reverse().find((key) => key.toUpperCase() === "PATH") || "Path"; } var init_path_key = __esm({ "../../node_modules/execa/node_modules/path-key/index.js"() { "use strict"; } }); // ../../node_modules/execa/node_modules/npm-run-path/index.js function npmRunPath(options = {}) { const { cwd = import_node_process.default.cwd(), path: path_ = import_node_process.default.env[pathKey()], execPath = import_node_process.default.execPath } = options; let previous; const cwdString = cwd instanceof URL ? import_node_url.default.fileURLToPath(cwd) : cwd; let cwdPath = import_node_path.default.resolve(cwdString); const result = []; while (previous !== cwdPath) { result.push(import_node_path.default.join(cwdPath, "node_modules/.bin")); previous = cwdPath; cwdPath = import_node_path.default.resolve(cwdPath, ".."); } result.push(import_node_path.default.resolve(cwdString, execPath, "..")); return [...result, path_].join(import_node_path.default.delimiter); } function npmRunPathEnv({ env = import_node_process.default.env, ...options } = {}) { env = { ...env }; const path3 = pathKey({ env }); options.path = env[path3]; env[path3] = npmRunPath(options); return env; } var import_node_process, import_node_path, import_node_url; var init_npm_run_path = __esm({ "../../node_modules/execa/node_modules/npm-run-path/index.js"() { "use strict"; import_node_process = __toESM(require("process"), 1); import_node_path = __toESM(require("path"), 1); import_node_url = __toESM(require("url"), 1); init_path_key(); } }); // ../../node_modules/execa/node_modules/mimic-fn/index.js function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) { const { name } = to; for (const property of Reflect.ownKeys(from)) { copyProperty(to, from, property, ignoreNonConfigurable); } changePrototype(to, from); changeToString(to, from, name); return to; } var copyProperty, canCopyProperty, changePrototype, wrappedToString, toStringDescriptor, toStringName, changeToString; var init_mimic_fn = __esm({ "../../node_modules/execa/node_modules/mimic-fn/index.js"() { "use strict"; copyProperty = (to, from, property, ignoreNonConfigurable) => { if (property === "length" || property === "prototype") { return; } if (property === "arguments" || property === "caller") { return; } const toDescriptor = Object.getOwnPropertyDescriptor(to, property); const fromDescriptor = Object.getOwnPropertyDescriptor(from, property); if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) { return; } Object.defineProperty(to, property, fromDescriptor); }; canCopyProperty = function(toDescriptor, fromDescriptor) { return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value); }; changePrototype = (to, from) => { const fromPrototype = Object.getPrototypeOf(from); if (fromPrototype === Object.getPrototypeOf(to)) { return; } Object.setPrototypeOf(to, fromPrototype); }; wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/ ${fromBody}`; toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString"); toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name"); changeToString = (to, from, name) => { const withName = name === "" ? "" : `with ${name.trim()}() `; const newToString = wrappedToString.bind(null, withName, from.toString()); Object.defineProperty(newToString, "name", toStringName); Object.defineProperty(to, "toString", { ...toStringDescriptor, value: newToString }); }; } }); // ../../node_modules/execa/node_modules/onetime/index.js var calledFunctions, onetime, onetime_default; var init_onetime = __esm({ "../../node_modules/execa/node_modules/onetime/index.js"() { "use strict"; init_mimic_fn(); calledFunctions = /* @__PURE__ */ new WeakMap(); onetime = (function_, options = {}) => { if (typeof function_ !== "function") { throw new TypeError("Expected a function"); } let returnValue; let callCount = 0; const functionName = function_.displayName || function_.name || "<anonymous>"; const onetime2 = function(...arguments_) { calledFunctions.set(onetime2, ++callCount); if (callCount === 1) { returnValue = function_.apply(this, arguments_); function_ = null; } else if (options.throw === true) { throw new Error(`Function \`${functionName}\` can only be called once`); } return returnValue; }; mimicFunction(onetime2, function_); calledFunctions.set(onetime2, callCount); return onetime2; }; onetime.callCount = (function_) => { if (!calledFunctions.has(function_)) { throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`); } return calledFunctions.get(function_); }; onetime_default = onetime; } }); // ../../node_modules/execa/node_modules/human-signals/build/src/realtime.js var getRealtimeSignals, getRealtimeSignal, SIGRTMIN, SIGRTMAX; var init_realtime = __esm({ "../../node_modules/execa/node_modules/human-signals/build/src/realtime.js"() { "use strict"; getRealtimeSignals = () => { const length = SIGRTMAX - SIGRTMIN + 1; return Array.from({ length }, getRealtimeSignal); }; getRealtimeSignal = (value, index) => ({ name: `SIGRT${index + 1}`, number: SIGRTMIN + index, action: "terminate", description: "Application-specific signal (realtime)", standard: "posix" }); SIGRTMIN = 34; SIGRTMAX = 64; } }); // ../../node_modules/execa/node_modules/human-signals/build/src/core.js var SIGNALS; var init_core = __esm({ "../../node_modules/execa/node_modules/human-signals/build/src/core.js"() { "use strict"; 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" } ]; } }); // ../../node_modules/execa/node_modules/human-signals/build/src/signals.js var import_node_os, getSignals, normalizeSignal; var init_signals = __esm({ "../../node_modules/execa/node_modules/human-signals/build/src/signals.js"() { "use strict"; import_node_os = require("os"); init_core(); init_realtime(); getSignals = () => { const realtimeSignals = getRealtimeSignals(); const signals2 = [...SIGNALS, ...realtimeSignals].map(normalizeSignal); return signals2; }; normalizeSignal = ({ name, number: defaultNumber, description, action, forced = false, standard }) => { const { signals: { [name]: constantSignal } } = import_node_os.constants; const supported = constantSignal !== void 0; const number = supported ? constantSignal : defaultNumber; return { name, number, description, supported, action, forced, standard }; }; } }); // ../../node_modules/execa/node_modules/human-signals/build/src/main.js var import_node_os2, getSignalsByName, getSignalByName, signalsByName, getSignalsByNumber, getSignalByNumber, findSignalByNumber, signalsByNumber; var init_main = __esm({ "../../node_modules/execa/node_modules/human-signals/build/src/main.js"() { "use strict"; import_node_os2 = require("os"); init_realtime(); init_signals(); getSignalsByName = () => { const signals2 = getSignals(); return Object.fromEntries(signals2.map(getSignalByName)); }; getSignalByName = ({ name, number, description, supported, action, forced, standard }) => [name, { name, number, description, supported, action, forced, standard }]; signalsByName = getSignalsByName(); getSignalsByNumber = () => { const signals2 = getSignals(); const length = SIGRTMAX + 1; const signalsA = Array.from( { length }, (value, number) => getSignalByNumber(number, signals2) ); return Object.assign({}, ...signalsA); }; getSignalByNumber = (number, signals2) => { const signal = findSignalByNumber(number, signals2); if (signal === void 0) { return {}; } const { name, description, supported, action, forced, standard } = signal; return { [number]: { name, number, description, supported, action, forced, standard } }; }; findSignalByNumber = (number, signals2) => { const signal = signals2.find(({ name }) => import_node_os2.constants.signals[name] === number); if (signal !== void 0) { return signal; } return signals2.find((signalA) => signalA.number === number); }; signalsByNumber = getSignalsByNumber(); } }); // ../../node_modules/execa/lib/error.js var import_node_process2, getErrorPrefix, makeError; var init_error = __esm({ "../../node_modules/execa/lib/error.js"() { "use strict"; import_node_process2 = __toESM(require("process"), 1); init_main(); getErrorPrefix = ({ timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled }) => { if (timedOut) { return `timed out after ${timeout} milliseconds`; } if (isCanceled) { return "was canceled"; } if (errorCode !== void 0) { return `failed with ${errorCode}`; } if (signal !== void 0) { return `was killed with ${signal} (${signalDescription})`; } if (exitCode !== void 0) { return `failed with exit code ${exitCode}`; } return "failed"; }; makeError = ({ stdout, stderr, all, error, signal, exitCode, command, escapedCommand, timedOut, isCanceled, killed, parsed: { options: { timeout, cwd = import_node_process2.default.cwd() } } }) => { exitCode = exitCode === null ? void 0 : exitCode; signal = signal === null ? void 0 : signal; const signalDescription = signal === void 0 ? void 0 : 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} ${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; error.cwd = cwd; if (all !== void 0) { 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; }; } }); // ../../node_modules/execa/lib/stdio.js var aliases, hasAlias, normalizeStdio, normalizeStdioNode; var init_stdio = __esm({ "../../node_modules/execa/lib/stdio.js"() { "use strict"; aliases = ["stdin", "stdout", "stderr"]; hasAlias = (options) => aliases.some((alias) => options[alias] !== void 0); normalizeStdio = (options) => { if (!options) { return; } const { stdio } = options; if (stdio === void 0) { 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]); }; normalizeStdioNode = (options) => { const stdio = normalizeStdio(options); if (stdio === "ipc") { return "ipc"; } if (stdio === void 0 || typeof stdio === "string") { return [stdio, stdio, stdio, "ipc"]; } if (stdio.includes("ipc")) { return stdio; } return [...stdio, "ipc"]; }; } }); // ../../node_modules/execa/node_modules/signal-exit/dist/mjs/signals.js var signals; var init_signals2 = __esm({ "../../node_modules/execa/node_modules/signal-exit/dist/mjs/signals.js"() { "use strict"; signals = []; signals.push("SIGHUP", "SIGINT", "SIGTERM"); if (process.platform !== "win32") { signals.push( "SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT" // should detect profiler and enable/disable accordingly. // see #21 // 'SIGPROF' ); } if (process.platform === "linux") { signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT"); } } }); // ../../node_modules/execa/node_modules/signal-exit/dist/mjs/index.js var processOk, kExitEmitter, global2, ObjectDefineProperty, Emitter, SignalExitBase, signalExitWrap, SignalExitFallback, SignalExit, process4, onExit, load, unload; var init_mjs = __esm({ "../../node_modules/execa/node_modules/signal-exit/dist/mjs/index.js"() { "use strict"; init_signals2(); processOk = (process7) => !!process7 && typeof process7 === "object" && typeof process7.removeListener === "function" && typeof process7.emit === "function" && typeof process7.reallyExit === "function" && typeof process7.listeners === "function" && typeof process7.kill === "function" && typeof process7.pid === "number" && typeof process7.on === "function"; kExitEmitter = Symbol.for("signal-exit emitter"); global2 = globalThis; ObjectDefineProperty = Object.defineProperty.bind(Object); Emitter = class { emitted = { afterExit: false, exit: false }; listeners = { afterExit: [], exit: [] }; count = 0; id = Math.random(); constructor() { if (global2[kExitEmitter]) { return global2[kExitEmitter]; } ObjectDefineProperty(global2, kExitEmitter, { value: this, writable: false, enumerable: false, configurable: false }); } on(ev, fn) { this.listeners[ev].push(fn); } removeListener(ev, fn) { const list = this.listeners[ev]; const i = list.indexOf(fn); if (i === -1) { return; } if (i === 0 && list.length === 1) { list.length = 0; } else { list.splice(i, 1); } } emit(ev, code, signal) { if (this.emitted[ev]) { return false; } this.emitted[ev] = true; let ret = false; for (const fn of this.listeners[ev]) { ret = fn(code, signal) === true || ret; } if (ev === "exit") { ret = this.emit("afterExit", code, signal) || ret; } return ret; } }; SignalExitBase = class { }; signalExitWrap = (handler) => { return { onExit(cb, opts) { return handler.onExit(cb, opts); }, load() { return handler.load(); }, unload() { return handler.unload(); } }; }; SignalExitFallback = class extends SignalExitBase { onExit() { return () => { }; } load() { } unload() { } }; SignalExit = class extends SignalExitBase { // "SIGHUP" throws an `ENOSYS` error on Windows, // so use a supported signal instead /* c8 ignore start */ #hupSig = process4.platform === "win32" ? "SIGINT" : "SIGHUP"; /* c8 ignore stop */ #emitter = new Emitter(); #process; #originalProcessEmit; #originalProcessReallyExit; #sigListeners = {}; #loaded = false; constructor(process7) { super(); this.#process = process7; this.#sigListeners = {}; for (const sig of signals) { this.#sigListeners[sig] = () => { const listeners = this.#process.listeners(sig); let { count } = this.#emitter; const p = process7; if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") { count += p.__signal_exit_emitter__.count; } if (listeners.length === count) { this.unload(); const ret = this.#emitter.emit("exit", null, sig); const s = sig === "SIGHUP" ? this.#hupSig : sig; if (!ret) process7.kill(process7.pid, s); } }; } this.#originalProcessReallyExit = process7.reallyExit; this.#originalProcessEmit = process7.emit; } onExit(cb, opts) { if (!processOk(this.#process)) { return () => { }; } if (this.#loaded === false) { this.load(); } const ev = opts?.alwaysLast ? "afterExit" : "exit"; this.#emitter.on(ev, cb); return () => { this.#emitter.removeListener(ev, cb); if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) { this.unload(); } }; } load() { if (this.#loaded) { return; } this.#loaded = true; this.#emitter.count += 1; for (const sig of signals) { try { const fn = this.#sigListeners[sig]; if (fn) this.#process.on(sig, fn); } catch (_) { } } this.#process.emit = (ev, ...a) => { return this.#processEmit(ev, ...a); }; this.#process.reallyExit = (code) => { return this.#processReallyExit(code); }; } unload() { if (!this.#loaded) { return; } this.#loaded = false; signals.forEach((sig) => { const listener = this.#sigListeners[sig]; if (!listener) { throw new Error("Listener not defined for signal: " + sig); } try { this.#process.removeListener(sig, listener); } catch (_) { } }); this.#process.emit = this.#originalProcessEmit; this.#process.reallyExit = this.#originalProcessReallyExit; this.#emitter.count -= 1; } #processReallyExit(code) { if (!processOk(this.#process)) { return 0; } this.#process.exitCode = code || 0; this.#emitter.emit("exit", this.#process.exitCode, null); return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode); } #processEmit(ev, ...args) { const og = this.#originalProcessEmit; if (ev === "exit" && processOk(this.#process)) { if (typeof args[0] === "number") { this.#process.exitCode = args[0]; } const ret = og.call(this.#process, ev, ...args); this.#emitter.emit("exit", this.#process.exitCode, null); return ret; } else { return og.call(this.#process, ev, ...args); } } }; process4 = globalThis.process; ({ onExit: ( /** * Called when the process is exiting, whether via signal, explicit * exit, or running out of stuff to do. * * If the global process object is not suitable for instrumentation, * then this will be a no-op. * * Returns a function that may be used to unload signal-exit. */ onExit ), load: ( /** * Load the listeners. Likely you never need to call this, unless * doing a rather deep integration with signal-exit functionality. * Mostly exposed for the benefit of testing. * * @internal */ load ), unload: ( /** * Unload the listeners. Likely you never need to call this, unless * doing a rather deep integration with signal-exit functionality. * Mostly exposed for the benefit of testing. * * @internal */ unload ) } = signalExitWrap(processOk(process4) ? new SignalExit(process4) : new SignalExitFallback())); } }); // ../../node_modules/execa/lib/kill.js var import_node_os3, DEFAULT_FORCE_KILL_TIMEOUT, spawnedKill, setKillTimeout, shouldForceKill, isSigterm, getForceKillAfterTimeout, spawnedCancel, timeoutKill, setupTimeout, validateTimeout, setExitHandler; var init_kill = __esm({ "../../node_modules/execa/lib/kill.js"() { "use strict"; import_node_os3 = __toESM(require("os"), 1); init_mjs(); DEFAULT_FORCE_KILL_TIMEOUT = 1e3 * 5; spawnedKill = (kill, signal = "SIGTERM", options = {}) => { const killResult = kill(signal); setKillTimeout(kill, signal, options, killResult); return killResult; }; setKillTimeout = (kill, signal, options, killResult) => { if (!shouldForceKill(signal, options, killResult)) { return; } const timeout = getForceKillAfterTimeout(options); const t = setTimeout(() => { kill("SIGKILL"); }, timeout); if (t.unref) { t.unref(); } }; shouldForceKill = (signal, { forceKillAfterTimeout }, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult; isSigterm = (signal) => signal === import_node_os3.default.constants.signals.SIGTERM || typeof signal === "string" && signal.toUpperCase() === "SIGTERM"; 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; }; spawnedCancel = (spawned, context) => { const killResult = spawned.kill(); if (killResult) { context.isCanceled = true; } }; timeoutKill = (spawned, signal, reject) => { spawned.kill(signal); reject(Object.assign(new Error("Timed out"), { timedOut: true, signal })); }; setupTimeout = (spawned, { timeout, killSignal = "SIGTERM" }, spawnedPromise) => { if (timeout === 0 || timeout === void 0) { 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]); }; validateTimeout = ({ timeout }) => { if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout < 0)) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } }; setExitHandler = async (spawned, { cleanup, detached }, timedPromise) => { if (!cleanup || detached) { return timedPromise; } const removeExitHandler = onExit(() => { spawned.kill(); }); return timedPromise.finally(() => { removeExitHandler(); }); }; } }); // ../../node_modules/execa/node_modules/is-stream/index.js function isStream(stream) { return stream !== null && typeof stream === "object" && typeof stream.pipe === "function"; } function isWr