@redocly/cli 2.41.2 → 2.42.0

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 (73) hide show
  1. package/README.md +15 -0
  2. package/THIRD_PARTY_NOTICES +3 -2
  3. package/lib/chunks/32XCOMOR.js +7 -0
  4. package/lib/chunks/4S2W4DOH.js +7 -0
  5. package/lib/chunks/55GMSQDD.js +7 -0
  6. package/lib/chunks/62KMHHXM.js +93 -0
  7. package/lib/chunks/7J6QXKSL.js +59 -0
  8. package/lib/chunks/7TEHO26G.js +3132 -0
  9. package/lib/chunks/AE6JGTY4.js +7 -0
  10. package/lib/chunks/B62AKN6U.js +7 -0
  11. package/lib/chunks/BZ7PKRCP.js +2317 -0
  12. package/lib/chunks/D5T6ETPZ.js +8 -0
  13. package/lib/chunks/DNYSY7SK.js +8 -0
  14. package/lib/chunks/E2UJUSIU.js +11 -0
  15. package/lib/chunks/ECZUPR2N.js +7 -0
  16. package/lib/chunks/EU6GURJZ.js +7 -0
  17. package/lib/chunks/F4DGJH6G.js +8 -0
  18. package/lib/chunks/GELB6SHC.js +22 -0
  19. package/lib/chunks/HJ6KJBQG.js +9 -0
  20. package/lib/chunks/HXR6INJN.js +22 -0
  21. package/lib/chunks/IP2FG3VC.js +19 -0
  22. package/lib/chunks/KLY5RV3W.js +7 -0
  23. package/lib/chunks/LSG6IYBM.js +47 -0
  24. package/lib/chunks/NEWT5A6S.js +159 -0
  25. package/lib/chunks/O6MCQRCP.js +59 -0
  26. package/lib/chunks/O6PRCLSV.js +13 -0
  27. package/lib/chunks/OFAMJNQ6.js +7 -0
  28. package/lib/chunks/P26PQ2RU.js +7 -0
  29. package/lib/chunks/QQOKWPJZ.js +184 -0
  30. package/lib/chunks/RFWIIJFG.js +7 -0
  31. package/lib/chunks/RS5PUOTT.js +18 -0
  32. package/lib/chunks/SPVQTYE2.js +7 -0
  33. package/lib/chunks/TXOARWFE.js +7 -0
  34. package/lib/chunks/UPPWQBGX.js +7 -0
  35. package/lib/chunks/UYZXI3NO.js +7 -0
  36. package/lib/chunks/WZXA5XPB.js +7 -0
  37. package/lib/chunks/XYO6U5CE.js +31 -0
  38. package/lib/chunks/ZGSJFP2Z.js +8 -0
  39. package/lib/index.js +226 -13885
  40. package/package.json +1 -1
  41. package/lib/chunks/3CX2Z7JI.js +0 -496
  42. package/lib/chunks/3UUTQVCJ.js +0 -3614
  43. package/lib/chunks/4FB5ZIPP.js +0 -1133
  44. package/lib/chunks/5ILQMFXK.js +0 -59
  45. package/lib/chunks/7F5O43EU.js +0 -1756
  46. package/lib/chunks/7IX44JLO.js +0 -16
  47. package/lib/chunks/7MOL2QVN.js +0 -92635
  48. package/lib/chunks/A3VFVVHD.js +0 -25
  49. package/lib/chunks/A6JSOHCP.js +0 -41
  50. package/lib/chunks/AIT3U3JT.js +0 -22
  51. package/lib/chunks/ASYQPOQY.js +0 -681
  52. package/lib/chunks/BVP23YP7.js +0 -13374
  53. package/lib/chunks/FO6BDVGE.js +0 -25
  54. package/lib/chunks/GFU5KGSW.js +0 -92
  55. package/lib/chunks/ICPYP2LP.js +0 -401
  56. package/lib/chunks/KPMZLKQG.js +0 -79
  57. package/lib/chunks/KRMBH6JF.js +0 -17902
  58. package/lib/chunks/NLIKC7UP.js +0 -528
  59. package/lib/chunks/NW3XJZXQ.js +0 -175
  60. package/lib/chunks/P6UGG7F6.js +0 -414
  61. package/lib/chunks/RRC5IDC3.js +0 -2416
  62. package/lib/chunks/T6UZU3XM.js +0 -17
  63. package/lib/chunks/TS33ZDKX.js +0 -35
  64. package/lib/chunks/UUU33DK3.js +0 -125
  65. package/lib/chunks/VUDTNFRL.js +0 -42
  66. package/lib/chunks/VXIQEZPR.js +0 -2564
  67. package/lib/chunks/W7G5WVPB.js +0 -44
  68. package/lib/chunks/XB6C62FW.js +0 -18497
  69. package/lib/chunks/XHPY6UJF.js +0 -1638
  70. package/lib/chunks/Y6DTFCLS.js +0 -15
  71. package/lib/chunks/Z2664VV5.js +0 -39331
  72. package/lib/chunks/Z2I5YXYN.js +0 -20272
  73. package/lib/chunks/ZK3QRKL5.js +0 -129
