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