@saasmakers/eslint 1.0.2 → 1.0.4

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.
Files changed (62) hide show
  1. package/dist/eslint.config.cjs +10905 -19
  2. package/dist/eslint.config.d.cts +1 -3874
  3. package/dist/eslint.config.d.mts +1 -3874
  4. package/dist/eslint.config.d.ts +1 -3874
  5. package/dist/eslint.config.mjs +10883 -18
  6. package/dist/index.cjs +9 -8
  7. package/dist/index.mjs +9 -8
  8. package/dist/shared/{eslint.C6EaTeQZ.mjs → eslint.CohBuu1-.mjs} +1 -34
  9. package/dist/shared/{eslint.Dxl4X46J.cjs → eslint.DhFjwkxh.cjs} +0 -37
  10. package/package.json +1 -2
  11. package/dist/chunks/formatters.cjs +0 -248
  12. package/dist/chunks/formatters.mjs +0 -246
  13. package/dist/chunks/import.cjs +0 -53
  14. package/dist/chunks/import.mjs +0 -51
  15. package/dist/chunks/index.cjs +0 -120
  16. package/dist/chunks/index.mjs +0 -101
  17. package/dist/chunks/index2.cjs +0 -880
  18. package/dist/chunks/index2.mjs +0 -868
  19. package/dist/chunks/index3.cjs +0 -982
  20. package/dist/chunks/index3.mjs +0 -979
  21. package/dist/chunks/index4.cjs +0 -12099
  22. package/dist/chunks/index4.mjs +0 -12077
  23. package/dist/chunks/jsdoc.cjs +0 -38398
  24. package/dist/chunks/jsdoc.mjs +0 -38391
  25. package/dist/chunks/regexp.cjs +0 -18518
  26. package/dist/chunks/regexp.mjs +0 -18511
  27. package/dist/chunks/stylistic.cjs +0 -23935
  28. package/dist/chunks/stylistic.mjs +0 -23932
  29. package/dist/chunks/typescript.cjs +0 -56168
  30. package/dist/chunks/typescript.mjs +0 -56154
  31. package/dist/chunks/unicorn.cjs +0 -82775
  32. package/dist/chunks/unicorn.mjs +0 -82764
  33. package/dist/chunks/vue.cjs +0 -96233
  34. package/dist/chunks/vue.mjs +0 -96220
  35. package/dist/shared/eslint.05nu4VbT.mjs +0 -9
  36. package/dist/shared/eslint.07qTxm9w.mjs +0 -3352
  37. package/dist/shared/eslint.6MAvpL4q.cjs +0 -2141
  38. package/dist/shared/eslint.7dipMixF.cjs +0 -14
  39. package/dist/shared/eslint.B6FFUbNC.mjs +0 -3814
  40. package/dist/shared/eslint.BGpVg2tt.cjs +0 -13
  41. package/dist/shared/eslint.BL4sYiVQ.cjs +0 -820
  42. package/dist/shared/eslint.BOOP2x9L.cjs +0 -67
  43. package/dist/shared/eslint.BXzpdiiq.mjs +0 -10
  44. package/dist/shared/eslint.Bl69eiyD.cjs +0 -7073
  45. package/dist/shared/eslint.BtkqW7nC.mjs +0 -818
  46. package/dist/shared/eslint.C12_M0Cw.cjs +0 -9
  47. package/dist/shared/eslint.COweQ1RR.mjs +0 -5
  48. package/dist/shared/eslint.CUi9znUC.mjs +0 -13
  49. package/dist/shared/eslint.Cg6Ty7p7.mjs +0 -2699
  50. package/dist/shared/eslint.CxAZpd0w.cjs +0 -3365
  51. package/dist/shared/eslint.DDD2xc4l.cjs +0 -25
  52. package/dist/shared/eslint.DI7QBrVD.mjs +0 -6
  53. package/dist/shared/eslint.DITpUYTO.mjs +0 -36955
  54. package/dist/shared/eslint.DP_6nQqR.cjs +0 -3822
  55. package/dist/shared/eslint.DUamuDzp.cjs +0 -7
  56. package/dist/shared/eslint.Difk5awg.mjs +0 -2139
  57. package/dist/shared/eslint.Dlgr3LGM.mjs +0 -7070
  58. package/dist/shared/eslint.DoYGbUIG.cjs +0 -2724
  59. package/dist/shared/eslint.Dprsk9zl.mjs +0 -65
  60. package/dist/shared/eslint.MfgVmFE7.cjs +0 -3054
  61. package/dist/shared/eslint.W7RM7aEw.mjs +0 -3052
  62. package/dist/shared/eslint.sHyLr4S9.cjs +0 -37003
