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