@outerlayer/cli 0.38.0-next.20261109042440 → 0.38.0-next.20261109134838

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 (30) hide show
  1. package/dist/build-info.json +1 -1
  2. package/dist/{check-V7O237A4.js → check-Z25NGNZY.js} +6 -6
  3. package/dist/{chunk-CFJTX2QF.js → chunk-2OHSKVZG.js} +1 -1
  4. package/dist/{chunk-N3KJY74V.js → chunk-2WQG2WLR.js} +1 -1
  5. package/dist/{chunk-MM4B7IZK.js → chunk-CKN6NS7D.js} +1 -1
  6. package/dist/{chunk-JSWKSMVE.js → chunk-ELTELKNV.js} +1 -1
  7. package/dist/{chunk-IOSY5ZYJ.js → chunk-KF4IV2ET.js} +4 -4
  8. package/dist/chunk-LIH6CIVB.js +2642 -0
  9. package/dist/{chunk-KZNIQUOC.js → chunk-UIPZEJSC.js} +11 -5
  10. package/dist/{chunk-ZLJD2AY3.js → chunk-YEE42T22.js} +1 -1
  11. package/dist/{chunk-IEKXNDKX.js → chunk-ZK552E7A.js} +5 -2
  12. package/dist/{cli-DLRZZO5D.js → cli-WSTTVQYE.js} +22 -22
  13. package/dist/{command-323XICE4.js → command-YTVFIEDS.js} +3 -3
  14. package/dist/{container-start-2EZGXAQ2.js → container-start-B4GC6QH4.js} +4 -4
  15. package/dist/{doctor-GHJ7EPRT.js → doctor-32ODPZE2.js} +4 -4
  16. package/dist/{host-checks-CSAVTTJ5.js → host-checks-JVFVCWIF.js} +2 -2
  17. package/dist/index.js +1 -1
  18. package/dist/{init-F4CGGR62.js → init-JR2KKJZ2.js} +2 -2
  19. package/dist/{init-RXTPXCHN.js → init-WRA2KJKD.js} +2 -2
  20. package/dist/{init-agent-RT45WGLM.js → init-agent-UBGGM5K6.js} +2 -2
  21. package/dist/{init-cmd-HMPM33KI.js → init-cmd-OIWNFYIA.js} +1 -1
  22. package/dist/{loop-DINF6WGB.js → loop-Q33AQ2UD.js} +6 -6
  23. package/dist/{machine-KBGKKY6E.js → machine-LANNWRZS.js} +2 -2
  24. package/dist/{runner-key-W76LSC57.js → runner-key-LYEB7RTM.js} +2 -2
  25. package/dist/{status-J5BVCENR.js → status-XTL6X4EU.js} +2 -2
  26. package/dist/{update-steps-U7KB2PPF.js → update-steps-G2XJ43PU.js} +3 -3
  27. package/dist/{work-proofs-cmd-B6JFSXPH.js → work-proofs-cmd-7JOEX2VA.js} +2 -2
  28. package/dist/{work-proofs-record-PWYMY3XW.js → work-proofs-record-6BM436H2.js} +2 -2
  29. package/package.json +3 -3
  30. package/dist/chunk-HQMSXIDX.js +0 -2185
