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