@visulima/package 3.5.4 → 3.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,13 @@
1
1
  import { existsSync } from 'node:fs';
2
- import { installPackage } from '@antfu/install-pkg';
2
+ import process$1 from 'node:process';
3
+ import fs from 'node:fs/promises';
4
+ import path, { resolve as resolve$1 } from 'node:path';
5
+ import { createRequire } from 'node:module';
6
+ import { spawn } from 'child_process';
7
+ import { delimiter, resolve, dirname, normalize } from 'path';
8
+ import { cwd } from 'process';
9
+ import { PassThrough } from 'stream';
10
+ import me from 'readline';
3
11
  import confirm from '@inquirer/confirm';
4
12
  import { findUp, readJson, findUpSync, readJsonSync, writeJson, writeJsonSync } from '@visulima/fs';
5
13
  import { NotFoundError } from '@visulima/fs/error';
@@ -7,6 +15,813 @@ import { toPath, parseJson } from '@visulima/fs/utils';
7
15
  import { join } from '@visulima/path';
8
16
  import normalizeData from 'normalize-package-data';
9
17
 
18
+ const AGENTS = [
19
+ "npm",
20
+ "yarn",
21
+ "yarn@berry",
22
+ "pnpm",
23
+ "pnpm@6",
24
+ "bun",
25
+ "deno"
26
+ ];
27
+ const LOCKS = {
28
+ "bun.lock": "bun",
29
+ "bun.lockb": "bun",
30
+ "deno.lock": "deno",
31
+ "pnpm-lock.yaml": "pnpm",
32
+ "pnpm-workspace.yaml": "pnpm",
33
+ "yarn.lock": "yarn",
34
+ "package-lock.json": "npm",
35
+ "npm-shrinkwrap.json": "npm"
36
+ };
37
+ const INSTALL_METADATA = {
38
+ "node_modules/.deno/": "deno",
39
+ "node_modules/.pnpm/": "pnpm",
40
+ "node_modules/.yarn-state.yml": "yarn",
41
+ // yarn v2+ (node-modules)
42
+ "node_modules/.yarn_integrity": "yarn",
43
+ // yarn v1
44
+ "node_modules/.package-lock.json": "npm",
45
+ ".pnp.cjs": "yarn",
46
+ // yarn v3+ (pnp)
47
+ ".pnp.js": "yarn",
48
+ // yarn v2 (pnp)
49
+ "bun.lock": "bun",
50
+ "bun.lockb": "bun"
51
+ };
52
+
53
+ var __defProp$4 = Object.defineProperty;
54
+ var __name$4 = (target, value) => __defProp$4(target, "name", { value, configurable: true });
55
+ async function pathExists(path2, type) {
56
+ try {
57
+ const stat = await fs.stat(path2);
58
+ return type === "file" ? stat.isFile() : stat.isDirectory();
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ __name$4(pathExists, "pathExists");
64
+ function getUserAgent() {
65
+ const userAgent = process$1.env.npm_config_user_agent;
66
+ if (!userAgent) {
67
+ return null;
68
+ }
69
+ const name = userAgent.split("/")[0];
70
+ return AGENTS.includes(name) ? name : null;
71
+ }
72
+ __name$4(getUserAgent, "getUserAgent");
73
+ function* lookup(cwd = process$1.cwd()) {
74
+ let directory = path.resolve(cwd);
75
+ const { root } = path.parse(directory);
76
+ while (directory && directory !== root) {
77
+ yield directory;
78
+ directory = path.dirname(directory);
79
+ }
80
+ }
81
+ __name$4(lookup, "lookup");
82
+ async function parsePackageJson$1(filepath, onUnknown) {
83
+ return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
84
+ }
85
+ __name$4(parsePackageJson$1, "parsePackageJson");
86
+ async function detect(options = {}) {
87
+ const {
88
+ cwd,
89
+ strategies = ["lockfile", "packageManager-field", "devEngines-field"],
90
+ onUnknown
91
+ } = options;
92
+ let stopDir;
93
+ if (typeof options.stopDir === "string") {
94
+ const resolved = path.resolve(options.stopDir);
95
+ stopDir = /* @__PURE__ */ __name$4((dir) => dir === resolved, "stopDir");
96
+ } else {
97
+ stopDir = options.stopDir;
98
+ }
99
+ for (const directory of lookup(cwd)) {
100
+ for (const strategy of strategies) {
101
+ switch (strategy) {
102
+ case "lockfile": {
103
+ for (const lock of Object.keys(LOCKS)) {
104
+ if (await pathExists(path.join(directory, lock), "file")) {
105
+ const name = LOCKS[lock];
106
+ const result = await parsePackageJson$1(path.join(directory, "package.json"), onUnknown);
107
+ if (result)
108
+ return result;
109
+ else
110
+ return { name, agent: name };
111
+ }
112
+ }
113
+ break;
114
+ }
115
+ case "packageManager-field":
116
+ case "devEngines-field": {
117
+ const result = await parsePackageJson$1(path.join(directory, "package.json"), onUnknown);
118
+ if (result)
119
+ return result;
120
+ break;
121
+ }
122
+ case "install-metadata": {
123
+ for (const metadata of Object.keys(INSTALL_METADATA)) {
124
+ const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
125
+ if (await pathExists(path.join(directory, metadata), fileOrDir)) {
126
+ const name = INSTALL_METADATA[metadata];
127
+ const agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
128
+ return { name, agent };
129
+ }
130
+ }
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ if (stopDir?.(directory))
136
+ break;
137
+ }
138
+ return null;
139
+ }
140
+ __name$4(detect, "detect");
141
+ function getNameAndVer(pkg) {
142
+ const handelVer = /* @__PURE__ */ __name$4((version) => version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version, "handelVer");
143
+ if (typeof pkg.packageManager === "string") {
144
+ const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
145
+ return { name, ver: handelVer(ver) };
146
+ }
147
+ if (typeof pkg.devEngines?.packageManager?.name === "string") {
148
+ return {
149
+ name: pkg.devEngines.packageManager.name,
150
+ ver: handelVer(pkg.devEngines.packageManager.version)
151
+ };
152
+ }
153
+ return void 0;
154
+ }
155
+ __name$4(getNameAndVer, "getNameAndVer");
156
+ async function handlePackageManager(filepath, onUnknown) {
157
+ try {
158
+ const pkg = JSON.parse(await fs.readFile(filepath, "utf8"));
159
+ let agent;
160
+ const nameAndVer = getNameAndVer(pkg);
161
+ if (nameAndVer) {
162
+ const name = nameAndVer.name;
163
+ const ver = nameAndVer.ver;
164
+ let version = ver;
165
+ if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
166
+ agent = "yarn@berry";
167
+ version = "berry";
168
+ return { name, agent, version };
169
+ } else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
170
+ agent = "pnpm@6";
171
+ return { name, agent, version };
172
+ } else if (AGENTS.includes(name)) {
173
+ agent = name;
174
+ return { name, agent, version };
175
+ } else {
176
+ return onUnknown?.(pkg.packageManager) ?? null;
177
+ }
178
+ }
179
+ } catch {
180
+ }
181
+ return null;
182
+ }
183
+ __name$4(handlePackageManager, "handlePackageManager");
184
+ function isMetadataYarnClassic(metadataPath) {
185
+ return metadataPath.endsWith(".yarn_integrity");
186
+ }
187
+ __name$4(isMetadataYarnClassic, "isMetadataYarnClassic");
188
+
189
+ var __defProp$3 = Object.defineProperty;
190
+ var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
191
+ const require2 = createRequire(import.meta.url);
192
+ var St = Object.create;
193
+ var $ = Object.defineProperty;
194
+ var kt = Object.getOwnPropertyDescriptor;
195
+ var Tt = Object.getOwnPropertyNames;
196
+ var At = Object.getPrototypeOf;
197
+ var Rt = Object.prototype.hasOwnProperty;
198
+ var h = /* @__PURE__ */ ((t) => typeof require2 < "u" ? require2 : typeof Proxy < "u" ? new Proxy(t, {
199
+ get: /* @__PURE__ */ __name$3((e, n) => (typeof require2 < "u" ? require2 : e)[n], "get")
200
+ }) : t)(function(t) {
201
+ if (typeof require2 < "u") return require2.apply(this, arguments);
202
+ throw Error('Dynamic require of "' + t + '" is not supported');
203
+ });
204
+ var l = /* @__PURE__ */ __name$3((t, e) => () => (e || t((e = { exports: {} }).exports, e), e.exports), "l");
205
+ var $t = /* @__PURE__ */ __name$3((t, e, n, r) => {
206
+ if (e && typeof e == "object" || typeof e == "function")
207
+ for (let s of Tt(e))
208
+ !Rt.call(t, s) && s !== n && $(t, s, { get: /* @__PURE__ */ __name$3(() => e[s], "get"), enumerable: !(r = kt(e, s)) || r.enumerable });
209
+ return t;
210
+ }, "$t");
211
+ var Nt = /* @__PURE__ */ __name$3((t, e, n) => (n = t != null ? St(At(t)) : {}, $t(
212
+ // If the importer is in node compatibility mode or this is not an ESM
213
+ // file that has been converted to a CommonJS file using a Babel-
214
+ // compatible transform (i.e. "__esModule" has not been set), then set
215
+ // "default" to the CommonJS "module.exports" for node compatibility.
216
+ e || !t || !t.__esModule ? $(n, "default", { value: t, enumerable: true }) : n,
217
+ t
218
+ )), "Nt");
219
+ var W = l((Se, H) => {
220
+ H.exports = z;
221
+ z.sync = Wt;
222
+ var j = h("fs");
223
+ function Ht(t, e) {
224
+ var n = e.pathExt !== void 0 ? e.pathExt : process.env.PATHEXT;
225
+ if (!n || (n = n.split(";"), n.indexOf("") !== -1))
226
+ return true;
227
+ for (var r = 0; r < n.length; r++) {
228
+ var s = n[r].toLowerCase();
229
+ if (s && t.substr(-s.length).toLowerCase() === s)
230
+ return true;
231
+ }
232
+ return false;
233
+ }
234
+ __name$3(Ht, "Ht");
235
+ function F(t, e, n) {
236
+ return !t.isSymbolicLink() && !t.isFile() ? false : Ht(e, n);
237
+ }
238
+ __name$3(F, "F");
239
+ function z(t, e, n) {
240
+ j.stat(t, function(r, s) {
241
+ n(r, r ? false : F(s, t, e));
242
+ });
243
+ }
244
+ __name$3(z, "z");
245
+ function Wt(t, e) {
246
+ return F(j.statSync(t), t, e);
247
+ }
248
+ __name$3(Wt, "Wt");
249
+ });
250
+ var X = l((ke, B) => {
251
+ B.exports = K;
252
+ K.sync = Dt;
253
+ var D = h("fs");
254
+ function K(t, e, n) {
255
+ D.stat(t, function(r, s) {
256
+ n(r, r ? false : M(s, e));
257
+ });
258
+ }
259
+ __name$3(K, "K");
260
+ function Dt(t, e) {
261
+ return M(D.statSync(t), e);
262
+ }
263
+ __name$3(Dt, "Dt");
264
+ function M(t, e) {
265
+ return t.isFile() && Kt(t, e);
266
+ }
267
+ __name$3(M, "M");
268
+ function Kt(t, e) {
269
+ 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;
270
+ return p;
271
+ }
272
+ __name$3(Kt, "Kt");
273
+ });
274
+ var U = l((Ae, G) => {
275
+ h("fs"); var v;
276
+ process.platform === "win32" || global.TESTING_WINDOWS ? v = W() : v = X();
277
+ G.exports = y;
278
+ y.sync = Mt;
279
+ function y(t, e, n) {
280
+ if (typeof e == "function" && (n = e, e = {}), !n) {
281
+ if (typeof Promise != "function")
282
+ throw new TypeError("callback not provided");
283
+ return new Promise(function(r, s) {
284
+ y(t, e || {}, function(o, i) {
285
+ o ? s(o) : r(i);
286
+ });
287
+ });
288
+ }
289
+ v(t, e || {}, function(r, s) {
290
+ r && (r.code === "EACCES" || e && e.ignoreErrors) && (r = null, s = false), n(r, s);
291
+ });
292
+ }
293
+ __name$3(y, "y");
294
+ function Mt(t, e) {
295
+ try {
296
+ return v.sync(t, e || {});
297
+ } catch (n) {
298
+ if (e && e.ignoreErrors || n.code === "EACCES")
299
+ return false;
300
+ throw n;
301
+ }
302
+ }
303
+ __name$3(Mt, "Mt");
304
+ });
305
+ var et = l((Re, tt) => {
306
+ var g = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys", Y = h("path"), Bt = g ? ";" : ":", V = U(), J = /* @__PURE__ */ __name$3((t) => Object.assign(new Error(`not found: ${t}`), { code: "ENOENT" }), "J"), Q = /* @__PURE__ */ __name$3((t, e) => {
307
+ let n = e.colon || Bt, r = t.match(/\//) || g && t.match(/\\/) ? [""] : [
308
+ // windows always checks the cwd first
309
+ ...g ? [process.cwd()] : [],
310
+ ...(e.path || process.env.PATH || /* istanbul ignore next: very unusual */
311
+ "").split(n)
312
+ ], s = g ? e.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "", o = g ? s.split(n) : [""];
313
+ return g && t.indexOf(".") !== -1 && o[0] !== "" && o.unshift(""), {
314
+ pathEnv: r,
315
+ pathExt: o,
316
+ pathExtExe: s
317
+ };
318
+ }, "Q"), Z = /* @__PURE__ */ __name$3((t, e, n) => {
319
+ typeof e == "function" && (n = e, e = {}), e || (e = {});
320
+ let { pathEnv: r, pathExt: s, pathExtExe: o } = Q(t, e), i = [], a = /* @__PURE__ */ __name$3((u) => new Promise((f, p) => {
321
+ if (u === r.length)
322
+ return e.all && i.length ? f(i) : p(J(t));
323
+ 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;
324
+ f(c(b, u, 0));
325
+ }), "a"), c = /* @__PURE__ */ __name$3((u, f, p) => new Promise((d, w) => {
326
+ if (p === s.length)
327
+ return d(a(f + 1));
328
+ let m = s[p];
329
+ V(u + m, { pathExt: o }, (b, Ot) => {
330
+ if (!b && Ot)
331
+ if (e.all)
332
+ i.push(u + m);
333
+ else
334
+ return d(u + m);
335
+ return d(c(u, f, p + 1));
336
+ });
337
+ }), "c");
338
+ return n ? a(0).then((u) => n(null, u), n) : a(0);
339
+ }, "Z"), Xt = /* @__PURE__ */ __name$3((t, e) => {
340
+ e = e || {};
341
+ let { pathEnv: n, pathExt: r, pathExtExe: s } = Q(t, e), o = [];
342
+ for (let i = 0; i < n.length; i++) {
343
+ 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;
344
+ for (let p = 0; p < r.length; p++) {
345
+ let d = f + r[p];
346
+ try {
347
+ if (V.sync(d, { pathExt: s }))
348
+ if (e.all)
349
+ o.push(d);
350
+ else
351
+ return d;
352
+ } catch {
353
+ }
354
+ }
355
+ }
356
+ if (e.all && o.length)
357
+ return o;
358
+ if (e.nothrow)
359
+ return null;
360
+ throw J(t);
361
+ }, "Xt");
362
+ tt.exports = Z;
363
+ Z.sync = Xt;
364
+ });
365
+ var rt = l(($e, _) => {
366
+ var nt = /* @__PURE__ */ __name$3((t = {}) => {
367
+ let e = t.env || process.env;
368
+ return (t.platform || process.platform) !== "win32" ? "PATH" : Object.keys(e).reverse().find((r) => r.toUpperCase() === "PATH") || "Path";
369
+ }, "nt");
370
+ _.exports = nt;
371
+ _.exports.default = nt;
372
+ });
373
+ var ct = l((Ne, it) => {
374
+ var st = h("path"), Gt = et(), Ut = rt();
375
+ function ot(t, e) {
376
+ let n = t.options.env || process.env, r = process.cwd(), s = t.options.cwd != null, o = s && process.chdir !== void 0 && !process.chdir.disabled;
377
+ if (o)
378
+ try {
379
+ process.chdir(t.options.cwd);
380
+ } catch {
381
+ }
382
+ let i;
383
+ try {
384
+ i = Gt.sync(t.command, {
385
+ path: n[Ut({ env: n })],
386
+ pathExt: e ? st.delimiter : void 0
387
+ });
388
+ } catch {
389
+ } finally {
390
+ o && process.chdir(r);
391
+ }
392
+ return i && (i = st.resolve(s ? t.options.cwd : "", i)), i;
393
+ }
394
+ __name$3(ot, "ot");
395
+ function Yt(t) {
396
+ return ot(t) || ot(t, true);
397
+ }
398
+ __name$3(Yt, "Yt");
399
+ it.exports = Yt;
400
+ });
401
+ var ut = l((qe, P) => {
402
+ var C = /([()\][%!^"`<>&|;, *?])/g;
403
+ function Vt(t) {
404
+ return t = t.replace(C, "^$1"), t;
405
+ }
406
+ __name$3(Vt, "Vt");
407
+ function Jt(t, e) {
408
+ 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;
409
+ }
410
+ __name$3(Jt, "Jt");
411
+ P.exports.command = Vt;
412
+ P.exports.argument = Jt;
413
+ });
414
+ var lt = l((Ie, at) => {
415
+ at.exports = /^#!(.*)/;
416
+ });
417
+ var dt = l((Le, pt) => {
418
+ var Qt = lt();
419
+ pt.exports = (t = "") => {
420
+ let e = t.match(Qt);
421
+ if (!e)
422
+ return null;
423
+ let [n, r] = e[0].replace(/#! ?/, "").split(" "), s = n.split("/").pop();
424
+ return s === "env" ? r : r ? `${s} ${r}` : s;
425
+ };
426
+ });
427
+ var ht = l((je, ft) => {
428
+ var O = h("fs"), Zt = dt();
429
+ function te(t) {
430
+ let n = Buffer.alloc(150), r;
431
+ try {
432
+ r = O.openSync(t, "r"), O.readSync(r, n, 0, 150, 0), O.closeSync(r);
433
+ } catch {
434
+ }
435
+ return Zt(n.toString());
436
+ }
437
+ __name$3(te, "te");
438
+ ft.exports = te;
439
+ });
440
+ var wt = l((Fe, Et) => {
441
+ var ee = h("path"), mt = ct(), gt = ut(), ne = ht(), re = process.platform === "win32", se = /\.(?:com|exe)$/i, oe = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
442
+ function ie(t) {
443
+ t.file = mt(t);
444
+ let e = t.file && ne(t.file);
445
+ return e ? (t.args.unshift(t.file), t.command = e, mt(t)) : t.file;
446
+ }
447
+ __name$3(ie, "ie");
448
+ function ce(t) {
449
+ if (!re)
450
+ return t;
451
+ let e = ie(t), n = !se.test(e);
452
+ if (t.options.forceShell || n) {
453
+ let r = oe.test(e);
454
+ t.command = ee.normalize(t.command), t.command = gt.command(t.command), t.args = t.args.map((o) => gt.argument(o, r));
455
+ let s = [t.command].concat(t.args).join(" ");
456
+ t.args = ["/d", "/s", "/c", `"${s}"`], t.command = process.env.comspec || "cmd.exe", t.options.windowsVerbatimArguments = true;
457
+ }
458
+ return t;
459
+ }
460
+ __name$3(ce, "ce");
461
+ function ue(t, e, n) {
462
+ e && !Array.isArray(e) && (n = e, e = null), e = e ? e.slice(0) : [], n = Object.assign({}, n);
463
+ let r = {
464
+ command: t,
465
+ args: e,
466
+ options: n,
467
+ file: void 0,
468
+ original: {
469
+ command: t,
470
+ args: e
471
+ }
472
+ };
473
+ return n.shell ? r : ce(r);
474
+ }
475
+ __name$3(ue, "ue");
476
+ Et.exports = ue;
477
+ });
478
+ var bt = l((ze, vt) => {
479
+ var S = process.platform === "win32";
480
+ function k(t, e) {
481
+ return Object.assign(new Error(`${e} ${t.command} ENOENT`), {
482
+ code: "ENOENT",
483
+ errno: "ENOENT",
484
+ syscall: `${e} ${t.command}`,
485
+ path: t.command,
486
+ spawnargs: t.args
487
+ });
488
+ }
489
+ __name$3(k, "k");
490
+ function ae(t, e) {
491
+ if (!S)
492
+ return;
493
+ let n = t.emit;
494
+ t.emit = function(r, s) {
495
+ if (r === "exit") {
496
+ let o = xt(s, e);
497
+ if (o)
498
+ return n.call(t, "error", o);
499
+ }
500
+ return n.apply(t, arguments);
501
+ };
502
+ }
503
+ __name$3(ae, "ae");
504
+ function xt(t, e) {
505
+ return S && t === 1 && !e.file ? k(e.original, "spawn") : null;
506
+ }
507
+ __name$3(xt, "xt");
508
+ function le(t, e) {
509
+ return S && t === 1 && !e.file ? k(e.original, "spawnSync") : null;
510
+ }
511
+ __name$3(le, "le");
512
+ vt.exports = {
513
+ hookChildProcess: ae,
514
+ verifyENOENT: xt,
515
+ verifyENOENTSync: le,
516
+ notFoundError: k
517
+ };
518
+ });
519
+ var Ct = l((He, E) => {
520
+ var yt = h("child_process"), T = wt(), A = bt();
521
+ function _t(t, e, n) {
522
+ let r = T(t, e, n), s = yt.spawn(r.command, r.args, r.options);
523
+ return A.hookChildProcess(s, r), s;
524
+ }
525
+ __name$3(_t, "_t");
526
+ function pe(t, e, n) {
527
+ let r = T(t, e, n), s = yt.spawnSync(r.command, r.args, r.options);
528
+ return s.error = s.error || A.verifyENOENTSync(s.status, r), s;
529
+ }
530
+ __name$3(pe, "pe");
531
+ E.exports = _t;
532
+ E.exports.spawn = _t;
533
+ E.exports.sync = pe;
534
+ E.exports._parse = T;
535
+ E.exports._enoent = A;
536
+ });
537
+ var Lt = /^path$/i;
538
+ var q = { key: "PATH", value: "" };
539
+ function jt(t) {
540
+ for (let e in t) {
541
+ if (!Object.prototype.hasOwnProperty.call(t, e) || !Lt.test(e))
542
+ continue;
543
+ let n = t[e];
544
+ return n ? { key: e, value: n } : q;
545
+ }
546
+ return q;
547
+ }
548
+ __name$3(jt, "jt");
549
+ function Ft(t, e) {
550
+ let n = e.value.split(delimiter), r = t, s;
551
+ do
552
+ n.push(resolve(r, "node_modules", ".bin")), s = r, r = dirname(r);
553
+ while (r !== s);
554
+ return { key: e.key, value: n.join(delimiter) };
555
+ }
556
+ __name$3(Ft, "Ft");
557
+ function I(t, e) {
558
+ let n = {
559
+ ...process.env,
560
+ ...e
561
+ }, r = Ft(t, jt(n));
562
+ return n[r.key] = r.value, n;
563
+ }
564
+ __name$3(I, "I");
565
+ var L = /* @__PURE__ */ __name$3((t) => {
566
+ let e = t.length, n = new PassThrough(), r = /* @__PURE__ */ __name$3(() => {
567
+ --e === 0 && n.emit("end");
568
+ }, "r");
569
+ for (let s of t)
570
+ s.pipe(n, { end: false }), s.on("end", r);
571
+ return n;
572
+ }, "L");
573
+ var Pt = Nt(Ct(), 1);
574
+ var x = class extends Error {
575
+ static {
576
+ __name$3(this, "x");
577
+ }
578
+ result;
579
+ output;
580
+ get exitCode() {
581
+ if (this.result.exitCode !== null)
582
+ return this.result.exitCode;
583
+ }
584
+ constructor(e, n) {
585
+ super(`Process exited with non-zero status (${e.exitCode})`), this.result = e, this.output = n;
586
+ }
587
+ };
588
+ var ge = {
589
+ timeout: void 0,
590
+ persist: false
591
+ };
592
+ var Ee = {
593
+ windowsHide: true
594
+ };
595
+ function we(t, e) {
596
+ return {
597
+ command: normalize(t),
598
+ args: e ?? []
599
+ };
600
+ }
601
+ __name$3(we, "we");
602
+ function xe(t) {
603
+ let e = new AbortController();
604
+ for (let n of t) {
605
+ if (n.aborted)
606
+ return e.abort(), n;
607
+ let r = /* @__PURE__ */ __name$3(() => {
608
+ e.abort(n.reason);
609
+ }, "r");
610
+ n.addEventListener("abort", r, {
611
+ signal: e.signal
612
+ });
613
+ }
614
+ return e.signal;
615
+ }
616
+ __name$3(xe, "xe");
617
+ var R = class {
618
+ static {
619
+ __name$3(this, "R");
620
+ }
621
+ _process;
622
+ _aborted = false;
623
+ _options;
624
+ _command;
625
+ _args;
626
+ _resolveClose;
627
+ _processClosed;
628
+ _thrownError;
629
+ get process() {
630
+ return this._process;
631
+ }
632
+ get pid() {
633
+ return this._process?.pid;
634
+ }
635
+ get exitCode() {
636
+ if (this._process && this._process.exitCode !== null)
637
+ return this._process.exitCode;
638
+ }
639
+ constructor(e, n, r) {
640
+ this._options = {
641
+ ...ge,
642
+ ...r
643
+ }, this._command = e, this._args = n ?? [], this._processClosed = new Promise((s) => {
644
+ this._resolveClose = s;
645
+ });
646
+ }
647
+ kill(e) {
648
+ return this._process?.kill(e) === true;
649
+ }
650
+ get aborted() {
651
+ return this._aborted;
652
+ }
653
+ get killed() {
654
+ return this._process?.killed === true;
655
+ }
656
+ pipe(e, n, r) {
657
+ return be(e, n, {
658
+ ...r,
659
+ stdin: this
660
+ });
661
+ }
662
+ async *[Symbol.asyncIterator]() {
663
+ let e = this._process;
664
+ if (!e)
665
+ return;
666
+ let n = [];
667
+ this._streamErr && n.push(this._streamErr), this._streamOut && n.push(this._streamOut);
668
+ let r = L(n), s = me.createInterface({
669
+ input: r
670
+ });
671
+ for await (let o of s)
672
+ yield o.toString();
673
+ if (await this._processClosed, e.removeAllListeners(), this._thrownError)
674
+ throw this._thrownError;
675
+ if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0)
676
+ throw new x(this);
677
+ }
678
+ async _waitForOutput() {
679
+ let e = this._process;
680
+ if (!e)
681
+ throw new Error("No process was started");
682
+ let n = "", r = "";
683
+ if (this._streamOut)
684
+ for await (let o of this._streamOut)
685
+ r += o.toString();
686
+ if (this._streamErr)
687
+ for await (let o of this._streamErr)
688
+ n += o.toString();
689
+ if (await this._processClosed, this._options?.stdin && await this._options.stdin, e.removeAllListeners(), this._thrownError)
690
+ throw this._thrownError;
691
+ let s = {
692
+ stderr: n,
693
+ stdout: r,
694
+ exitCode: this.exitCode
695
+ };
696
+ if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0)
697
+ throw new x(this, s);
698
+ return s;
699
+ }
700
+ then(e, n) {
701
+ return this._waitForOutput().then(e, n);
702
+ }
703
+ _streamOut;
704
+ _streamErr;
705
+ spawn() {
706
+ let e = cwd(), n = this._options, r = {
707
+ ...Ee,
708
+ ...n.nodeOptions
709
+ }, s = [];
710
+ this._resetState(), n.timeout !== void 0 && s.push(AbortSignal.timeout(n.timeout)), n.signal !== void 0 && s.push(n.signal), n.persist === true && (r.detached = true), s.length > 0 && (r.signal = xe(s)), r.env = I(e, r.env);
711
+ let { command: o, args: i } = we(this._command, this._args), a = (0, Pt._parse)(o, i, r), c = spawn(
712
+ a.command,
713
+ a.args,
714
+ a.options
715
+ );
716
+ 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) {
717
+ let { stdout: u } = n.stdin.process;
718
+ u && u.pipe(c.stdin);
719
+ }
720
+ }
721
+ _resetState() {
722
+ this._aborted = false, this._processClosed = new Promise((e) => {
723
+ this._resolveClose = e;
724
+ }), this._thrownError = void 0;
725
+ }
726
+ _onError = /* @__PURE__ */ __name$3((e) => {
727
+ if (e.name === "AbortError" && (!(e.cause instanceof Error) || e.cause.name !== "TimeoutError")) {
728
+ this._aborted = true;
729
+ return;
730
+ }
731
+ this._thrownError = e;
732
+ }, "_onError");
733
+ _onClose = /* @__PURE__ */ __name$3(() => {
734
+ this._resolveClose && this._resolveClose();
735
+ }, "_onClose");
736
+ };
737
+ var ve = /* @__PURE__ */ __name$3((t, e, n) => {
738
+ let r = new R(t, e, n);
739
+ return r.spawn(), r;
740
+ }, "ve");
741
+ var be = ve;
742
+
743
+ var __defProp$2 = Object.defineProperty;
744
+ var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
745
+ async function detectPackageManager(cwd = process$1.cwd()) {
746
+ const result = await detect({
747
+ cwd,
748
+ onUnknown(packageManager) {
749
+ console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
750
+ return void 0;
751
+ }
752
+ });
753
+ return result?.agent || null;
754
+ }
755
+ __name$2(detectPackageManager, "detectPackageManager");
756
+ async function installPackage(names, options = {}) {
757
+ const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
758
+ const [agent] = detectedAgent.split("@");
759
+ if (!Array.isArray(names))
760
+ names = [names];
761
+ const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
762
+ if (options.preferOffline) {
763
+ if (detectedAgent === "yarn@berry")
764
+ args.unshift("--cached");
765
+ else
766
+ args.unshift("--prefer-offline");
767
+ }
768
+ if (agent === "pnpm") {
769
+ args.unshift(
770
+ /**
771
+ * Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`
772
+ * @see https://pnpm.io/cli/install#--prod--p
773
+ */
774
+ "--prod=false"
775
+ );
776
+ if (existsSync(resolve$1(options.cwd ?? process$1.cwd(), "pnpm-workspace.yaml"))) {
777
+ args.unshift("-w");
778
+ }
779
+ }
780
+ return ve(
781
+ agent,
782
+ [
783
+ agent === "yarn" ? "add" : "install",
784
+ options.dev ? "-D" : "",
785
+ ...args,
786
+ ...names
787
+ ].filter(Boolean),
788
+ {
789
+ nodeOptions: {
790
+ stdio: options.silent ? "ignore" : "inherit",
791
+ cwd: options.cwd
792
+ },
793
+ throwOnError: true
794
+ }
795
+ );
796
+ }
797
+ __name$2(installPackage, "installPackage");
798
+ async function uninstallPackage(names, options = {}) {
799
+ const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
800
+ const [agent] = detectedAgent.split("@");
801
+ if (!Array.isArray(names))
802
+ names = [names];
803
+ const args = options.additionalArgs || [];
804
+ if (agent === "pnpm" && existsSync(resolve$1(options.cwd ?? process$1.cwd(), "pnpm-workspace.yaml")))
805
+ args.unshift("-w");
806
+ return ve(
807
+ agent,
808
+ [
809
+ agent === "yarn" ? "remove" : "uninstall",
810
+ options.dev ? "-D" : "",
811
+ ...args,
812
+ ...names
813
+ ].filter(Boolean),
814
+ {
815
+ nodeOptions: {
816
+ stdio: options.silent ? "ignore" : "inherit",
817
+ cwd: options.cwd
818
+ },
819
+ throwOnError: true
820
+ }
821
+ );
822
+ }
823
+ __name$2(uninstallPackage, "uninstallPackage");
824
+
10
825
  var __defProp$1 = Object.defineProperty;
11
826
  var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
12
827
  const isObject = /* @__PURE__ */ __name$1((value) => {