@@ -1,880 +0,0 @@
1
- 'use strict';
2
-
3
- const process$1 = require('node:process');
4
- const fs = require('node:fs/promises');
5
- const path = require('node:path');
6
- const fs$1 = require('node:fs');
7
- const require$$6 = require('module');
8
- const node_child_process = require('node:child_process');
9
- const node_stream = require('node:stream');
10
- const k$1 = require('node:readline');
11
-
12
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
-
15
- const process__default = /*#__PURE__*/_interopDefaultCompat(process$1);
16
- const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
17
- const path__default = /*#__PURE__*/_interopDefaultCompat(path);
18
- const k__default = /*#__PURE__*/_interopDefaultCompat(k$1);
19
-
20
- const AGENTS = [
21
- "npm",
22
- "yarn",
23
- "yarn@berry",
24
- "pnpm",
25
- "pnpm@6",
26
- "bun",
27
- "deno"
28
- ];
29
- const LOCKS = {
30
- "bun.lock": "bun",
31
- "bun.lockb": "bun",
32
- "deno.lock": "deno",
33
- "pnpm-lock.yaml": "pnpm",
34
- "pnpm-workspace.yaml": "pnpm",
35
- "yarn.lock": "yarn",
36
- "package-lock.json": "npm",
37
- "npm-shrinkwrap.json": "npm"
38
- };
39
- const INSTALL_METADATA = {
40
- "node_modules/.deno/": "deno",
41
- "node_modules/.pnpm/": "pnpm",
42
- "node_modules/.yarn-state.yml": "yarn",
43
- // yarn v2+ (node-modules)
44
- "node_modules/.yarn_integrity": "yarn",
45
- // yarn v1
46
- "node_modules/.package-lock.json": "npm",
47
- ".pnp.cjs": "yarn",
48
- // yarn v3+ (pnp)
49
- ".pnp.js": "yarn",
50
- // yarn v2 (pnp)
51
- "bun.lock": "bun",
52
- "bun.lockb": "bun"
53
- };
54
-
55
- async function pathExists(path2, type) {
56
- try {
57
- const stat = await fs__default.stat(path2);
58
- return type === "file" ? stat.isFile() : stat.isDirectory();
59
- } catch {
60
- return false;
61
- }
62
- }
63
- function* lookup(cwd = process__default.cwd()) {
64
- let directory = path__default.resolve(cwd);
65
- const { root } = path__default.parse(directory);
66
- while (directory && directory !== root) {
67
- yield directory;
68
- directory = path__default.dirname(directory);
69
- }
70
- }
71
- async function parsePackageJson(filepath, onUnknown) {
72
- return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
73
- }
74
- async function detect(options = {}) {
75
- const {
76
- cwd,
77
- strategies = ["lockfile", "packageManager-field", "devEngines-field"],
78
- onUnknown
79
- } = options;
80
- let stopDir;
81
- if (typeof options.stopDir === "string") {
82
- const resolved = path__default.resolve(options.stopDir);
83
- stopDir = (dir) => dir === resolved;
84
- } else {
85
- stopDir = options.stopDir;
86
- }
87
- for (const directory of lookup(cwd)) {
88
- for (const strategy of strategies) {
89
- switch (strategy) {
90
- case "lockfile": {
91
- for (const lock of Object.keys(LOCKS)) {
92
- if (await pathExists(path__default.join(directory, lock), "file")) {
93
- const name = LOCKS[lock];
94
- const result = await parsePackageJson(path__default.join(directory, "package.json"), onUnknown);
95
- if (result)
96
- return result;
97
- else
98
- return { name, agent: name };
99
- }
100
- }
101
- break;
102
- }
103
- case "packageManager-field":
104
- case "devEngines-field": {
105
- const result = await parsePackageJson(path__default.join(directory, "package.json"), onUnknown);
106
- if (result)
107
- return result;
108
- break;
109
- }
110
- case "install-metadata": {
111
- for (const metadata of Object.keys(INSTALL_METADATA)) {
112
- const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
113
- if (await pathExists(path__default.join(directory, metadata), fileOrDir)) {
114
- const name = INSTALL_METADATA[metadata];
115
- const agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
116
- return { name, agent };
117
- }
118
- }
119
- break;
120
- }
121
- }
122
- }
123
- if (stopDir?.(directory))
124
- break;
125
- }
126
- return null;
127
- }
128
- function getNameAndVer(pkg) {
129
- const handelVer = (version) => version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
130
- if (typeof pkg.packageManager === "string") {
131
- const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
132
- return { name, ver: handelVer(ver) };
133
- }
134
- if (typeof pkg.devEngines?.packageManager?.name === "string") {
135
- return {
136
- name: pkg.devEngines.packageManager.name,
137
- ver: handelVer(pkg.devEngines.packageManager.version)
138
- };
139
- }
140
- return void 0;
141
- }
142
- async function handlePackageManager(filepath, onUnknown) {
143
- try {
144
- const pkg = JSON.parse(await fs__default.readFile(filepath, "utf8"));
145
- let agent;
146
- const nameAndVer = getNameAndVer(pkg);
147
- if (nameAndVer) {
148
- const name = nameAndVer.name;
149
- const ver = nameAndVer.ver;
150
- let version = ver;
151
- if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
152
- agent = "yarn@berry";
153
- version = "berry";
154
- return { name, agent, version };
155
- } else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
156
- agent = "pnpm@6";
157
- return { name, agent, version };
158
- } else if (AGENTS.includes(name)) {
159
- agent = name;
160
- return { name, agent, version };
161
- } else {
162
- return onUnknown?.(pkg.packageManager) ?? null;
163
- }
164
- }
165
- } catch {
166
- }
167
- return null;
168
- }
169
- function isMetadataYarnClassic(metadataPath) {
170
- return metadataPath.endsWith(".yarn_integrity");
171
- }
172
-
173
- var l = Object.create;
174
- var u = Object.defineProperty;
175
- var d = Object.getOwnPropertyDescriptor;
176
- var f = Object.getOwnPropertyNames;
177
- var p = Object.getPrototypeOf;
178
- var m = Object.prototype.hasOwnProperty;
179
- var h = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports);
180
- var g = (e, t, n, r) => {
181
- if (t && typeof t === "object" || typeof t === "function") for (var i = f(t), a = 0, o = i.length, s; a < o; a++) {
182
- s = i[a];
183
- if (!m.call(e, s) && s !== n) u(e, s, {
184
- get: ((e) => t[e]).bind(null, s),
185
- enumerable: !(r = d(t, s)) || r.enumerable
186
- });
187
- }
188
- return e;
189
- };
190
- var _ = (e, t, n) => (n = e != null ? l(p(e)) : {}, g(u(n, "default", {
191
- value: e,
192
- enumerable: true
193
- }) , e));
194
- var v = /* @__PURE__ */ require$$6.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunks/index2.cjs', document.baseURI).href)));
195
- const y = /^path$/i;
196
- const b = {
197
- key: "PATH",
198
- value: ""
199
- };
200
- function x(e) {
201
- for (const t in e) {
202
- if (!Object.prototype.hasOwnProperty.call(e, t) || !y.test(t)) continue;
203
- const n = e[t];
204
- if (!n) return b;
205
- return {
206
- key: t,
207
- value: n
208
- };
209
- }
210
- return b;
211
- }
212
- function S(e, t) {
213
- const i = t.value.split(path.delimiter);
214
- let o = e;
215
- let s;
216
- do {
217
- i.push(path.resolve(o, "node_modules", ".bin"));
218
- s = o;
219
- o = path.dirname(o);
220
- } while (o !== s);
221
- return {
222
- key: t.key,
223
- value: i.join(path.delimiter)
224
- };
225
- }
226
- function C(e, t) {
227
- const n = {
228
- ...process.env,
229
- ...t
230
- };
231
- const r = S(e, x(n));
232
- n[r.key] = r.value;
233
- return n;
234
- }
235
- const w = (e) => {
236
- let t = e.length;
237
- const n = new node_stream.PassThrough();
238
- const r = () => {
239
- if (--t === 0) n.emit("end");
240
- };
241
- for (const t of e) {
242
- t.pipe(n, { end: false });
243
- t.on("end", r);
244
- }
245
- return n;
246
- };
247
- var T = h((exports$1, t) => {
248
- t.exports = a;
249
- a.sync = o;
250
- var n = v("fs");
251
- function r(e, t) {
252
- var n = t.pathExt !== void 0 ? t.pathExt : process.env.PATHEXT;
253
- if (!n) return true;
254
- n = n.split(";");
255
- if (n.indexOf("") !== -1) return true;
256
- for (var r = 0; r < n.length; r++) {
257
- var i = n[r].toLowerCase();
258
- if (i && e.substr(-i.length).toLowerCase() === i) return true;
259
- }
260
- return false;
261
- }
262
- function i(e, t, n) {
263
- if (!e.isSymbolicLink() && !e.isFile()) return false;
264
- return r(t, n);
265
- }
266
- function a(e, t, r) {
267
- n.stat(e, function(n, a) {
268
- r(n, n ? false : i(a, e, t));
269
- });
270
- }
271
- function o(e, t) {
272
- return i(n.statSync(e), e, t);
273
- }
274
- });
275
- var E = h((exports$1, t) => {
276
- t.exports = r;
277
- r.sync = i;
278
- var n = v("fs");
279
- function r(e, t, r) {
280
- n.stat(e, function(e, n) {
281
- r(e, e ? false : a(n, t));
282
- });
283
- }
284
- function i(e, t) {
285
- return a(n.statSync(e), t);
286
- }
287
- function a(e, t) {
288
- return e.isFile() && o(e, t);
289
- }
290
- function o(e, t) {
291
- var n = e.mode;
292
- var r = e.uid;
293
- var i = e.gid;
294
- var a = t.uid !== void 0 ? t.uid : process.getuid && process.getuid();
295
- var o = t.gid !== void 0 ? t.gid : process.getgid && process.getgid();
296
- var s = parseInt("100", 8);
297
- var c = parseInt("010", 8);
298
- var l = parseInt("001", 8);
299
- var u = s | c;
300
- var d = n & l || n & c && i === o || n & s && r === a || n & u && a === 0;
301
- return d;
302
- }
303
- });
304
- var D = h((exports$1, t) => {
305
- v("fs");
306
- var r;
307
- if (process.platform === "win32" || global.TESTING_WINDOWS) r = T();
308
- else r = E();
309
- t.exports = i;
310
- i.sync = a;
311
- function i(e, t, n) {
312
- if (typeof t === "function") {
313
- n = t;
314
- t = {};
315
- }
316
- if (!n) {
317
- if (typeof Promise !== "function") throw new TypeError("callback not provided");
318
- return new Promise(function(n, r) {
319
- i(e, t || {}, function(e, t) {
320
- if (e) r(e);
321
- else n(t);
322
- });
323
- });
324
- }
325
- r(e, t || {}, function(e, r) {
326
- if (e) {
327
- if (e.code === "EACCES" || t && t.ignoreErrors) {
328
- e = null;
329
- r = false;
330
- }
331
- }
332
- n(e, r);
333
- });
334
- }
335
- function a(e, t) {
336
- try {
337
- return r.sync(e, t || {});
338
- } catch (e) {
339
- if (t && t.ignoreErrors || e.code === "EACCES") return false;
340
- else throw e;
341
- }
342
- }
343
- });
344
- var O = h((exports$1, t) => {
345
- const n = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
346
- const r = v("path");
347
- const i = n ? ";" : ":";
348
- const a = D();
349
- const o = (e) => Object.assign(new Error(`not found: ${e}`), { code: "ENOENT" });
350
- const s = (e, t) => {
351
- const r = t.colon || i;
352
- const a = e.match(/\//) || n && e.match(/\\/) ? [""] : [...n ? [process.cwd()] : [], ...(t.path || process.env.PATH || "").split(r)];
353
- const o = n ? t.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
354
- const s = n ? o.split(r) : [""];
355
- if (n) {
356
- if (e.indexOf(".") !== -1 && s[0] !== "") s.unshift("");
357
- }
358
- return {
359
- pathEnv: a,
360
- pathExt: s,
361
- pathExtExe: o
362
- };
363
- };
364
- const c = (e, t, n) => {
365
- if (typeof t === "function") {
366
- n = t;
367
- t = {};
368
- }
369
- if (!t) t = {};
370
- const { pathEnv: i, pathExt: c, pathExtExe: l } = s(e, t);
371
- const u = [];
372
- const d = (n) => new Promise((a, s) => {
373
- if (n === i.length) return t.all && u.length ? a(u) : s(o(e));
374
- const c = i[n];
375
- const l = /^".*"$/.test(c) ? c.slice(1, -1) : c;
376
- const d = r.join(l, e);
377
- const p = !l && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + d : d;
378
- a(f(p, n, 0));
379
- });
380
- const f = (e, n, r) => new Promise((i, o) => {
381
- if (r === c.length) return i(d(n + 1));
382
- const s = c[r];
383
- a(e + s, { pathExt: l }, (a, o) => {
384
- if (!a && o) if (t.all) u.push(e + s);
385
- else return i(e + s);
386
- return i(f(e, n, r + 1));
387
- });
388
- });
389
- return n ? d(0).then((e) => n(null, e), n) : d(0);
390
- };
391
- const l = (e, t) => {
392
- t = t || {};
393
- const { pathEnv: n, pathExt: i, pathExtExe: c } = s(e, t);
394
- const l = [];
395
- for (let o = 0; o < n.length; o++) {
396
- const s = n[o];
397
- const u = /^".*"$/.test(s) ? s.slice(1, -1) : s;
398
- const d = r.join(u, e);
399
- const f = !u && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + d : d;
400
- for (let e = 0; e < i.length; e++) {
401
- const n = f + i[e];
402
- try {
403
- const e = a.sync(n, { pathExt: c });
404
- if (e) if (t.all) l.push(n);
405
- else return n;
406
- } catch (e) {}
407
- }
408
- }
409
- if (t.all && l.length) return l;
410
- if (t.nothrow) return null;
411
- throw o(e);
412
- };
413
- t.exports = c;
414
- c.sync = l;
415
- });
416
- var k = h((exports$1, t) => {
417
- const n = (e = {}) => {
418
- const t = e.env || process.env;
419
- const n = e.platform || process.platform;
420
- if (n !== "win32") return "PATH";
421
- return Object.keys(t).reverse().find((e) => e.toUpperCase() === "PATH") || "Path";
422
- };
423
- t.exports = n;
424
- t.exports.default = n;
425
- });
426
- var A = h((exports$1, t) => {
427
- const n = v("path");
428
- const r = O();
429
- const i = k();
430
- function a(e, t) {
431
- const a = e.options.env || process.env;
432
- const o = process.cwd();
433
- const s = e.options.cwd != null;
434
- const c = s && process.chdir !== void 0 && !process.chdir.disabled;
435
- if (c) try {
436
- process.chdir(e.options.cwd);
437
- } catch (e) {}
438
- let l;
439
- try {
440
- l = r.sync(e.command, {
441
- path: a[i({ env: a })],
442
- pathExt: t ? n.delimiter : void 0
443
- });
444
- } catch (e) {} finally {
445
- if (c) process.chdir(o);
446
- }
447
- if (l) l = n.resolve(s ? e.options.cwd : "", l);
448
- return l;
449
- }
450
- function o(e) {
451
- return a(e) || a(e, true);
452
- }
453
- t.exports = o;
454
- });
455
- var j = h((exports$1, t) => {
456
- const n = /([()\][%!^"`<>&|;, *?])/g;
457
- function r(e) {
458
- e = e.replace(n, "^$1");
459
- return e;
460
- }
461
- function i(e, t) {
462
- e = `${e}`;
463
- e = e.replace(/(\\*)"/g, "$1$1\\\"");
464
- e = e.replace(/(\\*)$/, "$1$1");
465
- e = `"${e}"`;
466
- e = e.replace(n, "^$1");
467
- if (t) e = e.replace(n, "^$1");
468
- return e;
469
- }
470
- t.exports.command = r;
471
- t.exports.argument = i;
472
- });
473
- var M = h((exports$1, t) => {
474
- t.exports = /^#!(.*)/;
475
- });
476
- var N = h((exports$1, t) => {
477
- const n = M();
478
- t.exports = (e = "") => {
479
- const t = e.match(n);
480
- if (!t) return null;
481
- const [r, i] = t[0].replace(/#! ?/, "").split(" ");
482
- const a = r.split("/").pop();
483
- if (a === "env") return i;
484
- return i ? `${a} ${i}` : a;
485
- };
486
- });
487
- var P = h((exports$1, t) => {
488
- const n = v("fs");
489
- const r = N();
490
- function i(e) {
491
- const t = 150;
492
- const i = Buffer.alloc(t);
493
- let a;
494
- try {
495
- a = n.openSync(e, "r");
496
- n.readSync(a, i, 0, t, 0);
497
- n.closeSync(a);
498
- } catch (e) {}
499
- return r(i.toString());
500
- }
501
- t.exports = i;
502
- });
503
- var F = h((exports$1, t) => {
504
- const n = v("path");
505
- const r = A();
506
- const i = j();
507
- const a = P();
508
- const o = process.platform === "win32";
509
- const s = /\.(?:com|exe)$/i;
510
- const c = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
511
- function l(e) {
512
- e.file = r(e);
513
- const t = e.file && a(e.file);
514
- if (t) {
515
- e.args.unshift(e.file);
516
- e.command = t;
517
- return r(e);
518
- }
519
- return e.file;
520
- }
521
- function u(e) {
522
- if (!o) return e;
523
- const t = l(e);
524
- const r = !s.test(t);
525
- if (e.options.forceShell || r) {
526
- const r = c.test(t);
527
- e.command = n.normalize(e.command);
528
- e.command = i.command(e.command);
529
- e.args = e.args.map((e) => i.argument(e, r));
530
- const a = [e.command].concat(e.args).join(" ");
531
- e.args = [
532
- "/d",
533
- "/s",
534
- "/c",
535
- `"${a}"`
536
- ];
537
- e.command = process.env.comspec || "cmd.exe";
538
- e.options.windowsVerbatimArguments = true;
539
- }
540
- return e;
541
- }
542
- function d(e, t, n) {
543
- if (t && !Array.isArray(t)) {
544
- n = t;
545
- t = null;
546
- }
547
- t = t ? t.slice(0) : [];
548
- n = Object.assign({}, n);
549
- const r = {
550
- command: e,
551
- args: t,
552
- options: n,
553
- file: void 0,
554
- original: {
555
- command: e,
556
- args: t
557
- }
558
- };
559
- return n.shell ? r : u(r);
560
- }
561
- t.exports = d;
562
- });
563
- var I = h((exports$1, t) => {
564
- const n = process.platform === "win32";
565
- function r(e, t) {
566
- return Object.assign(new Error(`${t} ${e.command} ENOENT`), {
567
- code: "ENOENT",
568
- errno: "ENOENT",
569
- syscall: `${t} ${e.command}`,
570
- path: e.command,
571
- spawnargs: e.args
572
- });
573
- }
574
- function i(e, t) {
575
- if (!n) return;
576
- const r = e.emit;
577
- e.emit = function(n, i) {
578
- if (n === "exit") {
579
- const n = a(i, t);
580
- if (n) return r.call(e, "error", n);
581
- }
582
- return r.apply(e, arguments);
583
- };
584
- }
585
- function a(e, t) {
586
- if (n && e === 1 && !t.file) return r(t.original, "spawn");
587
- return null;
588
- }
589
- function o(e, t) {
590
- if (n && e === 1 && !t.file) return r(t.original, "spawnSync");
591
- return null;
592
- }
593
- t.exports = {
594
- hookChildProcess: i,
595
- verifyENOENT: a,
596
- verifyENOENTSync: o,
597
- notFoundError: r
598
- };
599
- });
600
- var L = h((exports$1, t) => {
601
- const n = v("child_process");
602
- const r = F();
603
- const i = I();
604
- function a(e, t, a) {
605
- const o = r(e, t, a);
606
- const s = n.spawn(o.command, o.args, o.options);
607
- i.hookChildProcess(s, o);
608
- return s;
609
- }
610
- function o(e, t, a) {
611
- const o = r(e, t, a);
612
- const s = n.spawnSync(o.command, o.args, o.options);
613
- s.error = s.error || i.verifyENOENTSync(s.status, o);
614
- return s;
615
- }
616
- t.exports = a;
617
- t.exports.spawn = a;
618
- t.exports.sync = o;
619
- t.exports._parse = r;
620
- t.exports._enoent = i;
621
- });
622
- var R = _(L());
623
- var z = class extends Error {
624
- result;
625
- output;
626
- get exitCode() {
627
- if (this.result.exitCode !== null) return this.result.exitCode;
628
- return void 0;
629
- }
630
- constructor(e, t) {
631
- super(`Process exited with non-zero status (${e.exitCode})`);
632
- this.result = e;
633
- this.output = t;
634
- }
635
- };
636
- const B = {
637
- timeout: void 0,
638
- persist: false
639
- };
640
- const V = { windowsHide: true };
641
- function H(e, t) {
642
- const n = path.normalize(e);
643
- const r = t ?? [];
644
- return {
645
- command: n,
646
- args: r
647
- };
648
- }
649
- function U(e) {
650
- const t = new AbortController();
651
- for (const n of e) {
652
- if (n.aborted) {
653
- t.abort();
654
- return n;
655
- }
656
- const e = () => {
657
- t.abort(n.reason);
658
- };
659
- n.addEventListener("abort", e, { signal: t.signal });
660
- }
661
- return t.signal;
662
- }
663
- async function W(e) {
664
- let t = "";
665
- for await (const n of e) t += n.toString();
666
- return t;
667
- }
668
- var G = class {
669
- _process;
670
- _aborted = false;
671
- _options;
672
- _command;
673
- _args;
674
- _resolveClose;
675
- _processClosed;
676
- _thrownError;
677
- get process() {
678
- return this._process;
679
- }
680
- get pid() {
681
- return this._process?.pid;
682
- }
683
- get exitCode() {
684
- if (this._process && this._process.exitCode !== null) return this._process.exitCode;
685
- return void 0;
686
- }
687
- constructor(e, t, n) {
688
- this._options = {
689
- ...B,
690
- ...n
691
- };
692
- this._command = e;
693
- this._args = t ?? [];
694
- this._processClosed = new Promise((e) => {
695
- this._resolveClose = e;
696
- });
697
- }
698
- kill(e) {
699
- return this._process?.kill(e) === true;
700
- }
701
- get aborted() {
702
- return this._aborted;
703
- }
704
- get killed() {
705
- return this._process?.killed === true;
706
- }
707
- pipe(e, t, n) {
708
- return q(e, t, {
709
- ...n,
710
- stdin: this
711
- });
712
- }
713
- async *[Symbol.asyncIterator]() {
714
- const e = this._process;
715
- if (!e) return;
716
- const t = [];
717
- if (this._streamErr) t.push(this._streamErr);
718
- if (this._streamOut) t.push(this._streamOut);
719
- const n = w(t);
720
- const r = k__default.createInterface({ input: n });
721
- for await (const e of r) yield e.toString();
722
- await this._processClosed;
723
- e.removeAllListeners();
724
- if (this._thrownError) throw this._thrownError;
725
- if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) throw new z(this);
726
- }
727
- async _waitForOutput() {
728
- const e = this._process;
729
- if (!e) throw new Error("No process was started");
730
- const [t, n] = await Promise.all([this._streamOut ? W(this._streamOut) : "", this._streamErr ? W(this._streamErr) : ""]);
731
- await this._processClosed;
732
- if (this._options?.stdin) await this._options.stdin;
733
- e.removeAllListeners();
734
- if (this._thrownError) throw this._thrownError;
735
- const r = {
736
- stderr: n,
737
- stdout: t,
738
- exitCode: this.exitCode
739
- };
740
- if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) throw new z(this, r);
741
- return r;
742
- }
743
- then(e, t) {
744
- return this._waitForOutput().then(e, t);
745
- }
746
- _streamOut;
747
- _streamErr;
748
- spawn() {
749
- const e = process$1.cwd();
750
- const n = this._options;
751
- const r = {
752
- ...V,
753
- ...n.nodeOptions
754
- };
755
- const i = [];
756
- this._resetState();
757
- if (n.timeout !== void 0) i.push(AbortSignal.timeout(n.timeout));
758
- if (n.signal !== void 0) i.push(n.signal);
759
- if (n.persist === true) r.detached = true;
760
- if (i.length > 0) r.signal = U(i);
761
- r.env = C(e, r.env);
762
- const { command: a, args: s } = H(this._command, this._args);
763
- const c = (0, R._parse)(a, s, r);
764
- const l = node_child_process.spawn(c.command, c.args, c.options);
765
- if (l.stderr) this._streamErr = l.stderr;
766
- if (l.stdout) this._streamOut = l.stdout;
767
- this._process = l;
768
- l.once("error", this._onError);
769
- l.once("close", this._onClose);
770
- if (n.stdin !== void 0 && l.stdin && n.stdin.process) {
771
- const { stdout: e } = n.stdin.process;
772
- if (e) e.pipe(l.stdin);
773
- }
774
- }
775
- _resetState() {
776
- this._aborted = false;
777
- this._processClosed = new Promise((e) => {
778
- this._resolveClose = e;
779
- });
780
- this._thrownError = void 0;
781
- }
782
- _onError = (e) => {
783
- if (e.name === "AbortError" && (!(e.cause instanceof Error) || e.cause.name !== "TimeoutError")) {
784
- this._aborted = true;
785
- return;
786
- }
787
- this._thrownError = e;
788
- };
789
- _onClose = () => {
790
- if (this._resolveClose) this._resolveClose();
791
- };
792
- };
793
- const K = (e, t, n) => {
794
- const r = new G(e, t, n);
795
- r.spawn();
796
- return r;
797
- };
798
- const q = K;
799
-
800
- // src/detect.ts
801
- async function detectPackageManager(cwd = process__default.cwd()) {
802
- const result = await detect({
803
- cwd,
804
- onUnknown(packageManager) {
805
- console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
806
- return void 0;
807
- }
808
- });
809
- return result?.agent || null;
810
- }
811
- async function installPackage(names, options = {}) {
812
- const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
813
- const [agent] = detectedAgent.split("@");
814
- if (!Array.isArray(names))
815
- names = [names];
816
- const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
817
- if (options.preferOffline) {
818
- if (detectedAgent === "yarn@berry")
819
- args.unshift("--cached");
820
- else
821
- args.unshift("--prefer-offline");
822
- }
823
- if (agent === "pnpm") {
824
- args.unshift(
825
- /**
826
- * Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`
827
- * @see https://pnpm.io/cli/install#--prod--p
828
- */
829
- "--prod=false"
830
- );
831
- if (fs$1.existsSync(path.resolve(options.cwd ?? process__default.cwd(), "pnpm-workspace.yaml"))) {
832
- args.unshift("-w");
833
- }
834
- }
835
- return K(
836
- agent,
837
- [
838
- agent === "yarn" ? "add" : "install",
839
- options.dev ? "-D" : "",
840
- ...args,
841
- ...names
842
- ].filter(Boolean),
843
- {
844
- nodeOptions: {
845
- stdio: options.silent ? "ignore" : "inherit",
846
- cwd: options.cwd
847
- },
848
- throwOnError: true
849
- }
850
- );
851
- }
852
- async function uninstallPackage(names, options = {}) {
853
- const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
854
- const [agent] = detectedAgent.split("@");
855
- if (!Array.isArray(names))
856
- names = [names];
857
- const args = options.additionalArgs || [];
858
- if (agent === "pnpm" && fs$1.existsSync(path.resolve(options.cwd ?? process__default.cwd(), "pnpm-workspace.yaml")))
859
- args.unshift("-w");
860
- return K(
861
- agent,
862
- [
863
- agent === "yarn" ? "remove" : "uninstall",
864
- options.dev ? "-D" : "",
865
- ...args,
866
- ...names
867
- ].filter(Boolean),
868
- {
869
- nodeOptions: {
870
- stdio: options.silent ? "ignore" : "inherit",
871
- cwd: options.cwd
872
- },
873
- throwOnError: true
874
- }
875
- );
876
- }
877
-
878
- exports.detectPackageManager = detectPackageManager;
879
- exports.installPackage = installPackage;
880
- exports.uninstallPackage = uninstallPackage;