jiek 2.0.2-alpha.5 → 2.0.2-alpha.7

Sign up to get free protection for your applications and to get access to all the features.
package/cli.js ADDED
@@ -0,0 +1,4685 @@
1
+ import * as childProcess from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import path, { isAbsolute, relative, resolve } from 'node:path';
4
+ import { TAGS, bump } from '@jiek/utils/bumper';
5
+ import { program } from 'commander';
6
+ import detectIndent from 'detect-indent';
7
+ import { applyEdits, modify } from 'jsonc-parser';
8
+ import { createRequire } from 'node:module';
9
+ import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
10
+ import { load } from 'js-yaml';
11
+ import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
12
+ import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports } from '@jiek/pkger/entrypoints';
13
+ import require$$0 from 'util';
14
+ import require$$0$1 from 'path';
15
+ import 'jiek/cli-only-build';
16
+
17
+ let root;
18
+ function getRoot() {
19
+ if (root)
20
+ return root;
21
+ const rootOption = program.getOptionValue("root");
22
+ root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
23
+ return root;
24
+ }
25
+
26
+ let wd;
27
+ let notWorkspace = false;
28
+ function getWD() {
29
+ if (wd)
30
+ return { wd, notWorkspace };
31
+ const root = getRoot();
32
+ if (root !== void 0) {
33
+ const isWorkspace = isWorkspaceDir(root, type);
34
+ notWorkspace = !isWorkspace;
35
+ wd = root;
36
+ return { wd, notWorkspace };
37
+ }
38
+ try {
39
+ wd = getWorkspaceDir(type);
40
+ } catch (e) {
41
+ if ("message" in e && e.message === "workspace root not found") {
42
+ wd = root;
43
+ notWorkspace = true;
44
+ } else {
45
+ throw e;
46
+ }
47
+ }
48
+ return { wd, notWorkspace };
49
+ }
50
+
51
+ let type = "";
52
+ try {
53
+ const require = createRequire(import.meta.url);
54
+ require.resolve("@pnpm/filter-workspace-packages");
55
+ type = "pnpm";
56
+ } catch {
57
+ }
58
+ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
59
+ let root = getRoot();
60
+ const { wd, notWorkspace } = getWD();
61
+ if (notWorkspace) {
62
+ return {
63
+ wd,
64
+ root,
65
+ value: {
66
+ [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
67
+ }
68
+ };
69
+ }
70
+ if (type === "pnpm") {
71
+ const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
72
+ const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
73
+ const pnpmWorkspace = load(pnpmWorkspaceFileContent);
74
+ if (root === wd && !filter) {
75
+ throw new Error("root path is workspace root, please provide a filter");
76
+ }
77
+ if (root === void 0) {
78
+ root = process.cwd();
79
+ }
80
+ if (root !== wd && !filter) {
81
+ const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
82
+ if (!packageJSONIsExist) {
83
+ throw new Error("root path is not workspace root, please provide a filter");
84
+ }
85
+ const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
86
+ if (!packageJSON.name) {
87
+ throw new Error("root path is not workspace root, please provide a filter");
88
+ }
89
+ filter = packageJSON.name;
90
+ }
91
+ const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
92
+ filter: filter ?? "",
93
+ followProdDepsOnly: true
94
+ }], {
95
+ prefix: root,
96
+ workspaceDir: wd,
97
+ patterns: pnpmWorkspace.packages
98
+ });
99
+ return {
100
+ wd,
101
+ root,
102
+ value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
103
+ acc[key] = value.package.manifest;
104
+ return acc;
105
+ }, {})
106
+ };
107
+ }
108
+ throw new Error(`not supported package manager ${type}`);
109
+ }
110
+
111
+ var utils$1 = {};
112
+
113
+ var hasRequiredUtils$1;
114
+
115
+ function requireUtils$1 () {
116
+ if (hasRequiredUtils$1) return utils$1;
117
+ hasRequiredUtils$1 = 1;
118
+ (function (exports) {
119
+
120
+ exports.isInteger = num => {
121
+ if (typeof num === 'number') {
122
+ return Number.isInteger(num);
123
+ }
124
+ if (typeof num === 'string' && num.trim() !== '') {
125
+ return Number.isInteger(Number(num));
126
+ }
127
+ return false;
128
+ };
129
+
130
+ /**
131
+ * Find a node of the given type
132
+ */
133
+
134
+ exports.find = (node, type) => node.nodes.find(node => node.type === type);
135
+
136
+ /**
137
+ * Find a node of the given type
138
+ */
139
+
140
+ exports.exceedsLimit = (min, max, step = 1, limit) => {
141
+ if (limit === false) return false;
142
+ if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
143
+ return ((Number(max) - Number(min)) / Number(step)) >= limit;
144
+ };
145
+
146
+ /**
147
+ * Escape the given node with '\\' before node.value
148
+ */
149
+
150
+ exports.escapeNode = (block, n = 0, type) => {
151
+ let node = block.nodes[n];
152
+ if (!node) return;
153
+
154
+ if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
155
+ if (node.escaped !== true) {
156
+ node.value = '\\' + node.value;
157
+ node.escaped = true;
158
+ }
159
+ }
160
+ };
161
+
162
+ /**
163
+ * Returns true if the given brace node should be enclosed in literal braces
164
+ */
165
+
166
+ exports.encloseBrace = node => {
167
+ if (node.type !== 'brace') return false;
168
+ if ((node.commas >> 0 + node.ranges >> 0) === 0) {
169
+ node.invalid = true;
170
+ return true;
171
+ }
172
+ return false;
173
+ };
174
+
175
+ /**
176
+ * Returns true if a brace node is invalid.
177
+ */
178
+
179
+ exports.isInvalidBrace = block => {
180
+ if (block.type !== 'brace') return false;
181
+ if (block.invalid === true || block.dollar) return true;
182
+ if ((block.commas >> 0 + block.ranges >> 0) === 0) {
183
+ block.invalid = true;
184
+ return true;
185
+ }
186
+ if (block.open !== true || block.close !== true) {
187
+ block.invalid = true;
188
+ return true;
189
+ }
190
+ return false;
191
+ };
192
+
193
+ /**
194
+ * Returns true if a node is an open or close node
195
+ */
196
+
197
+ exports.isOpenOrClose = node => {
198
+ if (node.type === 'open' || node.type === 'close') {
199
+ return true;
200
+ }
201
+ return node.open === true || node.close === true;
202
+ };
203
+
204
+ /**
205
+ * Reduce an array of text nodes.
206
+ */
207
+
208
+ exports.reduce = nodes => nodes.reduce((acc, node) => {
209
+ if (node.type === 'text') acc.push(node.value);
210
+ if (node.type === 'range') node.type = 'text';
211
+ return acc;
212
+ }, []);
213
+
214
+ /**
215
+ * Flatten an array
216
+ */
217
+
218
+ exports.flatten = (...args) => {
219
+ const result = [];
220
+ const flat = arr => {
221
+ for (let i = 0; i < arr.length; i++) {
222
+ let ele = arr[i];
223
+ Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
224
+ }
225
+ return result;
226
+ };
227
+ flat(args);
228
+ return result;
229
+ };
230
+ } (utils$1));
231
+ return utils$1;
232
+ }
233
+
234
+ var stringify;
235
+ var hasRequiredStringify;
236
+
237
+ function requireStringify () {
238
+ if (hasRequiredStringify) return stringify;
239
+ hasRequiredStringify = 1;
240
+
241
+ const utils = requireUtils$1();
242
+
243
+ stringify = (ast, options = {}) => {
244
+ let stringify = (node, parent = {}) => {
245
+ let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
246
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
247
+ let output = '';
248
+
249
+ if (node.value) {
250
+ if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
251
+ return '\\' + node.value;
252
+ }
253
+ return node.value;
254
+ }
255
+
256
+ if (node.value) {
257
+ return node.value;
258
+ }
259
+
260
+ if (node.nodes) {
261
+ for (let child of node.nodes) {
262
+ output += stringify(child);
263
+ }
264
+ }
265
+ return output;
266
+ };
267
+
268
+ return stringify(ast);
269
+ };
270
+ return stringify;
271
+ }
272
+
273
+ /*!
274
+ * is-number <https://github.com/jonschlinkert/is-number>
275
+ *
276
+ * Copyright (c) 2014-present, Jon Schlinkert.
277
+ * Released under the MIT License.
278
+ */
279
+
280
+ var isNumber;
281
+ var hasRequiredIsNumber;
282
+
283
+ function requireIsNumber () {
284
+ if (hasRequiredIsNumber) return isNumber;
285
+ hasRequiredIsNumber = 1;
286
+
287
+ isNumber = function(num) {
288
+ if (typeof num === 'number') {
289
+ return num - num === 0;
290
+ }
291
+ if (typeof num === 'string' && num.trim() !== '') {
292
+ return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
293
+ }
294
+ return false;
295
+ };
296
+ return isNumber;
297
+ }
298
+
299
+ /*!
300
+ * to-regex-range <https://github.com/micromatch/to-regex-range>
301
+ *
302
+ * Copyright (c) 2015-present, Jon Schlinkert.
303
+ * Released under the MIT License.
304
+ */
305
+
306
+ var toRegexRange_1;
307
+ var hasRequiredToRegexRange;
308
+
309
+ function requireToRegexRange () {
310
+ if (hasRequiredToRegexRange) return toRegexRange_1;
311
+ hasRequiredToRegexRange = 1;
312
+
313
+ const isNumber = requireIsNumber();
314
+
315
+ const toRegexRange = (min, max, options) => {
316
+ if (isNumber(min) === false) {
317
+ throw new TypeError('toRegexRange: expected the first argument to be a number');
318
+ }
319
+
320
+ if (max === void 0 || min === max) {
321
+ return String(min);
322
+ }
323
+
324
+ if (isNumber(max) === false) {
325
+ throw new TypeError('toRegexRange: expected the second argument to be a number.');
326
+ }
327
+
328
+ let opts = { relaxZeros: true, ...options };
329
+ if (typeof opts.strictZeros === 'boolean') {
330
+ opts.relaxZeros = opts.strictZeros === false;
331
+ }
332
+
333
+ let relax = String(opts.relaxZeros);
334
+ let shorthand = String(opts.shorthand);
335
+ let capture = String(opts.capture);
336
+ let wrap = String(opts.wrap);
337
+ let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
338
+
339
+ if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
340
+ return toRegexRange.cache[cacheKey].result;
341
+ }
342
+
343
+ let a = Math.min(min, max);
344
+ let b = Math.max(min, max);
345
+
346
+ if (Math.abs(a - b) === 1) {
347
+ let result = min + '|' + max;
348
+ if (opts.capture) {
349
+ return `(${result})`;
350
+ }
351
+ if (opts.wrap === false) {
352
+ return result;
353
+ }
354
+ return `(?:${result})`;
355
+ }
356
+
357
+ let isPadded = hasPadding(min) || hasPadding(max);
358
+ let state = { min, max, a, b };
359
+ let positives = [];
360
+ let negatives = [];
361
+
362
+ if (isPadded) {
363
+ state.isPadded = isPadded;
364
+ state.maxLen = String(state.max).length;
365
+ }
366
+
367
+ if (a < 0) {
368
+ let newMin = b < 0 ? Math.abs(b) : 1;
369
+ negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
370
+ a = state.a = 0;
371
+ }
372
+
373
+ if (b >= 0) {
374
+ positives = splitToPatterns(a, b, state, opts);
375
+ }
376
+
377
+ state.negatives = negatives;
378
+ state.positives = positives;
379
+ state.result = collatePatterns(negatives, positives);
380
+
381
+ if (opts.capture === true) {
382
+ state.result = `(${state.result})`;
383
+ } else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
384
+ state.result = `(?:${state.result})`;
385
+ }
386
+
387
+ toRegexRange.cache[cacheKey] = state;
388
+ return state.result;
389
+ };
390
+
391
+ function collatePatterns(neg, pos, options) {
392
+ let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
393
+ let onlyPositive = filterPatterns(pos, neg, '', false) || [];
394
+ let intersected = filterPatterns(neg, pos, '-?', true) || [];
395
+ let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
396
+ return subpatterns.join('|');
397
+ }
398
+
399
+ function splitToRanges(min, max) {
400
+ let nines = 1;
401
+ let zeros = 1;
402
+
403
+ let stop = countNines(min, nines);
404
+ let stops = new Set([max]);
405
+
406
+ while (min <= stop && stop <= max) {
407
+ stops.add(stop);
408
+ nines += 1;
409
+ stop = countNines(min, nines);
410
+ }
411
+
412
+ stop = countZeros(max + 1, zeros) - 1;
413
+
414
+ while (min < stop && stop <= max) {
415
+ stops.add(stop);
416
+ zeros += 1;
417
+ stop = countZeros(max + 1, zeros) - 1;
418
+ }
419
+
420
+ stops = [...stops];
421
+ stops.sort(compare);
422
+ return stops;
423
+ }
424
+
425
+ /**
426
+ * Convert a range to a regex pattern
427
+ * @param {Number} `start`
428
+ * @param {Number} `stop`
429
+ * @return {String}
430
+ */
431
+
432
+ function rangeToPattern(start, stop, options) {
433
+ if (start === stop) {
434
+ return { pattern: start, count: [], digits: 0 };
435
+ }
436
+
437
+ let zipped = zip(start, stop);
438
+ let digits = zipped.length;
439
+ let pattern = '';
440
+ let count = 0;
441
+
442
+ for (let i = 0; i < digits; i++) {
443
+ let [startDigit, stopDigit] = zipped[i];
444
+
445
+ if (startDigit === stopDigit) {
446
+ pattern += startDigit;
447
+
448
+ } else if (startDigit !== '0' || stopDigit !== '9') {
449
+ pattern += toCharacterClass(startDigit, stopDigit);
450
+
451
+ } else {
452
+ count++;
453
+ }
454
+ }
455
+
456
+ if (count) {
457
+ pattern += options.shorthand === true ? '\\d' : '[0-9]';
458
+ }
459
+
460
+ return { pattern, count: [count], digits };
461
+ }
462
+
463
+ function splitToPatterns(min, max, tok, options) {
464
+ let ranges = splitToRanges(min, max);
465
+ let tokens = [];
466
+ let start = min;
467
+ let prev;
468
+
469
+ for (let i = 0; i < ranges.length; i++) {
470
+ let max = ranges[i];
471
+ let obj = rangeToPattern(String(start), String(max), options);
472
+ let zeros = '';
473
+
474
+ if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
475
+ if (prev.count.length > 1) {
476
+ prev.count.pop();
477
+ }
478
+
479
+ prev.count.push(obj.count[0]);
480
+ prev.string = prev.pattern + toQuantifier(prev.count);
481
+ start = max + 1;
482
+ continue;
483
+ }
484
+
485
+ if (tok.isPadded) {
486
+ zeros = padZeros(max, tok, options);
487
+ }
488
+
489
+ obj.string = zeros + obj.pattern + toQuantifier(obj.count);
490
+ tokens.push(obj);
491
+ start = max + 1;
492
+ prev = obj;
493
+ }
494
+
495
+ return tokens;
496
+ }
497
+
498
+ function filterPatterns(arr, comparison, prefix, intersection, options) {
499
+ let result = [];
500
+
501
+ for (let ele of arr) {
502
+ let { string } = ele;
503
+
504
+ // only push if _both_ are negative...
505
+ if (!intersection && !contains(comparison, 'string', string)) {
506
+ result.push(prefix + string);
507
+ }
508
+
509
+ // or _both_ are positive
510
+ if (intersection && contains(comparison, 'string', string)) {
511
+ result.push(prefix + string);
512
+ }
513
+ }
514
+ return result;
515
+ }
516
+
517
+ /**
518
+ * Zip strings
519
+ */
520
+
521
+ function zip(a, b) {
522
+ let arr = [];
523
+ for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
524
+ return arr;
525
+ }
526
+
527
+ function compare(a, b) {
528
+ return a > b ? 1 : b > a ? -1 : 0;
529
+ }
530
+
531
+ function contains(arr, key, val) {
532
+ return arr.some(ele => ele[key] === val);
533
+ }
534
+
535
+ function countNines(min, len) {
536
+ return Number(String(min).slice(0, -len) + '9'.repeat(len));
537
+ }
538
+
539
+ function countZeros(integer, zeros) {
540
+ return integer - (integer % Math.pow(10, zeros));
541
+ }
542
+
543
+ function toQuantifier(digits) {
544
+ let [start = 0, stop = ''] = digits;
545
+ if (stop || start > 1) {
546
+ return `{${start + (stop ? ',' + stop : '')}}`;
547
+ }
548
+ return '';
549
+ }
550
+
551
+ function toCharacterClass(a, b, options) {
552
+ return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
553
+ }
554
+
555
+ function hasPadding(str) {
556
+ return /^-?(0+)\d/.test(str);
557
+ }
558
+
559
+ function padZeros(value, tok, options) {
560
+ if (!tok.isPadded) {
561
+ return value;
562
+ }
563
+
564
+ let diff = Math.abs(tok.maxLen - String(value).length);
565
+ let relax = options.relaxZeros !== false;
566
+
567
+ switch (diff) {
568
+ case 0:
569
+ return '';
570
+ case 1:
571
+ return relax ? '0?' : '0';
572
+ case 2:
573
+ return relax ? '0{0,2}' : '00';
574
+ default: {
575
+ return relax ? `0{0,${diff}}` : `0{${diff}}`;
576
+ }
577
+ }
578
+ }
579
+
580
+ /**
581
+ * Cache
582
+ */
583
+
584
+ toRegexRange.cache = {};
585
+ toRegexRange.clearCache = () => (toRegexRange.cache = {});
586
+
587
+ /**
588
+ * Expose `toRegexRange`
589
+ */
590
+
591
+ toRegexRange_1 = toRegexRange;
592
+ return toRegexRange_1;
593
+ }
594
+
595
+ /*!
596
+ * fill-range <https://github.com/jonschlinkert/fill-range>
597
+ *
598
+ * Copyright (c) 2014-present, Jon Schlinkert.
599
+ * Licensed under the MIT License.
600
+ */
601
+
602
+ var fillRange;
603
+ var hasRequiredFillRange;
604
+
605
+ function requireFillRange () {
606
+ if (hasRequiredFillRange) return fillRange;
607
+ hasRequiredFillRange = 1;
608
+
609
+ const util = require$$0;
610
+ const toRegexRange = requireToRegexRange();
611
+
612
+ const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
613
+
614
+ const transform = toNumber => {
615
+ return value => toNumber === true ? Number(value) : String(value);
616
+ };
617
+
618
+ const isValidValue = value => {
619
+ return typeof value === 'number' || (typeof value === 'string' && value !== '');
620
+ };
621
+
622
+ const isNumber = num => Number.isInteger(+num);
623
+
624
+ const zeros = input => {
625
+ let value = `${input}`;
626
+ let index = -1;
627
+ if (value[0] === '-') value = value.slice(1);
628
+ if (value === '0') return false;
629
+ while (value[++index] === '0');
630
+ return index > 0;
631
+ };
632
+
633
+ const stringify = (start, end, options) => {
634
+ if (typeof start === 'string' || typeof end === 'string') {
635
+ return true;
636
+ }
637
+ return options.stringify === true;
638
+ };
639
+
640
+ const pad = (input, maxLength, toNumber) => {
641
+ if (maxLength > 0) {
642
+ let dash = input[0] === '-' ? '-' : '';
643
+ if (dash) input = input.slice(1);
644
+ input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
645
+ }
646
+ if (toNumber === false) {
647
+ return String(input);
648
+ }
649
+ return input;
650
+ };
651
+
652
+ const toMaxLen = (input, maxLength) => {
653
+ let negative = input[0] === '-' ? '-' : '';
654
+ if (negative) {
655
+ input = input.slice(1);
656
+ maxLength--;
657
+ }
658
+ while (input.length < maxLength) input = '0' + input;
659
+ return negative ? ('-' + input) : input;
660
+ };
661
+
662
+ const toSequence = (parts, options) => {
663
+ parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
664
+ parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
665
+
666
+ let prefix = options.capture ? '' : '?:';
667
+ let positives = '';
668
+ let negatives = '';
669
+ let result;
670
+
671
+ if (parts.positives.length) {
672
+ positives = parts.positives.join('|');
673
+ }
674
+
675
+ if (parts.negatives.length) {
676
+ negatives = `-(${prefix}${parts.negatives.join('|')})`;
677
+ }
678
+
679
+ if (positives && negatives) {
680
+ result = `${positives}|${negatives}`;
681
+ } else {
682
+ result = positives || negatives;
683
+ }
684
+
685
+ if (options.wrap) {
686
+ return `(${prefix}${result})`;
687
+ }
688
+
689
+ return result;
690
+ };
691
+
692
+ const toRange = (a, b, isNumbers, options) => {
693
+ if (isNumbers) {
694
+ return toRegexRange(a, b, { wrap: false, ...options });
695
+ }
696
+
697
+ let start = String.fromCharCode(a);
698
+ if (a === b) return start;
699
+
700
+ let stop = String.fromCharCode(b);
701
+ return `[${start}-${stop}]`;
702
+ };
703
+
704
+ const toRegex = (start, end, options) => {
705
+ if (Array.isArray(start)) {
706
+ let wrap = options.wrap === true;
707
+ let prefix = options.capture ? '' : '?:';
708
+ return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
709
+ }
710
+ return toRegexRange(start, end, options);
711
+ };
712
+
713
+ const rangeError = (...args) => {
714
+ return new RangeError('Invalid range arguments: ' + util.inspect(...args));
715
+ };
716
+
717
+ const invalidRange = (start, end, options) => {
718
+ if (options.strictRanges === true) throw rangeError([start, end]);
719
+ return [];
720
+ };
721
+
722
+ const invalidStep = (step, options) => {
723
+ if (options.strictRanges === true) {
724
+ throw new TypeError(`Expected step "${step}" to be a number`);
725
+ }
726
+ return [];
727
+ };
728
+
729
+ const fillNumbers = (start, end, step = 1, options = {}) => {
730
+ let a = Number(start);
731
+ let b = Number(end);
732
+
733
+ if (!Number.isInteger(a) || !Number.isInteger(b)) {
734
+ if (options.strictRanges === true) throw rangeError([start, end]);
735
+ return [];
736
+ }
737
+
738
+ // fix negative zero
739
+ if (a === 0) a = 0;
740
+ if (b === 0) b = 0;
741
+
742
+ let descending = a > b;
743
+ let startString = String(start);
744
+ let endString = String(end);
745
+ let stepString = String(step);
746
+ step = Math.max(Math.abs(step), 1);
747
+
748
+ let padded = zeros(startString) || zeros(endString) || zeros(stepString);
749
+ let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
750
+ let toNumber = padded === false && stringify(start, end, options) === false;
751
+ let format = options.transform || transform(toNumber);
752
+
753
+ if (options.toRegex && step === 1) {
754
+ return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
755
+ }
756
+
757
+ let parts = { negatives: [], positives: [] };
758
+ let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
759
+ let range = [];
760
+ let index = 0;
761
+
762
+ while (descending ? a >= b : a <= b) {
763
+ if (options.toRegex === true && step > 1) {
764
+ push(a);
765
+ } else {
766
+ range.push(pad(format(a, index), maxLen, toNumber));
767
+ }
768
+ a = descending ? a - step : a + step;
769
+ index++;
770
+ }
771
+
772
+ if (options.toRegex === true) {
773
+ return step > 1
774
+ ? toSequence(parts, options)
775
+ : toRegex(range, null, { wrap: false, ...options });
776
+ }
777
+
778
+ return range;
779
+ };
780
+
781
+ const fillLetters = (start, end, step = 1, options = {}) => {
782
+ if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
783
+ return invalidRange(start, end, options);
784
+ }
785
+
786
+
787
+ let format = options.transform || (val => String.fromCharCode(val));
788
+ let a = `${start}`.charCodeAt(0);
789
+ let b = `${end}`.charCodeAt(0);
790
+
791
+ let descending = a > b;
792
+ let min = Math.min(a, b);
793
+ let max = Math.max(a, b);
794
+
795
+ if (options.toRegex && step === 1) {
796
+ return toRange(min, max, false, options);
797
+ }
798
+
799
+ let range = [];
800
+ let index = 0;
801
+
802
+ while (descending ? a >= b : a <= b) {
803
+ range.push(format(a, index));
804
+ a = descending ? a - step : a + step;
805
+ index++;
806
+ }
807
+
808
+ if (options.toRegex === true) {
809
+ return toRegex(range, null, { wrap: false, options });
810
+ }
811
+
812
+ return range;
813
+ };
814
+
815
+ const fill = (start, end, step, options = {}) => {
816
+ if (end == null && isValidValue(start)) {
817
+ return [start];
818
+ }
819
+
820
+ if (!isValidValue(start) || !isValidValue(end)) {
821
+ return invalidRange(start, end, options);
822
+ }
823
+
824
+ if (typeof step === 'function') {
825
+ return fill(start, end, 1, { transform: step });
826
+ }
827
+
828
+ if (isObject(step)) {
829
+ return fill(start, end, 0, step);
830
+ }
831
+
832
+ let opts = { ...options };
833
+ if (opts.capture === true) opts.wrap = true;
834
+ step = step || opts.step || 1;
835
+
836
+ if (!isNumber(step)) {
837
+ if (step != null && !isObject(step)) return invalidStep(step, opts);
838
+ return fill(start, end, 1, step);
839
+ }
840
+
841
+ if (isNumber(start) && isNumber(end)) {
842
+ return fillNumbers(start, end, step, opts);
843
+ }
844
+
845
+ return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
846
+ };
847
+
848
+ fillRange = fill;
849
+ return fillRange;
850
+ }
851
+
852
+ var compile_1;
853
+ var hasRequiredCompile;
854
+
855
+ function requireCompile () {
856
+ if (hasRequiredCompile) return compile_1;
857
+ hasRequiredCompile = 1;
858
+
859
+ const fill = requireFillRange();
860
+ const utils = requireUtils$1();
861
+
862
+ const compile = (ast, options = {}) => {
863
+ let walk = (node, parent = {}) => {
864
+ let invalidBlock = utils.isInvalidBrace(parent);
865
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
866
+ let invalid = invalidBlock === true || invalidNode === true;
867
+ let prefix = options.escapeInvalid === true ? '\\' : '';
868
+ let output = '';
869
+
870
+ if (node.isOpen === true) {
871
+ return prefix + node.value;
872
+ }
873
+ if (node.isClose === true) {
874
+ return prefix + node.value;
875
+ }
876
+
877
+ if (node.type === 'open') {
878
+ return invalid ? (prefix + node.value) : '(';
879
+ }
880
+
881
+ if (node.type === 'close') {
882
+ return invalid ? (prefix + node.value) : ')';
883
+ }
884
+
885
+ if (node.type === 'comma') {
886
+ return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
887
+ }
888
+
889
+ if (node.value) {
890
+ return node.value;
891
+ }
892
+
893
+ if (node.nodes && node.ranges > 0) {
894
+ let args = utils.reduce(node.nodes);
895
+ let range = fill(...args, { ...options, wrap: false, toRegex: true });
896
+
897
+ if (range.length !== 0) {
898
+ return args.length > 1 && range.length > 1 ? `(${range})` : range;
899
+ }
900
+ }
901
+
902
+ if (node.nodes) {
903
+ for (let child of node.nodes) {
904
+ output += walk(child, node);
905
+ }
906
+ }
907
+ return output;
908
+ };
909
+
910
+ return walk(ast);
911
+ };
912
+
913
+ compile_1 = compile;
914
+ return compile_1;
915
+ }
916
+
917
+ var expand_1;
918
+ var hasRequiredExpand;
919
+
920
+ function requireExpand () {
921
+ if (hasRequiredExpand) return expand_1;
922
+ hasRequiredExpand = 1;
923
+
924
+ const fill = requireFillRange();
925
+ const stringify = requireStringify();
926
+ const utils = requireUtils$1();
927
+
928
+ const append = (queue = '', stash = '', enclose = false) => {
929
+ let result = [];
930
+
931
+ queue = [].concat(queue);
932
+ stash = [].concat(stash);
933
+
934
+ if (!stash.length) return queue;
935
+ if (!queue.length) {
936
+ return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
937
+ }
938
+
939
+ for (let item of queue) {
940
+ if (Array.isArray(item)) {
941
+ for (let value of item) {
942
+ result.push(append(value, stash, enclose));
943
+ }
944
+ } else {
945
+ for (let ele of stash) {
946
+ if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
947
+ result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
948
+ }
949
+ }
950
+ }
951
+ return utils.flatten(result);
952
+ };
953
+
954
+ const expand = (ast, options = {}) => {
955
+ let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
956
+
957
+ let walk = (node, parent = {}) => {
958
+ node.queue = [];
959
+
960
+ let p = parent;
961
+ let q = parent.queue;
962
+
963
+ while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
964
+ p = p.parent;
965
+ q = p.queue;
966
+ }
967
+
968
+ if (node.invalid || node.dollar) {
969
+ q.push(append(q.pop(), stringify(node, options)));
970
+ return;
971
+ }
972
+
973
+ if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
974
+ q.push(append(q.pop(), ['{}']));
975
+ return;
976
+ }
977
+
978
+ if (node.nodes && node.ranges > 0) {
979
+ let args = utils.reduce(node.nodes);
980
+
981
+ if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
982
+ throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
983
+ }
984
+
985
+ let range = fill(...args, options);
986
+ if (range.length === 0) {
987
+ range = stringify(node, options);
988
+ }
989
+
990
+ q.push(append(q.pop(), range));
991
+ node.nodes = [];
992
+ return;
993
+ }
994
+
995
+ let enclose = utils.encloseBrace(node);
996
+ let queue = node.queue;
997
+ let block = node;
998
+
999
+ while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
1000
+ block = block.parent;
1001
+ queue = block.queue;
1002
+ }
1003
+
1004
+ for (let i = 0; i < node.nodes.length; i++) {
1005
+ let child = node.nodes[i];
1006
+
1007
+ if (child.type === 'comma' && node.type === 'brace') {
1008
+ if (i === 1) queue.push('');
1009
+ queue.push('');
1010
+ continue;
1011
+ }
1012
+
1013
+ if (child.type === 'close') {
1014
+ q.push(append(q.pop(), queue, enclose));
1015
+ continue;
1016
+ }
1017
+
1018
+ if (child.value && child.type !== 'open') {
1019
+ queue.push(append(queue.pop(), child.value));
1020
+ continue;
1021
+ }
1022
+
1023
+ if (child.nodes) {
1024
+ walk(child, node);
1025
+ }
1026
+ }
1027
+
1028
+ return queue;
1029
+ };
1030
+
1031
+ return utils.flatten(walk(ast));
1032
+ };
1033
+
1034
+ expand_1 = expand;
1035
+ return expand_1;
1036
+ }
1037
+
1038
+ var constants$1;
1039
+ var hasRequiredConstants$1;
1040
+
1041
+ function requireConstants$1 () {
1042
+ if (hasRequiredConstants$1) return constants$1;
1043
+ hasRequiredConstants$1 = 1;
1044
+
1045
+ constants$1 = {
1046
+ MAX_LENGTH: 1024 * 64,
1047
+
1048
+ // Digits
1049
+ CHAR_0: '0', /* 0 */
1050
+ CHAR_9: '9', /* 9 */
1051
+
1052
+ // Alphabet chars.
1053
+ CHAR_UPPERCASE_A: 'A', /* A */
1054
+ CHAR_LOWERCASE_A: 'a', /* a */
1055
+ CHAR_UPPERCASE_Z: 'Z', /* Z */
1056
+ CHAR_LOWERCASE_Z: 'z', /* z */
1057
+
1058
+ CHAR_LEFT_PARENTHESES: '(', /* ( */
1059
+ CHAR_RIGHT_PARENTHESES: ')', /* ) */
1060
+
1061
+ CHAR_ASTERISK: '*', /* * */
1062
+
1063
+ // Non-alphabetic chars.
1064
+ CHAR_AMPERSAND: '&', /* & */
1065
+ CHAR_AT: '@', /* @ */
1066
+ CHAR_BACKSLASH: '\\', /* \ */
1067
+ CHAR_BACKTICK: '`', /* ` */
1068
+ CHAR_CARRIAGE_RETURN: '\r', /* \r */
1069
+ CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
1070
+ CHAR_COLON: ':', /* : */
1071
+ CHAR_COMMA: ',', /* , */
1072
+ CHAR_DOLLAR: '$', /* . */
1073
+ CHAR_DOT: '.', /* . */
1074
+ CHAR_DOUBLE_QUOTE: '"', /* " */
1075
+ CHAR_EQUAL: '=', /* = */
1076
+ CHAR_EXCLAMATION_MARK: '!', /* ! */
1077
+ CHAR_FORM_FEED: '\f', /* \f */
1078
+ CHAR_FORWARD_SLASH: '/', /* / */
1079
+ CHAR_HASH: '#', /* # */
1080
+ CHAR_HYPHEN_MINUS: '-', /* - */
1081
+ CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
1082
+ CHAR_LEFT_CURLY_BRACE: '{', /* { */
1083
+ CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
1084
+ CHAR_LINE_FEED: '\n', /* \n */
1085
+ CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
1086
+ CHAR_PERCENT: '%', /* % */
1087
+ CHAR_PLUS: '+', /* + */
1088
+ CHAR_QUESTION_MARK: '?', /* ? */
1089
+ CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
1090
+ CHAR_RIGHT_CURLY_BRACE: '}', /* } */
1091
+ CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
1092
+ CHAR_SEMICOLON: ';', /* ; */
1093
+ CHAR_SINGLE_QUOTE: '\'', /* ' */
1094
+ CHAR_SPACE: ' ', /* */
1095
+ CHAR_TAB: '\t', /* \t */
1096
+ CHAR_UNDERSCORE: '_', /* _ */
1097
+ CHAR_VERTICAL_LINE: '|', /* | */
1098
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
1099
+ };
1100
+ return constants$1;
1101
+ }
1102
+
1103
+ var parse_1$1;
1104
+ var hasRequiredParse$1;
1105
+
1106
+ function requireParse$1 () {
1107
+ if (hasRequiredParse$1) return parse_1$1;
1108
+ hasRequiredParse$1 = 1;
1109
+
1110
+ const stringify = requireStringify();
1111
+
1112
+ /**
1113
+ * Constants
1114
+ */
1115
+
1116
+ const {
1117
+ MAX_LENGTH,
1118
+ CHAR_BACKSLASH, /* \ */
1119
+ CHAR_BACKTICK, /* ` */
1120
+ CHAR_COMMA, /* , */
1121
+ CHAR_DOT, /* . */
1122
+ CHAR_LEFT_PARENTHESES, /* ( */
1123
+ CHAR_RIGHT_PARENTHESES, /* ) */
1124
+ CHAR_LEFT_CURLY_BRACE, /* { */
1125
+ CHAR_RIGHT_CURLY_BRACE, /* } */
1126
+ CHAR_LEFT_SQUARE_BRACKET, /* [ */
1127
+ CHAR_RIGHT_SQUARE_BRACKET, /* ] */
1128
+ CHAR_DOUBLE_QUOTE, /* " */
1129
+ CHAR_SINGLE_QUOTE, /* ' */
1130
+ CHAR_NO_BREAK_SPACE,
1131
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE
1132
+ } = requireConstants$1();
1133
+
1134
+ /**
1135
+ * parse
1136
+ */
1137
+
1138
+ const parse = (input, options = {}) => {
1139
+ if (typeof input !== 'string') {
1140
+ throw new TypeError('Expected a string');
1141
+ }
1142
+
1143
+ let opts = options || {};
1144
+ let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1145
+ if (input.length > max) {
1146
+ throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
1147
+ }
1148
+
1149
+ let ast = { type: 'root', input, nodes: [] };
1150
+ let stack = [ast];
1151
+ let block = ast;
1152
+ let prev = ast;
1153
+ let brackets = 0;
1154
+ let length = input.length;
1155
+ let index = 0;
1156
+ let depth = 0;
1157
+ let value;
1158
+
1159
+ /**
1160
+ * Helpers
1161
+ */
1162
+
1163
+ const advance = () => input[index++];
1164
+ const push = node => {
1165
+ if (node.type === 'text' && prev.type === 'dot') {
1166
+ prev.type = 'text';
1167
+ }
1168
+
1169
+ if (prev && prev.type === 'text' && node.type === 'text') {
1170
+ prev.value += node.value;
1171
+ return;
1172
+ }
1173
+
1174
+ block.nodes.push(node);
1175
+ node.parent = block;
1176
+ node.prev = prev;
1177
+ prev = node;
1178
+ return node;
1179
+ };
1180
+
1181
+ push({ type: 'bos' });
1182
+
1183
+ while (index < length) {
1184
+ block = stack[stack.length - 1];
1185
+ value = advance();
1186
+
1187
+ /**
1188
+ * Invalid chars
1189
+ */
1190
+
1191
+ if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
1192
+ continue;
1193
+ }
1194
+
1195
+ /**
1196
+ * Escaped chars
1197
+ */
1198
+
1199
+ if (value === CHAR_BACKSLASH) {
1200
+ push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
1201
+ continue;
1202
+ }
1203
+
1204
+ /**
1205
+ * Right square bracket (literal): ']'
1206
+ */
1207
+
1208
+ if (value === CHAR_RIGHT_SQUARE_BRACKET) {
1209
+ push({ type: 'text', value: '\\' + value });
1210
+ continue;
1211
+ }
1212
+
1213
+ /**
1214
+ * Left square bracket: '['
1215
+ */
1216
+
1217
+ if (value === CHAR_LEFT_SQUARE_BRACKET) {
1218
+ brackets++;
1219
+ let next;
1220
+
1221
+ while (index < length && (next = advance())) {
1222
+ value += next;
1223
+
1224
+ if (next === CHAR_LEFT_SQUARE_BRACKET) {
1225
+ brackets++;
1226
+ continue;
1227
+ }
1228
+
1229
+ if (next === CHAR_BACKSLASH) {
1230
+ value += advance();
1231
+ continue;
1232
+ }
1233
+
1234
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
1235
+ brackets--;
1236
+
1237
+ if (brackets === 0) {
1238
+ break;
1239
+ }
1240
+ }
1241
+ }
1242
+
1243
+ push({ type: 'text', value });
1244
+ continue;
1245
+ }
1246
+
1247
+ /**
1248
+ * Parentheses
1249
+ */
1250
+
1251
+ if (value === CHAR_LEFT_PARENTHESES) {
1252
+ block = push({ type: 'paren', nodes: [] });
1253
+ stack.push(block);
1254
+ push({ type: 'text', value });
1255
+ continue;
1256
+ }
1257
+
1258
+ if (value === CHAR_RIGHT_PARENTHESES) {
1259
+ if (block.type !== 'paren') {
1260
+ push({ type: 'text', value });
1261
+ continue;
1262
+ }
1263
+ block = stack.pop();
1264
+ push({ type: 'text', value });
1265
+ block = stack[stack.length - 1];
1266
+ continue;
1267
+ }
1268
+
1269
+ /**
1270
+ * Quotes: '|"|`
1271
+ */
1272
+
1273
+ if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
1274
+ let open = value;
1275
+ let next;
1276
+
1277
+ if (options.keepQuotes !== true) {
1278
+ value = '';
1279
+ }
1280
+
1281
+ while (index < length && (next = advance())) {
1282
+ if (next === CHAR_BACKSLASH) {
1283
+ value += next + advance();
1284
+ continue;
1285
+ }
1286
+
1287
+ if (next === open) {
1288
+ if (options.keepQuotes === true) value += next;
1289
+ break;
1290
+ }
1291
+
1292
+ value += next;
1293
+ }
1294
+
1295
+ push({ type: 'text', value });
1296
+ continue;
1297
+ }
1298
+
1299
+ /**
1300
+ * Left curly brace: '{'
1301
+ */
1302
+
1303
+ if (value === CHAR_LEFT_CURLY_BRACE) {
1304
+ depth++;
1305
+
1306
+ let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
1307
+ let brace = {
1308
+ type: 'brace',
1309
+ open: true,
1310
+ close: false,
1311
+ dollar,
1312
+ depth,
1313
+ commas: 0,
1314
+ ranges: 0,
1315
+ nodes: []
1316
+ };
1317
+
1318
+ block = push(brace);
1319
+ stack.push(block);
1320
+ push({ type: 'open', value });
1321
+ continue;
1322
+ }
1323
+
1324
+ /**
1325
+ * Right curly brace: '}'
1326
+ */
1327
+
1328
+ if (value === CHAR_RIGHT_CURLY_BRACE) {
1329
+ if (block.type !== 'brace') {
1330
+ push({ type: 'text', value });
1331
+ continue;
1332
+ }
1333
+
1334
+ let type = 'close';
1335
+ block = stack.pop();
1336
+ block.close = true;
1337
+
1338
+ push({ type, value });
1339
+ depth--;
1340
+
1341
+ block = stack[stack.length - 1];
1342
+ continue;
1343
+ }
1344
+
1345
+ /**
1346
+ * Comma: ','
1347
+ */
1348
+
1349
+ if (value === CHAR_COMMA && depth > 0) {
1350
+ if (block.ranges > 0) {
1351
+ block.ranges = 0;
1352
+ let open = block.nodes.shift();
1353
+ block.nodes = [open, { type: 'text', value: stringify(block) }];
1354
+ }
1355
+
1356
+ push({ type: 'comma', value });
1357
+ block.commas++;
1358
+ continue;
1359
+ }
1360
+
1361
+ /**
1362
+ * Dot: '.'
1363
+ */
1364
+
1365
+ if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
1366
+ let siblings = block.nodes;
1367
+
1368
+ if (depth === 0 || siblings.length === 0) {
1369
+ push({ type: 'text', value });
1370
+ continue;
1371
+ }
1372
+
1373
+ if (prev.type === 'dot') {
1374
+ block.range = [];
1375
+ prev.value += value;
1376
+ prev.type = 'range';
1377
+
1378
+ if (block.nodes.length !== 3 && block.nodes.length !== 5) {
1379
+ block.invalid = true;
1380
+ block.ranges = 0;
1381
+ prev.type = 'text';
1382
+ continue;
1383
+ }
1384
+
1385
+ block.ranges++;
1386
+ block.args = [];
1387
+ continue;
1388
+ }
1389
+
1390
+ if (prev.type === 'range') {
1391
+ siblings.pop();
1392
+
1393
+ let before = siblings[siblings.length - 1];
1394
+ before.value += prev.value + value;
1395
+ prev = before;
1396
+ block.ranges--;
1397
+ continue;
1398
+ }
1399
+
1400
+ push({ type: 'dot', value });
1401
+ continue;
1402
+ }
1403
+
1404
+ /**
1405
+ * Text
1406
+ */
1407
+
1408
+ push({ type: 'text', value });
1409
+ }
1410
+
1411
+ // Mark imbalanced braces and brackets as invalid
1412
+ do {
1413
+ block = stack.pop();
1414
+
1415
+ if (block.type !== 'root') {
1416
+ block.nodes.forEach(node => {
1417
+ if (!node.nodes) {
1418
+ if (node.type === 'open') node.isOpen = true;
1419
+ if (node.type === 'close') node.isClose = true;
1420
+ if (!node.nodes) node.type = 'text';
1421
+ node.invalid = true;
1422
+ }
1423
+ });
1424
+
1425
+ // get the location of the block on parent.nodes (block's siblings)
1426
+ let parent = stack[stack.length - 1];
1427
+ let index = parent.nodes.indexOf(block);
1428
+ // replace the (invalid) block with it's nodes
1429
+ parent.nodes.splice(index, 1, ...block.nodes);
1430
+ }
1431
+ } while (stack.length > 0);
1432
+
1433
+ push({ type: 'eos' });
1434
+ return ast;
1435
+ };
1436
+
1437
+ parse_1$1 = parse;
1438
+ return parse_1$1;
1439
+ }
1440
+
1441
+ var braces_1;
1442
+ var hasRequiredBraces;
1443
+
1444
+ function requireBraces () {
1445
+ if (hasRequiredBraces) return braces_1;
1446
+ hasRequiredBraces = 1;
1447
+
1448
+ const stringify = requireStringify();
1449
+ const compile = requireCompile();
1450
+ const expand = requireExpand();
1451
+ const parse = requireParse$1();
1452
+
1453
+ /**
1454
+ * Expand the given pattern or create a regex-compatible string.
1455
+ *
1456
+ * ```js
1457
+ * const braces = require('braces');
1458
+ * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
1459
+ * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
1460
+ * ```
1461
+ * @param {String} `str`
1462
+ * @param {Object} `options`
1463
+ * @return {String}
1464
+ * @api public
1465
+ */
1466
+
1467
+ const braces = (input, options = {}) => {
1468
+ let output = [];
1469
+
1470
+ if (Array.isArray(input)) {
1471
+ for (let pattern of input) {
1472
+ let result = braces.create(pattern, options);
1473
+ if (Array.isArray(result)) {
1474
+ output.push(...result);
1475
+ } else {
1476
+ output.push(result);
1477
+ }
1478
+ }
1479
+ } else {
1480
+ output = [].concat(braces.create(input, options));
1481
+ }
1482
+
1483
+ if (options && options.expand === true && options.nodupes === true) {
1484
+ output = [...new Set(output)];
1485
+ }
1486
+ return output;
1487
+ };
1488
+
1489
+ /**
1490
+ * Parse the given `str` with the given `options`.
1491
+ *
1492
+ * ```js
1493
+ * // braces.parse(pattern, [, options]);
1494
+ * const ast = braces.parse('a/{b,c}/d');
1495
+ * console.log(ast);
1496
+ * ```
1497
+ * @param {String} pattern Brace pattern to parse
1498
+ * @param {Object} options
1499
+ * @return {Object} Returns an AST
1500
+ * @api public
1501
+ */
1502
+
1503
+ braces.parse = (input, options = {}) => parse(input, options);
1504
+
1505
+ /**
1506
+ * Creates a braces string from an AST, or an AST node.
1507
+ *
1508
+ * ```js
1509
+ * const braces = require('braces');
1510
+ * let ast = braces.parse('foo/{a,b}/bar');
1511
+ * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
1512
+ * ```
1513
+ * @param {String} `input` Brace pattern or AST.
1514
+ * @param {Object} `options`
1515
+ * @return {Array} Returns an array of expanded values.
1516
+ * @api public
1517
+ */
1518
+
1519
+ braces.stringify = (input, options = {}) => {
1520
+ if (typeof input === 'string') {
1521
+ return stringify(braces.parse(input, options), options);
1522
+ }
1523
+ return stringify(input, options);
1524
+ };
1525
+
1526
+ /**
1527
+ * Compiles a brace pattern into a regex-compatible, optimized string.
1528
+ * This method is called by the main [braces](#braces) function by default.
1529
+ *
1530
+ * ```js
1531
+ * const braces = require('braces');
1532
+ * console.log(braces.compile('a/{b,c}/d'));
1533
+ * //=> ['a/(b|c)/d']
1534
+ * ```
1535
+ * @param {String} `input` Brace pattern or AST.
1536
+ * @param {Object} `options`
1537
+ * @return {Array} Returns an array of expanded values.
1538
+ * @api public
1539
+ */
1540
+
1541
+ braces.compile = (input, options = {}) => {
1542
+ if (typeof input === 'string') {
1543
+ input = braces.parse(input, options);
1544
+ }
1545
+ return compile(input, options);
1546
+ };
1547
+
1548
+ /**
1549
+ * Expands a brace pattern into an array. This method is called by the
1550
+ * main [braces](#braces) function when `options.expand` is true. Before
1551
+ * using this method it's recommended that you read the [performance notes](#performance))
1552
+ * and advantages of using [.compile](#compile) instead.
1553
+ *
1554
+ * ```js
1555
+ * const braces = require('braces');
1556
+ * console.log(braces.expand('a/{b,c}/d'));
1557
+ * //=> ['a/b/d', 'a/c/d'];
1558
+ * ```
1559
+ * @param {String} `pattern` Brace pattern
1560
+ * @param {Object} `options`
1561
+ * @return {Array} Returns an array of expanded values.
1562
+ * @api public
1563
+ */
1564
+
1565
+ braces.expand = (input, options = {}) => {
1566
+ if (typeof input === 'string') {
1567
+ input = braces.parse(input, options);
1568
+ }
1569
+
1570
+ let result = expand(input, options);
1571
+
1572
+ // filter out empty strings if specified
1573
+ if (options.noempty === true) {
1574
+ result = result.filter(Boolean);
1575
+ }
1576
+
1577
+ // filter out duplicates if specified
1578
+ if (options.nodupes === true) {
1579
+ result = [...new Set(result)];
1580
+ }
1581
+
1582
+ return result;
1583
+ };
1584
+
1585
+ /**
1586
+ * Processes a brace pattern and returns either an expanded array
1587
+ * (if `options.expand` is true), a highly optimized regex-compatible string.
1588
+ * This method is called by the main [braces](#braces) function.
1589
+ *
1590
+ * ```js
1591
+ * const braces = require('braces');
1592
+ * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
1593
+ * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
1594
+ * ```
1595
+ * @param {String} `pattern` Brace pattern
1596
+ * @param {Object} `options`
1597
+ * @return {Array} Returns an array of expanded values.
1598
+ * @api public
1599
+ */
1600
+
1601
+ braces.create = (input, options = {}) => {
1602
+ if (input === '' || input.length < 3) {
1603
+ return [input];
1604
+ }
1605
+
1606
+ return options.expand !== true
1607
+ ? braces.compile(input, options)
1608
+ : braces.expand(input, options);
1609
+ };
1610
+
1611
+ /**
1612
+ * Expose "braces"
1613
+ */
1614
+
1615
+ braces_1 = braces;
1616
+ return braces_1;
1617
+ }
1618
+
1619
+ var utils = {};
1620
+
1621
+ var constants;
1622
+ var hasRequiredConstants;
1623
+
1624
+ function requireConstants () {
1625
+ if (hasRequiredConstants) return constants;
1626
+ hasRequiredConstants = 1;
1627
+
1628
+ const path = require$$0$1;
1629
+ const WIN_SLASH = '\\\\/';
1630
+ const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
1631
+
1632
+ /**
1633
+ * Posix glob regex
1634
+ */
1635
+
1636
+ const DOT_LITERAL = '\\.';
1637
+ const PLUS_LITERAL = '\\+';
1638
+ const QMARK_LITERAL = '\\?';
1639
+ const SLASH_LITERAL = '\\/';
1640
+ const ONE_CHAR = '(?=.)';
1641
+ const QMARK = '[^/]';
1642
+ const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
1643
+ const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
1644
+ const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
1645
+ const NO_DOT = `(?!${DOT_LITERAL})`;
1646
+ const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
1647
+ const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
1648
+ const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
1649
+ const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
1650
+ const STAR = `${QMARK}*?`;
1651
+
1652
+ const POSIX_CHARS = {
1653
+ DOT_LITERAL,
1654
+ PLUS_LITERAL,
1655
+ QMARK_LITERAL,
1656
+ SLASH_LITERAL,
1657
+ ONE_CHAR,
1658
+ QMARK,
1659
+ END_ANCHOR,
1660
+ DOTS_SLASH,
1661
+ NO_DOT,
1662
+ NO_DOTS,
1663
+ NO_DOT_SLASH,
1664
+ NO_DOTS_SLASH,
1665
+ QMARK_NO_DOT,
1666
+ STAR,
1667
+ START_ANCHOR
1668
+ };
1669
+
1670
+ /**
1671
+ * Windows glob regex
1672
+ */
1673
+
1674
+ const WINDOWS_CHARS = {
1675
+ ...POSIX_CHARS,
1676
+
1677
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
1678
+ QMARK: WIN_NO_SLASH,
1679
+ STAR: `${WIN_NO_SLASH}*?`,
1680
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
1681
+ NO_DOT: `(?!${DOT_LITERAL})`,
1682
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
1683
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
1684
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
1685
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
1686
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
1687
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
1688
+ };
1689
+
1690
+ /**
1691
+ * POSIX Bracket Regex
1692
+ */
1693
+
1694
+ const POSIX_REGEX_SOURCE = {
1695
+ alnum: 'a-zA-Z0-9',
1696
+ alpha: 'a-zA-Z',
1697
+ ascii: '\\x00-\\x7F',
1698
+ blank: ' \\t',
1699
+ cntrl: '\\x00-\\x1F\\x7F',
1700
+ digit: '0-9',
1701
+ graph: '\\x21-\\x7E',
1702
+ lower: 'a-z',
1703
+ print: '\\x20-\\x7E ',
1704
+ punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
1705
+ space: ' \\t\\r\\n\\v\\f',
1706
+ upper: 'A-Z',
1707
+ word: 'A-Za-z0-9_',
1708
+ xdigit: 'A-Fa-f0-9'
1709
+ };
1710
+
1711
+ constants = {
1712
+ MAX_LENGTH: 1024 * 64,
1713
+ POSIX_REGEX_SOURCE,
1714
+
1715
+ // regular expressions
1716
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
1717
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
1718
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
1719
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
1720
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
1721
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
1722
+
1723
+ // Replace globs with equivalent patterns to reduce parsing time.
1724
+ REPLACEMENTS: {
1725
+ '***': '*',
1726
+ '**/**': '**',
1727
+ '**/**/**': '**'
1728
+ },
1729
+
1730
+ // Digits
1731
+ CHAR_0: 48, /* 0 */
1732
+ CHAR_9: 57, /* 9 */
1733
+
1734
+ // Alphabet chars.
1735
+ CHAR_UPPERCASE_A: 65, /* A */
1736
+ CHAR_LOWERCASE_A: 97, /* a */
1737
+ CHAR_UPPERCASE_Z: 90, /* Z */
1738
+ CHAR_LOWERCASE_Z: 122, /* z */
1739
+
1740
+ CHAR_LEFT_PARENTHESES: 40, /* ( */
1741
+ CHAR_RIGHT_PARENTHESES: 41, /* ) */
1742
+
1743
+ CHAR_ASTERISK: 42, /* * */
1744
+
1745
+ // Non-alphabetic chars.
1746
+ CHAR_AMPERSAND: 38, /* & */
1747
+ CHAR_AT: 64, /* @ */
1748
+ CHAR_BACKWARD_SLASH: 92, /* \ */
1749
+ CHAR_CARRIAGE_RETURN: 13, /* \r */
1750
+ CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
1751
+ CHAR_COLON: 58, /* : */
1752
+ CHAR_COMMA: 44, /* , */
1753
+ CHAR_DOT: 46, /* . */
1754
+ CHAR_DOUBLE_QUOTE: 34, /* " */
1755
+ CHAR_EQUAL: 61, /* = */
1756
+ CHAR_EXCLAMATION_MARK: 33, /* ! */
1757
+ CHAR_FORM_FEED: 12, /* \f */
1758
+ CHAR_FORWARD_SLASH: 47, /* / */
1759
+ CHAR_GRAVE_ACCENT: 96, /* ` */
1760
+ CHAR_HASH: 35, /* # */
1761
+ CHAR_HYPHEN_MINUS: 45, /* - */
1762
+ CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
1763
+ CHAR_LEFT_CURLY_BRACE: 123, /* { */
1764
+ CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
1765
+ CHAR_LINE_FEED: 10, /* \n */
1766
+ CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
1767
+ CHAR_PERCENT: 37, /* % */
1768
+ CHAR_PLUS: 43, /* + */
1769
+ CHAR_QUESTION_MARK: 63, /* ? */
1770
+ CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
1771
+ CHAR_RIGHT_CURLY_BRACE: 125, /* } */
1772
+ CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
1773
+ CHAR_SEMICOLON: 59, /* ; */
1774
+ CHAR_SINGLE_QUOTE: 39, /* ' */
1775
+ CHAR_SPACE: 32, /* */
1776
+ CHAR_TAB: 9, /* \t */
1777
+ CHAR_UNDERSCORE: 95, /* _ */
1778
+ CHAR_VERTICAL_LINE: 124, /* | */
1779
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
1780
+
1781
+ SEP: path.sep,
1782
+
1783
+ /**
1784
+ * Create EXTGLOB_CHARS
1785
+ */
1786
+
1787
+ extglobChars(chars) {
1788
+ return {
1789
+ '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
1790
+ '?': { type: 'qmark', open: '(?:', close: ')?' },
1791
+ '+': { type: 'plus', open: '(?:', close: ')+' },
1792
+ '*': { type: 'star', open: '(?:', close: ')*' },
1793
+ '@': { type: 'at', open: '(?:', close: ')' }
1794
+ };
1795
+ },
1796
+
1797
+ /**
1798
+ * Create GLOB_CHARS
1799
+ */
1800
+
1801
+ globChars(win32) {
1802
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
1803
+ }
1804
+ };
1805
+ return constants;
1806
+ }
1807
+
1808
+ var hasRequiredUtils;
1809
+
1810
+ function requireUtils () {
1811
+ if (hasRequiredUtils) return utils;
1812
+ hasRequiredUtils = 1;
1813
+ (function (exports) {
1814
+
1815
+ const path = require$$0$1;
1816
+ const win32 = process.platform === 'win32';
1817
+ const {
1818
+ REGEX_BACKSLASH,
1819
+ REGEX_REMOVE_BACKSLASH,
1820
+ REGEX_SPECIAL_CHARS,
1821
+ REGEX_SPECIAL_CHARS_GLOBAL
1822
+ } = requireConstants();
1823
+
1824
+ exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
1825
+ exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
1826
+ exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
1827
+ exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
1828
+ exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
1829
+
1830
+ exports.removeBackslashes = str => {
1831
+ return str.replace(REGEX_REMOVE_BACKSLASH, match => {
1832
+ return match === '\\' ? '' : match;
1833
+ });
1834
+ };
1835
+
1836
+ exports.supportsLookbehinds = () => {
1837
+ const segs = process.version.slice(1).split('.').map(Number);
1838
+ if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
1839
+ return true;
1840
+ }
1841
+ return false;
1842
+ };
1843
+
1844
+ exports.isWindows = options => {
1845
+ if (options && typeof options.windows === 'boolean') {
1846
+ return options.windows;
1847
+ }
1848
+ return win32 === true || path.sep === '\\';
1849
+ };
1850
+
1851
+ exports.escapeLast = (input, char, lastIdx) => {
1852
+ const idx = input.lastIndexOf(char, lastIdx);
1853
+ if (idx === -1) return input;
1854
+ if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
1855
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
1856
+ };
1857
+
1858
+ exports.removePrefix = (input, state = {}) => {
1859
+ let output = input;
1860
+ if (output.startsWith('./')) {
1861
+ output = output.slice(2);
1862
+ state.prefix = './';
1863
+ }
1864
+ return output;
1865
+ };
1866
+
1867
+ exports.wrapOutput = (input, state = {}, options = {}) => {
1868
+ const prepend = options.contains ? '' : '^';
1869
+ const append = options.contains ? '' : '$';
1870
+
1871
+ let output = `${prepend}(?:${input})${append}`;
1872
+ if (state.negated === true) {
1873
+ output = `(?:^(?!${output}).*$)`;
1874
+ }
1875
+ return output;
1876
+ };
1877
+ } (utils));
1878
+ return utils;
1879
+ }
1880
+
1881
+ var scan_1;
1882
+ var hasRequiredScan;
1883
+
1884
+ function requireScan () {
1885
+ if (hasRequiredScan) return scan_1;
1886
+ hasRequiredScan = 1;
1887
+
1888
+ const utils = requireUtils();
1889
+ const {
1890
+ CHAR_ASTERISK, /* * */
1891
+ CHAR_AT, /* @ */
1892
+ CHAR_BACKWARD_SLASH, /* \ */
1893
+ CHAR_COMMA, /* , */
1894
+ CHAR_DOT, /* . */
1895
+ CHAR_EXCLAMATION_MARK, /* ! */
1896
+ CHAR_FORWARD_SLASH, /* / */
1897
+ CHAR_LEFT_CURLY_BRACE, /* { */
1898
+ CHAR_LEFT_PARENTHESES, /* ( */
1899
+ CHAR_LEFT_SQUARE_BRACKET, /* [ */
1900
+ CHAR_PLUS, /* + */
1901
+ CHAR_QUESTION_MARK, /* ? */
1902
+ CHAR_RIGHT_CURLY_BRACE, /* } */
1903
+ CHAR_RIGHT_PARENTHESES, /* ) */
1904
+ CHAR_RIGHT_SQUARE_BRACKET /* ] */
1905
+ } = requireConstants();
1906
+
1907
+ const isPathSeparator = code => {
1908
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
1909
+ };
1910
+
1911
+ const depth = token => {
1912
+ if (token.isPrefix !== true) {
1913
+ token.depth = token.isGlobstar ? Infinity : 1;
1914
+ }
1915
+ };
1916
+
1917
+ /**
1918
+ * Quickly scans a glob pattern and returns an object with a handful of
1919
+ * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
1920
+ * `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
1921
+ * with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
1922
+ *
1923
+ * ```js
1924
+ * const pm = require('picomatch');
1925
+ * console.log(pm.scan('foo/bar/*.js'));
1926
+ * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
1927
+ * ```
1928
+ * @param {String} `str`
1929
+ * @param {Object} `options`
1930
+ * @return {Object} Returns an object with tokens and regex source string.
1931
+ * @api public
1932
+ */
1933
+
1934
+ const scan = (input, options) => {
1935
+ const opts = options || {};
1936
+
1937
+ const length = input.length - 1;
1938
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
1939
+ const slashes = [];
1940
+ const tokens = [];
1941
+ const parts = [];
1942
+
1943
+ let str = input;
1944
+ let index = -1;
1945
+ let start = 0;
1946
+ let lastIndex = 0;
1947
+ let isBrace = false;
1948
+ let isBracket = false;
1949
+ let isGlob = false;
1950
+ let isExtglob = false;
1951
+ let isGlobstar = false;
1952
+ let braceEscaped = false;
1953
+ let backslashes = false;
1954
+ let negated = false;
1955
+ let negatedExtglob = false;
1956
+ let finished = false;
1957
+ let braces = 0;
1958
+ let prev;
1959
+ let code;
1960
+ let token = { value: '', depth: 0, isGlob: false };
1961
+
1962
+ const eos = () => index >= length;
1963
+ const peek = () => str.charCodeAt(index + 1);
1964
+ const advance = () => {
1965
+ prev = code;
1966
+ return str.charCodeAt(++index);
1967
+ };
1968
+
1969
+ while (index < length) {
1970
+ code = advance();
1971
+ let next;
1972
+
1973
+ if (code === CHAR_BACKWARD_SLASH) {
1974
+ backslashes = token.backslashes = true;
1975
+ code = advance();
1976
+
1977
+ if (code === CHAR_LEFT_CURLY_BRACE) {
1978
+ braceEscaped = true;
1979
+ }
1980
+ continue;
1981
+ }
1982
+
1983
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
1984
+ braces++;
1985
+
1986
+ while (eos() !== true && (code = advance())) {
1987
+ if (code === CHAR_BACKWARD_SLASH) {
1988
+ backslashes = token.backslashes = true;
1989
+ advance();
1990
+ continue;
1991
+ }
1992
+
1993
+ if (code === CHAR_LEFT_CURLY_BRACE) {
1994
+ braces++;
1995
+ continue;
1996
+ }
1997
+
1998
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
1999
+ isBrace = token.isBrace = true;
2000
+ isGlob = token.isGlob = true;
2001
+ finished = true;
2002
+
2003
+ if (scanToEnd === true) {
2004
+ continue;
2005
+ }
2006
+
2007
+ break;
2008
+ }
2009
+
2010
+ if (braceEscaped !== true && code === CHAR_COMMA) {
2011
+ isBrace = token.isBrace = true;
2012
+ isGlob = token.isGlob = true;
2013
+ finished = true;
2014
+
2015
+ if (scanToEnd === true) {
2016
+ continue;
2017
+ }
2018
+
2019
+ break;
2020
+ }
2021
+
2022
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
2023
+ braces--;
2024
+
2025
+ if (braces === 0) {
2026
+ braceEscaped = false;
2027
+ isBrace = token.isBrace = true;
2028
+ finished = true;
2029
+ break;
2030
+ }
2031
+ }
2032
+ }
2033
+
2034
+ if (scanToEnd === true) {
2035
+ continue;
2036
+ }
2037
+
2038
+ break;
2039
+ }
2040
+
2041
+ if (code === CHAR_FORWARD_SLASH) {
2042
+ slashes.push(index);
2043
+ tokens.push(token);
2044
+ token = { value: '', depth: 0, isGlob: false };
2045
+
2046
+ if (finished === true) continue;
2047
+ if (prev === CHAR_DOT && index === (start + 1)) {
2048
+ start += 2;
2049
+ continue;
2050
+ }
2051
+
2052
+ lastIndex = index + 1;
2053
+ continue;
2054
+ }
2055
+
2056
+ if (opts.noext !== true) {
2057
+ const isExtglobChar = code === CHAR_PLUS
2058
+ || code === CHAR_AT
2059
+ || code === CHAR_ASTERISK
2060
+ || code === CHAR_QUESTION_MARK
2061
+ || code === CHAR_EXCLAMATION_MARK;
2062
+
2063
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
2064
+ isGlob = token.isGlob = true;
2065
+ isExtglob = token.isExtglob = true;
2066
+ finished = true;
2067
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
2068
+ negatedExtglob = true;
2069
+ }
2070
+
2071
+ if (scanToEnd === true) {
2072
+ while (eos() !== true && (code = advance())) {
2073
+ if (code === CHAR_BACKWARD_SLASH) {
2074
+ backslashes = token.backslashes = true;
2075
+ code = advance();
2076
+ continue;
2077
+ }
2078
+
2079
+ if (code === CHAR_RIGHT_PARENTHESES) {
2080
+ isGlob = token.isGlob = true;
2081
+ finished = true;
2082
+ break;
2083
+ }
2084
+ }
2085
+ continue;
2086
+ }
2087
+ break;
2088
+ }
2089
+ }
2090
+
2091
+ if (code === CHAR_ASTERISK) {
2092
+ if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
2093
+ isGlob = token.isGlob = true;
2094
+ finished = true;
2095
+
2096
+ if (scanToEnd === true) {
2097
+ continue;
2098
+ }
2099
+ break;
2100
+ }
2101
+
2102
+ if (code === CHAR_QUESTION_MARK) {
2103
+ isGlob = token.isGlob = true;
2104
+ finished = true;
2105
+
2106
+ if (scanToEnd === true) {
2107
+ continue;
2108
+ }
2109
+ break;
2110
+ }
2111
+
2112
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
2113
+ while (eos() !== true && (next = advance())) {
2114
+ if (next === CHAR_BACKWARD_SLASH) {
2115
+ backslashes = token.backslashes = true;
2116
+ advance();
2117
+ continue;
2118
+ }
2119
+
2120
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
2121
+ isBracket = token.isBracket = true;
2122
+ isGlob = token.isGlob = true;
2123
+ finished = true;
2124
+ break;
2125
+ }
2126
+ }
2127
+
2128
+ if (scanToEnd === true) {
2129
+ continue;
2130
+ }
2131
+
2132
+ break;
2133
+ }
2134
+
2135
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
2136
+ negated = token.negated = true;
2137
+ start++;
2138
+ continue;
2139
+ }
2140
+
2141
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
2142
+ isGlob = token.isGlob = true;
2143
+
2144
+ if (scanToEnd === true) {
2145
+ while (eos() !== true && (code = advance())) {
2146
+ if (code === CHAR_LEFT_PARENTHESES) {
2147
+ backslashes = token.backslashes = true;
2148
+ code = advance();
2149
+ continue;
2150
+ }
2151
+
2152
+ if (code === CHAR_RIGHT_PARENTHESES) {
2153
+ finished = true;
2154
+ break;
2155
+ }
2156
+ }
2157
+ continue;
2158
+ }
2159
+ break;
2160
+ }
2161
+
2162
+ if (isGlob === true) {
2163
+ finished = true;
2164
+
2165
+ if (scanToEnd === true) {
2166
+ continue;
2167
+ }
2168
+
2169
+ break;
2170
+ }
2171
+ }
2172
+
2173
+ if (opts.noext === true) {
2174
+ isExtglob = false;
2175
+ isGlob = false;
2176
+ }
2177
+
2178
+ let base = str;
2179
+ let prefix = '';
2180
+ let glob = '';
2181
+
2182
+ if (start > 0) {
2183
+ prefix = str.slice(0, start);
2184
+ str = str.slice(start);
2185
+ lastIndex -= start;
2186
+ }
2187
+
2188
+ if (base && isGlob === true && lastIndex > 0) {
2189
+ base = str.slice(0, lastIndex);
2190
+ glob = str.slice(lastIndex);
2191
+ } else if (isGlob === true) {
2192
+ base = '';
2193
+ glob = str;
2194
+ } else {
2195
+ base = str;
2196
+ }
2197
+
2198
+ if (base && base !== '' && base !== '/' && base !== str) {
2199
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
2200
+ base = base.slice(0, -1);
2201
+ }
2202
+ }
2203
+
2204
+ if (opts.unescape === true) {
2205
+ if (glob) glob = utils.removeBackslashes(glob);
2206
+
2207
+ if (base && backslashes === true) {
2208
+ base = utils.removeBackslashes(base);
2209
+ }
2210
+ }
2211
+
2212
+ const state = {
2213
+ prefix,
2214
+ input,
2215
+ start,
2216
+ base,
2217
+ glob,
2218
+ isBrace,
2219
+ isBracket,
2220
+ isGlob,
2221
+ isExtglob,
2222
+ isGlobstar,
2223
+ negated,
2224
+ negatedExtglob
2225
+ };
2226
+
2227
+ if (opts.tokens === true) {
2228
+ state.maxDepth = 0;
2229
+ if (!isPathSeparator(code)) {
2230
+ tokens.push(token);
2231
+ }
2232
+ state.tokens = tokens;
2233
+ }
2234
+
2235
+ if (opts.parts === true || opts.tokens === true) {
2236
+ let prevIndex;
2237
+
2238
+ for (let idx = 0; idx < slashes.length; idx++) {
2239
+ const n = prevIndex ? prevIndex + 1 : start;
2240
+ const i = slashes[idx];
2241
+ const value = input.slice(n, i);
2242
+ if (opts.tokens) {
2243
+ if (idx === 0 && start !== 0) {
2244
+ tokens[idx].isPrefix = true;
2245
+ tokens[idx].value = prefix;
2246
+ } else {
2247
+ tokens[idx].value = value;
2248
+ }
2249
+ depth(tokens[idx]);
2250
+ state.maxDepth += tokens[idx].depth;
2251
+ }
2252
+ if (idx !== 0 || value !== '') {
2253
+ parts.push(value);
2254
+ }
2255
+ prevIndex = i;
2256
+ }
2257
+
2258
+ if (prevIndex && prevIndex + 1 < input.length) {
2259
+ const value = input.slice(prevIndex + 1);
2260
+ parts.push(value);
2261
+
2262
+ if (opts.tokens) {
2263
+ tokens[tokens.length - 1].value = value;
2264
+ depth(tokens[tokens.length - 1]);
2265
+ state.maxDepth += tokens[tokens.length - 1].depth;
2266
+ }
2267
+ }
2268
+
2269
+ state.slashes = slashes;
2270
+ state.parts = parts;
2271
+ }
2272
+
2273
+ return state;
2274
+ };
2275
+
2276
+ scan_1 = scan;
2277
+ return scan_1;
2278
+ }
2279
+
2280
+ var parse_1;
2281
+ var hasRequiredParse;
2282
+
2283
+ function requireParse () {
2284
+ if (hasRequiredParse) return parse_1;
2285
+ hasRequiredParse = 1;
2286
+
2287
+ const constants = requireConstants();
2288
+ const utils = requireUtils();
2289
+
2290
+ /**
2291
+ * Constants
2292
+ */
2293
+
2294
+ const {
2295
+ MAX_LENGTH,
2296
+ POSIX_REGEX_SOURCE,
2297
+ REGEX_NON_SPECIAL_CHARS,
2298
+ REGEX_SPECIAL_CHARS_BACKREF,
2299
+ REPLACEMENTS
2300
+ } = constants;
2301
+
2302
+ /**
2303
+ * Helpers
2304
+ */
2305
+
2306
+ const expandRange = (args, options) => {
2307
+ if (typeof options.expandRange === 'function') {
2308
+ return options.expandRange(...args, options);
2309
+ }
2310
+
2311
+ args.sort();
2312
+ const value = `[${args.join('-')}]`;
2313
+
2314
+ try {
2315
+ /* eslint-disable-next-line no-new */
2316
+ new RegExp(value);
2317
+ } catch (ex) {
2318
+ return args.map(v => utils.escapeRegex(v)).join('..');
2319
+ }
2320
+
2321
+ return value;
2322
+ };
2323
+
2324
+ /**
2325
+ * Create the message for a syntax error
2326
+ */
2327
+
2328
+ const syntaxError = (type, char) => {
2329
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
2330
+ };
2331
+
2332
+ /**
2333
+ * Parse the given input string.
2334
+ * @param {String} input
2335
+ * @param {Object} options
2336
+ * @return {Object}
2337
+ */
2338
+
2339
+ const parse = (input, options) => {
2340
+ if (typeof input !== 'string') {
2341
+ throw new TypeError('Expected a string');
2342
+ }
2343
+
2344
+ input = REPLACEMENTS[input] || input;
2345
+
2346
+ const opts = { ...options };
2347
+ const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
2348
+
2349
+ let len = input.length;
2350
+ if (len > max) {
2351
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
2352
+ }
2353
+
2354
+ const bos = { type: 'bos', value: '', output: opts.prepend || '' };
2355
+ const tokens = [bos];
2356
+
2357
+ const capture = opts.capture ? '' : '?:';
2358
+ const win32 = utils.isWindows(options);
2359
+
2360
+ // create constants based on platform, for windows or posix
2361
+ const PLATFORM_CHARS = constants.globChars(win32);
2362
+ const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
2363
+
2364
+ const {
2365
+ DOT_LITERAL,
2366
+ PLUS_LITERAL,
2367
+ SLASH_LITERAL,
2368
+ ONE_CHAR,
2369
+ DOTS_SLASH,
2370
+ NO_DOT,
2371
+ NO_DOT_SLASH,
2372
+ NO_DOTS_SLASH,
2373
+ QMARK,
2374
+ QMARK_NO_DOT,
2375
+ STAR,
2376
+ START_ANCHOR
2377
+ } = PLATFORM_CHARS;
2378
+
2379
+ const globstar = opts => {
2380
+ return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
2381
+ };
2382
+
2383
+ const nodot = opts.dot ? '' : NO_DOT;
2384
+ const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
2385
+ let star = opts.bash === true ? globstar(opts) : STAR;
2386
+
2387
+ if (opts.capture) {
2388
+ star = `(${star})`;
2389
+ }
2390
+
2391
+ // minimatch options support
2392
+ if (typeof opts.noext === 'boolean') {
2393
+ opts.noextglob = opts.noext;
2394
+ }
2395
+
2396
+ const state = {
2397
+ input,
2398
+ index: -1,
2399
+ start: 0,
2400
+ dot: opts.dot === true,
2401
+ consumed: '',
2402
+ output: '',
2403
+ prefix: '',
2404
+ backtrack: false,
2405
+ negated: false,
2406
+ brackets: 0,
2407
+ braces: 0,
2408
+ parens: 0,
2409
+ quotes: 0,
2410
+ globstar: false,
2411
+ tokens
2412
+ };
2413
+
2414
+ input = utils.removePrefix(input, state);
2415
+ len = input.length;
2416
+
2417
+ const extglobs = [];
2418
+ const braces = [];
2419
+ const stack = [];
2420
+ let prev = bos;
2421
+ let value;
2422
+
2423
+ /**
2424
+ * Tokenizing helpers
2425
+ */
2426
+
2427
+ const eos = () => state.index === len - 1;
2428
+ const peek = state.peek = (n = 1) => input[state.index + n];
2429
+ const advance = state.advance = () => input[++state.index] || '';
2430
+ const remaining = () => input.slice(state.index + 1);
2431
+ const consume = (value = '', num = 0) => {
2432
+ state.consumed += value;
2433
+ state.index += num;
2434
+ };
2435
+
2436
+ const append = token => {
2437
+ state.output += token.output != null ? token.output : token.value;
2438
+ consume(token.value);
2439
+ };
2440
+
2441
+ const negate = () => {
2442
+ let count = 1;
2443
+
2444
+ while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
2445
+ advance();
2446
+ state.start++;
2447
+ count++;
2448
+ }
2449
+
2450
+ if (count % 2 === 0) {
2451
+ return false;
2452
+ }
2453
+
2454
+ state.negated = true;
2455
+ state.start++;
2456
+ return true;
2457
+ };
2458
+
2459
+ const increment = type => {
2460
+ state[type]++;
2461
+ stack.push(type);
2462
+ };
2463
+
2464
+ const decrement = type => {
2465
+ state[type]--;
2466
+ stack.pop();
2467
+ };
2468
+
2469
+ /**
2470
+ * Push tokens onto the tokens array. This helper speeds up
2471
+ * tokenizing by 1) helping us avoid backtracking as much as possible,
2472
+ * and 2) helping us avoid creating extra tokens when consecutive
2473
+ * characters are plain text. This improves performance and simplifies
2474
+ * lookbehinds.
2475
+ */
2476
+
2477
+ const push = tok => {
2478
+ if (prev.type === 'globstar') {
2479
+ const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
2480
+ const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
2481
+
2482
+ if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
2483
+ state.output = state.output.slice(0, -prev.output.length);
2484
+ prev.type = 'star';
2485
+ prev.value = '*';
2486
+ prev.output = star;
2487
+ state.output += prev.output;
2488
+ }
2489
+ }
2490
+
2491
+ if (extglobs.length && tok.type !== 'paren') {
2492
+ extglobs[extglobs.length - 1].inner += tok.value;
2493
+ }
2494
+
2495
+ if (tok.value || tok.output) append(tok);
2496
+ if (prev && prev.type === 'text' && tok.type === 'text') {
2497
+ prev.value += tok.value;
2498
+ prev.output = (prev.output || '') + tok.value;
2499
+ return;
2500
+ }
2501
+
2502
+ tok.prev = prev;
2503
+ tokens.push(tok);
2504
+ prev = tok;
2505
+ };
2506
+
2507
+ const extglobOpen = (type, value) => {
2508
+ const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
2509
+
2510
+ token.prev = prev;
2511
+ token.parens = state.parens;
2512
+ token.output = state.output;
2513
+ const output = (opts.capture ? '(' : '') + token.open;
2514
+
2515
+ increment('parens');
2516
+ push({ type, value, output: state.output ? '' : ONE_CHAR });
2517
+ push({ type: 'paren', extglob: true, value: advance(), output });
2518
+ extglobs.push(token);
2519
+ };
2520
+
2521
+ const extglobClose = token => {
2522
+ let output = token.close + (opts.capture ? ')' : '');
2523
+ let rest;
2524
+
2525
+ if (token.type === 'negate') {
2526
+ let extglobStar = star;
2527
+
2528
+ if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
2529
+ extglobStar = globstar(opts);
2530
+ }
2531
+
2532
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
2533
+ output = token.close = `)$))${extglobStar}`;
2534
+ }
2535
+
2536
+ if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
2537
+ // Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
2538
+ // In this case, we need to parse the string and use it in the output of the original pattern.
2539
+ // Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
2540
+ //
2541
+ // Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
2542
+ const expression = parse(rest, { ...options, fastpaths: false }).output;
2543
+
2544
+ output = token.close = `)${expression})${extglobStar})`;
2545
+ }
2546
+
2547
+ if (token.prev.type === 'bos') {
2548
+ state.negatedExtglob = true;
2549
+ }
2550
+ }
2551
+
2552
+ push({ type: 'paren', extglob: true, value, output });
2553
+ decrement('parens');
2554
+ };
2555
+
2556
+ /**
2557
+ * Fast paths
2558
+ */
2559
+
2560
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
2561
+ let backslashes = false;
2562
+
2563
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
2564
+ if (first === '\\') {
2565
+ backslashes = true;
2566
+ return m;
2567
+ }
2568
+
2569
+ if (first === '?') {
2570
+ if (esc) {
2571
+ return esc + first + (rest ? QMARK.repeat(rest.length) : '');
2572
+ }
2573
+ if (index === 0) {
2574
+ return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
2575
+ }
2576
+ return QMARK.repeat(chars.length);
2577
+ }
2578
+
2579
+ if (first === '.') {
2580
+ return DOT_LITERAL.repeat(chars.length);
2581
+ }
2582
+
2583
+ if (first === '*') {
2584
+ if (esc) {
2585
+ return esc + first + (rest ? star : '');
2586
+ }
2587
+ return star;
2588
+ }
2589
+ return esc ? m : `\\${m}`;
2590
+ });
2591
+
2592
+ if (backslashes === true) {
2593
+ if (opts.unescape === true) {
2594
+ output = output.replace(/\\/g, '');
2595
+ } else {
2596
+ output = output.replace(/\\+/g, m => {
2597
+ return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
2598
+ });
2599
+ }
2600
+ }
2601
+
2602
+ if (output === input && opts.contains === true) {
2603
+ state.output = input;
2604
+ return state;
2605
+ }
2606
+
2607
+ state.output = utils.wrapOutput(output, state, options);
2608
+ return state;
2609
+ }
2610
+
2611
+ /**
2612
+ * Tokenize input until we reach end-of-string
2613
+ */
2614
+
2615
+ while (!eos()) {
2616
+ value = advance();
2617
+
2618
+ if (value === '\u0000') {
2619
+ continue;
2620
+ }
2621
+
2622
+ /**
2623
+ * Escaped characters
2624
+ */
2625
+
2626
+ if (value === '\\') {
2627
+ const next = peek();
2628
+
2629
+ if (next === '/' && opts.bash !== true) {
2630
+ continue;
2631
+ }
2632
+
2633
+ if (next === '.' || next === ';') {
2634
+ continue;
2635
+ }
2636
+
2637
+ if (!next) {
2638
+ value += '\\';
2639
+ push({ type: 'text', value });
2640
+ continue;
2641
+ }
2642
+
2643
+ // collapse slashes to reduce potential for exploits
2644
+ const match = /^\\+/.exec(remaining());
2645
+ let slashes = 0;
2646
+
2647
+ if (match && match[0].length > 2) {
2648
+ slashes = match[0].length;
2649
+ state.index += slashes;
2650
+ if (slashes % 2 !== 0) {
2651
+ value += '\\';
2652
+ }
2653
+ }
2654
+
2655
+ if (opts.unescape === true) {
2656
+ value = advance();
2657
+ } else {
2658
+ value += advance();
2659
+ }
2660
+
2661
+ if (state.brackets === 0) {
2662
+ push({ type: 'text', value });
2663
+ continue;
2664
+ }
2665
+ }
2666
+
2667
+ /**
2668
+ * If we're inside a regex character class, continue
2669
+ * until we reach the closing bracket.
2670
+ */
2671
+
2672
+ if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
2673
+ if (opts.posix !== false && value === ':') {
2674
+ const inner = prev.value.slice(1);
2675
+ if (inner.includes('[')) {
2676
+ prev.posix = true;
2677
+
2678
+ if (inner.includes(':')) {
2679
+ const idx = prev.value.lastIndexOf('[');
2680
+ const pre = prev.value.slice(0, idx);
2681
+ const rest = prev.value.slice(idx + 2);
2682
+ const posix = POSIX_REGEX_SOURCE[rest];
2683
+ if (posix) {
2684
+ prev.value = pre + posix;
2685
+ state.backtrack = true;
2686
+ advance();
2687
+
2688
+ if (!bos.output && tokens.indexOf(prev) === 1) {
2689
+ bos.output = ONE_CHAR;
2690
+ }
2691
+ continue;
2692
+ }
2693
+ }
2694
+ }
2695
+ }
2696
+
2697
+ if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
2698
+ value = `\\${value}`;
2699
+ }
2700
+
2701
+ if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
2702
+ value = `\\${value}`;
2703
+ }
2704
+
2705
+ if (opts.posix === true && value === '!' && prev.value === '[') {
2706
+ value = '^';
2707
+ }
2708
+
2709
+ prev.value += value;
2710
+ append({ value });
2711
+ continue;
2712
+ }
2713
+
2714
+ /**
2715
+ * If we're inside a quoted string, continue
2716
+ * until we reach the closing double quote.
2717
+ */
2718
+
2719
+ if (state.quotes === 1 && value !== '"') {
2720
+ value = utils.escapeRegex(value);
2721
+ prev.value += value;
2722
+ append({ value });
2723
+ continue;
2724
+ }
2725
+
2726
+ /**
2727
+ * Double quotes
2728
+ */
2729
+
2730
+ if (value === '"') {
2731
+ state.quotes = state.quotes === 1 ? 0 : 1;
2732
+ if (opts.keepQuotes === true) {
2733
+ push({ type: 'text', value });
2734
+ }
2735
+ continue;
2736
+ }
2737
+
2738
+ /**
2739
+ * Parentheses
2740
+ */
2741
+
2742
+ if (value === '(') {
2743
+ increment('parens');
2744
+ push({ type: 'paren', value });
2745
+ continue;
2746
+ }
2747
+
2748
+ if (value === ')') {
2749
+ if (state.parens === 0 && opts.strictBrackets === true) {
2750
+ throw new SyntaxError(syntaxError('opening', '('));
2751
+ }
2752
+
2753
+ const extglob = extglobs[extglobs.length - 1];
2754
+ if (extglob && state.parens === extglob.parens + 1) {
2755
+ extglobClose(extglobs.pop());
2756
+ continue;
2757
+ }
2758
+
2759
+ push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
2760
+ decrement('parens');
2761
+ continue;
2762
+ }
2763
+
2764
+ /**
2765
+ * Square brackets
2766
+ */
2767
+
2768
+ if (value === '[') {
2769
+ if (opts.nobracket === true || !remaining().includes(']')) {
2770
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
2771
+ throw new SyntaxError(syntaxError('closing', ']'));
2772
+ }
2773
+
2774
+ value = `\\${value}`;
2775
+ } else {
2776
+ increment('brackets');
2777
+ }
2778
+
2779
+ push({ type: 'bracket', value });
2780
+ continue;
2781
+ }
2782
+
2783
+ if (value === ']') {
2784
+ if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
2785
+ push({ type: 'text', value, output: `\\${value}` });
2786
+ continue;
2787
+ }
2788
+
2789
+ if (state.brackets === 0) {
2790
+ if (opts.strictBrackets === true) {
2791
+ throw new SyntaxError(syntaxError('opening', '['));
2792
+ }
2793
+
2794
+ push({ type: 'text', value, output: `\\${value}` });
2795
+ continue;
2796
+ }
2797
+
2798
+ decrement('brackets');
2799
+
2800
+ const prevValue = prev.value.slice(1);
2801
+ if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
2802
+ value = `/${value}`;
2803
+ }
2804
+
2805
+ prev.value += value;
2806
+ append({ value });
2807
+
2808
+ // when literal brackets are explicitly disabled
2809
+ // assume we should match with a regex character class
2810
+ if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
2811
+ continue;
2812
+ }
2813
+
2814
+ const escaped = utils.escapeRegex(prev.value);
2815
+ state.output = state.output.slice(0, -prev.value.length);
2816
+
2817
+ // when literal brackets are explicitly enabled
2818
+ // assume we should escape the brackets to match literal characters
2819
+ if (opts.literalBrackets === true) {
2820
+ state.output += escaped;
2821
+ prev.value = escaped;
2822
+ continue;
2823
+ }
2824
+
2825
+ // when the user specifies nothing, try to match both
2826
+ prev.value = `(${capture}${escaped}|${prev.value})`;
2827
+ state.output += prev.value;
2828
+ continue;
2829
+ }
2830
+
2831
+ /**
2832
+ * Braces
2833
+ */
2834
+
2835
+ if (value === '{' && opts.nobrace !== true) {
2836
+ increment('braces');
2837
+
2838
+ const open = {
2839
+ type: 'brace',
2840
+ value,
2841
+ output: '(',
2842
+ outputIndex: state.output.length,
2843
+ tokensIndex: state.tokens.length
2844
+ };
2845
+
2846
+ braces.push(open);
2847
+ push(open);
2848
+ continue;
2849
+ }
2850
+
2851
+ if (value === '}') {
2852
+ const brace = braces[braces.length - 1];
2853
+
2854
+ if (opts.nobrace === true || !brace) {
2855
+ push({ type: 'text', value, output: value });
2856
+ continue;
2857
+ }
2858
+
2859
+ let output = ')';
2860
+
2861
+ if (brace.dots === true) {
2862
+ const arr = tokens.slice();
2863
+ const range = [];
2864
+
2865
+ for (let i = arr.length - 1; i >= 0; i--) {
2866
+ tokens.pop();
2867
+ if (arr[i].type === 'brace') {
2868
+ break;
2869
+ }
2870
+ if (arr[i].type !== 'dots') {
2871
+ range.unshift(arr[i].value);
2872
+ }
2873
+ }
2874
+
2875
+ output = expandRange(range, opts);
2876
+ state.backtrack = true;
2877
+ }
2878
+
2879
+ if (brace.comma !== true && brace.dots !== true) {
2880
+ const out = state.output.slice(0, brace.outputIndex);
2881
+ const toks = state.tokens.slice(brace.tokensIndex);
2882
+ brace.value = brace.output = '\\{';
2883
+ value = output = '\\}';
2884
+ state.output = out;
2885
+ for (const t of toks) {
2886
+ state.output += (t.output || t.value);
2887
+ }
2888
+ }
2889
+
2890
+ push({ type: 'brace', value, output });
2891
+ decrement('braces');
2892
+ braces.pop();
2893
+ continue;
2894
+ }
2895
+
2896
+ /**
2897
+ * Pipes
2898
+ */
2899
+
2900
+ if (value === '|') {
2901
+ if (extglobs.length > 0) {
2902
+ extglobs[extglobs.length - 1].conditions++;
2903
+ }
2904
+ push({ type: 'text', value });
2905
+ continue;
2906
+ }
2907
+
2908
+ /**
2909
+ * Commas
2910
+ */
2911
+
2912
+ if (value === ',') {
2913
+ let output = value;
2914
+
2915
+ const brace = braces[braces.length - 1];
2916
+ if (brace && stack[stack.length - 1] === 'braces') {
2917
+ brace.comma = true;
2918
+ output = '|';
2919
+ }
2920
+
2921
+ push({ type: 'comma', value, output });
2922
+ continue;
2923
+ }
2924
+
2925
+ /**
2926
+ * Slashes
2927
+ */
2928
+
2929
+ if (value === '/') {
2930
+ // if the beginning of the glob is "./", advance the start
2931
+ // to the current index, and don't add the "./" characters
2932
+ // to the state. This greatly simplifies lookbehinds when
2933
+ // checking for BOS characters like "!" and "." (not "./")
2934
+ if (prev.type === 'dot' && state.index === state.start + 1) {
2935
+ state.start = state.index + 1;
2936
+ state.consumed = '';
2937
+ state.output = '';
2938
+ tokens.pop();
2939
+ prev = bos; // reset "prev" to the first token
2940
+ continue;
2941
+ }
2942
+
2943
+ push({ type: 'slash', value, output: SLASH_LITERAL });
2944
+ continue;
2945
+ }
2946
+
2947
+ /**
2948
+ * Dots
2949
+ */
2950
+
2951
+ if (value === '.') {
2952
+ if (state.braces > 0 && prev.type === 'dot') {
2953
+ if (prev.value === '.') prev.output = DOT_LITERAL;
2954
+ const brace = braces[braces.length - 1];
2955
+ prev.type = 'dots';
2956
+ prev.output += value;
2957
+ prev.value += value;
2958
+ brace.dots = true;
2959
+ continue;
2960
+ }
2961
+
2962
+ if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
2963
+ push({ type: 'text', value, output: DOT_LITERAL });
2964
+ continue;
2965
+ }
2966
+
2967
+ push({ type: 'dot', value, output: DOT_LITERAL });
2968
+ continue;
2969
+ }
2970
+
2971
+ /**
2972
+ * Question marks
2973
+ */
2974
+
2975
+ if (value === '?') {
2976
+ const isGroup = prev && prev.value === '(';
2977
+ if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
2978
+ extglobOpen('qmark', value);
2979
+ continue;
2980
+ }
2981
+
2982
+ if (prev && prev.type === 'paren') {
2983
+ const next = peek();
2984
+ let output = value;
2985
+
2986
+ if (next === '<' && !utils.supportsLookbehinds()) {
2987
+ throw new Error('Node.js v10 or higher is required for regex lookbehinds');
2988
+ }
2989
+
2990
+ if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
2991
+ output = `\\${value}`;
2992
+ }
2993
+
2994
+ push({ type: 'text', value, output });
2995
+ continue;
2996
+ }
2997
+
2998
+ if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
2999
+ push({ type: 'qmark', value, output: QMARK_NO_DOT });
3000
+ continue;
3001
+ }
3002
+
3003
+ push({ type: 'qmark', value, output: QMARK });
3004
+ continue;
3005
+ }
3006
+
3007
+ /**
3008
+ * Exclamation
3009
+ */
3010
+
3011
+ if (value === '!') {
3012
+ if (opts.noextglob !== true && peek() === '(') {
3013
+ if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
3014
+ extglobOpen('negate', value);
3015
+ continue;
3016
+ }
3017
+ }
3018
+
3019
+ if (opts.nonegate !== true && state.index === 0) {
3020
+ negate();
3021
+ continue;
3022
+ }
3023
+ }
3024
+
3025
+ /**
3026
+ * Plus
3027
+ */
3028
+
3029
+ if (value === '+') {
3030
+ if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
3031
+ extglobOpen('plus', value);
3032
+ continue;
3033
+ }
3034
+
3035
+ if ((prev && prev.value === '(') || opts.regex === false) {
3036
+ push({ type: 'plus', value, output: PLUS_LITERAL });
3037
+ continue;
3038
+ }
3039
+
3040
+ if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
3041
+ push({ type: 'plus', value });
3042
+ continue;
3043
+ }
3044
+
3045
+ push({ type: 'plus', value: PLUS_LITERAL });
3046
+ continue;
3047
+ }
3048
+
3049
+ /**
3050
+ * Plain text
3051
+ */
3052
+
3053
+ if (value === '@') {
3054
+ if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
3055
+ push({ type: 'at', extglob: true, value, output: '' });
3056
+ continue;
3057
+ }
3058
+
3059
+ push({ type: 'text', value });
3060
+ continue;
3061
+ }
3062
+
3063
+ /**
3064
+ * Plain text
3065
+ */
3066
+
3067
+ if (value !== '*') {
3068
+ if (value === '$' || value === '^') {
3069
+ value = `\\${value}`;
3070
+ }
3071
+
3072
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
3073
+ if (match) {
3074
+ value += match[0];
3075
+ state.index += match[0].length;
3076
+ }
3077
+
3078
+ push({ type: 'text', value });
3079
+ continue;
3080
+ }
3081
+
3082
+ /**
3083
+ * Stars
3084
+ */
3085
+
3086
+ if (prev && (prev.type === 'globstar' || prev.star === true)) {
3087
+ prev.type = 'star';
3088
+ prev.star = true;
3089
+ prev.value += value;
3090
+ prev.output = star;
3091
+ state.backtrack = true;
3092
+ state.globstar = true;
3093
+ consume(value);
3094
+ continue;
3095
+ }
3096
+
3097
+ let rest = remaining();
3098
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
3099
+ extglobOpen('star', value);
3100
+ continue;
3101
+ }
3102
+
3103
+ if (prev.type === 'star') {
3104
+ if (opts.noglobstar === true) {
3105
+ consume(value);
3106
+ continue;
3107
+ }
3108
+
3109
+ const prior = prev.prev;
3110
+ const before = prior.prev;
3111
+ const isStart = prior.type === 'slash' || prior.type === 'bos';
3112
+ const afterStar = before && (before.type === 'star' || before.type === 'globstar');
3113
+
3114
+ if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
3115
+ push({ type: 'star', value, output: '' });
3116
+ continue;
3117
+ }
3118
+
3119
+ const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
3120
+ const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
3121
+ if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
3122
+ push({ type: 'star', value, output: '' });
3123
+ continue;
3124
+ }
3125
+
3126
+ // strip consecutive `/**/`
3127
+ while (rest.slice(0, 3) === '/**') {
3128
+ const after = input[state.index + 4];
3129
+ if (after && after !== '/') {
3130
+ break;
3131
+ }
3132
+ rest = rest.slice(3);
3133
+ consume('/**', 3);
3134
+ }
3135
+
3136
+ if (prior.type === 'bos' && eos()) {
3137
+ prev.type = 'globstar';
3138
+ prev.value += value;
3139
+ prev.output = globstar(opts);
3140
+ state.output = prev.output;
3141
+ state.globstar = true;
3142
+ consume(value);
3143
+ continue;
3144
+ }
3145
+
3146
+ if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
3147
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
3148
+ prior.output = `(?:${prior.output}`;
3149
+
3150
+ prev.type = 'globstar';
3151
+ prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
3152
+ prev.value += value;
3153
+ state.globstar = true;
3154
+ state.output += prior.output + prev.output;
3155
+ consume(value);
3156
+ continue;
3157
+ }
3158
+
3159
+ if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
3160
+ const end = rest[1] !== void 0 ? '|$' : '';
3161
+
3162
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
3163
+ prior.output = `(?:${prior.output}`;
3164
+
3165
+ prev.type = 'globstar';
3166
+ prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
3167
+ prev.value += value;
3168
+
3169
+ state.output += prior.output + prev.output;
3170
+ state.globstar = true;
3171
+
3172
+ consume(value + advance());
3173
+
3174
+ push({ type: 'slash', value: '/', output: '' });
3175
+ continue;
3176
+ }
3177
+
3178
+ if (prior.type === 'bos' && rest[0] === '/') {
3179
+ prev.type = 'globstar';
3180
+ prev.value += value;
3181
+ prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
3182
+ state.output = prev.output;
3183
+ state.globstar = true;
3184
+ consume(value + advance());
3185
+ push({ type: 'slash', value: '/', output: '' });
3186
+ continue;
3187
+ }
3188
+
3189
+ // remove single star from output
3190
+ state.output = state.output.slice(0, -prev.output.length);
3191
+
3192
+ // reset previous token to globstar
3193
+ prev.type = 'globstar';
3194
+ prev.output = globstar(opts);
3195
+ prev.value += value;
3196
+
3197
+ // reset output with globstar
3198
+ state.output += prev.output;
3199
+ state.globstar = true;
3200
+ consume(value);
3201
+ continue;
3202
+ }
3203
+
3204
+ const token = { type: 'star', value, output: star };
3205
+
3206
+ if (opts.bash === true) {
3207
+ token.output = '.*?';
3208
+ if (prev.type === 'bos' || prev.type === 'slash') {
3209
+ token.output = nodot + token.output;
3210
+ }
3211
+ push(token);
3212
+ continue;
3213
+ }
3214
+
3215
+ if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
3216
+ token.output = value;
3217
+ push(token);
3218
+ continue;
3219
+ }
3220
+
3221
+ if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
3222
+ if (prev.type === 'dot') {
3223
+ state.output += NO_DOT_SLASH;
3224
+ prev.output += NO_DOT_SLASH;
3225
+
3226
+ } else if (opts.dot === true) {
3227
+ state.output += NO_DOTS_SLASH;
3228
+ prev.output += NO_DOTS_SLASH;
3229
+
3230
+ } else {
3231
+ state.output += nodot;
3232
+ prev.output += nodot;
3233
+ }
3234
+
3235
+ if (peek() !== '*') {
3236
+ state.output += ONE_CHAR;
3237
+ prev.output += ONE_CHAR;
3238
+ }
3239
+ }
3240
+
3241
+ push(token);
3242
+ }
3243
+
3244
+ while (state.brackets > 0) {
3245
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
3246
+ state.output = utils.escapeLast(state.output, '[');
3247
+ decrement('brackets');
3248
+ }
3249
+
3250
+ while (state.parens > 0) {
3251
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
3252
+ state.output = utils.escapeLast(state.output, '(');
3253
+ decrement('parens');
3254
+ }
3255
+
3256
+ while (state.braces > 0) {
3257
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
3258
+ state.output = utils.escapeLast(state.output, '{');
3259
+ decrement('braces');
3260
+ }
3261
+
3262
+ if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
3263
+ push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
3264
+ }
3265
+
3266
+ // rebuild the output if we had to backtrack at any point
3267
+ if (state.backtrack === true) {
3268
+ state.output = '';
3269
+
3270
+ for (const token of state.tokens) {
3271
+ state.output += token.output != null ? token.output : token.value;
3272
+
3273
+ if (token.suffix) {
3274
+ state.output += token.suffix;
3275
+ }
3276
+ }
3277
+ }
3278
+
3279
+ return state;
3280
+ };
3281
+
3282
+ /**
3283
+ * Fast paths for creating regular expressions for common glob patterns.
3284
+ * This can significantly speed up processing and has very little downside
3285
+ * impact when none of the fast paths match.
3286
+ */
3287
+
3288
+ parse.fastpaths = (input, options) => {
3289
+ const opts = { ...options };
3290
+ const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
3291
+ const len = input.length;
3292
+ if (len > max) {
3293
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
3294
+ }
3295
+
3296
+ input = REPLACEMENTS[input] || input;
3297
+ const win32 = utils.isWindows(options);
3298
+
3299
+ // create constants based on platform, for windows or posix
3300
+ const {
3301
+ DOT_LITERAL,
3302
+ SLASH_LITERAL,
3303
+ ONE_CHAR,
3304
+ DOTS_SLASH,
3305
+ NO_DOT,
3306
+ NO_DOTS,
3307
+ NO_DOTS_SLASH,
3308
+ STAR,
3309
+ START_ANCHOR
3310
+ } = constants.globChars(win32);
3311
+
3312
+ const nodot = opts.dot ? NO_DOTS : NO_DOT;
3313
+ const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
3314
+ const capture = opts.capture ? '' : '?:';
3315
+ const state = { negated: false, prefix: '' };
3316
+ let star = opts.bash === true ? '.*?' : STAR;
3317
+
3318
+ if (opts.capture) {
3319
+ star = `(${star})`;
3320
+ }
3321
+
3322
+ const globstar = opts => {
3323
+ if (opts.noglobstar === true) return star;
3324
+ return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
3325
+ };
3326
+
3327
+ const create = str => {
3328
+ switch (str) {
3329
+ case '*':
3330
+ return `${nodot}${ONE_CHAR}${star}`;
3331
+
3332
+ case '.*':
3333
+ return `${DOT_LITERAL}${ONE_CHAR}${star}`;
3334
+
3335
+ case '*.*':
3336
+ return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
3337
+
3338
+ case '*/*':
3339
+ return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
3340
+
3341
+ case '**':
3342
+ return nodot + globstar(opts);
3343
+
3344
+ case '**/*':
3345
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
3346
+
3347
+ case '**/*.*':
3348
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
3349
+
3350
+ case '**/.*':
3351
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
3352
+
3353
+ default: {
3354
+ const match = /^(.*?)\.(\w+)$/.exec(str);
3355
+ if (!match) return;
3356
+
3357
+ const source = create(match[1]);
3358
+ if (!source) return;
3359
+
3360
+ return source + DOT_LITERAL + match[2];
3361
+ }
3362
+ }
3363
+ };
3364
+
3365
+ const output = utils.removePrefix(input, state);
3366
+ let source = create(output);
3367
+
3368
+ if (source && opts.strictSlashes !== true) {
3369
+ source += `${SLASH_LITERAL}?`;
3370
+ }
3371
+
3372
+ return source;
3373
+ };
3374
+
3375
+ parse_1 = parse;
3376
+ return parse_1;
3377
+ }
3378
+
3379
+ var picomatch_1;
3380
+ var hasRequiredPicomatch$1;
3381
+
3382
+ function requirePicomatch$1 () {
3383
+ if (hasRequiredPicomatch$1) return picomatch_1;
3384
+ hasRequiredPicomatch$1 = 1;
3385
+
3386
+ const path = require$$0$1;
3387
+ const scan = requireScan();
3388
+ const parse = requireParse();
3389
+ const utils = requireUtils();
3390
+ const constants = requireConstants();
3391
+ const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
3392
+
3393
+ /**
3394
+ * Creates a matcher function from one or more glob patterns. The
3395
+ * returned function takes a string to match as its first argument,
3396
+ * and returns true if the string is a match. The returned matcher
3397
+ * function also takes a boolean as the second argument that, when true,
3398
+ * returns an object with additional information.
3399
+ *
3400
+ * ```js
3401
+ * const picomatch = require('picomatch');
3402
+ * // picomatch(glob[, options]);
3403
+ *
3404
+ * const isMatch = picomatch('*.!(*a)');
3405
+ * console.log(isMatch('a.a')); //=> false
3406
+ * console.log(isMatch('a.b')); //=> true
3407
+ * ```
3408
+ * @name picomatch
3409
+ * @param {String|Array} `globs` One or more glob patterns.
3410
+ * @param {Object=} `options`
3411
+ * @return {Function=} Returns a matcher function.
3412
+ * @api public
3413
+ */
3414
+
3415
+ const picomatch = (glob, options, returnState = false) => {
3416
+ if (Array.isArray(glob)) {
3417
+ const fns = glob.map(input => picomatch(input, options, returnState));
3418
+ const arrayMatcher = str => {
3419
+ for (const isMatch of fns) {
3420
+ const state = isMatch(str);
3421
+ if (state) return state;
3422
+ }
3423
+ return false;
3424
+ };
3425
+ return arrayMatcher;
3426
+ }
3427
+
3428
+ const isState = isObject(glob) && glob.tokens && glob.input;
3429
+
3430
+ if (glob === '' || (typeof glob !== 'string' && !isState)) {
3431
+ throw new TypeError('Expected pattern to be a non-empty string');
3432
+ }
3433
+
3434
+ const opts = options || {};
3435
+ const posix = utils.isWindows(options);
3436
+ const regex = isState
3437
+ ? picomatch.compileRe(glob, options)
3438
+ : picomatch.makeRe(glob, options, false, true);
3439
+
3440
+ const state = regex.state;
3441
+ delete regex.state;
3442
+
3443
+ let isIgnored = () => false;
3444
+ if (opts.ignore) {
3445
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
3446
+ isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
3447
+ }
3448
+
3449
+ const matcher = (input, returnObject = false) => {
3450
+ const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
3451
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
3452
+
3453
+ if (typeof opts.onResult === 'function') {
3454
+ opts.onResult(result);
3455
+ }
3456
+
3457
+ if (isMatch === false) {
3458
+ result.isMatch = false;
3459
+ return returnObject ? result : false;
3460
+ }
3461
+
3462
+ if (isIgnored(input)) {
3463
+ if (typeof opts.onIgnore === 'function') {
3464
+ opts.onIgnore(result);
3465
+ }
3466
+ result.isMatch = false;
3467
+ return returnObject ? result : false;
3468
+ }
3469
+
3470
+ if (typeof opts.onMatch === 'function') {
3471
+ opts.onMatch(result);
3472
+ }
3473
+ return returnObject ? result : true;
3474
+ };
3475
+
3476
+ if (returnState) {
3477
+ matcher.state = state;
3478
+ }
3479
+
3480
+ return matcher;
3481
+ };
3482
+
3483
+ /**
3484
+ * Test `input` with the given `regex`. This is used by the main
3485
+ * `picomatch()` function to test the input string.
3486
+ *
3487
+ * ```js
3488
+ * const picomatch = require('picomatch');
3489
+ * // picomatch.test(input, regex[, options]);
3490
+ *
3491
+ * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
3492
+ * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
3493
+ * ```
3494
+ * @param {String} `input` String to test.
3495
+ * @param {RegExp} `regex`
3496
+ * @return {Object} Returns an object with matching info.
3497
+ * @api public
3498
+ */
3499
+
3500
+ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
3501
+ if (typeof input !== 'string') {
3502
+ throw new TypeError('Expected input to be a string');
3503
+ }
3504
+
3505
+ if (input === '') {
3506
+ return { isMatch: false, output: '' };
3507
+ }
3508
+
3509
+ const opts = options || {};
3510
+ const format = opts.format || (posix ? utils.toPosixSlashes : null);
3511
+ let match = input === glob;
3512
+ let output = (match && format) ? format(input) : input;
3513
+
3514
+ if (match === false) {
3515
+ output = format ? format(input) : input;
3516
+ match = output === glob;
3517
+ }
3518
+
3519
+ if (match === false || opts.capture === true) {
3520
+ if (opts.matchBase === true || opts.basename === true) {
3521
+ match = picomatch.matchBase(input, regex, options, posix);
3522
+ } else {
3523
+ match = regex.exec(output);
3524
+ }
3525
+ }
3526
+
3527
+ return { isMatch: Boolean(match), match, output };
3528
+ };
3529
+
3530
+ /**
3531
+ * Match the basename of a filepath.
3532
+ *
3533
+ * ```js
3534
+ * const picomatch = require('picomatch');
3535
+ * // picomatch.matchBase(input, glob[, options]);
3536
+ * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
3537
+ * ```
3538
+ * @param {String} `input` String to test.
3539
+ * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
3540
+ * @return {Boolean}
3541
+ * @api public
3542
+ */
3543
+
3544
+ picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
3545
+ const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
3546
+ return regex.test(path.basename(input));
3547
+ };
3548
+
3549
+ /**
3550
+ * Returns true if **any** of the given glob `patterns` match the specified `string`.
3551
+ *
3552
+ * ```js
3553
+ * const picomatch = require('picomatch');
3554
+ * // picomatch.isMatch(string, patterns[, options]);
3555
+ *
3556
+ * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
3557
+ * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
3558
+ * ```
3559
+ * @param {String|Array} str The string to test.
3560
+ * @param {String|Array} patterns One or more glob patterns to use for matching.
3561
+ * @param {Object} [options] See available [options](#options).
3562
+ * @return {Boolean} Returns true if any patterns match `str`
3563
+ * @api public
3564
+ */
3565
+
3566
+ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
3567
+
3568
+ /**
3569
+ * Parse a glob pattern to create the source string for a regular
3570
+ * expression.
3571
+ *
3572
+ * ```js
3573
+ * const picomatch = require('picomatch');
3574
+ * const result = picomatch.parse(pattern[, options]);
3575
+ * ```
3576
+ * @param {String} `pattern`
3577
+ * @param {Object} `options`
3578
+ * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
3579
+ * @api public
3580
+ */
3581
+
3582
+ picomatch.parse = (pattern, options) => {
3583
+ if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
3584
+ return parse(pattern, { ...options, fastpaths: false });
3585
+ };
3586
+
3587
+ /**
3588
+ * Scan a glob pattern to separate the pattern into segments.
3589
+ *
3590
+ * ```js
3591
+ * const picomatch = require('picomatch');
3592
+ * // picomatch.scan(input[, options]);
3593
+ *
3594
+ * const result = picomatch.scan('!./foo/*.js');
3595
+ * console.log(result);
3596
+ * { prefix: '!./',
3597
+ * input: '!./foo/*.js',
3598
+ * start: 3,
3599
+ * base: 'foo',
3600
+ * glob: '*.js',
3601
+ * isBrace: false,
3602
+ * isBracket: false,
3603
+ * isGlob: true,
3604
+ * isExtglob: false,
3605
+ * isGlobstar: false,
3606
+ * negated: true }
3607
+ * ```
3608
+ * @param {String} `input` Glob pattern to scan.
3609
+ * @param {Object} `options`
3610
+ * @return {Object} Returns an object with
3611
+ * @api public
3612
+ */
3613
+
3614
+ picomatch.scan = (input, options) => scan(input, options);
3615
+
3616
+ /**
3617
+ * Compile a regular expression from the `state` object returned by the
3618
+ * [parse()](#parse) method.
3619
+ *
3620
+ * @param {Object} `state`
3621
+ * @param {Object} `options`
3622
+ * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
3623
+ * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
3624
+ * @return {RegExp}
3625
+ * @api public
3626
+ */
3627
+
3628
+ picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
3629
+ if (returnOutput === true) {
3630
+ return state.output;
3631
+ }
3632
+
3633
+ const opts = options || {};
3634
+ const prepend = opts.contains ? '' : '^';
3635
+ const append = opts.contains ? '' : '$';
3636
+
3637
+ let source = `${prepend}(?:${state.output})${append}`;
3638
+ if (state && state.negated === true) {
3639
+ source = `^(?!${source}).*$`;
3640
+ }
3641
+
3642
+ const regex = picomatch.toRegex(source, options);
3643
+ if (returnState === true) {
3644
+ regex.state = state;
3645
+ }
3646
+
3647
+ return regex;
3648
+ };
3649
+
3650
+ /**
3651
+ * Create a regular expression from a parsed glob pattern.
3652
+ *
3653
+ * ```js
3654
+ * const picomatch = require('picomatch');
3655
+ * const state = picomatch.parse('*.js');
3656
+ * // picomatch.compileRe(state[, options]);
3657
+ *
3658
+ * console.log(picomatch.compileRe(state));
3659
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
3660
+ * ```
3661
+ * @param {String} `state` The object returned from the `.parse` method.
3662
+ * @param {Object} `options`
3663
+ * @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
3664
+ * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
3665
+ * @return {RegExp} Returns a regex created from the given pattern.
3666
+ * @api public
3667
+ */
3668
+
3669
+ picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
3670
+ if (!input || typeof input !== 'string') {
3671
+ throw new TypeError('Expected a non-empty string');
3672
+ }
3673
+
3674
+ let parsed = { negated: false, fastpaths: true };
3675
+
3676
+ if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
3677
+ parsed.output = parse.fastpaths(input, options);
3678
+ }
3679
+
3680
+ if (!parsed.output) {
3681
+ parsed = parse(input, options);
3682
+ }
3683
+
3684
+ return picomatch.compileRe(parsed, options, returnOutput, returnState);
3685
+ };
3686
+
3687
+ /**
3688
+ * Create a regular expression from the given regex source string.
3689
+ *
3690
+ * ```js
3691
+ * const picomatch = require('picomatch');
3692
+ * // picomatch.toRegex(source[, options]);
3693
+ *
3694
+ * const { output } = picomatch.parse('*.js');
3695
+ * console.log(picomatch.toRegex(output));
3696
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
3697
+ * ```
3698
+ * @param {String} `source` Regular expression source string.
3699
+ * @param {Object} `options`
3700
+ * @return {RegExp}
3701
+ * @api public
3702
+ */
3703
+
3704
+ picomatch.toRegex = (source, options) => {
3705
+ try {
3706
+ const opts = options || {};
3707
+ return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
3708
+ } catch (err) {
3709
+ if (options && options.debug === true) throw err;
3710
+ return /$^/;
3711
+ }
3712
+ };
3713
+
3714
+ /**
3715
+ * Picomatch constants.
3716
+ * @return {Object}
3717
+ */
3718
+
3719
+ picomatch.constants = constants;
3720
+
3721
+ /**
3722
+ * Expose "picomatch"
3723
+ */
3724
+
3725
+ picomatch_1 = picomatch;
3726
+ return picomatch_1;
3727
+ }
3728
+
3729
+ var picomatch;
3730
+ var hasRequiredPicomatch;
3731
+
3732
+ function requirePicomatch () {
3733
+ if (hasRequiredPicomatch) return picomatch;
3734
+ hasRequiredPicomatch = 1;
3735
+
3736
+ picomatch = requirePicomatch$1();
3737
+ return picomatch;
3738
+ }
3739
+
3740
+ var micromatch_1;
3741
+ var hasRequiredMicromatch;
3742
+
3743
+ function requireMicromatch () {
3744
+ if (hasRequiredMicromatch) return micromatch_1;
3745
+ hasRequiredMicromatch = 1;
3746
+
3747
+ const util = require$$0;
3748
+ const braces = requireBraces();
3749
+ const picomatch = requirePicomatch();
3750
+ const utils = requireUtils();
3751
+ const isEmptyString = val => val === '' || val === './';
3752
+
3753
+ /**
3754
+ * Returns an array of strings that match one or more glob patterns.
3755
+ *
3756
+ * ```js
3757
+ * const mm = require('micromatch');
3758
+ * // mm(list, patterns[, options]);
3759
+ *
3760
+ * console.log(mm(['a.js', 'a.txt'], ['*.js']));
3761
+ * //=> [ 'a.js' ]
3762
+ * ```
3763
+ * @param {String|Array<string>} `list` List of strings to match.
3764
+ * @param {String|Array<string>} `patterns` One or more glob patterns to use for matching.
3765
+ * @param {Object} `options` See available [options](#options)
3766
+ * @return {Array} Returns an array of matches
3767
+ * @summary false
3768
+ * @api public
3769
+ */
3770
+
3771
+ const micromatch = (list, patterns, options) => {
3772
+ patterns = [].concat(patterns);
3773
+ list = [].concat(list);
3774
+
3775
+ let omit = new Set();
3776
+ let keep = new Set();
3777
+ let items = new Set();
3778
+ let negatives = 0;
3779
+
3780
+ let onResult = state => {
3781
+ items.add(state.output);
3782
+ if (options && options.onResult) {
3783
+ options.onResult(state);
3784
+ }
3785
+ };
3786
+
3787
+ for (let i = 0; i < patterns.length; i++) {
3788
+ let isMatch = picomatch(String(patterns[i]), { ...options, onResult }, true);
3789
+ let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
3790
+ if (negated) negatives++;
3791
+
3792
+ for (let item of list) {
3793
+ let matched = isMatch(item, true);
3794
+
3795
+ let match = negated ? !matched.isMatch : matched.isMatch;
3796
+ if (!match) continue;
3797
+
3798
+ if (negated) {
3799
+ omit.add(matched.output);
3800
+ } else {
3801
+ omit.delete(matched.output);
3802
+ keep.add(matched.output);
3803
+ }
3804
+ }
3805
+ }
3806
+
3807
+ let result = negatives === patterns.length ? [...items] : [...keep];
3808
+ let matches = result.filter(item => !omit.has(item));
3809
+
3810
+ if (options && matches.length === 0) {
3811
+ if (options.failglob === true) {
3812
+ throw new Error(`No matches found for "${patterns.join(', ')}"`);
3813
+ }
3814
+
3815
+ if (options.nonull === true || options.nullglob === true) {
3816
+ return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
3817
+ }
3818
+ }
3819
+
3820
+ return matches;
3821
+ };
3822
+
3823
+ /**
3824
+ * Backwards compatibility
3825
+ */
3826
+
3827
+ micromatch.match = micromatch;
3828
+
3829
+ /**
3830
+ * Returns a matcher function from the given glob `pattern` and `options`.
3831
+ * The returned function takes a string to match as its only argument and returns
3832
+ * true if the string is a match.
3833
+ *
3834
+ * ```js
3835
+ * const mm = require('micromatch');
3836
+ * // mm.matcher(pattern[, options]);
3837
+ *
3838
+ * const isMatch = mm.matcher('*.!(*a)');
3839
+ * console.log(isMatch('a.a')); //=> false
3840
+ * console.log(isMatch('a.b')); //=> true
3841
+ * ```
3842
+ * @param {String} `pattern` Glob pattern
3843
+ * @param {Object} `options`
3844
+ * @return {Function} Returns a matcher function.
3845
+ * @api public
3846
+ */
3847
+
3848
+ micromatch.matcher = (pattern, options) => picomatch(pattern, options);
3849
+
3850
+ /**
3851
+ * Returns true if **any** of the given glob `patterns` match the specified `string`.
3852
+ *
3853
+ * ```js
3854
+ * const mm = require('micromatch');
3855
+ * // mm.isMatch(string, patterns[, options]);
3856
+ *
3857
+ * console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
3858
+ * console.log(mm.isMatch('a.a', 'b.*')); //=> false
3859
+ * ```
3860
+ * @param {String} `str` The string to test.
3861
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
3862
+ * @param {Object} `[options]` See available [options](#options).
3863
+ * @return {Boolean} Returns true if any patterns match `str`
3864
+ * @api public
3865
+ */
3866
+
3867
+ micromatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
3868
+
3869
+ /**
3870
+ * Backwards compatibility
3871
+ */
3872
+
3873
+ micromatch.any = micromatch.isMatch;
3874
+
3875
+ /**
3876
+ * Returns a list of strings that _**do not match any**_ of the given `patterns`.
3877
+ *
3878
+ * ```js
3879
+ * const mm = require('micromatch');
3880
+ * // mm.not(list, patterns[, options]);
3881
+ *
3882
+ * console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
3883
+ * //=> ['b.b', 'c.c']
3884
+ * ```
3885
+ * @param {Array} `list` Array of strings to match.
3886
+ * @param {String|Array} `patterns` One or more glob pattern to use for matching.
3887
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
3888
+ * @return {Array} Returns an array of strings that **do not match** the given patterns.
3889
+ * @api public
3890
+ */
3891
+
3892
+ micromatch.not = (list, patterns, options = {}) => {
3893
+ patterns = [].concat(patterns).map(String);
3894
+ let result = new Set();
3895
+ let items = [];
3896
+
3897
+ let onResult = state => {
3898
+ if (options.onResult) options.onResult(state);
3899
+ items.push(state.output);
3900
+ };
3901
+
3902
+ let matches = new Set(micromatch(list, patterns, { ...options, onResult }));
3903
+
3904
+ for (let item of items) {
3905
+ if (!matches.has(item)) {
3906
+ result.add(item);
3907
+ }
3908
+ }
3909
+ return [...result];
3910
+ };
3911
+
3912
+ /**
3913
+ * Returns true if the given `string` contains the given pattern. Similar
3914
+ * to [.isMatch](#isMatch) but the pattern can match any part of the string.
3915
+ *
3916
+ * ```js
3917
+ * var mm = require('micromatch');
3918
+ * // mm.contains(string, pattern[, options]);
3919
+ *
3920
+ * console.log(mm.contains('aa/bb/cc', '*b'));
3921
+ * //=> true
3922
+ * console.log(mm.contains('aa/bb/cc', '*d'));
3923
+ * //=> false
3924
+ * ```
3925
+ * @param {String} `str` The string to match.
3926
+ * @param {String|Array} `patterns` Glob pattern to use for matching.
3927
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
3928
+ * @return {Boolean} Returns true if any of the patterns matches any part of `str`.
3929
+ * @api public
3930
+ */
3931
+
3932
+ micromatch.contains = (str, pattern, options) => {
3933
+ if (typeof str !== 'string') {
3934
+ throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
3935
+ }
3936
+
3937
+ if (Array.isArray(pattern)) {
3938
+ return pattern.some(p => micromatch.contains(str, p, options));
3939
+ }
3940
+
3941
+ if (typeof pattern === 'string') {
3942
+ if (isEmptyString(str) || isEmptyString(pattern)) {
3943
+ return false;
3944
+ }
3945
+
3946
+ if (str.includes(pattern) || (str.startsWith('./') && str.slice(2).includes(pattern))) {
3947
+ return true;
3948
+ }
3949
+ }
3950
+
3951
+ return micromatch.isMatch(str, pattern, { ...options, contains: true });
3952
+ };
3953
+
3954
+ /**
3955
+ * Filter the keys of the given object with the given `glob` pattern
3956
+ * and `options`. Does not attempt to match nested keys. If you need this feature,
3957
+ * use [glob-object][] instead.
3958
+ *
3959
+ * ```js
3960
+ * const mm = require('micromatch');
3961
+ * // mm.matchKeys(object, patterns[, options]);
3962
+ *
3963
+ * const obj = { aa: 'a', ab: 'b', ac: 'c' };
3964
+ * console.log(mm.matchKeys(obj, '*b'));
3965
+ * //=> { ab: 'b' }
3966
+ * ```
3967
+ * @param {Object} `object` The object with keys to filter.
3968
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
3969
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
3970
+ * @return {Object} Returns an object with only keys that match the given patterns.
3971
+ * @api public
3972
+ */
3973
+
3974
+ micromatch.matchKeys = (obj, patterns, options) => {
3975
+ if (!utils.isObject(obj)) {
3976
+ throw new TypeError('Expected the first argument to be an object');
3977
+ }
3978
+ let keys = micromatch(Object.keys(obj), patterns, options);
3979
+ let res = {};
3980
+ for (let key of keys) res[key] = obj[key];
3981
+ return res;
3982
+ };
3983
+
3984
+ /**
3985
+ * Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
3986
+ *
3987
+ * ```js
3988
+ * const mm = require('micromatch');
3989
+ * // mm.some(list, patterns[, options]);
3990
+ *
3991
+ * console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
3992
+ * // true
3993
+ * console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
3994
+ * // false
3995
+ * ```
3996
+ * @param {String|Array} `list` The string or array of strings to test. Returns as soon as the first match is found.
3997
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
3998
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
3999
+ * @return {Boolean} Returns true if any `patterns` matches any of the strings in `list`
4000
+ * @api public
4001
+ */
4002
+
4003
+ micromatch.some = (list, patterns, options) => {
4004
+ let items = [].concat(list);
4005
+
4006
+ for (let pattern of [].concat(patterns)) {
4007
+ let isMatch = picomatch(String(pattern), options);
4008
+ if (items.some(item => isMatch(item))) {
4009
+ return true;
4010
+ }
4011
+ }
4012
+ return false;
4013
+ };
4014
+
4015
+ /**
4016
+ * Returns true if every string in the given `list` matches
4017
+ * any of the given glob `patterns`.
4018
+ *
4019
+ * ```js
4020
+ * const mm = require('micromatch');
4021
+ * // mm.every(list, patterns[, options]);
4022
+ *
4023
+ * console.log(mm.every('foo.js', ['foo.js']));
4024
+ * // true
4025
+ * console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
4026
+ * // true
4027
+ * console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
4028
+ * // false
4029
+ * console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
4030
+ * // false
4031
+ * ```
4032
+ * @param {String|Array} `list` The string or array of strings to test.
4033
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4034
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4035
+ * @return {Boolean} Returns true if all `patterns` matches all of the strings in `list`
4036
+ * @api public
4037
+ */
4038
+
4039
+ micromatch.every = (list, patterns, options) => {
4040
+ let items = [].concat(list);
4041
+
4042
+ for (let pattern of [].concat(patterns)) {
4043
+ let isMatch = picomatch(String(pattern), options);
4044
+ if (!items.every(item => isMatch(item))) {
4045
+ return false;
4046
+ }
4047
+ }
4048
+ return true;
4049
+ };
4050
+
4051
+ /**
4052
+ * Returns true if **all** of the given `patterns` match
4053
+ * the specified string.
4054
+ *
4055
+ * ```js
4056
+ * const mm = require('micromatch');
4057
+ * // mm.all(string, patterns[, options]);
4058
+ *
4059
+ * console.log(mm.all('foo.js', ['foo.js']));
4060
+ * // true
4061
+ *
4062
+ * console.log(mm.all('foo.js', ['*.js', '!foo.js']));
4063
+ * // false
4064
+ *
4065
+ * console.log(mm.all('foo.js', ['*.js', 'foo.js']));
4066
+ * // true
4067
+ *
4068
+ * console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
4069
+ * // true
4070
+ * ```
4071
+ * @param {String|Array} `str` The string to test.
4072
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4073
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4074
+ * @return {Boolean} Returns true if any patterns match `str`
4075
+ * @api public
4076
+ */
4077
+
4078
+ micromatch.all = (str, patterns, options) => {
4079
+ if (typeof str !== 'string') {
4080
+ throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
4081
+ }
4082
+
4083
+ return [].concat(patterns).every(p => picomatch(p, options)(str));
4084
+ };
4085
+
4086
+ /**
4087
+ * Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
4088
+ *
4089
+ * ```js
4090
+ * const mm = require('micromatch');
4091
+ * // mm.capture(pattern, string[, options]);
4092
+ *
4093
+ * console.log(mm.capture('test/*.js', 'test/foo.js'));
4094
+ * //=> ['foo']
4095
+ * console.log(mm.capture('test/*.js', 'foo/bar.css'));
4096
+ * //=> null
4097
+ * ```
4098
+ * @param {String} `glob` Glob pattern to use for matching.
4099
+ * @param {String} `input` String to match
4100
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4101
+ * @return {Array|null} Returns an array of captures if the input matches the glob pattern, otherwise `null`.
4102
+ * @api public
4103
+ */
4104
+
4105
+ micromatch.capture = (glob, input, options) => {
4106
+ let posix = utils.isWindows(options);
4107
+ let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
4108
+ let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);
4109
+
4110
+ if (match) {
4111
+ return match.slice(1).map(v => v === void 0 ? '' : v);
4112
+ }
4113
+ };
4114
+
4115
+ /**
4116
+ * Create a regular expression from the given glob `pattern`.
4117
+ *
4118
+ * ```js
4119
+ * const mm = require('micromatch');
4120
+ * // mm.makeRe(pattern[, options]);
4121
+ *
4122
+ * console.log(mm.makeRe('*.js'));
4123
+ * //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
4124
+ * ```
4125
+ * @param {String} `pattern` A glob pattern to convert to regex.
4126
+ * @param {Object} `options`
4127
+ * @return {RegExp} Returns a regex created from the given pattern.
4128
+ * @api public
4129
+ */
4130
+
4131
+ micromatch.makeRe = (...args) => picomatch.makeRe(...args);
4132
+
4133
+ /**
4134
+ * Scan a glob pattern to separate the pattern into segments. Used
4135
+ * by the [split](#split) method.
4136
+ *
4137
+ * ```js
4138
+ * const mm = require('micromatch');
4139
+ * const state = mm.scan(pattern[, options]);
4140
+ * ```
4141
+ * @param {String} `pattern`
4142
+ * @param {Object} `options`
4143
+ * @return {Object} Returns an object with
4144
+ * @api public
4145
+ */
4146
+
4147
+ micromatch.scan = (...args) => picomatch.scan(...args);
4148
+
4149
+ /**
4150
+ * Parse a glob pattern to create the source string for a regular
4151
+ * expression.
4152
+ *
4153
+ * ```js
4154
+ * const mm = require('micromatch');
4155
+ * const state = mm.parse(pattern[, options]);
4156
+ * ```
4157
+ * @param {String} `glob`
4158
+ * @param {Object} `options`
4159
+ * @return {Object} Returns an object with useful properties and output to be used as regex source string.
4160
+ * @api public
4161
+ */
4162
+
4163
+ micromatch.parse = (patterns, options) => {
4164
+ let res = [];
4165
+ for (let pattern of [].concat(patterns || [])) {
4166
+ for (let str of braces(String(pattern), options)) {
4167
+ res.push(picomatch.parse(str, options));
4168
+ }
4169
+ }
4170
+ return res;
4171
+ };
4172
+
4173
+ /**
4174
+ * Process the given brace `pattern`.
4175
+ *
4176
+ * ```js
4177
+ * const { braces } = require('micromatch');
4178
+ * console.log(braces('foo/{a,b,c}/bar'));
4179
+ * //=> [ 'foo/(a|b|c)/bar' ]
4180
+ *
4181
+ * console.log(braces('foo/{a,b,c}/bar', { expand: true }));
4182
+ * //=> [ 'foo/a/bar', 'foo/b/bar', 'foo/c/bar' ]
4183
+ * ```
4184
+ * @param {String} `pattern` String with brace pattern to process.
4185
+ * @param {Object} `options` Any [options](#options) to change how expansion is performed. See the [braces][] library for all available options.
4186
+ * @return {Array}
4187
+ * @api public
4188
+ */
4189
+
4190
+ micromatch.braces = (pattern, options) => {
4191
+ if (typeof pattern !== 'string') throw new TypeError('Expected a string');
4192
+ if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
4193
+ return [pattern];
4194
+ }
4195
+ return braces(pattern, options);
4196
+ };
4197
+
4198
+ /**
4199
+ * Expand braces
4200
+ */
4201
+
4202
+ micromatch.braceExpand = (pattern, options) => {
4203
+ if (typeof pattern !== 'string') throw new TypeError('Expected a string');
4204
+ return micromatch.braces(pattern, { ...options, expand: true });
4205
+ };
4206
+
4207
+ /**
4208
+ * Expose micromatch
4209
+ */
4210
+
4211
+ micromatch_1 = micromatch;
4212
+ return micromatch_1;
4213
+ }
4214
+
4215
+ var micromatchExports = requireMicromatch();
4216
+
4217
+ const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4218
+ const {
4219
+ JIEK_OUT_DIR
4220
+ } = process.env;
4221
+ const OUTDIR = JIEK_OUT_DIR ?? "dist";
4222
+ function getOutDirs({
4223
+ cwd = process.cwd(),
4224
+ defaultOutdir = OUTDIR,
4225
+ config,
4226
+ pkgName
4227
+ }) {
4228
+ const { build = {} } = config ?? {};
4229
+ const outdir = build?.output?.dir;
4230
+ function resolveOutdir(type) {
4231
+ const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
4232
+ js: "dts",
4233
+ dts: "js"
4234
+ }[type]] : outdir) ?? defaultOutdir;
4235
+ return (isAbsolute(dir) ? dir : `./${relative(cwd, resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
4236
+ }
4237
+ return {
4238
+ js: resolveOutdir("js"),
4239
+ dts: resolveOutdir("dts")
4240
+ };
4241
+ }
4242
+ function getExports({
4243
+ entrypoints,
4244
+ pkgName,
4245
+ pkgIsModule,
4246
+ entries,
4247
+ config,
4248
+ dir,
4249
+ defaultOutdir = OUTDIR,
4250
+ // FIXME dts support
4251
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4252
+ noFilter,
4253
+ isPublish
4254
+ }) {
4255
+ const {
4256
+ build = {},
4257
+ publish: {
4258
+ withSuffix = false,
4259
+ withSource = true
4260
+ } = {}
4261
+ } = config ?? {};
4262
+ const {
4263
+ crossModuleConvertor = true
4264
+ } = build;
4265
+ const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4266
+ if (entries) {
4267
+ Object.entries(resolvedEntrypoints).forEach(([key]) => {
4268
+ if (!entries.some((e) => micromatchExports.isMatch(key, e, { matchBase: true }))) {
4269
+ delete resolvedEntrypoints[key];
4270
+ }
4271
+ });
4272
+ }
4273
+ const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : filterLeafs(
4274
+ resolvedEntrypoints,
4275
+ {
4276
+ skipValue: [
4277
+ // ignore values that filename starts with `.jk-noentry`
4278
+ /(^|\/)\.jk-noentry/,
4279
+ ...DEFAULT_SKIP_VALUES
4280
+ ]
4281
+ }
4282
+ );
4283
+ const crossModuleWithConditional = crossModuleConvertor ? {
4284
+ import: (opts) => !pkgIsModule && intersection(
4285
+ new Set(opts.conditionals),
4286
+ /* @__PURE__ */ new Set(["import", "module"])
4287
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4288
+ require: (opts) => pkgIsModule && intersection(
4289
+ new Set(opts.conditionals),
4290
+ /* @__PURE__ */ new Set(["require", "node"])
4291
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4292
+ } : {};
4293
+ return [
4294
+ filteredResolvedEntrypoints,
4295
+ entrypoints2Exports(filteredResolvedEntrypoints, {
4296
+ outdir,
4297
+ withSuffix: isPublish ? withSuffix : void 0,
4298
+ withSource: isPublish ? withSource : void 0,
4299
+ withConditional: {
4300
+ ...crossModuleWithConditional
4301
+ }
4302
+ }),
4303
+ outdir
4304
+ ];
4305
+ }
4306
+
4307
+ const require$1 = createRequire(import.meta.url);
4308
+ function packageIsExist(name) {
4309
+ try {
4310
+ require$1.resolve(name);
4311
+ return true;
4312
+ } catch (e) {
4313
+ return false;
4314
+ }
4315
+ }
4316
+ let tsRegisterName;
4317
+ const registers = [
4318
+ process.env.JIEK_TS_REGISTER,
4319
+ "esbuild-register",
4320
+ "@swc-node/register",
4321
+ "ts-node/register"
4322
+ ].filter(Boolean);
4323
+ for (const register of registers) {
4324
+ if (packageIsExist(register)) {
4325
+ tsRegisterName = register;
4326
+ break;
4327
+ }
4328
+ }
4329
+
4330
+ const require = createRequire(import.meta.url);
4331
+ let configName = "jiek.config";
4332
+ function getConfigPath(root, dir) {
4333
+ const isSupportTsLoader = !!tsRegisterName;
4334
+ function configWithExtIsExist(ext) {
4335
+ const filenames = [
4336
+ path.resolve(process.cwd(), `${configName}.${ext}`),
4337
+ path.resolve(process.cwd(), `.${configName}.${ext}`),
4338
+ path.resolve(root, `${configName}.${ext}`),
4339
+ path.resolve(root, `.${configName}.${ext}`)
4340
+ ];
4341
+ if (dir) {
4342
+ filenames.unshift(...[
4343
+ path.resolve(dir, `${configName}.${ext}`),
4344
+ path.resolve(dir, `.${configName}.${ext}`)
4345
+ ]);
4346
+ }
4347
+ for (const filename of filenames) {
4348
+ if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
4349
+ return filename;
4350
+ }
4351
+ }
4352
+ return;
4353
+ }
4354
+ configName = configWithExtIsExist("js") ?? configName;
4355
+ configName = configWithExtIsExist("json") ?? configName;
4356
+ configName = configWithExtIsExist("yaml") ?? configName;
4357
+ if (isSupportTsLoader) {
4358
+ configName = configWithExtIsExist("ts") ?? configName;
4359
+ }
4360
+ return path.resolve(root, configName);
4361
+ }
4362
+ function loadConfig(dirOrOptions) {
4363
+ let dir;
4364
+ let root;
4365
+ if (typeof dirOrOptions === "object") {
4366
+ dir = dirOrOptions.dir;
4367
+ root = dirOrOptions.root ?? getWD().wd;
4368
+ } else {
4369
+ dir = dirOrOptions;
4370
+ root = getWD().wd;
4371
+ }
4372
+ let configPath = program.getOptionValue("configPath");
4373
+ if (!configPath) {
4374
+ configPath = getConfigPath(root, dir);
4375
+ } else {
4376
+ if (!fs.existsSync(configPath)) {
4377
+ throw new Error(`config file not found: ${configPath}`);
4378
+ }
4379
+ if (!path.isAbsolute(configPath)) {
4380
+ configPath = path.resolve(root, configPath);
4381
+ }
4382
+ }
4383
+ const ext = path.extname(configPath);
4384
+ let module;
4385
+ switch (ext) {
4386
+ case ".js":
4387
+ module = require(configPath);
4388
+ break;
4389
+ case ".json":
4390
+ return require(configPath);
4391
+ case ".yaml":
4392
+ return load(fs.readFileSync(configPath, "utf-8"));
4393
+ case ".ts":
4394
+ if (tsRegisterName) {
4395
+ require(tsRegisterName);
4396
+ module = require(configPath);
4397
+ break;
4398
+ }
4399
+ throw new Error(
4400
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
4401
+ );
4402
+ case ".config":
4403
+ module = {};
4404
+ break;
4405
+ default:
4406
+ throw new Error(`unsupported config file type: ${ext}`);
4407
+ }
4408
+ if (!module)
4409
+ throw new Error("config file is empty");
4410
+ return module.default ?? module;
4411
+ }
4412
+
4413
+ const outdirDescription = `
4414
+ The output directory of the build, which relative to the target subpackage root directory.
4415
+ Support with variables: 'PKG_NAME',
4416
+ .e.g. 'dist/{{PKG_NAME}}'.
4417
+ `.trim();
4418
+
4419
+ const description = `
4420
+ Publish package to npm registry, and auto generate exports field and other fields in published package.json.
4421
+ If you want to through the options to the \`pnpm publish\` command, you can pass the options after '--'.
4422
+ `.trim();
4423
+ async function forEachSelectedProjectsGraphEntries(callback) {
4424
+ const { value = {} } = await getSelectedProjectsGraph() ?? {};
4425
+ const selectedProjectsGraphEntries = Object.entries(value);
4426
+ if (selectedProjectsGraphEntries.length === 0) {
4427
+ throw new Error("no packages selected");
4428
+ }
4429
+ for (const [dir, manifest] of selectedProjectsGraphEntries) {
4430
+ callback(dir, manifest);
4431
+ }
4432
+ }
4433
+ program.command("publish").description(description).aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").action(async ({ outdir, bumper }) => {
4434
+ let shouldPassThrough = false;
4435
+ const passThroughOptions = process.argv.reduce(
4436
+ (acc, value) => {
4437
+ if (shouldPassThrough) {
4438
+ acc.push(value);
4439
+ }
4440
+ if (value === "--") {
4441
+ shouldPassThrough = true;
4442
+ }
4443
+ return acc;
4444
+ },
4445
+ []
4446
+ );
4447
+ await forEachSelectedProjectsGraphEntries((dir) => {
4448
+ const args = ["pnpm", "publish", "--access", "public", "--no-git-checks"];
4449
+ if (bumper && TAGS.includes(bumper)) {
4450
+ args.push("--tag", bumper);
4451
+ }
4452
+ args.push(...passThroughOptions);
4453
+ childProcess.execSync(args.join(" "), {
4454
+ cwd: dir,
4455
+ stdio: "inherit",
4456
+ env: {
4457
+ ...process.env,
4458
+ JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4459
+ JIEK_PUBLISH_BUMPER: JSON.stringify(bumper)
4460
+ }
4461
+ });
4462
+ });
4463
+ });
4464
+ async function prepublish() {
4465
+ const {
4466
+ JIEK_PUBLISH_OUTDIR: outdirEnv,
4467
+ JIEK_PUBLISH_BUMPER: bumperEnv
4468
+ } = process.env;
4469
+ const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4470
+ const bumper = bumperEnv ? JSON.parse(bumperEnv) : false;
4471
+ const generateNewManifest = (dir, manifest) => {
4472
+ const { name, type, exports: entrypoints = {} } = manifest;
4473
+ if (!name) {
4474
+ throw new Error(`package.json in ${dir} must have a name field`);
4475
+ }
4476
+ const pkgIsModule = type === "module";
4477
+ const newManifest = { ...manifest };
4478
+ const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
4479
+ entrypoints,
4480
+ pkgIsModule,
4481
+ pkgName: name,
4482
+ config: loadConfig(dir),
4483
+ dir,
4484
+ defaultOutdir: outdir,
4485
+ noFilter: true,
4486
+ isPublish: true
4487
+ });
4488
+ newManifest.exports = {
4489
+ ...resolvedEntrypoints,
4490
+ ...exports
4491
+ };
4492
+ return [newManifest, resolvedOutdir];
4493
+ };
4494
+ const generateNewPackageJSONString = ({
4495
+ oldJSONString,
4496
+ oldJSON,
4497
+ manifest,
4498
+ formattingOptions
4499
+ }) => {
4500
+ let newJSONString = oldJSONString;
4501
+ newJSONString = applyEdits(
4502
+ newJSONString,
4503
+ modify(
4504
+ newJSONString,
4505
+ ["publishConfig", "typesVersions"],
4506
+ {
4507
+ "<5.0": {
4508
+ "*": [
4509
+ "*",
4510
+ `./*`,
4511
+ `./*/index.d.ts`,
4512
+ `./*/index.d.mts`,
4513
+ `./*/index.d.cts`
4514
+ ]
4515
+ }
4516
+ },
4517
+ { formattingOptions }
4518
+ )
4519
+ );
4520
+ for (const [key, value] of Object.entries(manifest)) {
4521
+ if (key === "version")
4522
+ continue;
4523
+ if (JSON.stringify(value) === JSON.stringify(oldJSON[key]))
4524
+ continue;
4525
+ if (key !== "exports") {
4526
+ newJSONString = applyEdits(
4527
+ newJSONString,
4528
+ modify(
4529
+ newJSONString,
4530
+ ["publishConfig", key],
4531
+ value,
4532
+ { formattingOptions }
4533
+ )
4534
+ );
4535
+ } else {
4536
+ const exports = value;
4537
+ for (const [k, v] of Object.entries(exports)) {
4538
+ newJSONString = applyEdits(
4539
+ newJSONString,
4540
+ modify(
4541
+ newJSONString,
4542
+ ["publishConfig", "exports", k],
4543
+ v,
4544
+ { formattingOptions }
4545
+ )
4546
+ );
4547
+ }
4548
+ const index = exports?.["."];
4549
+ const indexPublishConfig = {};
4550
+ if (index) {
4551
+ switch (typeof index) {
4552
+ case "string":
4553
+ indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
4554
+ break;
4555
+ case "object": {
4556
+ const indexExports = index;
4557
+ indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
4558
+ indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
4559
+ break;
4560
+ }
4561
+ }
4562
+ for (const [k, v] of Object.entries(indexPublishConfig)) {
4563
+ if (v === void 0)
4564
+ continue;
4565
+ newJSONString = applyEdits(
4566
+ newJSONString,
4567
+ modify(
4568
+ newJSONString,
4569
+ ["publishConfig", k],
4570
+ v,
4571
+ { formattingOptions }
4572
+ )
4573
+ );
4574
+ }
4575
+ }
4576
+ }
4577
+ }
4578
+ if (oldJSON["peerDependencies"]) {
4579
+ const peerDependenciesMeta = Object.keys(oldJSON["peerDependencies"]).reduce(
4580
+ (acc, key) => {
4581
+ acc[key] = { optional: true };
4582
+ return acc;
4583
+ },
4584
+ {}
4585
+ );
4586
+ newJSONString = applyEdits(
4587
+ newJSONString,
4588
+ modify(
4589
+ newJSONString,
4590
+ ["peerDependenciesMeta"],
4591
+ peerDependenciesMeta,
4592
+ { formattingOptions }
4593
+ )
4594
+ );
4595
+ }
4596
+ if (oldJSON["files"]) {
4597
+ newJSONString = applyEdits(
4598
+ newJSONString,
4599
+ modify(
4600
+ newJSONString,
4601
+ ["files"],
4602
+ void 0,
4603
+ { formattingOptions }
4604
+ )
4605
+ );
4606
+ }
4607
+ return newJSONString;
4608
+ };
4609
+ await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
4610
+ const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4611
+ const resolveByDir = (...paths) => path.resolve(dir, ...paths);
4612
+ const oldJSONString = fs.readFileSync(resolveByDir("package.json"), "utf-8");
4613
+ const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4614
+ if (typeof oldJSON.version !== "string") {
4615
+ throw new Error(`${dir}/package.json must have a version field with a string value`);
4616
+ }
4617
+ const { indent = " " } = detectIndent(oldJSONString);
4618
+ const formattingOptions = {
4619
+ tabSize: indent.length,
4620
+ insertSpaces: true
4621
+ };
4622
+ const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version;
4623
+ const modifyVersionPackageJSON = applyEdits(
4624
+ oldJSONString,
4625
+ modify(oldJSONString, ["version"], newVersion, { formattingOptions })
4626
+ );
4627
+ const newJSONString = generateNewPackageJSONString({
4628
+ oldJSONString: modifyVersionPackageJSON,
4629
+ oldJSON: {
4630
+ ...oldJSON,
4631
+ version: newVersion
4632
+ },
4633
+ manifest,
4634
+ formattingOptions
4635
+ });
4636
+ const withPublishConfigDirectoryOldJSONString = applyEdits(
4637
+ modifyVersionPackageJSON,
4638
+ modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
4639
+ );
4640
+ if (!fs.existsSync(resolveByDir(resolvedOutdir))) {
4641
+ fs.mkdirSync(resolveByDir(resolvedOutdir));
4642
+ }
4643
+ const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
4644
+ if (!fs.existsSync(resolveByDir(jiekTempDir))) {
4645
+ fs.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
4646
+ }
4647
+ fs.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
4648
+ fs.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4649
+ fs.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4650
+ });
4651
+ }
4652
+ async function postpublish() {
4653
+ await forEachSelectedProjectsGraphEntries((dir) => {
4654
+ const jiekTempDir = path.resolve(dir, "node_modules/.jiek/.tmp");
4655
+ const packageJSON = path.resolve(dir, "package.json");
4656
+ const jiekTempPackageJSON = path.resolve(jiekTempDir, "package.json");
4657
+ if (fs.existsSync(jiekTempPackageJSON)) {
4658
+ fs.copyFileSync(jiekTempPackageJSON, packageJSON);
4659
+ fs.rmSync(jiekTempPackageJSON);
4660
+ console.log(`
4661
+ ${dir}/package.json has been restored`);
4662
+ } else {
4663
+ throw new Error(
4664
+ `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
4665
+ );
4666
+ }
4667
+ });
4668
+ }
4669
+ program.action(async () => {
4670
+ const {
4671
+ npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4672
+ } = process.env;
4673
+ switch (NPM_LIFECYCLE_EVENT) {
4674
+ case "prepublish":
4675
+ await prepublish();
4676
+ break;
4677
+ case "postpublish":
4678
+ await postpublish();
4679
+ break;
4680
+ default:
4681
+ program.help();
4682
+ }
4683
+ });
4684
+ program.command("prepublish").action(prepublish);
4685
+ program.command("postpublish").action(postpublish);