jiek 2.2.6 → 2.2.7-alpha.1

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