jiek 2.0.2-alpha.2 → 2.0.2-alpha.3

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