jiek 2.0.2-alpha.1 → 2.0.2-alpha.10

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