jiek 2.0.1 → 2.0.2-alpha.1

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