main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. import { createRequire as __tinyexec_cr } from "node:module";const require = __tinyexec_cr(import.meta.url);
  2. var St = Object.create;
  3. var $ = Object.defineProperty;
  4. var kt = Object.getOwnPropertyDescriptor;
  5. var Tt = Object.getOwnPropertyNames;
  6. var At = Object.getPrototypeOf, Rt = Object.prototype.hasOwnProperty;
  7. var h = /* @__PURE__ */ ((t) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(t, {
  8. get: (e, n) => (typeof require < "u" ? require : e)[n]
  9. }) : t)(function(t) {
  10. if (typeof require < "u") return require.apply(this, arguments);
  11. throw Error('Dynamic require of "' + t + '" is not supported');
  12. });
  13. var l = (t, e) => () => (e || t((e = { exports: {} }).exports, e), e.exports);
  14. var $t = (t, e, n, r) => {
  15. if (e && typeof e == "object" || typeof e == "function")
  16. for (let s of Tt(e))
  17. !Rt.call(t, s) && s !== n && $(t, s, { get: () => e[s], enumerable: !(r = kt(e, s)) || r.enumerable });
  18. return t;
  19. };
  20. var Nt = (t, e, n) => (n = t != null ? St(At(t)) : {}, $t(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. e || !t || !t.__esModule ? $(n, "default", { value: t, enumerable: !0 }) : n,
  26. t
  27. ));
  28. // node_modules/isexe/windows.js
  29. var W = l((Se, H) => {
  30. "use strict";
  31. H.exports = z;
  32. z.sync = Wt;
  33. var j = h("fs");
  34. function Ht(t, e) {
  35. var n = e.pathExt !== void 0 ? e.pathExt : process.env.PATHEXT;
  36. if (!n || (n = n.split(";"), n.indexOf("") !== -1))
  37. return !0;
  38. for (var r = 0; r < n.length; r++) {
  39. var s = n[r].toLowerCase();
  40. if (s && t.substr(-s.length).toLowerCase() === s)
  41. return !0;
  42. }
  43. return !1;
  44. }
  45. function F(t, e, n) {
  46. return !t.isSymbolicLink() && !t.isFile() ? !1 : Ht(e, n);
  47. }
  48. function z(t, e, n) {
  49. j.stat(t, function(r, s) {
  50. n(r, r ? !1 : F(s, t, e));
  51. });
  52. }
  53. function Wt(t, e) {
  54. return F(j.statSync(t), t, e);
  55. }
  56. });
  57. // node_modules/isexe/mode.js
  58. var X = l((ke, B) => {
  59. "use strict";
  60. B.exports = K;
  61. K.sync = Dt;
  62. var D = h("fs");
  63. function K(t, e, n) {
  64. D.stat(t, function(r, s) {
  65. n(r, r ? !1 : M(s, e));
  66. });
  67. }
  68. function Dt(t, e) {
  69. return M(D.statSync(t), e);
  70. }
  71. function M(t, e) {
  72. return t.isFile() && Kt(t, e);
  73. }
  74. function Kt(t, e) {
  75. var n = t.mode, r = t.uid, s = t.gid, o = e.uid !== void 0 ? e.uid : process.getuid && process.getuid(), i = e.gid !== void 0 ? e.gid : process.getgid && process.getgid(), a = parseInt("100", 8), c = parseInt("010", 8), u = parseInt("001", 8), f = a | c, p = n & u || n & c && s === i || n & a && r === o || n & f && o === 0;
  76. return p;
  77. }
  78. });
  79. // node_modules/isexe/index.js
  80. var U = l((Ae, G) => {
  81. "use strict";
  82. var Te = h("fs"), v;
  83. process.platform === "win32" || global.TESTING_WINDOWS ? v = W() : v = X();
  84. G.exports = y;
  85. y.sync = Mt;
  86. function y(t, e, n) {
  87. if (typeof e == "function" && (n = e, e = {}), !n) {
  88. if (typeof Promise != "function")
  89. throw new TypeError("callback not provided");
  90. return new Promise(function(r, s) {
  91. y(t, e || {}, function(o, i) {
  92. o ? s(o) : r(i);
  93. });
  94. });
  95. }
  96. v(t, e || {}, function(r, s) {
  97. r && (r.code === "EACCES" || e && e.ignoreErrors) && (r = null, s = !1), n(r, s);
  98. });
  99. }
  100. function Mt(t, e) {
  101. try {
  102. return v.sync(t, e || {});
  103. } catch (n) {
  104. if (e && e.ignoreErrors || n.code === "EACCES")
  105. return !1;
  106. throw n;
  107. }
  108. }
  109. });
  110. // node_modules/which/which.js
  111. var et = l((Re, tt) => {
  112. "use strict";
  113. var g = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys", Y = h("path"), Bt = g ? ";" : ":", V = U(), J = (t) => Object.assign(new Error(`not found: ${t}`), { code: "ENOENT" }), Q = (t, e) => {
  114. let n = e.colon || Bt, r = t.match(/\//) || g && t.match(/\\/) ? [""] : [
  115. // windows always checks the cwd first
  116. ...g ? [process.cwd()] : [],
  117. ...(e.path || process.env.PATH || /* istanbul ignore next: very unusual */
  118. "").split(n)
  119. ], s = g ? e.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "", o = g ? s.split(n) : [""];
  120. return g && t.indexOf(".") !== -1 && o[0] !== "" && o.unshift(""), {
  121. pathEnv: r,
  122. pathExt: o,
  123. pathExtExe: s
  124. };
  125. }, Z = (t, e, n) => {
  126. typeof e == "function" && (n = e, e = {}), e || (e = {});
  127. let { pathEnv: r, pathExt: s, pathExtExe: o } = Q(t, e), i = [], a = (u) => new Promise((f, p) => {
  128. if (u === r.length)
  129. return e.all && i.length ? f(i) : p(J(t));
  130. let d = r[u], w = /^".*"$/.test(d) ? d.slice(1, -1) : d, m = Y.join(w, t), b = !w && /^\.[\\\/]/.test(t) ? t.slice(0, 2) + m : m;
  131. f(c(b, u, 0));
  132. }), c = (u, f, p) => new Promise((d, w) => {
  133. if (p === s.length)
  134. return d(a(f + 1));
  135. let m = s[p];
  136. V(u + m, { pathExt: o }, (b, Ot) => {
  137. if (!b && Ot)
  138. if (e.all)
  139. i.push(u + m);
  140. else
  141. return d(u + m);
  142. return d(c(u, f, p + 1));
  143. });
  144. });
  145. return n ? a(0).then((u) => n(null, u), n) : a(0);
  146. }, Xt = (t, e) => {
  147. e = e || {};
  148. let { pathEnv: n, pathExt: r, pathExtExe: s } = Q(t, e), o = [];
  149. for (let i = 0; i < n.length; i++) {
  150. let a = n[i], c = /^".*"$/.test(a) ? a.slice(1, -1) : a, u = Y.join(c, t), f = !c && /^\.[\\\/]/.test(t) ? t.slice(0, 2) + u : u;
  151. for (let p = 0; p < r.length; p++) {
  152. let d = f + r[p];
  153. try {
  154. if (V.sync(d, { pathExt: s }))
  155. if (e.all)
  156. o.push(d);
  157. else
  158. return d;
  159. } catch {
  160. }
  161. }
  162. }
  163. if (e.all && o.length)
  164. return o;
  165. if (e.nothrow)
  166. return null;
  167. throw J(t);
  168. };
  169. tt.exports = Z;
  170. Z.sync = Xt;
  171. });
  172. // node_modules/path-key/index.js
  173. var rt = l(($e, _) => {
  174. "use strict";
  175. var nt = (t = {}) => {
  176. let e = t.env || process.env;
  177. return (t.platform || process.platform) !== "win32" ? "PATH" : Object.keys(e).reverse().find((r) => r.toUpperCase() === "PATH") || "Path";
  178. };
  179. _.exports = nt;
  180. _.exports.default = nt;
  181. });
  182. // node_modules/cross-spawn/lib/util/resolveCommand.js
  183. var ct = l((Ne, it) => {
  184. "use strict";
  185. var st = h("path"), Gt = et(), Ut = rt();
  186. function ot(t, e) {
  187. let n = t.options.env || process.env, r = process.cwd(), s = t.options.cwd != null, o = s && process.chdir !== void 0 && !process.chdir.disabled;
  188. if (o)
  189. try {
  190. process.chdir(t.options.cwd);
  191. } catch {
  192. }
  193. let i;
  194. try {
  195. i = Gt.sync(t.command, {
  196. path: n[Ut({ env: n })],
  197. pathExt: e ? st.delimiter : void 0
  198. });
  199. } catch {
  200. } finally {
  201. o && process.chdir(r);
  202. }
  203. return i && (i = st.resolve(s ? t.options.cwd : "", i)), i;
  204. }
  205. function Yt(t) {
  206. return ot(t) || ot(t, !0);
  207. }
  208. it.exports = Yt;
  209. });
  210. // node_modules/cross-spawn/lib/util/escape.js
  211. var ut = l((qe, P) => {
  212. "use strict";
  213. var C = /([()\][%!^"`<>&|;, *?])/g;
  214. function Vt(t) {
  215. return t = t.replace(C, "^$1"), t;
  216. }
  217. function Jt(t, e) {
  218. return t = `${t}`, t = t.replace(/(\\*)"/g, '$1$1\\"'), t = t.replace(/(\\*)$/, "$1$1"), t = `"${t}"`, t = t.replace(C, "^$1"), e && (t = t.replace(C, "^$1")), t;
  219. }
  220. P.exports.command = Vt;
  221. P.exports.argument = Jt;
  222. });
  223. // node_modules/shebang-regex/index.js
  224. var lt = l((Ie, at) => {
  225. "use strict";
  226. at.exports = /^#!(.*)/;
  227. });
  228. // node_modules/shebang-command/index.js
  229. var dt = l((Le, pt) => {
  230. "use strict";
  231. var Qt = lt();
  232. pt.exports = (t = "") => {
  233. let e = t.match(Qt);
  234. if (!e)
  235. return null;
  236. let [n, r] = e[0].replace(/#! ?/, "").split(" "), s = n.split("/").pop();
  237. return s === "env" ? r : r ? `${s} ${r}` : s;
  238. };
  239. });
  240. // node_modules/cross-spawn/lib/util/readShebang.js
  241. var ht = l((je, ft) => {
  242. "use strict";
  243. var O = h("fs"), Zt = dt();
  244. function te(t) {
  245. let n = Buffer.alloc(150), r;
  246. try {
  247. r = O.openSync(t, "r"), O.readSync(r, n, 0, 150, 0), O.closeSync(r);
  248. } catch {
  249. }
  250. return Zt(n.toString());
  251. }
  252. ft.exports = te;
  253. });
  254. // node_modules/cross-spawn/lib/parse.js
  255. var wt = l((Fe, Et) => {
  256. "use strict";
  257. var ee = h("path"), mt = ct(), gt = ut(), ne = ht(), re = process.platform === "win32", se = /\.(?:com|exe)$/i, oe = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
  258. function ie(t) {
  259. t.file = mt(t);
  260. let e = t.file && ne(t.file);
  261. return e ? (t.args.unshift(t.file), t.command = e, mt(t)) : t.file;
  262. }
  263. function ce(t) {
  264. if (!re)
  265. return t;
  266. let e = ie(t), n = !se.test(e);
  267. if (t.options.forceShell || n) {
  268. let r = oe.test(e);
  269. t.command = ee.normalize(t.command), t.command = gt.command(t.command), t.args = t.args.map((o) => gt.argument(o, r));
  270. let s = [t.command].concat(t.args).join(" ");
  271. t.args = ["/d", "/s", "/c", `"${s}"`], t.command = process.env.comspec || "cmd.exe", t.options.windowsVerbatimArguments = !0;
  272. }
  273. return t;
  274. }
  275. function ue(t, e, n) {
  276. e && !Array.isArray(e) && (n = e, e = null), e = e ? e.slice(0) : [], n = Object.assign({}, n);
  277. let r = {
  278. command: t,
  279. args: e,
  280. options: n,
  281. file: void 0,
  282. original: {
  283. command: t,
  284. args: e
  285. }
  286. };
  287. return n.shell ? r : ce(r);
  288. }
  289. Et.exports = ue;
  290. });
  291. // node_modules/cross-spawn/lib/enoent.js
  292. var bt = l((ze, vt) => {
  293. "use strict";
  294. var S = process.platform === "win32";
  295. function k(t, e) {
  296. return Object.assign(new Error(`${e} ${t.command} ENOENT`), {
  297. code: "ENOENT",
  298. errno: "ENOENT",
  299. syscall: `${e} ${t.command}`,
  300. path: t.command,
  301. spawnargs: t.args
  302. });
  303. }
  304. function ae(t, e) {
  305. if (!S)
  306. return;
  307. let n = t.emit;
  308. t.emit = function(r, s) {
  309. if (r === "exit") {
  310. let o = xt(s, e, "spawn");
  311. if (o)
  312. return n.call(t, "error", o);
  313. }
  314. return n.apply(t, arguments);
  315. };
  316. }
  317. function xt(t, e) {
  318. return S && t === 1 && !e.file ? k(e.original, "spawn") : null;
  319. }
  320. function le(t, e) {
  321. return S && t === 1 && !e.file ? k(e.original, "spawnSync") : null;
  322. }
  323. vt.exports = {
  324. hookChildProcess: ae,
  325. verifyENOENT: xt,
  326. verifyENOENTSync: le,
  327. notFoundError: k
  328. };
  329. });
  330. // node_modules/cross-spawn/index.js
  331. var Ct = l((He, E) => {
  332. "use strict";
  333. var yt = h("child_process"), T = wt(), A = bt();
  334. function _t(t, e, n) {
  335. let r = T(t, e, n), s = yt.spawn(r.command, r.args, r.options);
  336. return A.hookChildProcess(s, r), s;
  337. }
  338. function pe(t, e, n) {
  339. let r = T(t, e, n), s = yt.spawnSync(r.command, r.args, r.options);
  340. return s.error = s.error || A.verifyENOENTSync(s.status, r), s;
  341. }
  342. E.exports = _t;
  343. E.exports.spawn = _t;
  344. E.exports.sync = pe;
  345. E.exports._parse = T;
  346. E.exports._enoent = A;
  347. });
  348. // src/main.ts
  349. import { spawn as de } from "child_process";
  350. import { normalize as fe } from "path";
  351. import { cwd as he } from "process";
  352. // src/env.ts
  353. import {
  354. delimiter as N,
  355. resolve as qt,
  356. dirname as It
  357. } from "path";
  358. var Lt = /^path$/i, q = { key: "PATH", value: "" };
  359. function jt(t) {
  360. for (let e in t) {
  361. if (!Object.prototype.hasOwnProperty.call(t, e) || !Lt.test(e))
  362. continue;
  363. let n = t[e];
  364. return n ? { key: e, value: n } : q;
  365. }
  366. return q;
  367. }
  368. function Ft(t, e) {
  369. let n = e.value.split(N), r = t, s;
  370. do
  371. n.push(qt(r, "node_modules", ".bin")), s = r, r = It(r);
  372. while (r !== s);
  373. return { key: e.key, value: n.join(N) };
  374. }
  375. function I(t, e) {
  376. let n = {
  377. ...process.env,
  378. ...e
  379. }, r = Ft(t, jt(n));
  380. return n[r.key] = r.value, n;
  381. }
  382. // src/stream.ts
  383. import { PassThrough as zt } from "stream";
  384. var L = (t) => {
  385. let e = t.length, n = new zt(), r = () => {
  386. --e === 0 && n.emit("end");
  387. };
  388. for (let s of t)
  389. s.pipe(n, { end: !1 }), s.on("end", r);
  390. return n;
  391. };
  392. // src/main.ts
  393. var Pt = Nt(Ct(), 1);
  394. import me from "readline";
  395. // src/non-zero-exit-error.ts
  396. var x = class extends Error {
  397. result;
  398. output;
  399. get exitCode() {
  400. if (this.result.exitCode !== null)
  401. return this.result.exitCode;
  402. }
  403. constructor(e, n) {
  404. super(`Process exited with non-zero status (${e.exitCode})`), this.result = e, this.output = n;
  405. }
  406. };
  407. // src/main.ts
  408. var ge = {
  409. timeout: void 0,
  410. persist: !1
  411. }, Ee = {
  412. windowsHide: !0
  413. };
  414. function we(t, e) {
  415. return {
  416. command: fe(t),
  417. args: e ?? []
  418. };
  419. }
  420. function xe(t) {
  421. let e = new AbortController();
  422. for (let n of t) {
  423. if (n.aborted)
  424. return e.abort(), n;
  425. let r = () => {
  426. e.abort(n.reason);
  427. };
  428. n.addEventListener("abort", r, {
  429. signal: e.signal
  430. });
  431. }
  432. return e.signal;
  433. }
  434. var R = class {
  435. _process;
  436. _aborted = !1;
  437. _options;
  438. _command;
  439. _args;
  440. _resolveClose;
  441. _processClosed;
  442. _thrownError;
  443. get process() {
  444. return this._process;
  445. }
  446. get pid() {
  447. return this._process?.pid;
  448. }
  449. get exitCode() {
  450. if (this._process && this._process.exitCode !== null)
  451. return this._process.exitCode;
  452. }
  453. constructor(e, n, r) {
  454. this._options = {
  455. ...ge,
  456. ...r
  457. }, this._command = e, this._args = n ?? [], this._processClosed = new Promise((s) => {
  458. this._resolveClose = s;
  459. });
  460. }
  461. kill(e) {
  462. return this._process?.kill(e) === !0;
  463. }
  464. get aborted() {
  465. return this._aborted;
  466. }
  467. get killed() {
  468. return this._process?.killed === !0;
  469. }
  470. pipe(e, n, r) {
  471. return be(e, n, {
  472. ...r,
  473. stdin: this
  474. });
  475. }
  476. async *[Symbol.asyncIterator]() {
  477. let e = this._process;
  478. if (!e)
  479. return;
  480. let n = [];
  481. this._streamErr && n.push(this._streamErr), this._streamOut && n.push(this._streamOut);
  482. let r = L(n), s = me.createInterface({
  483. input: r
  484. });
  485. for await (let o of s)
  486. yield o.toString();
  487. if (await this._processClosed, e.removeAllListeners(), this._thrownError)
  488. throw this._thrownError;
  489. if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0)
  490. throw new x(this);
  491. }
  492. async _waitForOutput() {
  493. let e = this._process;
  494. if (!e)
  495. throw new Error("No process was started");
  496. let n = "", r = "";
  497. if (this._streamOut)
  498. for await (let o of this._streamOut)
  499. r += o.toString();
  500. if (this._streamErr)
  501. for await (let o of this._streamErr)
  502. n += o.toString();
  503. if (await this._processClosed, this._options?.stdin && await this._options.stdin, e.removeAllListeners(), this._thrownError)
  504. throw this._thrownError;
  505. let s = {
  506. stderr: n,
  507. stdout: r,
  508. exitCode: this.exitCode
  509. };
  510. if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0)
  511. throw new x(this, s);
  512. return s;
  513. }
  514. then(e, n) {
  515. return this._waitForOutput().then(e, n);
  516. }
  517. _streamOut;
  518. _streamErr;
  519. spawn() {
  520. let e = he(), n = this._options, r = {
  521. ...Ee,
  522. ...n.nodeOptions
  523. }, s = [];
  524. this._resetState(), n.timeout !== void 0 && s.push(AbortSignal.timeout(n.timeout)), n.signal !== void 0 && s.push(n.signal), n.persist === !0 && (r.detached = !0), s.length > 0 && (r.signal = xe(s)), r.env = I(e, r.env);
  525. let { command: o, args: i } = we(this._command, this._args), a = (0, Pt._parse)(o, i, r), c = de(
  526. a.command,
  527. a.args,
  528. a.options
  529. );
  530. if (c.stderr && (this._streamErr = c.stderr), c.stdout && (this._streamOut = c.stdout), this._process = c, c.once("error", this._onError), c.once("close", this._onClose), n.stdin !== void 0 && c.stdin && n.stdin.process) {
  531. let { stdout: u } = n.stdin.process;
  532. u && u.pipe(c.stdin);
  533. }
  534. }
  535. _resetState() {
  536. this._aborted = !1, this._processClosed = new Promise((e) => {
  537. this._resolveClose = e;
  538. }), this._thrownError = void 0;
  539. }
  540. _onError = (e) => {
  541. if (e.name === "AbortError" && (!(e.cause instanceof Error) || e.cause.name !== "TimeoutError")) {
  542. this._aborted = !0;
  543. return;
  544. }
  545. this._thrownError = e;
  546. };
  547. _onClose = () => {
  548. this._resolveClose && this._resolveClose();
  549. };
  550. }, ve = (t, e, n) => {
  551. let r = new R(t, e, n);
  552. return r.spawn(), r;
  553. }, be = ve;
  554. export {
  555. R as ExecProcess,
  556. x as NonZeroExitError,
  557. be as exec,
  558. ve as x
  559. };