@dcf-micro/eslint-config 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/chunks/eslint-plugin-prettier.mjs +1716 -0
  2. package/dist/chunks/index.mjs +1341 -0
  3. package/dist/chunks/index10.mjs +39595 -0
  4. package/dist/chunks/index11.mjs +24 -0
  5. package/dist/chunks/index12.mjs +75273 -0
  6. package/dist/chunks/index13.mjs +55129 -0
  7. package/dist/chunks/index14.mjs +24 -0
  8. package/dist/chunks/index15.mjs +1441 -0
  9. package/dist/chunks/index2.mjs +31864 -0
  10. package/dist/chunks/index3.mjs +8154 -0
  11. package/dist/chunks/index4.mjs +24 -0
  12. package/dist/chunks/index5.mjs +44093 -0
  13. package/dist/chunks/index6.mjs +10371 -0
  14. package/dist/chunks/index7.mjs +21890 -0
  15. package/dist/chunks/index8.mjs +14424 -0
  16. package/dist/chunks/index9.mjs +194 -0
  17. package/dist/chunks/jiti.mjs +320 -0
  18. package/dist/index.d.mts +3897 -0
  19. package/dist/index.d.ts +3897 -0
  20. package/dist/index.mjs +4 -0
  21. package/dist/shared/eslint-config.BDBLGvXj.mjs +5282 -0
  22. package/dist/shared/eslint-config.BEdqg1el.mjs +12256 -0
  23. package/dist/shared/eslint-config.BKmXKm8B.mjs +5533 -0
  24. package/dist/shared/eslint-config.BjUMgISS.mjs +9012 -0
  25. package/dist/shared/eslint-config.Bk-3rH6Y.mjs +1355 -0
  26. package/dist/shared/eslint-config.BytuZ0Ec.mjs +20 -0
  27. package/dist/shared/eslint-config.C1V0I4Np.mjs +16900 -0
  28. package/dist/shared/eslint-config.CGxZQKHV.mjs +2091 -0
  29. package/dist/shared/eslint-config.COweQ1RR.mjs +5 -0
  30. package/dist/shared/eslint-config.CSnk9Q4w.mjs +9339 -0
  31. package/dist/shared/eslint-config.CWvTq0mr.mjs +2914 -0
  32. package/dist/shared/eslint-config.Ca4PTK8E.mjs +646 -0
  33. package/dist/shared/eslint-config.CmPTszkJ.mjs +3583 -0
  34. package/dist/shared/eslint-config.CqEANaNA.mjs +139622 -0
  35. package/dist/shared/eslint-config.CsePEcYJ.mjs +71 -0
  36. package/dist/shared/eslint-config.Cw6mETSZ.mjs +2580 -0
  37. package/dist/shared/eslint-config.DTVnsecK.mjs +1751 -0
  38. package/dist/shared/eslint-config.DWoU09EE.mjs +6958 -0
  39. package/dist/shared/eslint-config.DZvqTQUU.mjs +3818 -0
  40. package/dist/shared/eslint-config.Dhg7lT0g.mjs +1807 -0
  41. package/dist/shared/eslint-config.Du5y5qmf.mjs +200673 -0
  42. package/dist/shared/eslint-config.FKVuBSa4.mjs +394 -0
  43. package/dist/shared/eslint-config.I8d-HnmI.mjs +2654 -0
  44. package/dist/shared/eslint-config.YntqsQY1.mjs +40 -0
  45. package/dist/shared/eslint-config.uGTBNMD0.mjs +687 -0
  46. package/package.json +56 -0