@@ -1,3614 +0,0 @@
1
- import { createRequire as __createRequire } from 'node:module';
2
- const require = __createRequire(import.meta.url);
3
- import {
4
- AbortFlowError,
5
- exitWithError
6
- } from "./T6UZU3XM.js";
7
- import {
8
- ConfigValidationError,
9
- HandledError,
10
- ResolveError,
11
- YamlParseError,
12
- blue,
13
- formatProblems,
14
- getTotals,
15
- gray,
16
- green,
17
- isAbsoluteUrl,
18
- isEmptyObject,
19
- isNotEmptyArray,
20
- isNotEmptyObject,
21
- lint,
22
- lintConfig,
23
- loadConfig,
24
- logger,
25
- parseYaml,
26
- pluralize,
27
- red,
28
- stringifyYaml,
29
- yellow
30
- } from "./Z2664VV5.js";
31
-
32
- // src/commands/lint.ts
33
- import { performance as performance3 } from "perf_hooks";
34
-
35
- // src/utils/get-command-name-from-args.ts
36
- function getCommandNameFromArgs(argv) {
37
- return argv?._?.[0] ?? "";
38
- }
39
-
40
- // ../../node_modules/glob/dist/esm/index.min.js
41
- import { fileURLToPath as Wi } from "node:url";
42
- import { posix as mi, win32 as re } from "node:path";
43
- import { fileURLToPath as gi } from "node:url";
44
- import { lstatSync as wi, readdir as yi, readdirSync as bi, readlinkSync as Si, realpathSync as Ei } from "fs";
45
- import * as xi from "node:fs";
46
- import { lstat as Ci, readdir as Ti, readlink as Ai, realpath as ki } from "node:fs/promises";
47
- import { EventEmitter as ee } from "node:events";
48
- import Pe from "node:stream";
49
- import { StringDecoder as ni } from "node:string_decoder";
50
- var Gt = (n7, t, e) => {
51
- let s = n7 instanceof RegExp ? ce(n7, e) : n7, i = t instanceof RegExp ? ce(t, e) : t, r = s !== null && i != null && ss(s, i, e);
52
- return r && { start: r[0], end: r[1], pre: e.slice(0, r[0]), body: e.slice(r[0] + s.length, r[1]), post: e.slice(r[1] + i.length) };
53
- };
54
- var ce = (n7, t) => {
55
- let e = t.match(n7);
56
- return e ? e[0] : null;
57
- };
58
- var ss = (n7, t, e) => {
59
- let s, i, r, o, h, a = e.indexOf(n7), l = e.indexOf(t, a + 1), u = a;
60
- if (a >= 0 && l > 0) {
61
- if (n7 === t) return [a, l];
62
- for (s = [], r = e.length; u >= 0 && !h; ) {
63
- if (u === a) s.push(u), a = e.indexOf(n7, u + 1);
64
- else if (s.length === 1) {
65
- let c = s.pop();
66
- c !== void 0 && (h = [c, l]);
67
- } else i = s.pop(), i !== void 0 && i < r && (r = i, o = l), l = e.indexOf(t, u + 1);
68
- u = a < l && a >= 0 ? a : l;
69
- }
70
- s.length && o !== void 0 && (h = [r, o]);
71
- }
72
- return h;
73
- };
74
- var fe = "\0SLASH" + Math.random() + "\0";
75
- var ue = "\0OPEN" + Math.random() + "\0";
76
- var qt = "\0CLOSE" + Math.random() + "\0";
77
- var de = "\0COMMA" + Math.random() + "\0";
78
- var pe = "\0PERIOD" + Math.random() + "\0";
79
- var is = new RegExp(fe, "g");
80
- var rs = new RegExp(ue, "g");
81
- var ns = new RegExp(qt, "g");
82
- var os = new RegExp(de, "g");
83
- var hs = new RegExp(pe, "g");
84
- var as = /\\\\/g;
85
- var ls = /\\{/g;
86
- var cs = /\\}/g;
87
- var fs = /\\,/g;
88
- var us = /\\./g;
89
- var ds = 1e5;
90
- function Ht(n7) {
91
- return isNaN(n7) ? n7.charCodeAt(0) : parseInt(n7, 10);
92
- }
93
- function ps(n7) {
94
- return n7.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs, de).replace(us, pe);
95
- }
96
- function ms(n7) {
97
- return n7.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os, ",").replace(hs, ".");
98
- }
99
- function me(n7) {
100
- if (!n7) return [""];
101
- let t = [], e = Gt("{", "}", n7);
102
- if (!e) return n7.split(",");
103
- let { pre: s, body: i, post: r } = e, o = s.split(",");
104
- o[o.length - 1] += "{" + i + "}";
105
- let h = me(r);
106
- return r.length && (o[o.length - 1] += h.shift(), o.push.apply(o, h)), t.push.apply(t, o), t;
107
- }
108
- function ge(n7, t = {}) {
109
- if (!n7) return [];
110
- let { max: e = ds } = t;
111
- return n7.slice(0, 2) === "{}" && (n7 = "\\{\\}" + n7.slice(2)), ht(ps(n7), e, true).map(ms);
112
- }
113
- function gs(n7) {
114
- return "{" + n7 + "}";
115
- }
116
- function ws(n7) {
117
- return /^-?0\d/.test(n7);
118
- }
119
- function ys(n7, t) {
120
- return n7 <= t;
121
- }
122
- function bs(n7, t) {
123
- return n7 >= t;
124
- }
125
- function ht(n7, t, e) {
126
- let s = [], i = Gt("{", "}", n7);
127
- if (!i) return [n7];
128
- let r = i.pre, o = i.post.length ? ht(i.post, t, false) : [""];
129
- if (/\$$/.test(i.pre)) for (let h = 0; h < o.length && h < t; h++) {
130
- let a = r + "{" + i.body + "}" + o[h];
131
- s.push(a);
132
- }
133
- else {
134
- let h = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body), l = h || a, u = i.body.indexOf(",") >= 0;
135
- if (!l && !u) return i.post.match(/,(?!,).*\}/) ? (n7 = i.pre + "{" + i.body + qt + i.post, ht(n7, t, true)) : [n7];
136
- let c;
137
- if (l) c = i.body.split(/\.\./);
138
- else if (c = me(i.body), c.length === 1 && c[0] !== void 0 && (c = ht(c[0], t, false).map(gs), c.length === 1)) return o.map((f) => i.pre + c[0] + f);
139
- let d;
140
- if (l && c[0] !== void 0 && c[1] !== void 0) {
141
- let f = Ht(c[0]), m = Ht(c[1]), p = Math.max(c[0].length, c[1].length), w = c.length === 3 && c[2] !== void 0 ? Math.abs(Ht(c[2])) : 1, g = ys;
142
- m < f && (w *= -1, g = bs);
143
- let E = c.some(ws);
144
- d = [];
145
- for (let y = f; g(y, m); y += w) {
146
- let b;
147
- if (a) b = String.fromCharCode(y), b === "\\" && (b = "");
148
- else if (b = String(y), E) {
149
- let z = p - b.length;
150
- if (z > 0) {
151
- let $ = new Array(z + 1).join("0");
152
- y < 0 ? b = "-" + $ + b.slice(1) : b = $ + b;
153
- }
154
- }
155
- d.push(b);
156
- }
157
- } else {
158
- d = [];
159
- for (let f = 0; f < c.length; f++) d.push.apply(d, ht(c[f], t, false));
160
- }
161
- for (let f = 0; f < d.length; f++) for (let m = 0; m < o.length && s.length < t; m++) {
162
- let p = r + d[f] + o[m];
163
- (!e || l || p) && s.push(p);
164
- }
165
- }
166
- return s;
167
- }
168
- var at = (n7) => {
169
- if (typeof n7 != "string") throw new TypeError("invalid pattern");
170
- if (n7.length > 65536) throw new TypeError("pattern is too long");
171
- };
172
- var Ss = { "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true], "[:alpha:]": ["\\p{L}\\p{Nl}", true], "[:ascii:]": ["\\x00-\\x7f", false], "[:blank:]": ["\\p{Zs}\\t", true], "[:cntrl:]": ["\\p{Cc}", true], "[:digit:]": ["\\p{Nd}", true], "[:graph:]": ["\\p{Z}\\p{C}", true, true], "[:lower:]": ["\\p{Ll}", true], "[:print:]": ["\\p{C}", true], "[:punct:]": ["\\p{P}", true], "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true], "[:upper:]": ["\\p{Lu}", true], "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true], "[:xdigit:]": ["A-Fa-f0-9", false] };
173
- var lt = (n7) => n7.replace(/[[\]\\-]/g, "\\$&");
174
- var Es = (n7) => n7.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
175
- var we = (n7) => n7.join("");
176
- var ye = (n7, t) => {
177
- let e = t;
178
- if (n7.charAt(e) !== "[") throw new Error("not in a brace expression");
179
- let s = [], i = [], r = e + 1, o = false, h = false, a = false, l = false, u = e, c = "";
180
- t: for (; r < n7.length; ) {
181
- let p = n7.charAt(r);
182
- if ((p === "!" || p === "^") && r === e + 1) {
183
- l = true, r++;
184
- continue;
185
- }
186
- if (p === "]" && o && !a) {
187
- u = r + 1;
188
- break;
189
- }
190
- if (o = true, p === "\\" && !a) {
191
- a = true, r++;
192
- continue;
193
- }
194
- if (p === "[" && !a) {
195
- for (let [w, [g, S, E]] of Object.entries(Ss)) if (n7.startsWith(w, r)) {
196
- if (c) return ["$.", false, n7.length - e, true];
197
- r += w.length, E ? i.push(g) : s.push(g), h = h || S;
198
- continue t;
199
- }
200
- }
201
- if (a = false, c) {
202
- p > c ? s.push(lt(c) + "-" + lt(p)) : p === c && s.push(lt(p)), c = "", r++;
203
- continue;
204
- }
205
- if (n7.startsWith("-]", r + 1)) {
206
- s.push(lt(p + "-")), r += 2;
207
- continue;
208
- }
209
- if (n7.startsWith("-", r + 1)) {
210
- c = p, r += 2;
211
- continue;
212
- }
213
- s.push(lt(p)), r++;
214
- }
215
- if (u < r) return ["", false, 0, false];
216
- if (!s.length && !i.length) return ["$.", false, n7.length - e, true];
217
- if (i.length === 0 && s.length === 1 && /^\\?.$/.test(s[0]) && !l) {
218
- let p = s[0].length === 2 ? s[0].slice(-1) : s[0];
219
- return [Es(p), false, u - e, false];
220
- }
221
- let d = "[" + (l ? "^" : "") + we(s) + "]", f = "[" + (l ? "" : "^") + we(i) + "]";
222
- return [s.length && i.length ? "(" + d + "|" + f + ")" : s.length ? d : f, h, u - e, true];
223
- };
224
- var W = (n7, { windowsPathsNoEscape: t = false, magicalBraces: e = true } = {}) => e ? t ? n7.replace(/\[([^\/\\])\]/g, "$1") : n7.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1") : t ? n7.replace(/\[([^\/\\{}])\]/g, "$1") : n7.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, "$1$2").replace(/\\([^\/{}])/g, "$1");
225
- var xs = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
226
- var be = (n7) => xs.has(n7);
227
- var vs = "(?!(?:^|/)\\.\\.?(?:$|/))";
228
- var Ct = "(?!\\.)";
229
- var Cs = /* @__PURE__ */ new Set(["[", "."]);
230
- var Ts = /* @__PURE__ */ new Set(["..", "."]);
231
- var As = new Set("().*{}+?[]^$\\!");
232
- var ks = (n7) => n7.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
233
- var Kt = "[^/]";
234
- var Se = Kt + "*?";
235
- var Ee = Kt + "+?";
236
- var Q = class n {
237
- type;
238
- #t;
239
- #s;
240
- #n = false;
241
- #r = [];
242
- #o;
243
- #S;
244
- #w;
245
- #c = false;
246
- #h;
247
- #u;
248
- #f = false;
249
- constructor(t, e, s = {}) {
250
- this.type = t, t && (this.#s = true), this.#o = e, this.#t = this.#o ? this.#o.#t : this, this.#h = this.#t === this ? s : this.#t.#h, this.#w = this.#t === this ? [] : this.#t.#w, t === "!" && !this.#t.#c && this.#w.push(this), this.#S = this.#o ? this.#o.#r.length : 0;
251
- }
252
- get hasMagic() {
253
- if (this.#s !== void 0) return this.#s;
254
- for (let t of this.#r) if (typeof t != "string" && (t.type || t.hasMagic)) return this.#s = true;
255
- return this.#s;
256
- }
257
- toString() {
258
- return this.#u !== void 0 ? this.#u : this.type ? this.#u = this.type + "(" + this.#r.map((t) => String(t)).join("|") + ")" : this.#u = this.#r.map((t) => String(t)).join("");
259
- }
260
- #a() {
261
- if (this !== this.#t) throw new Error("should only call on root");
262
- if (this.#c) return this;
263
- this.toString(), this.#c = true;
264
- let t;
265
- for (; t = this.#w.pop(); ) {
266
- if (t.type !== "!") continue;
267
- let e = t, s = e.#o;
268
- for (; s; ) {
269
- for (let i = e.#S + 1; !s.type && i < s.#r.length; i++) for (let r of t.#r) {
270
- if (typeof r == "string") throw new Error("string part in extglob AST??");
271
- r.copyIn(s.#r[i]);
272
- }
273
- e = s, s = e.#o;
274
- }
275
- }
276
- return this;
277
- }
278
- push(...t) {
279
- for (let e of t) if (e !== "") {
280
- if (typeof e != "string" && !(e instanceof n && e.#o === this)) throw new Error("invalid part: " + e);
281
- this.#r.push(e);
282
- }
283
- }
284
- toJSON() {
285
- let t = this.type === null ? this.#r.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#r.map((e) => e.toJSON())];
286
- return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#t || this.#t.#c && this.#o?.type === "!") && t.push({}), t;
287
- }
288
- isStart() {
289
- if (this.#t === this) return true;
290
- if (!this.#o?.isStart()) return false;
291
- if (this.#S === 0) return true;
292
- let t = this.#o;
293
- for (let e = 0; e < this.#S; e++) {
294
- let s = t.#r[e];
295
- if (!(s instanceof n && s.type === "!")) return false;
296
- }
297
- return true;
298
- }
299
- isEnd() {
300
- if (this.#t === this || this.#o?.type === "!") return true;
301
- if (!this.#o?.isEnd()) return false;
302
- if (!this.type) return this.#o?.isEnd();
303
- let t = this.#o ? this.#o.#r.length : 0;
304
- return this.#S === t - 1;
305
- }
306
- copyIn(t) {
307
- typeof t == "string" ? this.push(t) : this.push(t.clone(this));
308
- }
309
- clone(t) {
310
- let e = new n(this.type, t);
311
- for (let s of this.#r) e.copyIn(s);
312
- return e;
313
- }
314
- static #i(t, e, s, i) {
315
- let r = false, o = false, h = -1, a = false;
316
- if (e.type === null) {
317
- let f = s, m = "";
318
- for (; f < t.length; ) {
319
- let p = t.charAt(f++);
320
- if (r || p === "\\") {
321
- r = !r, m += p;
322
- continue;
323
- }
324
- if (o) {
325
- f === h + 1 ? (p === "^" || p === "!") && (a = true) : p === "]" && !(f === h + 2 && a) && (o = false), m += p;
326
- continue;
327
- } else if (p === "[") {
328
- o = true, h = f, a = false, m += p;
329
- continue;
330
- }
331
- if (!i.noext && be(p) && t.charAt(f) === "(") {
332
- e.push(m), m = "";
333
- let w = new n(p, e);
334
- f = n.#i(t, w, f, i), e.push(w);
335
- continue;
336
- }
337
- m += p;
338
- }
339
- return e.push(m), f;
340
- }
341
- let l = s + 1, u = new n(null, e), c = [], d = "";
342
- for (; l < t.length; ) {
343
- let f = t.charAt(l++);
344
- if (r || f === "\\") {
345
- r = !r, d += f;
346
- continue;
347
- }
348
- if (o) {
349
- l === h + 1 ? (f === "^" || f === "!") && (a = true) : f === "]" && !(l === h + 2 && a) && (o = false), d += f;
350
- continue;
351
- } else if (f === "[") {
352
- o = true, h = l, a = false, d += f;
353
- continue;
354
- }
355
- if (be(f) && t.charAt(l) === "(") {
356
- u.push(d), d = "";
357
- let m = new n(f, u);
358
- u.push(m), l = n.#i(t, m, l, i);
359
- continue;
360
- }
361
- if (f === "|") {
362
- u.push(d), d = "", c.push(u), u = new n(null, e);
363
- continue;
364
- }
365
- if (f === ")") return d === "" && e.#r.length === 0 && (e.#f = true), u.push(d), d = "", e.push(...c, u), l;
366
- d += f;
367
- }
368
- return e.type = null, e.#s = void 0, e.#r = [t.substring(s - 1)], l;
369
- }
370
- static fromGlob(t, e = {}) {
371
- let s = new n(null, void 0, e);
372
- return n.#i(t, s, 0, e), s;
373
- }
374
- toMMPattern() {
375
- if (this !== this.#t) return this.#t.toMMPattern();
376
- let t = this.toString(), [e, s, i, r] = this.toRegExpSource();
377
- if (!(i || this.#s || this.#h.nocase && !this.#h.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase())) return s;
378
- let h = (this.#h.nocase ? "i" : "") + (r ? "u" : "");
379
- return Object.assign(new RegExp(`^${e}$`, h), { _src: e, _glob: t });
380
- }
381
- get options() {
382
- return this.#h;
383
- }
384
- toRegExpSource(t) {
385
- let e = t ?? !!this.#h.dot;
386
- if (this.#t === this && this.#a(), !this.type) {
387
- let a = this.isStart() && this.isEnd() && !this.#r.some((f) => typeof f != "string"), l = this.#r.map((f) => {
388
- let [m, p, w, g] = typeof f == "string" ? n.#E(f, this.#s, a) : f.toRegExpSource(t);
389
- return this.#s = this.#s || w, this.#n = this.#n || g, m;
390
- }).join(""), u = "";
391
- if (this.isStart() && typeof this.#r[0] == "string" && !(this.#r.length === 1 && Ts.has(this.#r[0]))) {
392
- let m = Cs, p = e && m.has(l.charAt(0)) || l.startsWith("\\.") && m.has(l.charAt(2)) || l.startsWith("\\.\\.") && m.has(l.charAt(4)), w = !e && !t && m.has(l.charAt(0));
393
- u = p ? vs : w ? Ct : "";
394
- }
395
- let c = "";
396
- return this.isEnd() && this.#t.#c && this.#o?.type === "!" && (c = "(?:$|\\/)"), [u + l + c, W(l), this.#s = !!this.#s, this.#n];
397
- }
398
- let s = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:", r = this.#d(e);
399
- if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
400
- let a = this.toString();
401
- return this.#r = [a], this.type = null, this.#s = void 0, [a, W(this.toString()), false, false];
402
- }
403
- let o = !s || t || e || !Ct ? "" : this.#d(true);
404
- o === r && (o = ""), o && (r = `(?:${r})(?:${o})*?`);
405
- let h = "";
406
- if (this.type === "!" && this.#f) h = (this.isStart() && !e ? Ct : "") + Ee;
407
- else {
408
- let a = this.type === "!" ? "))" + (this.isStart() && !e && !t ? Ct : "") + Se + ")" : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : `)${this.type}`;
409
- h = i + r + a;
410
- }
411
- return [h, W(r), this.#s = !!this.#s, this.#n];
412
- }
413
- #d(t) {
414
- return this.#r.map((e) => {
415
- if (typeof e == "string") throw new Error("string type in extglob ast??");
416
- let [s, i, r, o] = e.toRegExpSource(t);
417
- return this.#n = this.#n || o, s;
418
- }).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
419
- }
420
- static #E(t, e, s = false) {
421
- let i = false, r = "", o = false, h = false;
422
- for (let a = 0; a < t.length; a++) {
423
- let l = t.charAt(a);
424
- if (i) {
425
- i = false, r += (As.has(l) ? "\\" : "") + l;
426
- continue;
427
- }
428
- if (l === "*") {
429
- if (h) continue;
430
- h = true, r += s && /^[*]+$/.test(t) ? Ee : Se, e = true;
431
- continue;
432
- } else h = false;
433
- if (l === "\\") {
434
- a === t.length - 1 ? r += "\\\\" : i = true;
435
- continue;
436
- }
437
- if (l === "[") {
438
- let [u, c, d, f] = ye(t, a);
439
- if (d) {
440
- r += u, o = o || c, a += d - 1, e = e || f;
441
- continue;
442
- }
443
- }
444
- if (l === "?") {
445
- r += Kt, e = true;
446
- continue;
447
- }
448
- r += ks(l);
449
- }
450
- return [r, W(t), !!e, o];
451
- }
452
- };
453
- var tt = (n7, { windowsPathsNoEscape: t = false, magicalBraces: e = false } = {}) => e ? t ? n7.replace(/[?*()[\]{}]/g, "[$&]") : n7.replace(/[?*()[\]\\{}]/g, "\\$&") : t ? n7.replace(/[?*()[\]]/g, "[$&]") : n7.replace(/[?*()[\]\\]/g, "\\$&");
454
- var O = (n7, t, e = {}) => (at(t), !e.nocomment && t.charAt(0) === "#" ? false : new D(t, e).match(n7));
455
- var Rs = /^\*+([^+@!?\*\[\(]*)$/;
456
- var Os = (n7) => (t) => !t.startsWith(".") && t.endsWith(n7);
457
- var Fs = (n7) => (t) => t.endsWith(n7);
458
- var Ds = (n7) => (n7 = n7.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(n7));
459
- var Ms = (n7) => (n7 = n7.toLowerCase(), (t) => t.toLowerCase().endsWith(n7));
460
- var Ns = /^\*+\.\*+$/;
461
- var _s = (n7) => !n7.startsWith(".") && n7.includes(".");
462
- var Ls = (n7) => n7 !== "." && n7 !== ".." && n7.includes(".");
463
- var Ws = /^\.\*+$/;
464
- var Ps = (n7) => n7 !== "." && n7 !== ".." && n7.startsWith(".");
465
- var js = /^\*+$/;
466
- var Is = (n7) => n7.length !== 0 && !n7.startsWith(".");
467
- var zs = (n7) => n7.length !== 0 && n7 !== "." && n7 !== "..";
468
- var Bs = /^\?+([^+@!?\*\[\(]*)?$/;
469
- var Us = ([n7, t = ""]) => {
470
- let e = Ce([n7]);
471
- return t ? (t = t.toLowerCase(), (s) => e(s) && s.toLowerCase().endsWith(t)) : e;
472
- };
473
- var $s = ([n7, t = ""]) => {
474
- let e = Te([n7]);
475
- return t ? (t = t.toLowerCase(), (s) => e(s) && s.toLowerCase().endsWith(t)) : e;
476
- };
477
- var Gs = ([n7, t = ""]) => {
478
- let e = Te([n7]);
479
- return t ? (s) => e(s) && s.endsWith(t) : e;
480
- };
481
- var Hs = ([n7, t = ""]) => {
482
- let e = Ce([n7]);
483
- return t ? (s) => e(s) && s.endsWith(t) : e;
484
- };
485
- var Ce = ([n7]) => {
486
- let t = n7.length;
487
- return (e) => e.length === t && !e.startsWith(".");
488
- };
489
- var Te = ([n7]) => {
490
- let t = n7.length;
491
- return (e) => e.length === t && e !== "." && e !== "..";
492
- };
493
- var Ae = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
494
- var xe = { win32: { sep: "\\" }, posix: { sep: "/" } };
495
- var qs = Ae === "win32" ? xe.win32.sep : xe.posix.sep;
496
- O.sep = qs;
497
- var A = /* @__PURE__ */ Symbol("globstar **");
498
- O.GLOBSTAR = A;
499
- var Ks = "[^/]";
500
- var Vs = Ks + "*?";
501
- var Ys = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
502
- var Xs = "(?:(?!(?:\\/|^)\\.).)*?";
503
- var Js = (n7, t = {}) => (e) => O(e, n7, t);
504
- O.filter = Js;
505
- var N = (n7, t = {}) => Object.assign({}, n7, t);
506
- var Zs = (n7) => {
507
- if (!n7 || typeof n7 != "object" || !Object.keys(n7).length) return O;
508
- let t = O;
509
- return Object.assign((s, i, r = {}) => t(s, i, N(n7, r)), { Minimatch: class extends t.Minimatch {
510
- constructor(i, r = {}) {
511
- super(i, N(n7, r));
512
- }
513
- static defaults(i) {
514
- return t.defaults(N(n7, i)).Minimatch;
515
- }
516
- }, AST: class extends t.AST {
517
- constructor(i, r, o = {}) {
518
- super(i, r, N(n7, o));
519
- }
520
- static fromGlob(i, r = {}) {
521
- return t.AST.fromGlob(i, N(n7, r));
522
- }
523
- }, unescape: (s, i = {}) => t.unescape(s, N(n7, i)), escape: (s, i = {}) => t.escape(s, N(n7, i)), filter: (s, i = {}) => t.filter(s, N(n7, i)), defaults: (s) => t.defaults(N(n7, s)), makeRe: (s, i = {}) => t.makeRe(s, N(n7, i)), braceExpand: (s, i = {}) => t.braceExpand(s, N(n7, i)), match: (s, i, r = {}) => t.match(s, i, N(n7, r)), sep: t.sep, GLOBSTAR: A });
524
- };
525
- O.defaults = Zs;
526
- var ke = (n7, t = {}) => (at(n7), t.nobrace || !/\{(?:(?!\{).)*\}/.test(n7) ? [n7] : ge(n7, { max: t.braceExpandMax }));
527
- O.braceExpand = ke;
528
- var Qs = (n7, t = {}) => new D(n7, t).makeRe();
529
- O.makeRe = Qs;
530
- var ti = (n7, t, e = {}) => {
531
- let s = new D(t, e);
532
- return n7 = n7.filter((i) => s.match(i)), s.options.nonull && !n7.length && n7.push(t), n7;
533
- };
534
- O.match = ti;
535
- var ve = /[?*]|[+@!]\(.*?\)|\[|\]/;
536
- var ei = (n7) => n7.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
537
- var D = class {
538
- options;
539
- set;
540
- pattern;
541
- windowsPathsNoEscape;
542
- nonegate;
543
- negate;
544
- comment;
545
- empty;
546
- preserveMultipleSlashes;
547
- partial;
548
- globSet;
549
- globParts;
550
- nocase;
551
- isWindows;
552
- platform;
553
- windowsNoMagicRoot;
554
- regexp;
555
- constructor(t, e = {}) {
556
- at(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ae, this.isWindows = this.platform === "win32";
557
- let s = "allowWindowsEscape";
558
- this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e[s] === false, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = false, this.nonegate = !!e.nonegate, this.comment = false, this.empty = false, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
559
- }
560
- hasMagic() {
561
- if (this.options.magicalBraces && this.set.length > 1) return true;
562
- for (let t of this.set) for (let e of t) if (typeof e != "string") return true;
563
- return false;
564
- }
565
- debug(...t) {
566
- }
567
- make() {
568
- let t = this.pattern, e = this.options;
569
- if (!e.nocomment && t.charAt(0) === "#") {
570
- this.comment = true;
571
- return;
572
- }
573
- if (!t) {
574
- this.empty = true;
575
- return;
576
- }
577
- this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...r) => console.error(...r)), this.debug(this.pattern, this.globSet);
578
- let s = this.globSet.map((r) => this.slashSplit(r));
579
- this.globParts = this.preprocess(s), this.debug(this.pattern, this.globParts);
580
- let i = this.globParts.map((r, o, h) => {
581
- if (this.isWindows && this.windowsNoMagicRoot) {
582
- let a = r[0] === "" && r[1] === "" && (r[2] === "?" || !ve.test(r[2])) && !ve.test(r[3]), l = /^[a-z]:/i.test(r[0]);
583
- if (a) return [...r.slice(0, 4), ...r.slice(4).map((u) => this.parse(u))];
584
- if (l) return [r[0], ...r.slice(1).map((u) => this.parse(u))];
585
- }
586
- return r.map((a) => this.parse(a));
587
- });
588
- if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(false) === -1), this.isWindows) for (let r = 0; r < this.set.length; r++) {
589
- let o = this.set[r];
590
- o[0] === "" && o[1] === "" && this.globParts[r][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
591
- }
592
- this.debug(this.pattern, this.set);
593
- }
594
- preprocess(t) {
595
- if (this.options.noglobstar) for (let s = 0; s < t.length; s++) for (let i = 0; i < t[s].length; i++) t[s][i] === "**" && (t[s][i] = "*");
596
- let { optimizationLevel: e = 1 } = this.options;
597
- return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
598
- }
599
- adjascentGlobstarOptimize(t) {
600
- return t.map((e) => {
601
- let s = -1;
602
- for (; (s = e.indexOf("**", s + 1)) !== -1; ) {
603
- let i = s;
604
- for (; e[i + 1] === "**"; ) i++;
605
- i !== s && e.splice(s, i - s);
606
- }
607
- return e;
608
- });
609
- }
610
- levelOneOptimize(t) {
611
- return t.map((e) => (e = e.reduce((s, i) => {
612
- let r = s[s.length - 1];
613
- return i === "**" && r === "**" ? s : i === ".." && r && r !== ".." && r !== "." && r !== "**" ? (s.pop(), s) : (s.push(i), s);
614
- }, []), e.length === 0 ? [""] : e));
615
- }
616
- levelTwoFileOptimize(t) {
617
- Array.isArray(t) || (t = this.slashSplit(t));
618
- let e = false;
619
- do {
620
- if (e = false, !this.preserveMultipleSlashes) {
621
- for (let i = 1; i < t.length - 1; i++) {
622
- let r = t[i];
623
- i === 1 && r === "" && t[0] === "" || (r === "." || r === "") && (e = true, t.splice(i, 1), i--);
624
- }
625
- t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = true, t.pop());
626
- }
627
- let s = 0;
628
- for (; (s = t.indexOf("..", s + 1)) !== -1; ) {
629
- let i = t[s - 1];
630
- i && i !== "." && i !== ".." && i !== "**" && (e = true, t.splice(s - 1, 2), s -= 2);
631
- }
632
- } while (e);
633
- return t.length === 0 ? [""] : t;
634
- }
635
- firstPhasePreProcess(t) {
636
- let e = false;
637
- do {
638
- e = false;
639
- for (let s of t) {
640
- let i = -1;
641
- for (; (i = s.indexOf("**", i + 1)) !== -1; ) {
642
- let o = i;
643
- for (; s[o + 1] === "**"; ) o++;
644
- o > i && s.splice(i + 1, o - i);
645
- let h = s[i + 1], a = s[i + 2], l = s[i + 3];
646
- if (h !== ".." || !a || a === "." || a === ".." || !l || l === "." || l === "..") continue;
647
- e = true, s.splice(i, 1);
648
- let u = s.slice(0);
649
- u[i] = "**", t.push(u), i--;
650
- }
651
- if (!this.preserveMultipleSlashes) {
652
- for (let o = 1; o < s.length - 1; o++) {
653
- let h = s[o];
654
- o === 1 && h === "" && s[0] === "" || (h === "." || h === "") && (e = true, s.splice(o, 1), o--);
655
- }
656
- s[0] === "." && s.length === 2 && (s[1] === "." || s[1] === "") && (e = true, s.pop());
657
- }
658
- let r = 0;
659
- for (; (r = s.indexOf("..", r + 1)) !== -1; ) {
660
- let o = s[r - 1];
661
- if (o && o !== "." && o !== ".." && o !== "**") {
662
- e = true;
663
- let a = r === 1 && s[r + 1] === "**" ? ["."] : [];
664
- s.splice(r - 1, 2, ...a), s.length === 0 && s.push(""), r -= 2;
665
- }
666
- }
667
- }
668
- } while (e);
669
- return t;
670
- }
671
- secondPhasePreProcess(t) {
672
- for (let e = 0; e < t.length - 1; e++) for (let s = e + 1; s < t.length; s++) {
673
- let i = this.partsMatch(t[e], t[s], !this.preserveMultipleSlashes);
674
- if (i) {
675
- t[e] = [], t[s] = i;
676
- break;
677
- }
678
- }
679
- return t.filter((e) => e.length);
680
- }
681
- partsMatch(t, e, s = false) {
682
- let i = 0, r = 0, o = [], h = "";
683
- for (; i < t.length && r < e.length; ) if (t[i] === e[r]) o.push(h === "b" ? e[r] : t[i]), i++, r++;
684
- else if (s && t[i] === "**" && e[r] === t[i + 1]) o.push(t[i]), i++;
685
- else if (s && e[r] === "**" && t[i] === e[r + 1]) o.push(e[r]), r++;
686
- else if (t[i] === "*" && e[r] && (this.options.dot || !e[r].startsWith(".")) && e[r] !== "**") {
687
- if (h === "b") return false;
688
- h = "a", o.push(t[i]), i++, r++;
689
- } else if (e[r] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") {
690
- if (h === "a") return false;
691
- h = "b", o.push(e[r]), i++, r++;
692
- } else return false;
693
- return t.length === e.length && o;
694
- }
695
- parseNegate() {
696
- if (this.nonegate) return;
697
- let t = this.pattern, e = false, s = 0;
698
- for (let i = 0; i < t.length && t.charAt(i) === "!"; i++) e = !e, s++;
699
- s && (this.pattern = t.slice(s)), this.negate = e;
700
- }
701
- matchOne(t, e, s = false) {
702
- let i = this.options;
703
- if (this.isWindows) {
704
- let p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), w = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), g = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), S = !g && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), E = w ? 3 : p ? 0 : void 0, y = S ? 3 : g ? 0 : void 0;
705
- if (typeof E == "number" && typeof y == "number") {
706
- let [b, z] = [t[E], e[y]];
707
- b.toLowerCase() === z.toLowerCase() && (e[y] = b, y > E ? e = e.slice(y) : E > y && (t = t.slice(E)));
708
- }
709
- }
710
- let { optimizationLevel: r = 1 } = this.options;
711
- r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
712
- for (var o = 0, h = 0, a = t.length, l = e.length; o < a && h < l; o++, h++) {
713
- this.debug("matchOne loop");
714
- var u = e[h], c = t[o];
715
- if (this.debug(e, u, c), u === false) return false;
716
- if (u === A) {
717
- this.debug("GLOBSTAR", [e, u, c]);
718
- var d = o, f = h + 1;
719
- if (f === l) {
720
- for (this.debug("** at the end"); o < a; o++) if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".") return false;
721
- return true;
722
- }
723
- for (; d < a; ) {
724
- var m = t[d];
725
- if (this.debug(`
726
- globstar while`, t, d, e, f, m), this.matchOne(t.slice(d), e.slice(f), s)) return this.debug("globstar found match!", d, a, m), true;
727
- if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
728
- this.debug("dot detected!", t, d, e, f);
729
- break;
730
- }
731
- this.debug("globstar swallow a segment, and continue"), d++;
732
- }
733
- return !!(s && (this.debug(`
734
- >>> no match, partial?`, t, d, e, f), d === a));
735
- }
736
- let p;
737
- if (typeof u == "string" ? (p = c === u, this.debug("string match", u, c, p)) : (p = u.test(c), this.debug("pattern match", u, c, p)), !p) return false;
738
- }
739
- if (o === a && h === l) return true;
740
- if (o === a) return s;
741
- if (h === l) return o === a - 1 && t[o] === "";
742
- throw new Error("wtf?");
743
- }
744
- braceExpand() {
745
- return ke(this.pattern, this.options);
746
- }
747
- parse(t) {
748
- at(t);
749
- let e = this.options;
750
- if (t === "**") return A;
751
- if (t === "") return "";
752
- let s, i = null;
753
- (s = t.match(js)) ? i = e.dot ? zs : Is : (s = t.match(Rs)) ? i = (e.nocase ? e.dot ? Ms : Ds : e.dot ? Fs : Os)(s[1]) : (s = t.match(Bs)) ? i = (e.nocase ? e.dot ? $s : Us : e.dot ? Gs : Hs)(s) : (s = t.match(Ns)) ? i = e.dot ? Ls : _s : (s = t.match(Ws)) && (i = Ps);
754
- let r = Q.fromGlob(t, this.options).toMMPattern();
755
- return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
756
- }
757
- makeRe() {
758
- if (this.regexp || this.regexp === false) return this.regexp;
759
- let t = this.set;
760
- if (!t.length) return this.regexp = false, this.regexp;
761
- let e = this.options, s = e.noglobstar ? Vs : e.dot ? Ys : Xs, i = new Set(e.nocase ? ["i"] : []), r = t.map((a) => {
762
- let l = a.map((c) => {
763
- if (c instanceof RegExp) for (let d of c.flags.split("")) i.add(d);
764
- return typeof c == "string" ? ei(c) : c === A ? A : c._src;
765
- });
766
- l.forEach((c, d) => {
767
- let f = l[d + 1], m = l[d - 1];
768
- c !== A || m === A || (m === void 0 ? f !== void 0 && f !== A ? l[d + 1] = "(?:\\/|" + s + "\\/)?" + f : l[d] = s : f === void 0 ? l[d - 1] = m + "(?:\\/|\\/" + s + ")?" : f !== A && (l[d - 1] = m + "(?:\\/|\\/" + s + "\\/)" + f, l[d + 1] = A));
769
- });
770
- let u = l.filter((c) => c !== A);
771
- if (this.partial && u.length >= 1) {
772
- let c = [];
773
- for (let d = 1; d <= u.length; d++) c.push(u.slice(0, d).join("/"));
774
- return "(?:" + c.join("|") + ")";
775
- }
776
- return u.join("/");
777
- }).join("|"), [o, h] = t.length > 1 ? ["(?:", ")"] : ["", ""];
778
- r = "^" + o + r + h + "$", this.partial && (r = "^(?:\\/|" + o + r.slice(1, -1) + h + ")$"), this.negate && (r = "^(?!" + r + ").+$");
779
- try {
780
- this.regexp = new RegExp(r, [...i].join(""));
781
- } catch {
782
- this.regexp = false;
783
- }
784
- return this.regexp;
785
- }
786
- slashSplit(t) {
787
- return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\/\/[^\/]+/.test(t) ? ["", ...t.split(/\/+/)] : t.split(/\/+/);
788
- }
789
- match(t, e = this.partial) {
790
- if (this.debug("match", t, this.pattern), this.comment) return false;
791
- if (this.empty) return t === "";
792
- if (t === "/" && e) return true;
793
- let s = this.options;
794
- this.isWindows && (t = t.split("\\").join("/"));
795
- let i = this.slashSplit(t);
796
- this.debug(this.pattern, "split", i);
797
- let r = this.set;
798
- this.debug(this.pattern, "set", r);
799
- let o = i[i.length - 1];
800
- if (!o) for (let h = i.length - 2; !o && h >= 0; h--) o = i[h];
801
- for (let h = 0; h < r.length; h++) {
802
- let a = r[h], l = i;
803
- if (s.matchBase && a.length === 1 && (l = [o]), this.matchOne(l, a, e)) return s.flipNegate ? true : !this.negate;
804
- }
805
- return s.flipNegate ? false : this.negate;
806
- }
807
- static defaults(t) {
808
- return O.defaults(t).Minimatch;
809
- }
810
- };
811
- O.AST = Q;
812
- O.Minimatch = D;
813
- O.escape = tt;
814
- O.unescape = W;
815
- var si = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date;
816
- var Oe = /* @__PURE__ */ new Set();
817
- var Vt = typeof process == "object" && process ? process : {};
818
- var Fe = (n7, t, e, s) => {
819
- typeof Vt.emitWarning == "function" ? Vt.emitWarning(n7, t, e, s) : console.error(`[${e}] ${t}: ${n7}`);
820
- };
821
- var At = globalThis.AbortController;
822
- var Re = globalThis.AbortSignal;
823
- if (typeof At > "u") {
824
- Re = class {
825
- onabort;
826
- _onabort = [];
827
- reason;
828
- aborted = false;
829
- addEventListener(e, s) {
830
- this._onabort.push(s);
831
- }
832
- }, At = class {
833
- constructor() {
834
- t();
835
- }
836
- signal = new Re();
837
- abort(e) {
838
- if (!this.signal.aborted) {
839
- this.signal.reason = e, this.signal.aborted = true;
840
- for (let s of this.signal._onabort) s(e);
841
- this.signal.onabort?.(e);
842
- }
843
- }
844
- };
845
- let n7 = Vt.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1", t = () => {
846
- n7 && (n7 = false, Fe("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", t));
847
- };
848
- }
849
- var ii = (n7) => !Oe.has(n7);
850
- var q = (n7) => n7 && n7 === Math.floor(n7) && n7 > 0 && isFinite(n7);
851
- var De = (n7) => q(n7) ? n7 <= Math.pow(2, 8) ? Uint8Array : n7 <= Math.pow(2, 16) ? Uint16Array : n7 <= Math.pow(2, 32) ? Uint32Array : n7 <= Number.MAX_SAFE_INTEGER ? Tt : null : null;
852
- var Tt = class extends Array {
853
- constructor(n7) {
854
- super(n7), this.fill(0);
855
- }
856
- };
857
- var ri = class ct {
858
- heap;
859
- length;
860
- static #t = false;
861
- static create(t) {
862
- let e = De(t);
863
- if (!e) return [];
864
- ct.#t = true;
865
- let s = new ct(t, e);
866
- return ct.#t = false, s;
867
- }
868
- constructor(t, e) {
869
- if (!ct.#t) throw new TypeError("instantiate Stack using Stack.create(n)");
870
- this.heap = new e(t), this.length = 0;
871
- }
872
- push(t) {
873
- this.heap[this.length++] = t;
874
- }
875
- pop() {
876
- return this.heap[--this.length];
877
- }
878
- };
879
- var ft = class Me {
880
- #t;
881
- #s;
882
- #n;
883
- #r;
884
- #o;
885
- #S;
886
- #w;
887
- #c;
888
- get perf() {
889
- return this.#c;
890
- }
891
- ttl;
892
- ttlResolution;
893
- ttlAutopurge;
894
- updateAgeOnGet;
895
- updateAgeOnHas;
896
- allowStale;
897
- noDisposeOnSet;
898
- noUpdateTTL;
899
- maxEntrySize;
900
- sizeCalculation;
901
- noDeleteOnFetchRejection;
902
- noDeleteOnStaleGet;
903
- allowStaleOnFetchAbort;
904
- allowStaleOnFetchRejection;
905
- ignoreFetchAbort;
906
- #h;
907
- #u;
908
- #f;
909
- #a;
910
- #i;
911
- #d;
912
- #E;
913
- #b;
914
- #p;
915
- #R;
916
- #m;
917
- #C;
918
- #T;
919
- #g;
920
- #y;
921
- #x;
922
- #A;
923
- #e;
924
- #_;
925
- static unsafeExposeInternals(t) {
926
- return { starts: t.#T, ttls: t.#g, autopurgeTimers: t.#y, sizes: t.#C, keyMap: t.#f, keyList: t.#a, valList: t.#i, next: t.#d, prev: t.#E, get head() {
927
- return t.#b;
928
- }, get tail() {
929
- return t.#p;
930
- }, free: t.#R, isBackgroundFetch: (e) => t.#l(e), backgroundFetch: (e, s, i, r) => t.#U(e, s, i, r), moveToTail: (e) => t.#W(e), indexes: (e) => t.#F(e), rindexes: (e) => t.#D(e), isStale: (e) => t.#v(e) };
931
- }
932
- get max() {
933
- return this.#t;
934
- }
935
- get maxSize() {
936
- return this.#s;
937
- }
938
- get calculatedSize() {
939
- return this.#u;
940
- }
941
- get size() {
942
- return this.#h;
943
- }
944
- get fetchMethod() {
945
- return this.#S;
946
- }
947
- get memoMethod() {
948
- return this.#w;
949
- }
950
- get dispose() {
951
- return this.#n;
952
- }
953
- get onInsert() {
954
- return this.#r;
955
- }
956
- get disposeAfter() {
957
- return this.#o;
958
- }
959
- constructor(t) {
960
- let { max: e = 0, ttl: s, ttlResolution: i = 1, ttlAutopurge: r, updateAgeOnGet: o, updateAgeOnHas: h, allowStale: a, dispose: l, onInsert: u, disposeAfter: c, noDisposeOnSet: d, noUpdateTTL: f, maxSize: m = 0, maxEntrySize: p = 0, sizeCalculation: w, fetchMethod: g, memoMethod: S, noDeleteOnFetchRejection: E, noDeleteOnStaleGet: y, allowStaleOnFetchRejection: b, allowStaleOnFetchAbort: z, ignoreFetchAbort: $, perf: J } = t;
961
- if (J !== void 0 && typeof J?.now != "function") throw new TypeError("perf option must have a now() method if specified");
962
- if (this.#c = J ?? si, e !== 0 && !q(e)) throw new TypeError("max option must be a nonnegative integer");
963
- let Z = e ? De(e) : Array;
964
- if (!Z) throw new Error("invalid max value: " + e);
965
- if (this.#t = e, this.#s = m, this.maxEntrySize = p || this.#s, this.sizeCalculation = w, this.sizeCalculation) {
966
- if (!this.#s && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
967
- if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
968
- }
969
- if (S !== void 0 && typeof S != "function") throw new TypeError("memoMethod must be a function if defined");
970
- if (this.#w = S, g !== void 0 && typeof g != "function") throw new TypeError("fetchMethod must be a function if specified");
971
- if (this.#S = g, this.#A = !!g, this.#f = /* @__PURE__ */ new Map(), this.#a = new Array(e).fill(void 0), this.#i = new Array(e).fill(void 0), this.#d = new Z(e), this.#E = new Z(e), this.#b = 0, this.#p = 0, this.#R = ri.create(e), this.#h = 0, this.#u = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof c == "function" ? (this.#o = c, this.#m = []) : (this.#o = void 0, this.#m = void 0), this.#x = !!this.#n, this.#_ = !!this.#r, this.#e = !!this.#o, this.noDisposeOnSet = !!d, this.noUpdateTTL = !!f, this.noDeleteOnFetchRejection = !!E, this.allowStaleOnFetchRejection = !!b, this.allowStaleOnFetchAbort = !!z, this.ignoreFetchAbort = !!$, this.maxEntrySize !== 0) {
972
- if (this.#s !== 0 && !q(this.#s)) throw new TypeError("maxSize must be a positive integer if specified");
973
- if (!q(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
974
- this.#G();
975
- }
976
- if (this.allowStale = !!a, this.noDeleteOnStaleGet = !!y, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!h, this.ttlResolution = q(i) || i === 0 ? i : 1, this.ttlAutopurge = !!r, this.ttl = s || 0, this.ttl) {
977
- if (!q(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
978
- this.#M();
979
- }
980
- if (this.#t === 0 && this.ttl === 0 && this.#s === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
981
- if (!this.ttlAutopurge && !this.#t && !this.#s) {
982
- let $t = "LRU_CACHE_UNBOUNDED";
983
- ii($t) && (Oe.add($t), Fe("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", $t, Me));
984
- }
985
- }
986
- getRemainingTTL(t) {
987
- return this.#f.has(t) ? 1 / 0 : 0;
988
- }
989
- #M() {
990
- let t = new Tt(this.#t), e = new Tt(this.#t);
991
- this.#g = t, this.#T = e;
992
- let s = this.ttlAutopurge ? new Array(this.#t) : void 0;
993
- this.#y = s, this.#j = (o, h, a = this.#c.now()) => {
994
- if (e[o] = h !== 0 ? a : 0, t[o] = h, s?.[o] && (clearTimeout(s[o]), s[o] = void 0), h !== 0 && s) {
995
- let l = setTimeout(() => {
996
- this.#v(o) && this.#O(this.#a[o], "expire");
997
- }, h + 1);
998
- l.unref && l.unref(), s[o] = l;
999
- }
1000
- }, this.#k = (o) => {
1001
- e[o] = t[o] !== 0 ? this.#c.now() : 0;
1002
- }, this.#N = (o, h) => {
1003
- if (t[h]) {
1004
- let a = t[h], l = e[h];
1005
- if (!a || !l) return;
1006
- o.ttl = a, o.start = l, o.now = i || r();
1007
- let u = o.now - l;
1008
- o.remainingTTL = a - u;
1009
- }
1010
- };
1011
- let i = 0, r = () => {
1012
- let o = this.#c.now();
1013
- if (this.ttlResolution > 0) {
1014
- i = o;
1015
- let h = setTimeout(() => i = 0, this.ttlResolution);
1016
- h.unref && h.unref();
1017
- }
1018
- return o;
1019
- };
1020
- this.getRemainingTTL = (o) => {
1021
- let h = this.#f.get(o);
1022
- if (h === void 0) return 0;
1023
- let a = t[h], l = e[h];
1024
- if (!a || !l) return 1 / 0;
1025
- let u = (i || r()) - l;
1026
- return a - u;
1027
- }, this.#v = (o) => {
1028
- let h = e[o], a = t[o];
1029
- return !!a && !!h && (i || r()) - h > a;
1030
- };
1031
- }
1032
- #k = () => {
1033
- };
1034
- #N = () => {
1035
- };
1036
- #j = () => {
1037
- };
1038
- #v = () => false;
1039
- #G() {
1040
- let t = new Tt(this.#t);
1041
- this.#u = 0, this.#C = t, this.#P = (e) => {
1042
- this.#u -= t[e], t[e] = 0;
1043
- }, this.#I = (e, s, i, r) => {
1044
- if (this.#l(s)) return 0;
1045
- if (!q(i)) if (r) {
1046
- if (typeof r != "function") throw new TypeError("sizeCalculation must be a function");
1047
- if (i = r(s, e), !q(i)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
1048
- } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
1049
- return i;
1050
- }, this.#L = (e, s, i) => {
1051
- if (t[e] = s, this.#s) {
1052
- let r = this.#s - t[e];
1053
- for (; this.#u > r; ) this.#B(true);
1054
- }
1055
- this.#u += t[e], i && (i.entrySize = s, i.totalCalculatedSize = this.#u);
1056
- };
1057
- }
1058
- #P = (t) => {
1059
- };
1060
- #L = (t, e, s) => {
1061
- };
1062
- #I = (t, e, s, i) => {
1063
- if (s || i) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
1064
- return 0;
1065
- };
1066
- *#F({ allowStale: t = this.allowStale } = {}) {
1067
- if (this.#h) for (let e = this.#p; !(!this.#z(e) || ((t || !this.#v(e)) && (yield e), e === this.#b)); ) e = this.#E[e];
1068
- }
1069
- *#D({ allowStale: t = this.allowStale } = {}) {
1070
- if (this.#h) for (let e = this.#b; !(!this.#z(e) || ((t || !this.#v(e)) && (yield e), e === this.#p)); ) e = this.#d[e];
1071
- }
1072
- #z(t) {
1073
- return t !== void 0 && this.#f.get(this.#a[t]) === t;
1074
- }
1075
- *entries() {
1076
- for (let t of this.#F()) this.#i[t] !== void 0 && this.#a[t] !== void 0 && !this.#l(this.#i[t]) && (yield [this.#a[t], this.#i[t]]);
1077
- }
1078
- *rentries() {
1079
- for (let t of this.#D()) this.#i[t] !== void 0 && this.#a[t] !== void 0 && !this.#l(this.#i[t]) && (yield [this.#a[t], this.#i[t]]);
1080
- }
1081
- *keys() {
1082
- for (let t of this.#F()) {
1083
- let e = this.#a[t];
1084
- e !== void 0 && !this.#l(this.#i[t]) && (yield e);
1085
- }
1086
- }
1087
- *rkeys() {
1088
- for (let t of this.#D()) {
1089
- let e = this.#a[t];
1090
- e !== void 0 && !this.#l(this.#i[t]) && (yield e);
1091
- }
1092
- }
1093
- *values() {
1094
- for (let t of this.#F()) this.#i[t] !== void 0 && !this.#l(this.#i[t]) && (yield this.#i[t]);
1095
- }
1096
- *rvalues() {
1097
- for (let t of this.#D()) this.#i[t] !== void 0 && !this.#l(this.#i[t]) && (yield this.#i[t]);
1098
- }
1099
- [Symbol.iterator]() {
1100
- return this.entries();
1101
- }
1102
- [Symbol.toStringTag] = "LRUCache";
1103
- find(t, e = {}) {
1104
- for (let s of this.#F()) {
1105
- let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
1106
- if (r !== void 0 && t(r, this.#a[s], this)) return this.get(this.#a[s], e);
1107
- }
1108
- }
1109
- forEach(t, e = this) {
1110
- for (let s of this.#F()) {
1111
- let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
1112
- r !== void 0 && t.call(e, r, this.#a[s], this);
1113
- }
1114
- }
1115
- rforEach(t, e = this) {
1116
- for (let s of this.#D()) {
1117
- let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
1118
- r !== void 0 && t.call(e, r, this.#a[s], this);
1119
- }
1120
- }
1121
- purgeStale() {
1122
- let t = false;
1123
- for (let e of this.#D({ allowStale: true })) this.#v(e) && (this.#O(this.#a[e], "expire"), t = true);
1124
- return t;
1125
- }
1126
- info(t) {
1127
- let e = this.#f.get(t);
1128
- if (e === void 0) return;
1129
- let s = this.#i[e], i = this.#l(s) ? s.__staleWhileFetching : s;
1130
- if (i === void 0) return;
1131
- let r = { value: i };
1132
- if (this.#g && this.#T) {
1133
- let o = this.#g[e], h = this.#T[e];
1134
- if (o && h) {
1135
- let a = o - (this.#c.now() - h);
1136
- r.ttl = a, r.start = Date.now();
1137
- }
1138
- }
1139
- return this.#C && (r.size = this.#C[e]), r;
1140
- }
1141
- dump() {
1142
- let t = [];
1143
- for (let e of this.#F({ allowStale: true })) {
1144
- let s = this.#a[e], i = this.#i[e], r = this.#l(i) ? i.__staleWhileFetching : i;
1145
- if (r === void 0 || s === void 0) continue;
1146
- let o = { value: r };
1147
- if (this.#g && this.#T) {
1148
- o.ttl = this.#g[e];
1149
- let h = this.#c.now() - this.#T[e];
1150
- o.start = Math.floor(Date.now() - h);
1151
- }
1152
- this.#C && (o.size = this.#C[e]), t.unshift([s, o]);
1153
- }
1154
- return t;
1155
- }
1156
- load(t) {
1157
- this.clear();
1158
- for (let [e, s] of t) {
1159
- if (s.start) {
1160
- let i = Date.now() - s.start;
1161
- s.start = this.#c.now() - i;
1162
- }
1163
- this.set(e, s.value, s);
1164
- }
1165
- }
1166
- set(t, e, s = {}) {
1167
- if (e === void 0) return this.delete(t), this;
1168
- let { ttl: i = this.ttl, start: r, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: h = this.sizeCalculation, status: a } = s, { noUpdateTTL: l = this.noUpdateTTL } = s, u = this.#I(t, e, s.size || 0, h);
1169
- if (this.maxEntrySize && u > this.maxEntrySize) return a && (a.set = "miss", a.maxEntrySizeExceeded = true), this.#O(t, "set"), this;
1170
- let c = this.#h === 0 ? void 0 : this.#f.get(t);
1171
- if (c === void 0) c = this.#h === 0 ? this.#p : this.#R.length !== 0 ? this.#R.pop() : this.#h === this.#t ? this.#B(false) : this.#h, this.#a[c] = t, this.#i[c] = e, this.#f.set(t, c), this.#d[this.#p] = c, this.#E[c] = this.#p, this.#p = c, this.#h++, this.#L(c, u, a), a && (a.set = "add"), l = false, this.#_ && this.#r?.(e, t, "add");
1172
- else {
1173
- this.#W(c);
1174
- let d = this.#i[c];
1175
- if (e !== d) {
1176
- if (this.#A && this.#l(d)) {
1177
- d.__abortController.abort(new Error("replaced"));
1178
- let { __staleWhileFetching: f } = d;
1179
- f !== void 0 && !o && (this.#x && this.#n?.(f, t, "set"), this.#e && this.#m?.push([f, t, "set"]));
1180
- } else o || (this.#x && this.#n?.(d, t, "set"), this.#e && this.#m?.push([d, t, "set"]));
1181
- if (this.#P(c), this.#L(c, u, a), this.#i[c] = e, a) {
1182
- a.set = "replace";
1183
- let f = d && this.#l(d) ? d.__staleWhileFetching : d;
1184
- f !== void 0 && (a.oldValue = f);
1185
- }
1186
- } else a && (a.set = "update");
1187
- this.#_ && this.onInsert?.(e, t, e === d ? "update" : "replace");
1188
- }
1189
- if (i !== 0 && !this.#g && this.#M(), this.#g && (l || this.#j(c, i, r), a && this.#N(a, c)), !o && this.#e && this.#m) {
1190
- let d = this.#m, f;
1191
- for (; f = d?.shift(); ) this.#o?.(...f);
1192
- }
1193
- return this;
1194
- }
1195
- pop() {
1196
- try {
1197
- for (; this.#h; ) {
1198
- let t = this.#i[this.#b];
1199
- if (this.#B(true), this.#l(t)) {
1200
- if (t.__staleWhileFetching) return t.__staleWhileFetching;
1201
- } else if (t !== void 0) return t;
1202
- }
1203
- } finally {
1204
- if (this.#e && this.#m) {
1205
- let t = this.#m, e;
1206
- for (; e = t?.shift(); ) this.#o?.(...e);
1207
- }
1208
- }
1209
- }
1210
- #B(t) {
1211
- let e = this.#b, s = this.#a[e], i = this.#i[e];
1212
- return this.#A && this.#l(i) ? i.__abortController.abort(new Error("evicted")) : (this.#x || this.#e) && (this.#x && this.#n?.(i, s, "evict"), this.#e && this.#m?.push([i, s, "evict"])), this.#P(e), this.#y?.[e] && (clearTimeout(this.#y[e]), this.#y[e] = void 0), t && (this.#a[e] = void 0, this.#i[e] = void 0, this.#R.push(e)), this.#h === 1 ? (this.#b = this.#p = 0, this.#R.length = 0) : this.#b = this.#d[e], this.#f.delete(s), this.#h--, e;
1213
- }
1214
- has(t, e = {}) {
1215
- let { updateAgeOnHas: s = this.updateAgeOnHas, status: i } = e, r = this.#f.get(t);
1216
- if (r !== void 0) {
1217
- let o = this.#i[r];
1218
- if (this.#l(o) && o.__staleWhileFetching === void 0) return false;
1219
- if (this.#v(r)) i && (i.has = "stale", this.#N(i, r));
1220
- else return s && this.#k(r), i && (i.has = "hit", this.#N(i, r)), true;
1221
- } else i && (i.has = "miss");
1222
- return false;
1223
- }
1224
- peek(t, e = {}) {
1225
- let { allowStale: s = this.allowStale } = e, i = this.#f.get(t);
1226
- if (i === void 0 || !s && this.#v(i)) return;
1227
- let r = this.#i[i];
1228
- return this.#l(r) ? r.__staleWhileFetching : r;
1229
- }
1230
- #U(t, e, s, i) {
1231
- let r = e === void 0 ? void 0 : this.#i[e];
1232
- if (this.#l(r)) return r;
1233
- let o = new At(), { signal: h } = s;
1234
- h?.addEventListener("abort", () => o.abort(h.reason), { signal: o.signal });
1235
- let a = { signal: o.signal, options: s, context: i }, l = (p, w = false) => {
1236
- let { aborted: g } = o.signal, S = s.ignoreFetchAbort && p !== void 0, E = s.ignoreFetchAbort || !!(s.allowStaleOnFetchAbort && p !== void 0);
1237
- if (s.status && (g && !w ? (s.status.fetchAborted = true, s.status.fetchError = o.signal.reason, S && (s.status.fetchAbortIgnored = true)) : s.status.fetchResolved = true), g && !S && !w) return c(o.signal.reason, E);
1238
- let y = f, b = this.#i[e];
1239
- return (b === f || S && w && b === void 0) && (p === void 0 ? y.__staleWhileFetching !== void 0 ? this.#i[e] = y.__staleWhileFetching : this.#O(t, "fetch") : (s.status && (s.status.fetchUpdated = true), this.set(t, p, a.options))), p;
1240
- }, u = (p) => (s.status && (s.status.fetchRejected = true, s.status.fetchError = p), c(p, false)), c = (p, w) => {
1241
- let { aborted: g } = o.signal, S = g && s.allowStaleOnFetchAbort, E = S || s.allowStaleOnFetchRejection, y = E || s.noDeleteOnFetchRejection, b = f;
1242
- if (this.#i[e] === f && (!y || !w && b.__staleWhileFetching === void 0 ? this.#O(t, "fetch") : S || (this.#i[e] = b.__staleWhileFetching)), E) return s.status && b.__staleWhileFetching !== void 0 && (s.status.returnedStale = true), b.__staleWhileFetching;
1243
- if (b.__returned === b) throw p;
1244
- }, d = (p, w) => {
1245
- let g = this.#S?.(t, r, a);
1246
- g && g instanceof Promise && g.then((S) => p(S === void 0 ? void 0 : S), w), o.signal.addEventListener("abort", () => {
1247
- (!s.ignoreFetchAbort || s.allowStaleOnFetchAbort) && (p(void 0), s.allowStaleOnFetchAbort && (p = (S) => l(S, true)));
1248
- });
1249
- };
1250
- s.status && (s.status.fetchDispatched = true);
1251
- let f = new Promise(d).then(l, u), m = Object.assign(f, { __abortController: o, __staleWhileFetching: r, __returned: void 0 });
1252
- return e === void 0 ? (this.set(t, m, { ...a.options, status: void 0 }), e = this.#f.get(t)) : this.#i[e] = m, m;
1253
- }
1254
- #l(t) {
1255
- if (!this.#A) return false;
1256
- let e = t;
1257
- return !!e && e instanceof Promise && e.hasOwnProperty("__staleWhileFetching") && e.__abortController instanceof At;
1258
- }
1259
- async fetch(t, e = {}) {
1260
- let { allowStale: s = this.allowStale, updateAgeOnGet: i = this.updateAgeOnGet, noDeleteOnStaleGet: r = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: a = 0, sizeCalculation: l = this.sizeCalculation, noUpdateTTL: u = this.noUpdateTTL, noDeleteOnFetchRejection: c = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: f = this.ignoreFetchAbort, allowStaleOnFetchAbort: m = this.allowStaleOnFetchAbort, context: p, forceRefresh: w = false, status: g, signal: S } = e;
1261
- if (!this.#A) return g && (g.fetch = "get"), this.get(t, { allowStale: s, updateAgeOnGet: i, noDeleteOnStaleGet: r, status: g });
1262
- let E = { allowStale: s, updateAgeOnGet: i, noDeleteOnStaleGet: r, ttl: o, noDisposeOnSet: h, size: a, sizeCalculation: l, noUpdateTTL: u, noDeleteOnFetchRejection: c, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: m, ignoreFetchAbort: f, status: g, signal: S }, y = this.#f.get(t);
1263
- if (y === void 0) {
1264
- g && (g.fetch = "miss");
1265
- let b = this.#U(t, y, E, p);
1266
- return b.__returned = b;
1267
- } else {
1268
- let b = this.#i[y];
1269
- if (this.#l(b)) {
1270
- let Z = s && b.__staleWhileFetching !== void 0;
1271
- return g && (g.fetch = "inflight", Z && (g.returnedStale = true)), Z ? b.__staleWhileFetching : b.__returned = b;
1272
- }
1273
- let z = this.#v(y);
1274
- if (!w && !z) return g && (g.fetch = "hit"), this.#W(y), i && this.#k(y), g && this.#N(g, y), b;
1275
- let $ = this.#U(t, y, E, p), J = $.__staleWhileFetching !== void 0 && s;
1276
- return g && (g.fetch = z ? "stale" : "refresh", J && z && (g.returnedStale = true)), J ? $.__staleWhileFetching : $.__returned = $;
1277
- }
1278
- }
1279
- async forceFetch(t, e = {}) {
1280
- let s = await this.fetch(t, e);
1281
- if (s === void 0) throw new Error("fetch() returned undefined");
1282
- return s;
1283
- }
1284
- memo(t, e = {}) {
1285
- let s = this.#w;
1286
- if (!s) throw new Error("no memoMethod provided to constructor");
1287
- let { context: i, forceRefresh: r, ...o } = e, h = this.get(t, o);
1288
- if (!r && h !== void 0) return h;
1289
- let a = s(t, h, { options: o, context: i });
1290
- return this.set(t, a, o), a;
1291
- }
1292
- get(t, e = {}) {
1293
- let { allowStale: s = this.allowStale, updateAgeOnGet: i = this.updateAgeOnGet, noDeleteOnStaleGet: r = this.noDeleteOnStaleGet, status: o } = e, h = this.#f.get(t);
1294
- if (h !== void 0) {
1295
- let a = this.#i[h], l = this.#l(a);
1296
- return o && this.#N(o, h), this.#v(h) ? (o && (o.get = "stale"), l ? (o && s && a.__staleWhileFetching !== void 0 && (o.returnedStale = true), s ? a.__staleWhileFetching : void 0) : (r || this.#O(t, "expire"), o && s && (o.returnedStale = true), s ? a : void 0)) : (o && (o.get = "hit"), l ? a.__staleWhileFetching : (this.#W(h), i && this.#k(h), a));
1297
- } else o && (o.get = "miss");
1298
- }
1299
- #$(t, e) {
1300
- this.#E[e] = t, this.#d[t] = e;
1301
- }
1302
- #W(t) {
1303
- t !== this.#p && (t === this.#b ? this.#b = this.#d[t] : this.#$(this.#E[t], this.#d[t]), this.#$(this.#p, t), this.#p = t);
1304
- }
1305
- delete(t) {
1306
- return this.#O(t, "delete");
1307
- }
1308
- #O(t, e) {
1309
- let s = false;
1310
- if (this.#h !== 0) {
1311
- let i = this.#f.get(t);
1312
- if (i !== void 0) if (this.#y?.[i] && (clearTimeout(this.#y?.[i]), this.#y[i] = void 0), s = true, this.#h === 1) this.#H(e);
1313
- else {
1314
- this.#P(i);
1315
- let r = this.#i[i];
1316
- if (this.#l(r) ? r.__abortController.abort(new Error("deleted")) : (this.#x || this.#e) && (this.#x && this.#n?.(r, t, e), this.#e && this.#m?.push([r, t, e])), this.#f.delete(t), this.#a[i] = void 0, this.#i[i] = void 0, i === this.#p) this.#p = this.#E[i];
1317
- else if (i === this.#b) this.#b = this.#d[i];
1318
- else {
1319
- let o = this.#E[i];
1320
- this.#d[o] = this.#d[i];
1321
- let h = this.#d[i];
1322
- this.#E[h] = this.#E[i];
1323
- }
1324
- this.#h--, this.#R.push(i);
1325
- }
1326
- }
1327
- if (this.#e && this.#m?.length) {
1328
- let i = this.#m, r;
1329
- for (; r = i?.shift(); ) this.#o?.(...r);
1330
- }
1331
- return s;
1332
- }
1333
- clear() {
1334
- return this.#H("delete");
1335
- }
1336
- #H(t) {
1337
- for (let e of this.#D({ allowStale: true })) {
1338
- let s = this.#i[e];
1339
- if (this.#l(s)) s.__abortController.abort(new Error("deleted"));
1340
- else {
1341
- let i = this.#a[e];
1342
- this.#x && this.#n?.(s, i, t), this.#e && this.#m?.push([s, i, t]);
1343
- }
1344
- }
1345
- if (this.#f.clear(), this.#i.fill(void 0), this.#a.fill(void 0), this.#g && this.#T) {
1346
- this.#g.fill(0), this.#T.fill(0);
1347
- for (let e of this.#y ?? []) e !== void 0 && clearTimeout(e);
1348
- this.#y?.fill(void 0);
1349
- }
1350
- if (this.#C && this.#C.fill(0), this.#b = 0, this.#p = 0, this.#R.length = 0, this.#u = 0, this.#h = 0, this.#e && this.#m) {
1351
- let e = this.#m, s;
1352
- for (; s = e?.shift(); ) this.#o?.(...s);
1353
- }
1354
- }
1355
- };
1356
- var Ne = typeof process == "object" && process ? process : { stdout: null, stderr: null };
1357
- var oi = (n7) => !!n7 && typeof n7 == "object" && (n7 instanceof V || n7 instanceof Pe || hi(n7) || ai(n7));
1358
- var hi = (n7) => !!n7 && typeof n7 == "object" && n7 instanceof ee && typeof n7.pipe == "function" && n7.pipe !== Pe.Writable.prototype.pipe;
1359
- var ai = (n7) => !!n7 && typeof n7 == "object" && n7 instanceof ee && typeof n7.write == "function" && typeof n7.end == "function";
1360
- var G = /* @__PURE__ */ Symbol("EOF");
1361
- var H = /* @__PURE__ */ Symbol("maybeEmitEnd");
1362
- var K = /* @__PURE__ */ Symbol("emittedEnd");
1363
- var kt = /* @__PURE__ */ Symbol("emittingEnd");
1364
- var ut = /* @__PURE__ */ Symbol("emittedError");
1365
- var Rt = /* @__PURE__ */ Symbol("closed");
1366
- var _e = /* @__PURE__ */ Symbol("read");
1367
- var Ot = /* @__PURE__ */ Symbol("flush");
1368
- var Le = /* @__PURE__ */ Symbol("flushChunk");
1369
- var P = /* @__PURE__ */ Symbol("encoding");
1370
- var et = /* @__PURE__ */ Symbol("decoder");
1371
- var v = /* @__PURE__ */ Symbol("flowing");
1372
- var dt = /* @__PURE__ */ Symbol("paused");
1373
- var st = /* @__PURE__ */ Symbol("resume");
1374
- var C = /* @__PURE__ */ Symbol("buffer");
1375
- var F = /* @__PURE__ */ Symbol("pipes");
1376
- var T = /* @__PURE__ */ Symbol("bufferLength");
1377
- var Yt = /* @__PURE__ */ Symbol("bufferPush");
1378
- var Ft = /* @__PURE__ */ Symbol("bufferShift");
1379
- var k = /* @__PURE__ */ Symbol("objectMode");
1380
- var x = /* @__PURE__ */ Symbol("destroyed");
1381
- var Xt = /* @__PURE__ */ Symbol("error");
1382
- var Jt = /* @__PURE__ */ Symbol("emitData");
1383
- var We = /* @__PURE__ */ Symbol("emitEnd");
1384
- var Zt = /* @__PURE__ */ Symbol("emitEnd2");
1385
- var B = /* @__PURE__ */ Symbol("async");
1386
- var Qt = /* @__PURE__ */ Symbol("abort");
1387
- var Dt = /* @__PURE__ */ Symbol("aborted");
1388
- var pt = /* @__PURE__ */ Symbol("signal");
1389
- var Y = /* @__PURE__ */ Symbol("dataListeners");
1390
- var M = /* @__PURE__ */ Symbol("discarded");
1391
- var mt = (n7) => Promise.resolve().then(n7);
1392
- var li = (n7) => n7();
1393
- var ci = (n7) => n7 === "end" || n7 === "finish" || n7 === "prefinish";
1394
- var fi = (n7) => n7 instanceof ArrayBuffer || !!n7 && typeof n7 == "object" && n7.constructor && n7.constructor.name === "ArrayBuffer" && n7.byteLength >= 0;
1395
- var ui = (n7) => !Buffer.isBuffer(n7) && ArrayBuffer.isView(n7);
1396
- var Mt = class {
1397
- src;
1398
- dest;
1399
- opts;
1400
- ondrain;
1401
- constructor(t, e, s) {
1402
- this.src = t, this.dest = e, this.opts = s, this.ondrain = () => t[st](), this.dest.on("drain", this.ondrain);
1403
- }
1404
- unpipe() {
1405
- this.dest.removeListener("drain", this.ondrain);
1406
- }
1407
- proxyErrors(t) {
1408
- }
1409
- end() {
1410
- this.unpipe(), this.opts.end && this.dest.end();
1411
- }
1412
- };
1413
- var te = class extends Mt {
1414
- unpipe() {
1415
- this.src.removeListener("error", this.proxyErrors), super.unpipe();
1416
- }
1417
- constructor(t, e, s) {
1418
- super(t, e, s), this.proxyErrors = (i) => e.emit("error", i), t.on("error", this.proxyErrors);
1419
- }
1420
- };
1421
- var di = (n7) => !!n7.objectMode;
1422
- var pi = (n7) => !n7.objectMode && !!n7.encoding && n7.encoding !== "buffer";
1423
- var V = class extends ee {
1424
- [v] = false;
1425
- [dt] = false;
1426
- [F] = [];
1427
- [C] = [];
1428
- [k];
1429
- [P];
1430
- [B];
1431
- [et];
1432
- [G] = false;
1433
- [K] = false;
1434
- [kt] = false;
1435
- [Rt] = false;
1436
- [ut] = null;
1437
- [T] = 0;
1438
- [x] = false;
1439
- [pt];
1440
- [Dt] = false;
1441
- [Y] = 0;
1442
- [M] = false;
1443
- writable = true;
1444
- readable = true;
1445
- constructor(...t) {
1446
- let e = t[0] || {};
1447
- if (super(), e.objectMode && typeof e.encoding == "string") throw new TypeError("Encoding and objectMode may not be used together");
1448
- di(e) ? (this[k] = true, this[P] = null) : pi(e) ? (this[P] = e.encoding, this[k] = false) : (this[k] = false, this[P] = null), this[B] = !!e.async, this[et] = this[P] ? new ni(this[P]) : null, e && e.debugExposeBuffer === true && Object.defineProperty(this, "buffer", { get: () => this[C] }), e && e.debugExposePipes === true && Object.defineProperty(this, "pipes", { get: () => this[F] });
1449
- let { signal: s } = e;
1450
- s && (this[pt] = s, s.aborted ? this[Qt]() : s.addEventListener("abort", () => this[Qt]()));
1451
- }
1452
- get bufferLength() {
1453
- return this[T];
1454
- }
1455
- get encoding() {
1456
- return this[P];
1457
- }
1458
- set encoding(t) {
1459
- throw new Error("Encoding must be set at instantiation time");
1460
- }
1461
- setEncoding(t) {
1462
- throw new Error("Encoding must be set at instantiation time");
1463
- }
1464
- get objectMode() {
1465
- return this[k];
1466
- }
1467
- set objectMode(t) {
1468
- throw new Error("objectMode must be set at instantiation time");
1469
- }
1470
- get async() {
1471
- return this[B];
1472
- }
1473
- set async(t) {
1474
- this[B] = this[B] || !!t;
1475
- }
1476
- [Qt]() {
1477
- this[Dt] = true, this.emit("abort", this[pt]?.reason), this.destroy(this[pt]?.reason);
1478
- }
1479
- get aborted() {
1480
- return this[Dt];
1481
- }
1482
- set aborted(t) {
1483
- }
1484
- write(t, e, s) {
1485
- if (this[Dt]) return false;
1486
- if (this[G]) throw new Error("write after end");
1487
- if (this[x]) return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true;
1488
- typeof e == "function" && (s = e, e = "utf8"), e || (e = "utf8");
1489
- let i = this[B] ? mt : li;
1490
- if (!this[k] && !Buffer.isBuffer(t)) {
1491
- if (ui(t)) t = Buffer.from(t.buffer, t.byteOffset, t.byteLength);
1492
- else if (fi(t)) t = Buffer.from(t);
1493
- else if (typeof t != "string") throw new Error("Non-contiguous data written to non-objectMode stream");
1494
- }
1495
- return this[k] ? (this[v] && this[T] !== 0 && this[Ot](true), this[v] ? this.emit("data", t) : this[Yt](t), this[T] !== 0 && this.emit("readable"), s && i(s), this[v]) : t.length ? (typeof t == "string" && !(e === this[P] && !this[et]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[P] && (t = this[et].write(t)), this[v] && this[T] !== 0 && this[Ot](true), this[v] ? this.emit("data", t) : this[Yt](t), this[T] !== 0 && this.emit("readable"), s && i(s), this[v]) : (this[T] !== 0 && this.emit("readable"), s && i(s), this[v]);
1496
- }
1497
- read(t) {
1498
- if (this[x]) return null;
1499
- if (this[M] = false, this[T] === 0 || t === 0 || t && t > this[T]) return this[H](), null;
1500
- this[k] && (t = null), this[C].length > 1 && !this[k] && (this[C] = [this[P] ? this[C].join("") : Buffer.concat(this[C], this[T])]);
1501
- let e = this[_e](t || null, this[C][0]);
1502
- return this[H](), e;
1503
- }
1504
- [_e](t, e) {
1505
- if (this[k]) this[Ft]();
1506
- else {
1507
- let s = e;
1508
- t === s.length || t === null ? this[Ft]() : typeof s == "string" ? (this[C][0] = s.slice(t), e = s.slice(0, t), this[T] -= t) : (this[C][0] = s.subarray(t), e = s.subarray(0, t), this[T] -= t);
1509
- }
1510
- return this.emit("data", e), !this[C].length && !this[G] && this.emit("drain"), e;
1511
- }
1512
- end(t, e, s) {
1513
- return typeof t == "function" && (s = t, t = void 0), typeof e == "function" && (s = e, e = "utf8"), t !== void 0 && this.write(t, e), s && this.once("end", s), this[G] = true, this.writable = false, (this[v] || !this[dt]) && this[H](), this;
1514
- }
1515
- [st]() {
1516
- this[x] || (!this[Y] && !this[F].length && (this[M] = true), this[dt] = false, this[v] = true, this.emit("resume"), this[C].length ? this[Ot]() : this[G] ? this[H]() : this.emit("drain"));
1517
- }
1518
- resume() {
1519
- return this[st]();
1520
- }
1521
- pause() {
1522
- this[v] = false, this[dt] = true, this[M] = false;
1523
- }
1524
- get destroyed() {
1525
- return this[x];
1526
- }
1527
- get flowing() {
1528
- return this[v];
1529
- }
1530
- get paused() {
1531
- return this[dt];
1532
- }
1533
- [Yt](t) {
1534
- this[k] ? this[T] += 1 : this[T] += t.length, this[C].push(t);
1535
- }
1536
- [Ft]() {
1537
- return this[k] ? this[T] -= 1 : this[T] -= this[C][0].length, this[C].shift();
1538
- }
1539
- [Ot](t = false) {
1540
- do
1541
- ;
1542
- while (this[Le](this[Ft]()) && this[C].length);
1543
- !t && !this[C].length && !this[G] && this.emit("drain");
1544
- }
1545
- [Le](t) {
1546
- return this.emit("data", t), this[v];
1547
- }
1548
- pipe(t, e) {
1549
- if (this[x]) return t;
1550
- this[M] = false;
1551
- let s = this[K];
1552
- return e = e || {}, t === Ne.stdout || t === Ne.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, s ? e.end && t.end() : (this[F].push(e.proxyErrors ? new te(this, t, e) : new Mt(this, t, e)), this[B] ? mt(() => this[st]()) : this[st]()), t;
1553
- }
1554
- unpipe(t) {
1555
- let e = this[F].find((s) => s.dest === t);
1556
- e && (this[F].length === 1 ? (this[v] && this[Y] === 0 && (this[v] = false), this[F] = []) : this[F].splice(this[F].indexOf(e), 1), e.unpipe());
1557
- }
1558
- addListener(t, e) {
1559
- return this.on(t, e);
1560
- }
1561
- on(t, e) {
1562
- let s = super.on(t, e);
1563
- if (t === "data") this[M] = false, this[Y]++, !this[F].length && !this[v] && this[st]();
1564
- else if (t === "readable" && this[T] !== 0) super.emit("readable");
1565
- else if (ci(t) && this[K]) super.emit(t), this.removeAllListeners(t);
1566
- else if (t === "error" && this[ut]) {
1567
- let i = e;
1568
- this[B] ? mt(() => i.call(this, this[ut])) : i.call(this, this[ut]);
1569
- }
1570
- return s;
1571
- }
1572
- removeListener(t, e) {
1573
- return this.off(t, e);
1574
- }
1575
- off(t, e) {
1576
- let s = super.off(t, e);
1577
- return t === "data" && (this[Y] = this.listeners("data").length, this[Y] === 0 && !this[M] && !this[F].length && (this[v] = false)), s;
1578
- }
1579
- removeAllListeners(t) {
1580
- let e = super.removeAllListeners(t);
1581
- return (t === "data" || t === void 0) && (this[Y] = 0, !this[M] && !this[F].length && (this[v] = false)), e;
1582
- }
1583
- get emittedEnd() {
1584
- return this[K];
1585
- }
1586
- [H]() {
1587
- !this[kt] && !this[K] && !this[x] && this[C].length === 0 && this[G] && (this[kt] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Rt] && this.emit("close"), this[kt] = false);
1588
- }
1589
- emit(t, ...e) {
1590
- let s = e[0];
1591
- if (t !== "error" && t !== "close" && t !== x && this[x]) return false;
1592
- if (t === "data") return !this[k] && !s ? false : this[B] ? (mt(() => this[Jt](s)), true) : this[Jt](s);
1593
- if (t === "end") return this[We]();
1594
- if (t === "close") {
1595
- if (this[Rt] = true, !this[K] && !this[x]) return false;
1596
- let r = super.emit("close");
1597
- return this.removeAllListeners("close"), r;
1598
- } else if (t === "error") {
1599
- this[ut] = s, super.emit(Xt, s);
1600
- let r = !this[pt] || this.listeners("error").length ? super.emit("error", s) : false;
1601
- return this[H](), r;
1602
- } else if (t === "resume") {
1603
- let r = super.emit("resume");
1604
- return this[H](), r;
1605
- } else if (t === "finish" || t === "prefinish") {
1606
- let r = super.emit(t);
1607
- return this.removeAllListeners(t), r;
1608
- }
1609
- let i = super.emit(t, ...e);
1610
- return this[H](), i;
1611
- }
1612
- [Jt](t) {
1613
- for (let s of this[F]) s.dest.write(t) === false && this.pause();
1614
- let e = this[M] ? false : super.emit("data", t);
1615
- return this[H](), e;
1616
- }
1617
- [We]() {
1618
- return this[K] ? false : (this[K] = true, this.readable = false, this[B] ? (mt(() => this[Zt]()), true) : this[Zt]());
1619
- }
1620
- [Zt]() {
1621
- if (this[et]) {
1622
- let e = this[et].end();
1623
- if (e) {
1624
- for (let s of this[F]) s.dest.write(e);
1625
- this[M] || super.emit("data", e);
1626
- }
1627
- }
1628
- for (let e of this[F]) e.end();
1629
- let t = super.emit("end");
1630
- return this.removeAllListeners("end"), t;
1631
- }
1632
- async collect() {
1633
- let t = Object.assign([], { dataLength: 0 });
1634
- this[k] || (t.dataLength = 0);
1635
- let e = this.promise();
1636
- return this.on("data", (s) => {
1637
- t.push(s), this[k] || (t.dataLength += s.length);
1638
- }), await e, t;
1639
- }
1640
- async concat() {
1641
- if (this[k]) throw new Error("cannot concat in objectMode");
1642
- let t = await this.collect();
1643
- return this[P] ? t.join("") : Buffer.concat(t, t.dataLength);
1644
- }
1645
- async promise() {
1646
- return new Promise((t, e) => {
1647
- this.on(x, () => e(new Error("stream destroyed"))), this.on("error", (s) => e(s)), this.on("end", () => t());
1648
- });
1649
- }
1650
- [Symbol.asyncIterator]() {
1651
- this[M] = false;
1652
- let t = false, e = async () => (this.pause(), t = true, { value: void 0, done: true });
1653
- return { next: () => {
1654
- if (t) return e();
1655
- let i = this.read();
1656
- if (i !== null) return Promise.resolve({ done: false, value: i });
1657
- if (this[G]) return e();
1658
- let r, o, h = (c) => {
1659
- this.off("data", a), this.off("end", l), this.off(x, u), e(), o(c);
1660
- }, a = (c) => {
1661
- this.off("error", h), this.off("end", l), this.off(x, u), this.pause(), r({ value: c, done: !!this[G] });
1662
- }, l = () => {
1663
- this.off("error", h), this.off("data", a), this.off(x, u), e(), r({ done: true, value: void 0 });
1664
- }, u = () => h(new Error("stream destroyed"));
1665
- return new Promise((c, d) => {
1666
- o = d, r = c, this.once(x, u), this.once("error", h), this.once("end", l), this.once("data", a);
1667
- });
1668
- }, throw: e, return: e, [Symbol.asyncIterator]() {
1669
- return this;
1670
- } };
1671
- }
1672
- [Symbol.iterator]() {
1673
- this[M] = false;
1674
- let t = false, e = () => (this.pause(), this.off(Xt, e), this.off(x, e), this.off("end", e), t = true, { done: true, value: void 0 }), s = () => {
1675
- if (t) return e();
1676
- let i = this.read();
1677
- return i === null ? e() : { done: false, value: i };
1678
- };
1679
- return this.once("end", e), this.once(Xt, e), this.once(x, e), { next: s, throw: e, return: e, [Symbol.iterator]() {
1680
- return this;
1681
- } };
1682
- }
1683
- destroy(t) {
1684
- if (this[x]) return t ? this.emit("error", t) : this.emit(x), this;
1685
- this[x] = true, this[M] = true, this[C].length = 0, this[T] = 0;
1686
- let e = this;
1687
- return typeof e.close == "function" && !this[Rt] && e.close(), t ? this.emit("error", t) : this.emit(x), this;
1688
- }
1689
- static get isStream() {
1690
- return oi;
1691
- }
1692
- };
1693
- var vi = Ei.native;
1694
- var wt = { lstatSync: wi, readdir: yi, readdirSync: bi, readlinkSync: Si, realpathSync: vi, promises: { lstat: Ci, readdir: Ti, readlink: Ai, realpath: ki } };
1695
- var Ue = (n7) => !n7 || n7 === wt || n7 === xi ? wt : { ...wt, ...n7, promises: { ...wt.promises, ...n7.promises || {} } };
1696
- var $e = /^\\\\\?\\([a-z]:)\\?$/i;
1697
- var Ri = (n7) => n7.replace(/\//g, "\\").replace($e, "$1\\");
1698
- var Oi = /[\\\/]/;
1699
- var L = 0;
1700
- var Ge = 1;
1701
- var He = 2;
1702
- var U = 4;
1703
- var qe = 6;
1704
- var Ke = 8;
1705
- var X = 10;
1706
- var Ve = 12;
1707
- var _ = 15;
1708
- var gt = ~_;
1709
- var se = 16;
1710
- var je = 32;
1711
- var yt = 64;
1712
- var j = 128;
1713
- var Nt = 256;
1714
- var Lt = 512;
1715
- var Ie = yt | j | Lt;
1716
- var Fi = 1023;
1717
- var ie = (n7) => n7.isFile() ? Ke : n7.isDirectory() ? U : n7.isSymbolicLink() ? X : n7.isCharacterDevice() ? He : n7.isBlockDevice() ? qe : n7.isSocket() ? Ve : n7.isFIFO() ? Ge : L;
1718
- var ze = new ft({ max: 2 ** 12 });
1719
- var bt = (n7) => {
1720
- let t = ze.get(n7);
1721
- if (t) return t;
1722
- let e = n7.normalize("NFKD");
1723
- return ze.set(n7, e), e;
1724
- };
1725
- var Be = new ft({ max: 2 ** 12 });
1726
- var _t = (n7) => {
1727
- let t = Be.get(n7);
1728
- if (t) return t;
1729
- let e = bt(n7.toLowerCase());
1730
- return Be.set(n7, e), e;
1731
- };
1732
- var Wt = class extends ft {
1733
- constructor() {
1734
- super({ max: 256 });
1735
- }
1736
- };
1737
- var ne = class extends ft {
1738
- constructor(t = 16 * 1024) {
1739
- super({ maxSize: t, sizeCalculation: (e) => e.length + 1 });
1740
- }
1741
- };
1742
- var Ye = /* @__PURE__ */ Symbol("PathScurry setAsCwd");
1743
- var R = class {
1744
- name;
1745
- root;
1746
- roots;
1747
- parent;
1748
- nocase;
1749
- isCWD = false;
1750
- #t;
1751
- #s;
1752
- get dev() {
1753
- return this.#s;
1754
- }
1755
- #n;
1756
- get mode() {
1757
- return this.#n;
1758
- }
1759
- #r;
1760
- get nlink() {
1761
- return this.#r;
1762
- }
1763
- #o;
1764
- get uid() {
1765
- return this.#o;
1766
- }
1767
- #S;
1768
- get gid() {
1769
- return this.#S;
1770
- }
1771
- #w;
1772
- get rdev() {
1773
- return this.#w;
1774
- }
1775
- #c;
1776
- get blksize() {
1777
- return this.#c;
1778
- }
1779
- #h;
1780
- get ino() {
1781
- return this.#h;
1782
- }
1783
- #u;
1784
- get size() {
1785
- return this.#u;
1786
- }
1787
- #f;
1788
- get blocks() {
1789
- return this.#f;
1790
- }
1791
- #a;
1792
- get atimeMs() {
1793
- return this.#a;
1794
- }
1795
- #i;
1796
- get mtimeMs() {
1797
- return this.#i;
1798
- }
1799
- #d;
1800
- get ctimeMs() {
1801
- return this.#d;
1802
- }
1803
- #E;
1804
- get birthtimeMs() {
1805
- return this.#E;
1806
- }
1807
- #b;
1808
- get atime() {
1809
- return this.#b;
1810
- }
1811
- #p;
1812
- get mtime() {
1813
- return this.#p;
1814
- }
1815
- #R;
1816
- get ctime() {
1817
- return this.#R;
1818
- }
1819
- #m;
1820
- get birthtime() {
1821
- return this.#m;
1822
- }
1823
- #C;
1824
- #T;
1825
- #g;
1826
- #y;
1827
- #x;
1828
- #A;
1829
- #e;
1830
- #_;
1831
- #M;
1832
- #k;
1833
- get parentPath() {
1834
- return (this.parent || this).fullpath();
1835
- }
1836
- get path() {
1837
- return this.parentPath;
1838
- }
1839
- constructor(t, e = L, s, i, r, o, h) {
1840
- this.name = t, this.#C = r ? _t(t) : bt(t), this.#e = e & Fi, this.nocase = r, this.roots = i, this.root = s || this, this.#_ = o, this.#g = h.fullpath, this.#x = h.relative, this.#A = h.relativePosix, this.parent = h.parent, this.parent ? this.#t = this.parent.#t : this.#t = Ue(h.fs);
1841
- }
1842
- depth() {
1843
- return this.#T !== void 0 ? this.#T : this.parent ? this.#T = this.parent.depth() + 1 : this.#T = 0;
1844
- }
1845
- childrenCache() {
1846
- return this.#_;
1847
- }
1848
- resolve(t) {
1849
- if (!t) return this;
1850
- let e = this.getRootString(t), i = t.substring(e.length).split(this.splitSep);
1851
- return e ? this.getRoot(e).#N(i) : this.#N(i);
1852
- }
1853
- #N(t) {
1854
- let e = this;
1855
- for (let s of t) e = e.child(s);
1856
- return e;
1857
- }
1858
- children() {
1859
- let t = this.#_.get(this);
1860
- if (t) return t;
1861
- let e = Object.assign([], { provisional: 0 });
1862
- return this.#_.set(this, e), this.#e &= ~se, e;
1863
- }
1864
- child(t, e) {
1865
- if (t === "" || t === ".") return this;
1866
- if (t === "..") return this.parent || this;
1867
- let s = this.children(), i = this.nocase ? _t(t) : bt(t);
1868
- for (let a of s) if (a.#C === i) return a;
1869
- let r = this.parent ? this.sep : "", o = this.#g ? this.#g + r + t : void 0, h = this.newChild(t, L, { ...e, parent: this, fullpath: o });
1870
- return this.canReaddir() || (h.#e |= j), s.push(h), h;
1871
- }
1872
- relative() {
1873
- if (this.isCWD) return "";
1874
- if (this.#x !== void 0) return this.#x;
1875
- let t = this.name, e = this.parent;
1876
- if (!e) return this.#x = this.name;
1877
- let s = e.relative();
1878
- return s + (!s || !e.parent ? "" : this.sep) + t;
1879
- }
1880
- relativePosix() {
1881
- if (this.sep === "/") return this.relative();
1882
- if (this.isCWD) return "";
1883
- if (this.#A !== void 0) return this.#A;
1884
- let t = this.name, e = this.parent;
1885
- if (!e) return this.#A = this.fullpathPosix();
1886
- let s = e.relativePosix();
1887
- return s + (!s || !e.parent ? "" : "/") + t;
1888
- }
1889
- fullpath() {
1890
- if (this.#g !== void 0) return this.#g;
1891
- let t = this.name, e = this.parent;
1892
- if (!e) return this.#g = this.name;
1893
- let i = e.fullpath() + (e.parent ? this.sep : "") + t;
1894
- return this.#g = i;
1895
- }
1896
- fullpathPosix() {
1897
- if (this.#y !== void 0) return this.#y;
1898
- if (this.sep === "/") return this.#y = this.fullpath();
1899
- if (!this.parent) {
1900
- let i = this.fullpath().replace(/\\/g, "/");
1901
- return /^[a-z]:\//i.test(i) ? this.#y = `//?/${i}` : this.#y = i;
1902
- }
1903
- let t = this.parent, e = t.fullpathPosix(), s = e + (!e || !t.parent ? "" : "/") + this.name;
1904
- return this.#y = s;
1905
- }
1906
- isUnknown() {
1907
- return (this.#e & _) === L;
1908
- }
1909
- isType(t) {
1910
- return this[`is${t}`]();
1911
- }
1912
- getType() {
1913
- return this.isUnknown() ? "Unknown" : this.isDirectory() ? "Directory" : this.isFile() ? "File" : this.isSymbolicLink() ? "SymbolicLink" : this.isFIFO() ? "FIFO" : this.isCharacterDevice() ? "CharacterDevice" : this.isBlockDevice() ? "BlockDevice" : this.isSocket() ? "Socket" : "Unknown";
1914
- }
1915
- isFile() {
1916
- return (this.#e & _) === Ke;
1917
- }
1918
- isDirectory() {
1919
- return (this.#e & _) === U;
1920
- }
1921
- isCharacterDevice() {
1922
- return (this.#e & _) === He;
1923
- }
1924
- isBlockDevice() {
1925
- return (this.#e & _) === qe;
1926
- }
1927
- isFIFO() {
1928
- return (this.#e & _) === Ge;
1929
- }
1930
- isSocket() {
1931
- return (this.#e & _) === Ve;
1932
- }
1933
- isSymbolicLink() {
1934
- return (this.#e & X) === X;
1935
- }
1936
- lstatCached() {
1937
- return this.#e & je ? this : void 0;
1938
- }
1939
- readlinkCached() {
1940
- return this.#M;
1941
- }
1942
- realpathCached() {
1943
- return this.#k;
1944
- }
1945
- readdirCached() {
1946
- let t = this.children();
1947
- return t.slice(0, t.provisional);
1948
- }
1949
- canReadlink() {
1950
- if (this.#M) return true;
1951
- if (!this.parent) return false;
1952
- let t = this.#e & _;
1953
- return !(t !== L && t !== X || this.#e & Nt || this.#e & j);
1954
- }
1955
- calledReaddir() {
1956
- return !!(this.#e & se);
1957
- }
1958
- isENOENT() {
1959
- return !!(this.#e & j);
1960
- }
1961
- isNamed(t) {
1962
- return this.nocase ? this.#C === _t(t) : this.#C === bt(t);
1963
- }
1964
- async readlink() {
1965
- let t = this.#M;
1966
- if (t) return t;
1967
- if (this.canReadlink() && this.parent) try {
1968
- let e = await this.#t.promises.readlink(this.fullpath()), s = (await this.parent.realpath())?.resolve(e);
1969
- if (s) return this.#M = s;
1970
- } catch (e) {
1971
- this.#D(e.code);
1972
- return;
1973
- }
1974
- }
1975
- readlinkSync() {
1976
- let t = this.#M;
1977
- if (t) return t;
1978
- if (this.canReadlink() && this.parent) try {
1979
- let e = this.#t.readlinkSync(this.fullpath()), s = this.parent.realpathSync()?.resolve(e);
1980
- if (s) return this.#M = s;
1981
- } catch (e) {
1982
- this.#D(e.code);
1983
- return;
1984
- }
1985
- }
1986
- #j(t) {
1987
- this.#e |= se;
1988
- for (let e = t.provisional; e < t.length; e++) {
1989
- let s = t[e];
1990
- s && s.#v();
1991
- }
1992
- }
1993
- #v() {
1994
- this.#e & j || (this.#e = (this.#e | j) & gt, this.#G());
1995
- }
1996
- #G() {
1997
- let t = this.children();
1998
- t.provisional = 0;
1999
- for (let e of t) e.#v();
2000
- }
2001
- #P() {
2002
- this.#e |= Lt, this.#L();
2003
- }
2004
- #L() {
2005
- if (this.#e & yt) return;
2006
- let t = this.#e;
2007
- (t & _) === U && (t &= gt), this.#e = t | yt, this.#G();
2008
- }
2009
- #I(t = "") {
2010
- t === "ENOTDIR" || t === "EPERM" ? this.#L() : t === "ENOENT" ? this.#v() : this.children().provisional = 0;
2011
- }
2012
- #F(t = "") {
2013
- t === "ENOTDIR" ? this.parent.#L() : t === "ENOENT" && this.#v();
2014
- }
2015
- #D(t = "") {
2016
- let e = this.#e;
2017
- e |= Nt, t === "ENOENT" && (e |= j), (t === "EINVAL" || t === "UNKNOWN") && (e &= gt), this.#e = e, t === "ENOTDIR" && this.parent && this.parent.#L();
2018
- }
2019
- #z(t, e) {
2020
- return this.#U(t, e) || this.#B(t, e);
2021
- }
2022
- #B(t, e) {
2023
- let s = ie(t), i = this.newChild(t.name, s, { parent: this }), r = i.#e & _;
2024
- return r !== U && r !== X && r !== L && (i.#e |= yt), e.unshift(i), e.provisional++, i;
2025
- }
2026
- #U(t, e) {
2027
- for (let s = e.provisional; s < e.length; s++) {
2028
- let i = e[s];
2029
- if ((this.nocase ? _t(t.name) : bt(t.name)) === i.#C) return this.#l(t, i, s, e);
2030
- }
2031
- }
2032
- #l(t, e, s, i) {
2033
- let r = e.name;
2034
- return e.#e = e.#e & gt | ie(t), r !== t.name && (e.name = t.name), s !== i.provisional && (s === i.length - 1 ? i.pop() : i.splice(s, 1), i.unshift(e)), i.provisional++, e;
2035
- }
2036
- async lstat() {
2037
- if ((this.#e & j) === 0) try {
2038
- return this.#$(await this.#t.promises.lstat(this.fullpath())), this;
2039
- } catch (t) {
2040
- this.#F(t.code);
2041
- }
2042
- }
2043
- lstatSync() {
2044
- if ((this.#e & j) === 0) try {
2045
- return this.#$(this.#t.lstatSync(this.fullpath())), this;
2046
- } catch (t) {
2047
- this.#F(t.code);
2048
- }
2049
- }
2050
- #$(t) {
2051
- let { atime: e, atimeMs: s, birthtime: i, birthtimeMs: r, blksize: o, blocks: h, ctime: a, ctimeMs: l, dev: u, gid: c, ino: d, mode: f, mtime: m, mtimeMs: p, nlink: w, rdev: g, size: S, uid: E } = t;
2052
- this.#b = e, this.#a = s, this.#m = i, this.#E = r, this.#c = o, this.#f = h, this.#R = a, this.#d = l, this.#s = u, this.#S = c, this.#h = d, this.#n = f, this.#p = m, this.#i = p, this.#r = w, this.#w = g, this.#u = S, this.#o = E;
2053
- let y = ie(t);
2054
- this.#e = this.#e & gt | y | je, y !== L && y !== U && y !== X && (this.#e |= yt);
2055
- }
2056
- #W = [];
2057
- #O = false;
2058
- #H(t) {
2059
- this.#O = false;
2060
- let e = this.#W.slice();
2061
- this.#W.length = 0, e.forEach((s) => s(null, t));
2062
- }
2063
- readdirCB(t, e = false) {
2064
- if (!this.canReaddir()) {
2065
- e ? t(null, []) : queueMicrotask(() => t(null, []));
2066
- return;
2067
- }
2068
- let s = this.children();
2069
- if (this.calledReaddir()) {
2070
- let r = s.slice(0, s.provisional);
2071
- e ? t(null, r) : queueMicrotask(() => t(null, r));
2072
- return;
2073
- }
2074
- if (this.#W.push(t), this.#O) return;
2075
- this.#O = true;
2076
- let i = this.fullpath();
2077
- this.#t.readdir(i, { withFileTypes: true }, (r, o) => {
2078
- if (r) this.#I(r.code), s.provisional = 0;
2079
- else {
2080
- for (let h of o) this.#z(h, s);
2081
- this.#j(s);
2082
- }
2083
- this.#H(s.slice(0, s.provisional));
2084
- });
2085
- }
2086
- #q;
2087
- async readdir() {
2088
- if (!this.canReaddir()) return [];
2089
- let t = this.children();
2090
- if (this.calledReaddir()) return t.slice(0, t.provisional);
2091
- let e = this.fullpath();
2092
- if (this.#q) await this.#q;
2093
- else {
2094
- let s = () => {
2095
- };
2096
- this.#q = new Promise((i) => s = i);
2097
- try {
2098
- for (let i of await this.#t.promises.readdir(e, { withFileTypes: true })) this.#z(i, t);
2099
- this.#j(t);
2100
- } catch (i) {
2101
- this.#I(i.code), t.provisional = 0;
2102
- }
2103
- this.#q = void 0, s();
2104
- }
2105
- return t.slice(0, t.provisional);
2106
- }
2107
- readdirSync() {
2108
- if (!this.canReaddir()) return [];
2109
- let t = this.children();
2110
- if (this.calledReaddir()) return t.slice(0, t.provisional);
2111
- let e = this.fullpath();
2112
- try {
2113
- for (let s of this.#t.readdirSync(e, { withFileTypes: true })) this.#z(s, t);
2114
- this.#j(t);
2115
- } catch (s) {
2116
- this.#I(s.code), t.provisional = 0;
2117
- }
2118
- return t.slice(0, t.provisional);
2119
- }
2120
- canReaddir() {
2121
- if (this.#e & Ie) return false;
2122
- let t = _ & this.#e;
2123
- return t === L || t === U || t === X;
2124
- }
2125
- shouldWalk(t, e) {
2126
- return (this.#e & U) === U && !(this.#e & Ie) && !t.has(this) && (!e || e(this));
2127
- }
2128
- async realpath() {
2129
- if (this.#k) return this.#k;
2130
- if (!((Lt | Nt | j) & this.#e)) try {
2131
- let t = await this.#t.promises.realpath(this.fullpath());
2132
- return this.#k = this.resolve(t);
2133
- } catch {
2134
- this.#P();
2135
- }
2136
- }
2137
- realpathSync() {
2138
- if (this.#k) return this.#k;
2139
- if (!((Lt | Nt | j) & this.#e)) try {
2140
- let t = this.#t.realpathSync(this.fullpath());
2141
- return this.#k = this.resolve(t);
2142
- } catch {
2143
- this.#P();
2144
- }
2145
- }
2146
- [Ye](t) {
2147
- if (t === this) return;
2148
- t.isCWD = false, this.isCWD = true;
2149
- let e = /* @__PURE__ */ new Set([]), s = [], i = this;
2150
- for (; i && i.parent; ) e.add(i), i.#x = s.join(this.sep), i.#A = s.join("/"), i = i.parent, s.push("..");
2151
- for (i = t; i && i.parent && !e.has(i); ) i.#x = void 0, i.#A = void 0, i = i.parent;
2152
- }
2153
- };
2154
- var Pt = class n2 extends R {
2155
- sep = "\\";
2156
- splitSep = Oi;
2157
- constructor(t, e = L, s, i, r, o, h) {
2158
- super(t, e, s, i, r, o, h);
2159
- }
2160
- newChild(t, e = L, s = {}) {
2161
- return new n2(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
2162
- }
2163
- getRootString(t) {
2164
- return re.parse(t).root;
2165
- }
2166
- getRoot(t) {
2167
- if (t = Ri(t.toUpperCase()), t === this.root.name) return this.root;
2168
- for (let [e, s] of Object.entries(this.roots)) if (this.sameRoot(t, e)) return this.roots[t] = s;
2169
- return this.roots[t] = new it(t, this).root;
2170
- }
2171
- sameRoot(t, e = this.root.name) {
2172
- return t = t.toUpperCase().replace(/\//g, "\\").replace($e, "$1\\"), t === e;
2173
- }
2174
- };
2175
- var jt = class n3 extends R {
2176
- splitSep = "/";
2177
- sep = "/";
2178
- constructor(t, e = L, s, i, r, o, h) {
2179
- super(t, e, s, i, r, o, h);
2180
- }
2181
- getRootString(t) {
2182
- return t.startsWith("/") ? "/" : "";
2183
- }
2184
- getRoot(t) {
2185
- return this.root;
2186
- }
2187
- newChild(t, e = L, s = {}) {
2188
- return new n3(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
2189
- }
2190
- };
2191
- var It = class {
2192
- root;
2193
- rootPath;
2194
- roots;
2195
- cwd;
2196
- #t;
2197
- #s;
2198
- #n;
2199
- nocase;
2200
- #r;
2201
- constructor(t = process.cwd(), e, s, { nocase: i, childrenCacheSize: r = 16 * 1024, fs: o = wt } = {}) {
2202
- this.#r = Ue(o), (t instanceof URL || t.startsWith("file://")) && (t = gi(t));
2203
- let h = e.resolve(t);
2204
- this.roots = /* @__PURE__ */ Object.create(null), this.rootPath = this.parseRootPath(h), this.#t = new Wt(), this.#s = new Wt(), this.#n = new ne(r);
2205
- let a = h.substring(this.rootPath.length).split(s);
2206
- if (a.length === 1 && !a[0] && a.pop(), i === void 0) throw new TypeError("must provide nocase setting to PathScurryBase ctor");
2207
- this.nocase = i, this.root = this.newRoot(this.#r), this.roots[this.rootPath] = this.root;
2208
- let l = this.root, u = a.length - 1, c = e.sep, d = this.rootPath, f = false;
2209
- for (let m of a) {
2210
- let p = u--;
2211
- l = l.child(m, { relative: new Array(p).fill("..").join(c), relativePosix: new Array(p).fill("..").join("/"), fullpath: d += (f ? "" : c) + m }), f = true;
2212
- }
2213
- this.cwd = l;
2214
- }
2215
- depth(t = this.cwd) {
2216
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.depth();
2217
- }
2218
- childrenCache() {
2219
- return this.#n;
2220
- }
2221
- resolve(...t) {
2222
- let e = "";
2223
- for (let r = t.length - 1; r >= 0; r--) {
2224
- let o = t[r];
2225
- if (!(!o || o === ".") && (e = e ? `${o}/${e}` : o, this.isAbsolute(o))) break;
2226
- }
2227
- let s = this.#t.get(e);
2228
- if (s !== void 0) return s;
2229
- let i = this.cwd.resolve(e).fullpath();
2230
- return this.#t.set(e, i), i;
2231
- }
2232
- resolvePosix(...t) {
2233
- let e = "";
2234
- for (let r = t.length - 1; r >= 0; r--) {
2235
- let o = t[r];
2236
- if (!(!o || o === ".") && (e = e ? `${o}/${e}` : o, this.isAbsolute(o))) break;
2237
- }
2238
- let s = this.#s.get(e);
2239
- if (s !== void 0) return s;
2240
- let i = this.cwd.resolve(e).fullpathPosix();
2241
- return this.#s.set(e, i), i;
2242
- }
2243
- relative(t = this.cwd) {
2244
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.relative();
2245
- }
2246
- relativePosix(t = this.cwd) {
2247
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.relativePosix();
2248
- }
2249
- basename(t = this.cwd) {
2250
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.name;
2251
- }
2252
- dirname(t = this.cwd) {
2253
- return typeof t == "string" && (t = this.cwd.resolve(t)), (t.parent || t).fullpath();
2254
- }
2255
- async readdir(t = this.cwd, e = { withFileTypes: true }) {
2256
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2257
- let { withFileTypes: s } = e;
2258
- if (t.canReaddir()) {
2259
- let i = await t.readdir();
2260
- return s ? i : i.map((r) => r.name);
2261
- } else return [];
2262
- }
2263
- readdirSync(t = this.cwd, e = { withFileTypes: true }) {
2264
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2265
- let { withFileTypes: s = true } = e;
2266
- return t.canReaddir() ? s ? t.readdirSync() : t.readdirSync().map((i) => i.name) : [];
2267
- }
2268
- async lstat(t = this.cwd) {
2269
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.lstat();
2270
- }
2271
- lstatSync(t = this.cwd) {
2272
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.lstatSync();
2273
- }
2274
- async readlink(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
2275
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
2276
- let s = await t.readlink();
2277
- return e ? s : s?.fullpath();
2278
- }
2279
- readlinkSync(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
2280
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
2281
- let s = t.readlinkSync();
2282
- return e ? s : s?.fullpath();
2283
- }
2284
- async realpath(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
2285
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
2286
- let s = await t.realpath();
2287
- return e ? s : s?.fullpath();
2288
- }
2289
- realpathSync(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
2290
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
2291
- let s = t.realpathSync();
2292
- return e ? s : s?.fullpath();
2293
- }
2294
- async walk(t = this.cwd, e = {}) {
2295
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2296
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = [];
2297
- (!r || r(t)) && h.push(s ? t : t.fullpath());
2298
- let a = /* @__PURE__ */ new Set(), l = (c, d) => {
2299
- a.add(c), c.readdirCB((f, m) => {
2300
- if (f) return d(f);
2301
- let p = m.length;
2302
- if (!p) return d();
2303
- let w = () => {
2304
- --p === 0 && d();
2305
- };
2306
- for (let g of m) (!r || r(g)) && h.push(s ? g : g.fullpath()), i && g.isSymbolicLink() ? g.realpath().then((S) => S?.isUnknown() ? S.lstat() : S).then((S) => S?.shouldWalk(a, o) ? l(S, w) : w()) : g.shouldWalk(a, o) ? l(g, w) : w();
2307
- }, true);
2308
- }, u = t;
2309
- return new Promise((c, d) => {
2310
- l(u, (f) => {
2311
- if (f) return d(f);
2312
- c(h);
2313
- });
2314
- });
2315
- }
2316
- walkSync(t = this.cwd, e = {}) {
2317
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2318
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = [];
2319
- (!r || r(t)) && h.push(s ? t : t.fullpath());
2320
- let a = /* @__PURE__ */ new Set([t]);
2321
- for (let l of a) {
2322
- let u = l.readdirSync();
2323
- for (let c of u) {
2324
- (!r || r(c)) && h.push(s ? c : c.fullpath());
2325
- let d = c;
2326
- if (c.isSymbolicLink()) {
2327
- if (!(i && (d = c.realpathSync()))) continue;
2328
- d.isUnknown() && d.lstatSync();
2329
- }
2330
- d.shouldWalk(a, o) && a.add(d);
2331
- }
2332
- }
2333
- return h;
2334
- }
2335
- [Symbol.asyncIterator]() {
2336
- return this.iterate();
2337
- }
2338
- iterate(t = this.cwd, e = {}) {
2339
- return typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd), this.stream(t, e)[Symbol.asyncIterator]();
2340
- }
2341
- [Symbol.iterator]() {
2342
- return this.iterateSync();
2343
- }
2344
- *iterateSync(t = this.cwd, e = {}) {
2345
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2346
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e;
2347
- (!r || r(t)) && (yield s ? t : t.fullpath());
2348
- let h = /* @__PURE__ */ new Set([t]);
2349
- for (let a of h) {
2350
- let l = a.readdirSync();
2351
- for (let u of l) {
2352
- (!r || r(u)) && (yield s ? u : u.fullpath());
2353
- let c = u;
2354
- if (u.isSymbolicLink()) {
2355
- if (!(i && (c = u.realpathSync()))) continue;
2356
- c.isUnknown() && c.lstatSync();
2357
- }
2358
- c.shouldWalk(h, o) && h.add(c);
2359
- }
2360
- }
2361
- }
2362
- stream(t = this.cwd, e = {}) {
2363
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2364
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = new V({ objectMode: true });
2365
- (!r || r(t)) && h.write(s ? t : t.fullpath());
2366
- let a = /* @__PURE__ */ new Set(), l = [t], u = 0, c = () => {
2367
- let d = false;
2368
- for (; !d; ) {
2369
- let f = l.shift();
2370
- if (!f) {
2371
- u === 0 && h.end();
2372
- return;
2373
- }
2374
- u++, a.add(f);
2375
- let m = (w, g, S = false) => {
2376
- if (w) return h.emit("error", w);
2377
- if (i && !S) {
2378
- let E = [];
2379
- for (let y of g) y.isSymbolicLink() && E.push(y.realpath().then((b) => b?.isUnknown() ? b.lstat() : b));
2380
- if (E.length) {
2381
- Promise.all(E).then(() => m(null, g, true));
2382
- return;
2383
- }
2384
- }
2385
- for (let E of g) E && (!r || r(E)) && (h.write(s ? E : E.fullpath()) || (d = true));
2386
- u--;
2387
- for (let E of g) {
2388
- let y = E.realpathCached() || E;
2389
- y.shouldWalk(a, o) && l.push(y);
2390
- }
2391
- d && !h.flowing ? h.once("drain", c) : p || c();
2392
- }, p = true;
2393
- f.readdirCB(m, true), p = false;
2394
- }
2395
- };
2396
- return c(), h;
2397
- }
2398
- streamSync(t = this.cwd, e = {}) {
2399
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
2400
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = new V({ objectMode: true }), a = /* @__PURE__ */ new Set();
2401
- (!r || r(t)) && h.write(s ? t : t.fullpath());
2402
- let l = [t], u = 0, c = () => {
2403
- let d = false;
2404
- for (; !d; ) {
2405
- let f = l.shift();
2406
- if (!f) {
2407
- u === 0 && h.end();
2408
- return;
2409
- }
2410
- u++, a.add(f);
2411
- let m = f.readdirSync();
2412
- for (let p of m) (!r || r(p)) && (h.write(s ? p : p.fullpath()) || (d = true));
2413
- u--;
2414
- for (let p of m) {
2415
- let w = p;
2416
- if (p.isSymbolicLink()) {
2417
- if (!(i && (w = p.realpathSync()))) continue;
2418
- w.isUnknown() && w.lstatSync();
2419
- }
2420
- w.shouldWalk(a, o) && l.push(w);
2421
- }
2422
- }
2423
- d && !h.flowing && h.once("drain", c);
2424
- };
2425
- return c(), h;
2426
- }
2427
- chdir(t = this.cwd) {
2428
- let e = this.cwd;
2429
- this.cwd = typeof t == "string" ? this.cwd.resolve(t) : t, this.cwd[Ye](e);
2430
- }
2431
- };
2432
- var it = class extends It {
2433
- sep = "\\";
2434
- constructor(t = process.cwd(), e = {}) {
2435
- let { nocase: s = true } = e;
2436
- super(t, re, "\\", { ...e, nocase: s }), this.nocase = s;
2437
- for (let i = this.cwd; i; i = i.parent) i.nocase = this.nocase;
2438
- }
2439
- parseRootPath(t) {
2440
- return re.parse(t).root.toUpperCase();
2441
- }
2442
- newRoot(t) {
2443
- return new Pt(this.rootPath, U, void 0, this.roots, this.nocase, this.childrenCache(), { fs: t });
2444
- }
2445
- isAbsolute(t) {
2446
- return t.startsWith("/") || t.startsWith("\\") || /^[a-z]:(\/|\\)/i.test(t);
2447
- }
2448
- };
2449
- var rt = class extends It {
2450
- sep = "/";
2451
- constructor(t = process.cwd(), e = {}) {
2452
- let { nocase: s = false } = e;
2453
- super(t, mi, "/", { ...e, nocase: s }), this.nocase = s;
2454
- }
2455
- parseRootPath(t) {
2456
- return "/";
2457
- }
2458
- newRoot(t) {
2459
- return new jt(this.rootPath, U, void 0, this.roots, this.nocase, this.childrenCache(), { fs: t });
2460
- }
2461
- isAbsolute(t) {
2462
- return t.startsWith("/");
2463
- }
2464
- };
2465
- var St = class extends rt {
2466
- constructor(t = process.cwd(), e = {}) {
2467
- let { nocase: s = true } = e;
2468
- super(t, { ...e, nocase: s });
2469
- }
2470
- };
2471
- var Cr = process.platform === "win32" ? Pt : jt;
2472
- var Xe = process.platform === "win32" ? it : process.platform === "darwin" ? St : rt;
2473
- var Di = (n7) => n7.length >= 1;
2474
- var Mi = (n7) => n7.length >= 1;
2475
- var Ni = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
2476
- var nt = class n4 {
2477
- #t;
2478
- #s;
2479
- #n;
2480
- length;
2481
- #r;
2482
- #o;
2483
- #S;
2484
- #w;
2485
- #c;
2486
- #h;
2487
- #u = true;
2488
- constructor(t, e, s, i) {
2489
- if (!Di(t)) throw new TypeError("empty pattern list");
2490
- if (!Mi(e)) throw new TypeError("empty glob list");
2491
- if (e.length !== t.length) throw new TypeError("mismatched pattern list and glob list lengths");
2492
- if (this.length = t.length, s < 0 || s >= this.length) throw new TypeError("index out of range");
2493
- if (this.#t = t, this.#s = e, this.#n = s, this.#r = i, this.#n === 0) {
2494
- if (this.isUNC()) {
2495
- let [r, o, h, a, ...l] = this.#t, [u, c, d, f, ...m] = this.#s;
2496
- l[0] === "" && (l.shift(), m.shift());
2497
- let p = [r, o, h, a, ""].join("/"), w = [u, c, d, f, ""].join("/");
2498
- this.#t = [p, ...l], this.#s = [w, ...m], this.length = this.#t.length;
2499
- } else if (this.isDrive() || this.isAbsolute()) {
2500
- let [r, ...o] = this.#t, [h, ...a] = this.#s;
2501
- o[0] === "" && (o.shift(), a.shift());
2502
- let l = r + "/", u = h + "/";
2503
- this.#t = [l, ...o], this.#s = [u, ...a], this.length = this.#t.length;
2504
- }
2505
- }
2506
- }
2507
- [Ni]() {
2508
- return "Pattern <" + this.#s.slice(this.#n).join("/") + ">";
2509
- }
2510
- pattern() {
2511
- return this.#t[this.#n];
2512
- }
2513
- isString() {
2514
- return typeof this.#t[this.#n] == "string";
2515
- }
2516
- isGlobstar() {
2517
- return this.#t[this.#n] === A;
2518
- }
2519
- isRegExp() {
2520
- return this.#t[this.#n] instanceof RegExp;
2521
- }
2522
- globString() {
2523
- return this.#S = this.#S || (this.#n === 0 ? this.isAbsolute() ? this.#s[0] + this.#s.slice(1).join("/") : this.#s.join("/") : this.#s.slice(this.#n).join("/"));
2524
- }
2525
- hasMore() {
2526
- return this.length > this.#n + 1;
2527
- }
2528
- rest() {
2529
- return this.#o !== void 0 ? this.#o : this.hasMore() ? (this.#o = new n4(this.#t, this.#s, this.#n + 1, this.#r), this.#o.#h = this.#h, this.#o.#c = this.#c, this.#o.#w = this.#w, this.#o) : this.#o = null;
2530
- }
2531
- isUNC() {
2532
- let t = this.#t;
2533
- return this.#c !== void 0 ? this.#c : this.#c = this.#r === "win32" && this.#n === 0 && t[0] === "" && t[1] === "" && typeof t[2] == "string" && !!t[2] && typeof t[3] == "string" && !!t[3];
2534
- }
2535
- isDrive() {
2536
- let t = this.#t;
2537
- return this.#w !== void 0 ? this.#w : this.#w = this.#r === "win32" && this.#n === 0 && this.length > 1 && typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]);
2538
- }
2539
- isAbsolute() {
2540
- let t = this.#t;
2541
- return this.#h !== void 0 ? this.#h : this.#h = t[0] === "" && t.length > 1 || this.isDrive() || this.isUNC();
2542
- }
2543
- root() {
2544
- let t = this.#t[0];
2545
- return typeof t == "string" && this.isAbsolute() && this.#n === 0 ? t : "";
2546
- }
2547
- checkFollowGlobstar() {
2548
- return !(this.#n === 0 || !this.isGlobstar() || !this.#u);
2549
- }
2550
- markFollowGlobstar() {
2551
- return this.#n === 0 || !this.isGlobstar() || !this.#u ? false : (this.#u = false, true);
2552
- }
2553
- };
2554
- var _i = typeof process == "object" && process && typeof process.platform == "string" ? process.platform : "linux";
2555
- var ot = class {
2556
- relative;
2557
- relativeChildren;
2558
- absolute;
2559
- absoluteChildren;
2560
- platform;
2561
- mmopts;
2562
- constructor(t, { nobrace: e, nocase: s, noext: i, noglobstar: r, platform: o = _i }) {
2563
- this.relative = [], this.absolute = [], this.relativeChildren = [], this.absoluteChildren = [], this.platform = o, this.mmopts = { dot: true, nobrace: e, nocase: s, noext: i, noglobstar: r, optimizationLevel: 2, platform: o, nocomment: true, nonegate: true };
2564
- for (let h of t) this.add(h);
2565
- }
2566
- add(t) {
2567
- let e = new D(t, this.mmopts);
2568
- for (let s = 0; s < e.set.length; s++) {
2569
- let i = e.set[s], r = e.globParts[s];
2570
- if (!i || !r) throw new Error("invalid pattern object");
2571
- for (; i[0] === "." && r[0] === "."; ) i.shift(), r.shift();
2572
- let o = new nt(i, r, 0, this.platform), h = new D(o.globString(), this.mmopts), a = r[r.length - 1] === "**", l = o.isAbsolute();
2573
- l ? this.absolute.push(h) : this.relative.push(h), a && (l ? this.absoluteChildren.push(h) : this.relativeChildren.push(h));
2574
- }
2575
- }
2576
- ignored(t) {
2577
- let e = t.fullpath(), s = `${e}/`, i = t.relative() || ".", r = `${i}/`;
2578
- for (let o of this.relative) if (o.match(i) || o.match(r)) return true;
2579
- for (let o of this.absolute) if (o.match(e) || o.match(s)) return true;
2580
- return false;
2581
- }
2582
- childrenIgnored(t) {
2583
- let e = t.fullpath() + "/", s = (t.relative() || ".") + "/";
2584
- for (let i of this.relativeChildren) if (i.match(s)) return true;
2585
- for (let i of this.absoluteChildren) if (i.match(e)) return true;
2586
- return false;
2587
- }
2588
- };
2589
- var oe = class n5 {
2590
- store;
2591
- constructor(t = /* @__PURE__ */ new Map()) {
2592
- this.store = t;
2593
- }
2594
- copy() {
2595
- return new n5(new Map(this.store));
2596
- }
2597
- hasWalked(t, e) {
2598
- return this.store.get(t.fullpath())?.has(e.globString());
2599
- }
2600
- storeWalked(t, e) {
2601
- let s = t.fullpath(), i = this.store.get(s);
2602
- i ? i.add(e.globString()) : this.store.set(s, /* @__PURE__ */ new Set([e.globString()]));
2603
- }
2604
- };
2605
- var he = class {
2606
- store = /* @__PURE__ */ new Map();
2607
- add(t, e, s) {
2608
- let i = (e ? 2 : 0) | (s ? 1 : 0), r = this.store.get(t);
2609
- this.store.set(t, r === void 0 ? i : i & r);
2610
- }
2611
- entries() {
2612
- return [...this.store.entries()].map(([t, e]) => [t, !!(e & 2), !!(e & 1)]);
2613
- }
2614
- };
2615
- var ae = class {
2616
- store = /* @__PURE__ */ new Map();
2617
- add(t, e) {
2618
- if (!t.canReaddir()) return;
2619
- let s = this.store.get(t);
2620
- s ? s.find((i) => i.globString() === e.globString()) || s.push(e) : this.store.set(t, [e]);
2621
- }
2622
- get(t) {
2623
- let e = this.store.get(t);
2624
- if (!e) throw new Error("attempting to walk unknown path");
2625
- return e;
2626
- }
2627
- entries() {
2628
- return this.keys().map((t) => [t, this.store.get(t)]);
2629
- }
2630
- keys() {
2631
- return [...this.store.keys()].filter((t) => t.canReaddir());
2632
- }
2633
- };
2634
- var Et = class n6 {
2635
- hasWalkedCache;
2636
- matches = new he();
2637
- subwalks = new ae();
2638
- patterns;
2639
- follow;
2640
- dot;
2641
- opts;
2642
- constructor(t, e) {
2643
- this.opts = t, this.follow = !!t.follow, this.dot = !!t.dot, this.hasWalkedCache = e ? e.copy() : new oe();
2644
- }
2645
- processPatterns(t, e) {
2646
- this.patterns = e;
2647
- let s = e.map((i) => [t, i]);
2648
- for (let [i, r] of s) {
2649
- this.hasWalkedCache.storeWalked(i, r);
2650
- let o = r.root(), h = r.isAbsolute() && this.opts.absolute !== false;
2651
- if (o) {
2652
- i = i.resolve(o === "/" && this.opts.root !== void 0 ? this.opts.root : o);
2653
- let c = r.rest();
2654
- if (c) r = c;
2655
- else {
2656
- this.matches.add(i, true, false);
2657
- continue;
2658
- }
2659
- }
2660
- if (i.isENOENT()) continue;
2661
- let a, l, u = false;
2662
- for (; typeof (a = r.pattern()) == "string" && (l = r.rest()); ) i = i.resolve(a), r = l, u = true;
2663
- if (a = r.pattern(), l = r.rest(), u) {
2664
- if (this.hasWalkedCache.hasWalked(i, r)) continue;
2665
- this.hasWalkedCache.storeWalked(i, r);
2666
- }
2667
- if (typeof a == "string") {
2668
- let c = a === ".." || a === "" || a === ".";
2669
- this.matches.add(i.resolve(a), h, c);
2670
- continue;
2671
- } else if (a === A) {
2672
- (!i.isSymbolicLink() || this.follow || r.checkFollowGlobstar()) && this.subwalks.add(i, r);
2673
- let c = l?.pattern(), d = l?.rest();
2674
- if (!l || (c === "" || c === ".") && !d) this.matches.add(i, h, c === "" || c === ".");
2675
- else if (c === "..") {
2676
- let f = i.parent || i;
2677
- d ? this.hasWalkedCache.hasWalked(f, d) || this.subwalks.add(f, d) : this.matches.add(f, h, true);
2678
- }
2679
- } else a instanceof RegExp && this.subwalks.add(i, r);
2680
- }
2681
- return this;
2682
- }
2683
- subwalkTargets() {
2684
- return this.subwalks.keys();
2685
- }
2686
- child() {
2687
- return new n6(this.opts, this.hasWalkedCache);
2688
- }
2689
- filterEntries(t, e) {
2690
- let s = this.subwalks.get(t), i = this.child();
2691
- for (let r of e) for (let o of s) {
2692
- let h = o.isAbsolute(), a = o.pattern(), l = o.rest();
2693
- a === A ? i.testGlobstar(r, o, l, h) : a instanceof RegExp ? i.testRegExp(r, a, l, h) : i.testString(r, a, l, h);
2694
- }
2695
- return i;
2696
- }
2697
- testGlobstar(t, e, s, i) {
2698
- if ((this.dot || !t.name.startsWith(".")) && (e.hasMore() || this.matches.add(t, i, false), t.canReaddir() && (this.follow || !t.isSymbolicLink() ? this.subwalks.add(t, e) : t.isSymbolicLink() && (s && e.checkFollowGlobstar() ? this.subwalks.add(t, s) : e.markFollowGlobstar() && this.subwalks.add(t, e)))), s) {
2699
- let r = s.pattern();
2700
- if (typeof r == "string" && r !== ".." && r !== "" && r !== ".") this.testString(t, r, s.rest(), i);
2701
- else if (r === "..") {
2702
- let o = t.parent || t;
2703
- this.subwalks.add(o, s);
2704
- } else r instanceof RegExp && this.testRegExp(t, r, s.rest(), i);
2705
- }
2706
- }
2707
- testRegExp(t, e, s, i) {
2708
- e.test(t.name) && (s ? this.subwalks.add(t, s) : this.matches.add(t, i, false));
2709
- }
2710
- testString(t, e, s, i) {
2711
- t.isNamed(e) && (s ? this.subwalks.add(t, s) : this.matches.add(t, i, false));
2712
- }
2713
- };
2714
- var Li = (n7, t) => typeof n7 == "string" ? new ot([n7], t) : Array.isArray(n7) ? new ot(n7, t) : n7;
2715
- var zt = class {
2716
- path;
2717
- patterns;
2718
- opts;
2719
- seen = /* @__PURE__ */ new Set();
2720
- paused = false;
2721
- aborted = false;
2722
- #t = [];
2723
- #s;
2724
- #n;
2725
- signal;
2726
- maxDepth;
2727
- includeChildMatches;
2728
- constructor(t, e, s) {
2729
- if (this.patterns = t, this.path = e, this.opts = s, this.#n = !s.posix && s.platform === "win32" ? "\\" : "/", this.includeChildMatches = s.includeChildMatches !== false, (s.ignore || !this.includeChildMatches) && (this.#s = Li(s.ignore ?? [], s), !this.includeChildMatches && typeof this.#s.add != "function")) {
2730
- let i = "cannot ignore child matches, ignore lacks add() method.";
2731
- throw new Error(i);
2732
- }
2733
- this.maxDepth = s.maxDepth || 1 / 0, s.signal && (this.signal = s.signal, this.signal.addEventListener("abort", () => {
2734
- this.#t.length = 0;
2735
- }));
2736
- }
2737
- #r(t) {
2738
- return this.seen.has(t) || !!this.#s?.ignored?.(t);
2739
- }
2740
- #o(t) {
2741
- return !!this.#s?.childrenIgnored?.(t);
2742
- }
2743
- pause() {
2744
- this.paused = true;
2745
- }
2746
- resume() {
2747
- if (this.signal?.aborted) return;
2748
- this.paused = false;
2749
- let t;
2750
- for (; !this.paused && (t = this.#t.shift()); ) t();
2751
- }
2752
- onResume(t) {
2753
- this.signal?.aborted || (this.paused ? this.#t.push(t) : t());
2754
- }
2755
- async matchCheck(t, e) {
2756
- if (e && this.opts.nodir) return;
2757
- let s;
2758
- if (this.opts.realpath) {
2759
- if (s = t.realpathCached() || await t.realpath(), !s) return;
2760
- t = s;
2761
- }
2762
- let r = t.isUnknown() || this.opts.stat ? await t.lstat() : t;
2763
- if (this.opts.follow && this.opts.nodir && r?.isSymbolicLink()) {
2764
- let o = await r.realpath();
2765
- o && (o.isUnknown() || this.opts.stat) && await o.lstat();
2766
- }
2767
- return this.matchCheckTest(r, e);
2768
- }
2769
- matchCheckTest(t, e) {
2770
- return t && (this.maxDepth === 1 / 0 || t.depth() <= this.maxDepth) && (!e || t.canReaddir()) && (!this.opts.nodir || !t.isDirectory()) && (!this.opts.nodir || !this.opts.follow || !t.isSymbolicLink() || !t.realpathCached()?.isDirectory()) && !this.#r(t) ? t : void 0;
2771
- }
2772
- matchCheckSync(t, e) {
2773
- if (e && this.opts.nodir) return;
2774
- let s;
2775
- if (this.opts.realpath) {
2776
- if (s = t.realpathCached() || t.realpathSync(), !s) return;
2777
- t = s;
2778
- }
2779
- let r = t.isUnknown() || this.opts.stat ? t.lstatSync() : t;
2780
- if (this.opts.follow && this.opts.nodir && r?.isSymbolicLink()) {
2781
- let o = r.realpathSync();
2782
- o && (o?.isUnknown() || this.opts.stat) && o.lstatSync();
2783
- }
2784
- return this.matchCheckTest(r, e);
2785
- }
2786
- matchFinish(t, e) {
2787
- if (this.#r(t)) return;
2788
- if (!this.includeChildMatches && this.#s?.add) {
2789
- let r = `${t.relativePosix()}/**`;
2790
- this.#s.add(r);
2791
- }
2792
- let s = this.opts.absolute === void 0 ? e : this.opts.absolute;
2793
- this.seen.add(t);
2794
- let i = this.opts.mark && t.isDirectory() ? this.#n : "";
2795
- if (this.opts.withFileTypes) this.matchEmit(t);
2796
- else if (s) {
2797
- let r = this.opts.posix ? t.fullpathPosix() : t.fullpath();
2798
- this.matchEmit(r + i);
2799
- } else {
2800
- let r = this.opts.posix ? t.relativePosix() : t.relative(), o = this.opts.dotRelative && !r.startsWith(".." + this.#n) ? "." + this.#n : "";
2801
- this.matchEmit(r ? o + r + i : "." + i);
2802
- }
2803
- }
2804
- async match(t, e, s) {
2805
- let i = await this.matchCheck(t, s);
2806
- i && this.matchFinish(i, e);
2807
- }
2808
- matchSync(t, e, s) {
2809
- let i = this.matchCheckSync(t, s);
2810
- i && this.matchFinish(i, e);
2811
- }
2812
- walkCB(t, e, s) {
2813
- this.signal?.aborted && s(), this.walkCB2(t, e, new Et(this.opts), s);
2814
- }
2815
- walkCB2(t, e, s, i) {
2816
- if (this.#o(t)) return i();
2817
- if (this.signal?.aborted && i(), this.paused) {
2818
- this.onResume(() => this.walkCB2(t, e, s, i));
2819
- return;
2820
- }
2821
- s.processPatterns(t, e);
2822
- let r = 1, o = () => {
2823
- --r === 0 && i();
2824
- };
2825
- for (let [h, a, l] of s.matches.entries()) this.#r(h) || (r++, this.match(h, a, l).then(() => o()));
2826
- for (let h of s.subwalkTargets()) {
2827
- if (this.maxDepth !== 1 / 0 && h.depth() >= this.maxDepth) continue;
2828
- r++;
2829
- let a = h.readdirCached();
2830
- h.calledReaddir() ? this.walkCB3(h, a, s, o) : h.readdirCB((l, u) => this.walkCB3(h, u, s, o), true);
2831
- }
2832
- o();
2833
- }
2834
- walkCB3(t, e, s, i) {
2835
- s = s.filterEntries(t, e);
2836
- let r = 1, o = () => {
2837
- --r === 0 && i();
2838
- };
2839
- for (let [h, a, l] of s.matches.entries()) this.#r(h) || (r++, this.match(h, a, l).then(() => o()));
2840
- for (let [h, a] of s.subwalks.entries()) r++, this.walkCB2(h, a, s.child(), o);
2841
- o();
2842
- }
2843
- walkCBSync(t, e, s) {
2844
- this.signal?.aborted && s(), this.walkCB2Sync(t, e, new Et(this.opts), s);
2845
- }
2846
- walkCB2Sync(t, e, s, i) {
2847
- if (this.#o(t)) return i();
2848
- if (this.signal?.aborted && i(), this.paused) {
2849
- this.onResume(() => this.walkCB2Sync(t, e, s, i));
2850
- return;
2851
- }
2852
- s.processPatterns(t, e);
2853
- let r = 1, o = () => {
2854
- --r === 0 && i();
2855
- };
2856
- for (let [h, a, l] of s.matches.entries()) this.#r(h) || this.matchSync(h, a, l);
2857
- for (let h of s.subwalkTargets()) {
2858
- if (this.maxDepth !== 1 / 0 && h.depth() >= this.maxDepth) continue;
2859
- r++;
2860
- let a = h.readdirSync();
2861
- this.walkCB3Sync(h, a, s, o);
2862
- }
2863
- o();
2864
- }
2865
- walkCB3Sync(t, e, s, i) {
2866
- s = s.filterEntries(t, e);
2867
- let r = 1, o = () => {
2868
- --r === 0 && i();
2869
- };
2870
- for (let [h, a, l] of s.matches.entries()) this.#r(h) || this.matchSync(h, a, l);
2871
- for (let [h, a] of s.subwalks.entries()) r++, this.walkCB2Sync(h, a, s.child(), o);
2872
- o();
2873
- }
2874
- };
2875
- var xt = class extends zt {
2876
- matches = /* @__PURE__ */ new Set();
2877
- constructor(t, e, s) {
2878
- super(t, e, s);
2879
- }
2880
- matchEmit(t) {
2881
- this.matches.add(t);
2882
- }
2883
- async walk() {
2884
- if (this.signal?.aborted) throw this.signal.reason;
2885
- return this.path.isUnknown() && await this.path.lstat(), await new Promise((t, e) => {
2886
- this.walkCB(this.path, this.patterns, () => {
2887
- this.signal?.aborted ? e(this.signal.reason) : t(this.matches);
2888
- });
2889
- }), this.matches;
2890
- }
2891
- walkSync() {
2892
- if (this.signal?.aborted) throw this.signal.reason;
2893
- return this.path.isUnknown() && this.path.lstatSync(), this.walkCBSync(this.path, this.patterns, () => {
2894
- if (this.signal?.aborted) throw this.signal.reason;
2895
- }), this.matches;
2896
- }
2897
- };
2898
- var vt = class extends zt {
2899
- results;
2900
- constructor(t, e, s) {
2901
- super(t, e, s), this.results = new V({ signal: this.signal, objectMode: true }), this.results.on("drain", () => this.resume()), this.results.on("resume", () => this.resume());
2902
- }
2903
- matchEmit(t) {
2904
- this.results.write(t), this.results.flowing || this.pause();
2905
- }
2906
- stream() {
2907
- let t = this.path;
2908
- return t.isUnknown() ? t.lstat().then(() => {
2909
- this.walkCB(t, this.patterns, () => this.results.end());
2910
- }) : this.walkCB(t, this.patterns, () => this.results.end()), this.results;
2911
- }
2912
- streamSync() {
2913
- return this.path.isUnknown() && this.path.lstatSync(), this.walkCBSync(this.path, this.patterns, () => this.results.end()), this.results;
2914
- }
2915
- };
2916
- var Pi = typeof process == "object" && process && typeof process.platform == "string" ? process.platform : "linux";
2917
- var I = class {
2918
- absolute;
2919
- cwd;
2920
- root;
2921
- dot;
2922
- dotRelative;
2923
- follow;
2924
- ignore;
2925
- magicalBraces;
2926
- mark;
2927
- matchBase;
2928
- maxDepth;
2929
- nobrace;
2930
- nocase;
2931
- nodir;
2932
- noext;
2933
- noglobstar;
2934
- pattern;
2935
- platform;
2936
- realpath;
2937
- scurry;
2938
- stat;
2939
- signal;
2940
- windowsPathsNoEscape;
2941
- withFileTypes;
2942
- includeChildMatches;
2943
- opts;
2944
- patterns;
2945
- constructor(t, e) {
2946
- if (!e) throw new TypeError("glob options required");
2947
- if (this.withFileTypes = !!e.withFileTypes, this.signal = e.signal, this.follow = !!e.follow, this.dot = !!e.dot, this.dotRelative = !!e.dotRelative, this.nodir = !!e.nodir, this.mark = !!e.mark, e.cwd ? (e.cwd instanceof URL || e.cwd.startsWith("file://")) && (e.cwd = Wi(e.cwd)) : this.cwd = "", this.cwd = e.cwd || "", this.root = e.root, this.magicalBraces = !!e.magicalBraces, this.nobrace = !!e.nobrace, this.noext = !!e.noext, this.realpath = !!e.realpath, this.absolute = e.absolute, this.includeChildMatches = e.includeChildMatches !== false, this.noglobstar = !!e.noglobstar, this.matchBase = !!e.matchBase, this.maxDepth = typeof e.maxDepth == "number" ? e.maxDepth : 1 / 0, this.stat = !!e.stat, this.ignore = e.ignore, this.withFileTypes && this.absolute !== void 0) throw new Error("cannot set absolute and withFileTypes:true");
2948
- if (typeof t == "string" && (t = [t]), this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === false, this.windowsPathsNoEscape && (t = t.map((a) => a.replace(/\\/g, "/"))), this.matchBase) {
2949
- if (e.noglobstar) throw new TypeError("base matching requires globstar");
2950
- t = t.map((a) => a.includes("/") ? a : `./**/${a}`);
2951
- }
2952
- if (this.pattern = t, this.platform = e.platform || Pi, this.opts = { ...e, platform: this.platform }, e.scurry) {
2953
- if (this.scurry = e.scurry, e.nocase !== void 0 && e.nocase !== e.scurry.nocase) throw new Error("nocase option contradicts provided scurry option");
2954
- } else {
2955
- let a = e.platform === "win32" ? it : e.platform === "darwin" ? St : e.platform ? rt : Xe;
2956
- this.scurry = new a(this.cwd, { nocase: e.nocase, fs: e.fs });
2957
- }
2958
- this.nocase = this.scurry.nocase;
2959
- let s = this.platform === "darwin" || this.platform === "win32", i = { braceExpandMax: 1e4, ...e, dot: this.dot, matchBase: this.matchBase, nobrace: this.nobrace, nocase: this.nocase, nocaseMagicOnly: s, nocomment: true, noext: this.noext, nonegate: true, optimizationLevel: 2, platform: this.platform, windowsPathsNoEscape: this.windowsPathsNoEscape, debug: !!this.opts.debug }, r = this.pattern.map((a) => new D(a, i)), [o, h] = r.reduce((a, l) => (a[0].push(...l.set), a[1].push(...l.globParts), a), [[], []]);
2960
- this.patterns = o.map((a, l) => {
2961
- let u = h[l];
2962
- if (!u) throw new Error("invalid pattern object");
2963
- return new nt(a, u, 0, this.platform);
2964
- });
2965
- }
2966
- async walk() {
2967
- return [...await new xt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).walk()];
2968
- }
2969
- walkSync() {
2970
- return [...new xt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).walkSync()];
2971
- }
2972
- stream() {
2973
- return new vt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).stream();
2974
- }
2975
- streamSync() {
2976
- return new vt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).streamSync();
2977
- }
2978
- iterateSync() {
2979
- return this.streamSync()[Symbol.iterator]();
2980
- }
2981
- [Symbol.iterator]() {
2982
- return this.iterateSync();
2983
- }
2984
- iterate() {
2985
- return this.stream()[Symbol.asyncIterator]();
2986
- }
2987
- [Symbol.asyncIterator]() {
2988
- return this.iterate();
2989
- }
2990
- };
2991
- var le = (n7, t = {}) => {
2992
- Array.isArray(n7) || (n7 = [n7]);
2993
- for (let e of n7) if (new D(e, t).hasMagic()) return true;
2994
- return false;
2995
- };
2996
- function Bt(n7, t = {}) {
2997
- return new I(n7, t).streamSync();
2998
- }
2999
- function Qe(n7, t = {}) {
3000
- return new I(n7, t).stream();
3001
- }
3002
- function ts(n7, t = {}) {
3003
- return new I(n7, t).walkSync();
3004
- }
3005
- async function Je(n7, t = {}) {
3006
- return new I(n7, t).walk();
3007
- }
3008
- function Ut(n7, t = {}) {
3009
- return new I(n7, t).iterateSync();
3010
- }
3011
- function es(n7, t = {}) {
3012
- return new I(n7, t).iterate();
3013
- }
3014
- var ji = Bt;
3015
- var Ii = Object.assign(Qe, { sync: Bt });
3016
- var zi = Ut;
3017
- var Bi = Object.assign(es, { sync: Ut });
3018
- var Ui = Object.assign(ts, { stream: Bt, iterate: Ut });
3019
- var Ze = Object.assign(Je, { glob: Je, globSync: ts, sync: Ui, globStream: Qe, stream: Ii, globStreamSync: Bt, streamSync: ji, globIterate: es, iterate: Bi, globIterateSync: Ut, iterateSync: zi, Glob: I, hasMagic: le, escape: tt, unescape: W });
3020
- Ze.glob = Ze;
3021
-
3022
- // src/utils/miscellaneous.ts
3023
- import * as fs2 from "node:fs";
3024
- import { basename, dirname, extname, join, resolve, relative } from "node:path";
3025
- import * as process2 from "node:process";
3026
- import { performance as performance2 } from "perf_hooks";
3027
-
3028
- // src/types.ts
3029
- var outputExtensions = ["json", "yaml", "yml"];
3030
-
3031
- // src/utils/miscellaneous.ts
3032
- async function getFallbackApisOrExit(argsApis, config) {
3033
- const shouldFallbackToAllDefinitions = !isNotEmptyArray(argsApis) && isNotEmptyObject(config.resolvedConfig.apis);
3034
- const res = shouldFallbackToAllDefinitions ? fallbackToAllDefinitions(config) : await expandGlobsInEntrypoints(argsApis, config);
3035
- const filteredInvalidEntrypoints = res.filter(({ path }) => !isApiPathValid(path));
3036
- if (isNotEmptyArray(filteredInvalidEntrypoints)) {
3037
- for (const { path } of filteredInvalidEntrypoints) {
3038
- logger.warn(`
3039
- ${formatPath(path)} ${red(`does not exist or is invalid.
3040
-
3041
- `)}`);
3042
- }
3043
- exitWithError("Please provide a valid path.");
3044
- }
3045
- if (res.length === 0) {
3046
- exitWithError(
3047
- "No APIs were provided. Specify an API via the command argument or define one in your config."
3048
- );
3049
- }
3050
- return res;
3051
- }
3052
- function getConfigDirectory(config) {
3053
- return config.configPath ? dirname(config.configPath) : process2.cwd();
3054
- }
3055
- function isApiPathValid(apiPath) {
3056
- if (!apiPath.trim()) {
3057
- exitWithError("Path cannot be empty.");
3058
- return;
3059
- }
3060
- return fs2.existsSync(apiPath) || isAbsoluteUrl(apiPath) ? apiPath : void 0;
3061
- }
3062
- function fallbackToAllDefinitions(config) {
3063
- return Object.entries(config.resolvedConfig.apis || {}).map(([alias, { root, output }]) => ({
3064
- path: isAbsoluteUrl(root) ? root : resolve(getConfigDirectory(config), root),
3065
- alias,
3066
- output: output && resolve(getConfigDirectory(config), output)
3067
- }));
3068
- }
3069
- function getAliasOrPath(config, aliasOrPath) {
3070
- const configDir = getConfigDirectory(config);
3071
- const aliasApi = config.resolvedConfig.apis?.[aliasOrPath];
3072
- return aliasApi ? {
3073
- path: isAbsoluteUrl(aliasApi.root) ? aliasApi.root : resolve(configDir, aliasApi.root),
3074
- alias: aliasOrPath,
3075
- output: aliasApi.output && resolve(configDir, aliasApi.output)
3076
- } : {
3077
- path: aliasOrPath,
3078
- // find alias by path, take the first match
3079
- alias: Object.entries(config.resolvedConfig.apis || {}).find(([_alias, api]) => {
3080
- return resolve(configDir, api.root) === resolve(aliasOrPath);
3081
- })?.[0] ?? void 0
3082
- };
3083
- }
3084
- async function expandGlobsInEntrypoints(argApis, config) {
3085
- return (await Promise.all(
3086
- argApis.map(async (aliasOrPath) => {
3087
- const shouldResolveGlob = le(aliasOrPath) && !isAbsoluteUrl(aliasOrPath);
3088
- if (shouldResolveGlob) {
3089
- const data = await Ze(aliasOrPath, {
3090
- cwd: getConfigDirectory(config)
3091
- });
3092
- return data.map((g) => getAliasOrPath(config, g));
3093
- }
3094
- return getAliasOrPath(config, aliasOrPath);
3095
- })
3096
- )).flat();
3097
- }
3098
- function getExecutionTime(startedAt) {
3099
- return process2.env.NODE_ENV === "test" ? "<test>ms" : `${Math.ceil(performance2.now() - startedAt)}ms`;
3100
- }
3101
- function printExecutionTime(commandName, startedAt, api) {
3102
- const elapsed = getExecutionTime(startedAt);
3103
- logger.info(gray(`
3104
- ${api}: ${commandName} processed in ${elapsed}
3105
-
3106
- `));
3107
- }
3108
- function pathToFilename(path, pathSeparator) {
3109
- if (path === "/") {
3110
- return pathSeparator;
3111
- }
3112
- return path.replaceAll("~1", "/").replaceAll("~0", "~").replace(/^\//, "").replaceAll("/", pathSeparator);
3113
- }
3114
- function escapeLanguageName(lang) {
3115
- return lang.replace(/#/g, "_sharp").replace(/\//, "_").replace(/\s/g, "");
3116
- }
3117
- function langToExt(lang) {
3118
- const langObj = {
3119
- php: ".php",
3120
- "c#": ".cs",
3121
- shell: ".sh",
3122
- curl: ".sh",
3123
- bash: ".sh",
3124
- javascript: ".js",
3125
- js: ".js",
3126
- python: ".py",
3127
- c: ".c",
3128
- "c++": ".cpp",
3129
- coffeescript: ".litcoffee",
3130
- dart: ".dart",
3131
- elixir: ".ex",
3132
- go: ".go",
3133
- groovy: ".groovy",
3134
- java: ".java",
3135
- kotlin: ".kt",
3136
- "objective-c": ".m",
3137
- perl: ".pl",
3138
- powershell: ".ps1",
3139
- ruby: ".rb",
3140
- rust: ".rs",
3141
- scala: ".sc",
3142
- swift: ".swift",
3143
- typescript: ".ts",
3144
- tsx: ".tsx",
3145
- "visual basic": ".vb",
3146
- "c/al": ".al"
3147
- };
3148
- return langObj[lang.toLowerCase()] ?? "";
3149
- }
3150
- var CircularJSONNotSupportedError = class _CircularJSONNotSupportedError extends Error {
3151
- constructor(originalError) {
3152
- super(originalError.message);
3153
- this.originalError = originalError;
3154
- Object.setPrototypeOf(this, _CircularJSONNotSupportedError.prototype);
3155
- }
3156
- originalError;
3157
- };
3158
- function dumpBundle(obj, format, dereference) {
3159
- if (format === "json") {
3160
- try {
3161
- return JSON.stringify(obj, null, 2);
3162
- } catch (e) {
3163
- if (e.message.indexOf("circular") > -1) {
3164
- throw new CircularJSONNotSupportedError(e);
3165
- }
3166
- throw e;
3167
- }
3168
- } else {
3169
- return stringifyYaml(obj, {
3170
- noRefs: !dereference,
3171
- lineWidth: -1
3172
- });
3173
- }
3174
- }
3175
- function saveBundle(filename, output) {
3176
- fs2.mkdirSync(dirname(filename), { recursive: true });
3177
- fs2.writeFileSync(filename, output);
3178
- }
3179
- function readYaml(filename) {
3180
- return parseYaml(fs2.readFileSync(filename, "utf-8"), { filename });
3181
- }
3182
- function writeToFileByExtension(data, filePath, noRefs) {
3183
- const ext = getAndValidateFileExtension(filePath);
3184
- if (ext === "json") {
3185
- writeJson(data, filePath);
3186
- return;
3187
- }
3188
- writeYaml(data, filePath, noRefs);
3189
- }
3190
- function writeYaml(data, filename, noRefs = false) {
3191
- const content = stringifyYaml(data, { noRefs });
3192
- if (process2.env.NODE_ENV === "test") {
3193
- logger.info(content);
3194
- return;
3195
- }
3196
- fs2.mkdirSync(dirname(filename), { recursive: true });
3197
- fs2.writeFileSync(filename, content);
3198
- }
3199
- function writeJson(data, filename) {
3200
- const content = JSON.stringify(data, null, 2);
3201
- if (process2.env.NODE_ENV === "test") {
3202
- logger.info(content);
3203
- return;
3204
- }
3205
- fs2.mkdirSync(dirname(filename), { recursive: true });
3206
- fs2.writeFileSync(filename, content);
3207
- }
3208
- function getAndValidateFileExtension(fileName) {
3209
- const ext = fileName.split(".").pop();
3210
- if (outputExtensions.includes(ext)) {
3211
- return ext;
3212
- }
3213
- logger.warn(`Unsupported file extension: ${ext}. Using yaml.
3214
- `);
3215
- return "yaml";
3216
- }
3217
- function handleError(e, ref) {
3218
- switch (e.constructor) {
3219
- case HandledError: {
3220
- throw e;
3221
- }
3222
- case ResolveError:
3223
- exitWithError(`Failed to resolve API description at ${ref}:
3224
-
3225
- - ${e.message}`);
3226
- break;
3227
- case YamlParseError:
3228
- exitWithError(`Failed to parse API description at ${ref}:
3229
-
3230
- - ${e.message}`);
3231
- break;
3232
- case CircularJSONNotSupportedError: {
3233
- exitWithError(
3234
- `Detected circular reference which can't be converted to JSON.
3235
- Try to use ${blue("yaml")} output or remove ${blue("--dereferenced")}.`
3236
- );
3237
- break;
3238
- }
3239
- case SyntaxError:
3240
- exitWithError(`Syntax error: ${e.message} ${e.stack?.split("\n\n")?.[0]}`);
3241
- break;
3242
- case ConfigValidationError:
3243
- exitWithError(e.message);
3244
- break;
3245
- default: {
3246
- exitWithError(`Something went wrong when processing ${ref}:
3247
-
3248
- - ${e.message}`);
3249
- }
3250
- }
3251
- }
3252
- function printLintTotals(totals, definitionsCount) {
3253
- const ignored = totals.ignored ? yellow(`${totals.ignored} ${pluralize("problem is", totals.ignored)} explicitly ignored.
3254
-
3255
- `) : "";
3256
- if (totals.errors > 0) {
3257
- logger.error(
3258
- `\u274C Validation failed with ${totals.errors} ${pluralize("error", totals.errors)}${totals.warnings > 0 ? ` and ${totals.warnings} ${pluralize("warning", totals.warnings)}` : ""}.
3259
- ${ignored}`
3260
- );
3261
- } else if (totals.warnings > 0) {
3262
- logger.info(
3263
- green(`Woohoo! Your API ${pluralize("description is", definitionsCount)} valid. \u{1F389}
3264
- `)
3265
- );
3266
- logger.warn(
3267
- `You have ${totals.warnings} ${pluralize("warning", totals.warnings)}.
3268
- ${ignored}`
3269
- );
3270
- } else {
3271
- logger.info(
3272
- green(
3273
- `Woohoo! Your API ${pluralize("description is", definitionsCount)} valid. \u{1F389}
3274
- ${ignored}`
3275
- )
3276
- );
3277
- }
3278
- if (totals.errors > 0) {
3279
- logger.info(
3280
- gray(`run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
3281
- `)
3282
- );
3283
- }
3284
- logger.info("\n");
3285
- }
3286
- function printConfigLintTotals(totals, command) {
3287
- if (totals.errors > 0) {
3288
- logger.error(`\u274C Your config has ${totals.errors} ${pluralize("error", totals.errors)}.
3289
- `);
3290
- } else if (totals.warnings > 0) {
3291
- logger.warn(
3292
- `\u26A0\uFE0F Your config has ${totals.warnings} ${pluralize("warning", totals.warnings)}.
3293
- `
3294
- );
3295
- } else if (command === "check-config") {
3296
- logger.info(green("\u2705 Your config is valid.\n"));
3297
- }
3298
- }
3299
- function getOutputFileName({
3300
- entrypoint,
3301
- output,
3302
- argvOutput,
3303
- ext,
3304
- entries
3305
- }) {
3306
- let outputFile = output || argvOutput;
3307
- if (!outputFile) {
3308
- return { ext: ext || "yaml" };
3309
- }
3310
- if (entries > 1 && argvOutput) {
3311
- ext = ext || extname(entrypoint).substring(1);
3312
- if (!outputExtensions.includes(ext)) {
3313
- throw new Error(`Invalid file extension: ${ext}.`);
3314
- }
3315
- outputFile = join(argvOutput, basename(entrypoint, extname(entrypoint))) + "." + ext;
3316
- } else {
3317
- ext = ext || extname(outputFile).substring(1) || extname(entrypoint).substring(1);
3318
- if (!outputExtensions.includes(ext)) {
3319
- throw new Error(`Invalid file extension: ${ext}.`);
3320
- }
3321
- outputFile = join(dirname(outputFile), basename(outputFile, extname(outputFile))) + "." + ext;
3322
- }
3323
- return { outputFile, ext };
3324
- }
3325
- function printUnusedWarnings(config) {
3326
- const { preprocessors, rules, decorators } = config.getUnusedRules();
3327
- if (rules.length) {
3328
- logger.warn(
3329
- `[WARNING] Unused rules found in ${blue(config.configPath || "")}: ${rules.join(", ")}.
3330
- `
3331
- );
3332
- }
3333
- if (preprocessors.length) {
3334
- logger.warn(
3335
- `[WARNING] Unused preprocessors found in ${blue(
3336
- config.configPath || ""
3337
- )}: ${preprocessors.join(", ")}.
3338
- `
3339
- );
3340
- }
3341
- if (decorators.length) {
3342
- logger.warn(
3343
- `[WARNING] Unused decorators found in ${blue(config.configPath || "")}: ${decorators.join(
3344
- ", "
3345
- )}.
3346
- `
3347
- );
3348
- }
3349
- if (rules.length || preprocessors.length) {
3350
- logger.warn(`Check the spelling and verify the added plugin prefix.
3351
- `);
3352
- }
3353
- }
3354
- async function loadConfigAndHandleErrors(argv, version) {
3355
- try {
3356
- const config = await loadConfig({
3357
- configPath: argv.config,
3358
- customExtends: argv.extends
3359
- });
3360
- await handleLintConfig(argv, version, config);
3361
- return config;
3362
- } catch (e) {
3363
- handleError(e, "");
3364
- }
3365
- }
3366
- function isAsync2Definition(doc) {
3367
- return doc.asyncapi?.startsWith("2");
3368
- }
3369
- var oas2OrderedKeys = [
3370
- "swagger",
3371
- "info",
3372
- "host",
3373
- "basePath",
3374
- "schemes",
3375
- "consumes",
3376
- "produces",
3377
- "security",
3378
- "tags",
3379
- "externalDocs",
3380
- "paths",
3381
- "definitions",
3382
- "parameters",
3383
- "responses",
3384
- "securityDefinitions"
3385
- ];
3386
- var oas3OrderedKeys = [
3387
- "openapi",
3388
- "info",
3389
- "jsonSchemaDialect",
3390
- "servers",
3391
- "security",
3392
- "tags",
3393
- "externalDocs",
3394
- "paths",
3395
- "webhooks",
3396
- "x-webhooks",
3397
- "components"
3398
- ];
3399
- var asyncApi2OrderedKeys = [
3400
- "asyncapi",
3401
- "id",
3402
- "info",
3403
- "externalDocs",
3404
- "tags",
3405
- "defaultContentType",
3406
- "servers",
3407
- "channels",
3408
- "components"
3409
- ];
3410
- var asyncApi3OrderedKeys = [
3411
- "asyncapi",
3412
- "info",
3413
- "defaultContentType",
3414
- "servers",
3415
- "channels",
3416
- "operations",
3417
- "components"
3418
- ];
3419
- function sortTopLevelKeys(document) {
3420
- if ("asyncapi" in document) {
3421
- return isAsync2Definition(document) ? sortDocumentKeys(document, asyncApi2OrderedKeys) : sortDocumentKeys(document, asyncApi3OrderedKeys);
3422
- }
3423
- if ("swagger" in document) {
3424
- return sortDocumentKeys(document, oas2OrderedKeys);
3425
- }
3426
- return sortDocumentKeys(document, oas3OrderedKeys);
3427
- }
3428
- function sortDocumentKeys(document, orderedKeys) {
3429
- const result = {};
3430
- for (const key of orderedKeys) {
3431
- if (document.hasOwnProperty(key)) {
3432
- result[key] = document[key];
3433
- }
3434
- }
3435
- return Object.assign(result, document);
3436
- }
3437
- function checkIfRulesetExist(rules) {
3438
- const ruleset = {
3439
- ...rules.oas2,
3440
- ...rules.oas3_0,
3441
- ...rules.oas3_1,
3442
- ...rules.oas3_2,
3443
- ...rules.async2,
3444
- ...rules.async3,
3445
- ...rules.arazzo1,
3446
- ...rules.overlay1,
3447
- ...rules.openrpc1,
3448
- ...rules.graphql
3449
- };
3450
- if (isEmptyObject(ruleset)) {
3451
- exitWithError(
3452
- "\u26A0\uFE0F No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/"
3453
- );
3454
- }
3455
- }
3456
- function cleanColors(input) {
3457
- return input.replace(/\x1b\[\d+m/g, "");
3458
- }
3459
- function formatPath(path) {
3460
- if (isAbsoluteUrl(path)) {
3461
- return path;
3462
- }
3463
- return relative(process2.cwd(), path);
3464
- }
3465
- function capitalize(s) {
3466
- if (s?.length > 0) {
3467
- return s[0].toUpperCase() + s.slice(1);
3468
- }
3469
- return s;
3470
- }
3471
-
3472
- // src/commands/lint.ts
3473
- async function handleLint({
3474
- argv,
3475
- config,
3476
- version,
3477
- collectSpecData
3478
- }) {
3479
- const apis = await getFallbackApisOrExit(argv.apis, config);
3480
- const totals = { errors: 0, warnings: 0, ignored: 0 };
3481
- let totalIgnored = 0;
3482
- const isAggregatedXmlFormat = argv.format === "checkstyle" || argv.format === "junit";
3483
- const aggregatedResults = [];
3484
- for (const { path, alias } of apis) {
3485
- try {
3486
- const startedAt = performance3.now();
3487
- const aliasConfig = config.forAlias(alias);
3488
- checkIfRulesetExist(aliasConfig.rules);
3489
- aliasConfig.skipRules(argv["skip-rule"]);
3490
- aliasConfig.skipPreprocessors(argv["skip-preprocessor"]);
3491
- if (typeof config.document?.parsed === "undefined" && !argv.extends) {
3492
- logger.info(
3493
- `No configurations were provided -- using built in ${blue(
3494
- "recommended"
3495
- )} configuration by default.
3496
-
3497
- `
3498
- );
3499
- }
3500
- if (alias === void 0) {
3501
- logger.info(gray(`validating ${formatPath(path)}...
3502
- `));
3503
- } else {
3504
- logger.info(
3505
- gray(`validating ${formatPath(path)} using lint rules for api '${alias}'...
3506
- `)
3507
- );
3508
- }
3509
- const results = await lint({
3510
- ref: path,
3511
- config: aliasConfig,
3512
- collectSpecData
3513
- });
3514
- const fileTotals = getTotals(results);
3515
- totals.errors += fileTotals.errors;
3516
- totals.warnings += fileTotals.warnings;
3517
- totals.ignored += fileTotals.ignored;
3518
- if (argv["generate-ignore-file"]) {
3519
- config.clearIgnoreForRef(path);
3520
- for (const m of results) {
3521
- config.addIgnore(m);
3522
- totalIgnored++;
3523
- }
3524
- } else if (isAggregatedXmlFormat) {
3525
- aggregatedResults.push(...results);
3526
- } else {
3527
- formatProblems(results, {
3528
- format: argv.format,
3529
- maxProblems: argv["max-problems"],
3530
- totals: fileTotals,
3531
- version,
3532
- command: "lint"
3533
- });
3534
- }
3535
- const elapsed = getExecutionTime(startedAt);
3536
- logger.info(gray(`${formatPath(path)}: validated in ${elapsed}
3537
-
3538
- `));
3539
- } catch (e) {
3540
- handleError(e, path);
3541
- }
3542
- }
3543
- if (isAggregatedXmlFormat && !argv["generate-ignore-file"]) {
3544
- formatProblems(aggregatedResults, {
3545
- format: argv.format,
3546
- maxProblems: argv["max-problems"],
3547
- totals,
3548
- version,
3549
- command: "lint"
3550
- });
3551
- }
3552
- if (argv["generate-ignore-file"]) {
3553
- config.saveIgnore();
3554
- logger.info(`Explicitly ignored ${totalIgnored} ${pluralize("problem", totalIgnored)}.
3555
-
3556
- `);
3557
- } else {
3558
- printLintTotals(totals, apis.length);
3559
- }
3560
- printUnusedWarnings(config);
3561
- if (!(totals.errors === 0 || argv["generate-ignore-file"])) {
3562
- throw new AbortFlowError("Lint failed.");
3563
- }
3564
- }
3565
- async function handleLintConfig(argv, version, config) {
3566
- if (argv["lint-config"] === "off" || config.document === void 0) {
3567
- return;
3568
- }
3569
- if (argv.format === "json" || argv.format === "junit" || argv.format === "checkstyle") {
3570
- return;
3571
- }
3572
- const command = argv ? getCommandNameFromArgs(argv) : void 0;
3573
- const problems = await lintConfig({
3574
- config,
3575
- severity: argv["lint-config"] || "warn"
3576
- });
3577
- const fileTotals = getTotals(problems);
3578
- formatProblems(problems, {
3579
- format: argv.format,
3580
- maxProblems: argv["max-problems"],
3581
- totals: fileTotals,
3582
- version,
3583
- command: "check-config"
3584
- });
3585
- printConfigLintTotals(fileTotals, command);
3586
- if (fileTotals.errors > 0) {
3587
- throw new ConfigValidationError();
3588
- }
3589
- }
3590
-
3591
- export {
3592
- handleLint,
3593
- outputExtensions,
3594
- getFallbackApisOrExit,
3595
- getAliasOrPath,
3596
- getExecutionTime,
3597
- printExecutionTime,
3598
- pathToFilename,
3599
- escapeLanguageName,
3600
- langToExt,
3601
- dumpBundle,
3602
- saveBundle,
3603
- readYaml,
3604
- writeToFileByExtension,
3605
- getAndValidateFileExtension,
3606
- handleError,
3607
- getOutputFileName,
3608
- printUnusedWarnings,
3609
- loadConfigAndHandleErrors,
3610
- sortTopLevelKeys,
3611
- cleanColors,
3612
- formatPath,
3613
- capitalize
3614
- };