const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.cjs');
let node_path = require("node:path");
let node_process = require("node:process");
let node_module = require("node:module");
let node_stream = require("node:stream");
let node_child_process = require("node:child_process");
let node_readline = require("node:readline");
node_readline = require_rolldown_runtime.__toESM(node_readline);

//#region ../../node_modules/.pnpm/tinyexec@1.0.2/node_modules/tinyexec/dist/main.js
var l = Object.create;
var u = Object.defineProperty;
var d = Object.getOwnPropertyDescriptor;
var f = Object.getOwnPropertyNames;
var p = Object.getPrototypeOf;
var m = Object.prototype.hasOwnProperty;
var h = (e$1, t$1) => () => (t$1 || e$1((t$1 = { exports: {} }).exports, t$1), t$1.exports);
var g = (e$1, t$1, n$1, r$1) => {
	if (t$1 && typeof t$1 === "object" || typeof t$1 === "function") for (var i$1 = f(t$1), a$1 = 0, o$1 = i$1.length, s$1; a$1 < o$1; a$1++) {
		s$1 = i$1[a$1];
		if (!m.call(e$1, s$1) && s$1 !== n$1) u(e$1, s$1, {
			get: ((e$2) => t$1[e$2]).bind(null, s$1),
			enumerable: !(r$1 = d(t$1, s$1)) || r$1.enumerable
		});
	}
	return e$1;
};
var _ = (e$1, t$1, n$1) => (n$1 = e$1 != null ? l(p(e$1)) : {}, g(t$1 || !e$1 || !e$1.__esModule ? u(n$1, "default", {
	value: e$1,
	enumerable: true
}) : n$1, e$1));
var v = /* @__PURE__ */ (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
const y = /^path$/i;
const b = {
	key: "PATH",
	value: ""
};
function x(e$1) {
	for (const t$1 in e$1) {
		if (!Object.prototype.hasOwnProperty.call(e$1, t$1) || !y.test(t$1)) continue;
		const n$1 = e$1[t$1];
		if (!n$1) return b;
		return {
			key: t$1,
			value: n$1
		};
	}
	return b;
}
function S(e$1, t$1) {
	const i$1 = t$1.value.split(node_path.delimiter);
	let o$1 = e$1;
	let s$1;
	do {
		i$1.push((0, node_path.resolve)(o$1, "node_modules", ".bin"));
		s$1 = o$1;
		o$1 = (0, node_path.dirname)(o$1);
	} while (o$1 !== s$1);
	return {
		key: t$1.key,
		value: i$1.join(node_path.delimiter)
	};
}
function C(e$1, t$1) {
	const n$1 = {
		...process.env,
		...t$1
	};
	const r$1 = S(e$1, x(n$1));
	n$1[r$1.key] = r$1.value;
	return n$1;
}
const w = (e$1) => {
	let t$1 = e$1.length;
	const n$1 = new node_stream.PassThrough();
	const r$1 = () => {
		if (--t$1 === 0) n$1.emit("end");
	};
	for (const t$2 of e$1) {
		t$2.pipe(n$1, { end: false });
		t$2.on("end", r$1);
	}
	return n$1;
};
var T = h((exports$1, t$1) => {
	t$1.exports = a$1;
	a$1.sync = o$1;
	var n$1 = v("fs");
	function r$1(e$1, t$2) {
		var n$2 = t$2.pathExt !== void 0 ? t$2.pathExt : process.env.PATHEXT;
		if (!n$2) return true;
		n$2 = n$2.split(";");
		if (n$2.indexOf("") !== -1) return true;
		for (var r$2 = 0; r$2 < n$2.length; r$2++) {
			var i$2 = n$2[r$2].toLowerCase();
			if (i$2 && e$1.substr(-i$2.length).toLowerCase() === i$2) return true;
		}
		return false;
	}
	function i$1(e$1, t$2, n$2) {
		if (!e$1.isSymbolicLink() && !e$1.isFile()) return false;
		return r$1(t$2, n$2);
	}
	function a$1(e$1, t$2, r$2) {
		n$1.stat(e$1, function(n$2, a$2) {
			r$2(n$2, n$2 ? false : i$1(a$2, e$1, t$2));
		});
	}
	function o$1(e$1, t$2) {
		return i$1(n$1.statSync(e$1), e$1, t$2);
	}
});
var E = h((exports$1, t$1) => {
	t$1.exports = r$1;
	r$1.sync = i$1;
	var n$1 = v("fs");
	function r$1(e$1, t$2, r$2) {
		n$1.stat(e$1, function(e$2, n$2) {
			r$2(e$2, e$2 ? false : a$1(n$2, t$2));
		});
	}
	function i$1(e$1, t$2) {
		return a$1(n$1.statSync(e$1), t$2);
	}
	function a$1(e$1, t$2) {
		return e$1.isFile() && o$1(e$1, t$2);
	}
	function o$1(e$1, t$2) {
		var n$2 = e$1.mode;
		var r$2 = e$1.uid;
		var i$2 = e$1.gid;
		var a$2 = t$2.uid !== void 0 ? t$2.uid : process.getuid && process.getuid();
		var o$2 = t$2.gid !== void 0 ? t$2.gid : process.getgid && process.getgid();
		var s$1 = parseInt("100", 8);
		var c$1 = parseInt("010", 8);
		var l$1 = parseInt("001", 8);
		var u$1 = s$1 | c$1;
		return n$2 & l$1 || n$2 & c$1 && i$2 === o$2 || n$2 & s$1 && r$2 === a$2 || n$2 & u$1 && a$2 === 0;
	}
});
var D = h((exports$1, t$1) => {
	v("fs");
	var r$1;
	if (process.platform === "win32" || global.TESTING_WINDOWS) r$1 = T();
	else r$1 = E();
	t$1.exports = i$1;
	i$1.sync = a$1;
	function i$1(e$1, t$2, n$1) {
		if (typeof t$2 === "function") {
			n$1 = t$2;
			t$2 = {};
		}
		if (!n$1) {
			if (typeof Promise !== "function") throw new TypeError("callback not provided");
			return new Promise(function(n$2, r$2) {
				i$1(e$1, t$2 || {}, function(e$2, t$3) {
					if (e$2) r$2(e$2);
					else n$2(t$3);
				});
			});
		}
		r$1(e$1, t$2 || {}, function(e$2, r$2) {
			if (e$2) {
				if (e$2.code === "EACCES" || t$2 && t$2.ignoreErrors) {
					e$2 = null;
					r$2 = false;
				}
			}
			n$1(e$2, r$2);
		});
	}
	function a$1(e$1, t$2) {
		try {
			return r$1.sync(e$1, t$2 || {});
		} catch (e$2) {
			if (t$2 && t$2.ignoreErrors || e$2.code === "EACCES") return false;
			else throw e$2;
		}
	}
});
var O = h((exports$1, t$1) => {
	const n$1 = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
	const r$1 = v("path");
	const i$1 = n$1 ? ";" : ":";
	const a$1 = D();
	const o$1 = (e$1) => Object.assign(/* @__PURE__ */ new Error(`not found: ${e$1}`), { code: "ENOENT" });
	const s$1 = (e$1, t$2) => {
		const r$2 = t$2.colon || i$1;
		const a$2 = e$1.match(/\//) || n$1 && e$1.match(/\\/) ? [""] : [...n$1 ? [process.cwd()] : [], ...(t$2.path || process.env.PATH || "").split(r$2)];
		const o$2 = n$1 ? t$2.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
		const s$2 = n$1 ? o$2.split(r$2) : [""];
		if (n$1) {
			if (e$1.indexOf(".") !== -1 && s$2[0] !== "") s$2.unshift("");
		}
		return {
			pathEnv: a$2,
			pathExt: s$2,
			pathExtExe: o$2
		};
	};
	const c$1 = (e$1, t$2, n$2) => {
		if (typeof t$2 === "function") {
			n$2 = t$2;
			t$2 = {};
		}
		if (!t$2) t$2 = {};
		const { pathEnv: i$2, pathExt: c$2, pathExtExe: l$2 } = s$1(e$1, t$2);
		const u$1 = [];
		const d$1 = (n$3) => new Promise((a$2, s$2) => {
			if (n$3 === i$2.length) return t$2.all && u$1.length ? a$2(u$1) : s$2(o$1(e$1));
			const c$3 = i$2[n$3];
			const l$3 = /^".*"$/.test(c$3) ? c$3.slice(1, -1) : c$3;
			const d$2 = r$1.join(l$3, e$1);
			a$2(f$1(!l$3 && /^\.[\\\/]/.test(e$1) ? e$1.slice(0, 2) + d$2 : d$2, n$3, 0));
		});
		const f$1 = (e$2, n$3, r$2) => new Promise((i$3, o$2) => {
			if (r$2 === c$2.length) return i$3(d$1(n$3 + 1));
			const s$2 = c$2[r$2];
			a$1(e$2 + s$2, { pathExt: l$2 }, (a$2, o$3) => {
				if (!a$2 && o$3) if (t$2.all) u$1.push(e$2 + s$2);
				else return i$3(e$2 + s$2);
				return i$3(f$1(e$2, n$3, r$2 + 1));
			});
		});
		return n$2 ? d$1(0).then((e$2) => n$2(null, e$2), n$2) : d$1(0);
	};
	const l$1 = (e$1, t$2) => {
		t$2 = t$2 || {};
		const { pathEnv: n$2, pathExt: i$2, pathExtExe: c$2 } = s$1(e$1, t$2);
		const l$2 = [];
		for (let o$2 = 0; o$2 < n$2.length; o$2++) {
			const s$2 = n$2[o$2];
			const u$1 = /^".*"$/.test(s$2) ? s$2.slice(1, -1) : s$2;
			const d$1 = r$1.join(u$1, e$1);
			const f$1 = !u$1 && /^\.[\\\/]/.test(e$1) ? e$1.slice(0, 2) + d$1 : d$1;
			for (let e$2 = 0; e$2 < i$2.length; e$2++) {
				const n$3 = f$1 + i$2[e$2];
				try {
					if (a$1.sync(n$3, { pathExt: c$2 })) if (t$2.all) l$2.push(n$3);
					else return n$3;
				} catch (e$3) {}
			}
		}
		if (t$2.all && l$2.length) return l$2;
		if (t$2.nothrow) return null;
		throw o$1(e$1);
	};
	t$1.exports = c$1;
	c$1.sync = l$1;
});
var k = h((exports$1, t$1) => {
	const n$1 = (e$1 = {}) => {
		const t$2 = e$1.env || process.env;
		if ((e$1.platform || process.platform) !== "win32") return "PATH";
		return Object.keys(t$2).reverse().find((e$2) => e$2.toUpperCase() === "PATH") || "Path";
	};
	t$1.exports = n$1;
	t$1.exports.default = n$1;
});
var A = h((exports$1, t$1) => {
	const n$1 = v("path");
	const r$1 = O();
	const i$1 = k();
	function a$1(e$1, t$2) {
		const a$2 = e$1.options.env || process.env;
		const o$2 = process.cwd();
		const s$1 = e$1.options.cwd != null;
		const c$1 = s$1 && process.chdir !== void 0 && !process.chdir.disabled;
		if (c$1) try {
			process.chdir(e$1.options.cwd);
		} catch (e$2) {}
		let l$1;
		try {
			l$1 = r$1.sync(e$1.command, {
				path: a$2[i$1({ env: a$2 })],
				pathExt: t$2 ? n$1.delimiter : void 0
			});
		} catch (e$2) {} finally {
			if (c$1) process.chdir(o$2);
		}
		if (l$1) l$1 = n$1.resolve(s$1 ? e$1.options.cwd : "", l$1);
		return l$1;
	}
	function o$1(e$1) {
		return a$1(e$1) || a$1(e$1, true);
	}
	t$1.exports = o$1;
});
var j = h((exports$1, t$1) => {
	const n$1 = /([()\][%!^"`<>&|;, *?])/g;
	function r$1(e$1) {
		e$1 = e$1.replace(n$1, "^$1");
		return e$1;
	}
	function i$1(e$1, t$2) {
		e$1 = `${e$1}`;
		e$1 = e$1.replace(/(\\*)"/g, "$1$1\\\"");
		e$1 = e$1.replace(/(\\*)$/, "$1$1");
		e$1 = `"${e$1}"`;
		e$1 = e$1.replace(n$1, "^$1");
		if (t$2) e$1 = e$1.replace(n$1, "^$1");
		return e$1;
	}
	t$1.exports.command = r$1;
	t$1.exports.argument = i$1;
});
var M = h((exports$1, t$1) => {
	t$1.exports = /^#!(.*)/;
});
var N = h((exports$1, t$1) => {
	const n$1 = M();
	t$1.exports = (e$1 = "") => {
		const t$2 = e$1.match(n$1);
		if (!t$2) return null;
		const [r$1, i$1] = t$2[0].replace(/#! ?/, "").split(" ");
		const a$1 = r$1.split("/").pop();
		if (a$1 === "env") return i$1;
		return i$1 ? `${a$1} ${i$1}` : a$1;
	};
});
var P = h((exports$1, t$1) => {
	const n$1 = v("fs");
	const r$1 = N();
	function i$1(e$1) {
		const t$2 = 150;
		const i$2 = Buffer.alloc(t$2);
		let a$1;
		try {
			a$1 = n$1.openSync(e$1, "r");
			n$1.readSync(a$1, i$2, 0, t$2, 0);
			n$1.closeSync(a$1);
		} catch (e$2) {}
		return r$1(i$2.toString());
	}
	t$1.exports = i$1;
});
var F = h((exports$1, t$1) => {
	const n$1 = v("path");
	const r$1 = A();
	const i$1 = j();
	const a$1 = P();
	const o$1 = process.platform === "win32";
	const s$1 = /\.(?:com|exe)$/i;
	const c$1 = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
	function l$1(e$1) {
		e$1.file = r$1(e$1);
		const t$2 = e$1.file && a$1(e$1.file);
		if (t$2) {
			e$1.args.unshift(e$1.file);
			e$1.command = t$2;
			return r$1(e$1);
		}
		return e$1.file;
	}
	function u$1(e$1) {
		if (!o$1) return e$1;
		const t$2 = l$1(e$1);
		const r$2 = !s$1.test(t$2);
		if (e$1.options.forceShell || r$2) {
			const r$3 = c$1.test(t$2);
			e$1.command = n$1.normalize(e$1.command);
			e$1.command = i$1.command(e$1.command);
			e$1.args = e$1.args.map((e$2) => i$1.argument(e$2, r$3));
			e$1.args = [
				"/d",
				"/s",
				"/c",
				`"${[e$1.command].concat(e$1.args).join(" ")}"`
			];
			e$1.command = process.env.comspec || "cmd.exe";
			e$1.options.windowsVerbatimArguments = true;
		}
		return e$1;
	}
	function d$1(e$1, t$2, n$2) {
		if (t$2 && !Array.isArray(t$2)) {
			n$2 = t$2;
			t$2 = null;
		}
		t$2 = t$2 ? t$2.slice(0) : [];
		n$2 = Object.assign({}, n$2);
		const r$2 = {
			command: e$1,
			args: t$2,
			options: n$2,
			file: void 0,
			original: {
				command: e$1,
				args: t$2
			}
		};
		return n$2.shell ? r$2 : u$1(r$2);
	}
	t$1.exports = d$1;
});
var I = h((exports$1, t$1) => {
	const n$1 = process.platform === "win32";
	function r$1(e$1, t$2) {
		return Object.assign(/* @__PURE__ */ new Error(`${t$2} ${e$1.command} ENOENT`), {
			code: "ENOENT",
			errno: "ENOENT",
			syscall: `${t$2} ${e$1.command}`,
			path: e$1.command,
			spawnargs: e$1.args
		});
	}
	function i$1(e$1, t$2) {
		if (!n$1) return;
		const r$2 = e$1.emit;
		e$1.emit = function(n$2, i$2) {
			if (n$2 === "exit") {
				const n$3 = a$1(i$2, t$2, "spawn");
				if (n$3) return r$2.call(e$1, "error", n$3);
			}
			return r$2.apply(e$1, arguments);
		};
	}
	function a$1(e$1, t$2) {
		if (n$1 && e$1 === 1 && !t$2.file) return r$1(t$2.original, "spawn");
		return null;
	}
	function o$1(e$1, t$2) {
		if (n$1 && e$1 === 1 && !t$2.file) return r$1(t$2.original, "spawnSync");
		return null;
	}
	t$1.exports = {
		hookChildProcess: i$1,
		verifyENOENT: a$1,
		verifyENOENTSync: o$1,
		notFoundError: r$1
	};
});
var R = _(h((exports$1, t$1) => {
	const n$1 = v("child_process");
	const r$1 = F();
	const i$1 = I();
	function a$1(e$1, t$2, a$2) {
		const o$2 = r$1(e$1, t$2, a$2);
		const s$1 = n$1.spawn(o$2.command, o$2.args, o$2.options);
		i$1.hookChildProcess(s$1, o$2);
		return s$1;
	}
	function o$1(e$1, t$2, a$2) {
		const o$2 = r$1(e$1, t$2, a$2);
		const s$1 = n$1.spawnSync(o$2.command, o$2.args, o$2.options);
		s$1.error = s$1.error || i$1.verifyENOENTSync(s$1.status, o$2);
		return s$1;
	}
	t$1.exports = a$1;
	t$1.exports.spawn = a$1;
	t$1.exports.sync = o$1;
	t$1.exports._parse = r$1;
	t$1.exports._enoent = i$1;
})(), 1);
var z = class extends Error {
	result;
	output;
	get exitCode() {
		if (this.result.exitCode !== null) return this.result.exitCode;
	}
	constructor(e$1, t$1) {
		super(`Process exited with non-zero status (${e$1.exitCode})`);
		this.result = e$1;
		this.output = t$1;
	}
};
const B = {
	timeout: void 0,
	persist: false
};
const V = { windowsHide: true };
function H(e$1, t$1) {
	return {
		command: (0, node_path.normalize)(e$1),
		args: t$1 ?? []
	};
}
function U(e$1) {
	const t$1 = new AbortController();
	for (const n$1 of e$1) {
		if (n$1.aborted) {
			t$1.abort();
			return n$1;
		}
		const e$2 = () => {
			t$1.abort(n$1.reason);
		};
		n$1.addEventListener("abort", e$2, { signal: t$1.signal });
	}
	return t$1.signal;
}
async function W(e$1) {
	let t$1 = "";
	for await (const n$1 of e$1) t$1 += n$1.toString();
	return t$1;
}
var G = class {
	_process;
	_aborted = false;
	_options;
	_command;
	_args;
	_resolveClose;
	_processClosed;
	_thrownError;
	get process() {
		return this._process;
	}
	get pid() {
		return this._process?.pid;
	}
	get exitCode() {
		if (this._process && this._process.exitCode !== null) return this._process.exitCode;
	}
	constructor(e$1, t$1, n$1) {
		this._options = {
			...B,
			...n$1
		};
		this._command = e$1;
		this._args = t$1 ?? [];
		this._processClosed = new Promise((e$2) => {
			this._resolveClose = e$2;
		});
	}
	kill(e$1) {
		return this._process?.kill(e$1) === true;
	}
	get aborted() {
		return this._aborted;
	}
	get killed() {
		return this._process?.killed === true;
	}
	pipe(e$1, t$1, n$1) {
		return q(e$1, t$1, {
			...n$1,
			stdin: this
		});
	}
	async *[Symbol.asyncIterator]() {
		const e$1 = this._process;
		if (!e$1) return;
		const t$1 = [];
		if (this._streamErr) t$1.push(this._streamErr);
		if (this._streamOut) t$1.push(this._streamOut);
		const n$1 = w(t$1);
		const r$1 = node_readline.default.createInterface({ input: n$1 });
		for await (const e$2 of r$1) yield e$2.toString();
		await this._processClosed;
		e$1.removeAllListeners();
		if (this._thrownError) throw this._thrownError;
		if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) throw new z(this);
	}
	async _waitForOutput() {
		const e$1 = this._process;
		if (!e$1) throw new Error("No process was started");
		const [t$1, n$1] = await Promise.all([this._streamOut ? W(this._streamOut) : "", this._streamErr ? W(this._streamErr) : ""]);
		await this._processClosed;
		if (this._options?.stdin) await this._options.stdin;
		e$1.removeAllListeners();
		if (this._thrownError) throw this._thrownError;
		const r$1 = {
			stderr: n$1,
			stdout: t$1,
			exitCode: this.exitCode
		};
		if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) throw new z(this, r$1);
		return r$1;
	}
	then(e$1, t$1) {
		return this._waitForOutput().then(e$1, t$1);
	}
	_streamOut;
	_streamErr;
	spawn() {
		const e$1 = (0, node_process.cwd)();
		const n$1 = this._options;
		const r$1 = {
			...V,
			...n$1.nodeOptions
		};
		const i$1 = [];
		this._resetState();
		if (n$1.timeout !== void 0) i$1.push(AbortSignal.timeout(n$1.timeout));
		if (n$1.signal !== void 0) i$1.push(n$1.signal);
		if (n$1.persist === true) r$1.detached = true;
		if (i$1.length > 0) r$1.signal = U(i$1);
		r$1.env = C(e$1, r$1.env);
		const { command: a$1, args: s$1 } = H(this._command, this._args);
		const c$1 = (0, R._parse)(a$1, s$1, r$1);
		const l$1 = (0, node_child_process.spawn)(c$1.command, c$1.args, c$1.options);
		if (l$1.stderr) this._streamErr = l$1.stderr;
		if (l$1.stdout) this._streamOut = l$1.stdout;
		this._process = l$1;
		l$1.once("error", this._onError);
		l$1.once("close", this._onClose);
		if (n$1.stdin !== void 0 && l$1.stdin && n$1.stdin.process) {
			const { stdout: e$2 } = n$1.stdin.process;
			if (e$2) e$2.pipe(l$1.stdin);
		}
	}
	_resetState() {
		this._aborted = false;
		this._processClosed = new Promise((e$1) => {
			this._resolveClose = e$1;
		});
		this._thrownError = void 0;
	}
	_onError = (e$1) => {
		if (e$1.name === "AbortError" && (!(e$1.cause instanceof Error) || e$1.cause.name !== "TimeoutError")) {
			this._aborted = true;
			return;
		}
		this._thrownError = e$1;
	};
	_onClose = () => {
		if (this._resolveClose) this._resolveClose();
	};
};
const K = (e$1, t$1, n$1) => {
	const r$1 = new G(e$1, t$1, n$1);
	r$1.spawn();
	return r$1;
};
const q = K;

//#endregion
exports.K = K;