@@ -0,0 +1,2091 @@
1
+ import { r as requireBalancedMatch } from './eslint-config.CsePEcYJ.mjs';
2
+
3
+ var commonjs = {};
4
+
5
+ var braceExpansion;
6
+ var hasRequiredBraceExpansion;
7
+
8
+ function requireBraceExpansion () {
9
+ if (hasRequiredBraceExpansion) return braceExpansion;
10
+ hasRequiredBraceExpansion = 1;
11
+ var balanced = requireBalancedMatch();
12
+
13
+ braceExpansion = expandTop;
14
+
15
+ var escSlash = '\0SLASH'+Math.random()+'\0';
16
+ var escOpen = '\0OPEN'+Math.random()+'\0';
17
+ var escClose = '\0CLOSE'+Math.random()+'\0';
18
+ var escComma = '\0COMMA'+Math.random()+'\0';
19
+ var escPeriod = '\0PERIOD'+Math.random()+'\0';
20
+
21
+ function numeric(str) {
22
+ return parseInt(str, 10) == str
23
+ ? parseInt(str, 10)
24
+ : str.charCodeAt(0);
25
+ }
26
+
27
+ function escapeBraces(str) {
28
+ return str.split('\\\\').join(escSlash)
29
+ .split('\\{').join(escOpen)
30
+ .split('\\}').join(escClose)
31
+ .split('\\,').join(escComma)
32
+ .split('\\.').join(escPeriod);
33
+ }
34
+
35
+ function unescapeBraces(str) {
36
+ return str.split(escSlash).join('\\')
37
+ .split(escOpen).join('{')
38
+ .split(escClose).join('}')
39
+ .split(escComma).join(',')
40
+ .split(escPeriod).join('.');
41
+ }
42
+
43
+
44
+ // Basically just str.split(","), but handling cases
45
+ // where we have nested braced sections, which should be
46
+ // treated as individual members, like {a,{b,c},d}
47
+ function parseCommaParts(str) {
48
+ if (!str)
49
+ return [''];
50
+
51
+ var parts = [];
52
+ var m = balanced('{', '}', str);
53
+
54
+ if (!m)
55
+ return str.split(',');
56
+
57
+ var pre = m.pre;
58
+ var body = m.body;
59
+ var post = m.post;
60
+ var p = pre.split(',');
61
+
62
+ p[p.length-1] += '{' + body + '}';
63
+ var postParts = parseCommaParts(post);
64
+ if (post.length) {
65
+ p[p.length-1] += postParts.shift();
66
+ p.push.apply(p, postParts);
67
+ }
68
+
69
+ parts.push.apply(parts, p);
70
+
71
+ return parts;
72
+ }
73
+
74
+ function expandTop(str) {
75
+ if (!str)
76
+ return [];
77
+
78
+ // I don't know why Bash 4.3 does this, but it does.
79
+ // Anything starting with {} will have the first two bytes preserved
80
+ // but *only* at the top level, so {},a}b will not expand to anything,
81
+ // but a{},b}c will be expanded to [a}c,abc].
82
+ // One could argue that this is a bug in Bash, but since the goal of
83
+ // this module is to match Bash's rules, we escape a leading {}
84
+ if (str.substr(0, 2) === '{}') {
85
+ str = '\\{\\}' + str.substr(2);
86
+ }
87
+
88
+ return expand(escapeBraces(str), true).map(unescapeBraces);
89
+ }
90
+
91
+ function embrace(str) {
92
+ return '{' + str + '}';
93
+ }
94
+ function isPadded(el) {
95
+ return /^-?0\d/.test(el);
96
+ }
97
+
98
+ function lte(i, y) {
99
+ return i <= y;
100
+ }
101
+ function gte(i, y) {
102
+ return i >= y;
103
+ }
104
+
105
+ function expand(str, isTop) {
106
+ var expansions = [];
107
+
108
+ var m = balanced('{', '}', str);
109
+ if (!m) return [str];
110
+
111
+ // no need to expand pre, since it is guaranteed to be free of brace-sets
112
+ var pre = m.pre;
113
+ var post = m.post.length
114
+ ? expand(m.post, false)
115
+ : [''];
116
+
117
+ if (/\$$/.test(m.pre)) {
118
+ for (var k = 0; k < post.length; k++) {
119
+ var expansion = pre+ '{' + m.body + '}' + post[k];
120
+ expansions.push(expansion);
121
+ }
122
+ } else {
123
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
124
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
125
+ var isSequence = isNumericSequence || isAlphaSequence;
126
+ var isOptions = m.body.indexOf(',') >= 0;
127
+ if (!isSequence && !isOptions) {
128
+ // {a},b}
129
+ if (m.post.match(/,.*\}/)) {
130
+ str = m.pre + '{' + m.body + escClose + m.post;
131
+ return expand(str);
132
+ }
133
+ return [str];
134
+ }
135
+
136
+ var n;
137
+ if (isSequence) {
138
+ n = m.body.split(/\.\./);
139
+ } else {
140
+ n = parseCommaParts(m.body);
141
+ if (n.length === 1) {
142
+ // x{{a,b}}y ==> x{a}y x{b}y
143
+ n = expand(n[0], false).map(embrace);
144
+ if (n.length === 1) {
145
+ return post.map(function(p) {
146
+ return m.pre + n[0] + p;
147
+ });
148
+ }
149
+ }
150
+ }
151
+
152
+ // at this point, n is the parts, and we know it's not a comma set
153
+ // with a single entry.
154
+ var N;
155
+
156
+ if (isSequence) {
157
+ var x = numeric(n[0]);
158
+ var y = numeric(n[1]);
159
+ var width = Math.max(n[0].length, n[1].length);
160
+ var incr = n.length == 3
161
+ ? Math.abs(numeric(n[2]))
162
+ : 1;
163
+ var test = lte;
164
+ var reverse = y < x;
165
+ if (reverse) {
166
+ incr *= -1;
167
+ test = gte;
168
+ }
169
+ var pad = n.some(isPadded);
170
+
171
+ N = [];
172
+
173
+ for (var i = x; test(i, y); i += incr) {
174
+ var c;
175
+ if (isAlphaSequence) {
176
+ c = String.fromCharCode(i);
177
+ if (c === '\\')
178
+ c = '';
179
+ } else {
180
+ c = String(i);
181
+ if (pad) {
182
+ var need = width - c.length;
183
+ if (need > 0) {
184
+ var z = new Array(need + 1).join('0');
185
+ if (i < 0)
186
+ c = '-' + z + c.slice(1);
187
+ else
188
+ c = z + c;
189
+ }
190
+ }
191
+ }
192
+ N.push(c);
193
+ }
194
+ } else {
195
+ N = [];
196
+
197
+ for (var j = 0; j < n.length; j++) {
198
+ N.push.apply(N, expand(n[j], false));
199
+ }
200
+ }
201
+
202
+ for (var j = 0; j < N.length; j++) {
203
+ for (var k = 0; k < post.length; k++) {
204
+ var expansion = pre + N[j] + post[k];
205
+ if (!isTop || isSequence || expansion)
206
+ expansions.push(expansion);
207
+ }
208
+ }
209
+ }
210
+
211
+ return expansions;
212
+ }
213
+ return braceExpansion;
214
+ }
215
+
216
+ var assertValidPattern = {};
217
+
218
+ var hasRequiredAssertValidPattern;
219
+
220
+ function requireAssertValidPattern () {
221
+ if (hasRequiredAssertValidPattern) return assertValidPattern;
222
+ hasRequiredAssertValidPattern = 1;
223
+ Object.defineProperty(assertValidPattern, "__esModule", { value: true });
224
+ assertValidPattern.assertValidPattern = void 0;
225
+ const MAX_PATTERN_LENGTH = 1024 * 64;
226
+ const assertValidPattern$1 = (pattern) => {
227
+ if (typeof pattern !== 'string') {
228
+ throw new TypeError('invalid pattern');
229
+ }
230
+ if (pattern.length > MAX_PATTERN_LENGTH) {
231
+ throw new TypeError('pattern is too long');
232
+ }
233
+ };
234
+ assertValidPattern.assertValidPattern = assertValidPattern$1;
235
+
236
+ return assertValidPattern;
237
+ }
238
+
239
+ var ast = {};
240
+
241
+ var braceExpressions = {};
242
+
243
+ var hasRequiredBraceExpressions;
244
+
245
+ function requireBraceExpressions () {
246
+ if (hasRequiredBraceExpressions) return braceExpressions;
247
+ hasRequiredBraceExpressions = 1;
248
+ // translate the various posix character classes into unicode properties
249
+ // this works across all unicode locales
250
+ Object.defineProperty(braceExpressions, "__esModule", { value: true });
251
+ braceExpressions.parseClass = void 0;
252
+ // { <posix class>: [<translation>, /u flag required, negated]
253
+ const posixClasses = {
254
+ '[:alnum:]': ['\\p{L}\\p{Nl}\\p{Nd}', true],
255
+ '[:alpha:]': ['\\p{L}\\p{Nl}', true],
256
+ '[:ascii:]': ['\\x' + '00-\\x' + '7f', false],
257
+ '[:blank:]': ['\\p{Zs}\\t', true],
258
+ '[:cntrl:]': ['\\p{Cc}', true],
259
+ '[:digit:]': ['\\p{Nd}', true],
260
+ '[:graph:]': ['\\p{Z}\\p{C}', true, true],
261
+ '[:lower:]': ['\\p{Ll}', true],
262
+ '[:print:]': ['\\p{C}', true],
263
+ '[:punct:]': ['\\p{P}', true],
264
+ '[:space:]': ['\\p{Z}\\t\\r\\n\\v\\f', true],
265
+ '[:upper:]': ['\\p{Lu}', true],
266
+ '[:word:]': ['\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}', true],
267
+ '[:xdigit:]': ['A-Fa-f0-9', false],
268
+ };
269
+ // only need to escape a few things inside of brace expressions
270
+ // escapes: [ \ ] -
271
+ const braceEscape = (s) => s.replace(/[[\]\\-]/g, '\\$&');
272
+ // escape all regexp magic characters
273
+ const regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
274
+ // everything has already been escaped, we just have to join
275
+ const rangesToString = (ranges) => ranges.join('');
276
+ // takes a glob string at a posix brace expression, and returns
277
+ // an equivalent regular expression source, and boolean indicating
278
+ // whether the /u flag needs to be applied, and the number of chars
279
+ // consumed to parse the character class.
280
+ // This also removes out of order ranges, and returns ($.) if the
281
+ // entire class just no good.
282
+ const parseClass = (glob, position) => {
283
+ const pos = position;
284
+ /* c8 ignore start */
285
+ if (glob.charAt(pos) !== '[') {
286
+ throw new Error('not in a brace expression');
287
+ }
288
+ /* c8 ignore stop */
289
+ const ranges = [];
290
+ const negs = [];
291
+ let i = pos + 1;
292
+ let sawStart = false;
293
+ let uflag = false;
294
+ let escaping = false;
295
+ let negate = false;
296
+ let endPos = pos;
297
+ let rangeStart = '';
298
+ WHILE: while (i < glob.length) {
299
+ const c = glob.charAt(i);
300
+ if ((c === '!' || c === '^') && i === pos + 1) {
301
+ negate = true;
302
+ i++;
303
+ continue;
304
+ }
305
+ if (c === ']' && sawStart && !escaping) {
306
+ endPos = i + 1;
307
+ break;
308
+ }
309
+ sawStart = true;
310
+ if (c === '\\') {
311
+ if (!escaping) {
312
+ escaping = true;
313
+ i++;
314
+ continue;
315
+ }
316
+ // escaped \ char, fall through and treat like normal char
317
+ }
318
+ if (c === '[' && !escaping) {
319
+ // either a posix class, a collation equivalent, or just a [
320
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
321
+ if (glob.startsWith(cls, i)) {
322
+ // invalid, [a-[] is fine, but not [a-[:alpha]]
323
+ if (rangeStart) {
324
+ return ['$.', false, glob.length - pos, true];
325
+ }
326
+ i += cls.length;
327
+ if (neg)
328
+ negs.push(unip);
329
+ else
330
+ ranges.push(unip);
331
+ uflag = uflag || u;
332
+ continue WHILE;
333
+ }
334
+ }
335
+ }
336
+ // now it's just a normal character, effectively
337
+ escaping = false;
338
+ if (rangeStart) {
339
+ // throw this range away if it's not valid, but others
340
+ // can still match.
341
+ if (c > rangeStart) {
342
+ ranges.push(braceEscape(rangeStart) + '-' + braceEscape(c));
343
+ }
344
+ else if (c === rangeStart) {
345
+ ranges.push(braceEscape(c));
346
+ }
347
+ rangeStart = '';
348
+ i++;
349
+ continue;
350
+ }
351
+ // now might be the start of a range.
352
+ // can be either c-d or c-] or c<more...>] or c] at this point
353
+ if (glob.startsWith('-]', i + 1)) {
354
+ ranges.push(braceEscape(c + '-'));
355
+ i += 2;
356
+ continue;
357
+ }
358
+ if (glob.startsWith('-', i + 1)) {
359
+ rangeStart = c;
360
+ i += 2;
361
+ continue;
362
+ }
363
+ // not the start of a range, just a single character
364
+ ranges.push(braceEscape(c));
365
+ i++;
366
+ }
367
+ if (endPos < i) {
368
+ // didn't see the end of the class, not a valid class,
369
+ // but might still be valid as a literal match.
370
+ return ['', false, 0, false];
371
+ }
372
+ // if we got no ranges and no negates, then we have a range that
373
+ // cannot possibly match anything, and that poisons the whole glob
374
+ if (!ranges.length && !negs.length) {
375
+ return ['$.', false, glob.length - pos, true];
376
+ }
377
+ // if we got one positive range, and it's a single character, then that's
378
+ // not actually a magic pattern, it's just that one literal character.
379
+ // we should not treat that as "magic", we should just return the literal
380
+ // character. [_] is a perfectly valid way to escape glob magic chars.
381
+ if (negs.length === 0 &&
382
+ ranges.length === 1 &&
383
+ /^\\?.$/.test(ranges[0]) &&
384
+ !negate) {
385
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
386
+ return [regexpEscape(r), false, endPos - pos, false];
387
+ }
388
+ const sranges = '[' + (negate ? '^' : '') + rangesToString(ranges) + ']';
389
+ const snegs = '[' + (negate ? '' : '^') + rangesToString(negs) + ']';
390
+ const comb = ranges.length && negs.length
391
+ ? '(' + sranges + '|' + snegs + ')'
392
+ : ranges.length
393
+ ? sranges
394
+ : snegs;
395
+ return [comb, uflag, endPos - pos, true];
396
+ };
397
+ braceExpressions.parseClass = parseClass;
398
+
399
+ return braceExpressions;
400
+ }
401
+
402
+ var _unescape = {};
403
+
404
+ var hasRequired_unescape;
405
+
406
+ function require_unescape () {
407
+ if (hasRequired_unescape) return _unescape;
408
+ hasRequired_unescape = 1;
409
+ Object.defineProperty(_unescape, "__esModule", { value: true });
410
+ _unescape.unescape = void 0;
411
+ /**
412
+ * Un-escape a string that has been escaped with {@link escape}.
413
+ *
414
+ * If the {@link windowsPathsNoEscape} option is used, then square-brace
415
+ * escapes are removed, but not backslash escapes. For example, it will turn
416
+ * the string `'[*]'` into `*`, but it will not turn `'\\*'` into `'*'`,
417
+ * becuase `\` is a path separator in `windowsPathsNoEscape` mode.
418
+ *
419
+ * When `windowsPathsNoEscape` is not set, then both brace escapes and
420
+ * backslash escapes are removed.
421
+ *
422
+ * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
423
+ * or unescaped.
424
+ */
425
+ const unescape = (s, { windowsPathsNoEscape = false, } = {}) => {
426
+ return windowsPathsNoEscape
427
+ ? s.replace(/\[([^\/\\])\]/g, '$1')
428
+ : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1');
429
+ };
430
+ _unescape.unescape = unescape;
431
+
432
+ return _unescape;
433
+ }
434
+
435
+ var hasRequiredAst;
436
+
437
+ function requireAst () {
438
+ if (hasRequiredAst) return ast;
439
+ hasRequiredAst = 1;
440
+ // parse a single path portion
441
+ Object.defineProperty(ast, "__esModule", { value: true });
442
+ ast.AST = void 0;
443
+ const brace_expressions_js_1 = requireBraceExpressions();
444
+ const unescape_js_1 = require_unescape();
445
+ const types = new Set(['!', '?', '+', '*', '@']);
446
+ const isExtglobType = (c) => types.has(c);
447
+ // Patterns that get prepended to bind to the start of either the
448
+ // entire string, or just a single path portion, to prevent dots
449
+ // and/or traversal patterns, when needed.
450
+ // Exts don't need the ^ or / bit, because the root binds that already.
451
+ const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))';
452
+ const startNoDot = '(?!\\.)';
453
+ // characters that indicate a start of pattern needs the "no dots" bit,
454
+ // because a dot *might* be matched. ( is not in the list, because in
455
+ // the case of a child extglob, it will handle the prevention itself.
456
+ const addPatternStart = new Set(['[', '.']);
457
+ // cases where traversal is A-OK, no dot prevention needed
458
+ const justDots = new Set(['..', '.']);
459
+ const reSpecials = new Set('().*{}+?[]^$\\!');
460
+ const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
461
+ // any single thing other than /
462
+ const qmark = '[^/]';
463
+ // * => any number of characters
464
+ const star = qmark + '*?';
465
+ // use + when we need to ensure that *something* matches, because the * is
466
+ // the only thing in the path portion.
467
+ const starNoEmpty = qmark + '+?';
468
+ // remove the \ chars that we added if we end up doing a nonmagic compare
469
+ // const deslash = (s: string) => s.replace(/\\(.)/g, '$1')
470
+ class AST {
471
+ type;
472
+ #root;
473
+ #hasMagic;
474
+ #uflag = false;
475
+ #parts = [];
476
+ #parent;
477
+ #parentIndex;
478
+ #negs;
479
+ #filledNegs = false;
480
+ #options;
481
+ #toString;
482
+ // set to true if it's an extglob with no children
483
+ // (which really means one child of '')
484
+ #emptyExt = false;
485
+ constructor(type, parent, options = {}) {
486
+ this.type = type;
487
+ // extglobs are inherently magical
488
+ if (type)
489
+ this.#hasMagic = true;
490
+ this.#parent = parent;
491
+ this.#root = this.#parent ? this.#parent.#root : this;
492
+ this.#options = this.#root === this ? options : this.#root.#options;
493
+ this.#negs = this.#root === this ? [] : this.#root.#negs;
494
+ if (type === '!' && !this.#root.#filledNegs)
495
+ this.#negs.push(this);
496
+ this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
497
+ }
498
+ get hasMagic() {
499
+ /* c8 ignore start */
500
+ if (this.#hasMagic !== undefined)
501
+ return this.#hasMagic;
502
+ /* c8 ignore stop */
503
+ for (const p of this.#parts) {
504
+ if (typeof p === 'string')
505
+ continue;
506
+ if (p.type || p.hasMagic)
507
+ return (this.#hasMagic = true);
508
+ }
509
+ // note: will be undefined until we generate the regexp src and find out
510
+ return this.#hasMagic;
511
+ }
512
+ // reconstructs the pattern
513
+ toString() {
514
+ if (this.#toString !== undefined)
515
+ return this.#toString;
516
+ if (!this.type) {
517
+ return (this.#toString = this.#parts.map(p => String(p)).join(''));
518
+ }
519
+ else {
520
+ return (this.#toString =
521
+ this.type + '(' + this.#parts.map(p => String(p)).join('|') + ')');
522
+ }
523
+ }
524
+ #fillNegs() {
525
+ /* c8 ignore start */
526
+ if (this !== this.#root)
527
+ throw new Error('should only call on root');
528
+ if (this.#filledNegs)
529
+ return this;
530
+ /* c8 ignore stop */
531
+ // call toString() once to fill this out
532
+ this.toString();
533
+ this.#filledNegs = true;
534
+ let n;
535
+ while ((n = this.#negs.pop())) {
536
+ if (n.type !== '!')
537
+ continue;
538
+ // walk up the tree, appending everthing that comes AFTER parentIndex
539
+ let p = n;
540
+ let pp = p.#parent;
541
+ while (pp) {
542
+ for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) {
543
+ for (const part of n.#parts) {
544
+ /* c8 ignore start */
545
+ if (typeof part === 'string') {
546
+ throw new Error('string part in extglob AST??');
547
+ }
548
+ /* c8 ignore stop */
549
+ part.copyIn(pp.#parts[i]);
550
+ }
551
+ }
552
+ p = pp;
553
+ pp = p.#parent;
554
+ }
555
+ }
556
+ return this;
557
+ }
558
+ push(...parts) {
559
+ for (const p of parts) {
560
+ if (p === '')
561
+ continue;
562
+ /* c8 ignore start */
563
+ if (typeof p !== 'string' && !(p instanceof AST && p.#parent === this)) {
564
+ throw new Error('invalid part: ' + p);
565
+ }
566
+ /* c8 ignore stop */
567
+ this.#parts.push(p);
568
+ }
569
+ }
570
+ toJSON() {
571
+ const ret = this.type === null
572
+ ? this.#parts.slice().map(p => (typeof p === 'string' ? p : p.toJSON()))
573
+ : [this.type, ...this.#parts.map(p => p.toJSON())];
574
+ if (this.isStart() && !this.type)
575
+ ret.unshift([]);
576
+ if (this.isEnd() &&
577
+ (this === this.#root ||
578
+ (this.#root.#filledNegs && this.#parent?.type === '!'))) {
579
+ ret.push({});
580
+ }
581
+ return ret;
582
+ }
583
+ isStart() {
584
+ if (this.#root === this)
585
+ return true;
586
+ // if (this.type) return !!this.#parent?.isStart()
587
+ if (!this.#parent?.isStart())
588
+ return false;
589
+ if (this.#parentIndex === 0)
590
+ return true;
591
+ // if everything AHEAD of this is a negation, then it's still the "start"
592
+ const p = this.#parent;
593
+ for (let i = 0; i < this.#parentIndex; i++) {
594
+ const pp = p.#parts[i];
595
+ if (!(pp instanceof AST && pp.type === '!')) {
596
+ return false;
597
+ }
598
+ }
599
+ return true;
600
+ }
601
+ isEnd() {
602
+ if (this.#root === this)
603
+ return true;
604
+ if (this.#parent?.type === '!')
605
+ return true;
606
+ if (!this.#parent?.isEnd())
607
+ return false;
608
+ if (!this.type)
609
+ return this.#parent?.isEnd();
610
+ // if not root, it'll always have a parent
611
+ /* c8 ignore start */
612
+ const pl = this.#parent ? this.#parent.#parts.length : 0;
613
+ /* c8 ignore stop */
614
+ return this.#parentIndex === pl - 1;
615
+ }
616
+ copyIn(part) {
617
+ if (typeof part === 'string')
618
+ this.push(part);
619
+ else
620
+ this.push(part.clone(this));
621
+ }
622
+ clone(parent) {
623
+ const c = new AST(this.type, parent);
624
+ for (const p of this.#parts) {
625
+ c.copyIn(p);
626
+ }
627
+ return c;
628
+ }
629
+ static #parseAST(str, ast, pos, opt) {
630
+ let escaping = false;
631
+ let inBrace = false;
632
+ let braceStart = -1;
633
+ let braceNeg = false;
634
+ if (ast.type === null) {
635
+ // outside of a extglob, append until we find a start
636
+ let i = pos;
637
+ let acc = '';
638
+ while (i < str.length) {
639
+ const c = str.charAt(i++);
640
+ // still accumulate escapes at this point, but we do ignore
641
+ // starts that are escaped
642
+ if (escaping || c === '\\') {
643
+ escaping = !escaping;
644
+ acc += c;
645
+ continue;
646
+ }
647
+ if (inBrace) {
648
+ if (i === braceStart + 1) {
649
+ if (c === '^' || c === '!') {
650
+ braceNeg = true;
651
+ }
652
+ }
653
+ else if (c === ']' && !(i === braceStart + 2 && braceNeg)) {
654
+ inBrace = false;
655
+ }
656
+ acc += c;
657
+ continue;
658
+ }
659
+ else if (c === '[') {
660
+ inBrace = true;
661
+ braceStart = i;
662
+ braceNeg = false;
663
+ acc += c;
664
+ continue;
665
+ }
666
+ if (!opt.noext && isExtglobType(c) && str.charAt(i) === '(') {
667
+ ast.push(acc);
668
+ acc = '';
669
+ const ext = new AST(c, ast);
670
+ i = AST.#parseAST(str, ext, i, opt);
671
+ ast.push(ext);
672
+ continue;
673
+ }
674
+ acc += c;
675
+ }
676
+ ast.push(acc);
677
+ return i;
678
+ }
679
+ // some kind of extglob, pos is at the (
680
+ // find the next | or )
681
+ let i = pos + 1;
682
+ let part = new AST(null, ast);
683
+ const parts = [];
684
+ let acc = '';
685
+ while (i < str.length) {
686
+ const c = str.charAt(i++);
687
+ // still accumulate escapes at this point, but we do ignore
688
+ // starts that are escaped
689
+ if (escaping || c === '\\') {
690
+ escaping = !escaping;
691
+ acc += c;
692
+ continue;
693
+ }
694
+ if (inBrace) {
695
+ if (i === braceStart + 1) {
696
+ if (c === '^' || c === '!') {
697
+ braceNeg = true;
698
+ }
699
+ }
700
+ else if (c === ']' && !(i === braceStart + 2 && braceNeg)) {
701
+ inBrace = false;
702
+ }
703
+ acc += c;
704
+ continue;
705
+ }
706
+ else if (c === '[') {
707
+ inBrace = true;
708
+ braceStart = i;
709
+ braceNeg = false;
710
+ acc += c;
711
+ continue;
712
+ }
713
+ if (isExtglobType(c) && str.charAt(i) === '(') {
714
+ part.push(acc);
715
+ acc = '';
716
+ const ext = new AST(c, part);
717
+ part.push(ext);
718
+ i = AST.#parseAST(str, ext, i, opt);
719
+ continue;
720
+ }
721
+ if (c === '|') {
722
+ part.push(acc);
723
+ acc = '';
724
+ parts.push(part);
725
+ part = new AST(null, ast);
726
+ continue;
727
+ }
728
+ if (c === ')') {
729
+ if (acc === '' && ast.#parts.length === 0) {
730
+ ast.#emptyExt = true;
731
+ }
732
+ part.push(acc);
733
+ acc = '';
734
+ ast.push(...parts, part);
735
+ return i;
736
+ }
737
+ acc += c;
738
+ }
739
+ // unfinished extglob
740
+ // if we got here, it was a malformed extglob! not an extglob, but
741
+ // maybe something else in there.
742
+ ast.type = null;
743
+ ast.#hasMagic = undefined;
744
+ ast.#parts = [str.substring(pos - 1)];
745
+ return i;
746
+ }
747
+ static fromGlob(pattern, options = {}) {
748
+ const ast = new AST(null, undefined, options);
749
+ AST.#parseAST(pattern, ast, 0, options);
750
+ return ast;
751
+ }
752
+ // returns the regular expression if there's magic, or the unescaped
753
+ // string if not.
754
+ toMMPattern() {
755
+ // should only be called on root
756
+ /* c8 ignore start */
757
+ if (this !== this.#root)
758
+ return this.#root.toMMPattern();
759
+ /* c8 ignore stop */
760
+ const glob = this.toString();
761
+ const [re, body, hasMagic, uflag] = this.toRegExpSource();
762
+ // if we're in nocase mode, and not nocaseMagicOnly, then we do
763
+ // still need a regular expression if we have to case-insensitively
764
+ // match capital/lowercase characters.
765
+ const anyMagic = hasMagic ||
766
+ this.#hasMagic ||
767
+ (this.#options.nocase &&
768
+ !this.#options.nocaseMagicOnly &&
769
+ glob.toUpperCase() !== glob.toLowerCase());
770
+ if (!anyMagic) {
771
+ return body;
772
+ }
773
+ const flags = (this.#options.nocase ? 'i' : '') + (uflag ? 'u' : '');
774
+ return Object.assign(new RegExp(`^${re}$`, flags), {
775
+ _src: re,
776
+ _glob: glob,
777
+ });
778
+ }
779
+ get options() {
780
+ return this.#options;
781
+ }
782
+ // returns the string match, the regexp source, whether there's magic
783
+ // in the regexp (so a regular expression is required) and whether or
784
+ // not the uflag is needed for the regular expression (for posix classes)
785
+ // TODO: instead of injecting the start/end at this point, just return
786
+ // the BODY of the regexp, along with the start/end portions suitable
787
+ // for binding the start/end in either a joined full-path makeRe context
788
+ // (where we bind to (^|/), or a standalone matchPart context (where
789
+ // we bind to ^, and not /). Otherwise slashes get duped!
790
+ //
791
+ // In part-matching mode, the start is:
792
+ // - if not isStart: nothing
793
+ // - if traversal possible, but not allowed: ^(?!\.\.?$)
794
+ // - if dots allowed or not possible: ^
795
+ // - if dots possible and not allowed: ^(?!\.)
796
+ // end is:
797
+ // - if not isEnd(): nothing
798
+ // - else: $
799
+ //
800
+ // In full-path matching mode, we put the slash at the START of the
801
+ // pattern, so start is:
802
+ // - if first pattern: same as part-matching mode
803
+ // - if not isStart(): nothing
804
+ // - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
805
+ // - if dots allowed or not possible: /
806
+ // - if dots possible and not allowed: /(?!\.)
807
+ // end is:
808
+ // - if last pattern, same as part-matching mode
809
+ // - else nothing
810
+ //
811
+ // Always put the (?:$|/) on negated tails, though, because that has to be
812
+ // there to bind the end of the negated pattern portion, and it's easier to
813
+ // just stick it in now rather than try to inject it later in the middle of
814
+ // the pattern.
815
+ //
816
+ // We can just always return the same end, and leave it up to the caller
817
+ // to know whether it's going to be used joined or in parts.
818
+ // And, if the start is adjusted slightly, can do the same there:
819
+ // - if not isStart: nothing
820
+ // - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
821
+ // - if dots allowed or not possible: (?:/|^)
822
+ // - if dots possible and not allowed: (?:/|^)(?!\.)
823
+ //
824
+ // But it's better to have a simpler binding without a conditional, for
825
+ // performance, so probably better to return both start options.
826
+ //
827
+ // Then the caller just ignores the end if it's not the first pattern,
828
+ // and the start always gets applied.
829
+ //
830
+ // But that's always going to be $ if it's the ending pattern, or nothing,
831
+ // so the caller can just attach $ at the end of the pattern when building.
832
+ //
833
+ // So the todo is:
834
+ // - better detect what kind of start is needed
835
+ // - return both flavors of starting pattern
836
+ // - attach $ at the end of the pattern when creating the actual RegExp
837
+ //
838
+ // Ah, but wait, no, that all only applies to the root when the first pattern
839
+ // is not an extglob. If the first pattern IS an extglob, then we need all
840
+ // that dot prevention biz to live in the extglob portions, because eg
841
+ // +(*|.x*) can match .xy but not .yx.
842
+ //
843
+ // So, return the two flavors if it's #root and the first child is not an
844
+ // AST, otherwise leave it to the child AST to handle it, and there,
845
+ // use the (?:^|/) style of start binding.
846
+ //
847
+ // Even simplified further:
848
+ // - Since the start for a join is eg /(?!\.) and the start for a part
849
+ // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
850
+ // or start or whatever) and prepend ^ or / at the Regexp construction.
851
+ toRegExpSource(allowDot) {
852
+ const dot = allowDot ?? !!this.#options.dot;
853
+ if (this.#root === this)
854
+ this.#fillNegs();
855
+ if (!this.type) {
856
+ const noEmpty = this.isStart() && this.isEnd();
857
+ const src = this.#parts
858
+ .map(p => {
859
+ const [re, _, hasMagic, uflag] = typeof p === 'string'
860
+ ? AST.#parseGlob(p, this.#hasMagic, noEmpty)
861
+ : p.toRegExpSource(allowDot);
862
+ this.#hasMagic = this.#hasMagic || hasMagic;
863
+ this.#uflag = this.#uflag || uflag;
864
+ return re;
865
+ })
866
+ .join('');
867
+ let start = '';
868
+ if (this.isStart()) {
869
+ if (typeof this.#parts[0] === 'string') {
870
+ // this is the string that will match the start of the pattern,
871
+ // so we need to protect against dots and such.
872
+ // '.' and '..' cannot match unless the pattern is that exactly,
873
+ // even if it starts with . or dot:true is set.
874
+ const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
875
+ if (!dotTravAllowed) {
876
+ const aps = addPatternStart;
877
+ // check if we have a possibility of matching . or ..,
878
+ // and prevent that.
879
+ const needNoTrav =
880
+ // dots are allowed, and the pattern starts with [ or .
881
+ (dot && aps.has(src.charAt(0))) ||
882
+ // the pattern starts with \., and then [ or .
883
+ (src.startsWith('\\.') && aps.has(src.charAt(2))) ||
884
+ // the pattern starts with \.\., and then [ or .
885
+ (src.startsWith('\\.\\.') && aps.has(src.charAt(4)));
886
+ // no need to prevent dots if it can't match a dot, or if a
887
+ // sub-pattern will be preventing it anyway.
888
+ const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
889
+ start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : '';
890
+ }
891
+ }
892
+ }
893
+ // append the "end of path portion" pattern to negation tails
894
+ let end = '';
895
+ if (this.isEnd() &&
896
+ this.#root.#filledNegs &&
897
+ this.#parent?.type === '!') {
898
+ end = '(?:$|\\/)';
899
+ }
900
+ const final = start + src + end;
901
+ return [
902
+ final,
903
+ (0, unescape_js_1.unescape)(src),
904
+ (this.#hasMagic = !!this.#hasMagic),
905
+ this.#uflag,
906
+ ];
907
+ }
908
+ // We need to calculate the body *twice* if it's a repeat pattern
909
+ // at the start, once in nodot mode, then again in dot mode, so a
910
+ // pattern like *(?) can match 'x.y'
911
+ const repeated = this.type === '*' || this.type === '+';
912
+ // some kind of extglob
913
+ const start = this.type === '!' ? '(?:(?!(?:' : '(?:';
914
+ let body = this.#partsToRegExp(dot);
915
+ if (this.isStart() && this.isEnd() && !body && this.type !== '!') {
916
+ // invalid extglob, has to at least be *something* present, if it's
917
+ // the entire path portion.
918
+ const s = this.toString();
919
+ this.#parts = [s];
920
+ this.type = null;
921
+ this.#hasMagic = undefined;
922
+ return [s, (0, unescape_js_1.unescape)(this.toString()), false, false];
923
+ }
924
+ // XXX abstract out this map method
925
+ let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot
926
+ ? ''
927
+ : this.#partsToRegExp(true);
928
+ if (bodyDotAllowed === body) {
929
+ bodyDotAllowed = '';
930
+ }
931
+ if (bodyDotAllowed) {
932
+ body = `(?:${body})(?:${bodyDotAllowed})*?`;
933
+ }
934
+ // an empty !() is exactly equivalent to a starNoEmpty
935
+ let final = '';
936
+ if (this.type === '!' && this.#emptyExt) {
937
+ final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty;
938
+ }
939
+ else {
940
+ const close = this.type === '!'
941
+ ? // !() must match something,but !(x) can match ''
942
+ '))' +
943
+ (this.isStart() && !dot && !allowDot ? startNoDot : '') +
944
+ star +
945
+ ')'
946
+ : this.type === '@'
947
+ ? ')'
948
+ : this.type === '?'
949
+ ? ')?'
950
+ : this.type === '+' && bodyDotAllowed
951
+ ? ')'
952
+ : this.type === '*' && bodyDotAllowed
953
+ ? `)?`
954
+ : `)${this.type}`;
955
+ final = start + body + close;
956
+ }
957
+ return [
958
+ final,
959
+ (0, unescape_js_1.unescape)(body),
960
+ (this.#hasMagic = !!this.#hasMagic),
961
+ this.#uflag,
962
+ ];
963
+ }
964
+ #partsToRegExp(dot) {
965
+ return this.#parts
966
+ .map(p => {
967
+ // extglob ASTs should only contain parent ASTs
968
+ /* c8 ignore start */
969
+ if (typeof p === 'string') {
970
+ throw new Error('string type in extglob ast??');
971
+ }
972
+ /* c8 ignore stop */
973
+ // can ignore hasMagic, because extglobs are already always magic
974
+ const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
975
+ this.#uflag = this.#uflag || uflag;
976
+ return re;
977
+ })
978
+ .filter(p => !(this.isStart() && this.isEnd()) || !!p)
979
+ .join('|');
980
+ }
981
+ static #parseGlob(glob, hasMagic, noEmpty = false) {
982
+ let escaping = false;
983
+ let re = '';
984
+ let uflag = false;
985
+ for (let i = 0; i < glob.length; i++) {
986
+ const c = glob.charAt(i);
987
+ if (escaping) {
988
+ escaping = false;
989
+ re += (reSpecials.has(c) ? '\\' : '') + c;
990
+ continue;
991
+ }
992
+ if (c === '\\') {
993
+ if (i === glob.length - 1) {
994
+ re += '\\\\';
995
+ }
996
+ else {
997
+ escaping = true;
998
+ }
999
+ continue;
1000
+ }
1001
+ if (c === '[') {
1002
+ const [src, needUflag, consumed, magic] = (0, brace_expressions_js_1.parseClass)(glob, i);
1003
+ if (consumed) {
1004
+ re += src;
1005
+ uflag = uflag || needUflag;
1006
+ i += consumed - 1;
1007
+ hasMagic = hasMagic || magic;
1008
+ continue;
1009
+ }
1010
+ }
1011
+ if (c === '*') {
1012
+ if (noEmpty && glob === '*')
1013
+ re += starNoEmpty;
1014
+ else
1015
+ re += star;
1016
+ hasMagic = true;
1017
+ continue;
1018
+ }
1019
+ if (c === '?') {
1020
+ re += qmark;
1021
+ hasMagic = true;
1022
+ continue;
1023
+ }
1024
+ re += regExpEscape(c);
1025
+ }
1026
+ return [re, (0, unescape_js_1.unescape)(glob), !!hasMagic, uflag];
1027
+ }
1028
+ }
1029
+ ast.AST = AST;
1030
+
1031
+ return ast;
1032
+ }
1033
+
1034
+ var _escape = {};
1035
+
1036
+ var hasRequired_escape;
1037
+
1038
+ function require_escape () {
1039
+ if (hasRequired_escape) return _escape;
1040
+ hasRequired_escape = 1;
1041
+ Object.defineProperty(_escape, "__esModule", { value: true });
1042
+ _escape.escape = void 0;
1043
+ /**
1044
+ * Escape all magic characters in a glob pattern.
1045
+ *
1046
+ * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
1047
+ * option is used, then characters are escaped by wrapping in `[]`, because
1048
+ * a magic character wrapped in a character class can only be satisfied by
1049
+ * that exact character. In this mode, `\` is _not_ escaped, because it is
1050
+ * not interpreted as a magic character, but instead as a path separator.
1051
+ */
1052
+ const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
1053
+ // don't need to escape +@! because we escape the parens
1054
+ // that make those magic, and escaping ! as [!] isn't valid,
1055
+ // because [!]] is a valid glob class meaning not ']'.
1056
+ return windowsPathsNoEscape
1057
+ ? s.replace(/[?*()[\]]/g, '[$&]')
1058
+ : s.replace(/[?*()[\]\\]/g, '\\$&');
1059
+ };
1060
+ _escape.escape = escape;
1061
+
1062
+ return _escape;
1063
+ }
1064
+
1065
+ var hasRequiredCommonjs;
1066
+
1067
+ function requireCommonjs () {
1068
+ if (hasRequiredCommonjs) return commonjs;
1069
+ hasRequiredCommonjs = 1;
1070
+ (function (exports) {
1071
+ var __importDefault = (commonjs && commonjs.__importDefault) || function (mod) {
1072
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1073
+ };
1074
+ Object.defineProperty(exports, "__esModule", { value: true });
1075
+ exports.unescape = exports.escape = exports.AST = exports.Minimatch = exports.match = exports.makeRe = exports.braceExpand = exports.defaults = exports.filter = exports.GLOBSTAR = exports.sep = exports.minimatch = void 0;
1076
+ const brace_expansion_1 = __importDefault(requireBraceExpansion());
1077
+ const assert_valid_pattern_js_1 = requireAssertValidPattern();
1078
+ const ast_js_1 = requireAst();
1079
+ const escape_js_1 = require_escape();
1080
+ const unescape_js_1 = require_unescape();
1081
+ const minimatch = (p, pattern, options = {}) => {
1082
+ (0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
1083
+ // shortcut: comments match nothing.
1084
+ if (!options.nocomment && pattern.charAt(0) === '#') {
1085
+ return false;
1086
+ }
1087
+ return new Minimatch(pattern, options).match(p);
1088
+ };
1089
+ exports.minimatch = minimatch;
1090
+ // Optimized checking for the most common glob patterns.
1091
+ const starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
1092
+ const starDotExtTest = (ext) => (f) => !f.startsWith('.') && f.endsWith(ext);
1093
+ const starDotExtTestDot = (ext) => (f) => f.endsWith(ext);
1094
+ const starDotExtTestNocase = (ext) => {
1095
+ ext = ext.toLowerCase();
1096
+ return (f) => !f.startsWith('.') && f.toLowerCase().endsWith(ext);
1097
+ };
1098
+ const starDotExtTestNocaseDot = (ext) => {
1099
+ ext = ext.toLowerCase();
1100
+ return (f) => f.toLowerCase().endsWith(ext);
1101
+ };
1102
+ const starDotStarRE = /^\*+\.\*+$/;
1103
+ const starDotStarTest = (f) => !f.startsWith('.') && f.includes('.');
1104
+ const starDotStarTestDot = (f) => f !== '.' && f !== '..' && f.includes('.');
1105
+ const dotStarRE = /^\.\*+$/;
1106
+ const dotStarTest = (f) => f !== '.' && f !== '..' && f.startsWith('.');
1107
+ const starRE = /^\*+$/;
1108
+ const starTest = (f) => f.length !== 0 && !f.startsWith('.');
1109
+ const starTestDot = (f) => f.length !== 0 && f !== '.' && f !== '..';
1110
+ const qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
1111
+ const qmarksTestNocase = ([$0, ext = '']) => {
1112
+ const noext = qmarksTestNoExt([$0]);
1113
+ if (!ext)
1114
+ return noext;
1115
+ ext = ext.toLowerCase();
1116
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext);
1117
+ };
1118
+ const qmarksTestNocaseDot = ([$0, ext = '']) => {
1119
+ const noext = qmarksTestNoExtDot([$0]);
1120
+ if (!ext)
1121
+ return noext;
1122
+ ext = ext.toLowerCase();
1123
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext);
1124
+ };
1125
+ const qmarksTestDot = ([$0, ext = '']) => {
1126
+ const noext = qmarksTestNoExtDot([$0]);
1127
+ return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
1128
+ };
1129
+ const qmarksTest = ([$0, ext = '']) => {
1130
+ const noext = qmarksTestNoExt([$0]);
1131
+ return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
1132
+ };
1133
+ const qmarksTestNoExt = ([$0]) => {
1134
+ const len = $0.length;
1135
+ return (f) => f.length === len && !f.startsWith('.');
1136
+ };
1137
+ const qmarksTestNoExtDot = ([$0]) => {
1138
+ const len = $0.length;
1139
+ return (f) => f.length === len && f !== '.' && f !== '..';
1140
+ };
1141
+ /* c8 ignore start */
1142
+ const defaultPlatform = (typeof process === 'object' && process
1143
+ ? (typeof process.env === 'object' &&
1144
+ process.env &&
1145
+ process.env.__MINIMATCH_TESTING_PLATFORM__) ||
1146
+ process.platform
1147
+ : 'posix');
1148
+ const path = {
1149
+ win32: { sep: '\\' },
1150
+ posix: { sep: '/' },
1151
+ };
1152
+ /* c8 ignore stop */
1153
+ exports.sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep;
1154
+ exports.minimatch.sep = exports.sep;
1155
+ exports.GLOBSTAR = Symbol('globstar **');
1156
+ exports.minimatch.GLOBSTAR = exports.GLOBSTAR;
1157
+ // any single thing other than /
1158
+ // don't need to escape / when using new RegExp()
1159
+ const qmark = '[^/]';
1160
+ // * => any number of characters
1161
+ const star = qmark + '*?';
1162
+ // ** when dots are allowed. Anything goes, except .. and .
1163
+ // not (^ or / followed by one or two dots followed by $ or /),
1164
+ // followed by anything, any number of times.
1165
+ const twoStarDot = '(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?';
1166
+ // not a ^ or / followed by a dot,
1167
+ // followed by anything, any number of times.
1168
+ const twoStarNoDot = '(?:(?!(?:\\/|^)\\.).)*?';
1169
+ const filter = (pattern, options = {}) => (p) => (0, exports.minimatch)(p, pattern, options);
1170
+ exports.filter = filter;
1171
+ exports.minimatch.filter = exports.filter;
1172
+ const ext = (a, b = {}) => Object.assign({}, a, b);
1173
+ const defaults = (def) => {
1174
+ if (!def || typeof def !== 'object' || !Object.keys(def).length) {
1175
+ return exports.minimatch;
1176
+ }
1177
+ const orig = exports.minimatch;
1178
+ const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
1179
+ return Object.assign(m, {
1180
+ Minimatch: class Minimatch extends orig.Minimatch {
1181
+ constructor(pattern, options = {}) {
1182
+ super(pattern, ext(def, options));
1183
+ }
1184
+ static defaults(options) {
1185
+ return orig.defaults(ext(def, options)).Minimatch;
1186
+ }
1187
+ },
1188
+ AST: class AST extends orig.AST {
1189
+ /* c8 ignore start */
1190
+ constructor(type, parent, options = {}) {
1191
+ super(type, parent, ext(def, options));
1192
+ }
1193
+ /* c8 ignore stop */
1194
+ static fromGlob(pattern, options = {}) {
1195
+ return orig.AST.fromGlob(pattern, ext(def, options));
1196
+ }
1197
+ },
1198
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
1199
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
1200
+ filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
1201
+ defaults: (options) => orig.defaults(ext(def, options)),
1202
+ makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
1203
+ braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
1204
+ match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
1205
+ sep: orig.sep,
1206
+ GLOBSTAR: exports.GLOBSTAR,
1207
+ });
1208
+ };
1209
+ exports.defaults = defaults;
1210
+ exports.minimatch.defaults = exports.defaults;
1211
+ // Brace expansion:
1212
+ // a{b,c}d -> abd acd
1213
+ // a{b,}c -> abc ac
1214
+ // a{0..3}d -> a0d a1d a2d a3d
1215
+ // a{b,c{d,e}f}g -> abg acdfg acefg
1216
+ // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
1217
+ //
1218
+ // Invalid sets are not expanded.
1219
+ // a{2..}b -> a{2..}b
1220
+ // a{b}c -> a{b}c
1221
+ const braceExpand = (pattern, options = {}) => {
1222
+ (0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
1223
+ // Thanks to Yeting Li <https://github.com/yetingli> for
1224
+ // improving this regexp to avoid a ReDOS vulnerability.
1225
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
1226
+ // shortcut. no need to expand.
1227
+ return [pattern];
1228
+ }
1229
+ return (0, brace_expansion_1.default)(pattern);
1230
+ };
1231
+ exports.braceExpand = braceExpand;
1232
+ exports.minimatch.braceExpand = exports.braceExpand;
1233
+ // parse a component of the expanded set.
1234
+ // At this point, no pattern may contain "/" in it
1235
+ // so we're going to return a 2d array, where each entry is the full
1236
+ // pattern, split on '/', and then turned into a regular expression.
1237
+ // A regexp is made at the end which joins each array with an
1238
+ // escaped /, and another full one which joins each regexp with |.
1239
+ //
1240
+ // Following the lead of Bash 4.1, note that "**" only has special meaning
1241
+ // when it is the *only* thing in a path portion. Otherwise, any series
1242
+ // of * is equivalent to a single *. Globstar behavior is enabled by
1243
+ // default, and can be disabled by setting options.noglobstar.
1244
+ const makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
1245
+ exports.makeRe = makeRe;
1246
+ exports.minimatch.makeRe = exports.makeRe;
1247
+ const match = (list, pattern, options = {}) => {
1248
+ const mm = new Minimatch(pattern, options);
1249
+ list = list.filter(f => mm.match(f));
1250
+ if (mm.options.nonull && !list.length) {
1251
+ list.push(pattern);
1252
+ }
1253
+ return list;
1254
+ };
1255
+ exports.match = match;
1256
+ exports.minimatch.match = exports.match;
1257
+ // replace stuff like \* with *
1258
+ const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
1259
+ const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
1260
+ class Minimatch {
1261
+ options;
1262
+ set;
1263
+ pattern;
1264
+ windowsPathsNoEscape;
1265
+ nonegate;
1266
+ negate;
1267
+ comment;
1268
+ empty;
1269
+ preserveMultipleSlashes;
1270
+ partial;
1271
+ globSet;
1272
+ globParts;
1273
+ nocase;
1274
+ isWindows;
1275
+ platform;
1276
+ windowsNoMagicRoot;
1277
+ regexp;
1278
+ constructor(pattern, options = {}) {
1279
+ (0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
1280
+ options = options || {};
1281
+ this.options = options;
1282
+ this.pattern = pattern;
1283
+ this.platform = options.platform || defaultPlatform;
1284
+ this.isWindows = this.platform === 'win32';
1285
+ this.windowsPathsNoEscape =
1286
+ !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
1287
+ if (this.windowsPathsNoEscape) {
1288
+ this.pattern = this.pattern.replace(/\\/g, '/');
1289
+ }
1290
+ this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
1291
+ this.regexp = null;
1292
+ this.negate = false;
1293
+ this.nonegate = !!options.nonegate;
1294
+ this.comment = false;
1295
+ this.empty = false;
1296
+ this.partial = !!options.partial;
1297
+ this.nocase = !!this.options.nocase;
1298
+ this.windowsNoMagicRoot =
1299
+ options.windowsNoMagicRoot !== undefined
1300
+ ? options.windowsNoMagicRoot
1301
+ : !!(this.isWindows && this.nocase);
1302
+ this.globSet = [];
1303
+ this.globParts = [];
1304
+ this.set = [];
1305
+ // make the set of regexps etc.
1306
+ this.make();
1307
+ }
1308
+ hasMagic() {
1309
+ if (this.options.magicalBraces && this.set.length > 1) {
1310
+ return true;
1311
+ }
1312
+ for (const pattern of this.set) {
1313
+ for (const part of pattern) {
1314
+ if (typeof part !== 'string')
1315
+ return true;
1316
+ }
1317
+ }
1318
+ return false;
1319
+ }
1320
+ debug(..._) { }
1321
+ make() {
1322
+ const pattern = this.pattern;
1323
+ const options = this.options;
1324
+ // empty patterns and comments match nothing.
1325
+ if (!options.nocomment && pattern.charAt(0) === '#') {
1326
+ this.comment = true;
1327
+ return;
1328
+ }
1329
+ if (!pattern) {
1330
+ this.empty = true;
1331
+ return;
1332
+ }
1333
+ // step 1: figure out negation, etc.
1334
+ this.parseNegate();
1335
+ // step 2: expand braces
1336
+ this.globSet = [...new Set(this.braceExpand())];
1337
+ if (options.debug) {
1338
+ this.debug = (...args) => console.error(...args);
1339
+ }
1340
+ this.debug(this.pattern, this.globSet);
1341
+ // step 3: now we have a set, so turn each one into a series of
1342
+ // path-portion matching patterns.
1343
+ // These will be regexps, except in the case of "**", which is
1344
+ // set to the GLOBSTAR object for globstar behavior,
1345
+ // and will not contain any / characters
1346
+ //
1347
+ // First, we preprocess to make the glob pattern sets a bit simpler
1348
+ // and deduped. There are some perf-killing patterns that can cause
1349
+ // problems with a glob walk, but we can simplify them down a bit.
1350
+ const rawGlobParts = this.globSet.map(s => this.slashSplit(s));
1351
+ this.globParts = this.preprocess(rawGlobParts);
1352
+ this.debug(this.pattern, this.globParts);
1353
+ // glob --> regexps
1354
+ let set = this.globParts.map((s, _, __) => {
1355
+ if (this.isWindows && this.windowsNoMagicRoot) {
1356
+ // check if it's a drive or unc path.
1357
+ const isUNC = s[0] === '' &&
1358
+ s[1] === '' &&
1359
+ (s[2] === '?' || !globMagic.test(s[2])) &&
1360
+ !globMagic.test(s[3]);
1361
+ const isDrive = /^[a-z]:/i.test(s[0]);
1362
+ if (isUNC) {
1363
+ return [...s.slice(0, 4), ...s.slice(4).map(ss => this.parse(ss))];
1364
+ }
1365
+ else if (isDrive) {
1366
+ return [s[0], ...s.slice(1).map(ss => this.parse(ss))];
1367
+ }
1368
+ }
1369
+ return s.map(ss => this.parse(ss));
1370
+ });
1371
+ this.debug(this.pattern, set);
1372
+ // filter out everything that didn't compile properly.
1373
+ this.set = set.filter(s => s.indexOf(false) === -1);
1374
+ // do not treat the ? in UNC paths as magic
1375
+ if (this.isWindows) {
1376
+ for (let i = 0; i < this.set.length; i++) {
1377
+ const p = this.set[i];
1378
+ if (p[0] === '' &&
1379
+ p[1] === '' &&
1380
+ this.globParts[i][2] === '?' &&
1381
+ typeof p[3] === 'string' &&
1382
+ /^[a-z]:$/i.test(p[3])) {
1383
+ p[2] = '?';
1384
+ }
1385
+ }
1386
+ }
1387
+ this.debug(this.pattern, this.set);
1388
+ }
1389
+ // various transforms to equivalent pattern sets that are
1390
+ // faster to process in a filesystem walk. The goal is to
1391
+ // eliminate what we can, and push all ** patterns as far
1392
+ // to the right as possible, even if it increases the number
1393
+ // of patterns that we have to process.
1394
+ preprocess(globParts) {
1395
+ // if we're not in globstar mode, then turn all ** into *
1396
+ if (this.options.noglobstar) {
1397
+ for (let i = 0; i < globParts.length; i++) {
1398
+ for (let j = 0; j < globParts[i].length; j++) {
1399
+ if (globParts[i][j] === '**') {
1400
+ globParts[i][j] = '*';
1401
+ }
1402
+ }
1403
+ }
1404
+ }
1405
+ const { optimizationLevel = 1 } = this.options;
1406
+ if (optimizationLevel >= 2) {
1407
+ // aggressive optimization for the purpose of fs walking
1408
+ globParts = this.firstPhasePreProcess(globParts);
1409
+ globParts = this.secondPhasePreProcess(globParts);
1410
+ }
1411
+ else if (optimizationLevel >= 1) {
1412
+ // just basic optimizations to remove some .. parts
1413
+ globParts = this.levelOneOptimize(globParts);
1414
+ }
1415
+ else {
1416
+ // just collapse multiple ** portions into one
1417
+ globParts = this.adjascentGlobstarOptimize(globParts);
1418
+ }
1419
+ return globParts;
1420
+ }
1421
+ // just get rid of adjascent ** portions
1422
+ adjascentGlobstarOptimize(globParts) {
1423
+ return globParts.map(parts => {
1424
+ let gs = -1;
1425
+ while (-1 !== (gs = parts.indexOf('**', gs + 1))) {
1426
+ let i = gs;
1427
+ while (parts[i + 1] === '**') {
1428
+ i++;
1429
+ }
1430
+ if (i !== gs) {
1431
+ parts.splice(gs, i - gs);
1432
+ }
1433
+ }
1434
+ return parts;
1435
+ });
1436
+ }
1437
+ // get rid of adjascent ** and resolve .. portions
1438
+ levelOneOptimize(globParts) {
1439
+ return globParts.map(parts => {
1440
+ parts = parts.reduce((set, part) => {
1441
+ const prev = set[set.length - 1];
1442
+ if (part === '**' && prev === '**') {
1443
+ return set;
1444
+ }
1445
+ if (part === '..') {
1446
+ if (prev && prev !== '..' && prev !== '.' && prev !== '**') {
1447
+ set.pop();
1448
+ return set;
1449
+ }
1450
+ }
1451
+ set.push(part);
1452
+ return set;
1453
+ }, []);
1454
+ return parts.length === 0 ? [''] : parts;
1455
+ });
1456
+ }
1457
+ levelTwoFileOptimize(parts) {
1458
+ if (!Array.isArray(parts)) {
1459
+ parts = this.slashSplit(parts);
1460
+ }
1461
+ let didSomething = false;
1462
+ do {
1463
+ didSomething = false;
1464
+ // <pre>/<e>/<rest> -> <pre>/<rest>
1465
+ if (!this.preserveMultipleSlashes) {
1466
+ for (let i = 1; i < parts.length - 1; i++) {
1467
+ const p = parts[i];
1468
+ // don't squeeze out UNC patterns
1469
+ if (i === 1 && p === '' && parts[0] === '')
1470
+ continue;
1471
+ if (p === '.' || p === '') {
1472
+ didSomething = true;
1473
+ parts.splice(i, 1);
1474
+ i--;
1475
+ }
1476
+ }
1477
+ if (parts[0] === '.' &&
1478
+ parts.length === 2 &&
1479
+ (parts[1] === '.' || parts[1] === '')) {
1480
+ didSomething = true;
1481
+ parts.pop();
1482
+ }
1483
+ }
1484
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
1485
+ let dd = 0;
1486
+ while (-1 !== (dd = parts.indexOf('..', dd + 1))) {
1487
+ const p = parts[dd - 1];
1488
+ if (p && p !== '.' && p !== '..' && p !== '**') {
1489
+ didSomething = true;
1490
+ parts.splice(dd - 1, 2);
1491
+ dd -= 2;
1492
+ }
1493
+ }
1494
+ } while (didSomething);
1495
+ return parts.length === 0 ? [''] : parts;
1496
+ }
1497
+ // First phase: single-pattern processing
1498
+ // <pre> is 1 or more portions
1499
+ // <rest> is 1 or more portions
1500
+ // <p> is any portion other than ., .., '', or **
1501
+ // <e> is . or ''
1502
+ //
1503
+ // **/.. is *brutal* for filesystem walking performance, because
1504
+ // it effectively resets the recursive walk each time it occurs,
1505
+ // and ** cannot be reduced out by a .. pattern part like a regexp
1506
+ // or most strings (other than .., ., and '') can be.
1507
+ //
1508
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
1509
+ // <pre>/<e>/<rest> -> <pre>/<rest>
1510
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
1511
+ // **/**/<rest> -> **/<rest>
1512
+ //
1513
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
1514
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
1515
+ firstPhasePreProcess(globParts) {
1516
+ let didSomething = false;
1517
+ do {
1518
+ didSomething = false;
1519
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
1520
+ for (let parts of globParts) {
1521
+ let gs = -1;
1522
+ while (-1 !== (gs = parts.indexOf('**', gs + 1))) {
1523
+ let gss = gs;
1524
+ while (parts[gss + 1] === '**') {
1525
+ // <pre>/**/**/<rest> -> <pre>/**/<rest>
1526
+ gss++;
1527
+ }
1528
+ // eg, if gs is 2 and gss is 4, that means we have 3 **
1529
+ // parts, and can remove 2 of them.
1530
+ if (gss > gs) {
1531
+ parts.splice(gs + 1, gss - gs);
1532
+ }
1533
+ let next = parts[gs + 1];
1534
+ const p = parts[gs + 2];
1535
+ const p2 = parts[gs + 3];
1536
+ if (next !== '..')
1537
+ continue;
1538
+ if (!p ||
1539
+ p === '.' ||
1540
+ p === '..' ||
1541
+ !p2 ||
1542
+ p2 === '.' ||
1543
+ p2 === '..') {
1544
+ continue;
1545
+ }
1546
+ didSomething = true;
1547
+ // edit parts in place, and push the new one
1548
+ parts.splice(gs, 1);
1549
+ const other = parts.slice(0);
1550
+ other[gs] = '**';
1551
+ globParts.push(other);
1552
+ gs--;
1553
+ }
1554
+ // <pre>/<e>/<rest> -> <pre>/<rest>
1555
+ if (!this.preserveMultipleSlashes) {
1556
+ for (let i = 1; i < parts.length - 1; i++) {
1557
+ const p = parts[i];
1558
+ // don't squeeze out UNC patterns
1559
+ if (i === 1 && p === '' && parts[0] === '')
1560
+ continue;
1561
+ if (p === '.' || p === '') {
1562
+ didSomething = true;
1563
+ parts.splice(i, 1);
1564
+ i--;
1565
+ }
1566
+ }
1567
+ if (parts[0] === '.' &&
1568
+ parts.length === 2 &&
1569
+ (parts[1] === '.' || parts[1] === '')) {
1570
+ didSomething = true;
1571
+ parts.pop();
1572
+ }
1573
+ }
1574
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
1575
+ let dd = 0;
1576
+ while (-1 !== (dd = parts.indexOf('..', dd + 1))) {
1577
+ const p = parts[dd - 1];
1578
+ if (p && p !== '.' && p !== '..' && p !== '**') {
1579
+ didSomething = true;
1580
+ const needDot = dd === 1 && parts[dd + 1] === '**';
1581
+ const splin = needDot ? ['.'] : [];
1582
+ parts.splice(dd - 1, 2, ...splin);
1583
+ if (parts.length === 0)
1584
+ parts.push('');
1585
+ dd -= 2;
1586
+ }
1587
+ }
1588
+ }
1589
+ } while (didSomething);
1590
+ return globParts;
1591
+ }
1592
+ // second phase: multi-pattern dedupes
1593
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
1594
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
1595
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
1596
+ //
1597
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
1598
+ // ^-- not valid because ** doens't follow symlinks
1599
+ secondPhasePreProcess(globParts) {
1600
+ for (let i = 0; i < globParts.length - 1; i++) {
1601
+ for (let j = i + 1; j < globParts.length; j++) {
1602
+ const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
1603
+ if (matched) {
1604
+ globParts[i] = [];
1605
+ globParts[j] = matched;
1606
+ break;
1607
+ }
1608
+ }
1609
+ }
1610
+ return globParts.filter(gs => gs.length);
1611
+ }
1612
+ partsMatch(a, b, emptyGSMatch = false) {
1613
+ let ai = 0;
1614
+ let bi = 0;
1615
+ let result = [];
1616
+ let which = '';
1617
+ while (ai < a.length && bi < b.length) {
1618
+ if (a[ai] === b[bi]) {
1619
+ result.push(which === 'b' ? b[bi] : a[ai]);
1620
+ ai++;
1621
+ bi++;
1622
+ }
1623
+ else if (emptyGSMatch && a[ai] === '**' && b[bi] === a[ai + 1]) {
1624
+ result.push(a[ai]);
1625
+ ai++;
1626
+ }
1627
+ else if (emptyGSMatch && b[bi] === '**' && a[ai] === b[bi + 1]) {
1628
+ result.push(b[bi]);
1629
+ bi++;
1630
+ }
1631
+ else if (a[ai] === '*' &&
1632
+ b[bi] &&
1633
+ (this.options.dot || !b[bi].startsWith('.')) &&
1634
+ b[bi] !== '**') {
1635
+ if (which === 'b')
1636
+ return false;
1637
+ which = 'a';
1638
+ result.push(a[ai]);
1639
+ ai++;
1640
+ bi++;
1641
+ }
1642
+ else if (b[bi] === '*' &&
1643
+ a[ai] &&
1644
+ (this.options.dot || !a[ai].startsWith('.')) &&
1645
+ a[ai] !== '**') {
1646
+ if (which === 'a')
1647
+ return false;
1648
+ which = 'b';
1649
+ result.push(b[bi]);
1650
+ ai++;
1651
+ bi++;
1652
+ }
1653
+ else {
1654
+ return false;
1655
+ }
1656
+ }
1657
+ // if we fall out of the loop, it means they two are identical
1658
+ // as long as their lengths match
1659
+ return a.length === b.length && result;
1660
+ }
1661
+ parseNegate() {
1662
+ if (this.nonegate)
1663
+ return;
1664
+ const pattern = this.pattern;
1665
+ let negate = false;
1666
+ let negateOffset = 0;
1667
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === '!'; i++) {
1668
+ negate = !negate;
1669
+ negateOffset++;
1670
+ }
1671
+ if (negateOffset)
1672
+ this.pattern = pattern.slice(negateOffset);
1673
+ this.negate = negate;
1674
+ }
1675
+ // set partial to true to test if, for example,
1676
+ // "/a/b" matches the start of "/*/b/*/d"
1677
+ // Partial means, if you run out of file before you run
1678
+ // out of pattern, then that's fine, as long as all
1679
+ // the parts match.
1680
+ matchOne(file, pattern, partial = false) {
1681
+ const options = this.options;
1682
+ // UNC paths like //?/X:/... can match X:/... and vice versa
1683
+ // Drive letters in absolute drive or unc paths are always compared
1684
+ // case-insensitively.
1685
+ if (this.isWindows) {
1686
+ const fileDrive = typeof file[0] === 'string' && /^[a-z]:$/i.test(file[0]);
1687
+ const fileUNC = !fileDrive &&
1688
+ file[0] === '' &&
1689
+ file[1] === '' &&
1690
+ file[2] === '?' &&
1691
+ /^[a-z]:$/i.test(file[3]);
1692
+ const patternDrive = typeof pattern[0] === 'string' && /^[a-z]:$/i.test(pattern[0]);
1693
+ const patternUNC = !patternDrive &&
1694
+ pattern[0] === '' &&
1695
+ pattern[1] === '' &&
1696
+ pattern[2] === '?' &&
1697
+ typeof pattern[3] === 'string' &&
1698
+ /^[a-z]:$/i.test(pattern[3]);
1699
+ const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined;
1700
+ const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined;
1701
+ if (typeof fdi === 'number' && typeof pdi === 'number') {
1702
+ const [fd, pd] = [file[fdi], pattern[pdi]];
1703
+ if (fd.toLowerCase() === pd.toLowerCase()) {
1704
+ pattern[pdi] = fd;
1705
+ if (pdi > fdi) {
1706
+ pattern = pattern.slice(pdi);
1707
+ }
1708
+ else if (fdi > pdi) {
1709
+ file = file.slice(fdi);
1710
+ }
1711
+ }
1712
+ }
1713
+ }
1714
+ // resolve and reduce . and .. portions in the file as well.
1715
+ // dont' need to do the second phase, because it's only one string[]
1716
+ const { optimizationLevel = 1 } = this.options;
1717
+ if (optimizationLevel >= 2) {
1718
+ file = this.levelTwoFileOptimize(file);
1719
+ }
1720
+ this.debug('matchOne', this, { file, pattern });
1721
+ this.debug('matchOne', file.length, pattern.length);
1722
+ for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
1723
+ this.debug('matchOne loop');
1724
+ var p = pattern[pi];
1725
+ var f = file[fi];
1726
+ this.debug(pattern, p, f);
1727
+ // should be impossible.
1728
+ // some invalid regexp stuff in the set.
1729
+ /* c8 ignore start */
1730
+ if (p === false) {
1731
+ return false;
1732
+ }
1733
+ /* c8 ignore stop */
1734
+ if (p === exports.GLOBSTAR) {
1735
+ this.debug('GLOBSTAR', [pattern, p, f]);
1736
+ // "**"
1737
+ // a/**/b/**/c would match the following:
1738
+ // a/b/x/y/z/c
1739
+ // a/x/y/z/b/c
1740
+ // a/b/x/b/x/c
1741
+ // a/b/c
1742
+ // To do this, take the rest of the pattern after
1743
+ // the **, and see if it would match the file remainder.
1744
+ // If so, return success.
1745
+ // If not, the ** "swallows" a segment, and try again.
1746
+ // This is recursively awful.
1747
+ //
1748
+ // a/**/b/**/c matching a/b/x/y/z/c
1749
+ // - a matches a
1750
+ // - doublestar
1751
+ // - matchOne(b/x/y/z/c, b/**/c)
1752
+ // - b matches b
1753
+ // - doublestar
1754
+ // - matchOne(x/y/z/c, c) -> no
1755
+ // - matchOne(y/z/c, c) -> no
1756
+ // - matchOne(z/c, c) -> no
1757
+ // - matchOne(c, c) yes, hit
1758
+ var fr = fi;
1759
+ var pr = pi + 1;
1760
+ if (pr === pl) {
1761
+ this.debug('** at the end');
1762
+ // a ** at the end will just swallow the rest.
1763
+ // We have found a match.
1764
+ // however, it will not swallow /.x, unless
1765
+ // options.dot is set.
1766
+ // . and .. are *never* matched by **, for explosively
1767
+ // exponential reasons.
1768
+ for (; fi < fl; fi++) {
1769
+ if (file[fi] === '.' ||
1770
+ file[fi] === '..' ||
1771
+ (!options.dot && file[fi].charAt(0) === '.'))
1772
+ return false;
1773
+ }
1774
+ return true;
1775
+ }
1776
+ // ok, let's see if we can swallow whatever we can.
1777
+ while (fr < fl) {
1778
+ var swallowee = file[fr];
1779
+ this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
1780
+ // XXX remove this slice. Just pass the start index.
1781
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
1782
+ this.debug('globstar found match!', fr, fl, swallowee);
1783
+ // found a match.
1784
+ return true;
1785
+ }
1786
+ else {
1787
+ // can't swallow "." or ".." ever.
1788
+ // can only swallow ".foo" when explicitly asked.
1789
+ if (swallowee === '.' ||
1790
+ swallowee === '..' ||
1791
+ (!options.dot && swallowee.charAt(0) === '.')) {
1792
+ this.debug('dot detected!', file, fr, pattern, pr);
1793
+ break;
1794
+ }
1795
+ // ** swallows a segment, and continue.
1796
+ this.debug('globstar swallow a segment, and continue');
1797
+ fr++;
1798
+ }
1799
+ }
1800
+ // no match was found.
1801
+ // However, in partial mode, we can't say this is necessarily over.
1802
+ /* c8 ignore start */
1803
+ if (partial) {
1804
+ // ran out of file
1805
+ this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
1806
+ if (fr === fl) {
1807
+ return true;
1808
+ }
1809
+ }
1810
+ /* c8 ignore stop */
1811
+ return false;
1812
+ }
1813
+ // something other than **
1814
+ // non-magic patterns just have to match exactly
1815
+ // patterns with magic have been turned into regexps.
1816
+ let hit;
1817
+ if (typeof p === 'string') {
1818
+ hit = f === p;
1819
+ this.debug('string match', p, f, hit);
1820
+ }
1821
+ else {
1822
+ hit = p.test(f);
1823
+ this.debug('pattern match', p, f, hit);
1824
+ }
1825
+ if (!hit)
1826
+ return false;
1827
+ }
1828
+ // Note: ending in / means that we'll get a final ""
1829
+ // at the end of the pattern. This can only match a
1830
+ // corresponding "" at the end of the file.
1831
+ // If the file ends in /, then it can only match a
1832
+ // a pattern that ends in /, unless the pattern just
1833
+ // doesn't have any more for it. But, a/b/ should *not*
1834
+ // match "a/b/*", even though "" matches against the
1835
+ // [^/]*? pattern, except in partial mode, where it might
1836
+ // simply not be reached yet.
1837
+ // However, a/b/ should still satisfy a/*
1838
+ // now either we fell off the end of the pattern, or we're done.
1839
+ if (fi === fl && pi === pl) {
1840
+ // ran out of pattern and filename at the same time.
1841
+ // an exact hit!
1842
+ return true;
1843
+ }
1844
+ else if (fi === fl) {
1845
+ // ran out of file, but still had pattern left.
1846
+ // this is ok if we're doing the match as part of
1847
+ // a glob fs traversal.
1848
+ return partial;
1849
+ }
1850
+ else if (pi === pl) {
1851
+ // ran out of pattern, still have file left.
1852
+ // this is only acceptable if we're on the very last
1853
+ // empty segment of a file with a trailing slash.
1854
+ // a/* should match a/b/
1855
+ return fi === fl - 1 && file[fi] === '';
1856
+ /* c8 ignore start */
1857
+ }
1858
+ else {
1859
+ // should be unreachable.
1860
+ throw new Error('wtf?');
1861
+ }
1862
+ /* c8 ignore stop */
1863
+ }
1864
+ braceExpand() {
1865
+ return (0, exports.braceExpand)(this.pattern, this.options);
1866
+ }
1867
+ parse(pattern) {
1868
+ (0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
1869
+ const options = this.options;
1870
+ // shortcuts
1871
+ if (pattern === '**')
1872
+ return exports.GLOBSTAR;
1873
+ if (pattern === '')
1874
+ return '';
1875
+ // far and away, the most common glob pattern parts are
1876
+ // *, *.*, and *.<ext> Add a fast check method for those.
1877
+ let m;
1878
+ let fastTest = null;
1879
+ if ((m = pattern.match(starRE))) {
1880
+ fastTest = options.dot ? starTestDot : starTest;
1881
+ }
1882
+ else if ((m = pattern.match(starDotExtRE))) {
1883
+ fastTest = (options.nocase
1884
+ ? options.dot
1885
+ ? starDotExtTestNocaseDot
1886
+ : starDotExtTestNocase
1887
+ : options.dot
1888
+ ? starDotExtTestDot
1889
+ : starDotExtTest)(m[1]);
1890
+ }
1891
+ else if ((m = pattern.match(qmarksRE))) {
1892
+ fastTest = (options.nocase
1893
+ ? options.dot
1894
+ ? qmarksTestNocaseDot
1895
+ : qmarksTestNocase
1896
+ : options.dot
1897
+ ? qmarksTestDot
1898
+ : qmarksTest)(m);
1899
+ }
1900
+ else if ((m = pattern.match(starDotStarRE))) {
1901
+ fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
1902
+ }
1903
+ else if ((m = pattern.match(dotStarRE))) {
1904
+ fastTest = dotStarTest;
1905
+ }
1906
+ const re = ast_js_1.AST.fromGlob(pattern, this.options).toMMPattern();
1907
+ if (fastTest && typeof re === 'object') {
1908
+ // Avoids overriding in frozen environments
1909
+ Reflect.defineProperty(re, 'test', { value: fastTest });
1910
+ }
1911
+ return re;
1912
+ }
1913
+ makeRe() {
1914
+ if (this.regexp || this.regexp === false)
1915
+ return this.regexp;
1916
+ // at this point, this.set is a 2d array of partial
1917
+ // pattern strings, or "**".
1918
+ //
1919
+ // It's better to use .match(). This function shouldn't
1920
+ // be used, really, but it's pretty convenient sometimes,
1921
+ // when you just want to work with a regex.
1922
+ const set = this.set;
1923
+ if (!set.length) {
1924
+ this.regexp = false;
1925
+ return this.regexp;
1926
+ }
1927
+ const options = this.options;
1928
+ const twoStar = options.noglobstar
1929
+ ? star
1930
+ : options.dot
1931
+ ? twoStarDot
1932
+ : twoStarNoDot;
1933
+ const flags = new Set(options.nocase ? ['i'] : []);
1934
+ // regexpify non-globstar patterns
1935
+ // if ** is only item, then we just do one twoStar
1936
+ // if ** is first, and there are more, prepend (\/|twoStar\/)? to next
1937
+ // if ** is last, append (\/twoStar|) to previous
1938
+ // if ** is in the middle, append (\/|\/twoStar\/) to previous
1939
+ // then filter out GLOBSTAR symbols
1940
+ let re = set
1941
+ .map(pattern => {
1942
+ const pp = pattern.map(p => {
1943
+ if (p instanceof RegExp) {
1944
+ for (const f of p.flags.split(''))
1945
+ flags.add(f);
1946
+ }
1947
+ return typeof p === 'string'
1948
+ ? regExpEscape(p)
1949
+ : p === exports.GLOBSTAR
1950
+ ? exports.GLOBSTAR
1951
+ : p._src;
1952
+ });
1953
+ pp.forEach((p, i) => {
1954
+ const next = pp[i + 1];
1955
+ const prev = pp[i - 1];
1956
+ if (p !== exports.GLOBSTAR || prev === exports.GLOBSTAR) {
1957
+ return;
1958
+ }
1959
+ if (prev === undefined) {
1960
+ if (next !== undefined && next !== exports.GLOBSTAR) {
1961
+ pp[i + 1] = '(?:\\/|' + twoStar + '\\/)?' + next;
1962
+ }
1963
+ else {
1964
+ pp[i] = twoStar;
1965
+ }
1966
+ }
1967
+ else if (next === undefined) {
1968
+ pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?';
1969
+ }
1970
+ else if (next !== exports.GLOBSTAR) {
1971
+ pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next;
1972
+ pp[i + 1] = exports.GLOBSTAR;
1973
+ }
1974
+ });
1975
+ return pp.filter(p => p !== exports.GLOBSTAR).join('/');
1976
+ })
1977
+ .join('|');
1978
+ // need to wrap in parens if we had more than one thing with |,
1979
+ // otherwise only the first will be anchored to ^ and the last to $
1980
+ const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', ''];
1981
+ // must match entire pattern
1982
+ // ending in a * or ** will make it less strict.
1983
+ re = '^' + open + re + close + '$';
1984
+ // can match anything, as long as it's not this.
1985
+ if (this.negate)
1986
+ re = '^(?!' + re + ').+$';
1987
+ try {
1988
+ this.regexp = new RegExp(re, [...flags].join(''));
1989
+ /* c8 ignore start */
1990
+ }
1991
+ catch (ex) {
1992
+ // should be impossible
1993
+ this.regexp = false;
1994
+ }
1995
+ /* c8 ignore stop */
1996
+ return this.regexp;
1997
+ }
1998
+ slashSplit(p) {
1999
+ // if p starts with // on windows, we preserve that
2000
+ // so that UNC paths aren't broken. Otherwise, any number of
2001
+ // / characters are coalesced into one, unless
2002
+ // preserveMultipleSlashes is set to true.
2003
+ if (this.preserveMultipleSlashes) {
2004
+ return p.split('/');
2005
+ }
2006
+ else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
2007
+ // add an extra '' for the one we lose
2008
+ return ['', ...p.split(/\/+/)];
2009
+ }
2010
+ else {
2011
+ return p.split(/\/+/);
2012
+ }
2013
+ }
2014
+ match(f, partial = this.partial) {
2015
+ this.debug('match', f, this.pattern);
2016
+ // short-circuit in the case of busted things.
2017
+ // comments, etc.
2018
+ if (this.comment) {
2019
+ return false;
2020
+ }
2021
+ if (this.empty) {
2022
+ return f === '';
2023
+ }
2024
+ if (f === '/' && partial) {
2025
+ return true;
2026
+ }
2027
+ const options = this.options;
2028
+ // windows: need to use /, not \
2029
+ if (this.isWindows) {
2030
+ f = f.split('\\').join('/');
2031
+ }
2032
+ // treat the test path as a set of pathparts.
2033
+ const ff = this.slashSplit(f);
2034
+ this.debug(this.pattern, 'split', ff);
2035
+ // just ONE of the pattern sets in this.set needs to match
2036
+ // in order for it to be valid. If negating, then just one
2037
+ // match means that we have failed.
2038
+ // Either way, return on the first hit.
2039
+ const set = this.set;
2040
+ this.debug(this.pattern, 'set', set);
2041
+ // Find the basename of the path by looking for the last non-empty segment
2042
+ let filename = ff[ff.length - 1];
2043
+ if (!filename) {
2044
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
2045
+ filename = ff[i];
2046
+ }
2047
+ }
2048
+ for (let i = 0; i < set.length; i++) {
2049
+ const pattern = set[i];
2050
+ let file = ff;
2051
+ if (options.matchBase && pattern.length === 1) {
2052
+ file = [filename];
2053
+ }
2054
+ const hit = this.matchOne(file, pattern, partial);
2055
+ if (hit) {
2056
+ if (options.flipNegate) {
2057
+ return true;
2058
+ }
2059
+ return !this.negate;
2060
+ }
2061
+ }
2062
+ // didn't get any hits. this is success if it's a negative
2063
+ // pattern, failure otherwise.
2064
+ if (options.flipNegate) {
2065
+ return false;
2066
+ }
2067
+ return this.negate;
2068
+ }
2069
+ static defaults(def) {
2070
+ return exports.minimatch.defaults(def).Minimatch;
2071
+ }
2072
+ }
2073
+ exports.Minimatch = Minimatch;
2074
+ /* c8 ignore start */
2075
+ var ast_js_2 = requireAst();
2076
+ Object.defineProperty(exports, "AST", { enumerable: true, get: function () { return ast_js_2.AST; } });
2077
+ var escape_js_2 = require_escape();
2078
+ Object.defineProperty(exports, "escape", { enumerable: true, get: function () { return escape_js_2.escape; } });
2079
+ var unescape_js_2 = require_unescape();
2080
+ Object.defineProperty(exports, "unescape", { enumerable: true, get: function () { return unescape_js_2.unescape; } });
2081
+ /* c8 ignore stop */
2082
+ exports.minimatch.AST = ast_js_1.AST;
2083
+ exports.minimatch.Minimatch = Minimatch;
2084
+ exports.minimatch.escape = escape_js_1.escape;
2085
+ exports.minimatch.unescape = unescape_js_1.unescape;
2086
+
2087
+ } (commonjs));
2088
+ return commonjs;
2089
+ }
2090
+
2091
+ export { requireCommonjs as r };