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