@@ -0,0 +1,2642 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from 'node:module';
3
+ import { sanitizeTerminal } from './chunk-2DVQHK37.js';
4
+ import { resolvePackRoot, parseProofsConfig } from './chunk-OKELGJNN.js';
5
+ import { CHECK_ITEM_REASON_MAX_LENGTH, CHECK_ITEMS_MAX, CheckItemsSchema, CHECK_ITEM_REFS_MAX, CHECK_ITEM_ID_MAX_LENGTH, CHECK_ITEM_REF_PATH_MAX_LENGTH, JUDGE_NOT_RUN_ITEM_ID, REVIEWED_COMMIT_ITEM_ID } from './chunk-HE53NIRE.js';
6
+ import { createHash } from 'crypto';
7
+ import { join } from 'path';
8
+ import { pathToFileURL } from 'url';
9
+
10
+ createRequire(import.meta.url);
11
+
12
+ // ../../node_modules/balanced-match/dist/esm/index.js
13
+ var balanced = (a, b, str) => {
14
+ const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
15
+ const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
16
+ const r = ma !== null && mb != null && range(ma, mb, str);
17
+ return r && {
18
+ start: r[0],
19
+ end: r[1],
20
+ pre: str.slice(0, r[0]),
21
+ body: str.slice(r[0] + ma.length, r[1]),
22
+ post: str.slice(r[1] + mb.length)
23
+ };
24
+ };
25
+ var maybeMatch = (reg, str) => {
26
+ const m = str.match(reg);
27
+ return m ? m[0] : null;
28
+ };
29
+ var range = (a, b, str) => {
30
+ let begs, beg, left, right = void 0, result;
31
+ let ai = str.indexOf(a);
32
+ let bi = str.indexOf(b, ai + 1);
33
+ let i = ai;
34
+ if (ai >= 0 && bi > 0) {
35
+ if (a === b) {
36
+ return [ai, bi];
37
+ }
38
+ begs = [];
39
+ left = str.length;
40
+ while (i >= 0 && !result) {
41
+ if (i === ai) {
42
+ begs.push(i);
43
+ ai = str.indexOf(a, i + 1);
44
+ } else if (begs.length === 1) {
45
+ const r = begs.pop();
46
+ if (r !== void 0)
47
+ result = [r, bi];
48
+ } else {
49
+ beg = begs.pop();
50
+ if (beg !== void 0 && beg < left) {
51
+ left = beg;
52
+ right = bi;
53
+ }
54
+ bi = str.indexOf(b, i + 1);
55
+ }
56
+ i = ai < bi && ai >= 0 ? ai : bi;
57
+ }
58
+ if (begs.length && right !== void 0) {
59
+ result = [left, right];
60
+ }
61
+ }
62
+ return result;
63
+ };
64
+
65
+ // ../../node_modules/brace-expansion/dist/esm/index.js
66
+ var escSlash = "\0SLASH" + Math.random() + "\0";
67
+ var escOpen = "\0OPEN" + Math.random() + "\0";
68
+ var escClose = "\0CLOSE" + Math.random() + "\0";
69
+ var escComma = "\0COMMA" + Math.random() + "\0";
70
+ var escPeriod = "\0PERIOD" + Math.random() + "\0";
71
+ var escSlashPattern = new RegExp(escSlash, "g");
72
+ var escOpenPattern = new RegExp(escOpen, "g");
73
+ var escClosePattern = new RegExp(escClose, "g");
74
+ var escCommaPattern = new RegExp(escComma, "g");
75
+ var escPeriodPattern = new RegExp(escPeriod, "g");
76
+ var slashPattern = /\\\\/g;
77
+ var openPattern = /\\{/g;
78
+ var closePattern = /\\}/g;
79
+ var commaPattern = /\\,/g;
80
+ var periodPattern = /\\\./g;
81
+ var EXPANSION_MAX = 1e5;
82
+ var EXPANSION_MAX_LENGTH = 4e6;
83
+ var EXPANSION_MAX_DEPTH = 1e3;
84
+ var EXPANSION_MAX_REWRITES = 1e3;
85
+ function numeric(str) {
86
+ return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
87
+ }
88
+ function escapeBraces(str) {
89
+ return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
90
+ }
91
+ function unescapeBraces(str) {
92
+ return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
93
+ }
94
+ function pushAll(target, items) {
95
+ for (let i = 0; i < items.length; i++) {
96
+ target.push(items[i]);
97
+ }
98
+ }
99
+ function parseCommaParts(str) {
100
+ const parts = [];
101
+ let carry = "";
102
+ for (; ; ) {
103
+ const m = balanced("{", "}", str);
104
+ if (!m) {
105
+ const tail = str.split(",");
106
+ tail[0] = carry + tail[0];
107
+ pushAll(parts, tail);
108
+ return parts;
109
+ }
110
+ const { pre, body, post } = m;
111
+ const p = pre.split(",");
112
+ p[0] = carry + p[0];
113
+ p[p.length - 1] += "{" + body + "}";
114
+ if (!post.length) {
115
+ pushAll(parts, p);
116
+ return parts;
117
+ }
118
+ carry = p.pop();
119
+ pushAll(parts, p);
120
+ str = post;
121
+ }
122
+ }
123
+ function expand(str, options = {}) {
124
+ if (!str) {
125
+ return [];
126
+ }
127
+ const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH, maxDepth = EXPANSION_MAX_DEPTH, maxRewrites = EXPANSION_MAX_REWRITES } = options;
128
+ if (str.slice(0, 2) === "{}") {
129
+ str = "\\{\\}" + str.slice(2);
130
+ }
131
+ return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces);
132
+ }
133
+ function embrace(str) {
134
+ return "{" + str + "}";
135
+ }
136
+ function isPadded(el) {
137
+ return /^-?0\d/.test(el);
138
+ }
139
+ function lte(i, y) {
140
+ return i <= y;
141
+ }
142
+ function gte(i, y) {
143
+ return i >= y;
144
+ }
145
+ function combine(acc, pre, values, max, maxLength, dropEmpties) {
146
+ const out = [];
147
+ let length = 0;
148
+ for (let a = 0; a < acc.length; a++) {
149
+ for (let v = 0; v < values.length; v++) {
150
+ if (out.length >= max)
151
+ return out;
152
+ const expansion = acc[a] + pre + values[v];
153
+ if (dropEmpties && !expansion)
154
+ continue;
155
+ if (length + expansion.length > maxLength)
156
+ return out;
157
+ out.push(expansion);
158
+ length += expansion.length;
159
+ }
160
+ }
161
+ return out;
162
+ }
163
+ function expandSequence(body, isAlphaSequence, max, maxLength) {
164
+ const n = body.split(/\.\./);
165
+ const N = [];
166
+ if (n[0] === void 0 || n[1] === void 0) {
167
+ return N;
168
+ }
169
+ const x = numeric(n[0]);
170
+ const y = numeric(n[1]);
171
+ const width = Math.max(n[0].length, n[1].length);
172
+ let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
173
+ let test = lte;
174
+ const reverse = y < x;
175
+ if (reverse) {
176
+ incr *= -1;
177
+ test = gte;
178
+ }
179
+ const pad = n.some(isPadded);
180
+ let length = 0;
181
+ for (let i = x; test(i, y) && N.length < max; i += incr) {
182
+ let c;
183
+ if (isAlphaSequence) {
184
+ c = String.fromCharCode(i);
185
+ if (c === "\\") {
186
+ c = "";
187
+ }
188
+ } else {
189
+ c = String(i);
190
+ if (pad) {
191
+ const need = width - c.length;
192
+ if (need > 0) {
193
+ const z = new Array(need + 1).join("0");
194
+ if (i < 0) {
195
+ c = "-" + z + c.slice(1);
196
+ } else {
197
+ c = z + c;
198
+ }
199
+ }
200
+ }
201
+ }
202
+ if (length + c.length > maxLength)
203
+ break;
204
+ N.push(c);
205
+ length += c.length;
206
+ }
207
+ return N;
208
+ }
209
+ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
210
+ if (depth > maxDepth) {
211
+ return [str];
212
+ }
213
+ let acc = [""];
214
+ let rewrites = 0;
215
+ let dropEmpties = false;
216
+ let firstGroup = true;
217
+ for (; ; ) {
218
+ const m = balanced("{", "}", str);
219
+ if (!m) {
220
+ return combine(acc, str, [""], max, maxLength, dropEmpties);
221
+ }
222
+ const pre = m.pre;
223
+ if (/\$$/.test(pre)) {
224
+ acc = combine(acc, pre + "{" + m.body + "}", [""], max, maxLength, dropEmpties && !m.post.length);
225
+ firstGroup = false;
226
+ if (!m.post.length)
227
+ break;
228
+ str = m.post;
229
+ continue;
230
+ }
231
+ const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
232
+ const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
233
+ const isSequence = isNumericSequence || isAlphaSequence;
234
+ const isOptions = m.body.indexOf(",") >= 0;
235
+ if (!isSequence && !isOptions) {
236
+ if (rewrites < maxRewrites && m.post.match(/,(?!,).*\}/)) {
237
+ rewrites++;
238
+ str = m.pre + "{" + m.body + escClose + m.post;
239
+ isTop = true;
240
+ continue;
241
+ }
242
+ return combine(acc, pre + "{" + m.body + "}" + m.post, [""], max, maxLength, dropEmpties);
243
+ }
244
+ if (firstGroup) {
245
+ dropEmpties = isTop && !isSequence;
246
+ firstGroup = false;
247
+ }
248
+ let values;
249
+ if (isSequence) {
250
+ values = expandSequence(m.body, isAlphaSequence, max, maxLength);
251
+ } else {
252
+ let n = parseCommaParts(m.body);
253
+ if (n.length === 1 && n[0] !== void 0) {
254
+ n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace);
255
+ if (n.length === 1) {
256
+ acc = combine(acc, pre + n[0], [""], max, maxLength, dropEmpties && !m.post.length);
257
+ if (!m.post.length)
258
+ break;
259
+ str = m.post;
260
+ continue;
261
+ }
262
+ }
263
+ let dropsEmpties = dropEmpties && !m.post.length && !pre;
264
+ for (let d = 0; dropsEmpties && d < acc.length; d++) {
265
+ if (acc[d]) {
266
+ dropsEmpties = false;
267
+ }
268
+ }
269
+ values = [];
270
+ let valuesLength = 0;
271
+ outer: for (let j = 0; j < n.length; j++) {
272
+ const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false);
273
+ for (let k = 0; k < expanded.length; k++) {
274
+ const v = expanded[k];
275
+ if (dropsEmpties && !v)
276
+ continue;
277
+ if (values.length >= max || valuesLength + v.length > maxLength) {
278
+ break outer;
279
+ }
280
+ values.push(v);
281
+ valuesLength += v.length;
282
+ }
283
+ }
284
+ }
285
+ acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
286
+ if (!m.post.length)
287
+ break;
288
+ str = m.post;
289
+ }
290
+ return acc;
291
+ }
292
+
293
+ // ../../node_modules/@isaacs/nonrecursive-glob-match/dist/esm/numeric-range.js
294
+ var digit = (a, b) => a === b ? { t: "lit", ch: String(a) } : { t: "class", re: new RegExp(`^[${a}-${b}]$`) };
295
+ var prefix = (d, alts) => alts.map((s) => [digit(d, d), ...s]);
296
+ var fixed = (a, b) => {
297
+ if (!a)
298
+ return [[]];
299
+ let lo = +a[0];
300
+ let hi = +b[0];
301
+ const ra = a.slice(1);
302
+ const rb = b.slice(1);
303
+ if (lo === hi)
304
+ return prefix(lo, fixed(ra, rb));
305
+ const zeros = "0".repeat(ra.length);
306
+ const nines = "9".repeat(ra.length);
307
+ const out = [];
308
+ if (ra !== zeros)
309
+ out.push(...prefix(lo++, fixed(ra, nines)));
310
+ const last = rb === nines ? [] : prefix(hi--, fixed(zeros, rb));
311
+ if (lo <= hi) {
312
+ out.push([digit(lo, hi), ...Array.from(ra, () => digit(0, 9))]);
313
+ }
314
+ out.push(...last);
315
+ return out;
316
+ };
317
+ var nonneg = (a, b, width) => {
318
+ if (width) {
319
+ return fixed(String(a).padStart(width, "0"), String(b).padStart(width, "0"));
320
+ }
321
+ const out = [];
322
+ for (let len = String(a).length; len <= String(b).length; len++) {
323
+ const lo = Math.max(a, len === 1 ? 0 : 10 ** (len - 1));
324
+ const hi = Math.min(b, 10 ** len - 1);
325
+ out.push(...fixed(String(lo), String(hi)));
326
+ }
327
+ return out;
328
+ };
329
+ var numericRange = (loStr, hiStr) => {
330
+ let lo = Number(loStr);
331
+ let hi = Number(hiStr);
332
+ if (!Number.isSafeInteger(lo) || !Number.isSafeInteger(hi))
333
+ return;
334
+ if (lo > hi)
335
+ [lo, hi] = [hi, lo];
336
+ const padded = /^-?0\d/.test(loStr) || /^-?0\d/.test(hiStr);
337
+ const width = padded ? Math.max(loStr.length, hiStr.length) : 0;
338
+ const out = [];
339
+ if (lo < 0) {
340
+ const neg = nonneg(Math.max(-hi, 1), -lo, width && width - 1);
341
+ out.push(...neg.map((s) => [{ t: "lit", ch: "-" }, ...s]));
342
+ }
343
+ if (hi >= 0)
344
+ out.push(...nonneg(Math.max(lo, 0), hi, width));
345
+ return out;
346
+ };
347
+
348
+ // ../../node_modules/@isaacs/nonrecursive-glob-match/dist/esm/parse-class.js
349
+ var posixClasses = {
350
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}"],
351
+ "[:alpha:]": ["\\p{L}\\p{Nl}"],
352
+ "[:ascii:]": ["\\x00-\\x7f"],
353
+ "[:blank:]": ["\\p{Zs}\\t"],
354
+ "[:cntrl:]": ["\\p{Cc}"],
355
+ "[:digit:]": ["\\p{Nd}"],
356
+ "[:graph:]": ["\\p{Z}\\p{C}", true],
357
+ "[:lower:]": ["\\p{Ll}"],
358
+ "[:print:]": ["\\p{C}", true],
359
+ "[:punct:]": ["\\p{P}\\p{S}"],
360
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f"],
361
+ "[:upper:]": ["\\p{Lu}"],
362
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}"],
363
+ "[:xdigit:]": ["A-Fa-f0-9"]
364
+ };
365
+ var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
366
+ var noMatch = /$./;
367
+ var parseClass = (glob, position, nocase = false, form) => {
368
+ const norm = (c) => {
369
+ const n = form ? c.normalize(form) : c;
370
+ return [...n].length === 1 ? n : c;
371
+ };
372
+ const pos = position;
373
+ if (glob.charAt(pos) !== "[") {
374
+ throw new Error("not in a brace expression");
375
+ }
376
+ const ranges = [];
377
+ const negs = [];
378
+ let i = pos + 1;
379
+ let sawStart = false;
380
+ let escaping = false;
381
+ let negate = false;
382
+ let endPos = pos;
383
+ let rangeStart = "";
384
+ WHILE: while (i < glob.length) {
385
+ const c = String.fromCodePoint(glob.codePointAt(i));
386
+ if ((c === "!" || c === "^") && i === pos + 1) {
387
+ negate = true;
388
+ i++;
389
+ continue;
390
+ }
391
+ if (c === "]" && sawStart && !escaping) {
392
+ endPos = i + 1;
393
+ break;
394
+ }
395
+ sawStart = true;
396
+ if (c === "\\") {
397
+ if (!escaping) {
398
+ escaping = true;
399
+ i++;
400
+ continue;
401
+ }
402
+ }
403
+ if (c === "[" && !escaping) {
404
+ for (const [cls, [unip, neg]] of Object.entries(posixClasses)) {
405
+ if (glob.startsWith(cls, i)) {
406
+ if (rangeStart) {
407
+ return [noMatch, glob.length - pos];
408
+ }
409
+ i += cls.length;
410
+ if (neg)
411
+ negs.push(unip);
412
+ else
413
+ ranges.push(unip);
414
+ continue WHILE;
415
+ }
416
+ }
417
+ }
418
+ escaping = false;
419
+ const n = norm(c);
420
+ if (rangeStart) {
421
+ if (n.codePointAt(0) > rangeStart.codePointAt(0)) {
422
+ ranges.push(braceEscape(rangeStart) + "-" + braceEscape(n));
423
+ } else if (n === rangeStart) {
424
+ ranges.push(braceEscape(n));
425
+ }
426
+ rangeStart = "";
427
+ i += c.length;
428
+ continue;
429
+ }
430
+ if (glob.startsWith("-]", i + c.length)) {
431
+ ranges.push(braceEscape(n + "-"));
432
+ i += c.length + 1;
433
+ continue;
434
+ }
435
+ if (glob.startsWith("-", i + c.length)) {
436
+ rangeStart = n;
437
+ i += c.length + 1;
438
+ continue;
439
+ }
440
+ ranges.push(braceEscape(n));
441
+ i += c.length;
442
+ }
443
+ if (endPos < i) {
444
+ return [noMatch, 0];
445
+ }
446
+ if (!ranges.length && !negs.length) {
447
+ return [noMatch, glob.length - pos];
448
+ }
449
+ const sranges = "[" + (negate ? "^" : "") + ranges.join("") + "]";
450
+ const snegs = "[" + (negate ? "" : "^") + negs.join("") + "]";
451
+ const comb = "^" + (ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs);
452
+ return [new RegExp(comb, nocase ? "iu" : "u"), endPos - pos];
453
+ };
454
+
455
+ // ../../node_modules/@isaacs/nonrecursive-glob-match/dist/esm/index.js
456
+ var MATCH = { t: "match", id: 0 };
457
+ var extTypes = "!?+*@";
458
+ var lit = (ch) => ({ t: "lit", ch });
459
+ var reEscape = (s) => s.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
460
+ var newFoldRe = (s) => new RegExp(`^${reEscape(s)}$`, "iu");
461
+ var foldCache = /* @__PURE__ */ new Map();
462
+ var foldRe = (ch) => {
463
+ let re = foldCache.get(ch);
464
+ if (!re) {
465
+ re = newFoldRe(ch);
466
+ if (foldCache.size >= 1e3)
467
+ foldCache.clear();
468
+ foldCache.set(ch, re);
469
+ }
470
+ return re;
471
+ };
472
+ var litMatch = (l, c) => {
473
+ if (c === l.ch)
474
+ return true;
475
+ if (!l.re)
476
+ return false;
477
+ const code = c.charCodeAt(0);
478
+ if (code >= 128)
479
+ return l.re.test(c);
480
+ const ascii = l.ascii ??= new Uint8Array(128);
481
+ ascii[code] ||= l.re.test(c) ? 1 : 2;
482
+ return ascii[code] === 1;
483
+ };
484
+ var tokenize = (p, nocase, noext, form, mark) => {
485
+ const toks = [];
486
+ for (let i = 0; i < p.length; ) {
487
+ const c = String.fromCodePoint(p.codePointAt(i));
488
+ if (mark) {
489
+ const m = c === "\\" && p.startsWith(mark, i + 1) ? 1 : 0;
490
+ if (m || c === mark) {
491
+ const start = i + m + mark.length;
492
+ const end = p.indexOf(mark, start);
493
+ const r = /^(-?\d+)\.\.(-?\d+)$/.exec(p.slice(start, end));
494
+ const alts = end !== -1 && r && numericRange(r[1], r[2]);
495
+ if (alts) {
496
+ toks.push({ t: "ext", type: "@", alts });
497
+ i = end + mark.length;
498
+ continue;
499
+ }
500
+ }
501
+ }
502
+ if (c === "\\") {
503
+ const e = p.codePointAt(i + 1);
504
+ const ch = e === void 0 ? c : String.fromCodePoint(e);
505
+ toks.push(lit(ch));
506
+ i += 1 + ch.length;
507
+ continue;
508
+ }
509
+ if (c === "[") {
510
+ const [re, consumed] = parseClass(p, i, nocase, form);
511
+ if (consumed) {
512
+ toks.push({ t: "class", re });
513
+ i += consumed;
514
+ continue;
515
+ }
516
+ }
517
+ if (!noext && extTypes.includes(c) && p[i + 1] === "(") {
518
+ toks.push({ t: "open", type: c });
519
+ i += 2;
520
+ continue;
521
+ }
522
+ toks.push(!noext && c === "|" ? { t: "bar" } : !noext && c === ")" ? { t: "close" } : c === "*" ? { t: "star" } : c === "?" ? { t: "any" } : lit(c));
523
+ i += c.length;
524
+ }
525
+ return toks;
526
+ };
527
+ var pair = (toks) => {
528
+ const pairs = /* @__PURE__ */ new Map();
529
+ const stack = [];
530
+ toks.forEach((tok, i) => {
531
+ if (tok.t === "open")
532
+ stack.push(i);
533
+ else if (tok.t === "close" && stack.length)
534
+ pairs.set(stack.pop(), i);
535
+ });
536
+ return pairs;
537
+ };
538
+ var build = (toks, pairs, start, end, top) => {
539
+ let seq = [];
540
+ const alts = [seq];
541
+ for (let i = start; i < end; i++) {
542
+ const tok = toks[i];
543
+ const close = pairs.get(i);
544
+ if (tok.t === "open" && close !== void 0) {
545
+ const sub = build(toks, pairs, i + 1, close, false);
546
+ seq.push({ t: "ext", type: tok.type, alts: sub });
547
+ i = close;
548
+ } else if (tok.t === "bar" && !top) {
549
+ alts.push(seq = []);
550
+ } else if (tok.t === "open") {
551
+ seq.push(lit(tok.type), lit("("));
552
+ } else if (tok.t === "bar") {
553
+ seq.push(lit("|"));
554
+ } else if (tok.t === "close") {
555
+ seq.push(lit(")"));
556
+ } else {
557
+ seq.push(tok);
558
+ }
559
+ }
560
+ return alts;
561
+ };
562
+ var normalize = (items, form) => {
563
+ const out = [];
564
+ let run = "";
565
+ const flush = () => {
566
+ for (const ch of run.normalize(form))
567
+ out.push(lit(ch));
568
+ run = "";
569
+ };
570
+ for (const it of items) {
571
+ if (it.t === "lit") {
572
+ run += it.ch;
573
+ continue;
574
+ }
575
+ flush();
576
+ out.push(it.t === "ext" ? { ...it, alts: it.alts.map((a) => normalize(a, form)) } : it);
577
+ }
578
+ flush();
579
+ return out;
580
+ };
581
+ var compile = (items, nocase) => {
582
+ let id = 1;
583
+ const split = (out) => ({ t: "split", id: id++, out });
584
+ const seq = (items2, next) => items2.reduceRight((next2, it) => item(it, next2), next);
585
+ const item = (it, next) => {
586
+ switch (it.t) {
587
+ case "lit":
588
+ const re = nocase ? foldRe(it.ch) : void 0;
589
+ return { t: "lit", id: id++, ch: it.ch, re, next };
590
+ case "any":
591
+ case "star":
592
+ return { t: it.t, id: id++, next };
593
+ case "class":
594
+ return { t: "class", id: id++, re: it.re, next };
595
+ }
596
+ const alts = (next2) => it.alts.map((a) => seq(a, next2));
597
+ switch (it.type) {
598
+ case "@":
599
+ return split(alts(next));
600
+ case "?":
601
+ return split([next, ...alts(next)]);
602
+ case "!":
603
+ return { t: "neg", id: id++, sub: split(alts(MATCH)), next };
604
+ }
605
+ const after = split([]);
606
+ const entry = split(alts(after));
607
+ after.out.push(next, entry);
608
+ return it.type === "*" ? after : entry;
609
+ };
610
+ const start = seq(items, MATCH);
611
+ return [start, id];
612
+ };
613
+ var show = (start) => {
614
+ const lines = [];
615
+ const seen = /* @__PURE__ */ new Set();
616
+ const ref = (n) => n.t === "match" ? "match" : String(n.id);
617
+ const walk = (n, indent) => {
618
+ if (n.t === "match" || seen.has(n))
619
+ return;
620
+ seen.add(n);
621
+ const line = (desc) => lines.push(`${indent}${n.id}: ${desc}`);
622
+ switch (n.t) {
623
+ case "split":
624
+ line(`split -> ${n.out.map(ref).join(", ")}`);
625
+ for (const o of n.out)
626
+ walk(o, indent);
627
+ return;
628
+ case "neg":
629
+ line(`!(${ref(n.sub)}) -> ${ref(n.next)}`);
630
+ walk(n.sub, indent + " ");
631
+ return walk(n.next, indent);
632
+ case "lit":
633
+ line(`${JSON.stringify(n.ch)} -> ${ref(n.next)}`);
634
+ break;
635
+ case "class":
636
+ line(`${n.re} -> ${ref(n.next)}`);
637
+ break;
638
+ default:
639
+ line(`${n.t === "any" ? "?" : "*"} -> ${ref(n.next)}`);
640
+ }
641
+ walk(n.next, indent);
642
+ };
643
+ walk(start, "");
644
+ return [`start -> ${ref(start)}`, ...lines].join("\n");
645
+ };
646
+ var State = class {
647
+ // set by the Sim, to mark the nodes that this state has
648
+ gen;
649
+ threads = [];
650
+ match = false;
651
+ runs = [];
652
+ // the sorted ids of the threads, with 0 for a match, once the
653
+ // state is done
654
+ ids = [];
655
+ constructor(gen) {
656
+ this.gen = gen;
657
+ }
658
+ // no threads, so nothing more can match
659
+ get dead() {
660
+ return !this.threads.length && !this.match && !this.runs.length;
661
+ }
662
+ };
663
+ var sameState = (a, b) => {
664
+ if (a.ids.length !== b.ids.length)
665
+ return false;
666
+ if (a.runs.length !== b.runs.length)
667
+ return false;
668
+ if (a.ids.some((id, i) => id !== b.ids[i]))
669
+ return false;
670
+ return a.runs.every((r) => b.runs.some((o) => o.neg === r.neg && sameState(o.state, r.state)));
671
+ };
672
+ var marks = (size) => ({
673
+ has: new Float64Array(size),
674
+ seen: new Float64Array(size),
675
+ gen: 0
676
+ });
677
+ var Sim = class {
678
+ // `.` and `..` only match literal dots, even with `dot:true`
679
+ dots;
680
+ // the string starts with `.`, and `dot:true` is not set
681
+ dotStart;
682
+ #marks;
683
+ constructor(dots, dotStart, marks2) {
684
+ this.dots = dots;
685
+ this.dotStart = dotStart;
686
+ this.#marks = marks2;
687
+ }
688
+ state() {
689
+ return new State(++this.#marks.gen);
690
+ }
691
+ // sort the ids of a state, once it has all of its threads
692
+ done(state) {
693
+ state.ids = state.threads.map((n) => n.id).sort((a, b) => a - b);
694
+ if (state.match)
695
+ state.ids.unshift(MATCH.id);
696
+ return state;
697
+ }
698
+ // true the first time that the state walks through the node, so
699
+ // that loops in the graph stop
700
+ #visit(state, node) {
701
+ const { seen } = this.#marks;
702
+ if (seen[node.id] === state.gen)
703
+ return false;
704
+ seen[node.id] = state.gen;
705
+ return true;
706
+ }
707
+ #addThread(state, node) {
708
+ const { has } = this.#marks;
709
+ if (has[node.id] === state.gen)
710
+ return false;
711
+ has[node.id] = state.gen;
712
+ state.threads.push(node);
713
+ return true;
714
+ }
715
+ // wildcards only match a leading dot if `dot:true`. In a negated
716
+ // sub-pattern, this does not apply, because the negation itself
717
+ // can not match a leading dot.
718
+ restricted(i, top) {
719
+ return top && (this.dots || this.dotStart && i === 0);
720
+ }
721
+ add(state, node, i, top) {
722
+ switch (node.t) {
723
+ case "split":
724
+ if (!this.#visit(state, node))
725
+ return;
726
+ for (const o of node.out)
727
+ this.add(state, o, i, top);
728
+ return;
729
+ case "neg":
730
+ if (!this.#visit(state, node))
731
+ return;
732
+ const sub = this.state();
733
+ this.add(sub, node.sub, i, false);
734
+ this.done(sub);
735
+ return this.addRun(state, { t: "run", neg: node, state: sub }, i, top);
736
+ case "star":
737
+ if (this.restricted(i, top))
738
+ return;
739
+ if (this.#addThread(state, node))
740
+ this.add(state, node.next, i, top);
741
+ return;
742
+ case "match":
743
+ state.match = true;
744
+ return;
745
+ default:
746
+ this.#addThread(state, node);
747
+ }
748
+ }
749
+ addRun(state, run, i, top) {
750
+ for (const r of state.runs) {
751
+ if (r.neg === run.neg && sameState(r.state, run.state))
752
+ return;
753
+ }
754
+ state.runs.push(run);
755
+ if (!run.state.match) {
756
+ this.add(state, run.neg.next, i, top);
757
+ }
758
+ }
759
+ // the threads after char `c`, at index `i`
760
+ step(state, c, i, top) {
761
+ const next = this.state();
762
+ for (const th of state.threads) {
763
+ switch (th.t) {
764
+ case "lit":
765
+ if (litMatch(th, c)) {
766
+ this.add(next, th.next, i + 1, top);
767
+ }
768
+ break;
769
+ case "any":
770
+ if (!this.restricted(i, top))
771
+ this.add(next, th.next, i + 1, top);
772
+ break;
773
+ case "class":
774
+ if (!this.restricted(i, top) && th.re.test(c)) {
775
+ this.add(next, th.next, i + 1, top);
776
+ }
777
+ break;
778
+ case "star":
779
+ if (!this.restricted(i, top))
780
+ this.add(next, th, i + 1, top);
781
+ }
782
+ }
783
+ if (!this.restricted(i, top)) {
784
+ for (const run of state.runs) {
785
+ if (run.state.dead) {
786
+ this.addRun(next, run, i + 1, top);
787
+ continue;
788
+ }
789
+ const sub = this.step(run.state, c, i, false);
790
+ this.addRun(next, { t: "run", neg: run.neg, state: sub }, i + 1, top);
791
+ }
792
+ }
793
+ return this.done(next);
794
+ }
795
+ };
796
+ var stateKey = (state) => {
797
+ const ids = state.ids.join();
798
+ if (!state.runs.length)
799
+ return ids;
800
+ const runs = state.runs.map((r) => `${r.neg.id}(${stateKey(r.state)})`);
801
+ return `${ids}|${runs.sort().join("|")}`;
802
+ };
803
+ var DFA_BUDGET = 1 << 18;
804
+ var Dfa = class {
805
+ #start;
806
+ #states = /* @__PURE__ */ new Map();
807
+ #size = 0;
808
+ #plain;
809
+ #dotStart;
810
+ #sim;
811
+ #dotSim;
812
+ constructor(start, marks2) {
813
+ this.#start = start;
814
+ this.#sim = new Sim(false, false, marks2);
815
+ this.#dotSim = new Sim(false, true, marks2);
816
+ }
817
+ #make(state) {
818
+ return {
819
+ state,
820
+ match: state.match,
821
+ dead: state.dead,
822
+ next: /* @__PURE__ */ new Map()
823
+ };
824
+ }
825
+ #intern(state) {
826
+ const key = stateKey(state);
827
+ const found = this.#states.get(key);
828
+ if (found)
829
+ return found;
830
+ if (this.#size > DFA_BUDGET)
831
+ this.#clear();
832
+ const d = this.#make(state);
833
+ this.#states.set(key, d);
834
+ this.#size += key.length + 1;
835
+ return d;
836
+ }
837
+ #clear() {
838
+ this.#states.clear();
839
+ this.#size = 0;
840
+ this.#plain = void 0;
841
+ this.#dotStart = void 0;
842
+ }
843
+ start(dotStart) {
844
+ if (dotStart) {
845
+ if (this.#dotStart)
846
+ return this.#dotStart;
847
+ const state2 = this.#dotSim.state();
848
+ this.#dotSim.add(state2, this.#start, 0, true);
849
+ return this.#dotStart = this.#make(this.#dotSim.done(state2));
850
+ }
851
+ if (this.#plain)
852
+ return this.#plain;
853
+ const state = this.#sim.state();
854
+ this.#sim.add(state, this.#start, 0, true);
855
+ return this.#plain = this.#intern(this.#sim.done(state));
856
+ }
857
+ // the next state, after a miss in `d.ascii`
858
+ next(d, c) {
859
+ const code = c.charCodeAt(0);
860
+ const found = code < 128 ? void 0 : d.next.get(c);
861
+ if (found)
862
+ return found;
863
+ const n = d === this.#dotStart ? this.#intern(this.#dotSim.step(d.state, c, 0, true)) : this.#intern(this.#sim.step(d.state, c, 1, true));
864
+ if (code < 128) {
865
+ if (!d.ascii) {
866
+ d.ascii = new Array(128);
867
+ this.#size += 128;
868
+ }
869
+ d.ascii[code] = n;
870
+ } else {
871
+ d.next.set(c, n);
872
+ }
873
+ this.#size++;
874
+ return n;
875
+ }
876
+ };
877
+ var linear = (start) => {
878
+ const nodes = [];
879
+ for (let n = start; n.t !== "match"; n = n.next) {
880
+ if (n.t === "split" || n.t === "neg")
881
+ return void 0;
882
+ nodes.push(n);
883
+ }
884
+ return nodes;
885
+ };
886
+ var testLinear = (nodes, chars, start, end) => {
887
+ let ni = 0;
888
+ let ci = start;
889
+ let starNi = -1;
890
+ let starCi = 0;
891
+ while (ci < end) {
892
+ const n = nodes[ni];
893
+ if (n?.t === "star") {
894
+ starNi = ni++;
895
+ starCi = ci;
896
+ continue;
897
+ }
898
+ const c = chars[ci];
899
+ if (n && (n.t === "any" || n.t === "lit" && litMatch(n, c) || n.t === "class" && n.re.test(c))) {
900
+ ni++;
901
+ ci++;
902
+ continue;
903
+ }
904
+ if (starNi === -1)
905
+ return false;
906
+ ni = starNi + 1;
907
+ ci = ++starCi;
908
+ }
909
+ while (nodes[ni]?.t === "star")
910
+ ni++;
911
+ return ni === nodes.length;
912
+ };
913
+ var lengths = (items) => {
914
+ let min = 0;
915
+ let max = 0;
916
+ for (const it of items) {
917
+ const [lo, hi] = itemLengths(it);
918
+ min += lo;
919
+ max += hi;
920
+ }
921
+ return [min, max];
922
+ };
923
+ var itemLengths = (it) => {
924
+ if (it.t === "star")
925
+ return [0, Infinity];
926
+ if (it.t !== "ext")
927
+ return [1, 1];
928
+ if (it.type === "!")
929
+ return [0, Infinity];
930
+ const alts = it.alts.map(lengths);
931
+ const min = Math.min(...alts.map((a) => a[0]));
932
+ const max = Math.max(...alts.map((a) => a[1]));
933
+ const loop = max === 0 ? 0 : Infinity;
934
+ return it.type === "@" ? [min, max] : it.type === "?" ? [0, max] : it.type === "*" ? [0, loop] : [min, loop];
935
+ };
936
+ var hasAffix = (lits, chars, start) => {
937
+ for (let j = 0; j < lits.length; j++) {
938
+ if (!litMatch(lits[j], chars[start + j]))
939
+ return false;
940
+ }
941
+ return true;
942
+ };
943
+ var slashOrSurrogate = /[/\ud800-\udfff]/;
944
+ var surrogate = /[\ud800-\udfff]/;
945
+ var codePoints = (s) => surrogate.test(s) ? [...s] : s;
946
+ var noSlash = (s) => {
947
+ if (s.includes("/")) {
948
+ throw new Error("can only match a single path portion, got: " + s);
949
+ }
950
+ };
951
+ var Matcher = class {
952
+ pattern;
953
+ options;
954
+ #start;
955
+ // the number of node ids
956
+ #size;
957
+ #marks;
958
+ // the Sim for strings that are only `.` or `..`
959
+ #dotsSim;
960
+ // the string to compare, if the pattern has no magic. With
961
+ // `nocase:true`, the RegExp that folds case is made when it is
962
+ // first used.
963
+ #literal;
964
+ #literalFold = false;
965
+ #literalRe;
966
+ // the nodes between the prefix and suffix, if the graph is a
967
+ // single chain
968
+ #linear;
969
+ // the linear nodes are only `*` and `?`, so the length bounds and
970
+ // the prefix and suffix decide the match
971
+ #wild = false;
972
+ // the least and most chars that a match can have
973
+ #min = 0;
974
+ #max = Infinity;
975
+ // the literals that a match must start and end with. Each one
976
+ // matches exactly one char, and they are distinct items in the
977
+ // pattern, so a string that does not have them can not match.
978
+ #prefix = [];
979
+ #suffix = [];
980
+ // the prefix and suffix as strings, if they do not fold case
981
+ #prefixStr;
982
+ #suffixStr;
983
+ // there is a prefix or suffix to check
984
+ #affix = false;
985
+ #dfa;
986
+ #form;
987
+ constructor(pattern, options = {}) {
988
+ if (pattern.includes("/")) {
989
+ throw new Error("can only match a single path portion, got pattern: " + pattern);
990
+ }
991
+ this.pattern = pattern;
992
+ this.options = options;
993
+ const { nocase = false, noext = false, normalize: n } = options;
994
+ this.#form = n === true ? "NFC" : n || void 0;
995
+ const literal2 = /^[?*+@]\(\)$/.test(pattern);
996
+ const toks = tokenize(pattern, nocase, noext || literal2, this.#form, options.rangeMark);
997
+ let [items] = build(toks, pair(toks), 0, toks.length, true);
998
+ if (this.#form)
999
+ items = normalize(items, this.#form);
1000
+ const [start, size] = compile(items, nocase);
1001
+ this.#start = start;
1002
+ this.#size = size;
1003
+ if (items.every((it) => it.t === "lit")) {
1004
+ this.#literal = items.map((it) => it.ch).join("");
1005
+ this.#literalFold = nocase;
1006
+ } else {
1007
+ const lit2 = (it) => it.t !== "lit" ? void 0 : nocase ? { ch: it.ch, re: foldRe(it.ch) } : { ch: it.ch };
1008
+ for (const it of items) {
1009
+ const l = lit2(it);
1010
+ if (!l)
1011
+ break;
1012
+ this.#prefix.push(l);
1013
+ }
1014
+ for (let j = items.length - 1; j >= 0; j--) {
1015
+ const l = lit2(items[j]);
1016
+ if (!l)
1017
+ break;
1018
+ this.#suffix.unshift(l);
1019
+ }
1020
+ this.#affix = !!(this.#prefix.length || this.#suffix.length);
1021
+ if (!nocase) {
1022
+ this.#prefixStr = this.#prefix.map((l) => l.ch).join("");
1023
+ this.#suffixStr = this.#suffix.map((l) => l.ch).join("");
1024
+ }
1025
+ this.#linear = linear(this.#start)?.slice(this.#prefix.length, -this.#suffix.length || void 0);
1026
+ this.#wild = !!this.#linear?.every((n2) => n2.t === "star" || n2.t === "any");
1027
+ const [min, max] = lengths(items);
1028
+ this.#min = min;
1029
+ this.#max = max;
1030
+ }
1031
+ }
1032
+ test(s) {
1033
+ if (this.#form) {
1034
+ noSlash(s);
1035
+ return this.#test(s.normalize(this.#form));
1036
+ }
1037
+ if (slashOrSurrogate.test(s)) {
1038
+ noSlash(s);
1039
+ return this.#test(s, [...s]);
1040
+ }
1041
+ return this.#test(s, s);
1042
+ }
1043
+ /**
1044
+ * The same as {@link Matcher#test}, but the string is not checked
1045
+ * for `/` chars, so the result for a string that has one is not
1046
+ * defined. Only use it for a string that is known to be one path
1047
+ * portion, such as a part of a path that was split on `/`. It can
1048
+ * be faster, because some patterns do not need to look at each char
1049
+ * of the string.
1050
+ */
1051
+ testUnchecked(s) {
1052
+ return this.#test(this.#form ? s.normalize(this.#form) : s);
1053
+ }
1054
+ // Test a string that has no `/`. `chars` indexes it by code point.
1055
+ // If it is not given, it is only found if a step needs it.
1056
+ #test(s, chars) {
1057
+ if (this.#literal !== void 0) {
1058
+ return this.#literalFold ? (this.#literalRe ??= newFoldRe(this.#literal)).test(s) : s === this.#literal;
1059
+ }
1060
+ const min = this.#min;
1061
+ const max = this.#max;
1062
+ if (chars === void 0) {
1063
+ const most = s.length;
1064
+ const least = most + 1 >> 1;
1065
+ if (most < min || least > max)
1066
+ return false;
1067
+ if (least < min || most > max)
1068
+ chars = codePoints(s);
1069
+ }
1070
+ if (chars !== void 0 && (chars.length < min || chars.length > max)) {
1071
+ return false;
1072
+ }
1073
+ const prefix2 = this.#prefix.length;
1074
+ if (this.#affix) {
1075
+ if (this.#prefixStr !== void 0 && this.#suffixStr !== void 0) {
1076
+ if (!s.startsWith(this.#prefixStr) || !s.endsWith(this.#suffixStr)) {
1077
+ return false;
1078
+ }
1079
+ } else {
1080
+ chars ??= codePoints(s);
1081
+ const end = chars.length - this.#suffix.length;
1082
+ if (!hasAffix(this.#prefix, chars, 0) || !hasAffix(this.#suffix, chars, end)) {
1083
+ return false;
1084
+ }
1085
+ }
1086
+ }
1087
+ const dotStart = !this.options.dot && s.startsWith(".");
1088
+ if (this.#linear) {
1089
+ if (s === "." || s === "..")
1090
+ return false;
1091
+ if (dotStart && !prefix2)
1092
+ return false;
1093
+ if (this.#wild)
1094
+ return true;
1095
+ chars ??= codePoints(s);
1096
+ const end = chars.length - this.#suffix.length;
1097
+ return testLinear(this.#linear, chars, prefix2, end);
1098
+ }
1099
+ chars ??= codePoints(s);
1100
+ if (s === "." || s === "..") {
1101
+ this.#marks ??= marks(this.#size);
1102
+ const sim = this.#dotsSim ??= new Sim(true, false, this.#marks);
1103
+ const start = sim.state();
1104
+ sim.add(start, this.#start, 0, true);
1105
+ let state = sim.done(start);
1106
+ for (let i = 0; i < chars.length; i++) {
1107
+ state = sim.step(state, chars[i], i, true);
1108
+ }
1109
+ return state.match;
1110
+ }
1111
+ this.#marks ??= marks(this.#size);
1112
+ const dfa = this.#dfa ??= new Dfa(this.#start, this.#marks);
1113
+ let d = dfa.start(dotStart);
1114
+ const str = chars === s;
1115
+ for (let i = 0; i < chars.length; i++) {
1116
+ if (d.dead)
1117
+ return false;
1118
+ const code = str ? s.charCodeAt(i) : chars[i].charCodeAt(0);
1119
+ d = d.ascii?.[code] ?? dfa.next(d, chars[i]);
1120
+ }
1121
+ return d.match;
1122
+ }
1123
+ /** a readable listing of the state machine */
1124
+ toString() {
1125
+ return show(this.#start);
1126
+ }
1127
+ };
1128
+
1129
+ // ../../node_modules/minimatch/dist/esm/assert-valid-pattern.js
1130
+ var MAX_PATTERN_LENGTH = 1024 * 64;
1131
+ var assertValidPattern = (pattern) => {
1132
+ if (typeof pattern !== "string") {
1133
+ throw new TypeError("invalid pattern");
1134
+ }
1135
+ if (pattern.length > MAX_PATTERN_LENGTH) {
1136
+ throw new TypeError("pattern is too long");
1137
+ }
1138
+ };
1139
+
1140
+ // ../../node_modules/minimatch/dist/esm/escape.js
1141
+ var escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {}) => {
1142
+ if (magicalBraces) {
1143
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&");
1144
+ }
1145
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
1146
+ };
1147
+
1148
+ // ../../node_modules/minimatch/dist/esm/unescape.js
1149
+ var unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}) => {
1150
+ if (magicalBraces) {
1151
+ return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1");
1152
+ }
1153
+ return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
1154
+ };
1155
+
1156
+ // ../../node_modules/minimatch/dist/esm/index.js
1157
+ var minimatch = (p, pattern, options = {}) => {
1158
+ assertValidPattern(pattern);
1159
+ if (!options.nocomment && pattern.charAt(0) === "#") {
1160
+ return false;
1161
+ }
1162
+ return cachedMinimatch(pattern, options).match(p);
1163
+ };
1164
+ var cache = /* @__PURE__ */ new Map();
1165
+ var cacheMax = 256;
1166
+ var cachedMinimatch = (pattern, options) => {
1167
+ const key = pattern + "\0" + JSON.stringify(options);
1168
+ let mm = cache.get(key);
1169
+ if (mm) {
1170
+ cache.delete(key);
1171
+ } else {
1172
+ mm = new Minimatch(pattern, { ...options });
1173
+ if (cache.size >= cacheMax) {
1174
+ cache.delete(cache.keys().next().value);
1175
+ }
1176
+ }
1177
+ cache.set(key, mm);
1178
+ return mm;
1179
+ };
1180
+ var defaultPlatform = typeof process === "object" && process ? process.env?.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
1181
+ var path = {
1182
+ win32: { sep: "\\" },
1183
+ posix: { sep: "/" }
1184
+ };
1185
+ var sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
1186
+ minimatch.sep = sep;
1187
+ var GLOBSTAR = /* @__PURE__ */ Symbol("globstar **");
1188
+ minimatch.GLOBSTAR = GLOBSTAR;
1189
+ var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
1190
+ minimatch.filter = filter;
1191
+ var ext = (a, b = {}) => Object.assign({}, a, b);
1192
+ var defaults = (def) => {
1193
+ if (!def || typeof def !== "object" || !Object.keys(def).length) {
1194
+ return minimatch;
1195
+ }
1196
+ const orig = minimatch;
1197
+ const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
1198
+ return Object.assign(m, {
1199
+ Minimatch: class Minimatch extends orig.Minimatch {
1200
+ constructor(pattern, options = {}) {
1201
+ super(pattern, ext(def, options));
1202
+ }
1203
+ static defaults(options) {
1204
+ return orig.defaults(ext(def, options)).Minimatch;
1205
+ }
1206
+ },
1207
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
1208
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
1209
+ filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
1210
+ defaults: (options) => orig.defaults(ext(def, options)),
1211
+ braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
1212
+ match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
1213
+ sep: orig.sep,
1214
+ GLOBSTAR
1215
+ });
1216
+ };
1217
+ minimatch.defaults = defaults;
1218
+ var braceExpand = (pattern, options = {}) => {
1219
+ assertValidPattern(pattern);
1220
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
1221
+ return [pattern];
1222
+ }
1223
+ return expand(pattern, { max: options.braceExpandMax });
1224
+ };
1225
+ minimatch.braceExpand = braceExpand;
1226
+ var RANGE_MIN = 100;
1227
+ var rangeRe = /(?<![\\$])\{(-?\d+)\.\.(-?\d+)\}/g;
1228
+ var match = (list, pattern, options = {}) => {
1229
+ const mm = new Minimatch(pattern, options);
1230
+ list = list.filter((f) => mm.match(f));
1231
+ if (mm.options.nonull && !list.length) {
1232
+ list.push(pattern);
1233
+ }
1234
+ return list;
1235
+ };
1236
+ minimatch.match = match;
1237
+ var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
1238
+ var classEnd = (pattern, start) => {
1239
+ let i = start + 1;
1240
+ if (pattern.charAt(i) === "!" || pattern.charAt(i) === "^")
1241
+ i++;
1242
+ let sawStart = false;
1243
+ for (; i < pattern.length; i++) {
1244
+ const c = pattern.charAt(i);
1245
+ if (c === "]" && sawStart)
1246
+ return i;
1247
+ sawStart = true;
1248
+ if (c === "\\")
1249
+ i++;
1250
+ }
1251
+ return -1;
1252
+ };
1253
+ var literal = (pattern, noext) => {
1254
+ if (!noext && (pattern === "+()" || pattern === "@()"))
1255
+ return pattern;
1256
+ let lit2 = "";
1257
+ for (let i = 0; i < pattern.length; i++) {
1258
+ const c = pattern.charAt(i);
1259
+ if (c === "\\") {
1260
+ lit2 += pattern.charAt(++i) || c;
1261
+ } else if (c === "*" || c === "?") {
1262
+ return void 0;
1263
+ } else if (c === "[") {
1264
+ const close = classEnd(pattern, i);
1265
+ if (close === -1) {
1266
+ lit2 += c;
1267
+ continue;
1268
+ }
1269
+ let body = pattern.slice(i + 1, close);
1270
+ if (body.startsWith("\\"))
1271
+ body = body.slice(1);
1272
+ if ([...body].length !== 1 || "!^".includes(pattern.charAt(i + 1))) {
1273
+ return void 0;
1274
+ }
1275
+ lit2 += body;
1276
+ i = close;
1277
+ } else if (!noext && "+@!".includes(c) && pattern.charAt(i + 1) === "(" && pattern.includes(")", i + 2)) {
1278
+ return void 0;
1279
+ } else {
1280
+ lit2 += c;
1281
+ }
1282
+ }
1283
+ return lit2;
1284
+ };
1285
+ var extSafe = (pattern) => {
1286
+ if (/^[?*+@]\(\)$/.test(pattern) || pattern.includes("[:"))
1287
+ return false;
1288
+ let depth = 0;
1289
+ for (let i = 0; i < pattern.length; i++) {
1290
+ const c = pattern.charAt(i);
1291
+ if (c === "\\") {
1292
+ if (++i === pattern.length)
1293
+ return false;
1294
+ } else if (c === "[") {
1295
+ const close = classEnd(pattern, i);
1296
+ if (close !== -1)
1297
+ i = close;
1298
+ } else if ("+@!?*".includes(c) && pattern.charAt(i + 1) === "(") {
1299
+ depth++;
1300
+ i++;
1301
+ } else if (c === ")") {
1302
+ if (!depth--)
1303
+ return false;
1304
+ } else if (c === "|" && !depth) {
1305
+ return false;
1306
+ }
1307
+ }
1308
+ return !depth;
1309
+ };
1310
+ var lastSplit;
1311
+ var lastChecked;
1312
+ var portionMatch = (p, f) => typeof p === "string" ? f === p : f !== "" && p.testUnchecked(f);
1313
+ var endIndex = (p, last, lastStart, prev, prevStart) => portionMatch(p, last) ? lastStart : prev !== void 0 && portionMatch(p, prev) ? prevStart : -1;
1314
+ var isDots = (p) => p === "." || p === "..";
1315
+ var isDrive = (p) => typeof p === "string" && /^[a-z]:$/i.test(p);
1316
+ var isLongUNC = (p) => typeof p === "string" && /^unc$/i.test(p);
1317
+ var uncHost = (p) => {
1318
+ if (p[0] !== "" || p[1] !== "")
1319
+ return -1;
1320
+ const h = p[2] !== "?" ? 2 : isLongUNC(p[3]) ? 4 : -1;
1321
+ const host = p[h];
1322
+ const share = p[h + 1];
1323
+ return h !== -1 && host !== void 0 && host !== "" && host !== GLOBSTAR && share !== void 0 && share !== "" && share !== GLOBSTAR ? h : -1;
1324
+ };
1325
+ var walkable = (p, dot) => !isDots(p) && (dot || !p.startsWith("."));
1326
+ var dotPortion = (f, start, end, dot, sep2) => {
1327
+ for (let k = start; k < end; ) {
1328
+ if (f.charCodeAt(k) === 46) {
1329
+ if (!dot)
1330
+ return true;
1331
+ const n = f.charCodeAt(k + 1) === 46 ? k + 2 : k + 1;
1332
+ if (n >= end || isSep(f.charCodeAt(n), sep2))
1333
+ return true;
1334
+ }
1335
+ const s = nextSep(f, k, sep2);
1336
+ if (s === -1)
1337
+ return false;
1338
+ k = s + 1;
1339
+ while (k < end && isSep(f.charCodeAt(k), sep2))
1340
+ k++;
1341
+ }
1342
+ return false;
1343
+ };
1344
+ var isSep = (c, sep2) => sep2 === "/" ? c === 47 : sep2 === "\\" ? c === 92 : c === 47 || c === 92;
1345
+ var nextSep = (f, from, sep2) => {
1346
+ if (sep2 !== "both")
1347
+ return f.indexOf(sep2, from);
1348
+ const s = f.indexOf("/", from);
1349
+ const b = f.indexOf("\\", from);
1350
+ return s === -1 ? b : b === -1 ? s : Math.min(s, b);
1351
+ };
1352
+ var lastSep = (f, from, sep2) => sep2 !== "both" ? f.lastIndexOf(sep2, from) : Math.max(f.lastIndexOf("/", from), f.lastIndexOf("\\", from));
1353
+ var PENDING = {};
1354
+ var Minimatch = class {
1355
+ options;
1356
+ set;
1357
+ pattern;
1358
+ windowsPathsNoEscape;
1359
+ nonegate;
1360
+ negate;
1361
+ comment;
1362
+ empty;
1363
+ preserveMultipleSlashes;
1364
+ partial;
1365
+ globSet;
1366
+ globParts;
1367
+ nocase;
1368
+ isWindows;
1369
+ platform;
1370
+ windowsNoMagicRoot;
1371
+ maxGlobstarRecursion;
1372
+ // the path can be checked against the last portion, and the string
1373
+ // portions, of each row before it is split. See #canMatch.
1374
+ #endCheck;
1375
+ #literalCheck;
1376
+ // level 2 resolves `.` and `..` portions in the path
1377
+ #level2;
1378
+ // the unicode normalization form, if any
1379
+ #form;
1380
+ // the string portions of each row in the set
1381
+ #literals = [];
1382
+ // the rows that #canMatch can match without splitting the path
1383
+ #shapes = [];
1384
+ // the rows whose last portion can be checked against the path's
1385
+ #endRows = [];
1386
+ // brace expansion can make the same portion in many rows, so they
1387
+ // share one Matcher, and the states that it caches
1388
+ #matchers = /* @__PURE__ */ new Map();
1389
+ // parse() returns PENDING in place of a Matcher
1390
+ #pending = false;
1391
+ // the char that marks numeric ranges in globSet, if any
1392
+ #rangeMark;
1393
+ // the GlobstarParts of each pattern row, by start index and partial
1394
+ #globstarParts = /* @__PURE__ */ new WeakMap();
1395
+ constructor(pattern, options = {}) {
1396
+ assertValidPattern(pattern);
1397
+ options = options || {};
1398
+ this.options = options;
1399
+ this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? 200;
1400
+ this.pattern = pattern;
1401
+ this.platform = options.platform || defaultPlatform;
1402
+ this.isWindows = this.platform === "win32";
1403
+ const awe = "allowWindowsEscape";
1404
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false;
1405
+ if (this.windowsPathsNoEscape) {
1406
+ this.pattern = this.pattern.replace(/\\/g, "/");
1407
+ }
1408
+ this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
1409
+ this.negate = false;
1410
+ this.nonegate = !!options.nonegate;
1411
+ this.comment = false;
1412
+ this.empty = false;
1413
+ this.partial = !!options.partial;
1414
+ this.nocase = !!this.options.nocase;
1415
+ this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
1416
+ this.globSet = [];
1417
+ this.globParts = [];
1418
+ this.set = [];
1419
+ this.#endCheck = !this.preserveMultipleSlashes;
1420
+ this.#level2 = (options.optimizationLevel ?? 1) >= 2;
1421
+ const n = options.normalize;
1422
+ this.#form = n === true ? "NFC" : n || void 0;
1423
+ this.make();
1424
+ const drives = this.set.map((row) => this.#rootIndex(row));
1425
+ this.#endRows = this.set.map((row, r) => this.#endCheck && row.length - 1 > drives[r]);
1426
+ this.#literals = this.set.map((row, r) => {
1427
+ const end = this.#endRows[r] ? row.length - 1 : row.length;
1428
+ const lits = row.slice(drives[r] + 1, end).filter((p) => typeof p === "string" && !!p);
1429
+ return [...new Set(lits)];
1430
+ });
1431
+ this.#literalCheck = this.#literals.some((l) => l.length);
1432
+ this.#shapes = this.set.map((row, r) => {
1433
+ const [p0, p1, p2] = row;
1434
+ if (this.#endRows[r] && row.length === 2) {
1435
+ if (p0 === GLOBSTAR && p1 !== GLOBSTAR)
1436
+ return "tail";
1437
+ }
1438
+ if (this.#endRows[r] && options.matchBase && row.length === 1 && p0 !== GLOBSTAR && p0 !== "") {
1439
+ return "base";
1440
+ }
1441
+ if (!this.#endCheck || drives[r] !== -1)
1442
+ return void 0;
1443
+ if (row.length === 3 && p0 === GLOBSTAR && p2 === GLOBSTAR && p1 !== GLOBSTAR && p1 !== "" && // the portion between is only matched below this limit
1444
+ this.maxGlobstarRecursion > 0) {
1445
+ return "mid";
1446
+ }
1447
+ if (row.length === 2 && p1 === GLOBSTAR && p0 !== GLOBSTAR && p0 !== "") {
1448
+ return "head";
1449
+ }
1450
+ return void 0;
1451
+ });
1452
+ }
1453
+ // a string portion of a pattern, normalized if the option is set
1454
+ #norm(p) {
1455
+ return this.#form ? p.normalize(this.#form) : p;
1456
+ }
1457
+ // On Windows, the index of the last root portion of a row, as
1458
+ // #matchRow finds it: 0 for `c:/...`, 3 for `//?/c:/...` and
1459
+ // `//host/share/...`, and 5 for `//?/UNC/host/share/...`. Otherwise
1460
+ // -1.
1461
+ #rootIndex(row) {
1462
+ if (!this.isWindows)
1463
+ return -1;
1464
+ if (isDrive(row[0]))
1465
+ return 0;
1466
+ const uncDrive = row[0] === "" && row[1] === "" && row[2] === "?" && isDrive(row[3]);
1467
+ if (uncDrive)
1468
+ return 3;
1469
+ const h = uncHost(row);
1470
+ return h === -1 ? -1 : h + 1;
1471
+ }
1472
+ hasMagic() {
1473
+ if (this.options.magicalBraces && this.set.length > 1) {
1474
+ return true;
1475
+ }
1476
+ for (const pattern of this.set) {
1477
+ for (const part of pattern) {
1478
+ if (typeof part !== "string")
1479
+ return true;
1480
+ }
1481
+ }
1482
+ return false;
1483
+ }
1484
+ make() {
1485
+ const pattern = this.pattern;
1486
+ const options = this.options;
1487
+ if (!options.nocomment && pattern.charAt(0) === "#") {
1488
+ this.comment = true;
1489
+ return;
1490
+ }
1491
+ if (!pattern) {
1492
+ this.empty = true;
1493
+ return;
1494
+ }
1495
+ this.parseNegate();
1496
+ this.globSet = [...new Set(this.#expandBraces())];
1497
+ const rawGlobParts = this.globSet.map((s) => this.#slashSplit(s));
1498
+ this.globParts = this.preprocess(rawGlobParts);
1499
+ this.#pending = true;
1500
+ let set = this.globParts.map((s, _, __) => {
1501
+ if (this.isWindows && this.windowsNoMagicRoot) {
1502
+ const n = s[2] === "?" && isLongUNC(s[3]) ? 6 : 4;
1503
+ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && s.slice(3, n).every((p) => !globMagic.test(p));
1504
+ const isDrive2 = /^[a-z]:/i.test(s[0]);
1505
+ if (isUNC) {
1506
+ return [
1507
+ ...s.slice(0, n).map((p) => this.#norm(p)),
1508
+ ...s.slice(n).map((ss) => this.parse(ss))
1509
+ ];
1510
+ } else if (isDrive2) {
1511
+ return [
1512
+ this.#norm(s[0]),
1513
+ ...s.slice(1).map((ss) => this.parse(ss))
1514
+ ];
1515
+ }
1516
+ }
1517
+ return s.map((ss) => this.parse(ss));
1518
+ });
1519
+ this.set = set.filter((s) => s.indexOf(false) === -1);
1520
+ if (this.isWindows) {
1521
+ for (let i = 0; i < this.set.length; i++) {
1522
+ const p = this.set[i];
1523
+ if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && (isDrive(p[3]) || isLongUNC(this.globParts[i][3]))) {
1524
+ if (isLongUNC(this.globParts[i][3]))
1525
+ p[3] = "UNC";
1526
+ p[2] = "?";
1527
+ }
1528
+ }
1529
+ }
1530
+ if (!options.noext)
1531
+ this.mergeRows();
1532
+ this.#pending = false;
1533
+ this.set.forEach((row, i) => {
1534
+ for (let k = 0; k < row.length; k++) {
1535
+ if (row[k] === PENDING) {
1536
+ row[k] = this.parse(this.globParts[i][k]);
1537
+ }
1538
+ }
1539
+ });
1540
+ }
1541
+ // Merge rows that only differ in one portion, where each of them
1542
+ // is a Matcher, into one row that matches any of them with
1543
+ // `@(a|b|...)`. Then a path is only walked once for all of them,
1544
+ // for example with `**/*.{js,ts}`.
1545
+ mergeRows() {
1546
+ let merged = true;
1547
+ while (merged) {
1548
+ merged = false;
1549
+ const len = Math.max(0, ...this.set.map((r) => r.length));
1550
+ for (let k = 0; k < len; k++) {
1551
+ const groups = /* @__PURE__ */ new Map();
1552
+ this.set.forEach((row, i) => {
1553
+ if (!(row[k] instanceof Matcher || row[k] === PENDING) || !extSafe(this.globParts[i][k])) {
1554
+ return;
1555
+ }
1556
+ const parts = [...this.globParts[i]];
1557
+ parts[k] = "";
1558
+ const key = `${row.length}/${parts.join("/")}`;
1559
+ const g = groups.get(key);
1560
+ if (g)
1561
+ g.push(i);
1562
+ else
1563
+ groups.set(key, [i]);
1564
+ });
1565
+ const drop = /* @__PURE__ */ new Set();
1566
+ for (const g of groups.values()) {
1567
+ if (g.length < 2)
1568
+ continue;
1569
+ const [first, ...rest] = g;
1570
+ const alts = g.map((i) => this.globParts[i][k]);
1571
+ const glob = `@(${alts.join("|")})`;
1572
+ this.globParts[first][k] = glob;
1573
+ this.set[first][k] = this.parse(glob);
1574
+ for (const i of rest)
1575
+ drop.add(i);
1576
+ }
1577
+ if (drop.size) {
1578
+ merged = true;
1579
+ this.set = this.set.filter((_, i) => !drop.has(i));
1580
+ this.globParts = this.globParts.filter((_, i) => !drop.has(i));
1581
+ }
1582
+ }
1583
+ }
1584
+ }
1585
+ // various transforms to equivalent pattern sets that are
1586
+ // faster to process in a filesystem walk. The goal is to
1587
+ // eliminate what we can, and push all ** patterns as far
1588
+ // to the right as possible, even if it increases the number
1589
+ // of patterns that we have to process.
1590
+ preprocess(globParts) {
1591
+ if (this.options.noglobstar) {
1592
+ for (const partset of globParts) {
1593
+ for (let j = 0; j < partset.length; j++) {
1594
+ if (partset[j] === "**") {
1595
+ partset[j] = "*";
1596
+ }
1597
+ }
1598
+ }
1599
+ }
1600
+ const { optimizationLevel = 1 } = this.options;
1601
+ if (optimizationLevel >= 2) {
1602
+ globParts = this.firstPhasePreProcess(globParts);
1603
+ globParts = this.secondPhasePreProcess(globParts);
1604
+ } else if (optimizationLevel >= 1) {
1605
+ globParts = this.levelOneOptimize(globParts);
1606
+ } else {
1607
+ globParts = this.adjascentGlobstarOptimize(globParts);
1608
+ }
1609
+ return globParts;
1610
+ }
1611
+ // just get rid of adjascent ** portions
1612
+ adjascentGlobstarOptimize(globParts) {
1613
+ return globParts.map((parts) => {
1614
+ let gs = -1;
1615
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
1616
+ let i = gs;
1617
+ while (parts[i + 1] === "**") {
1618
+ i++;
1619
+ }
1620
+ if (i !== gs) {
1621
+ parts.splice(gs, i - gs);
1622
+ }
1623
+ }
1624
+ return parts;
1625
+ });
1626
+ }
1627
+ // get rid of adjascent ** and resolve .. portions
1628
+ levelOneOptimize(globParts) {
1629
+ return globParts.map((parts) => {
1630
+ const root = this.#rootIndex(parts) + 1;
1631
+ parts = parts.reduce((set, part) => {
1632
+ const prev = set[set.length - 1];
1633
+ if (part === "**" && prev === "**") {
1634
+ return set;
1635
+ }
1636
+ if (part === "..") {
1637
+ if (set.length > root && prev && prev !== ".." && prev !== "." && prev !== "**") {
1638
+ set.pop();
1639
+ return set;
1640
+ }
1641
+ }
1642
+ set.push(part);
1643
+ return set;
1644
+ }, []);
1645
+ return parts.length === 0 ? [""] : parts;
1646
+ });
1647
+ }
1648
+ // Check the path against each row before it is split. 'no' if no
1649
+ // row can match, so it does not need to be split. 'yes' if a row of
1650
+ // `**` and one more portion matches. 'maybe' if it must be split to
1651
+ // know. None of this applies with partial, where the path can end
1652
+ // before the row does.
1653
+ //
1654
+ // On Windows, `\` is a separator in the path too, and the portions of
1655
+ // a row up to its drive letter or UNC share are not checked (see
1656
+ // #rootIndex).
1657
+ //
1658
+ // Each string portion of a row must be a portion of the path, so the
1659
+ // path must contain it. Level 2 can only take portions out of the
1660
+ // path, so this is still true then.
1661
+ //
1662
+ // The last portion of a row must match the last portion of the path,
1663
+ // or the one before a trailing `/` (as a/* and a/**/* match a/b/).
1664
+ // This does not apply to rows that end in **, rows that end in a
1665
+ // root, or preserveMultipleSlashes (which can leave more
1666
+ // than one '' at the end). At level 2, it does not apply if that
1667
+ // portion is `.` or `..`, which can be
1668
+ // resolved away. Level 2 only takes other portions out of the
1669
+ // middle of the path.
1670
+ //
1671
+ // A row of `**/x` then matches if the ** can walk the portions
1672
+ // before the one that x matches, the same as #matchGlobstar. At
1673
+ // level 2, this is only known if none of them are `.` or `..`, so
1674
+ // that the path does not change when it is resolved.
1675
+ #canMatch(f) {
1676
+ const sep2 = !this.isWindows || !f.includes("\\") ? "/" : f.includes("/") ? "both" : "\\";
1677
+ let ends = this.#endCheck ? 0 : -1;
1678
+ let last = "";
1679
+ let lastStart = 0;
1680
+ let prev;
1681
+ let prevStart = 0;
1682
+ const dot = !!this.options.dot;
1683
+ ROWS: for (let r = 0; r < this.set.length; r++) {
1684
+ const row = this.set[r];
1685
+ const p = row[row.length - 1];
1686
+ let end = ends !== -1 && this.#endRows[r] && p !== GLOBSTAR;
1687
+ if (end && ends === 0) {
1688
+ const i = lastSep(f, f.length, sep2);
1689
+ lastStart = i + 1;
1690
+ last = f.slice(lastStart);
1691
+ if (last === "" && i >= 0) {
1692
+ let j = i;
1693
+ while (j > 0 && isSep(f.charCodeAt(j - 1), sep2))
1694
+ j--;
1695
+ prevStart = j === 0 ? 0 : lastSep(f, j - 1, sep2) + 1;
1696
+ prev = f.slice(prevStart, j);
1697
+ }
1698
+ const resolves = this.#level2 && (isDots(last) || last === "" && prev !== void 0 && isDots(prev));
1699
+ ends = resolves ? -1 : 1;
1700
+ end = !resolves;
1701
+ }
1702
+ let tailStart = -1;
1703
+ if (end && typeof p === "string") {
1704
+ tailStart = endIndex(p, last, lastStart, prev, prevStart);
1705
+ if (tailStart === -1)
1706
+ continue;
1707
+ }
1708
+ if (this.#literalCheck) {
1709
+ for (const l of this.#literals[r]) {
1710
+ if (!f.includes(l))
1711
+ continue ROWS;
1712
+ }
1713
+ }
1714
+ if (end && typeof p === "object") {
1715
+ tailStart = endIndex(p, last, lastStart, prev, prevStart);
1716
+ if (tailStart === -1)
1717
+ continue;
1718
+ }
1719
+ const shape = this.#shapes[r];
1720
+ if (shape === "base" && end)
1721
+ return "yes";
1722
+ if (shape === "tail" && end) {
1723
+ if (this.#level2 && dotPortion(f, 0, tailStart, true, sep2)) {
1724
+ return "maybe";
1725
+ }
1726
+ if (!dotPortion(f, 0, tailStart, dot, sep2))
1727
+ return "yes";
1728
+ continue;
1729
+ }
1730
+ if (shape === "mid" || shape === "head") {
1731
+ const m = this.#walk(f, row, shape === "head", dot, sep2);
1732
+ if (m !== "no")
1733
+ return m;
1734
+ continue;
1735
+ }
1736
+ return "maybe";
1737
+ }
1738
+ return "no";
1739
+ }
1740
+ // Match a row of a known shape against the split path, the same as
1741
+ // #matchGlobstar and #matchGlobStarBodySections do. None of these
1742
+ // rows have a drive letter, so they start at the first portion.
1743
+ #matchShape(file, row, shape) {
1744
+ const dot = !!this.options.dot;
1745
+ const n = file.length;
1746
+ if (shape === "head") {
1747
+ if (n < 2 || !portionMatch(row[0], file[0])) {
1748
+ return false;
1749
+ }
1750
+ for (let i = 1; i < n; i++)
1751
+ if (!walkable(file[i], dot))
1752
+ return false;
1753
+ return true;
1754
+ }
1755
+ const x = row[1];
1756
+ if (shape === "tail") {
1757
+ let t = n - 1;
1758
+ if (!portionMatch(x, file[t])) {
1759
+ if (file[t] !== "" || n === 1 || !portionMatch(x, file[--t])) {
1760
+ return false;
1761
+ }
1762
+ }
1763
+ for (let i = 0; i < t; i++)
1764
+ if (!walkable(file[i], dot))
1765
+ return false;
1766
+ return true;
1767
+ }
1768
+ for (let k = 0; k < n; k++) {
1769
+ if (portionMatch(x, file[k]) && k + 1 < n) {
1770
+ let i = k + 1;
1771
+ while (i < n && walkable(file[i], dot))
1772
+ i++;
1773
+ if (i === n)
1774
+ return true;
1775
+ }
1776
+ if (!walkable(file[k], dot))
1777
+ return false;
1778
+ }
1779
+ return false;
1780
+ }
1781
+ // Match a row of `**/x/**` or `x/**` against the path, the same as
1782
+ // #matchGlobstar and #matchGlobStarBodySections do once it is split.
1783
+ // x must match a portion (the first one, for `x/**`), the ** before
1784
+ // it must be able to walk the portions before that one, and there
1785
+ // must be a portion after it, which the ** after it can walk. At
1786
+ // level 2, this is only known if no portion is `.` or `..`.
1787
+ #walk(f, row, head, dot, sep2) {
1788
+ if (this.#level2 && dotPortion(f, 0, f.length, true, sep2))
1789
+ return "maybe";
1790
+ const x = row[head ? 0 : 1];
1791
+ let s = 0;
1792
+ for (let e = nextSep(f, s, sep2); e !== -1; e = nextSep(f, s, sep2)) {
1793
+ let next = e + 1;
1794
+ while (next < f.length && isSep(f.charCodeAt(next), sep2))
1795
+ next++;
1796
+ const hit = typeof x === "string" ? e - s === x.length && f.startsWith(x, s) : e > s && x.testUnchecked(f.slice(s, e));
1797
+ if (hit && !dotPortion(f, next, f.length, dot, sep2))
1798
+ return "yes";
1799
+ if (head || dotPortion(f, s, next, dot, sep2))
1800
+ return "no";
1801
+ s = next;
1802
+ }
1803
+ return "no";
1804
+ }
1805
+ // the last split, if it was the same path with the same split
1806
+ // settings
1807
+ #cachedSplit(f) {
1808
+ const last = lastSplit;
1809
+ return last?.f === f && last.isWindows === this.isWindows && last.preserveMultipleSlashes === this.preserveMultipleSlashes && last.normalize === this.#form ? last : void 0;
1810
+ }
1811
+ // split a path for match(), and keep the parts for the next call
1812
+ #split(f) {
1813
+ const { isWindows, preserveMultipleSlashes } = this;
1814
+ let parts = this.#slashSplit(isWindows ? f.split("\\").join("/") : f);
1815
+ const normalize2 = this.#form;
1816
+ if (normalize2)
1817
+ parts = parts.map((p) => p.normalize(normalize2));
1818
+ lastSplit = {
1819
+ f,
1820
+ isWindows,
1821
+ preserveMultipleSlashes,
1822
+ normalize: normalize2,
1823
+ parts
1824
+ };
1825
+ return lastSplit;
1826
+ }
1827
+ // resolve `.` and `..` portions of a path, for level 2
1828
+ #levelTwoFileOptimize(file) {
1829
+ const parts = [...file];
1830
+ let didSomething = false;
1831
+ do {
1832
+ didSomething = false;
1833
+ if (!this.preserveMultipleSlashes) {
1834
+ for (let i = 1; i < parts.length - 1; i++) {
1835
+ const p = parts[i];
1836
+ if (i === 1 && p === "" && parts[0] === "")
1837
+ continue;
1838
+ if (p === "." || p === "") {
1839
+ didSomething = true;
1840
+ parts.splice(i, 1);
1841
+ i--;
1842
+ }
1843
+ }
1844
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
1845
+ didSomething = true;
1846
+ parts.pop();
1847
+ }
1848
+ }
1849
+ const root = this.#rootIndex(parts) + 1;
1850
+ let dd = root;
1851
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
1852
+ const p = parts[dd - 1];
1853
+ if (p && p !== "." && p !== ".." && p !== "**") {
1854
+ didSomething = true;
1855
+ parts.splice(dd - 1, 2);
1856
+ dd = Math.max(dd - 2, root);
1857
+ }
1858
+ }
1859
+ } while (didSomething);
1860
+ return parts.length === 0 ? [""] : parts;
1861
+ }
1862
+ // First phase: single-pattern processing
1863
+ // <pre> is 1 or more portions
1864
+ // <rest> is 1 or more portions
1865
+ // <p> is any portion other than ., .., '', or **
1866
+ // <e> is . or ''
1867
+ //
1868
+ // **/.. is *brutal* for filesystem walking performance, because
1869
+ // it effectively resets the recursive walk each time it occurs,
1870
+ // and ** cannot be reduced out by a .. pattern part like a regexp
1871
+ // or most strings (other than .., ., and '') can be.
1872
+ //
1873
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
1874
+ // <pre>/<e>/<rest> -> <pre>/<rest>
1875
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
1876
+ // **/**/<rest> -> **/<rest>
1877
+ //
1878
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
1879
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
1880
+ firstPhasePreProcess(globParts) {
1881
+ const { braceExpandMax = 1e5 } = this.options;
1882
+ let splitCells = 0;
1883
+ const maxSplitCells = 1e6;
1884
+ let didSomething = false;
1885
+ do {
1886
+ didSomething = false;
1887
+ for (let parts of globParts) {
1888
+ let gs = -1;
1889
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
1890
+ let gss = gs;
1891
+ while (parts[gss + 1] === "**") {
1892
+ gss++;
1893
+ }
1894
+ if (gss > gs) {
1895
+ parts.splice(gs + 1, gss - gs);
1896
+ }
1897
+ let next = parts[gs + 1];
1898
+ const p = parts[gs + 2];
1899
+ const p2 = parts[gs + 3];
1900
+ if (next !== "..")
1901
+ continue;
1902
+ if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
1903
+ continue;
1904
+ }
1905
+ const addedCells = parts.length - 1;
1906
+ if (globParts.length >= braceExpandMax || splitCells + addedCells > maxSplitCells) {
1907
+ throw new RangeError(`optimizationLevel 2: too many patterns from '**/..'`);
1908
+ }
1909
+ didSomething = true;
1910
+ parts.splice(gs, 1);
1911
+ const other = parts.slice(0);
1912
+ other[gs] = "**";
1913
+ splitCells += addedCells;
1914
+ globParts.push(other);
1915
+ gs--;
1916
+ }
1917
+ if (!this.preserveMultipleSlashes) {
1918
+ for (let i = 1; i < parts.length - 1; i++) {
1919
+ const p = parts[i];
1920
+ if (i === 1 && p === "" && parts[0] === "")
1921
+ continue;
1922
+ if (p === "." || p === "") {
1923
+ didSomething = true;
1924
+ parts.splice(i, 1);
1925
+ i--;
1926
+ }
1927
+ }
1928
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
1929
+ didSomething = true;
1930
+ parts.pop();
1931
+ }
1932
+ }
1933
+ const root = this.#rootIndex(parts) + 1;
1934
+ let dd = root;
1935
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
1936
+ const p = parts[dd - 1];
1937
+ if (p && p !== "." && p !== ".." && p !== "**") {
1938
+ didSomething = true;
1939
+ const needDot = dd === 1 && parts[dd + 1] === "**";
1940
+ const splin = needDot ? ["."] : [];
1941
+ parts.splice(dd - 1, 2, ...splin);
1942
+ if (parts.length === 0)
1943
+ parts.push("");
1944
+ dd = Math.max(dd - 2, root);
1945
+ }
1946
+ }
1947
+ }
1948
+ } while (didSomething);
1949
+ return globParts;
1950
+ }
1951
+ // second phase: multi-pattern dedupes
1952
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
1953
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
1954
+ secondPhasePreProcess(globParts) {
1955
+ const keys = /* @__PURE__ */ new Set();
1956
+ const rows = globParts.filter((parts) => {
1957
+ const key = parts.join("/");
1958
+ if (keys.has(key))
1959
+ return false;
1960
+ keys.add(key);
1961
+ return true;
1962
+ });
1963
+ const stars = /* @__PURE__ */ new Map();
1964
+ for (const parts of rows) {
1965
+ const s = [];
1966
+ for (let i = 0; i < parts.length; i++) {
1967
+ if (parts[i] === "*")
1968
+ s.push(i);
1969
+ }
1970
+ if (s.length)
1971
+ stars.set(s.join(","), s);
1972
+ }
1973
+ if (!stars.size || rows.length * stars.size > 1e5)
1974
+ return rows;
1975
+ const { dot } = this.options;
1976
+ return rows.filter((parts) => {
1977
+ for (const s of stars.values()) {
1978
+ if (s[s.length - 1] >= parts.length)
1979
+ continue;
1980
+ const c = [...parts];
1981
+ let ok = true;
1982
+ let changed = false;
1983
+ for (const i of s) {
1984
+ const p = parts[i];
1985
+ if (p === "*")
1986
+ continue;
1987
+ if (!p || p === "**" || !dot && p.startsWith(".")) {
1988
+ ok = false;
1989
+ break;
1990
+ }
1991
+ c[i] = "*";
1992
+ changed = true;
1993
+ }
1994
+ if (ok && changed && keys.has(c.join("/")))
1995
+ return false;
1996
+ }
1997
+ return true;
1998
+ });
1999
+ }
2000
+ parseNegate() {
2001
+ if (this.nonegate)
2002
+ return;
2003
+ const pattern = this.pattern;
2004
+ let negate = false;
2005
+ let negateOffset = 0;
2006
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
2007
+ negate = !negate;
2008
+ negateOffset++;
2009
+ }
2010
+ if (negateOffset)
2011
+ this.pattern = pattern.slice(negateOffset);
2012
+ this.negate = negate;
2013
+ }
2014
+ // Match the parts of a path against one row of the set. `resolved`
2015
+ // is the parts after level 2 resolves `.` and `..` in them, or the
2016
+ // same parts below level 2. Set partial to true to test if, for
2017
+ // example, "/a/b" matches the start of "/*/b/*/d". Partial means, if
2018
+ // you run out of file before you run out of pattern, then that's
2019
+ // fine, as long as all the parts match.
2020
+ #matchRow(file, resolved, pattern, partial) {
2021
+ let fileStartIndex = 0;
2022
+ let patternStartIndex = 0;
2023
+ const fh = this.isWindows ? uncHost(resolved) : -1;
2024
+ const ph = fh === -1 ? -1 : uncHost(pattern);
2025
+ if (ph !== -1) {
2026
+ const host = pattern[ph];
2027
+ const share = pattern[ph + 1];
2028
+ if (typeof host !== "string" || typeof share !== "string") {
2029
+ fileStartIndex = fh;
2030
+ patternStartIndex = ph;
2031
+ } else if (resolved[fh].toLowerCase() === host.toLowerCase() && resolved[fh + 1].toLowerCase() === share.toLowerCase()) {
2032
+ fileStartIndex = fh + 2;
2033
+ patternStartIndex = ph + 2;
2034
+ }
2035
+ } else if (this.isWindows) {
2036
+ const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
2037
+ const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
2038
+ const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
2039
+ const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
2040
+ const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
2041
+ const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
2042
+ if (typeof fdi === "number" && typeof pdi === "number") {
2043
+ const [fd, pd] = [
2044
+ file[fdi],
2045
+ pattern[pdi]
2046
+ ];
2047
+ if (fd.toLowerCase() === pd.toLowerCase()) {
2048
+ patternStartIndex = pdi + 1;
2049
+ fileStartIndex = fdi + 1;
2050
+ }
2051
+ }
2052
+ }
2053
+ file = resolved;
2054
+ if (pattern.includes(GLOBSTAR)) {
2055
+ return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
2056
+ }
2057
+ return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
2058
+ }
2059
+ #matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
2060
+ const { head, body, tail, segments } = this.#getGlobstarParts(pattern, partial, patternIndex);
2061
+ if (head.length) {
2062
+ const headEnd = fileIndex + head.length;
2063
+ if (!this.#matchOne(file, head, partial, fileIndex, 0, headEnd)) {
2064
+ return false;
2065
+ }
2066
+ fileIndex += head.length;
2067
+ patternIndex += head.length;
2068
+ }
2069
+ let fileTailMatch = 0;
2070
+ if (tail.length) {
2071
+ if (tail.length + fileIndex > file.length)
2072
+ return false;
2073
+ let tailStart = file.length - tail.length;
2074
+ if (this.#matchOne(file, tail, partial, tailStart, 0)) {
2075
+ fileTailMatch = tail.length;
2076
+ } else {
2077
+ if (file[file.length - 1] !== "" || fileIndex + tail.length === file.length) {
2078
+ return false;
2079
+ }
2080
+ tailStart--;
2081
+ if (!this.#matchOne(file, tail, partial, tailStart, 0)) {
2082
+ return false;
2083
+ }
2084
+ fileTailMatch = tail.length + 1;
2085
+ }
2086
+ }
2087
+ if (!body.length) {
2088
+ let sawSome = !!fileTailMatch;
2089
+ for (let i = fileIndex; i < file.length - fileTailMatch; i++) {
2090
+ const f = String(file[i]);
2091
+ sawSome = true;
2092
+ if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
2093
+ return false;
2094
+ }
2095
+ }
2096
+ return partial || sawSome;
2097
+ }
2098
+ return !!this.#matchGlobStarBodySections(file, segments, file.length - fileTailMatch, fileIndex, 0, partial, 0, !!fileTailMatch, /* @__PURE__ */ new Set());
2099
+ }
2100
+ // Split the pattern into head, tail, and middle of ** delimited
2101
+ // parts. The tail has to be at the end, and the others just have to
2102
+ // be found in order from the head. These only depend on the pattern
2103
+ // row, so they are kept for the next path.
2104
+ #getGlobstarParts(pattern, partial, patternIndex) {
2105
+ let byStart = this.#globstarParts.get(pattern);
2106
+ if (!byStart) {
2107
+ byStart = [];
2108
+ this.#globstarParts.set(pattern, byStart);
2109
+ }
2110
+ const key = patternIndex * 2 + (partial ? 1 : 0);
2111
+ const found = byStart[key];
2112
+ if (found)
2113
+ return found;
2114
+ const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
2115
+ const lastgs = pattern.lastIndexOf(GLOBSTAR);
2116
+ const head = pattern.slice(patternIndex, firstgs);
2117
+ const body = pattern.slice(firstgs + 1, partial ? void 0 : lastgs);
2118
+ const tail = partial ? [] : pattern.slice(lastgs + 1);
2119
+ const segments = [[[], 0]];
2120
+ let current = segments[0];
2121
+ let nonGsParts = 0;
2122
+ const nonGsPartsSums = [0];
2123
+ for (const b of body) {
2124
+ if (b === GLOBSTAR) {
2125
+ nonGsPartsSums.push(nonGsParts);
2126
+ current = [[], 0];
2127
+ segments.push(current);
2128
+ } else {
2129
+ current[0].push(b);
2130
+ nonGsParts++;
2131
+ }
2132
+ }
2133
+ segments.forEach((b, i) => {
2134
+ b[1] = nonGsParts - nonGsPartsSums[i];
2135
+ });
2136
+ const parts = { head, body, tail, segments };
2137
+ byStart[key] = parts;
2138
+ return parts;
2139
+ }
2140
+ // return false for "nope, not matching"
2141
+ // return null for "not matching, cannot keep trying"
2142
+ #matchGlobStarBodySections(file, bodySegments, fileLength, fileIndex, bodyIndex, partial, globStarDepth, sawTail, tried) {
2143
+ const bs = bodySegments[bodyIndex];
2144
+ if (!bs) {
2145
+ if (partial) {
2146
+ return fileIndex >= fileLength || fileIndex === fileLength - 1 && file[fileIndex] === "";
2147
+ }
2148
+ for (let i = fileIndex; i < fileLength; i++) {
2149
+ sawTail = true;
2150
+ const f = file[i];
2151
+ if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
2152
+ return false;
2153
+ }
2154
+ }
2155
+ return sawTail;
2156
+ }
2157
+ const [body, need] = bs;
2158
+ const after = partial ? fileLength : fileLength - need;
2159
+ while (fileIndex <= after) {
2160
+ const key = bodyIndex * (file.length + 1) + fileIndex;
2161
+ if (tried.has(key))
2162
+ return false;
2163
+ tried.add(key);
2164
+ const m = this.#matchOne(file, body, partial, fileIndex, 0, fileIndex + body.length);
2165
+ if (m && globStarDepth < this.maxGlobstarRecursion) {
2166
+ const sub = this.#matchGlobStarBodySections(file, bodySegments, fileLength, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail, tried);
2167
+ if (sub !== false) {
2168
+ return sub;
2169
+ }
2170
+ }
2171
+ if (fileIndex === after)
2172
+ break;
2173
+ const f = file[fileIndex];
2174
+ if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
2175
+ return false;
2176
+ }
2177
+ fileIndex++;
2178
+ }
2179
+ return partial || null;
2180
+ }
2181
+ #matchOne(file, pattern, partial, fileIndex, patternIndex, fileEnd = file.length) {
2182
+ let fi;
2183
+ let pi;
2184
+ let pl;
2185
+ let fl;
2186
+ for (fi = fileIndex, pi = patternIndex, fl = Math.min(fileEnd, file.length), pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
2187
+ let p = pattern[pi];
2188
+ let f = file[fi];
2189
+ if (p === false || p === GLOBSTAR) {
2190
+ return false;
2191
+ }
2192
+ if (!portionMatch(p, f))
2193
+ return false;
2194
+ }
2195
+ if (fi === fl && pi === pl) {
2196
+ return true;
2197
+ } else if (fi === fl) {
2198
+ return partial;
2199
+ } else if (pi === pl) {
2200
+ return fi === fl - 1 && file[fi] === "";
2201
+ } else {
2202
+ throw new Error("wtf?");
2203
+ }
2204
+ }
2205
+ braceExpand() {
2206
+ return braceExpand(this.pattern, this.options);
2207
+ }
2208
+ // Expand braces, except numeric ranges such as {0..999} with at
2209
+ // least RANGE_MIN values. Each of those stays in its pattern as
2210
+ // `<mark>0..999<mark>`, for the Matcher to test. If a range might
2211
+ // be inside a [...] class, expand all of them instead.
2212
+ #expandBraces() {
2213
+ const { pattern } = this;
2214
+ if (this.options.nobrace)
2215
+ return this.braceExpand();
2216
+ let code = 57344;
2217
+ while (pattern.includes(String.fromCharCode(code))) {
2218
+ if (++code > 63743)
2219
+ return this.braceExpand();
2220
+ }
2221
+ const mark = String.fromCharCode(code);
2222
+ let found = false;
2223
+ const marked = pattern.replace(rangeRe, (m, lo, hi) => {
2224
+ const a = Number(lo);
2225
+ const b = Number(hi);
2226
+ if (!Number.isSafeInteger(a) || !Number.isSafeInteger(b) || Math.abs(a - b) + 1 < RANGE_MIN) {
2227
+ return m;
2228
+ }
2229
+ found = true;
2230
+ return `${mark}${lo}..${hi}${mark}`;
2231
+ });
2232
+ if (!found)
2233
+ return this.braceExpand();
2234
+ const set = braceExpand(marked, this.options);
2235
+ for (const p of set) {
2236
+ for (const portion of p.split("/")) {
2237
+ const c = portion.indexOf("[");
2238
+ if (c !== -1 && c < portion.lastIndexOf(mark)) {
2239
+ return this.braceExpand();
2240
+ }
2241
+ }
2242
+ }
2243
+ this.#rangeMark = mark;
2244
+ return set;
2245
+ }
2246
+ parse(pattern) {
2247
+ assertValidPattern(pattern);
2248
+ const options = this.options;
2249
+ if (pattern === "**")
2250
+ return GLOBSTAR;
2251
+ if (pattern === "")
2252
+ return "";
2253
+ const { nocase, nocaseMagicOnly, noext = false, dot, normalize: normalize2 } = options;
2254
+ const rangeMark = this.#rangeMark;
2255
+ const lit2 = rangeMark && pattern.includes(rangeMark) ? void 0 : literal(pattern, noext);
2256
+ if (lit2 !== void 0 && !(nocase && !nocaseMagicOnly && pattern.toUpperCase() !== pattern.toLowerCase())) {
2257
+ return this.#norm(lit2);
2258
+ }
2259
+ if (this.#pending)
2260
+ return PENDING;
2261
+ let m = this.#matchers.get(pattern);
2262
+ if (!m) {
2263
+ m = new Matcher(pattern, {
2264
+ nocase,
2265
+ noext,
2266
+ dot,
2267
+ normalize: normalize2,
2268
+ ...rangeMark && { rangeMark }
2269
+ });
2270
+ this.#matchers.set(pattern, m);
2271
+ }
2272
+ return m;
2273
+ }
2274
+ #slashSplit(p) {
2275
+ if (this.preserveMultipleSlashes) {
2276
+ return p.split("/");
2277
+ } else if (this.isWindows && /^\/\/[^/]+/.test(p)) {
2278
+ return ["", ...p.split(/\/+/)];
2279
+ } else {
2280
+ return p.split(/\/+/);
2281
+ }
2282
+ }
2283
+ match(f, partial = this.partial) {
2284
+ if (this.comment) {
2285
+ return false;
2286
+ }
2287
+ if (this.empty) {
2288
+ return f === "";
2289
+ }
2290
+ if (f === "/" && partial) {
2291
+ return true;
2292
+ }
2293
+ const options = this.options;
2294
+ let split = this.#cachedSplit(f);
2295
+ if (!split) {
2296
+ if (!partial && !this.#form && (this.#endCheck || this.#literalCheck) && lastChecked !== f) {
2297
+ lastChecked = f;
2298
+ const can = this.#canMatch(f);
2299
+ if (can === "no")
2300
+ return options.flipNegate ? false : this.negate;
2301
+ if (can === "yes")
2302
+ return options.flipNegate ? true : !this.negate;
2303
+ }
2304
+ split = this.#split(f);
2305
+ }
2306
+ const ff = split.parts;
2307
+ const resolved = this.#level2 ? split.resolved ??= this.#levelTwoFileOptimize(ff) : ff;
2308
+ const set = this.set;
2309
+ let filename = ff[ff.length - 1];
2310
+ if (!filename) {
2311
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
2312
+ filename = ff[i];
2313
+ }
2314
+ }
2315
+ for (let r = 0; r < set.length; r++) {
2316
+ const pattern = set[r];
2317
+ const shape = partial ? void 0 : this.#shapes[r];
2318
+ const hit = shape === "base" ? portionMatch(pattern[0], filename) : shape ? this.#matchShape(resolved, pattern, shape) : options.matchBase && pattern.length === 1 ? this.#matchRow([filename], [filename], pattern, partial) : this.#matchRow(ff, resolved, pattern, partial);
2319
+ if (hit) {
2320
+ if (options.flipNegate) {
2321
+ return true;
2322
+ }
2323
+ return !this.negate;
2324
+ }
2325
+ }
2326
+ if (options.flipNegate) {
2327
+ return false;
2328
+ }
2329
+ return this.negate;
2330
+ }
2331
+ static defaults(def) {
2332
+ return minimatch.defaults(def).Minimatch;
2333
+ }
2334
+ };
2335
+ minimatch.Minimatch = Minimatch;
2336
+ minimatch.escape = escape;
2337
+ minimatch.unescape = unescape;
2338
+
2339
+ // src/runner-globs.ts
2340
+ var MAX_GLOB_ALTERNATIVES = 256;
2341
+ var MAX_GLOB_LENGTH = 1024;
2342
+ var MAX_GLOB_STARS_PER_SEGMENT = 3;
2343
+ var EXTGLOB = /[+*?@!]\(/;
2344
+ function compile2(glob) {
2345
+ if (glob.length > MAX_GLOB_LENGTH) return `it is longer than ${MAX_GLOB_LENGTH} characters`;
2346
+ if (braceExpand(glob, { braceExpandMax: MAX_GLOB_ALTERNATIVES + 1 }).length > MAX_GLOB_ALTERNATIVES) {
2347
+ return `its braces expand to more than ${MAX_GLOB_ALTERNATIVES} alternatives`;
2348
+ }
2349
+ if (EXTGLOB.test(glob)) return "it uses an extended glob form such as +(...) or !(...), which can take exponential time to match";
2350
+ const crowded = glob.split("/").some((segment) => segment !== "**" && segment.split("*").length - 1 > MAX_GLOB_STARS_PER_SEGMENT);
2351
+ if (crowded) return `a path segment of it holds more than ${MAX_GLOB_STARS_PER_SEGMENT} "*" characters, which can take too long to match`;
2352
+ return new Minimatch(glob, { dot: true });
2353
+ }
2354
+ function runnerMatcher(runners) {
2355
+ const matchers = runners.map((runner) => {
2356
+ const compiled = compile2(runner.files);
2357
+ if (typeof compiled === "string") {
2358
+ process.stderr.write(`The runner glob ${JSON.stringify(sanitizeTerminal(runner.files.slice(0, 80)))} matches no file: ${compiled}.
2359
+ `);
2360
+ }
2361
+ return compiled;
2362
+ });
2363
+ return (path2) => {
2364
+ const index = matchers.findIndex((matcher) => typeof matcher !== "string" && matcher.match(path2));
2365
+ return index === -1 ? void 0 : index;
2366
+ };
2367
+ }
2368
+
2369
+ // src/runner/diff-lines.ts
2370
+ var HUNK = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
2371
+ var NEW_FILE = /^\+\+\+ b\/([^\t"].*?)\t?$/;
2372
+ function diffLines(patch) {
2373
+ const files = /* @__PURE__ */ new Map();
2374
+ const lines = patch.split("\n");
2375
+ let path2;
2376
+ for (let at = 0; at < lines.length; at += 1) {
2377
+ const line = lines[at];
2378
+ if (line.startsWith("diff --git ")) {
2379
+ path2 = void 0;
2380
+ continue;
2381
+ }
2382
+ if (line.startsWith("+++ ")) {
2383
+ path2 = NEW_FILE.exec(line)?.[1];
2384
+ continue;
2385
+ }
2386
+ const hunk = HUNK.exec(line);
2387
+ if (hunk === null) continue;
2388
+ let oldLeft = Number(hunk[1] ?? 1);
2389
+ let newLeft = Number(hunk[3] ?? 1);
2390
+ const start = Number(hunk[2]);
2391
+ if (path2 !== void 0 && newLeft > 0) files.set(path2, [...files.get(path2) ?? [], [start, start + newLeft - 1]]);
2392
+ while ((oldLeft > 0 || newLeft > 0) && at + 1 < lines.length) {
2393
+ at += 1;
2394
+ const mark = lines[at][0];
2395
+ if (mark === "\\") continue;
2396
+ if (mark !== "+") oldLeft -= 1;
2397
+ if (mark !== "-") newLeft -= 1;
2398
+ }
2399
+ }
2400
+ return files;
2401
+ }
2402
+ function lineInDiff(lines, path2, line) {
2403
+ return (lines.get(path2) ?? []).some(([first, last]) => line >= first && line <= last);
2404
+ }
2405
+
2406
+ // src/runner/judge-items.ts
2407
+ var ARTIFACT_PROOF_REASON = "Its declared artifact proves it; the judge does not judge artifacts.";
2408
+ var NO_NAMED_TEST_REASON = "The judge named no test file that proves this criterion.";
2409
+ var NO_VERDICT_REASON = "The judge gave no result for this criterion.";
2410
+ var JUDGE_GROUP_SIZE = 12;
2411
+ function notReadAsTestReason(paths) {
2412
+ const named = paths.slice(0, 3).map((path2) => `\`${path2}\``);
2413
+ const list = named.length === 1 ? named[0] : `${named.slice(0, -1).join(", ")} and ${named.at(-1)}`;
2414
+ const more = paths.length > 3 ? " and other files" : "";
2415
+ const one = paths.length === 1;
2416
+ return `The judge named ${list}${more}, which ${one ? "is" : "are"} not read as ${one ? "a test" : "tests"}. If ${one ? "that file holds" : "one of them holds"} the test, name it with a runner glob in \`.outerlayer-proofs.yaml\`.`;
2417
+ }
2418
+ function treePath(raw, treeRoot) {
2419
+ let path2 = raw.trim().replace(/\\/g, "/");
2420
+ const root = `${treeRoot.replace(/\/+$/, "")}/`;
2421
+ if (path2.startsWith(root)) path2 = path2.slice(root.length);
2422
+ while (path2.startsWith("./")) path2 = path2.slice(2);
2423
+ if (path2 === "" || path2.length > CHECK_ITEM_REF_PATH_MAX_LENGTH || path2.startsWith("/") || /[\u0000-\u001f\u007f]/.test(path2)) return void 0;
2424
+ if (path2.split("/").some((segment) => segment === ".." || segment === "")) return void 0;
2425
+ return path2;
2426
+ }
2427
+ function criterionInputs(input) {
2428
+ const hash = createHash("sha256");
2429
+ const part = (text) => {
2430
+ hash.update(`${Buffer.byteLength(text)}:`);
2431
+ hash.update(text);
2432
+ };
2433
+ part("judge-criterion-v2");
2434
+ part(input.brief);
2435
+ part(input.criterion.id);
2436
+ part(input.criterion.text);
2437
+ part(input.criterion.proof ?? "");
2438
+ for (const path2 of [...input.files.keys()].sort()) {
2439
+ const text = input.files.get(path2);
2440
+ part(path2);
2441
+ part(text === void 0 ? "missing" : `text:${text}`);
2442
+ }
2443
+ return hash.digest("hex");
2444
+ }
2445
+ function refPaths(refs) {
2446
+ return [...new Set((refs ?? []).map((ref) => ref.path))].sort();
2447
+ }
2448
+ function planCriteria(input) {
2449
+ const previousById = new Map(input.previous.map((item) => [item.id, item]));
2450
+ const settled = [];
2451
+ const toJudge = [];
2452
+ for (const criterion of input.criteria) {
2453
+ const base = { id: criterion.id, criterion: criterion.id };
2454
+ if (criterion.proof !== null) {
2455
+ settled.push({ ...base, result: "skipped", reason: ARTIFACT_PROOF_REASON });
2456
+ continue;
2457
+ }
2458
+ const kept = previousById.get(criterion.id);
2459
+ const paths = refPaths(kept?.refs);
2460
+ if (kept !== void 0 && kept.result === "pass" && kept.inputs !== void 0 && paths.length > 0) {
2461
+ const inputs = input.inputsFor(criterion, paths);
2462
+ if (inputs === kept.inputs) {
2463
+ settled.push({ ...base, ...kept.commit === void 0 ? {} : { commit: kept.commit }, result: "pass", ...kept.reason === void 0 ? {} : { reason: kept.reason }, refs: kept.refs, inputs });
2464
+ continue;
2465
+ }
2466
+ }
2467
+ toJudge.push(criterion);
2468
+ }
2469
+ return { settled, toJudge };
2470
+ }
2471
+ function judgeGroups(criteria, size = JUDGE_GROUP_SIZE) {
2472
+ const groups = [];
2473
+ for (let start = 0; start < criteria.length; start += size) groups.push(criteria.slice(start, start + size));
2474
+ return groups;
2475
+ }
2476
+ var MAX_ANSWER_ENTRIES = 500;
2477
+ var MAX_NAMED_TESTS = 50;
2478
+ function readPlaces(raw) {
2479
+ if (!Array.isArray(raw)) return void 0;
2480
+ const tests = [];
2481
+ for (const entry of raw.slice(0, MAX_NAMED_TESTS)) {
2482
+ const { path: path2, line } = typeof entry === "object" && entry !== null ? entry : {};
2483
+ if (typeof path2 !== "string" || path2 === "" || path2.length > 1024) continue;
2484
+ tests.push({ path: path2, ...typeof line === "number" && Number.isInteger(line) && line > 0 ? { line } : {} });
2485
+ }
2486
+ return tests;
2487
+ }
2488
+ function readAnswer(raw) {
2489
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return { ok: false, problem: "expected an object" };
2490
+ const { result, items, reviewed } = raw;
2491
+ if (result !== void 0 && result !== "pass" && result !== "fail") return { ok: false, problem: 'result: must be "pass" or "fail"' };
2492
+ const read = Array.isArray(reviewed) ? reviewed.filter((path2) => typeof path2 === "string" && path2 !== "" && path2.length <= 500).slice(0, MAX_ANSWER_ENTRIES) : void 0;
2493
+ if (items !== void 0 && !Array.isArray(items)) return { ok: false, problem: "items: must be an array" };
2494
+ const entries = items ?? [];
2495
+ if (entries.length > MAX_ANSWER_ENTRIES) return { ok: false, problem: `items: at most ${MAX_ANSWER_ENTRIES} entries` };
2496
+ const answered = [];
2497
+ for (const [index, entry] of entries.entries()) {
2498
+ const { id, result: itemResult, reason, tests, refs } = typeof entry === "object" && entry !== null ? entry : {};
2499
+ if (typeof id !== "string" || id === "" || id.length > 200) return { ok: false, problem: `items.${index}.id: must be text of 1 to 200 characters` };
2500
+ if (itemResult !== "pass" && itemResult !== "fail") return { ok: false, problem: `items.${index}.result: must be "pass" or "fail"` };
2501
+ if (reason !== void 0 && typeof reason !== "string") return { ok: false, problem: `items.${index}.reason: must be text` };
2502
+ const named = readPlaces(tests);
2503
+ const places = readPlaces(refs);
2504
+ answered.push({ id, result: itemResult, ...reason === void 0 ? {} : { reason }, ...named === void 0 ? {} : { tests: named }, ...places === void 0 ? {} : { refs: places } });
2505
+ }
2506
+ return { ok: true, answer: { ...result === void 0 ? {} : { result }, items: answered, ...read === void 0 ? {} : { reviewed: read } } };
2507
+ }
2508
+ function parseJudgeAnswer(text) {
2509
+ if (text === void 0 || text.trim() === "") return void 0;
2510
+ let raw;
2511
+ try {
2512
+ raw = JSON.parse(text);
2513
+ } catch {
2514
+ return { ok: false, reason: "the judge's items.json is not JSON" };
2515
+ }
2516
+ const read = readAnswer(raw);
2517
+ return read.ok ? read : { ok: false, reason: `the judge's items.json does not match its shape: ${read.problem}` };
2518
+ }
2519
+ function oneLineReason(text) {
2520
+ if (text === void 0) return void 0;
2521
+ const line = text.replace(/\s+/g, " ").trim();
2522
+ if (line === "") return void 0;
2523
+ return line.length <= CHECK_ITEM_REASON_MAX_LENGTH ? line : `${line.slice(0, CHECK_ITEM_REASON_MAX_LENGTH - 1)}\u2026`;
2524
+ }
2525
+ function namedTests(tests, input) {
2526
+ const refs = [];
2527
+ const notTests = [];
2528
+ const seen = /* @__PURE__ */ new Set();
2529
+ for (const test of tests ?? []) {
2530
+ const written = treePath(test.path, input.treeRoot);
2531
+ if (written === void 0) continue;
2532
+ const path2 = written.startsWith("tree/") && input.ownTree !== true ? written.slice("tree/".length) : written;
2533
+ if (path2 === "") continue;
2534
+ const known = input.check(path2, test.line);
2535
+ if (known === void 0) continue;
2536
+ const key = `${path2}:${test.line ?? ""}`;
2537
+ if (seen.has(key)) continue;
2538
+ if (known === "not-a-test") {
2539
+ if (!notTests.includes(path2)) notTests.push(path2);
2540
+ continue;
2541
+ }
2542
+ seen.add(key);
2543
+ refs.push({ path: path2, ...test.line === void 0 ? {} : { line: test.line }, ...known.href === void 0 ? {} : { href: known.href } });
2544
+ if (refs.length >= CHECK_ITEM_REFS_MAX) break;
2545
+ }
2546
+ return { refs, notTests };
2547
+ }
2548
+ function judgedItems(input) {
2549
+ return input.toJudge.map((criterion) => {
2550
+ const said = input.results.get(criterion.id);
2551
+ const base = { id: criterion.id, criterion: criterion.id, commit: input.commit };
2552
+ if (said === void 0) return { ...base, result: "fail", reason: NO_VERDICT_REASON };
2553
+ const { refs, notTests } = namedTests(said.tests, { treeRoot: input.treeRoot, check: input.check, ownTree: input.ownTree });
2554
+ const withRefs = refs.length === 0 ? {} : { refs };
2555
+ if (said.result === "pass" && refs.length === 0) return { ...base, result: "fail", reason: notTests.length > 0 ? oneLineReason(notReadAsTestReason(notTests)) : NO_NAMED_TEST_REASON };
2556
+ const reason = oneLineReason(said.reason);
2557
+ const kept = said.result === "pass" ? { inputs: input.inputsFor(criterion, refPaths(refs)) } : {};
2558
+ return { ...base, result: said.result, ...reason === void 0 ? {} : { reason }, ...withRefs, ...kept };
2559
+ });
2560
+ }
2561
+ function itemIds(ids, clean) {
2562
+ const used = /* @__PURE__ */ new Set([JUDGE_NOT_RUN_ITEM_ID, REVIEWED_COMMIT_ITEM_ID]);
2563
+ return ids.map((id) => {
2564
+ const base = clean(id).replace(/[\u0000-\u001f\u007f]+/g, " ").trim() || "problem";
2565
+ let unique = base.slice(0, CHECK_ITEM_ID_MAX_LENGTH);
2566
+ for (let count = 2; used.has(unique); count += 1) unique = `${base.slice(0, CHECK_ITEM_ID_MAX_LENGTH - `-${count}`.length)}-${count}`;
2567
+ used.add(unique);
2568
+ return unique;
2569
+ });
2570
+ }
2571
+ function wholeItems(input) {
2572
+ const lines = diffLines(input.patch);
2573
+ const entries = [...input.answer.items.filter((entry) => entry.result === "fail"), ...input.answer.items.filter((entry) => entry.result !== "fail")].slice(0, CHECK_ITEMS_MAX - 1);
2574
+ const ids = itemIds(entries.map((entry) => entry.id), input.clean);
2575
+ return entries.map((entry, index) => {
2576
+ const reason = oneLineReason(entry.reason === void 0 ? void 0 : input.clean(entry.reason));
2577
+ const { refs } = namedTests(entry.refs, { treeRoot: input.treeRoot, check: input.place, ownTree: input.ownTree });
2578
+ const placed = entry.result === "fail" ? refs.map((ref) => ref.line === void 0 ? ref : { ...ref, inDiff: lineInDiff(lines, ref.path, ref.line) }) : refs;
2579
+ return { id: ids[index], result: entry.result, commit: input.commit, ...reason === void 0 ? {} : { reason }, ...placed.length === 0 ? {} : { refs: placed } };
2580
+ });
2581
+ }
2582
+ function failedItems(criteria, reason) {
2583
+ const said = oneLineReason(reason) ?? NO_VERDICT_REASON;
2584
+ return criteria.map((criterion) => ({ id: criterion.id, criterion: criterion.id, result: "fail", reason: said }));
2585
+ }
2586
+ function testsByCriterion(items) {
2587
+ const tests = {};
2588
+ for (const item of items) {
2589
+ tests[item.id] = (item.refs ?? []).flatMap((ref) => ref.line === void 0 ? [] : [{ path: ref.path, line: ref.line, href: ref.href ?? null }]);
2590
+ }
2591
+ return tests;
2592
+ }
2593
+ function inCriteriaOrder(items, criteria) {
2594
+ const order = new Map(criteria.map((criterion, index) => [criterion.id, index]));
2595
+ return [...items].sort((a, b) => (order.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (order.get(b.id) ?? Number.MAX_SAFE_INTEGER));
2596
+ }
2597
+ function itemsSentence(items, noun) {
2598
+ const failing = items.filter((item) => item.result === "fail").map((item) => item.id);
2599
+ if (failing.length === 0) return void 0;
2600
+ return `${failing.length} of ${items.length} ${items.length === 1 ? noun.one : noun.many} not satisfied: ${failing.join(", ")}`;
2601
+ }
2602
+ var MAX_TEST_FILE_BYTES = 1024 * 1024;
2603
+ async function loadCitationFinder() {
2604
+ return await import(pathToFileURL(join(resolvePackRoot(), "maintained", "outerlayer-build", "scripts", "criterion-citations.mjs")).href);
2605
+ }
2606
+ function testFileMatcher(finder, proofsText) {
2607
+ const parsed = proofsText === void 0 ? void 0 : parseProofsConfig(proofsText);
2608
+ const runners = parsed?.ok === true ? parsed.value.runners : [];
2609
+ const runnerFor = runnerMatcher(runners);
2610
+ const inRunnerGlob = (path2) => runnerFor(path2) !== void 0;
2611
+ return (path2) => finder.isTestFile(path2, inRunnerGlob);
2612
+ }
2613
+ function criteriaOf(workItem) {
2614
+ const criteria = Object(Object(workItem).criteria);
2615
+ if (!Array.isArray(criteria.items)) return void 0;
2616
+ const drafted = criteria.drafted === true;
2617
+ const items = [];
2618
+ for (const entry of criteria.items) {
2619
+ const { id, text, proof } = Object(entry);
2620
+ if (typeof id !== "string" || typeof text !== "string") continue;
2621
+ items.push({ id, text, proof: typeof proof === "string" ? proof : null, drafted });
2622
+ }
2623
+ return items.length === 0 ? void 0 : items;
2624
+ }
2625
+ function openPullRequests(workItem) {
2626
+ const declared = Object(workItem).pullRequests;
2627
+ if (!Array.isArray(declared)) return [];
2628
+ return declared.flatMap((entry) => {
2629
+ const { state, repository } = Object(entry);
2630
+ return (state === "open" || state === null || state === void 0) && typeof repository === "string" ? [repository] : [];
2631
+ });
2632
+ }
2633
+ function hostItemsOf(workItem, name) {
2634
+ const checks = Object(workItem).checks;
2635
+ if (!Array.isArray(checks)) return [];
2636
+ const check = checks.find((entry) => Object(entry).name === name);
2637
+ if (check?.source !== "host") return [];
2638
+ const parsed = CheckItemsSchema.safeParse(check.items);
2639
+ return parsed.success ? parsed.data : [];
2640
+ }
2641
+
2642
+ export { MAX_TEST_FILE_BYTES, NO_VERDICT_REASON, criteriaOf, criterionInputs, failedItems, hostItemsOf, inCriteriaOrder, itemsSentence, judgeGroups, judgedItems, loadCitationFinder, oneLineReason, openPullRequests, parseJudgeAnswer, planCriteria, runnerMatcher, testFileMatcher, testsByCriterion, wholeItems };