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