vlt
Version:
The vlt CLI
1,153 lines (1,130 loc) • 34.6 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout,clearTimeout,setImmediate,clearImmediate,setInterval,clearInterval} from "node:timers";
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
import {
PackageJson
} from "./chunk-YWPMIBJS.js";
import {
walkUp
} from "./chunk-SGEQHKFC.js";
import {
promiseSpawn
} from "./chunk-TJHWNOOA.js";
import {
error
} from "./chunk-RV3EHS4P.js";
import {
__commonJS,
__require,
__toESM
} from "./chunk-AECDW3EJ.js";
// ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
var require_windows = __commonJS({
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module) {
module.exports = isexe;
isexe.sync = sync;
var fs = __require("node:fs");
function checkPathExt(path, 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 && 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);
}
}
});
// ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js
var require_mode = __commonJS({
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module) {
module.exports = isexe;
isexe.sync = sync;
var fs = __require("node:fs");
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 !== 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/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
var require_isexe = __commonJS({
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module) {
var fs = __require("node:fs");
var core;
if (process.platform === "win32" || global.TESTING_WINDOWS) {
core = require_windows();
} else {
core = require_mode();
}
module.exports = isexe;
isexe.sync = sync;
function isexe(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(resolve2, reject) {
isexe(path, options || {}, function(er, is) {
if (er) {
reject(er);
} else {
resolve2(is);
}
});
});
}
core(path, options || {}, function(er, is) {
if (er) {
if (er.code === "EACCES" || options && options.ignoreErrors) {
er = null;
is = false;
}
}
cb(er, is);
});
}
function sync(path, options) {
try {
return core.sync(path, options || {});
} catch (er) {
if (options && options.ignoreErrors || er.code === "EACCES") {
return false;
} else {
throw er;
}
}
}
}
});
// ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
var require_which = __commonJS({
"../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module) {
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
var path = __require("node: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((resolve2, reject) => {
if (i === pathEnv.length)
return opt.all && found.length ? resolve2(found) : reject(getNotFoundError(cmd));
const ppRaw = pathEnv[i];
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
const pCmd = path.join(pathPart, cmd);
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
resolve2(subStep(p, i, 0));
});
const subStep = (p, i, ii) => new Promise((resolve2, reject) => {
if (ii === pathExt.length)
return resolve2(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 resolve2(p + ext);
}
return resolve2(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 = path.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);
};
module.exports = which;
which.sync = whichSync;
}
});
// ../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js
var require_path_key = __commonJS({
"../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js"(exports, module) {
"use strict";
var 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";
};
module.exports = pathKey;
module.exports.default = pathKey;
}
});
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
var require_resolveCommand = __commonJS({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
"use strict";
var path = __require("node: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 ? path.delimiter : void 0
});
} catch (e) {
} finally {
if (shouldSwitchCwd) {
process.chdir(cwd);
}
}
if (resolved) {
resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
}
return resolved;
}
function resolveCommand(parsed) {
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
}
module.exports = resolveCommand;
}
});
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
var require_escape = __commonJS({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module) {
"use strict";
var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
function escapeCommand(arg) {
arg = arg.replace(metaCharsRegExp, "^$1");
return arg;
}
function escapeArgument(arg, doubleEscapeMetaChars) {
arg = `${arg}`;
arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
arg = `"${arg}"`;
arg = arg.replace(metaCharsRegExp, "^$1");
if (doubleEscapeMetaChars) {
arg = arg.replace(metaCharsRegExp, "^$1");
}
return arg;
}
module.exports.command = escapeCommand;
module.exports.argument = escapeArgument;
}
});
// ../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js
var require_shebang_regex = __commonJS({
"../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js"(exports, module) {
"use strict";
module.exports = /^#!(.*)/;
}
});
// ../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js
var require_shebang_command = __commonJS({
"../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js"(exports, module) {
"use strict";
var shebangRegex = require_shebang_regex();
module.exports = (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;
};
}
});
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
var require_readShebang = __commonJS({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
"use strict";
var fs = __require("node: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());
}
module.exports = readShebang;
}
});
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
var require_parse = __commonJS({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module) {
"use strict";
var path = __require("node: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 = path.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);
}
module.exports = parse;
}
});
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
var require_enoent = __commonJS({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module) {
"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);
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;
}
module.exports = {
hookChildProcess,
verifyENOENT,
verifyENOENTSync,
notFoundError
};
}
});
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js
var require_cross_spawn = __commonJS({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports, module) {
"use strict";
var cp = __require("node:child_process");
var parse = require_parse();
var enoent = require_enoent();
function spawn3(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;
}
module.exports = spawn3;
module.exports.spawn = spawn3;
module.exports.sync = spawnSync;
module.exports._parse = parse;
module.exports._enoent = enoent;
}
});
// ../../node_modules/.pnpm/foreground-child@3.3.1/node_modules/foreground-child/dist/esm/index.js
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
import { spawn as nodeSpawn } from "node:child_process";
// ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
var 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/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
var processOk = (process3) => !!process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
var kExitEmitter = Symbol.for("signal-exit emitter");
var global2 = globalThis;
var ObjectDefineProperty = Object.defineProperty.bind(Object);
var 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;
}
};
var SignalExitBase = class {
};
var signalExitWrap = (handler) => {
return {
onExit(cb, opts) {
return handler.onExit(cb, opts);
},
load() {
return handler.load();
},
unload() {
return handler.unload();
}
};
};
var SignalExitFallback = class extends SignalExitBase {
onExit() {
return () => {
};
}
load() {
}
unload() {
}
};
var SignalExit = class extends SignalExitBase {
// "SIGHUP" throws an `ENOSYS` error on Windows,
// so use a supported signal instead
/* c8 ignore start */
#hupSig = process2.platform === "win32" ? "SIGINT" : "SIGHUP";
/* c8 ignore stop */
#emitter = new Emitter();
#process;
#originalProcessEmit;
#originalProcessReallyExit;
#sigListeners = {};
#loaded = false;
constructor(process3) {
super();
this.#process = process3;
this.#sigListeners = {};
for (const sig of signals) {
this.#sigListeners[sig] = () => {
const listeners = this.#process.listeners(sig);
let { count } = this.#emitter;
const p = process3;
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)
process3.kill(process3.pid, s);
}
};
}
this.#originalProcessReallyExit = process3.reallyExit;
this.#originalProcessEmit = process3.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);
}
}
};
var process2 = globalThis.process;
var {
/**
* 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 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 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(process2) ? new SignalExit(process2) : new SignalExitFallback());
// ../../node_modules/.pnpm/foreground-child@3.3.1/node_modules/foreground-child/dist/esm/all-signals.js
import constants from "node:constants";
var allSignals = (
// this is the full list of signals that Node will let us do anything with
Object.keys(constants).filter((k) => k.startsWith("SIG") && // https://github.com/tapjs/signal-exit/issues/21
k !== "SIGPROF" && // no sense trying to listen for SIGKILL, it's impossible
k !== "SIGKILL")
);
// ../../node_modules/.pnpm/foreground-child@3.3.1/node_modules/foreground-child/dist/esm/proxy-signals.js
var proxySignals = (child) => {
const listeners = /* @__PURE__ */ new Map();
for (const sig of allSignals) {
const listener = () => {
try {
child.kill(sig);
} catch (_) {
}
};
try {
process.on(sig, listener);
listeners.set(sig, listener);
} catch (_) {
}
}
const unproxy = () => {
for (const [sig, listener] of listeners) {
process.removeListener(sig, listener);
}
};
child.on("exit", unproxy);
return unproxy;
};
// ../../node_modules/.pnpm/foreground-child@3.3.1/node_modules/foreground-child/dist/esm/watchdog.js
import { spawn } from "node:child_process";
var watchdogCode = String.raw`
const pid = parseInt(process.argv[1], 10)
process.title = 'node (foreground-child watchdog pid=' + pid + ')'
if (!isNaN(pid)) {
let barked = false
// keepalive
const interval = setInterval(() => {}, 60000)
const bark = () => {
clearInterval(interval)
if (barked) return
barked = true
process.removeListener('SIGHUP', bark)
setTimeout(() => {
try {
process.kill(pid, 'SIGKILL')
setTimeout(() => process.exit(), 200)
} catch (_) {}
}, 500)
})
process.on('SIGHUP', bark)
}
`;
var watchdog = (child) => {
let dogExited = false;
const dog = spawn(process.execPath, ["-e", watchdogCode, String(child.pid)], {
stdio: "ignore"
});
dog.on("exit", () => dogExited = true);
child.on("exit", () => {
if (!dogExited)
dog.kill("SIGKILL");
});
return dog;
};
// ../../node_modules/.pnpm/foreground-child@3.3.1/node_modules/foreground-child/dist/esm/index.js
var spawn2 = process?.platform === "win32" ? import_cross_spawn.default : nodeSpawn;
var normalizeFgArgs = (fgArgs) => {
let [program, args = [], spawnOpts = {}, cleanup = () => {
}] = fgArgs;
if (typeof args === "function") {
cleanup = args;
spawnOpts = {};
args = [];
} else if (!!args && typeof args === "object" && !Array.isArray(args)) {
if (typeof spawnOpts === "function")
cleanup = spawnOpts;
spawnOpts = args;
args = [];
} else if (typeof spawnOpts === "function") {
cleanup = spawnOpts;
spawnOpts = {};
}
if (Array.isArray(program)) {
const [pp, ...pa] = program;
program = pp;
args = pa;
}
return [program, args, { ...spawnOpts }, cleanup];
};
function foregroundChild(...fgArgs) {
const [program, args, spawnOpts, cleanup] = normalizeFgArgs(fgArgs);
spawnOpts.stdio = [0, 1, 2];
if (process.send) {
spawnOpts.stdio.push("ipc");
}
const child = spawn2(program, args, spawnOpts);
const childHangup = () => {
try {
child.kill("SIGHUP");
} catch (_) {
child.kill("SIGTERM");
}
};
const removeOnExit = onExit(childHangup);
proxySignals(child);
const dog = watchdog(child);
let done = false;
child.on("close", async (code, signal) => {
if (done)
return;
done = true;
const result = cleanup(code, signal, {
watchdogPid: dog.pid
});
const res = isPromise(result) ? await result : result;
removeOnExit();
if (res === false)
return;
else if (typeof res === "string") {
signal = res;
code = null;
} else if (typeof res === "number") {
code = res;
signal = null;
}
if (signal) {
setTimeout(() => {
}, 2e3);
try {
process.kill(process.pid, signal);
} catch (_) {
process.kill(process.pid, "SIGTERM");
}
} else {
process.exit(code || 0);
}
});
if (process.send) {
process.removeAllListeners("message");
child.on("message", (message, sendHandle) => {
process.send?.(message, sendHandle);
});
process.on("message", (message, sendHandle) => {
child.send(message, sendHandle);
});
}
return child;
}
var isPromise = (o) => !!o && typeof o === "object" && typeof o.then === "function";
// ../../src/run/src/index.ts
import { statSync } from "node:fs";
import { delimiter, resolve, sep } from "node:path";
var dotBins = /* @__PURE__ */ new Map();
var dirExists = (p) => {
const cached = dotBins.get(p);
if (cached !== void 0) return cached;
try {
const isDir = statSync(p).isDirectory();
dotBins.set(p, isDir);
return isDir;
} catch {
dotBins.set(p, false);
return false;
}
};
var nmBin = `${sep}node_modules${sep}.bin`;
var addPaths = (projectRoot, cwd, env) => {
const { PATH = "" } = env;
const PATHsplit = PATH.split(delimiter);
const paths = /* @__PURE__ */ new Set();
for (const p of PATHsplit) {
if (p.endsWith(nmBin)) {
paths.add(p);
}
}
for (const p of walkUp(cwd)) {
const dotBin = resolve(p, "node_modules/.bin");
if (dirExists(dotBin)) paths.add(dotBin);
if (p === projectRoot) break;
}
for (const p of PATH.split(delimiter)) {
if (p) paths.add(p);
}
env.PATH = [...paths].join(delimiter);
return env;
};
var run = async (options) => runImpl(options, exec, "");
var runFG = async (options) => runImpl(options, execFG, null);
var isRunResult = (v) => !!v && typeof v === "object" && !Array.isArray(v) && "stdout" in v && "stderr" in v && "status" in v && "signal" in v;
var runImpl = async (options, execImpl, empty) => {
const {
arg0,
packageJson = new PackageJson(),
ignoreMissing = false,
manifest,
"script-shell": shell = true,
...execArgs
} = options;
const pjPath = resolve(options.cwd, "package.json");
const untrustworthy = !!(manifest?.gypfile && arg0 === "install" && manifest.scripts?.install === "node-gyp rebuild");
const pj = (untrustworthy ? void 0 : manifest) ?? packageJson.read(options.cwd);
const { scripts } = pj;
const command = scripts?.[arg0];
if (!command) {
if (ignoreMissing) {
return {
command: "",
/* c8 ignore next */
args: execArgs.args ?? [],
cwd: options.cwd,
status: 0,
signal: null,
stdout: empty,
stderr: empty
// `as` to workaround "could be instantiated with arbitrary type".
// it's private and used in 2 places, we know that it isn't.
};
}
throw error("Script not defined in package.json", {
name: arg0,
cwd: options.cwd,
args: options.args,
path: pjPath,
manifest: pj
});
}
const precommand = !options.ignorePrePost && scripts[`pre${arg0}`];
const pre = precommand ? await execImpl({
arg0: precommand,
...execArgs,
"script-shell": shell,
args: [],
env: {
...execArgs.env,
npm_package_json: pjPath,
npm_lifecycle_event: `pre${arg0}`,
npm_lifecycle_script: precommand
}
}) : void 0;
if (pre && (pre.status || pre.signal)) {
return pre;
}
const result = await execImpl({
arg0: command,
...execArgs,
"script-shell": shell,
env: {
...execArgs.env,
npm_package_json: pjPath,
npm_lifecycle_event: arg0,
npm_lifecycle_script: command
}
});
result.pre = pre;
if (result.signal || result.status) {
return result;
}
const postcommand = !options.ignorePrePost && scripts[`post${arg0}`];
if (!postcommand) return result;
const post = await execImpl({
arg0: postcommand,
...execArgs,
"script-shell": shell,
args: [],
env: {
...execArgs.env,
npm_package_json: pjPath,
npm_lifecycle_event: `post${arg0}`,
npm_lifecycle_script: postcommand
}
});
if (post.status || post.signal) {
const { status, signal } = post;
return Object.assign(result, { post, status, signal });
}
result.post = post;
return result;
};
var exec = async (options) => {
const {
arg0,
args = [],
cwd,
env = {},
projectRoot,
"script-shell": shell = false,
color = false,
...spawnOptions
} = options;
const p = promiseSpawn(arg0, args, {
...spawnOptions,
shell,
stdio: "pipe",
stdioString: true,
cwd,
env: addPaths(projectRoot, cwd, {
...process.env,
...env,
FORCE_COLOR: color ? "1" : "0"
}),
windowsHide: true
});
proxySignals(p.process);
return await p;
};
var execFG = async (options) => {
const {
arg0,
args = [],
cwd,
projectRoot,
env = {},
"script-shell": shell = false,
color = true,
...spawnOptions
} = options;
return new Promise((res) => {
foregroundChild(
arg0,
args,
{
...spawnOptions,
shell,
cwd,
env: addPaths(projectRoot, cwd, {
...process.env,
...env,
FORCE_COLOR: color ? "1" : "0"
})
},
(status, signal) => {
res({
command: arg0,
args,
cwd,
stdout: null,
stderr: null,
status,
signal
});
return false;
}
);
});
};
var runExecImpl = async (options, runImpl2, execImpl) => {
const { arg0, packageJson = new PackageJson(), ...args } = options;
const pj = packageJson.read(options.cwd);
const { scripts } = pj;
const command = scripts?.[arg0];
if (command) {
return runImpl2({ ...args, packageJson, arg0 });
} else {
return execImpl({ ...args, arg0 });
}
};
var runExec = async (options) => runExecImpl(options, run, exec);
var runExecFG = async (options) => runExecImpl(options, runFG, execFG);
export {
run,
runFG,
isRunResult,
exec,
execFG,
runExec,
runExecFG
};
//# sourceMappingURL=chunk-XZF5GYDF.js.map