vitest 3.2.0-beta.1 → 3.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +0 -232
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +3 -4
- package/dist/chunks/{base.SfTiRNZf.js → base.DwtwORaC.js} +2 -2
- package/dist/chunks/{cac.TfX2-DVH.js → cac.I9MLYfT-.js} +10 -8
- package/dist/chunks/{cli-api.2970Nj9J.js → cli-api.d6IK1pnk.js} +48 -16
- package/dist/chunks/{coverage.z0LVMxgb.js → coverage.OGU09Jbh.js} +126 -4215
- package/dist/chunks/{creator.CuL7xDWI.js → creator.DGAdZ4Hj.js} +18 -39
- package/dist/chunks/{execute.BpmIjFTD.js → execute.JlGHLJZT.js} +3 -5
- package/dist/chunks/{global.d.BCOHQEpR.d.ts → global.d.BPa1eL3O.d.ts} +10 -10
- package/dist/chunks/{globals.Cg4NtV4P.js → globals.CpxW8ccg.js} +1 -2
- package/dist/chunks/{index.Bw6JxgX8.js → index.CK1YOQaa.js} +7 -7
- package/dist/chunks/{index.CUacZlWG.js → index.CV36oG_L.js} +881 -948
- package/dist/chunks/{index.BPc7M5ni.js → index.CfXMNXHg.js} +1 -13
- package/dist/chunks/index.CmC5OK9L.js +275 -0
- package/dist/chunks/{index.DbWBPwtH.js → index.DswW_LEs.js} +1 -1
- package/dist/chunks/{index.DBIGubLC.js → index.X0nbfr6-.js} +7 -7
- package/dist/chunks/{reporters.d.DGm4k1Wx.d.ts → reporters.d.CLC9rhKy.d.ts} +17 -0
- package/dist/chunks/{runBaseTests.CguliJB5.js → runBaseTests.Dn2vyej_.js} +3 -4
- package/dist/chunks/{setup-common.BP6KrF_Z.js → setup-common.CYo3Y0dD.js} +1 -3
- package/dist/chunks/typechecker.DnTrplSJ.js +897 -0
- package/dist/chunks/{vite.d.DjP_ALCZ.d.ts → vite.d.CBZ3M_ru.d.ts} +1 -1
- package/dist/chunks/{vm.CuLHT1BG.js → vm.C1HHjtNS.js} +1 -1
- package/dist/cli.js +20 -1
- package/dist/config.d.ts +3 -3
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +4 -7
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +5 -27
- package/dist/index.js +1 -2
- package/dist/node.d.ts +4 -4
- package/dist/node.js +16 -18
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +14 -14
- package/dist/workers/forks.js +2 -2
- package/dist/workers/runVmTests.js +3 -4
- package/dist/workers/threads.js +2 -2
- package/dist/workers/vmForks.js +2 -2
- package/dist/workers/vmThreads.js +2 -2
- package/dist/workers.js +3 -3
- package/package.json +15 -19
- package/dist/chunks/run-once.Dimr7O9f.js +0 -47
- package/dist/chunks/typechecker.DYQbn8uK.js +0 -956
- package/dist/chunks/utils.8gfOgtry.js +0 -207
- package/dist/utils.d.ts +0 -3
- package/dist/utils.js +0 -2
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import fs, { statSync, realpathSync, promises as promises$1, mkdirSync, existsSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
3
|
-
import require$$0 from 'util';
|
|
4
|
-
import require$$0$1 from 'path';
|
|
5
2
|
import { relative, resolve, dirname, isAbsolute, join as join$1, normalize } from 'pathe';
|
|
3
|
+
import pm from 'picomatch';
|
|
6
4
|
import c from 'tinyrainbow';
|
|
7
5
|
import { c as configDefaults, e as benchmarkConfigDefaults, a as coverageConfigDefaults } from './defaults.DSxsTG0h.js';
|
|
8
6
|
import crypto from 'node:crypto';
|
|
9
7
|
import { slash, createDefer, shuffle, toArray } from '@vitest/utils';
|
|
10
8
|
import { builtinModules, createRequire } from 'node:module';
|
|
11
|
-
import
|
|
9
|
+
import path, { win32, dirname as dirname$1, join, resolve as resolve$1 } from 'node:path';
|
|
12
10
|
import process$1 from 'node:process';
|
|
13
11
|
import fsPromises, { writeFile, rename, stat, unlink } from 'node:fs/promises';
|
|
14
12
|
import { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$1 } from 'node:url';
|
|
@@ -24,7 +22,7 @@ import { version } from 'vite';
|
|
|
24
22
|
import EventEmitter from 'node:events';
|
|
25
23
|
import { c as createBirpc } from './index.CJ0plNrh.js';
|
|
26
24
|
import Tinypool$1, { Tinypool } from 'tinypool';
|
|
27
|
-
import { w as wrapSerializableConfig, a as Typechecker } from './typechecker.
|
|
25
|
+
import { w as wrapSerializableConfig, a as Typechecker } from './typechecker.DnTrplSJ.js';
|
|
28
26
|
import { MessageChannel } from 'node:worker_threads';
|
|
29
27
|
import { hasFailed } from '@vitest/runner/utils';
|
|
30
28
|
import { rootDir } from '../path.js';
|
|
@@ -737,7 +735,7 @@ function read(jsonPath, {base, specifier}) {
|
|
|
737
735
|
let string;
|
|
738
736
|
|
|
739
737
|
try {
|
|
740
|
-
string = fs.readFileSync(
|
|
738
|
+
string = fs.readFileSync(path.toNamespacedPath(jsonPath), 'utf8');
|
|
741
739
|
} catch (error) {
|
|
742
740
|
const exception = /** @type {ErrnoException} */ (error);
|
|
743
741
|
|
|
@@ -1123,7 +1121,7 @@ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
|
1123
1121
|
'DeprecationWarning',
|
|
1124
1122
|
'DEP0151'
|
|
1125
1123
|
);
|
|
1126
|
-
} else if (
|
|
1124
|
+
} else if (path.resolve(packagePath, main) !== urlPath) {
|
|
1127
1125
|
process$1.emitWarning(
|
|
1128
1126
|
`Package ${packagePath} has a "main" field set to "${main}", ` +
|
|
1129
1127
|
`excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
@@ -1284,7 +1282,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
|
1284
1282
|
{
|
|
1285
1283
|
const real = realpathSync(filePath);
|
|
1286
1284
|
const {search, hash} = resolved;
|
|
1287
|
-
resolved = pathToFileURL$1(real + (filePath.endsWith(
|
|
1285
|
+
resolved = pathToFileURL$1(real + (filePath.endsWith(path.sep) ? '/' : ''));
|
|
1288
1286
|
resolved.search = search;
|
|
1289
1287
|
resolved.hash = hash;
|
|
1290
1288
|
}
|
|
@@ -2357,13 +2355,13 @@ async function findUp$1(name, {
|
|
|
2357
2355
|
type = 'file',
|
|
2358
2356
|
stopAt,
|
|
2359
2357
|
} = {}) {
|
|
2360
|
-
let directory =
|
|
2361
|
-
const {root} =
|
|
2362
|
-
stopAt =
|
|
2363
|
-
const isAbsoluteName =
|
|
2358
|
+
let directory = path.resolve(toPath(cwd) ?? '');
|
|
2359
|
+
const {root} = path.parse(directory);
|
|
2360
|
+
stopAt = path.resolve(directory, toPath(stopAt ?? root));
|
|
2361
|
+
const isAbsoluteName = path.isAbsolute(name);
|
|
2364
2362
|
|
|
2365
2363
|
while (directory) {
|
|
2366
|
-
const filePath = isAbsoluteName ? name :
|
|
2364
|
+
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
2367
2365
|
try {
|
|
2368
2366
|
const stats = await fsPromises.stat(filePath); // eslint-disable-line no-await-in-loop
|
|
2369
2367
|
if ((type === 'file' && stats.isFile()) || (type === 'directory' && stats.isDirectory())) {
|
|
@@ -2375,7 +2373,7 @@ async function findUp$1(name, {
|
|
|
2375
2373
|
break;
|
|
2376
2374
|
}
|
|
2377
2375
|
|
|
2378
|
-
directory =
|
|
2376
|
+
directory = path.dirname(directory);
|
|
2379
2377
|
}
|
|
2380
2378
|
}
|
|
2381
2379
|
|
|
@@ -2384,13 +2382,13 @@ function findUpSync(name, {
|
|
|
2384
2382
|
type = 'file',
|
|
2385
2383
|
stopAt,
|
|
2386
2384
|
} = {}) {
|
|
2387
|
-
let directory =
|
|
2388
|
-
const {root} =
|
|
2389
|
-
stopAt =
|
|
2390
|
-
const isAbsoluteName =
|
|
2385
|
+
let directory = path.resolve(toPath(cwd) ?? '');
|
|
2386
|
+
const {root} = path.parse(directory);
|
|
2387
|
+
stopAt = path.resolve(directory, toPath(stopAt) ?? root);
|
|
2388
|
+
const isAbsoluteName = path.isAbsolute(name);
|
|
2391
2389
|
|
|
2392
2390
|
while (directory) {
|
|
2393
|
-
const filePath = isAbsoluteName ? name :
|
|
2391
|
+
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
2394
2392
|
|
|
2395
2393
|
try {
|
|
2396
2394
|
const stats = fs.statSync(filePath, {throwIfNoEntry: false});
|
|
@@ -2403,7 +2401,7 @@ function findUpSync(name, {
|
|
|
2403
2401
|
break;
|
|
2404
2402
|
}
|
|
2405
2403
|
|
|
2406
|
-
directory =
|
|
2404
|
+
directory = path.dirname(directory);
|
|
2407
2405
|
}
|
|
2408
2406
|
}
|
|
2409
2407
|
|
|
@@ -2512,4133 +2510,6 @@ function getWorkersCountByPercentage(percent) {
|
|
|
2512
2510
|
return Math.max(1, Math.min(maxWorkersCount, workersCountByPercentage));
|
|
2513
2511
|
}
|
|
2514
2512
|
|
|
2515
|
-
var utils$1 = {};
|
|
2516
|
-
|
|
2517
|
-
var hasRequiredUtils$1;
|
|
2518
|
-
|
|
2519
|
-
function requireUtils$1 () {
|
|
2520
|
-
if (hasRequiredUtils$1) return utils$1;
|
|
2521
|
-
hasRequiredUtils$1 = 1;
|
|
2522
|
-
(function (exports) {
|
|
2523
|
-
|
|
2524
|
-
exports.isInteger = num => {
|
|
2525
|
-
if (typeof num === 'number') {
|
|
2526
|
-
return Number.isInteger(num);
|
|
2527
|
-
}
|
|
2528
|
-
if (typeof num === 'string' && num.trim() !== '') {
|
|
2529
|
-
return Number.isInteger(Number(num));
|
|
2530
|
-
}
|
|
2531
|
-
return false;
|
|
2532
|
-
};
|
|
2533
|
-
|
|
2534
|
-
/**
|
|
2535
|
-
* Find a node of the given type
|
|
2536
|
-
*/
|
|
2537
|
-
|
|
2538
|
-
exports.find = (node, type) => node.nodes.find(node => node.type === type);
|
|
2539
|
-
|
|
2540
|
-
/**
|
|
2541
|
-
* Find a node of the given type
|
|
2542
|
-
*/
|
|
2543
|
-
|
|
2544
|
-
exports.exceedsLimit = (min, max, step = 1, limit) => {
|
|
2545
|
-
if (limit === false) return false;
|
|
2546
|
-
if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
|
|
2547
|
-
return ((Number(max) - Number(min)) / Number(step)) >= limit;
|
|
2548
|
-
};
|
|
2549
|
-
|
|
2550
|
-
/**
|
|
2551
|
-
* Escape the given node with '\\' before node.value
|
|
2552
|
-
*/
|
|
2553
|
-
|
|
2554
|
-
exports.escapeNode = (block, n = 0, type) => {
|
|
2555
|
-
const node = block.nodes[n];
|
|
2556
|
-
if (!node) return;
|
|
2557
|
-
|
|
2558
|
-
if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
|
|
2559
|
-
if (node.escaped !== true) {
|
|
2560
|
-
node.value = '\\' + node.value;
|
|
2561
|
-
node.escaped = true;
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
};
|
|
2565
|
-
|
|
2566
|
-
/**
|
|
2567
|
-
* Returns true if the given brace node should be enclosed in literal braces
|
|
2568
|
-
*/
|
|
2569
|
-
|
|
2570
|
-
exports.encloseBrace = node => {
|
|
2571
|
-
if (node.type !== 'brace') return false;
|
|
2572
|
-
if ((node.commas >> 0 + node.ranges >> 0) === 0) {
|
|
2573
|
-
node.invalid = true;
|
|
2574
|
-
return true;
|
|
2575
|
-
}
|
|
2576
|
-
return false;
|
|
2577
|
-
};
|
|
2578
|
-
|
|
2579
|
-
/**
|
|
2580
|
-
* Returns true if a brace node is invalid.
|
|
2581
|
-
*/
|
|
2582
|
-
|
|
2583
|
-
exports.isInvalidBrace = block => {
|
|
2584
|
-
if (block.type !== 'brace') return false;
|
|
2585
|
-
if (block.invalid === true || block.dollar) return true;
|
|
2586
|
-
if ((block.commas >> 0 + block.ranges >> 0) === 0) {
|
|
2587
|
-
block.invalid = true;
|
|
2588
|
-
return true;
|
|
2589
|
-
}
|
|
2590
|
-
if (block.open !== true || block.close !== true) {
|
|
2591
|
-
block.invalid = true;
|
|
2592
|
-
return true;
|
|
2593
|
-
}
|
|
2594
|
-
return false;
|
|
2595
|
-
};
|
|
2596
|
-
|
|
2597
|
-
/**
|
|
2598
|
-
* Returns true if a node is an open or close node
|
|
2599
|
-
*/
|
|
2600
|
-
|
|
2601
|
-
exports.isOpenOrClose = node => {
|
|
2602
|
-
if (node.type === 'open' || node.type === 'close') {
|
|
2603
|
-
return true;
|
|
2604
|
-
}
|
|
2605
|
-
return node.open === true || node.close === true;
|
|
2606
|
-
};
|
|
2607
|
-
|
|
2608
|
-
/**
|
|
2609
|
-
* Reduce an array of text nodes.
|
|
2610
|
-
*/
|
|
2611
|
-
|
|
2612
|
-
exports.reduce = nodes => nodes.reduce((acc, node) => {
|
|
2613
|
-
if (node.type === 'text') acc.push(node.value);
|
|
2614
|
-
if (node.type === 'range') node.type = 'text';
|
|
2615
|
-
return acc;
|
|
2616
|
-
}, []);
|
|
2617
|
-
|
|
2618
|
-
/**
|
|
2619
|
-
* Flatten an array
|
|
2620
|
-
*/
|
|
2621
|
-
|
|
2622
|
-
exports.flatten = (...args) => {
|
|
2623
|
-
const result = [];
|
|
2624
|
-
|
|
2625
|
-
const flat = arr => {
|
|
2626
|
-
for (let i = 0; i < arr.length; i++) {
|
|
2627
|
-
const ele = arr[i];
|
|
2628
|
-
|
|
2629
|
-
if (Array.isArray(ele)) {
|
|
2630
|
-
flat(ele);
|
|
2631
|
-
continue;
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
if (ele !== undefined) {
|
|
2635
|
-
result.push(ele);
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
return result;
|
|
2639
|
-
};
|
|
2640
|
-
|
|
2641
|
-
flat(args);
|
|
2642
|
-
return result;
|
|
2643
|
-
};
|
|
2644
|
-
} (utils$1));
|
|
2645
|
-
return utils$1;
|
|
2646
|
-
}
|
|
2647
|
-
|
|
2648
|
-
var stringify;
|
|
2649
|
-
var hasRequiredStringify;
|
|
2650
|
-
|
|
2651
|
-
function requireStringify () {
|
|
2652
|
-
if (hasRequiredStringify) return stringify;
|
|
2653
|
-
hasRequiredStringify = 1;
|
|
2654
|
-
|
|
2655
|
-
const utils = requireUtils$1();
|
|
2656
|
-
|
|
2657
|
-
stringify = (ast, options = {}) => {
|
|
2658
|
-
const stringify = (node, parent = {}) => {
|
|
2659
|
-
const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
|
2660
|
-
const invalidNode = node.invalid === true && options.escapeInvalid === true;
|
|
2661
|
-
let output = '';
|
|
2662
|
-
|
|
2663
|
-
if (node.value) {
|
|
2664
|
-
if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
|
2665
|
-
return '\\' + node.value;
|
|
2666
|
-
}
|
|
2667
|
-
return node.value;
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
if (node.value) {
|
|
2671
|
-
return node.value;
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
if (node.nodes) {
|
|
2675
|
-
for (const child of node.nodes) {
|
|
2676
|
-
output += stringify(child);
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
return output;
|
|
2680
|
-
};
|
|
2681
|
-
|
|
2682
|
-
return stringify(ast);
|
|
2683
|
-
};
|
|
2684
|
-
return stringify;
|
|
2685
|
-
}
|
|
2686
|
-
|
|
2687
|
-
/*!
|
|
2688
|
-
* is-number <https://github.com/jonschlinkert/is-number>
|
|
2689
|
-
*
|
|
2690
|
-
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
2691
|
-
* Released under the MIT License.
|
|
2692
|
-
*/
|
|
2693
|
-
|
|
2694
|
-
var isNumber;
|
|
2695
|
-
var hasRequiredIsNumber;
|
|
2696
|
-
|
|
2697
|
-
function requireIsNumber () {
|
|
2698
|
-
if (hasRequiredIsNumber) return isNumber;
|
|
2699
|
-
hasRequiredIsNumber = 1;
|
|
2700
|
-
|
|
2701
|
-
isNumber = function(num) {
|
|
2702
|
-
if (typeof num === 'number') {
|
|
2703
|
-
return num - num === 0;
|
|
2704
|
-
}
|
|
2705
|
-
if (typeof num === 'string' && num.trim() !== '') {
|
|
2706
|
-
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
|
|
2707
|
-
}
|
|
2708
|
-
return false;
|
|
2709
|
-
};
|
|
2710
|
-
return isNumber;
|
|
2711
|
-
}
|
|
2712
|
-
|
|
2713
|
-
/*!
|
|
2714
|
-
* to-regex-range <https://github.com/micromatch/to-regex-range>
|
|
2715
|
-
*
|
|
2716
|
-
* Copyright (c) 2015-present, Jon Schlinkert.
|
|
2717
|
-
* Released under the MIT License.
|
|
2718
|
-
*/
|
|
2719
|
-
|
|
2720
|
-
var toRegexRange_1;
|
|
2721
|
-
var hasRequiredToRegexRange;
|
|
2722
|
-
|
|
2723
|
-
function requireToRegexRange () {
|
|
2724
|
-
if (hasRequiredToRegexRange) return toRegexRange_1;
|
|
2725
|
-
hasRequiredToRegexRange = 1;
|
|
2726
|
-
|
|
2727
|
-
const isNumber = requireIsNumber();
|
|
2728
|
-
|
|
2729
|
-
const toRegexRange = (min, max, options) => {
|
|
2730
|
-
if (isNumber(min) === false) {
|
|
2731
|
-
throw new TypeError('toRegexRange: expected the first argument to be a number');
|
|
2732
|
-
}
|
|
2733
|
-
|
|
2734
|
-
if (max === void 0 || min === max) {
|
|
2735
|
-
return String(min);
|
|
2736
|
-
}
|
|
2737
|
-
|
|
2738
|
-
if (isNumber(max) === false) {
|
|
2739
|
-
throw new TypeError('toRegexRange: expected the second argument to be a number.');
|
|
2740
|
-
}
|
|
2741
|
-
|
|
2742
|
-
let opts = { relaxZeros: true, ...options };
|
|
2743
|
-
if (typeof opts.strictZeros === 'boolean') {
|
|
2744
|
-
opts.relaxZeros = opts.strictZeros === false;
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
let relax = String(opts.relaxZeros);
|
|
2748
|
-
let shorthand = String(opts.shorthand);
|
|
2749
|
-
let capture = String(opts.capture);
|
|
2750
|
-
let wrap = String(opts.wrap);
|
|
2751
|
-
let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
|
|
2752
|
-
|
|
2753
|
-
if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
|
|
2754
|
-
return toRegexRange.cache[cacheKey].result;
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2757
|
-
let a = Math.min(min, max);
|
|
2758
|
-
let b = Math.max(min, max);
|
|
2759
|
-
|
|
2760
|
-
if (Math.abs(a - b) === 1) {
|
|
2761
|
-
let result = min + '|' + max;
|
|
2762
|
-
if (opts.capture) {
|
|
2763
|
-
return `(${result})`;
|
|
2764
|
-
}
|
|
2765
|
-
if (opts.wrap === false) {
|
|
2766
|
-
return result;
|
|
2767
|
-
}
|
|
2768
|
-
return `(?:${result})`;
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
let isPadded = hasPadding(min) || hasPadding(max);
|
|
2772
|
-
let state = { min, max, a, b };
|
|
2773
|
-
let positives = [];
|
|
2774
|
-
let negatives = [];
|
|
2775
|
-
|
|
2776
|
-
if (isPadded) {
|
|
2777
|
-
state.isPadded = isPadded;
|
|
2778
|
-
state.maxLen = String(state.max).length;
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
if (a < 0) {
|
|
2782
|
-
let newMin = b < 0 ? Math.abs(b) : 1;
|
|
2783
|
-
negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
|
|
2784
|
-
a = state.a = 0;
|
|
2785
|
-
}
|
|
2786
|
-
|
|
2787
|
-
if (b >= 0) {
|
|
2788
|
-
positives = splitToPatterns(a, b, state, opts);
|
|
2789
|
-
}
|
|
2790
|
-
|
|
2791
|
-
state.negatives = negatives;
|
|
2792
|
-
state.positives = positives;
|
|
2793
|
-
state.result = collatePatterns(negatives, positives);
|
|
2794
|
-
|
|
2795
|
-
if (opts.capture === true) {
|
|
2796
|
-
state.result = `(${state.result})`;
|
|
2797
|
-
} else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
|
|
2798
|
-
state.result = `(?:${state.result})`;
|
|
2799
|
-
}
|
|
2800
|
-
|
|
2801
|
-
toRegexRange.cache[cacheKey] = state;
|
|
2802
|
-
return state.result;
|
|
2803
|
-
};
|
|
2804
|
-
|
|
2805
|
-
function collatePatterns(neg, pos, options) {
|
|
2806
|
-
let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
|
|
2807
|
-
let onlyPositive = filterPatterns(pos, neg, '', false) || [];
|
|
2808
|
-
let intersected = filterPatterns(neg, pos, '-?', true) || [];
|
|
2809
|
-
let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
|
|
2810
|
-
return subpatterns.join('|');
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
function splitToRanges(min, max) {
|
|
2814
|
-
let nines = 1;
|
|
2815
|
-
let zeros = 1;
|
|
2816
|
-
|
|
2817
|
-
let stop = countNines(min, nines);
|
|
2818
|
-
let stops = new Set([max]);
|
|
2819
|
-
|
|
2820
|
-
while (min <= stop && stop <= max) {
|
|
2821
|
-
stops.add(stop);
|
|
2822
|
-
nines += 1;
|
|
2823
|
-
stop = countNines(min, nines);
|
|
2824
|
-
}
|
|
2825
|
-
|
|
2826
|
-
stop = countZeros(max + 1, zeros) - 1;
|
|
2827
|
-
|
|
2828
|
-
while (min < stop && stop <= max) {
|
|
2829
|
-
stops.add(stop);
|
|
2830
|
-
zeros += 1;
|
|
2831
|
-
stop = countZeros(max + 1, zeros) - 1;
|
|
2832
|
-
}
|
|
2833
|
-
|
|
2834
|
-
stops = [...stops];
|
|
2835
|
-
stops.sort(compare);
|
|
2836
|
-
return stops;
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
/**
|
|
2840
|
-
* Convert a range to a regex pattern
|
|
2841
|
-
* @param {Number} `start`
|
|
2842
|
-
* @param {Number} `stop`
|
|
2843
|
-
* @return {String}
|
|
2844
|
-
*/
|
|
2845
|
-
|
|
2846
|
-
function rangeToPattern(start, stop, options) {
|
|
2847
|
-
if (start === stop) {
|
|
2848
|
-
return { pattern: start, count: [], digits: 0 };
|
|
2849
|
-
}
|
|
2850
|
-
|
|
2851
|
-
let zipped = zip(start, stop);
|
|
2852
|
-
let digits = zipped.length;
|
|
2853
|
-
let pattern = '';
|
|
2854
|
-
let count = 0;
|
|
2855
|
-
|
|
2856
|
-
for (let i = 0; i < digits; i++) {
|
|
2857
|
-
let [startDigit, stopDigit] = zipped[i];
|
|
2858
|
-
|
|
2859
|
-
if (startDigit === stopDigit) {
|
|
2860
|
-
pattern += startDigit;
|
|
2861
|
-
|
|
2862
|
-
} else if (startDigit !== '0' || stopDigit !== '9') {
|
|
2863
|
-
pattern += toCharacterClass(startDigit, stopDigit);
|
|
2864
|
-
|
|
2865
|
-
} else {
|
|
2866
|
-
count++;
|
|
2867
|
-
}
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
if (count) {
|
|
2871
|
-
pattern += options.shorthand === true ? '\\d' : '[0-9]';
|
|
2872
|
-
}
|
|
2873
|
-
|
|
2874
|
-
return { pattern, count: [count], digits };
|
|
2875
|
-
}
|
|
2876
|
-
|
|
2877
|
-
function splitToPatterns(min, max, tok, options) {
|
|
2878
|
-
let ranges = splitToRanges(min, max);
|
|
2879
|
-
let tokens = [];
|
|
2880
|
-
let start = min;
|
|
2881
|
-
let prev;
|
|
2882
|
-
|
|
2883
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
2884
|
-
let max = ranges[i];
|
|
2885
|
-
let obj = rangeToPattern(String(start), String(max), options);
|
|
2886
|
-
let zeros = '';
|
|
2887
|
-
|
|
2888
|
-
if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
|
|
2889
|
-
if (prev.count.length > 1) {
|
|
2890
|
-
prev.count.pop();
|
|
2891
|
-
}
|
|
2892
|
-
|
|
2893
|
-
prev.count.push(obj.count[0]);
|
|
2894
|
-
prev.string = prev.pattern + toQuantifier(prev.count);
|
|
2895
|
-
start = max + 1;
|
|
2896
|
-
continue;
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
if (tok.isPadded) {
|
|
2900
|
-
zeros = padZeros(max, tok, options);
|
|
2901
|
-
}
|
|
2902
|
-
|
|
2903
|
-
obj.string = zeros + obj.pattern + toQuantifier(obj.count);
|
|
2904
|
-
tokens.push(obj);
|
|
2905
|
-
start = max + 1;
|
|
2906
|
-
prev = obj;
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
return tokens;
|
|
2910
|
-
}
|
|
2911
|
-
|
|
2912
|
-
function filterPatterns(arr, comparison, prefix, intersection, options) {
|
|
2913
|
-
let result = [];
|
|
2914
|
-
|
|
2915
|
-
for (let ele of arr) {
|
|
2916
|
-
let { string } = ele;
|
|
2917
|
-
|
|
2918
|
-
// only push if _both_ are negative...
|
|
2919
|
-
if (!intersection && !contains(comparison, 'string', string)) {
|
|
2920
|
-
result.push(prefix + string);
|
|
2921
|
-
}
|
|
2922
|
-
|
|
2923
|
-
// or _both_ are positive
|
|
2924
|
-
if (intersection && contains(comparison, 'string', string)) {
|
|
2925
|
-
result.push(prefix + string);
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
return result;
|
|
2929
|
-
}
|
|
2930
|
-
|
|
2931
|
-
/**
|
|
2932
|
-
* Zip strings
|
|
2933
|
-
*/
|
|
2934
|
-
|
|
2935
|
-
function zip(a, b) {
|
|
2936
|
-
let arr = [];
|
|
2937
|
-
for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
|
|
2938
|
-
return arr;
|
|
2939
|
-
}
|
|
2940
|
-
|
|
2941
|
-
function compare(a, b) {
|
|
2942
|
-
return a > b ? 1 : b > a ? -1 : 0;
|
|
2943
|
-
}
|
|
2944
|
-
|
|
2945
|
-
function contains(arr, key, val) {
|
|
2946
|
-
return arr.some(ele => ele[key] === val);
|
|
2947
|
-
}
|
|
2948
|
-
|
|
2949
|
-
function countNines(min, len) {
|
|
2950
|
-
return Number(String(min).slice(0, -len) + '9'.repeat(len));
|
|
2951
|
-
}
|
|
2952
|
-
|
|
2953
|
-
function countZeros(integer, zeros) {
|
|
2954
|
-
return integer - (integer % Math.pow(10, zeros));
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
function toQuantifier(digits) {
|
|
2958
|
-
let [start = 0, stop = ''] = digits;
|
|
2959
|
-
if (stop || start > 1) {
|
|
2960
|
-
return `{${start + (stop ? ',' + stop : '')}}`;
|
|
2961
|
-
}
|
|
2962
|
-
return '';
|
|
2963
|
-
}
|
|
2964
|
-
|
|
2965
|
-
function toCharacterClass(a, b, options) {
|
|
2966
|
-
return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
function hasPadding(str) {
|
|
2970
|
-
return /^-?(0+)\d/.test(str);
|
|
2971
|
-
}
|
|
2972
|
-
|
|
2973
|
-
function padZeros(value, tok, options) {
|
|
2974
|
-
if (!tok.isPadded) {
|
|
2975
|
-
return value;
|
|
2976
|
-
}
|
|
2977
|
-
|
|
2978
|
-
let diff = Math.abs(tok.maxLen - String(value).length);
|
|
2979
|
-
let relax = options.relaxZeros !== false;
|
|
2980
|
-
|
|
2981
|
-
switch (diff) {
|
|
2982
|
-
case 0:
|
|
2983
|
-
return '';
|
|
2984
|
-
case 1:
|
|
2985
|
-
return relax ? '0?' : '0';
|
|
2986
|
-
case 2:
|
|
2987
|
-
return relax ? '0{0,2}' : '00';
|
|
2988
|
-
default: {
|
|
2989
|
-
return relax ? `0{0,${diff}}` : `0{${diff}}`;
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
|
-
/**
|
|
2995
|
-
* Cache
|
|
2996
|
-
*/
|
|
2997
|
-
|
|
2998
|
-
toRegexRange.cache = {};
|
|
2999
|
-
toRegexRange.clearCache = () => (toRegexRange.cache = {});
|
|
3000
|
-
|
|
3001
|
-
/**
|
|
3002
|
-
* Expose `toRegexRange`
|
|
3003
|
-
*/
|
|
3004
|
-
|
|
3005
|
-
toRegexRange_1 = toRegexRange;
|
|
3006
|
-
return toRegexRange_1;
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
/*!
|
|
3010
|
-
* fill-range <https://github.com/jonschlinkert/fill-range>
|
|
3011
|
-
*
|
|
3012
|
-
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
3013
|
-
* Licensed under the MIT License.
|
|
3014
|
-
*/
|
|
3015
|
-
|
|
3016
|
-
var fillRange;
|
|
3017
|
-
var hasRequiredFillRange;
|
|
3018
|
-
|
|
3019
|
-
function requireFillRange () {
|
|
3020
|
-
if (hasRequiredFillRange) return fillRange;
|
|
3021
|
-
hasRequiredFillRange = 1;
|
|
3022
|
-
|
|
3023
|
-
const util = require$$0;
|
|
3024
|
-
const toRegexRange = requireToRegexRange();
|
|
3025
|
-
|
|
3026
|
-
const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
3027
|
-
|
|
3028
|
-
const transform = toNumber => {
|
|
3029
|
-
return value => toNumber === true ? Number(value) : String(value);
|
|
3030
|
-
};
|
|
3031
|
-
|
|
3032
|
-
const isValidValue = value => {
|
|
3033
|
-
return typeof value === 'number' || (typeof value === 'string' && value !== '');
|
|
3034
|
-
};
|
|
3035
|
-
|
|
3036
|
-
const isNumber = num => Number.isInteger(+num);
|
|
3037
|
-
|
|
3038
|
-
const zeros = input => {
|
|
3039
|
-
let value = `${input}`;
|
|
3040
|
-
let index = -1;
|
|
3041
|
-
if (value[0] === '-') value = value.slice(1);
|
|
3042
|
-
if (value === '0') return false;
|
|
3043
|
-
while (value[++index] === '0');
|
|
3044
|
-
return index > 0;
|
|
3045
|
-
};
|
|
3046
|
-
|
|
3047
|
-
const stringify = (start, end, options) => {
|
|
3048
|
-
if (typeof start === 'string' || typeof end === 'string') {
|
|
3049
|
-
return true;
|
|
3050
|
-
}
|
|
3051
|
-
return options.stringify === true;
|
|
3052
|
-
};
|
|
3053
|
-
|
|
3054
|
-
const pad = (input, maxLength, toNumber) => {
|
|
3055
|
-
if (maxLength > 0) {
|
|
3056
|
-
let dash = input[0] === '-' ? '-' : '';
|
|
3057
|
-
if (dash) input = input.slice(1);
|
|
3058
|
-
input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
|
|
3059
|
-
}
|
|
3060
|
-
if (toNumber === false) {
|
|
3061
|
-
return String(input);
|
|
3062
|
-
}
|
|
3063
|
-
return input;
|
|
3064
|
-
};
|
|
3065
|
-
|
|
3066
|
-
const toMaxLen = (input, maxLength) => {
|
|
3067
|
-
let negative = input[0] === '-' ? '-' : '';
|
|
3068
|
-
if (negative) {
|
|
3069
|
-
input = input.slice(1);
|
|
3070
|
-
maxLength--;
|
|
3071
|
-
}
|
|
3072
|
-
while (input.length < maxLength) input = '0' + input;
|
|
3073
|
-
return negative ? ('-' + input) : input;
|
|
3074
|
-
};
|
|
3075
|
-
|
|
3076
|
-
const toSequence = (parts, options, maxLen) => {
|
|
3077
|
-
parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
3078
|
-
parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
3079
|
-
|
|
3080
|
-
let prefix = options.capture ? '' : '?:';
|
|
3081
|
-
let positives = '';
|
|
3082
|
-
let negatives = '';
|
|
3083
|
-
let result;
|
|
3084
|
-
|
|
3085
|
-
if (parts.positives.length) {
|
|
3086
|
-
positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
|
|
3087
|
-
}
|
|
3088
|
-
|
|
3089
|
-
if (parts.negatives.length) {
|
|
3090
|
-
negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
|
|
3091
|
-
}
|
|
3092
|
-
|
|
3093
|
-
if (positives && negatives) {
|
|
3094
|
-
result = `${positives}|${negatives}`;
|
|
3095
|
-
} else {
|
|
3096
|
-
result = positives || negatives;
|
|
3097
|
-
}
|
|
3098
|
-
|
|
3099
|
-
if (options.wrap) {
|
|
3100
|
-
return `(${prefix}${result})`;
|
|
3101
|
-
}
|
|
3102
|
-
|
|
3103
|
-
return result;
|
|
3104
|
-
};
|
|
3105
|
-
|
|
3106
|
-
const toRange = (a, b, isNumbers, options) => {
|
|
3107
|
-
if (isNumbers) {
|
|
3108
|
-
return toRegexRange(a, b, { wrap: false, ...options });
|
|
3109
|
-
}
|
|
3110
|
-
|
|
3111
|
-
let start = String.fromCharCode(a);
|
|
3112
|
-
if (a === b) return start;
|
|
3113
|
-
|
|
3114
|
-
let stop = String.fromCharCode(b);
|
|
3115
|
-
return `[${start}-${stop}]`;
|
|
3116
|
-
};
|
|
3117
|
-
|
|
3118
|
-
const toRegex = (start, end, options) => {
|
|
3119
|
-
if (Array.isArray(start)) {
|
|
3120
|
-
let wrap = options.wrap === true;
|
|
3121
|
-
let prefix = options.capture ? '' : '?:';
|
|
3122
|
-
return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
|
|
3123
|
-
}
|
|
3124
|
-
return toRegexRange(start, end, options);
|
|
3125
|
-
};
|
|
3126
|
-
|
|
3127
|
-
const rangeError = (...args) => {
|
|
3128
|
-
return new RangeError('Invalid range arguments: ' + util.inspect(...args));
|
|
3129
|
-
};
|
|
3130
|
-
|
|
3131
|
-
const invalidRange = (start, end, options) => {
|
|
3132
|
-
if (options.strictRanges === true) throw rangeError([start, end]);
|
|
3133
|
-
return [];
|
|
3134
|
-
};
|
|
3135
|
-
|
|
3136
|
-
const invalidStep = (step, options) => {
|
|
3137
|
-
if (options.strictRanges === true) {
|
|
3138
|
-
throw new TypeError(`Expected step "${step}" to be a number`);
|
|
3139
|
-
}
|
|
3140
|
-
return [];
|
|
3141
|
-
};
|
|
3142
|
-
|
|
3143
|
-
const fillNumbers = (start, end, step = 1, options = {}) => {
|
|
3144
|
-
let a = Number(start);
|
|
3145
|
-
let b = Number(end);
|
|
3146
|
-
|
|
3147
|
-
if (!Number.isInteger(a) || !Number.isInteger(b)) {
|
|
3148
|
-
if (options.strictRanges === true) throw rangeError([start, end]);
|
|
3149
|
-
return [];
|
|
3150
|
-
}
|
|
3151
|
-
|
|
3152
|
-
// fix negative zero
|
|
3153
|
-
if (a === 0) a = 0;
|
|
3154
|
-
if (b === 0) b = 0;
|
|
3155
|
-
|
|
3156
|
-
let descending = a > b;
|
|
3157
|
-
let startString = String(start);
|
|
3158
|
-
let endString = String(end);
|
|
3159
|
-
let stepString = String(step);
|
|
3160
|
-
step = Math.max(Math.abs(step), 1);
|
|
3161
|
-
|
|
3162
|
-
let padded = zeros(startString) || zeros(endString) || zeros(stepString);
|
|
3163
|
-
let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
|
|
3164
|
-
let toNumber = padded === false && stringify(start, end, options) === false;
|
|
3165
|
-
let format = options.transform || transform(toNumber);
|
|
3166
|
-
|
|
3167
|
-
if (options.toRegex && step === 1) {
|
|
3168
|
-
return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
|
|
3169
|
-
}
|
|
3170
|
-
|
|
3171
|
-
let parts = { negatives: [], positives: [] };
|
|
3172
|
-
let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
|
|
3173
|
-
let range = [];
|
|
3174
|
-
let index = 0;
|
|
3175
|
-
|
|
3176
|
-
while (descending ? a >= b : a <= b) {
|
|
3177
|
-
if (options.toRegex === true && step > 1) {
|
|
3178
|
-
push(a);
|
|
3179
|
-
} else {
|
|
3180
|
-
range.push(pad(format(a, index), maxLen, toNumber));
|
|
3181
|
-
}
|
|
3182
|
-
a = descending ? a - step : a + step;
|
|
3183
|
-
index++;
|
|
3184
|
-
}
|
|
3185
|
-
|
|
3186
|
-
if (options.toRegex === true) {
|
|
3187
|
-
return step > 1
|
|
3188
|
-
? toSequence(parts, options, maxLen)
|
|
3189
|
-
: toRegex(range, null, { wrap: false, ...options });
|
|
3190
|
-
}
|
|
3191
|
-
|
|
3192
|
-
return range;
|
|
3193
|
-
};
|
|
3194
|
-
|
|
3195
|
-
const fillLetters = (start, end, step = 1, options = {}) => {
|
|
3196
|
-
if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
|
|
3197
|
-
return invalidRange(start, end, options);
|
|
3198
|
-
}
|
|
3199
|
-
|
|
3200
|
-
let format = options.transform || (val => String.fromCharCode(val));
|
|
3201
|
-
let a = `${start}`.charCodeAt(0);
|
|
3202
|
-
let b = `${end}`.charCodeAt(0);
|
|
3203
|
-
|
|
3204
|
-
let descending = a > b;
|
|
3205
|
-
let min = Math.min(a, b);
|
|
3206
|
-
let max = Math.max(a, b);
|
|
3207
|
-
|
|
3208
|
-
if (options.toRegex && step === 1) {
|
|
3209
|
-
return toRange(min, max, false, options);
|
|
3210
|
-
}
|
|
3211
|
-
|
|
3212
|
-
let range = [];
|
|
3213
|
-
let index = 0;
|
|
3214
|
-
|
|
3215
|
-
while (descending ? a >= b : a <= b) {
|
|
3216
|
-
range.push(format(a, index));
|
|
3217
|
-
a = descending ? a - step : a + step;
|
|
3218
|
-
index++;
|
|
3219
|
-
}
|
|
3220
|
-
|
|
3221
|
-
if (options.toRegex === true) {
|
|
3222
|
-
return toRegex(range, null, { wrap: false, options });
|
|
3223
|
-
}
|
|
3224
|
-
|
|
3225
|
-
return range;
|
|
3226
|
-
};
|
|
3227
|
-
|
|
3228
|
-
const fill = (start, end, step, options = {}) => {
|
|
3229
|
-
if (end == null && isValidValue(start)) {
|
|
3230
|
-
return [start];
|
|
3231
|
-
}
|
|
3232
|
-
|
|
3233
|
-
if (!isValidValue(start) || !isValidValue(end)) {
|
|
3234
|
-
return invalidRange(start, end, options);
|
|
3235
|
-
}
|
|
3236
|
-
|
|
3237
|
-
if (typeof step === 'function') {
|
|
3238
|
-
return fill(start, end, 1, { transform: step });
|
|
3239
|
-
}
|
|
3240
|
-
|
|
3241
|
-
if (isObject(step)) {
|
|
3242
|
-
return fill(start, end, 0, step);
|
|
3243
|
-
}
|
|
3244
|
-
|
|
3245
|
-
let opts = { ...options };
|
|
3246
|
-
if (opts.capture === true) opts.wrap = true;
|
|
3247
|
-
step = step || opts.step || 1;
|
|
3248
|
-
|
|
3249
|
-
if (!isNumber(step)) {
|
|
3250
|
-
if (step != null && !isObject(step)) return invalidStep(step, opts);
|
|
3251
|
-
return fill(start, end, 1, step);
|
|
3252
|
-
}
|
|
3253
|
-
|
|
3254
|
-
if (isNumber(start) && isNumber(end)) {
|
|
3255
|
-
return fillNumbers(start, end, step, opts);
|
|
3256
|
-
}
|
|
3257
|
-
|
|
3258
|
-
return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
|
|
3259
|
-
};
|
|
3260
|
-
|
|
3261
|
-
fillRange = fill;
|
|
3262
|
-
return fillRange;
|
|
3263
|
-
}
|
|
3264
|
-
|
|
3265
|
-
var compile_1;
|
|
3266
|
-
var hasRequiredCompile;
|
|
3267
|
-
|
|
3268
|
-
function requireCompile () {
|
|
3269
|
-
if (hasRequiredCompile) return compile_1;
|
|
3270
|
-
hasRequiredCompile = 1;
|
|
3271
|
-
|
|
3272
|
-
const fill = requireFillRange();
|
|
3273
|
-
const utils = requireUtils$1();
|
|
3274
|
-
|
|
3275
|
-
const compile = (ast, options = {}) => {
|
|
3276
|
-
const walk = (node, parent = {}) => {
|
|
3277
|
-
const invalidBlock = utils.isInvalidBrace(parent);
|
|
3278
|
-
const invalidNode = node.invalid === true && options.escapeInvalid === true;
|
|
3279
|
-
const invalid = invalidBlock === true || invalidNode === true;
|
|
3280
|
-
const prefix = options.escapeInvalid === true ? '\\' : '';
|
|
3281
|
-
let output = '';
|
|
3282
|
-
|
|
3283
|
-
if (node.isOpen === true) {
|
|
3284
|
-
return prefix + node.value;
|
|
3285
|
-
}
|
|
3286
|
-
|
|
3287
|
-
if (node.isClose === true) {
|
|
3288
|
-
console.log('node.isClose', prefix, node.value);
|
|
3289
|
-
return prefix + node.value;
|
|
3290
|
-
}
|
|
3291
|
-
|
|
3292
|
-
if (node.type === 'open') {
|
|
3293
|
-
return invalid ? prefix + node.value : '(';
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
if (node.type === 'close') {
|
|
3297
|
-
return invalid ? prefix + node.value : ')';
|
|
3298
|
-
}
|
|
3299
|
-
|
|
3300
|
-
if (node.type === 'comma') {
|
|
3301
|
-
return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
|
|
3302
|
-
}
|
|
3303
|
-
|
|
3304
|
-
if (node.value) {
|
|
3305
|
-
return node.value;
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
if (node.nodes && node.ranges > 0) {
|
|
3309
|
-
const args = utils.reduce(node.nodes);
|
|
3310
|
-
const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
|
|
3311
|
-
|
|
3312
|
-
if (range.length !== 0) {
|
|
3313
|
-
return args.length > 1 && range.length > 1 ? `(${range})` : range;
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
if (node.nodes) {
|
|
3318
|
-
for (const child of node.nodes) {
|
|
3319
|
-
output += walk(child, node);
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
|
|
3323
|
-
return output;
|
|
3324
|
-
};
|
|
3325
|
-
|
|
3326
|
-
return walk(ast);
|
|
3327
|
-
};
|
|
3328
|
-
|
|
3329
|
-
compile_1 = compile;
|
|
3330
|
-
return compile_1;
|
|
3331
|
-
}
|
|
3332
|
-
|
|
3333
|
-
var expand_1;
|
|
3334
|
-
var hasRequiredExpand;
|
|
3335
|
-
|
|
3336
|
-
function requireExpand () {
|
|
3337
|
-
if (hasRequiredExpand) return expand_1;
|
|
3338
|
-
hasRequiredExpand = 1;
|
|
3339
|
-
|
|
3340
|
-
const fill = requireFillRange();
|
|
3341
|
-
const stringify = requireStringify();
|
|
3342
|
-
const utils = requireUtils$1();
|
|
3343
|
-
|
|
3344
|
-
const append = (queue = '', stash = '', enclose = false) => {
|
|
3345
|
-
const result = [];
|
|
3346
|
-
|
|
3347
|
-
queue = [].concat(queue);
|
|
3348
|
-
stash = [].concat(stash);
|
|
3349
|
-
|
|
3350
|
-
if (!stash.length) return queue;
|
|
3351
|
-
if (!queue.length) {
|
|
3352
|
-
return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
|
|
3353
|
-
}
|
|
3354
|
-
|
|
3355
|
-
for (const item of queue) {
|
|
3356
|
-
if (Array.isArray(item)) {
|
|
3357
|
-
for (const value of item) {
|
|
3358
|
-
result.push(append(value, stash, enclose));
|
|
3359
|
-
}
|
|
3360
|
-
} else {
|
|
3361
|
-
for (let ele of stash) {
|
|
3362
|
-
if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
|
|
3363
|
-
result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
|
|
3364
|
-
}
|
|
3365
|
-
}
|
|
3366
|
-
}
|
|
3367
|
-
return utils.flatten(result);
|
|
3368
|
-
};
|
|
3369
|
-
|
|
3370
|
-
const expand = (ast, options = {}) => {
|
|
3371
|
-
const rangeLimit = options.rangeLimit === undefined ? 1000 : options.rangeLimit;
|
|
3372
|
-
|
|
3373
|
-
const walk = (node, parent = {}) => {
|
|
3374
|
-
node.queue = [];
|
|
3375
|
-
|
|
3376
|
-
let p = parent;
|
|
3377
|
-
let q = parent.queue;
|
|
3378
|
-
|
|
3379
|
-
while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
|
|
3380
|
-
p = p.parent;
|
|
3381
|
-
q = p.queue;
|
|
3382
|
-
}
|
|
3383
|
-
|
|
3384
|
-
if (node.invalid || node.dollar) {
|
|
3385
|
-
q.push(append(q.pop(), stringify(node, options)));
|
|
3386
|
-
return;
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
|
|
3390
|
-
q.push(append(q.pop(), ['{}']));
|
|
3391
|
-
return;
|
|
3392
|
-
}
|
|
3393
|
-
|
|
3394
|
-
if (node.nodes && node.ranges > 0) {
|
|
3395
|
-
const args = utils.reduce(node.nodes);
|
|
3396
|
-
|
|
3397
|
-
if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
|
|
3398
|
-
throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
|
|
3399
|
-
}
|
|
3400
|
-
|
|
3401
|
-
let range = fill(...args, options);
|
|
3402
|
-
if (range.length === 0) {
|
|
3403
|
-
range = stringify(node, options);
|
|
3404
|
-
}
|
|
3405
|
-
|
|
3406
|
-
q.push(append(q.pop(), range));
|
|
3407
|
-
node.nodes = [];
|
|
3408
|
-
return;
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
const enclose = utils.encloseBrace(node);
|
|
3412
|
-
let queue = node.queue;
|
|
3413
|
-
let block = node;
|
|
3414
|
-
|
|
3415
|
-
while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
|
|
3416
|
-
block = block.parent;
|
|
3417
|
-
queue = block.queue;
|
|
3418
|
-
}
|
|
3419
|
-
|
|
3420
|
-
for (let i = 0; i < node.nodes.length; i++) {
|
|
3421
|
-
const child = node.nodes[i];
|
|
3422
|
-
|
|
3423
|
-
if (child.type === 'comma' && node.type === 'brace') {
|
|
3424
|
-
if (i === 1) queue.push('');
|
|
3425
|
-
queue.push('');
|
|
3426
|
-
continue;
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
if (child.type === 'close') {
|
|
3430
|
-
q.push(append(q.pop(), queue, enclose));
|
|
3431
|
-
continue;
|
|
3432
|
-
}
|
|
3433
|
-
|
|
3434
|
-
if (child.value && child.type !== 'open') {
|
|
3435
|
-
queue.push(append(queue.pop(), child.value));
|
|
3436
|
-
continue;
|
|
3437
|
-
}
|
|
3438
|
-
|
|
3439
|
-
if (child.nodes) {
|
|
3440
|
-
walk(child, node);
|
|
3441
|
-
}
|
|
3442
|
-
}
|
|
3443
|
-
|
|
3444
|
-
return queue;
|
|
3445
|
-
};
|
|
3446
|
-
|
|
3447
|
-
return utils.flatten(walk(ast));
|
|
3448
|
-
};
|
|
3449
|
-
|
|
3450
|
-
expand_1 = expand;
|
|
3451
|
-
return expand_1;
|
|
3452
|
-
}
|
|
3453
|
-
|
|
3454
|
-
var constants$1;
|
|
3455
|
-
var hasRequiredConstants$1;
|
|
3456
|
-
|
|
3457
|
-
function requireConstants$1 () {
|
|
3458
|
-
if (hasRequiredConstants$1) return constants$1;
|
|
3459
|
-
hasRequiredConstants$1 = 1;
|
|
3460
|
-
|
|
3461
|
-
constants$1 = {
|
|
3462
|
-
MAX_LENGTH: 10000,
|
|
3463
|
-
|
|
3464
|
-
// Digits
|
|
3465
|
-
CHAR_0: '0', /* 0 */
|
|
3466
|
-
CHAR_9: '9', /* 9 */
|
|
3467
|
-
|
|
3468
|
-
// Alphabet chars.
|
|
3469
|
-
CHAR_UPPERCASE_A: 'A', /* A */
|
|
3470
|
-
CHAR_LOWERCASE_A: 'a', /* a */
|
|
3471
|
-
CHAR_UPPERCASE_Z: 'Z', /* Z */
|
|
3472
|
-
CHAR_LOWERCASE_Z: 'z', /* z */
|
|
3473
|
-
|
|
3474
|
-
CHAR_LEFT_PARENTHESES: '(', /* ( */
|
|
3475
|
-
CHAR_RIGHT_PARENTHESES: ')', /* ) */
|
|
3476
|
-
|
|
3477
|
-
CHAR_ASTERISK: '*', /* * */
|
|
3478
|
-
|
|
3479
|
-
// Non-alphabetic chars.
|
|
3480
|
-
CHAR_AMPERSAND: '&', /* & */
|
|
3481
|
-
CHAR_AT: '@', /* @ */
|
|
3482
|
-
CHAR_BACKSLASH: '\\', /* \ */
|
|
3483
|
-
CHAR_BACKTICK: '`', /* ` */
|
|
3484
|
-
CHAR_CARRIAGE_RETURN: '\r', /* \r */
|
|
3485
|
-
CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
|
|
3486
|
-
CHAR_COLON: ':', /* : */
|
|
3487
|
-
CHAR_COMMA: ',', /* , */
|
|
3488
|
-
CHAR_DOLLAR: '$', /* . */
|
|
3489
|
-
CHAR_DOT: '.', /* . */
|
|
3490
|
-
CHAR_DOUBLE_QUOTE: '"', /* " */
|
|
3491
|
-
CHAR_EQUAL: '=', /* = */
|
|
3492
|
-
CHAR_EXCLAMATION_MARK: '!', /* ! */
|
|
3493
|
-
CHAR_FORM_FEED: '\f', /* \f */
|
|
3494
|
-
CHAR_FORWARD_SLASH: '/', /* / */
|
|
3495
|
-
CHAR_HASH: '#', /* # */
|
|
3496
|
-
CHAR_HYPHEN_MINUS: '-', /* - */
|
|
3497
|
-
CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
|
|
3498
|
-
CHAR_LEFT_CURLY_BRACE: '{', /* { */
|
|
3499
|
-
CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
|
|
3500
|
-
CHAR_LINE_FEED: '\n', /* \n */
|
|
3501
|
-
CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
|
|
3502
|
-
CHAR_PERCENT: '%', /* % */
|
|
3503
|
-
CHAR_PLUS: '+', /* + */
|
|
3504
|
-
CHAR_QUESTION_MARK: '?', /* ? */
|
|
3505
|
-
CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
|
|
3506
|
-
CHAR_RIGHT_CURLY_BRACE: '}', /* } */
|
|
3507
|
-
CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
|
|
3508
|
-
CHAR_SEMICOLON: ';', /* ; */
|
|
3509
|
-
CHAR_SINGLE_QUOTE: '\'', /* ' */
|
|
3510
|
-
CHAR_SPACE: ' ', /* */
|
|
3511
|
-
CHAR_TAB: '\t', /* \t */
|
|
3512
|
-
CHAR_UNDERSCORE: '_', /* _ */
|
|
3513
|
-
CHAR_VERTICAL_LINE: '|', /* | */
|
|
3514
|
-
CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
|
|
3515
|
-
};
|
|
3516
|
-
return constants$1;
|
|
3517
|
-
}
|
|
3518
|
-
|
|
3519
|
-
var parse_1$1;
|
|
3520
|
-
var hasRequiredParse$1;
|
|
3521
|
-
|
|
3522
|
-
function requireParse$1 () {
|
|
3523
|
-
if (hasRequiredParse$1) return parse_1$1;
|
|
3524
|
-
hasRequiredParse$1 = 1;
|
|
3525
|
-
|
|
3526
|
-
const stringify = requireStringify();
|
|
3527
|
-
|
|
3528
|
-
/**
|
|
3529
|
-
* Constants
|
|
3530
|
-
*/
|
|
3531
|
-
|
|
3532
|
-
const {
|
|
3533
|
-
MAX_LENGTH,
|
|
3534
|
-
CHAR_BACKSLASH, /* \ */
|
|
3535
|
-
CHAR_BACKTICK, /* ` */
|
|
3536
|
-
CHAR_COMMA, /* , */
|
|
3537
|
-
CHAR_DOT, /* . */
|
|
3538
|
-
CHAR_LEFT_PARENTHESES, /* ( */
|
|
3539
|
-
CHAR_RIGHT_PARENTHESES, /* ) */
|
|
3540
|
-
CHAR_LEFT_CURLY_BRACE, /* { */
|
|
3541
|
-
CHAR_RIGHT_CURLY_BRACE, /* } */
|
|
3542
|
-
CHAR_LEFT_SQUARE_BRACKET, /* [ */
|
|
3543
|
-
CHAR_RIGHT_SQUARE_BRACKET, /* ] */
|
|
3544
|
-
CHAR_DOUBLE_QUOTE, /* " */
|
|
3545
|
-
CHAR_SINGLE_QUOTE, /* ' */
|
|
3546
|
-
CHAR_NO_BREAK_SPACE,
|
|
3547
|
-
CHAR_ZERO_WIDTH_NOBREAK_SPACE
|
|
3548
|
-
} = requireConstants$1();
|
|
3549
|
-
|
|
3550
|
-
/**
|
|
3551
|
-
* parse
|
|
3552
|
-
*/
|
|
3553
|
-
|
|
3554
|
-
const parse = (input, options = {}) => {
|
|
3555
|
-
if (typeof input !== 'string') {
|
|
3556
|
-
throw new TypeError('Expected a string');
|
|
3557
|
-
}
|
|
3558
|
-
|
|
3559
|
-
const opts = options || {};
|
|
3560
|
-
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
3561
|
-
if (input.length > max) {
|
|
3562
|
-
throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
|
-
const ast = { type: 'root', input, nodes: [] };
|
|
3566
|
-
const stack = [ast];
|
|
3567
|
-
let block = ast;
|
|
3568
|
-
let prev = ast;
|
|
3569
|
-
let brackets = 0;
|
|
3570
|
-
const length = input.length;
|
|
3571
|
-
let index = 0;
|
|
3572
|
-
let depth = 0;
|
|
3573
|
-
let value;
|
|
3574
|
-
|
|
3575
|
-
/**
|
|
3576
|
-
* Helpers
|
|
3577
|
-
*/
|
|
3578
|
-
|
|
3579
|
-
const advance = () => input[index++];
|
|
3580
|
-
const push = node => {
|
|
3581
|
-
if (node.type === 'text' && prev.type === 'dot') {
|
|
3582
|
-
prev.type = 'text';
|
|
3583
|
-
}
|
|
3584
|
-
|
|
3585
|
-
if (prev && prev.type === 'text' && node.type === 'text') {
|
|
3586
|
-
prev.value += node.value;
|
|
3587
|
-
return;
|
|
3588
|
-
}
|
|
3589
|
-
|
|
3590
|
-
block.nodes.push(node);
|
|
3591
|
-
node.parent = block;
|
|
3592
|
-
node.prev = prev;
|
|
3593
|
-
prev = node;
|
|
3594
|
-
return node;
|
|
3595
|
-
};
|
|
3596
|
-
|
|
3597
|
-
push({ type: 'bos' });
|
|
3598
|
-
|
|
3599
|
-
while (index < length) {
|
|
3600
|
-
block = stack[stack.length - 1];
|
|
3601
|
-
value = advance();
|
|
3602
|
-
|
|
3603
|
-
/**
|
|
3604
|
-
* Invalid chars
|
|
3605
|
-
*/
|
|
3606
|
-
|
|
3607
|
-
if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
|
|
3608
|
-
continue;
|
|
3609
|
-
}
|
|
3610
|
-
|
|
3611
|
-
/**
|
|
3612
|
-
* Escaped chars
|
|
3613
|
-
*/
|
|
3614
|
-
|
|
3615
|
-
if (value === CHAR_BACKSLASH) {
|
|
3616
|
-
push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
|
|
3617
|
-
continue;
|
|
3618
|
-
}
|
|
3619
|
-
|
|
3620
|
-
/**
|
|
3621
|
-
* Right square bracket (literal): ']'
|
|
3622
|
-
*/
|
|
3623
|
-
|
|
3624
|
-
if (value === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
3625
|
-
push({ type: 'text', value: '\\' + value });
|
|
3626
|
-
continue;
|
|
3627
|
-
}
|
|
3628
|
-
|
|
3629
|
-
/**
|
|
3630
|
-
* Left square bracket: '['
|
|
3631
|
-
*/
|
|
3632
|
-
|
|
3633
|
-
if (value === CHAR_LEFT_SQUARE_BRACKET) {
|
|
3634
|
-
brackets++;
|
|
3635
|
-
|
|
3636
|
-
let next;
|
|
3637
|
-
|
|
3638
|
-
while (index < length && (next = advance())) {
|
|
3639
|
-
value += next;
|
|
3640
|
-
|
|
3641
|
-
if (next === CHAR_LEFT_SQUARE_BRACKET) {
|
|
3642
|
-
brackets++;
|
|
3643
|
-
continue;
|
|
3644
|
-
}
|
|
3645
|
-
|
|
3646
|
-
if (next === CHAR_BACKSLASH) {
|
|
3647
|
-
value += advance();
|
|
3648
|
-
continue;
|
|
3649
|
-
}
|
|
3650
|
-
|
|
3651
|
-
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
3652
|
-
brackets--;
|
|
3653
|
-
|
|
3654
|
-
if (brackets === 0) {
|
|
3655
|
-
break;
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
}
|
|
3659
|
-
|
|
3660
|
-
push({ type: 'text', value });
|
|
3661
|
-
continue;
|
|
3662
|
-
}
|
|
3663
|
-
|
|
3664
|
-
/**
|
|
3665
|
-
* Parentheses
|
|
3666
|
-
*/
|
|
3667
|
-
|
|
3668
|
-
if (value === CHAR_LEFT_PARENTHESES) {
|
|
3669
|
-
block = push({ type: 'paren', nodes: [] });
|
|
3670
|
-
stack.push(block);
|
|
3671
|
-
push({ type: 'text', value });
|
|
3672
|
-
continue;
|
|
3673
|
-
}
|
|
3674
|
-
|
|
3675
|
-
if (value === CHAR_RIGHT_PARENTHESES) {
|
|
3676
|
-
if (block.type !== 'paren') {
|
|
3677
|
-
push({ type: 'text', value });
|
|
3678
|
-
continue;
|
|
3679
|
-
}
|
|
3680
|
-
block = stack.pop();
|
|
3681
|
-
push({ type: 'text', value });
|
|
3682
|
-
block = stack[stack.length - 1];
|
|
3683
|
-
continue;
|
|
3684
|
-
}
|
|
3685
|
-
|
|
3686
|
-
/**
|
|
3687
|
-
* Quotes: '|"|`
|
|
3688
|
-
*/
|
|
3689
|
-
|
|
3690
|
-
if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
|
|
3691
|
-
const open = value;
|
|
3692
|
-
let next;
|
|
3693
|
-
|
|
3694
|
-
if (options.keepQuotes !== true) {
|
|
3695
|
-
value = '';
|
|
3696
|
-
}
|
|
3697
|
-
|
|
3698
|
-
while (index < length && (next = advance())) {
|
|
3699
|
-
if (next === CHAR_BACKSLASH) {
|
|
3700
|
-
value += next + advance();
|
|
3701
|
-
continue;
|
|
3702
|
-
}
|
|
3703
|
-
|
|
3704
|
-
if (next === open) {
|
|
3705
|
-
if (options.keepQuotes === true) value += next;
|
|
3706
|
-
break;
|
|
3707
|
-
}
|
|
3708
|
-
|
|
3709
|
-
value += next;
|
|
3710
|
-
}
|
|
3711
|
-
|
|
3712
|
-
push({ type: 'text', value });
|
|
3713
|
-
continue;
|
|
3714
|
-
}
|
|
3715
|
-
|
|
3716
|
-
/**
|
|
3717
|
-
* Left curly brace: '{'
|
|
3718
|
-
*/
|
|
3719
|
-
|
|
3720
|
-
if (value === CHAR_LEFT_CURLY_BRACE) {
|
|
3721
|
-
depth++;
|
|
3722
|
-
|
|
3723
|
-
const dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
|
|
3724
|
-
const brace = {
|
|
3725
|
-
type: 'brace',
|
|
3726
|
-
open: true,
|
|
3727
|
-
close: false,
|
|
3728
|
-
dollar,
|
|
3729
|
-
depth,
|
|
3730
|
-
commas: 0,
|
|
3731
|
-
ranges: 0,
|
|
3732
|
-
nodes: []
|
|
3733
|
-
};
|
|
3734
|
-
|
|
3735
|
-
block = push(brace);
|
|
3736
|
-
stack.push(block);
|
|
3737
|
-
push({ type: 'open', value });
|
|
3738
|
-
continue;
|
|
3739
|
-
}
|
|
3740
|
-
|
|
3741
|
-
/**
|
|
3742
|
-
* Right curly brace: '}'
|
|
3743
|
-
*/
|
|
3744
|
-
|
|
3745
|
-
if (value === CHAR_RIGHT_CURLY_BRACE) {
|
|
3746
|
-
if (block.type !== 'brace') {
|
|
3747
|
-
push({ type: 'text', value });
|
|
3748
|
-
continue;
|
|
3749
|
-
}
|
|
3750
|
-
|
|
3751
|
-
const type = 'close';
|
|
3752
|
-
block = stack.pop();
|
|
3753
|
-
block.close = true;
|
|
3754
|
-
|
|
3755
|
-
push({ type, value });
|
|
3756
|
-
depth--;
|
|
3757
|
-
|
|
3758
|
-
block = stack[stack.length - 1];
|
|
3759
|
-
continue;
|
|
3760
|
-
}
|
|
3761
|
-
|
|
3762
|
-
/**
|
|
3763
|
-
* Comma: ','
|
|
3764
|
-
*/
|
|
3765
|
-
|
|
3766
|
-
if (value === CHAR_COMMA && depth > 0) {
|
|
3767
|
-
if (block.ranges > 0) {
|
|
3768
|
-
block.ranges = 0;
|
|
3769
|
-
const open = block.nodes.shift();
|
|
3770
|
-
block.nodes = [open, { type: 'text', value: stringify(block) }];
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
push({ type: 'comma', value });
|
|
3774
|
-
block.commas++;
|
|
3775
|
-
continue;
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
/**
|
|
3779
|
-
* Dot: '.'
|
|
3780
|
-
*/
|
|
3781
|
-
|
|
3782
|
-
if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
|
|
3783
|
-
const siblings = block.nodes;
|
|
3784
|
-
|
|
3785
|
-
if (depth === 0 || siblings.length === 0) {
|
|
3786
|
-
push({ type: 'text', value });
|
|
3787
|
-
continue;
|
|
3788
|
-
}
|
|
3789
|
-
|
|
3790
|
-
if (prev.type === 'dot') {
|
|
3791
|
-
block.range = [];
|
|
3792
|
-
prev.value += value;
|
|
3793
|
-
prev.type = 'range';
|
|
3794
|
-
|
|
3795
|
-
if (block.nodes.length !== 3 && block.nodes.length !== 5) {
|
|
3796
|
-
block.invalid = true;
|
|
3797
|
-
block.ranges = 0;
|
|
3798
|
-
prev.type = 'text';
|
|
3799
|
-
continue;
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
block.ranges++;
|
|
3803
|
-
block.args = [];
|
|
3804
|
-
continue;
|
|
3805
|
-
}
|
|
3806
|
-
|
|
3807
|
-
if (prev.type === 'range') {
|
|
3808
|
-
siblings.pop();
|
|
3809
|
-
|
|
3810
|
-
const before = siblings[siblings.length - 1];
|
|
3811
|
-
before.value += prev.value + value;
|
|
3812
|
-
prev = before;
|
|
3813
|
-
block.ranges--;
|
|
3814
|
-
continue;
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
push({ type: 'dot', value });
|
|
3818
|
-
continue;
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3821
|
-
/**
|
|
3822
|
-
* Text
|
|
3823
|
-
*/
|
|
3824
|
-
|
|
3825
|
-
push({ type: 'text', value });
|
|
3826
|
-
}
|
|
3827
|
-
|
|
3828
|
-
// Mark imbalanced braces and brackets as invalid
|
|
3829
|
-
do {
|
|
3830
|
-
block = stack.pop();
|
|
3831
|
-
|
|
3832
|
-
if (block.type !== 'root') {
|
|
3833
|
-
block.nodes.forEach(node => {
|
|
3834
|
-
if (!node.nodes) {
|
|
3835
|
-
if (node.type === 'open') node.isOpen = true;
|
|
3836
|
-
if (node.type === 'close') node.isClose = true;
|
|
3837
|
-
if (!node.nodes) node.type = 'text';
|
|
3838
|
-
node.invalid = true;
|
|
3839
|
-
}
|
|
3840
|
-
});
|
|
3841
|
-
|
|
3842
|
-
// get the location of the block on parent.nodes (block's siblings)
|
|
3843
|
-
const parent = stack[stack.length - 1];
|
|
3844
|
-
const index = parent.nodes.indexOf(block);
|
|
3845
|
-
// replace the (invalid) block with it's nodes
|
|
3846
|
-
parent.nodes.splice(index, 1, ...block.nodes);
|
|
3847
|
-
}
|
|
3848
|
-
} while (stack.length > 0);
|
|
3849
|
-
|
|
3850
|
-
push({ type: 'eos' });
|
|
3851
|
-
return ast;
|
|
3852
|
-
};
|
|
3853
|
-
|
|
3854
|
-
parse_1$1 = parse;
|
|
3855
|
-
return parse_1$1;
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
var braces_1;
|
|
3859
|
-
var hasRequiredBraces;
|
|
3860
|
-
|
|
3861
|
-
function requireBraces () {
|
|
3862
|
-
if (hasRequiredBraces) return braces_1;
|
|
3863
|
-
hasRequiredBraces = 1;
|
|
3864
|
-
|
|
3865
|
-
const stringify = requireStringify();
|
|
3866
|
-
const compile = requireCompile();
|
|
3867
|
-
const expand = requireExpand();
|
|
3868
|
-
const parse = requireParse$1();
|
|
3869
|
-
|
|
3870
|
-
/**
|
|
3871
|
-
* Expand the given pattern or create a regex-compatible string.
|
|
3872
|
-
*
|
|
3873
|
-
* ```js
|
|
3874
|
-
* const braces = require('braces');
|
|
3875
|
-
* console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
|
|
3876
|
-
* console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
|
|
3877
|
-
* ```
|
|
3878
|
-
* @param {String} `str`
|
|
3879
|
-
* @param {Object} `options`
|
|
3880
|
-
* @return {String}
|
|
3881
|
-
* @api public
|
|
3882
|
-
*/
|
|
3883
|
-
|
|
3884
|
-
const braces = (input, options = {}) => {
|
|
3885
|
-
let output = [];
|
|
3886
|
-
|
|
3887
|
-
if (Array.isArray(input)) {
|
|
3888
|
-
for (const pattern of input) {
|
|
3889
|
-
const result = braces.create(pattern, options);
|
|
3890
|
-
if (Array.isArray(result)) {
|
|
3891
|
-
output.push(...result);
|
|
3892
|
-
} else {
|
|
3893
|
-
output.push(result);
|
|
3894
|
-
}
|
|
3895
|
-
}
|
|
3896
|
-
} else {
|
|
3897
|
-
output = [].concat(braces.create(input, options));
|
|
3898
|
-
}
|
|
3899
|
-
|
|
3900
|
-
if (options && options.expand === true && options.nodupes === true) {
|
|
3901
|
-
output = [...new Set(output)];
|
|
3902
|
-
}
|
|
3903
|
-
return output;
|
|
3904
|
-
};
|
|
3905
|
-
|
|
3906
|
-
/**
|
|
3907
|
-
* Parse the given `str` with the given `options`.
|
|
3908
|
-
*
|
|
3909
|
-
* ```js
|
|
3910
|
-
* // braces.parse(pattern, [, options]);
|
|
3911
|
-
* const ast = braces.parse('a/{b,c}/d');
|
|
3912
|
-
* console.log(ast);
|
|
3913
|
-
* ```
|
|
3914
|
-
* @param {String} pattern Brace pattern to parse
|
|
3915
|
-
* @param {Object} options
|
|
3916
|
-
* @return {Object} Returns an AST
|
|
3917
|
-
* @api public
|
|
3918
|
-
*/
|
|
3919
|
-
|
|
3920
|
-
braces.parse = (input, options = {}) => parse(input, options);
|
|
3921
|
-
|
|
3922
|
-
/**
|
|
3923
|
-
* Creates a braces string from an AST, or an AST node.
|
|
3924
|
-
*
|
|
3925
|
-
* ```js
|
|
3926
|
-
* const braces = require('braces');
|
|
3927
|
-
* let ast = braces.parse('foo/{a,b}/bar');
|
|
3928
|
-
* console.log(stringify(ast.nodes[2])); //=> '{a,b}'
|
|
3929
|
-
* ```
|
|
3930
|
-
* @param {String} `input` Brace pattern or AST.
|
|
3931
|
-
* @param {Object} `options`
|
|
3932
|
-
* @return {Array} Returns an array of expanded values.
|
|
3933
|
-
* @api public
|
|
3934
|
-
*/
|
|
3935
|
-
|
|
3936
|
-
braces.stringify = (input, options = {}) => {
|
|
3937
|
-
if (typeof input === 'string') {
|
|
3938
|
-
return stringify(braces.parse(input, options), options);
|
|
3939
|
-
}
|
|
3940
|
-
return stringify(input, options);
|
|
3941
|
-
};
|
|
3942
|
-
|
|
3943
|
-
/**
|
|
3944
|
-
* Compiles a brace pattern into a regex-compatible, optimized string.
|
|
3945
|
-
* This method is called by the main [braces](#braces) function by default.
|
|
3946
|
-
*
|
|
3947
|
-
* ```js
|
|
3948
|
-
* const braces = require('braces');
|
|
3949
|
-
* console.log(braces.compile('a/{b,c}/d'));
|
|
3950
|
-
* //=> ['a/(b|c)/d']
|
|
3951
|
-
* ```
|
|
3952
|
-
* @param {String} `input` Brace pattern or AST.
|
|
3953
|
-
* @param {Object} `options`
|
|
3954
|
-
* @return {Array} Returns an array of expanded values.
|
|
3955
|
-
* @api public
|
|
3956
|
-
*/
|
|
3957
|
-
|
|
3958
|
-
braces.compile = (input, options = {}) => {
|
|
3959
|
-
if (typeof input === 'string') {
|
|
3960
|
-
input = braces.parse(input, options);
|
|
3961
|
-
}
|
|
3962
|
-
return compile(input, options);
|
|
3963
|
-
};
|
|
3964
|
-
|
|
3965
|
-
/**
|
|
3966
|
-
* Expands a brace pattern into an array. This method is called by the
|
|
3967
|
-
* main [braces](#braces) function when `options.expand` is true. Before
|
|
3968
|
-
* using this method it's recommended that you read the [performance notes](#performance))
|
|
3969
|
-
* and advantages of using [.compile](#compile) instead.
|
|
3970
|
-
*
|
|
3971
|
-
* ```js
|
|
3972
|
-
* const braces = require('braces');
|
|
3973
|
-
* console.log(braces.expand('a/{b,c}/d'));
|
|
3974
|
-
* //=> ['a/b/d', 'a/c/d'];
|
|
3975
|
-
* ```
|
|
3976
|
-
* @param {String} `pattern` Brace pattern
|
|
3977
|
-
* @param {Object} `options`
|
|
3978
|
-
* @return {Array} Returns an array of expanded values.
|
|
3979
|
-
* @api public
|
|
3980
|
-
*/
|
|
3981
|
-
|
|
3982
|
-
braces.expand = (input, options = {}) => {
|
|
3983
|
-
if (typeof input === 'string') {
|
|
3984
|
-
input = braces.parse(input, options);
|
|
3985
|
-
}
|
|
3986
|
-
|
|
3987
|
-
let result = expand(input, options);
|
|
3988
|
-
|
|
3989
|
-
// filter out empty strings if specified
|
|
3990
|
-
if (options.noempty === true) {
|
|
3991
|
-
result = result.filter(Boolean);
|
|
3992
|
-
}
|
|
3993
|
-
|
|
3994
|
-
// filter out duplicates if specified
|
|
3995
|
-
if (options.nodupes === true) {
|
|
3996
|
-
result = [...new Set(result)];
|
|
3997
|
-
}
|
|
3998
|
-
|
|
3999
|
-
return result;
|
|
4000
|
-
};
|
|
4001
|
-
|
|
4002
|
-
/**
|
|
4003
|
-
* Processes a brace pattern and returns either an expanded array
|
|
4004
|
-
* (if `options.expand` is true), a highly optimized regex-compatible string.
|
|
4005
|
-
* This method is called by the main [braces](#braces) function.
|
|
4006
|
-
*
|
|
4007
|
-
* ```js
|
|
4008
|
-
* const braces = require('braces');
|
|
4009
|
-
* console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
|
|
4010
|
-
* //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
|
|
4011
|
-
* ```
|
|
4012
|
-
* @param {String} `pattern` Brace pattern
|
|
4013
|
-
* @param {Object} `options`
|
|
4014
|
-
* @return {Array} Returns an array of expanded values.
|
|
4015
|
-
* @api public
|
|
4016
|
-
*/
|
|
4017
|
-
|
|
4018
|
-
braces.create = (input, options = {}) => {
|
|
4019
|
-
if (input === '' || input.length < 3) {
|
|
4020
|
-
return [input];
|
|
4021
|
-
}
|
|
4022
|
-
|
|
4023
|
-
return options.expand !== true
|
|
4024
|
-
? braces.compile(input, options)
|
|
4025
|
-
: braces.expand(input, options);
|
|
4026
|
-
};
|
|
4027
|
-
|
|
4028
|
-
/**
|
|
4029
|
-
* Expose "braces"
|
|
4030
|
-
*/
|
|
4031
|
-
|
|
4032
|
-
braces_1 = braces;
|
|
4033
|
-
return braces_1;
|
|
4034
|
-
}
|
|
4035
|
-
|
|
4036
|
-
var utils = {};
|
|
4037
|
-
|
|
4038
|
-
var constants;
|
|
4039
|
-
var hasRequiredConstants;
|
|
4040
|
-
|
|
4041
|
-
function requireConstants () {
|
|
4042
|
-
if (hasRequiredConstants) return constants;
|
|
4043
|
-
hasRequiredConstants = 1;
|
|
4044
|
-
|
|
4045
|
-
const path = require$$0$1;
|
|
4046
|
-
const WIN_SLASH = '\\\\/';
|
|
4047
|
-
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
4048
|
-
|
|
4049
|
-
/**
|
|
4050
|
-
* Posix glob regex
|
|
4051
|
-
*/
|
|
4052
|
-
|
|
4053
|
-
const DOT_LITERAL = '\\.';
|
|
4054
|
-
const PLUS_LITERAL = '\\+';
|
|
4055
|
-
const QMARK_LITERAL = '\\?';
|
|
4056
|
-
const SLASH_LITERAL = '\\/';
|
|
4057
|
-
const ONE_CHAR = '(?=.)';
|
|
4058
|
-
const QMARK = '[^/]';
|
|
4059
|
-
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
4060
|
-
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
4061
|
-
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
4062
|
-
const NO_DOT = `(?!${DOT_LITERAL})`;
|
|
4063
|
-
const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
4064
|
-
const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
4065
|
-
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
4066
|
-
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
4067
|
-
const STAR = `${QMARK}*?`;
|
|
4068
|
-
|
|
4069
|
-
const POSIX_CHARS = {
|
|
4070
|
-
DOT_LITERAL,
|
|
4071
|
-
PLUS_LITERAL,
|
|
4072
|
-
QMARK_LITERAL,
|
|
4073
|
-
SLASH_LITERAL,
|
|
4074
|
-
ONE_CHAR,
|
|
4075
|
-
QMARK,
|
|
4076
|
-
END_ANCHOR,
|
|
4077
|
-
DOTS_SLASH,
|
|
4078
|
-
NO_DOT,
|
|
4079
|
-
NO_DOTS,
|
|
4080
|
-
NO_DOT_SLASH,
|
|
4081
|
-
NO_DOTS_SLASH,
|
|
4082
|
-
QMARK_NO_DOT,
|
|
4083
|
-
STAR,
|
|
4084
|
-
START_ANCHOR
|
|
4085
|
-
};
|
|
4086
|
-
|
|
4087
|
-
/**
|
|
4088
|
-
* Windows glob regex
|
|
4089
|
-
*/
|
|
4090
|
-
|
|
4091
|
-
const WINDOWS_CHARS = {
|
|
4092
|
-
...POSIX_CHARS,
|
|
4093
|
-
|
|
4094
|
-
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
4095
|
-
QMARK: WIN_NO_SLASH,
|
|
4096
|
-
STAR: `${WIN_NO_SLASH}*?`,
|
|
4097
|
-
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
4098
|
-
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
4099
|
-
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
4100
|
-
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
4101
|
-
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
4102
|
-
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
4103
|
-
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
4104
|
-
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
|
|
4105
|
-
};
|
|
4106
|
-
|
|
4107
|
-
/**
|
|
4108
|
-
* POSIX Bracket Regex
|
|
4109
|
-
*/
|
|
4110
|
-
|
|
4111
|
-
const POSIX_REGEX_SOURCE = {
|
|
4112
|
-
alnum: 'a-zA-Z0-9',
|
|
4113
|
-
alpha: 'a-zA-Z',
|
|
4114
|
-
ascii: '\\x00-\\x7F',
|
|
4115
|
-
blank: ' \\t',
|
|
4116
|
-
cntrl: '\\x00-\\x1F\\x7F',
|
|
4117
|
-
digit: '0-9',
|
|
4118
|
-
graph: '\\x21-\\x7E',
|
|
4119
|
-
lower: 'a-z',
|
|
4120
|
-
print: '\\x20-\\x7E ',
|
|
4121
|
-
punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
|
|
4122
|
-
space: ' \\t\\r\\n\\v\\f',
|
|
4123
|
-
upper: 'A-Z',
|
|
4124
|
-
word: 'A-Za-z0-9_',
|
|
4125
|
-
xdigit: 'A-Fa-f0-9'
|
|
4126
|
-
};
|
|
4127
|
-
|
|
4128
|
-
constants = {
|
|
4129
|
-
MAX_LENGTH: 1024 * 64,
|
|
4130
|
-
POSIX_REGEX_SOURCE,
|
|
4131
|
-
|
|
4132
|
-
// regular expressions
|
|
4133
|
-
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
4134
|
-
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
4135
|
-
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
4136
|
-
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
4137
|
-
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
4138
|
-
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
4139
|
-
|
|
4140
|
-
// Replace globs with equivalent patterns to reduce parsing time.
|
|
4141
|
-
REPLACEMENTS: {
|
|
4142
|
-
'***': '*',
|
|
4143
|
-
'**/**': '**',
|
|
4144
|
-
'**/**/**': '**'
|
|
4145
|
-
},
|
|
4146
|
-
|
|
4147
|
-
// Digits
|
|
4148
|
-
CHAR_0: 48, /* 0 */
|
|
4149
|
-
CHAR_9: 57, /* 9 */
|
|
4150
|
-
|
|
4151
|
-
// Alphabet chars.
|
|
4152
|
-
CHAR_UPPERCASE_A: 65, /* A */
|
|
4153
|
-
CHAR_LOWERCASE_A: 97, /* a */
|
|
4154
|
-
CHAR_UPPERCASE_Z: 90, /* Z */
|
|
4155
|
-
CHAR_LOWERCASE_Z: 122, /* z */
|
|
4156
|
-
|
|
4157
|
-
CHAR_LEFT_PARENTHESES: 40, /* ( */
|
|
4158
|
-
CHAR_RIGHT_PARENTHESES: 41, /* ) */
|
|
4159
|
-
|
|
4160
|
-
CHAR_ASTERISK: 42, /* * */
|
|
4161
|
-
|
|
4162
|
-
// Non-alphabetic chars.
|
|
4163
|
-
CHAR_AMPERSAND: 38, /* & */
|
|
4164
|
-
CHAR_AT: 64, /* @ */
|
|
4165
|
-
CHAR_BACKWARD_SLASH: 92, /* \ */
|
|
4166
|
-
CHAR_CARRIAGE_RETURN: 13, /* \r */
|
|
4167
|
-
CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
|
|
4168
|
-
CHAR_COLON: 58, /* : */
|
|
4169
|
-
CHAR_COMMA: 44, /* , */
|
|
4170
|
-
CHAR_DOT: 46, /* . */
|
|
4171
|
-
CHAR_DOUBLE_QUOTE: 34, /* " */
|
|
4172
|
-
CHAR_EQUAL: 61, /* = */
|
|
4173
|
-
CHAR_EXCLAMATION_MARK: 33, /* ! */
|
|
4174
|
-
CHAR_FORM_FEED: 12, /* \f */
|
|
4175
|
-
CHAR_FORWARD_SLASH: 47, /* / */
|
|
4176
|
-
CHAR_GRAVE_ACCENT: 96, /* ` */
|
|
4177
|
-
CHAR_HASH: 35, /* # */
|
|
4178
|
-
CHAR_HYPHEN_MINUS: 45, /* - */
|
|
4179
|
-
CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
|
|
4180
|
-
CHAR_LEFT_CURLY_BRACE: 123, /* { */
|
|
4181
|
-
CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
|
|
4182
|
-
CHAR_LINE_FEED: 10, /* \n */
|
|
4183
|
-
CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
|
|
4184
|
-
CHAR_PERCENT: 37, /* % */
|
|
4185
|
-
CHAR_PLUS: 43, /* + */
|
|
4186
|
-
CHAR_QUESTION_MARK: 63, /* ? */
|
|
4187
|
-
CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
|
|
4188
|
-
CHAR_RIGHT_CURLY_BRACE: 125, /* } */
|
|
4189
|
-
CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
|
|
4190
|
-
CHAR_SEMICOLON: 59, /* ; */
|
|
4191
|
-
CHAR_SINGLE_QUOTE: 39, /* ' */
|
|
4192
|
-
CHAR_SPACE: 32, /* */
|
|
4193
|
-
CHAR_TAB: 9, /* \t */
|
|
4194
|
-
CHAR_UNDERSCORE: 95, /* _ */
|
|
4195
|
-
CHAR_VERTICAL_LINE: 124, /* | */
|
|
4196
|
-
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
|
|
4197
|
-
|
|
4198
|
-
SEP: path.sep,
|
|
4199
|
-
|
|
4200
|
-
/**
|
|
4201
|
-
* Create EXTGLOB_CHARS
|
|
4202
|
-
*/
|
|
4203
|
-
|
|
4204
|
-
extglobChars(chars) {
|
|
4205
|
-
return {
|
|
4206
|
-
'!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
|
|
4207
|
-
'?': { type: 'qmark', open: '(?:', close: ')?' },
|
|
4208
|
-
'+': { type: 'plus', open: '(?:', close: ')+' },
|
|
4209
|
-
'*': { type: 'star', open: '(?:', close: ')*' },
|
|
4210
|
-
'@': { type: 'at', open: '(?:', close: ')' }
|
|
4211
|
-
};
|
|
4212
|
-
},
|
|
4213
|
-
|
|
4214
|
-
/**
|
|
4215
|
-
* Create GLOB_CHARS
|
|
4216
|
-
*/
|
|
4217
|
-
|
|
4218
|
-
globChars(win32) {
|
|
4219
|
-
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
4220
|
-
}
|
|
4221
|
-
};
|
|
4222
|
-
return constants;
|
|
4223
|
-
}
|
|
4224
|
-
|
|
4225
|
-
var hasRequiredUtils;
|
|
4226
|
-
|
|
4227
|
-
function requireUtils () {
|
|
4228
|
-
if (hasRequiredUtils) return utils;
|
|
4229
|
-
hasRequiredUtils = 1;
|
|
4230
|
-
(function (exports) {
|
|
4231
|
-
|
|
4232
|
-
const path = require$$0$1;
|
|
4233
|
-
const win32 = process.platform === 'win32';
|
|
4234
|
-
const {
|
|
4235
|
-
REGEX_BACKSLASH,
|
|
4236
|
-
REGEX_REMOVE_BACKSLASH,
|
|
4237
|
-
REGEX_SPECIAL_CHARS,
|
|
4238
|
-
REGEX_SPECIAL_CHARS_GLOBAL
|
|
4239
|
-
} = requireConstants();
|
|
4240
|
-
|
|
4241
|
-
exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
4242
|
-
exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
|
|
4243
|
-
exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
|
|
4244
|
-
exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
|
|
4245
|
-
exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
|
|
4246
|
-
|
|
4247
|
-
exports.removeBackslashes = str => {
|
|
4248
|
-
return str.replace(REGEX_REMOVE_BACKSLASH, match => {
|
|
4249
|
-
return match === '\\' ? '' : match;
|
|
4250
|
-
});
|
|
4251
|
-
};
|
|
4252
|
-
|
|
4253
|
-
exports.supportsLookbehinds = () => {
|
|
4254
|
-
const segs = process.version.slice(1).split('.').map(Number);
|
|
4255
|
-
if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
|
|
4256
|
-
return true;
|
|
4257
|
-
}
|
|
4258
|
-
return false;
|
|
4259
|
-
};
|
|
4260
|
-
|
|
4261
|
-
exports.isWindows = options => {
|
|
4262
|
-
if (options && typeof options.windows === 'boolean') {
|
|
4263
|
-
return options.windows;
|
|
4264
|
-
}
|
|
4265
|
-
return win32 === true || path.sep === '\\';
|
|
4266
|
-
};
|
|
4267
|
-
|
|
4268
|
-
exports.escapeLast = (input, char, lastIdx) => {
|
|
4269
|
-
const idx = input.lastIndexOf(char, lastIdx);
|
|
4270
|
-
if (idx === -1) return input;
|
|
4271
|
-
if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
|
|
4272
|
-
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
4273
|
-
};
|
|
4274
|
-
|
|
4275
|
-
exports.removePrefix = (input, state = {}) => {
|
|
4276
|
-
let output = input;
|
|
4277
|
-
if (output.startsWith('./')) {
|
|
4278
|
-
output = output.slice(2);
|
|
4279
|
-
state.prefix = './';
|
|
4280
|
-
}
|
|
4281
|
-
return output;
|
|
4282
|
-
};
|
|
4283
|
-
|
|
4284
|
-
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
4285
|
-
const prepend = options.contains ? '' : '^';
|
|
4286
|
-
const append = options.contains ? '' : '$';
|
|
4287
|
-
|
|
4288
|
-
let output = `${prepend}(?:${input})${append}`;
|
|
4289
|
-
if (state.negated === true) {
|
|
4290
|
-
output = `(?:^(?!${output}).*$)`;
|
|
4291
|
-
}
|
|
4292
|
-
return output;
|
|
4293
|
-
};
|
|
4294
|
-
} (utils));
|
|
4295
|
-
return utils;
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
var scan_1;
|
|
4299
|
-
var hasRequiredScan;
|
|
4300
|
-
|
|
4301
|
-
function requireScan () {
|
|
4302
|
-
if (hasRequiredScan) return scan_1;
|
|
4303
|
-
hasRequiredScan = 1;
|
|
4304
|
-
|
|
4305
|
-
const utils = requireUtils();
|
|
4306
|
-
const {
|
|
4307
|
-
CHAR_ASTERISK, /* * */
|
|
4308
|
-
CHAR_AT, /* @ */
|
|
4309
|
-
CHAR_BACKWARD_SLASH, /* \ */
|
|
4310
|
-
CHAR_COMMA, /* , */
|
|
4311
|
-
CHAR_DOT, /* . */
|
|
4312
|
-
CHAR_EXCLAMATION_MARK, /* ! */
|
|
4313
|
-
CHAR_FORWARD_SLASH, /* / */
|
|
4314
|
-
CHAR_LEFT_CURLY_BRACE, /* { */
|
|
4315
|
-
CHAR_LEFT_PARENTHESES, /* ( */
|
|
4316
|
-
CHAR_LEFT_SQUARE_BRACKET, /* [ */
|
|
4317
|
-
CHAR_PLUS, /* + */
|
|
4318
|
-
CHAR_QUESTION_MARK, /* ? */
|
|
4319
|
-
CHAR_RIGHT_CURLY_BRACE, /* } */
|
|
4320
|
-
CHAR_RIGHT_PARENTHESES, /* ) */
|
|
4321
|
-
CHAR_RIGHT_SQUARE_BRACKET /* ] */
|
|
4322
|
-
} = requireConstants();
|
|
4323
|
-
|
|
4324
|
-
const isPathSeparator = code => {
|
|
4325
|
-
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
4326
|
-
};
|
|
4327
|
-
|
|
4328
|
-
const depth = token => {
|
|
4329
|
-
if (token.isPrefix !== true) {
|
|
4330
|
-
token.depth = token.isGlobstar ? Infinity : 1;
|
|
4331
|
-
}
|
|
4332
|
-
};
|
|
4333
|
-
|
|
4334
|
-
/**
|
|
4335
|
-
* Quickly scans a glob pattern and returns an object with a handful of
|
|
4336
|
-
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
4337
|
-
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
4338
|
-
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
4339
|
-
*
|
|
4340
|
-
* ```js
|
|
4341
|
-
* const pm = require('picomatch');
|
|
4342
|
-
* console.log(pm.scan('foo/bar/*.js'));
|
|
4343
|
-
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
4344
|
-
* ```
|
|
4345
|
-
* @param {String} `str`
|
|
4346
|
-
* @param {Object} `options`
|
|
4347
|
-
* @return {Object} Returns an object with tokens and regex source string.
|
|
4348
|
-
* @api public
|
|
4349
|
-
*/
|
|
4350
|
-
|
|
4351
|
-
const scan = (input, options) => {
|
|
4352
|
-
const opts = options || {};
|
|
4353
|
-
|
|
4354
|
-
const length = input.length - 1;
|
|
4355
|
-
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
4356
|
-
const slashes = [];
|
|
4357
|
-
const tokens = [];
|
|
4358
|
-
const parts = [];
|
|
4359
|
-
|
|
4360
|
-
let str = input;
|
|
4361
|
-
let index = -1;
|
|
4362
|
-
let start = 0;
|
|
4363
|
-
let lastIndex = 0;
|
|
4364
|
-
let isBrace = false;
|
|
4365
|
-
let isBracket = false;
|
|
4366
|
-
let isGlob = false;
|
|
4367
|
-
let isExtglob = false;
|
|
4368
|
-
let isGlobstar = false;
|
|
4369
|
-
let braceEscaped = false;
|
|
4370
|
-
let backslashes = false;
|
|
4371
|
-
let negated = false;
|
|
4372
|
-
let negatedExtglob = false;
|
|
4373
|
-
let finished = false;
|
|
4374
|
-
let braces = 0;
|
|
4375
|
-
let prev;
|
|
4376
|
-
let code;
|
|
4377
|
-
let token = { value: '', depth: 0, isGlob: false };
|
|
4378
|
-
|
|
4379
|
-
const eos = () => index >= length;
|
|
4380
|
-
const peek = () => str.charCodeAt(index + 1);
|
|
4381
|
-
const advance = () => {
|
|
4382
|
-
prev = code;
|
|
4383
|
-
return str.charCodeAt(++index);
|
|
4384
|
-
};
|
|
4385
|
-
|
|
4386
|
-
while (index < length) {
|
|
4387
|
-
code = advance();
|
|
4388
|
-
let next;
|
|
4389
|
-
|
|
4390
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
4391
|
-
backslashes = token.backslashes = true;
|
|
4392
|
-
code = advance();
|
|
4393
|
-
|
|
4394
|
-
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
4395
|
-
braceEscaped = true;
|
|
4396
|
-
}
|
|
4397
|
-
continue;
|
|
4398
|
-
}
|
|
4399
|
-
|
|
4400
|
-
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
4401
|
-
braces++;
|
|
4402
|
-
|
|
4403
|
-
while (eos() !== true && (code = advance())) {
|
|
4404
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
4405
|
-
backslashes = token.backslashes = true;
|
|
4406
|
-
advance();
|
|
4407
|
-
continue;
|
|
4408
|
-
}
|
|
4409
|
-
|
|
4410
|
-
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
4411
|
-
braces++;
|
|
4412
|
-
continue;
|
|
4413
|
-
}
|
|
4414
|
-
|
|
4415
|
-
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
4416
|
-
isBrace = token.isBrace = true;
|
|
4417
|
-
isGlob = token.isGlob = true;
|
|
4418
|
-
finished = true;
|
|
4419
|
-
|
|
4420
|
-
if (scanToEnd === true) {
|
|
4421
|
-
continue;
|
|
4422
|
-
}
|
|
4423
|
-
|
|
4424
|
-
break;
|
|
4425
|
-
}
|
|
4426
|
-
|
|
4427
|
-
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
4428
|
-
isBrace = token.isBrace = true;
|
|
4429
|
-
isGlob = token.isGlob = true;
|
|
4430
|
-
finished = true;
|
|
4431
|
-
|
|
4432
|
-
if (scanToEnd === true) {
|
|
4433
|
-
continue;
|
|
4434
|
-
}
|
|
4435
|
-
|
|
4436
|
-
break;
|
|
4437
|
-
}
|
|
4438
|
-
|
|
4439
|
-
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
4440
|
-
braces--;
|
|
4441
|
-
|
|
4442
|
-
if (braces === 0) {
|
|
4443
|
-
braceEscaped = false;
|
|
4444
|
-
isBrace = token.isBrace = true;
|
|
4445
|
-
finished = true;
|
|
4446
|
-
break;
|
|
4447
|
-
}
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
|
|
4451
|
-
if (scanToEnd === true) {
|
|
4452
|
-
continue;
|
|
4453
|
-
}
|
|
4454
|
-
|
|
4455
|
-
break;
|
|
4456
|
-
}
|
|
4457
|
-
|
|
4458
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
4459
|
-
slashes.push(index);
|
|
4460
|
-
tokens.push(token);
|
|
4461
|
-
token = { value: '', depth: 0, isGlob: false };
|
|
4462
|
-
|
|
4463
|
-
if (finished === true) continue;
|
|
4464
|
-
if (prev === CHAR_DOT && index === (start + 1)) {
|
|
4465
|
-
start += 2;
|
|
4466
|
-
continue;
|
|
4467
|
-
}
|
|
4468
|
-
|
|
4469
|
-
lastIndex = index + 1;
|
|
4470
|
-
continue;
|
|
4471
|
-
}
|
|
4472
|
-
|
|
4473
|
-
if (opts.noext !== true) {
|
|
4474
|
-
const isExtglobChar = code === CHAR_PLUS
|
|
4475
|
-
|| code === CHAR_AT
|
|
4476
|
-
|| code === CHAR_ASTERISK
|
|
4477
|
-
|| code === CHAR_QUESTION_MARK
|
|
4478
|
-
|| code === CHAR_EXCLAMATION_MARK;
|
|
4479
|
-
|
|
4480
|
-
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
4481
|
-
isGlob = token.isGlob = true;
|
|
4482
|
-
isExtglob = token.isExtglob = true;
|
|
4483
|
-
finished = true;
|
|
4484
|
-
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
4485
|
-
negatedExtglob = true;
|
|
4486
|
-
}
|
|
4487
|
-
|
|
4488
|
-
if (scanToEnd === true) {
|
|
4489
|
-
while (eos() !== true && (code = advance())) {
|
|
4490
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
4491
|
-
backslashes = token.backslashes = true;
|
|
4492
|
-
code = advance();
|
|
4493
|
-
continue;
|
|
4494
|
-
}
|
|
4495
|
-
|
|
4496
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
4497
|
-
isGlob = token.isGlob = true;
|
|
4498
|
-
finished = true;
|
|
4499
|
-
break;
|
|
4500
|
-
}
|
|
4501
|
-
}
|
|
4502
|
-
continue;
|
|
4503
|
-
}
|
|
4504
|
-
break;
|
|
4505
|
-
}
|
|
4506
|
-
}
|
|
4507
|
-
|
|
4508
|
-
if (code === CHAR_ASTERISK) {
|
|
4509
|
-
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
4510
|
-
isGlob = token.isGlob = true;
|
|
4511
|
-
finished = true;
|
|
4512
|
-
|
|
4513
|
-
if (scanToEnd === true) {
|
|
4514
|
-
continue;
|
|
4515
|
-
}
|
|
4516
|
-
break;
|
|
4517
|
-
}
|
|
4518
|
-
|
|
4519
|
-
if (code === CHAR_QUESTION_MARK) {
|
|
4520
|
-
isGlob = token.isGlob = true;
|
|
4521
|
-
finished = true;
|
|
4522
|
-
|
|
4523
|
-
if (scanToEnd === true) {
|
|
4524
|
-
continue;
|
|
4525
|
-
}
|
|
4526
|
-
break;
|
|
4527
|
-
}
|
|
4528
|
-
|
|
4529
|
-
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
4530
|
-
while (eos() !== true && (next = advance())) {
|
|
4531
|
-
if (next === CHAR_BACKWARD_SLASH) {
|
|
4532
|
-
backslashes = token.backslashes = true;
|
|
4533
|
-
advance();
|
|
4534
|
-
continue;
|
|
4535
|
-
}
|
|
4536
|
-
|
|
4537
|
-
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
4538
|
-
isBracket = token.isBracket = true;
|
|
4539
|
-
isGlob = token.isGlob = true;
|
|
4540
|
-
finished = true;
|
|
4541
|
-
break;
|
|
4542
|
-
}
|
|
4543
|
-
}
|
|
4544
|
-
|
|
4545
|
-
if (scanToEnd === true) {
|
|
4546
|
-
continue;
|
|
4547
|
-
}
|
|
4548
|
-
|
|
4549
|
-
break;
|
|
4550
|
-
}
|
|
4551
|
-
|
|
4552
|
-
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
4553
|
-
negated = token.negated = true;
|
|
4554
|
-
start++;
|
|
4555
|
-
continue;
|
|
4556
|
-
}
|
|
4557
|
-
|
|
4558
|
-
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
4559
|
-
isGlob = token.isGlob = true;
|
|
4560
|
-
|
|
4561
|
-
if (scanToEnd === true) {
|
|
4562
|
-
while (eos() !== true && (code = advance())) {
|
|
4563
|
-
if (code === CHAR_LEFT_PARENTHESES) {
|
|
4564
|
-
backslashes = token.backslashes = true;
|
|
4565
|
-
code = advance();
|
|
4566
|
-
continue;
|
|
4567
|
-
}
|
|
4568
|
-
|
|
4569
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
4570
|
-
finished = true;
|
|
4571
|
-
break;
|
|
4572
|
-
}
|
|
4573
|
-
}
|
|
4574
|
-
continue;
|
|
4575
|
-
}
|
|
4576
|
-
break;
|
|
4577
|
-
}
|
|
4578
|
-
|
|
4579
|
-
if (isGlob === true) {
|
|
4580
|
-
finished = true;
|
|
4581
|
-
|
|
4582
|
-
if (scanToEnd === true) {
|
|
4583
|
-
continue;
|
|
4584
|
-
}
|
|
4585
|
-
|
|
4586
|
-
break;
|
|
4587
|
-
}
|
|
4588
|
-
}
|
|
4589
|
-
|
|
4590
|
-
if (opts.noext === true) {
|
|
4591
|
-
isExtglob = false;
|
|
4592
|
-
isGlob = false;
|
|
4593
|
-
}
|
|
4594
|
-
|
|
4595
|
-
let base = str;
|
|
4596
|
-
let prefix = '';
|
|
4597
|
-
let glob = '';
|
|
4598
|
-
|
|
4599
|
-
if (start > 0) {
|
|
4600
|
-
prefix = str.slice(0, start);
|
|
4601
|
-
str = str.slice(start);
|
|
4602
|
-
lastIndex -= start;
|
|
4603
|
-
}
|
|
4604
|
-
|
|
4605
|
-
if (base && isGlob === true && lastIndex > 0) {
|
|
4606
|
-
base = str.slice(0, lastIndex);
|
|
4607
|
-
glob = str.slice(lastIndex);
|
|
4608
|
-
} else if (isGlob === true) {
|
|
4609
|
-
base = '';
|
|
4610
|
-
glob = str;
|
|
4611
|
-
} else {
|
|
4612
|
-
base = str;
|
|
4613
|
-
}
|
|
4614
|
-
|
|
4615
|
-
if (base && base !== '' && base !== '/' && base !== str) {
|
|
4616
|
-
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
4617
|
-
base = base.slice(0, -1);
|
|
4618
|
-
}
|
|
4619
|
-
}
|
|
4620
|
-
|
|
4621
|
-
if (opts.unescape === true) {
|
|
4622
|
-
if (glob) glob = utils.removeBackslashes(glob);
|
|
4623
|
-
|
|
4624
|
-
if (base && backslashes === true) {
|
|
4625
|
-
base = utils.removeBackslashes(base);
|
|
4626
|
-
}
|
|
4627
|
-
}
|
|
4628
|
-
|
|
4629
|
-
const state = {
|
|
4630
|
-
prefix,
|
|
4631
|
-
input,
|
|
4632
|
-
start,
|
|
4633
|
-
base,
|
|
4634
|
-
glob,
|
|
4635
|
-
isBrace,
|
|
4636
|
-
isBracket,
|
|
4637
|
-
isGlob,
|
|
4638
|
-
isExtglob,
|
|
4639
|
-
isGlobstar,
|
|
4640
|
-
negated,
|
|
4641
|
-
negatedExtglob
|
|
4642
|
-
};
|
|
4643
|
-
|
|
4644
|
-
if (opts.tokens === true) {
|
|
4645
|
-
state.maxDepth = 0;
|
|
4646
|
-
if (!isPathSeparator(code)) {
|
|
4647
|
-
tokens.push(token);
|
|
4648
|
-
}
|
|
4649
|
-
state.tokens = tokens;
|
|
4650
|
-
}
|
|
4651
|
-
|
|
4652
|
-
if (opts.parts === true || opts.tokens === true) {
|
|
4653
|
-
let prevIndex;
|
|
4654
|
-
|
|
4655
|
-
for (let idx = 0; idx < slashes.length; idx++) {
|
|
4656
|
-
const n = prevIndex ? prevIndex + 1 : start;
|
|
4657
|
-
const i = slashes[idx];
|
|
4658
|
-
const value = input.slice(n, i);
|
|
4659
|
-
if (opts.tokens) {
|
|
4660
|
-
if (idx === 0 && start !== 0) {
|
|
4661
|
-
tokens[idx].isPrefix = true;
|
|
4662
|
-
tokens[idx].value = prefix;
|
|
4663
|
-
} else {
|
|
4664
|
-
tokens[idx].value = value;
|
|
4665
|
-
}
|
|
4666
|
-
depth(tokens[idx]);
|
|
4667
|
-
state.maxDepth += tokens[idx].depth;
|
|
4668
|
-
}
|
|
4669
|
-
if (idx !== 0 || value !== '') {
|
|
4670
|
-
parts.push(value);
|
|
4671
|
-
}
|
|
4672
|
-
prevIndex = i;
|
|
4673
|
-
}
|
|
4674
|
-
|
|
4675
|
-
if (prevIndex && prevIndex + 1 < input.length) {
|
|
4676
|
-
const value = input.slice(prevIndex + 1);
|
|
4677
|
-
parts.push(value);
|
|
4678
|
-
|
|
4679
|
-
if (opts.tokens) {
|
|
4680
|
-
tokens[tokens.length - 1].value = value;
|
|
4681
|
-
depth(tokens[tokens.length - 1]);
|
|
4682
|
-
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
4683
|
-
}
|
|
4684
|
-
}
|
|
4685
|
-
|
|
4686
|
-
state.slashes = slashes;
|
|
4687
|
-
state.parts = parts;
|
|
4688
|
-
}
|
|
4689
|
-
|
|
4690
|
-
return state;
|
|
4691
|
-
};
|
|
4692
|
-
|
|
4693
|
-
scan_1 = scan;
|
|
4694
|
-
return scan_1;
|
|
4695
|
-
}
|
|
4696
|
-
|
|
4697
|
-
var parse_1;
|
|
4698
|
-
var hasRequiredParse;
|
|
4699
|
-
|
|
4700
|
-
function requireParse () {
|
|
4701
|
-
if (hasRequiredParse) return parse_1;
|
|
4702
|
-
hasRequiredParse = 1;
|
|
4703
|
-
|
|
4704
|
-
const constants = requireConstants();
|
|
4705
|
-
const utils = requireUtils();
|
|
4706
|
-
|
|
4707
|
-
/**
|
|
4708
|
-
* Constants
|
|
4709
|
-
*/
|
|
4710
|
-
|
|
4711
|
-
const {
|
|
4712
|
-
MAX_LENGTH,
|
|
4713
|
-
POSIX_REGEX_SOURCE,
|
|
4714
|
-
REGEX_NON_SPECIAL_CHARS,
|
|
4715
|
-
REGEX_SPECIAL_CHARS_BACKREF,
|
|
4716
|
-
REPLACEMENTS
|
|
4717
|
-
} = constants;
|
|
4718
|
-
|
|
4719
|
-
/**
|
|
4720
|
-
* Helpers
|
|
4721
|
-
*/
|
|
4722
|
-
|
|
4723
|
-
const expandRange = (args, options) => {
|
|
4724
|
-
if (typeof options.expandRange === 'function') {
|
|
4725
|
-
return options.expandRange(...args, options);
|
|
4726
|
-
}
|
|
4727
|
-
|
|
4728
|
-
args.sort();
|
|
4729
|
-
const value = `[${args.join('-')}]`;
|
|
4730
|
-
|
|
4731
|
-
try {
|
|
4732
|
-
/* eslint-disable-next-line no-new */
|
|
4733
|
-
new RegExp(value);
|
|
4734
|
-
} catch (ex) {
|
|
4735
|
-
return args.map(v => utils.escapeRegex(v)).join('..');
|
|
4736
|
-
}
|
|
4737
|
-
|
|
4738
|
-
return value;
|
|
4739
|
-
};
|
|
4740
|
-
|
|
4741
|
-
/**
|
|
4742
|
-
* Create the message for a syntax error
|
|
4743
|
-
*/
|
|
4744
|
-
|
|
4745
|
-
const syntaxError = (type, char) => {
|
|
4746
|
-
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
4747
|
-
};
|
|
4748
|
-
|
|
4749
|
-
/**
|
|
4750
|
-
* Parse the given input string.
|
|
4751
|
-
* @param {String} input
|
|
4752
|
-
* @param {Object} options
|
|
4753
|
-
* @return {Object}
|
|
4754
|
-
*/
|
|
4755
|
-
|
|
4756
|
-
const parse = (input, options) => {
|
|
4757
|
-
if (typeof input !== 'string') {
|
|
4758
|
-
throw new TypeError('Expected a string');
|
|
4759
|
-
}
|
|
4760
|
-
|
|
4761
|
-
input = REPLACEMENTS[input] || input;
|
|
4762
|
-
|
|
4763
|
-
const opts = { ...options };
|
|
4764
|
-
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
4765
|
-
|
|
4766
|
-
let len = input.length;
|
|
4767
|
-
if (len > max) {
|
|
4768
|
-
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
4769
|
-
}
|
|
4770
|
-
|
|
4771
|
-
const bos = { type: 'bos', value: '', output: opts.prepend || '' };
|
|
4772
|
-
const tokens = [bos];
|
|
4773
|
-
|
|
4774
|
-
const capture = opts.capture ? '' : '?:';
|
|
4775
|
-
const win32 = utils.isWindows(options);
|
|
4776
|
-
|
|
4777
|
-
// create constants based on platform, for windows or posix
|
|
4778
|
-
const PLATFORM_CHARS = constants.globChars(win32);
|
|
4779
|
-
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
4780
|
-
|
|
4781
|
-
const {
|
|
4782
|
-
DOT_LITERAL,
|
|
4783
|
-
PLUS_LITERAL,
|
|
4784
|
-
SLASH_LITERAL,
|
|
4785
|
-
ONE_CHAR,
|
|
4786
|
-
DOTS_SLASH,
|
|
4787
|
-
NO_DOT,
|
|
4788
|
-
NO_DOT_SLASH,
|
|
4789
|
-
NO_DOTS_SLASH,
|
|
4790
|
-
QMARK,
|
|
4791
|
-
QMARK_NO_DOT,
|
|
4792
|
-
STAR,
|
|
4793
|
-
START_ANCHOR
|
|
4794
|
-
} = PLATFORM_CHARS;
|
|
4795
|
-
|
|
4796
|
-
const globstar = opts => {
|
|
4797
|
-
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
4798
|
-
};
|
|
4799
|
-
|
|
4800
|
-
const nodot = opts.dot ? '' : NO_DOT;
|
|
4801
|
-
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
4802
|
-
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
4803
|
-
|
|
4804
|
-
if (opts.capture) {
|
|
4805
|
-
star = `(${star})`;
|
|
4806
|
-
}
|
|
4807
|
-
|
|
4808
|
-
// minimatch options support
|
|
4809
|
-
if (typeof opts.noext === 'boolean') {
|
|
4810
|
-
opts.noextglob = opts.noext;
|
|
4811
|
-
}
|
|
4812
|
-
|
|
4813
|
-
const state = {
|
|
4814
|
-
input,
|
|
4815
|
-
index: -1,
|
|
4816
|
-
start: 0,
|
|
4817
|
-
dot: opts.dot === true,
|
|
4818
|
-
consumed: '',
|
|
4819
|
-
output: '',
|
|
4820
|
-
prefix: '',
|
|
4821
|
-
backtrack: false,
|
|
4822
|
-
negated: false,
|
|
4823
|
-
brackets: 0,
|
|
4824
|
-
braces: 0,
|
|
4825
|
-
parens: 0,
|
|
4826
|
-
quotes: 0,
|
|
4827
|
-
globstar: false,
|
|
4828
|
-
tokens
|
|
4829
|
-
};
|
|
4830
|
-
|
|
4831
|
-
input = utils.removePrefix(input, state);
|
|
4832
|
-
len = input.length;
|
|
4833
|
-
|
|
4834
|
-
const extglobs = [];
|
|
4835
|
-
const braces = [];
|
|
4836
|
-
const stack = [];
|
|
4837
|
-
let prev = bos;
|
|
4838
|
-
let value;
|
|
4839
|
-
|
|
4840
|
-
/**
|
|
4841
|
-
* Tokenizing helpers
|
|
4842
|
-
*/
|
|
4843
|
-
|
|
4844
|
-
const eos = () => state.index === len - 1;
|
|
4845
|
-
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
4846
|
-
const advance = state.advance = () => input[++state.index] || '';
|
|
4847
|
-
const remaining = () => input.slice(state.index + 1);
|
|
4848
|
-
const consume = (value = '', num = 0) => {
|
|
4849
|
-
state.consumed += value;
|
|
4850
|
-
state.index += num;
|
|
4851
|
-
};
|
|
4852
|
-
|
|
4853
|
-
const append = token => {
|
|
4854
|
-
state.output += token.output != null ? token.output : token.value;
|
|
4855
|
-
consume(token.value);
|
|
4856
|
-
};
|
|
4857
|
-
|
|
4858
|
-
const negate = () => {
|
|
4859
|
-
let count = 1;
|
|
4860
|
-
|
|
4861
|
-
while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
|
|
4862
|
-
advance();
|
|
4863
|
-
state.start++;
|
|
4864
|
-
count++;
|
|
4865
|
-
}
|
|
4866
|
-
|
|
4867
|
-
if (count % 2 === 0) {
|
|
4868
|
-
return false;
|
|
4869
|
-
}
|
|
4870
|
-
|
|
4871
|
-
state.negated = true;
|
|
4872
|
-
state.start++;
|
|
4873
|
-
return true;
|
|
4874
|
-
};
|
|
4875
|
-
|
|
4876
|
-
const increment = type => {
|
|
4877
|
-
state[type]++;
|
|
4878
|
-
stack.push(type);
|
|
4879
|
-
};
|
|
4880
|
-
|
|
4881
|
-
const decrement = type => {
|
|
4882
|
-
state[type]--;
|
|
4883
|
-
stack.pop();
|
|
4884
|
-
};
|
|
4885
|
-
|
|
4886
|
-
/**
|
|
4887
|
-
* Push tokens onto the tokens array. This helper speeds up
|
|
4888
|
-
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
4889
|
-
* and 2) helping us avoid creating extra tokens when consecutive
|
|
4890
|
-
* characters are plain text. This improves performance and simplifies
|
|
4891
|
-
* lookbehinds.
|
|
4892
|
-
*/
|
|
4893
|
-
|
|
4894
|
-
const push = tok => {
|
|
4895
|
-
if (prev.type === 'globstar') {
|
|
4896
|
-
const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
|
|
4897
|
-
const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
|
|
4898
|
-
|
|
4899
|
-
if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
|
|
4900
|
-
state.output = state.output.slice(0, -prev.output.length);
|
|
4901
|
-
prev.type = 'star';
|
|
4902
|
-
prev.value = '*';
|
|
4903
|
-
prev.output = star;
|
|
4904
|
-
state.output += prev.output;
|
|
4905
|
-
}
|
|
4906
|
-
}
|
|
4907
|
-
|
|
4908
|
-
if (extglobs.length && tok.type !== 'paren') {
|
|
4909
|
-
extglobs[extglobs.length - 1].inner += tok.value;
|
|
4910
|
-
}
|
|
4911
|
-
|
|
4912
|
-
if (tok.value || tok.output) append(tok);
|
|
4913
|
-
if (prev && prev.type === 'text' && tok.type === 'text') {
|
|
4914
|
-
prev.value += tok.value;
|
|
4915
|
-
prev.output = (prev.output || '') + tok.value;
|
|
4916
|
-
return;
|
|
4917
|
-
}
|
|
4918
|
-
|
|
4919
|
-
tok.prev = prev;
|
|
4920
|
-
tokens.push(tok);
|
|
4921
|
-
prev = tok;
|
|
4922
|
-
};
|
|
4923
|
-
|
|
4924
|
-
const extglobOpen = (type, value) => {
|
|
4925
|
-
const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
|
|
4926
|
-
|
|
4927
|
-
token.prev = prev;
|
|
4928
|
-
token.parens = state.parens;
|
|
4929
|
-
token.output = state.output;
|
|
4930
|
-
const output = (opts.capture ? '(' : '') + token.open;
|
|
4931
|
-
|
|
4932
|
-
increment('parens');
|
|
4933
|
-
push({ type, value, output: state.output ? '' : ONE_CHAR });
|
|
4934
|
-
push({ type: 'paren', extglob: true, value: advance(), output });
|
|
4935
|
-
extglobs.push(token);
|
|
4936
|
-
};
|
|
4937
|
-
|
|
4938
|
-
const extglobClose = token => {
|
|
4939
|
-
let output = token.close + (opts.capture ? ')' : '');
|
|
4940
|
-
let rest;
|
|
4941
|
-
|
|
4942
|
-
if (token.type === 'negate') {
|
|
4943
|
-
let extglobStar = star;
|
|
4944
|
-
|
|
4945
|
-
if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
|
|
4946
|
-
extglobStar = globstar(opts);
|
|
4947
|
-
}
|
|
4948
|
-
|
|
4949
|
-
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
4950
|
-
output = token.close = `)$))${extglobStar}`;
|
|
4951
|
-
}
|
|
4952
|
-
|
|
4953
|
-
if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
4954
|
-
// Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
|
|
4955
|
-
// In this case, we need to parse the string and use it in the output of the original pattern.
|
|
4956
|
-
// Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
|
|
4957
|
-
//
|
|
4958
|
-
// Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
|
|
4959
|
-
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
4960
|
-
|
|
4961
|
-
output = token.close = `)${expression})${extglobStar})`;
|
|
4962
|
-
}
|
|
4963
|
-
|
|
4964
|
-
if (token.prev.type === 'bos') {
|
|
4965
|
-
state.negatedExtglob = true;
|
|
4966
|
-
}
|
|
4967
|
-
}
|
|
4968
|
-
|
|
4969
|
-
push({ type: 'paren', extglob: true, value, output });
|
|
4970
|
-
decrement('parens');
|
|
4971
|
-
};
|
|
4972
|
-
|
|
4973
|
-
/**
|
|
4974
|
-
* Fast paths
|
|
4975
|
-
*/
|
|
4976
|
-
|
|
4977
|
-
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
4978
|
-
let backslashes = false;
|
|
4979
|
-
|
|
4980
|
-
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
4981
|
-
if (first === '\\') {
|
|
4982
|
-
backslashes = true;
|
|
4983
|
-
return m;
|
|
4984
|
-
}
|
|
4985
|
-
|
|
4986
|
-
if (first === '?') {
|
|
4987
|
-
if (esc) {
|
|
4988
|
-
return esc + first + (rest ? QMARK.repeat(rest.length) : '');
|
|
4989
|
-
}
|
|
4990
|
-
if (index === 0) {
|
|
4991
|
-
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
|
|
4992
|
-
}
|
|
4993
|
-
return QMARK.repeat(chars.length);
|
|
4994
|
-
}
|
|
4995
|
-
|
|
4996
|
-
if (first === '.') {
|
|
4997
|
-
return DOT_LITERAL.repeat(chars.length);
|
|
4998
|
-
}
|
|
4999
|
-
|
|
5000
|
-
if (first === '*') {
|
|
5001
|
-
if (esc) {
|
|
5002
|
-
return esc + first + (rest ? star : '');
|
|
5003
|
-
}
|
|
5004
|
-
return star;
|
|
5005
|
-
}
|
|
5006
|
-
return esc ? m : `\\${m}`;
|
|
5007
|
-
});
|
|
5008
|
-
|
|
5009
|
-
if (backslashes === true) {
|
|
5010
|
-
if (opts.unescape === true) {
|
|
5011
|
-
output = output.replace(/\\/g, '');
|
|
5012
|
-
} else {
|
|
5013
|
-
output = output.replace(/\\+/g, m => {
|
|
5014
|
-
return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
|
|
5015
|
-
});
|
|
5016
|
-
}
|
|
5017
|
-
}
|
|
5018
|
-
|
|
5019
|
-
if (output === input && opts.contains === true) {
|
|
5020
|
-
state.output = input;
|
|
5021
|
-
return state;
|
|
5022
|
-
}
|
|
5023
|
-
|
|
5024
|
-
state.output = utils.wrapOutput(output, state, options);
|
|
5025
|
-
return state;
|
|
5026
|
-
}
|
|
5027
|
-
|
|
5028
|
-
/**
|
|
5029
|
-
* Tokenize input until we reach end-of-string
|
|
5030
|
-
*/
|
|
5031
|
-
|
|
5032
|
-
while (!eos()) {
|
|
5033
|
-
value = advance();
|
|
5034
|
-
|
|
5035
|
-
if (value === '\u0000') {
|
|
5036
|
-
continue;
|
|
5037
|
-
}
|
|
5038
|
-
|
|
5039
|
-
/**
|
|
5040
|
-
* Escaped characters
|
|
5041
|
-
*/
|
|
5042
|
-
|
|
5043
|
-
if (value === '\\') {
|
|
5044
|
-
const next = peek();
|
|
5045
|
-
|
|
5046
|
-
if (next === '/' && opts.bash !== true) {
|
|
5047
|
-
continue;
|
|
5048
|
-
}
|
|
5049
|
-
|
|
5050
|
-
if (next === '.' || next === ';') {
|
|
5051
|
-
continue;
|
|
5052
|
-
}
|
|
5053
|
-
|
|
5054
|
-
if (!next) {
|
|
5055
|
-
value += '\\';
|
|
5056
|
-
push({ type: 'text', value });
|
|
5057
|
-
continue;
|
|
5058
|
-
}
|
|
5059
|
-
|
|
5060
|
-
// collapse slashes to reduce potential for exploits
|
|
5061
|
-
const match = /^\\+/.exec(remaining());
|
|
5062
|
-
let slashes = 0;
|
|
5063
|
-
|
|
5064
|
-
if (match && match[0].length > 2) {
|
|
5065
|
-
slashes = match[0].length;
|
|
5066
|
-
state.index += slashes;
|
|
5067
|
-
if (slashes % 2 !== 0) {
|
|
5068
|
-
value += '\\';
|
|
5069
|
-
}
|
|
5070
|
-
}
|
|
5071
|
-
|
|
5072
|
-
if (opts.unescape === true) {
|
|
5073
|
-
value = advance();
|
|
5074
|
-
} else {
|
|
5075
|
-
value += advance();
|
|
5076
|
-
}
|
|
5077
|
-
|
|
5078
|
-
if (state.brackets === 0) {
|
|
5079
|
-
push({ type: 'text', value });
|
|
5080
|
-
continue;
|
|
5081
|
-
}
|
|
5082
|
-
}
|
|
5083
|
-
|
|
5084
|
-
/**
|
|
5085
|
-
* If we're inside a regex character class, continue
|
|
5086
|
-
* until we reach the closing bracket.
|
|
5087
|
-
*/
|
|
5088
|
-
|
|
5089
|
-
if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
|
|
5090
|
-
if (opts.posix !== false && value === ':') {
|
|
5091
|
-
const inner = prev.value.slice(1);
|
|
5092
|
-
if (inner.includes('[')) {
|
|
5093
|
-
prev.posix = true;
|
|
5094
|
-
|
|
5095
|
-
if (inner.includes(':')) {
|
|
5096
|
-
const idx = prev.value.lastIndexOf('[');
|
|
5097
|
-
const pre = prev.value.slice(0, idx);
|
|
5098
|
-
const rest = prev.value.slice(idx + 2);
|
|
5099
|
-
const posix = POSIX_REGEX_SOURCE[rest];
|
|
5100
|
-
if (posix) {
|
|
5101
|
-
prev.value = pre + posix;
|
|
5102
|
-
state.backtrack = true;
|
|
5103
|
-
advance();
|
|
5104
|
-
|
|
5105
|
-
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
5106
|
-
bos.output = ONE_CHAR;
|
|
5107
|
-
}
|
|
5108
|
-
continue;
|
|
5109
|
-
}
|
|
5110
|
-
}
|
|
5111
|
-
}
|
|
5112
|
-
}
|
|
5113
|
-
|
|
5114
|
-
if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
|
|
5115
|
-
value = `\\${value}`;
|
|
5116
|
-
}
|
|
5117
|
-
|
|
5118
|
-
if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
|
|
5119
|
-
value = `\\${value}`;
|
|
5120
|
-
}
|
|
5121
|
-
|
|
5122
|
-
if (opts.posix === true && value === '!' && prev.value === '[') {
|
|
5123
|
-
value = '^';
|
|
5124
|
-
}
|
|
5125
|
-
|
|
5126
|
-
prev.value += value;
|
|
5127
|
-
append({ value });
|
|
5128
|
-
continue;
|
|
5129
|
-
}
|
|
5130
|
-
|
|
5131
|
-
/**
|
|
5132
|
-
* If we're inside a quoted string, continue
|
|
5133
|
-
* until we reach the closing double quote.
|
|
5134
|
-
*/
|
|
5135
|
-
|
|
5136
|
-
if (state.quotes === 1 && value !== '"') {
|
|
5137
|
-
value = utils.escapeRegex(value);
|
|
5138
|
-
prev.value += value;
|
|
5139
|
-
append({ value });
|
|
5140
|
-
continue;
|
|
5141
|
-
}
|
|
5142
|
-
|
|
5143
|
-
/**
|
|
5144
|
-
* Double quotes
|
|
5145
|
-
*/
|
|
5146
|
-
|
|
5147
|
-
if (value === '"') {
|
|
5148
|
-
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
5149
|
-
if (opts.keepQuotes === true) {
|
|
5150
|
-
push({ type: 'text', value });
|
|
5151
|
-
}
|
|
5152
|
-
continue;
|
|
5153
|
-
}
|
|
5154
|
-
|
|
5155
|
-
/**
|
|
5156
|
-
* Parentheses
|
|
5157
|
-
*/
|
|
5158
|
-
|
|
5159
|
-
if (value === '(') {
|
|
5160
|
-
increment('parens');
|
|
5161
|
-
push({ type: 'paren', value });
|
|
5162
|
-
continue;
|
|
5163
|
-
}
|
|
5164
|
-
|
|
5165
|
-
if (value === ')') {
|
|
5166
|
-
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
5167
|
-
throw new SyntaxError(syntaxError('opening', '('));
|
|
5168
|
-
}
|
|
5169
|
-
|
|
5170
|
-
const extglob = extglobs[extglobs.length - 1];
|
|
5171
|
-
if (extglob && state.parens === extglob.parens + 1) {
|
|
5172
|
-
extglobClose(extglobs.pop());
|
|
5173
|
-
continue;
|
|
5174
|
-
}
|
|
5175
|
-
|
|
5176
|
-
push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
|
|
5177
|
-
decrement('parens');
|
|
5178
|
-
continue;
|
|
5179
|
-
}
|
|
5180
|
-
|
|
5181
|
-
/**
|
|
5182
|
-
* Square brackets
|
|
5183
|
-
*/
|
|
5184
|
-
|
|
5185
|
-
if (value === '[') {
|
|
5186
|
-
if (opts.nobracket === true || !remaining().includes(']')) {
|
|
5187
|
-
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
5188
|
-
throw new SyntaxError(syntaxError('closing', ']'));
|
|
5189
|
-
}
|
|
5190
|
-
|
|
5191
|
-
value = `\\${value}`;
|
|
5192
|
-
} else {
|
|
5193
|
-
increment('brackets');
|
|
5194
|
-
}
|
|
5195
|
-
|
|
5196
|
-
push({ type: 'bracket', value });
|
|
5197
|
-
continue;
|
|
5198
|
-
}
|
|
5199
|
-
|
|
5200
|
-
if (value === ']') {
|
|
5201
|
-
if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
|
|
5202
|
-
push({ type: 'text', value, output: `\\${value}` });
|
|
5203
|
-
continue;
|
|
5204
|
-
}
|
|
5205
|
-
|
|
5206
|
-
if (state.brackets === 0) {
|
|
5207
|
-
if (opts.strictBrackets === true) {
|
|
5208
|
-
throw new SyntaxError(syntaxError('opening', '['));
|
|
5209
|
-
}
|
|
5210
|
-
|
|
5211
|
-
push({ type: 'text', value, output: `\\${value}` });
|
|
5212
|
-
continue;
|
|
5213
|
-
}
|
|
5214
|
-
|
|
5215
|
-
decrement('brackets');
|
|
5216
|
-
|
|
5217
|
-
const prevValue = prev.value.slice(1);
|
|
5218
|
-
if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
|
|
5219
|
-
value = `/${value}`;
|
|
5220
|
-
}
|
|
5221
|
-
|
|
5222
|
-
prev.value += value;
|
|
5223
|
-
append({ value });
|
|
5224
|
-
|
|
5225
|
-
// when literal brackets are explicitly disabled
|
|
5226
|
-
// assume we should match with a regex character class
|
|
5227
|
-
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
5228
|
-
continue;
|
|
5229
|
-
}
|
|
5230
|
-
|
|
5231
|
-
const escaped = utils.escapeRegex(prev.value);
|
|
5232
|
-
state.output = state.output.slice(0, -prev.value.length);
|
|
5233
|
-
|
|
5234
|
-
// when literal brackets are explicitly enabled
|
|
5235
|
-
// assume we should escape the brackets to match literal characters
|
|
5236
|
-
if (opts.literalBrackets === true) {
|
|
5237
|
-
state.output += escaped;
|
|
5238
|
-
prev.value = escaped;
|
|
5239
|
-
continue;
|
|
5240
|
-
}
|
|
5241
|
-
|
|
5242
|
-
// when the user specifies nothing, try to match both
|
|
5243
|
-
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
5244
|
-
state.output += prev.value;
|
|
5245
|
-
continue;
|
|
5246
|
-
}
|
|
5247
|
-
|
|
5248
|
-
/**
|
|
5249
|
-
* Braces
|
|
5250
|
-
*/
|
|
5251
|
-
|
|
5252
|
-
if (value === '{' && opts.nobrace !== true) {
|
|
5253
|
-
increment('braces');
|
|
5254
|
-
|
|
5255
|
-
const open = {
|
|
5256
|
-
type: 'brace',
|
|
5257
|
-
value,
|
|
5258
|
-
output: '(',
|
|
5259
|
-
outputIndex: state.output.length,
|
|
5260
|
-
tokensIndex: state.tokens.length
|
|
5261
|
-
};
|
|
5262
|
-
|
|
5263
|
-
braces.push(open);
|
|
5264
|
-
push(open);
|
|
5265
|
-
continue;
|
|
5266
|
-
}
|
|
5267
|
-
|
|
5268
|
-
if (value === '}') {
|
|
5269
|
-
const brace = braces[braces.length - 1];
|
|
5270
|
-
|
|
5271
|
-
if (opts.nobrace === true || !brace) {
|
|
5272
|
-
push({ type: 'text', value, output: value });
|
|
5273
|
-
continue;
|
|
5274
|
-
}
|
|
5275
|
-
|
|
5276
|
-
let output = ')';
|
|
5277
|
-
|
|
5278
|
-
if (brace.dots === true) {
|
|
5279
|
-
const arr = tokens.slice();
|
|
5280
|
-
const range = [];
|
|
5281
|
-
|
|
5282
|
-
for (let i = arr.length - 1; i >= 0; i--) {
|
|
5283
|
-
tokens.pop();
|
|
5284
|
-
if (arr[i].type === 'brace') {
|
|
5285
|
-
break;
|
|
5286
|
-
}
|
|
5287
|
-
if (arr[i].type !== 'dots') {
|
|
5288
|
-
range.unshift(arr[i].value);
|
|
5289
|
-
}
|
|
5290
|
-
}
|
|
5291
|
-
|
|
5292
|
-
output = expandRange(range, opts);
|
|
5293
|
-
state.backtrack = true;
|
|
5294
|
-
}
|
|
5295
|
-
|
|
5296
|
-
if (brace.comma !== true && brace.dots !== true) {
|
|
5297
|
-
const out = state.output.slice(0, brace.outputIndex);
|
|
5298
|
-
const toks = state.tokens.slice(brace.tokensIndex);
|
|
5299
|
-
brace.value = brace.output = '\\{';
|
|
5300
|
-
value = output = '\\}';
|
|
5301
|
-
state.output = out;
|
|
5302
|
-
for (const t of toks) {
|
|
5303
|
-
state.output += (t.output || t.value);
|
|
5304
|
-
}
|
|
5305
|
-
}
|
|
5306
|
-
|
|
5307
|
-
push({ type: 'brace', value, output });
|
|
5308
|
-
decrement('braces');
|
|
5309
|
-
braces.pop();
|
|
5310
|
-
continue;
|
|
5311
|
-
}
|
|
5312
|
-
|
|
5313
|
-
/**
|
|
5314
|
-
* Pipes
|
|
5315
|
-
*/
|
|
5316
|
-
|
|
5317
|
-
if (value === '|') {
|
|
5318
|
-
if (extglobs.length > 0) {
|
|
5319
|
-
extglobs[extglobs.length - 1].conditions++;
|
|
5320
|
-
}
|
|
5321
|
-
push({ type: 'text', value });
|
|
5322
|
-
continue;
|
|
5323
|
-
}
|
|
5324
|
-
|
|
5325
|
-
/**
|
|
5326
|
-
* Commas
|
|
5327
|
-
*/
|
|
5328
|
-
|
|
5329
|
-
if (value === ',') {
|
|
5330
|
-
let output = value;
|
|
5331
|
-
|
|
5332
|
-
const brace = braces[braces.length - 1];
|
|
5333
|
-
if (brace && stack[stack.length - 1] === 'braces') {
|
|
5334
|
-
brace.comma = true;
|
|
5335
|
-
output = '|';
|
|
5336
|
-
}
|
|
5337
|
-
|
|
5338
|
-
push({ type: 'comma', value, output });
|
|
5339
|
-
continue;
|
|
5340
|
-
}
|
|
5341
|
-
|
|
5342
|
-
/**
|
|
5343
|
-
* Slashes
|
|
5344
|
-
*/
|
|
5345
|
-
|
|
5346
|
-
if (value === '/') {
|
|
5347
|
-
// if the beginning of the glob is "./", advance the start
|
|
5348
|
-
// to the current index, and don't add the "./" characters
|
|
5349
|
-
// to the state. This greatly simplifies lookbehinds when
|
|
5350
|
-
// checking for BOS characters like "!" and "." (not "./")
|
|
5351
|
-
if (prev.type === 'dot' && state.index === state.start + 1) {
|
|
5352
|
-
state.start = state.index + 1;
|
|
5353
|
-
state.consumed = '';
|
|
5354
|
-
state.output = '';
|
|
5355
|
-
tokens.pop();
|
|
5356
|
-
prev = bos; // reset "prev" to the first token
|
|
5357
|
-
continue;
|
|
5358
|
-
}
|
|
5359
|
-
|
|
5360
|
-
push({ type: 'slash', value, output: SLASH_LITERAL });
|
|
5361
|
-
continue;
|
|
5362
|
-
}
|
|
5363
|
-
|
|
5364
|
-
/**
|
|
5365
|
-
* Dots
|
|
5366
|
-
*/
|
|
5367
|
-
|
|
5368
|
-
if (value === '.') {
|
|
5369
|
-
if (state.braces > 0 && prev.type === 'dot') {
|
|
5370
|
-
if (prev.value === '.') prev.output = DOT_LITERAL;
|
|
5371
|
-
const brace = braces[braces.length - 1];
|
|
5372
|
-
prev.type = 'dots';
|
|
5373
|
-
prev.output += value;
|
|
5374
|
-
prev.value += value;
|
|
5375
|
-
brace.dots = true;
|
|
5376
|
-
continue;
|
|
5377
|
-
}
|
|
5378
|
-
|
|
5379
|
-
if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
|
|
5380
|
-
push({ type: 'text', value, output: DOT_LITERAL });
|
|
5381
|
-
continue;
|
|
5382
|
-
}
|
|
5383
|
-
|
|
5384
|
-
push({ type: 'dot', value, output: DOT_LITERAL });
|
|
5385
|
-
continue;
|
|
5386
|
-
}
|
|
5387
|
-
|
|
5388
|
-
/**
|
|
5389
|
-
* Question marks
|
|
5390
|
-
*/
|
|
5391
|
-
|
|
5392
|
-
if (value === '?') {
|
|
5393
|
-
const isGroup = prev && prev.value === '(';
|
|
5394
|
-
if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
|
5395
|
-
extglobOpen('qmark', value);
|
|
5396
|
-
continue;
|
|
5397
|
-
}
|
|
5398
|
-
|
|
5399
|
-
if (prev && prev.type === 'paren') {
|
|
5400
|
-
const next = peek();
|
|
5401
|
-
let output = value;
|
|
5402
|
-
|
|
5403
|
-
if (next === '<' && !utils.supportsLookbehinds()) {
|
|
5404
|
-
throw new Error('Node.js v10 or higher is required for regex lookbehinds');
|
|
5405
|
-
}
|
|
5406
|
-
|
|
5407
|
-
if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
|
|
5408
|
-
output = `\\${value}`;
|
|
5409
|
-
}
|
|
5410
|
-
|
|
5411
|
-
push({ type: 'text', value, output });
|
|
5412
|
-
continue;
|
|
5413
|
-
}
|
|
5414
|
-
|
|
5415
|
-
if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
|
|
5416
|
-
push({ type: 'qmark', value, output: QMARK_NO_DOT });
|
|
5417
|
-
continue;
|
|
5418
|
-
}
|
|
5419
|
-
|
|
5420
|
-
push({ type: 'qmark', value, output: QMARK });
|
|
5421
|
-
continue;
|
|
5422
|
-
}
|
|
5423
|
-
|
|
5424
|
-
/**
|
|
5425
|
-
* Exclamation
|
|
5426
|
-
*/
|
|
5427
|
-
|
|
5428
|
-
if (value === '!') {
|
|
5429
|
-
if (opts.noextglob !== true && peek() === '(') {
|
|
5430
|
-
if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
|
|
5431
|
-
extglobOpen('negate', value);
|
|
5432
|
-
continue;
|
|
5433
|
-
}
|
|
5434
|
-
}
|
|
5435
|
-
|
|
5436
|
-
if (opts.nonegate !== true && state.index === 0) {
|
|
5437
|
-
negate();
|
|
5438
|
-
continue;
|
|
5439
|
-
}
|
|
5440
|
-
}
|
|
5441
|
-
|
|
5442
|
-
/**
|
|
5443
|
-
* Plus
|
|
5444
|
-
*/
|
|
5445
|
-
|
|
5446
|
-
if (value === '+') {
|
|
5447
|
-
if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
|
5448
|
-
extglobOpen('plus', value);
|
|
5449
|
-
continue;
|
|
5450
|
-
}
|
|
5451
|
-
|
|
5452
|
-
if ((prev && prev.value === '(') || opts.regex === false) {
|
|
5453
|
-
push({ type: 'plus', value, output: PLUS_LITERAL });
|
|
5454
|
-
continue;
|
|
5455
|
-
}
|
|
5456
|
-
|
|
5457
|
-
if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
|
|
5458
|
-
push({ type: 'plus', value });
|
|
5459
|
-
continue;
|
|
5460
|
-
}
|
|
5461
|
-
|
|
5462
|
-
push({ type: 'plus', value: PLUS_LITERAL });
|
|
5463
|
-
continue;
|
|
5464
|
-
}
|
|
5465
|
-
|
|
5466
|
-
/**
|
|
5467
|
-
* Plain text
|
|
5468
|
-
*/
|
|
5469
|
-
|
|
5470
|
-
if (value === '@') {
|
|
5471
|
-
if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
|
5472
|
-
push({ type: 'at', extglob: true, value, output: '' });
|
|
5473
|
-
continue;
|
|
5474
|
-
}
|
|
5475
|
-
|
|
5476
|
-
push({ type: 'text', value });
|
|
5477
|
-
continue;
|
|
5478
|
-
}
|
|
5479
|
-
|
|
5480
|
-
/**
|
|
5481
|
-
* Plain text
|
|
5482
|
-
*/
|
|
5483
|
-
|
|
5484
|
-
if (value !== '*') {
|
|
5485
|
-
if (value === '$' || value === '^') {
|
|
5486
|
-
value = `\\${value}`;
|
|
5487
|
-
}
|
|
5488
|
-
|
|
5489
|
-
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
5490
|
-
if (match) {
|
|
5491
|
-
value += match[0];
|
|
5492
|
-
state.index += match[0].length;
|
|
5493
|
-
}
|
|
5494
|
-
|
|
5495
|
-
push({ type: 'text', value });
|
|
5496
|
-
continue;
|
|
5497
|
-
}
|
|
5498
|
-
|
|
5499
|
-
/**
|
|
5500
|
-
* Stars
|
|
5501
|
-
*/
|
|
5502
|
-
|
|
5503
|
-
if (prev && (prev.type === 'globstar' || prev.star === true)) {
|
|
5504
|
-
prev.type = 'star';
|
|
5505
|
-
prev.star = true;
|
|
5506
|
-
prev.value += value;
|
|
5507
|
-
prev.output = star;
|
|
5508
|
-
state.backtrack = true;
|
|
5509
|
-
state.globstar = true;
|
|
5510
|
-
consume(value);
|
|
5511
|
-
continue;
|
|
5512
|
-
}
|
|
5513
|
-
|
|
5514
|
-
let rest = remaining();
|
|
5515
|
-
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
5516
|
-
extglobOpen('star', value);
|
|
5517
|
-
continue;
|
|
5518
|
-
}
|
|
5519
|
-
|
|
5520
|
-
if (prev.type === 'star') {
|
|
5521
|
-
if (opts.noglobstar === true) {
|
|
5522
|
-
consume(value);
|
|
5523
|
-
continue;
|
|
5524
|
-
}
|
|
5525
|
-
|
|
5526
|
-
const prior = prev.prev;
|
|
5527
|
-
const before = prior.prev;
|
|
5528
|
-
const isStart = prior.type === 'slash' || prior.type === 'bos';
|
|
5529
|
-
const afterStar = before && (before.type === 'star' || before.type === 'globstar');
|
|
5530
|
-
|
|
5531
|
-
if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
|
|
5532
|
-
push({ type: 'star', value, output: '' });
|
|
5533
|
-
continue;
|
|
5534
|
-
}
|
|
5535
|
-
|
|
5536
|
-
const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
|
|
5537
|
-
const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
|
|
5538
|
-
if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
|
|
5539
|
-
push({ type: 'star', value, output: '' });
|
|
5540
|
-
continue;
|
|
5541
|
-
}
|
|
5542
|
-
|
|
5543
|
-
// strip consecutive `/**/`
|
|
5544
|
-
while (rest.slice(0, 3) === '/**') {
|
|
5545
|
-
const after = input[state.index + 4];
|
|
5546
|
-
if (after && after !== '/') {
|
|
5547
|
-
break;
|
|
5548
|
-
}
|
|
5549
|
-
rest = rest.slice(3);
|
|
5550
|
-
consume('/**', 3);
|
|
5551
|
-
}
|
|
5552
|
-
|
|
5553
|
-
if (prior.type === 'bos' && eos()) {
|
|
5554
|
-
prev.type = 'globstar';
|
|
5555
|
-
prev.value += value;
|
|
5556
|
-
prev.output = globstar(opts);
|
|
5557
|
-
state.output = prev.output;
|
|
5558
|
-
state.globstar = true;
|
|
5559
|
-
consume(value);
|
|
5560
|
-
continue;
|
|
5561
|
-
}
|
|
5562
|
-
|
|
5563
|
-
if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
|
|
5564
|
-
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
5565
|
-
prior.output = `(?:${prior.output}`;
|
|
5566
|
-
|
|
5567
|
-
prev.type = 'globstar';
|
|
5568
|
-
prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
|
|
5569
|
-
prev.value += value;
|
|
5570
|
-
state.globstar = true;
|
|
5571
|
-
state.output += prior.output + prev.output;
|
|
5572
|
-
consume(value);
|
|
5573
|
-
continue;
|
|
5574
|
-
}
|
|
5575
|
-
|
|
5576
|
-
if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
|
|
5577
|
-
const end = rest[1] !== void 0 ? '|$' : '';
|
|
5578
|
-
|
|
5579
|
-
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
5580
|
-
prior.output = `(?:${prior.output}`;
|
|
5581
|
-
|
|
5582
|
-
prev.type = 'globstar';
|
|
5583
|
-
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
5584
|
-
prev.value += value;
|
|
5585
|
-
|
|
5586
|
-
state.output += prior.output + prev.output;
|
|
5587
|
-
state.globstar = true;
|
|
5588
|
-
|
|
5589
|
-
consume(value + advance());
|
|
5590
|
-
|
|
5591
|
-
push({ type: 'slash', value: '/', output: '' });
|
|
5592
|
-
continue;
|
|
5593
|
-
}
|
|
5594
|
-
|
|
5595
|
-
if (prior.type === 'bos' && rest[0] === '/') {
|
|
5596
|
-
prev.type = 'globstar';
|
|
5597
|
-
prev.value += value;
|
|
5598
|
-
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
5599
|
-
state.output = prev.output;
|
|
5600
|
-
state.globstar = true;
|
|
5601
|
-
consume(value + advance());
|
|
5602
|
-
push({ type: 'slash', value: '/', output: '' });
|
|
5603
|
-
continue;
|
|
5604
|
-
}
|
|
5605
|
-
|
|
5606
|
-
// remove single star from output
|
|
5607
|
-
state.output = state.output.slice(0, -prev.output.length);
|
|
5608
|
-
|
|
5609
|
-
// reset previous token to globstar
|
|
5610
|
-
prev.type = 'globstar';
|
|
5611
|
-
prev.output = globstar(opts);
|
|
5612
|
-
prev.value += value;
|
|
5613
|
-
|
|
5614
|
-
// reset output with globstar
|
|
5615
|
-
state.output += prev.output;
|
|
5616
|
-
state.globstar = true;
|
|
5617
|
-
consume(value);
|
|
5618
|
-
continue;
|
|
5619
|
-
}
|
|
5620
|
-
|
|
5621
|
-
const token = { type: 'star', value, output: star };
|
|
5622
|
-
|
|
5623
|
-
if (opts.bash === true) {
|
|
5624
|
-
token.output = '.*?';
|
|
5625
|
-
if (prev.type === 'bos' || prev.type === 'slash') {
|
|
5626
|
-
token.output = nodot + token.output;
|
|
5627
|
-
}
|
|
5628
|
-
push(token);
|
|
5629
|
-
continue;
|
|
5630
|
-
}
|
|
5631
|
-
|
|
5632
|
-
if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
|
|
5633
|
-
token.output = value;
|
|
5634
|
-
push(token);
|
|
5635
|
-
continue;
|
|
5636
|
-
}
|
|
5637
|
-
|
|
5638
|
-
if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
|
|
5639
|
-
if (prev.type === 'dot') {
|
|
5640
|
-
state.output += NO_DOT_SLASH;
|
|
5641
|
-
prev.output += NO_DOT_SLASH;
|
|
5642
|
-
|
|
5643
|
-
} else if (opts.dot === true) {
|
|
5644
|
-
state.output += NO_DOTS_SLASH;
|
|
5645
|
-
prev.output += NO_DOTS_SLASH;
|
|
5646
|
-
|
|
5647
|
-
} else {
|
|
5648
|
-
state.output += nodot;
|
|
5649
|
-
prev.output += nodot;
|
|
5650
|
-
}
|
|
5651
|
-
|
|
5652
|
-
if (peek() !== '*') {
|
|
5653
|
-
state.output += ONE_CHAR;
|
|
5654
|
-
prev.output += ONE_CHAR;
|
|
5655
|
-
}
|
|
5656
|
-
}
|
|
5657
|
-
|
|
5658
|
-
push(token);
|
|
5659
|
-
}
|
|
5660
|
-
|
|
5661
|
-
while (state.brackets > 0) {
|
|
5662
|
-
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
|
|
5663
|
-
state.output = utils.escapeLast(state.output, '[');
|
|
5664
|
-
decrement('brackets');
|
|
5665
|
-
}
|
|
5666
|
-
|
|
5667
|
-
while (state.parens > 0) {
|
|
5668
|
-
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
|
|
5669
|
-
state.output = utils.escapeLast(state.output, '(');
|
|
5670
|
-
decrement('parens');
|
|
5671
|
-
}
|
|
5672
|
-
|
|
5673
|
-
while (state.braces > 0) {
|
|
5674
|
-
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
|
|
5675
|
-
state.output = utils.escapeLast(state.output, '{');
|
|
5676
|
-
decrement('braces');
|
|
5677
|
-
}
|
|
5678
|
-
|
|
5679
|
-
if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
|
|
5680
|
-
push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
|
|
5681
|
-
}
|
|
5682
|
-
|
|
5683
|
-
// rebuild the output if we had to backtrack at any point
|
|
5684
|
-
if (state.backtrack === true) {
|
|
5685
|
-
state.output = '';
|
|
5686
|
-
|
|
5687
|
-
for (const token of state.tokens) {
|
|
5688
|
-
state.output += token.output != null ? token.output : token.value;
|
|
5689
|
-
|
|
5690
|
-
if (token.suffix) {
|
|
5691
|
-
state.output += token.suffix;
|
|
5692
|
-
}
|
|
5693
|
-
}
|
|
5694
|
-
}
|
|
5695
|
-
|
|
5696
|
-
return state;
|
|
5697
|
-
};
|
|
5698
|
-
|
|
5699
|
-
/**
|
|
5700
|
-
* Fast paths for creating regular expressions for common glob patterns.
|
|
5701
|
-
* This can significantly speed up processing and has very little downside
|
|
5702
|
-
* impact when none of the fast paths match.
|
|
5703
|
-
*/
|
|
5704
|
-
|
|
5705
|
-
parse.fastpaths = (input, options) => {
|
|
5706
|
-
const opts = { ...options };
|
|
5707
|
-
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
5708
|
-
const len = input.length;
|
|
5709
|
-
if (len > max) {
|
|
5710
|
-
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
5711
|
-
}
|
|
5712
|
-
|
|
5713
|
-
input = REPLACEMENTS[input] || input;
|
|
5714
|
-
const win32 = utils.isWindows(options);
|
|
5715
|
-
|
|
5716
|
-
// create constants based on platform, for windows or posix
|
|
5717
|
-
const {
|
|
5718
|
-
DOT_LITERAL,
|
|
5719
|
-
SLASH_LITERAL,
|
|
5720
|
-
ONE_CHAR,
|
|
5721
|
-
DOTS_SLASH,
|
|
5722
|
-
NO_DOT,
|
|
5723
|
-
NO_DOTS,
|
|
5724
|
-
NO_DOTS_SLASH,
|
|
5725
|
-
STAR,
|
|
5726
|
-
START_ANCHOR
|
|
5727
|
-
} = constants.globChars(win32);
|
|
5728
|
-
|
|
5729
|
-
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
5730
|
-
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
5731
|
-
const capture = opts.capture ? '' : '?:';
|
|
5732
|
-
const state = { negated: false, prefix: '' };
|
|
5733
|
-
let star = opts.bash === true ? '.*?' : STAR;
|
|
5734
|
-
|
|
5735
|
-
if (opts.capture) {
|
|
5736
|
-
star = `(${star})`;
|
|
5737
|
-
}
|
|
5738
|
-
|
|
5739
|
-
const globstar = opts => {
|
|
5740
|
-
if (opts.noglobstar === true) return star;
|
|
5741
|
-
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
5742
|
-
};
|
|
5743
|
-
|
|
5744
|
-
const create = str => {
|
|
5745
|
-
switch (str) {
|
|
5746
|
-
case '*':
|
|
5747
|
-
return `${nodot}${ONE_CHAR}${star}`;
|
|
5748
|
-
|
|
5749
|
-
case '.*':
|
|
5750
|
-
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5751
|
-
|
|
5752
|
-
case '*.*':
|
|
5753
|
-
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5754
|
-
|
|
5755
|
-
case '*/*':
|
|
5756
|
-
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
5757
|
-
|
|
5758
|
-
case '**':
|
|
5759
|
-
return nodot + globstar(opts);
|
|
5760
|
-
|
|
5761
|
-
case '**/*':
|
|
5762
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
5763
|
-
|
|
5764
|
-
case '**/*.*':
|
|
5765
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5766
|
-
|
|
5767
|
-
case '**/.*':
|
|
5768
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5769
|
-
|
|
5770
|
-
default: {
|
|
5771
|
-
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
5772
|
-
if (!match) return;
|
|
5773
|
-
|
|
5774
|
-
const source = create(match[1]);
|
|
5775
|
-
if (!source) return;
|
|
5776
|
-
|
|
5777
|
-
return source + DOT_LITERAL + match[2];
|
|
5778
|
-
}
|
|
5779
|
-
}
|
|
5780
|
-
};
|
|
5781
|
-
|
|
5782
|
-
const output = utils.removePrefix(input, state);
|
|
5783
|
-
let source = create(output);
|
|
5784
|
-
|
|
5785
|
-
if (source && opts.strictSlashes !== true) {
|
|
5786
|
-
source += `${SLASH_LITERAL}?`;
|
|
5787
|
-
}
|
|
5788
|
-
|
|
5789
|
-
return source;
|
|
5790
|
-
};
|
|
5791
|
-
|
|
5792
|
-
parse_1 = parse;
|
|
5793
|
-
return parse_1;
|
|
5794
|
-
}
|
|
5795
|
-
|
|
5796
|
-
var picomatch_1;
|
|
5797
|
-
var hasRequiredPicomatch$1;
|
|
5798
|
-
|
|
5799
|
-
function requirePicomatch$1 () {
|
|
5800
|
-
if (hasRequiredPicomatch$1) return picomatch_1;
|
|
5801
|
-
hasRequiredPicomatch$1 = 1;
|
|
5802
|
-
|
|
5803
|
-
const path = require$$0$1;
|
|
5804
|
-
const scan = requireScan();
|
|
5805
|
-
const parse = requireParse();
|
|
5806
|
-
const utils = requireUtils();
|
|
5807
|
-
const constants = requireConstants();
|
|
5808
|
-
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
5809
|
-
|
|
5810
|
-
/**
|
|
5811
|
-
* Creates a matcher function from one or more glob patterns. The
|
|
5812
|
-
* returned function takes a string to match as its first argument,
|
|
5813
|
-
* and returns true if the string is a match. The returned matcher
|
|
5814
|
-
* function also takes a boolean as the second argument that, when true,
|
|
5815
|
-
* returns an object with additional information.
|
|
5816
|
-
*
|
|
5817
|
-
* ```js
|
|
5818
|
-
* const picomatch = require('picomatch');
|
|
5819
|
-
* // picomatch(glob[, options]);
|
|
5820
|
-
*
|
|
5821
|
-
* const isMatch = picomatch('*.!(*a)');
|
|
5822
|
-
* console.log(isMatch('a.a')); //=> false
|
|
5823
|
-
* console.log(isMatch('a.b')); //=> true
|
|
5824
|
-
* ```
|
|
5825
|
-
* @name picomatch
|
|
5826
|
-
* @param {String|Array} `globs` One or more glob patterns.
|
|
5827
|
-
* @param {Object=} `options`
|
|
5828
|
-
* @return {Function=} Returns a matcher function.
|
|
5829
|
-
* @api public
|
|
5830
|
-
*/
|
|
5831
|
-
|
|
5832
|
-
const picomatch = (glob, options, returnState = false) => {
|
|
5833
|
-
if (Array.isArray(glob)) {
|
|
5834
|
-
const fns = glob.map(input => picomatch(input, options, returnState));
|
|
5835
|
-
const arrayMatcher = str => {
|
|
5836
|
-
for (const isMatch of fns) {
|
|
5837
|
-
const state = isMatch(str);
|
|
5838
|
-
if (state) return state;
|
|
5839
|
-
}
|
|
5840
|
-
return false;
|
|
5841
|
-
};
|
|
5842
|
-
return arrayMatcher;
|
|
5843
|
-
}
|
|
5844
|
-
|
|
5845
|
-
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
5846
|
-
|
|
5847
|
-
if (glob === '' || (typeof glob !== 'string' && !isState)) {
|
|
5848
|
-
throw new TypeError('Expected pattern to be a non-empty string');
|
|
5849
|
-
}
|
|
5850
|
-
|
|
5851
|
-
const opts = options || {};
|
|
5852
|
-
const posix = utils.isWindows(options);
|
|
5853
|
-
const regex = isState
|
|
5854
|
-
? picomatch.compileRe(glob, options)
|
|
5855
|
-
: picomatch.makeRe(glob, options, false, true);
|
|
5856
|
-
|
|
5857
|
-
const state = regex.state;
|
|
5858
|
-
delete regex.state;
|
|
5859
|
-
|
|
5860
|
-
let isIgnored = () => false;
|
|
5861
|
-
if (opts.ignore) {
|
|
5862
|
-
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
5863
|
-
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
5864
|
-
}
|
|
5865
|
-
|
|
5866
|
-
const matcher = (input, returnObject = false) => {
|
|
5867
|
-
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
|
5868
|
-
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
5869
|
-
|
|
5870
|
-
if (typeof opts.onResult === 'function') {
|
|
5871
|
-
opts.onResult(result);
|
|
5872
|
-
}
|
|
5873
|
-
|
|
5874
|
-
if (isMatch === false) {
|
|
5875
|
-
result.isMatch = false;
|
|
5876
|
-
return returnObject ? result : false;
|
|
5877
|
-
}
|
|
5878
|
-
|
|
5879
|
-
if (isIgnored(input)) {
|
|
5880
|
-
if (typeof opts.onIgnore === 'function') {
|
|
5881
|
-
opts.onIgnore(result);
|
|
5882
|
-
}
|
|
5883
|
-
result.isMatch = false;
|
|
5884
|
-
return returnObject ? result : false;
|
|
5885
|
-
}
|
|
5886
|
-
|
|
5887
|
-
if (typeof opts.onMatch === 'function') {
|
|
5888
|
-
opts.onMatch(result);
|
|
5889
|
-
}
|
|
5890
|
-
return returnObject ? result : true;
|
|
5891
|
-
};
|
|
5892
|
-
|
|
5893
|
-
if (returnState) {
|
|
5894
|
-
matcher.state = state;
|
|
5895
|
-
}
|
|
5896
|
-
|
|
5897
|
-
return matcher;
|
|
5898
|
-
};
|
|
5899
|
-
|
|
5900
|
-
/**
|
|
5901
|
-
* Test `input` with the given `regex`. This is used by the main
|
|
5902
|
-
* `picomatch()` function to test the input string.
|
|
5903
|
-
*
|
|
5904
|
-
* ```js
|
|
5905
|
-
* const picomatch = require('picomatch');
|
|
5906
|
-
* // picomatch.test(input, regex[, options]);
|
|
5907
|
-
*
|
|
5908
|
-
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
5909
|
-
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
5910
|
-
* ```
|
|
5911
|
-
* @param {String} `input` String to test.
|
|
5912
|
-
* @param {RegExp} `regex`
|
|
5913
|
-
* @return {Object} Returns an object with matching info.
|
|
5914
|
-
* @api public
|
|
5915
|
-
*/
|
|
5916
|
-
|
|
5917
|
-
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
5918
|
-
if (typeof input !== 'string') {
|
|
5919
|
-
throw new TypeError('Expected input to be a string');
|
|
5920
|
-
}
|
|
5921
|
-
|
|
5922
|
-
if (input === '') {
|
|
5923
|
-
return { isMatch: false, output: '' };
|
|
5924
|
-
}
|
|
5925
|
-
|
|
5926
|
-
const opts = options || {};
|
|
5927
|
-
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
5928
|
-
let match = input === glob;
|
|
5929
|
-
let output = (match && format) ? format(input) : input;
|
|
5930
|
-
|
|
5931
|
-
if (match === false) {
|
|
5932
|
-
output = format ? format(input) : input;
|
|
5933
|
-
match = output === glob;
|
|
5934
|
-
}
|
|
5935
|
-
|
|
5936
|
-
if (match === false || opts.capture === true) {
|
|
5937
|
-
if (opts.matchBase === true || opts.basename === true) {
|
|
5938
|
-
match = picomatch.matchBase(input, regex, options, posix);
|
|
5939
|
-
} else {
|
|
5940
|
-
match = regex.exec(output);
|
|
5941
|
-
}
|
|
5942
|
-
}
|
|
5943
|
-
|
|
5944
|
-
return { isMatch: Boolean(match), match, output };
|
|
5945
|
-
};
|
|
5946
|
-
|
|
5947
|
-
/**
|
|
5948
|
-
* Match the basename of a filepath.
|
|
5949
|
-
*
|
|
5950
|
-
* ```js
|
|
5951
|
-
* const picomatch = require('picomatch');
|
|
5952
|
-
* // picomatch.matchBase(input, glob[, options]);
|
|
5953
|
-
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
5954
|
-
* ```
|
|
5955
|
-
* @param {String} `input` String to test.
|
|
5956
|
-
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
5957
|
-
* @return {Boolean}
|
|
5958
|
-
* @api public
|
|
5959
|
-
*/
|
|
5960
|
-
|
|
5961
|
-
picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
|
|
5962
|
-
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
|
5963
|
-
return regex.test(path.basename(input));
|
|
5964
|
-
};
|
|
5965
|
-
|
|
5966
|
-
/**
|
|
5967
|
-
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
5968
|
-
*
|
|
5969
|
-
* ```js
|
|
5970
|
-
* const picomatch = require('picomatch');
|
|
5971
|
-
* // picomatch.isMatch(string, patterns[, options]);
|
|
5972
|
-
*
|
|
5973
|
-
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
5974
|
-
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
5975
|
-
* ```
|
|
5976
|
-
* @param {String|Array} str The string to test.
|
|
5977
|
-
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
5978
|
-
* @param {Object} [options] See available [options](#options).
|
|
5979
|
-
* @return {Boolean} Returns true if any patterns match `str`
|
|
5980
|
-
* @api public
|
|
5981
|
-
*/
|
|
5982
|
-
|
|
5983
|
-
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
5984
|
-
|
|
5985
|
-
/**
|
|
5986
|
-
* Parse a glob pattern to create the source string for a regular
|
|
5987
|
-
* expression.
|
|
5988
|
-
*
|
|
5989
|
-
* ```js
|
|
5990
|
-
* const picomatch = require('picomatch');
|
|
5991
|
-
* const result = picomatch.parse(pattern[, options]);
|
|
5992
|
-
* ```
|
|
5993
|
-
* @param {String} `pattern`
|
|
5994
|
-
* @param {Object} `options`
|
|
5995
|
-
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
5996
|
-
* @api public
|
|
5997
|
-
*/
|
|
5998
|
-
|
|
5999
|
-
picomatch.parse = (pattern, options) => {
|
|
6000
|
-
if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
|
|
6001
|
-
return parse(pattern, { ...options, fastpaths: false });
|
|
6002
|
-
};
|
|
6003
|
-
|
|
6004
|
-
/**
|
|
6005
|
-
* Scan a glob pattern to separate the pattern into segments.
|
|
6006
|
-
*
|
|
6007
|
-
* ```js
|
|
6008
|
-
* const picomatch = require('picomatch');
|
|
6009
|
-
* // picomatch.scan(input[, options]);
|
|
6010
|
-
*
|
|
6011
|
-
* const result = picomatch.scan('!./foo/*.js');
|
|
6012
|
-
* console.log(result);
|
|
6013
|
-
* { prefix: '!./',
|
|
6014
|
-
* input: '!./foo/*.js',
|
|
6015
|
-
* start: 3,
|
|
6016
|
-
* base: 'foo',
|
|
6017
|
-
* glob: '*.js',
|
|
6018
|
-
* isBrace: false,
|
|
6019
|
-
* isBracket: false,
|
|
6020
|
-
* isGlob: true,
|
|
6021
|
-
* isExtglob: false,
|
|
6022
|
-
* isGlobstar: false,
|
|
6023
|
-
* negated: true }
|
|
6024
|
-
* ```
|
|
6025
|
-
* @param {String} `input` Glob pattern to scan.
|
|
6026
|
-
* @param {Object} `options`
|
|
6027
|
-
* @return {Object} Returns an object with
|
|
6028
|
-
* @api public
|
|
6029
|
-
*/
|
|
6030
|
-
|
|
6031
|
-
picomatch.scan = (input, options) => scan(input, options);
|
|
6032
|
-
|
|
6033
|
-
/**
|
|
6034
|
-
* Compile a regular expression from the `state` object returned by the
|
|
6035
|
-
* [parse()](#parse) method.
|
|
6036
|
-
*
|
|
6037
|
-
* @param {Object} `state`
|
|
6038
|
-
* @param {Object} `options`
|
|
6039
|
-
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
6040
|
-
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
6041
|
-
* @return {RegExp}
|
|
6042
|
-
* @api public
|
|
6043
|
-
*/
|
|
6044
|
-
|
|
6045
|
-
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
6046
|
-
if (returnOutput === true) {
|
|
6047
|
-
return state.output;
|
|
6048
|
-
}
|
|
6049
|
-
|
|
6050
|
-
const opts = options || {};
|
|
6051
|
-
const prepend = opts.contains ? '' : '^';
|
|
6052
|
-
const append = opts.contains ? '' : '$';
|
|
6053
|
-
|
|
6054
|
-
let source = `${prepend}(?:${state.output})${append}`;
|
|
6055
|
-
if (state && state.negated === true) {
|
|
6056
|
-
source = `^(?!${source}).*$`;
|
|
6057
|
-
}
|
|
6058
|
-
|
|
6059
|
-
const regex = picomatch.toRegex(source, options);
|
|
6060
|
-
if (returnState === true) {
|
|
6061
|
-
regex.state = state;
|
|
6062
|
-
}
|
|
6063
|
-
|
|
6064
|
-
return regex;
|
|
6065
|
-
};
|
|
6066
|
-
|
|
6067
|
-
/**
|
|
6068
|
-
* Create a regular expression from a parsed glob pattern.
|
|
6069
|
-
*
|
|
6070
|
-
* ```js
|
|
6071
|
-
* const picomatch = require('picomatch');
|
|
6072
|
-
* const state = picomatch.parse('*.js');
|
|
6073
|
-
* // picomatch.compileRe(state[, options]);
|
|
6074
|
-
*
|
|
6075
|
-
* console.log(picomatch.compileRe(state));
|
|
6076
|
-
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
6077
|
-
* ```
|
|
6078
|
-
* @param {String} `state` The object returned from the `.parse` method.
|
|
6079
|
-
* @param {Object} `options`
|
|
6080
|
-
* @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.
|
|
6081
|
-
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
6082
|
-
* @return {RegExp} Returns a regex created from the given pattern.
|
|
6083
|
-
* @api public
|
|
6084
|
-
*/
|
|
6085
|
-
|
|
6086
|
-
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
6087
|
-
if (!input || typeof input !== 'string') {
|
|
6088
|
-
throw new TypeError('Expected a non-empty string');
|
|
6089
|
-
}
|
|
6090
|
-
|
|
6091
|
-
let parsed = { negated: false, fastpaths: true };
|
|
6092
|
-
|
|
6093
|
-
if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
|
|
6094
|
-
parsed.output = parse.fastpaths(input, options);
|
|
6095
|
-
}
|
|
6096
|
-
|
|
6097
|
-
if (!parsed.output) {
|
|
6098
|
-
parsed = parse(input, options);
|
|
6099
|
-
}
|
|
6100
|
-
|
|
6101
|
-
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
6102
|
-
};
|
|
6103
|
-
|
|
6104
|
-
/**
|
|
6105
|
-
* Create a regular expression from the given regex source string.
|
|
6106
|
-
*
|
|
6107
|
-
* ```js
|
|
6108
|
-
* const picomatch = require('picomatch');
|
|
6109
|
-
* // picomatch.toRegex(source[, options]);
|
|
6110
|
-
*
|
|
6111
|
-
* const { output } = picomatch.parse('*.js');
|
|
6112
|
-
* console.log(picomatch.toRegex(output));
|
|
6113
|
-
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
6114
|
-
* ```
|
|
6115
|
-
* @param {String} `source` Regular expression source string.
|
|
6116
|
-
* @param {Object} `options`
|
|
6117
|
-
* @return {RegExp}
|
|
6118
|
-
* @api public
|
|
6119
|
-
*/
|
|
6120
|
-
|
|
6121
|
-
picomatch.toRegex = (source, options) => {
|
|
6122
|
-
try {
|
|
6123
|
-
const opts = options || {};
|
|
6124
|
-
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
|
6125
|
-
} catch (err) {
|
|
6126
|
-
if (options && options.debug === true) throw err;
|
|
6127
|
-
return /$^/;
|
|
6128
|
-
}
|
|
6129
|
-
};
|
|
6130
|
-
|
|
6131
|
-
/**
|
|
6132
|
-
* Picomatch constants.
|
|
6133
|
-
* @return {Object}
|
|
6134
|
-
*/
|
|
6135
|
-
|
|
6136
|
-
picomatch.constants = constants;
|
|
6137
|
-
|
|
6138
|
-
/**
|
|
6139
|
-
* Expose "picomatch"
|
|
6140
|
-
*/
|
|
6141
|
-
|
|
6142
|
-
picomatch_1 = picomatch;
|
|
6143
|
-
return picomatch_1;
|
|
6144
|
-
}
|
|
6145
|
-
|
|
6146
|
-
var picomatch;
|
|
6147
|
-
var hasRequiredPicomatch;
|
|
6148
|
-
|
|
6149
|
-
function requirePicomatch () {
|
|
6150
|
-
if (hasRequiredPicomatch) return picomatch;
|
|
6151
|
-
hasRequiredPicomatch = 1;
|
|
6152
|
-
|
|
6153
|
-
picomatch = requirePicomatch$1();
|
|
6154
|
-
return picomatch;
|
|
6155
|
-
}
|
|
6156
|
-
|
|
6157
|
-
var micromatch_1;
|
|
6158
|
-
var hasRequiredMicromatch;
|
|
6159
|
-
|
|
6160
|
-
function requireMicromatch () {
|
|
6161
|
-
if (hasRequiredMicromatch) return micromatch_1;
|
|
6162
|
-
hasRequiredMicromatch = 1;
|
|
6163
|
-
|
|
6164
|
-
const util = require$$0;
|
|
6165
|
-
const braces = requireBraces();
|
|
6166
|
-
const picomatch = requirePicomatch();
|
|
6167
|
-
const utils = requireUtils();
|
|
6168
|
-
|
|
6169
|
-
const isEmptyString = v => v === '' || v === './';
|
|
6170
|
-
const hasBraces = v => {
|
|
6171
|
-
const index = v.indexOf('{');
|
|
6172
|
-
return index > -1 && v.indexOf('}', index) > -1;
|
|
6173
|
-
};
|
|
6174
|
-
|
|
6175
|
-
/**
|
|
6176
|
-
* Returns an array of strings that match one or more glob patterns.
|
|
6177
|
-
*
|
|
6178
|
-
* ```js
|
|
6179
|
-
* const mm = require('micromatch');
|
|
6180
|
-
* // mm(list, patterns[, options]);
|
|
6181
|
-
*
|
|
6182
|
-
* console.log(mm(['a.js', 'a.txt'], ['*.js']));
|
|
6183
|
-
* //=> [ 'a.js' ]
|
|
6184
|
-
* ```
|
|
6185
|
-
* @param {String|Array<string>} `list` List of strings to match.
|
|
6186
|
-
* @param {String|Array<string>} `patterns` One or more glob patterns to use for matching.
|
|
6187
|
-
* @param {Object} `options` See available [options](#options)
|
|
6188
|
-
* @return {Array} Returns an array of matches
|
|
6189
|
-
* @summary false
|
|
6190
|
-
* @api public
|
|
6191
|
-
*/
|
|
6192
|
-
|
|
6193
|
-
const micromatch = (list, patterns, options) => {
|
|
6194
|
-
patterns = [].concat(patterns);
|
|
6195
|
-
list = [].concat(list);
|
|
6196
|
-
|
|
6197
|
-
let omit = new Set();
|
|
6198
|
-
let keep = new Set();
|
|
6199
|
-
let items = new Set();
|
|
6200
|
-
let negatives = 0;
|
|
6201
|
-
|
|
6202
|
-
let onResult = state => {
|
|
6203
|
-
items.add(state.output);
|
|
6204
|
-
if (options && options.onResult) {
|
|
6205
|
-
options.onResult(state);
|
|
6206
|
-
}
|
|
6207
|
-
};
|
|
6208
|
-
|
|
6209
|
-
for (let i = 0; i < patterns.length; i++) {
|
|
6210
|
-
let isMatch = picomatch(String(patterns[i]), { ...options, onResult }, true);
|
|
6211
|
-
let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
|
|
6212
|
-
if (negated) negatives++;
|
|
6213
|
-
|
|
6214
|
-
for (let item of list) {
|
|
6215
|
-
let matched = isMatch(item, true);
|
|
6216
|
-
|
|
6217
|
-
let match = negated ? !matched.isMatch : matched.isMatch;
|
|
6218
|
-
if (!match) continue;
|
|
6219
|
-
|
|
6220
|
-
if (negated) {
|
|
6221
|
-
omit.add(matched.output);
|
|
6222
|
-
} else {
|
|
6223
|
-
omit.delete(matched.output);
|
|
6224
|
-
keep.add(matched.output);
|
|
6225
|
-
}
|
|
6226
|
-
}
|
|
6227
|
-
}
|
|
6228
|
-
|
|
6229
|
-
let result = negatives === patterns.length ? [...items] : [...keep];
|
|
6230
|
-
let matches = result.filter(item => !omit.has(item));
|
|
6231
|
-
|
|
6232
|
-
if (options && matches.length === 0) {
|
|
6233
|
-
if (options.failglob === true) {
|
|
6234
|
-
throw new Error(`No matches found for "${patterns.join(', ')}"`);
|
|
6235
|
-
}
|
|
6236
|
-
|
|
6237
|
-
if (options.nonull === true || options.nullglob === true) {
|
|
6238
|
-
return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
|
|
6239
|
-
}
|
|
6240
|
-
}
|
|
6241
|
-
|
|
6242
|
-
return matches;
|
|
6243
|
-
};
|
|
6244
|
-
|
|
6245
|
-
/**
|
|
6246
|
-
* Backwards compatibility
|
|
6247
|
-
*/
|
|
6248
|
-
|
|
6249
|
-
micromatch.match = micromatch;
|
|
6250
|
-
|
|
6251
|
-
/**
|
|
6252
|
-
* Returns a matcher function from the given glob `pattern` and `options`.
|
|
6253
|
-
* The returned function takes a string to match as its only argument and returns
|
|
6254
|
-
* true if the string is a match.
|
|
6255
|
-
*
|
|
6256
|
-
* ```js
|
|
6257
|
-
* const mm = require('micromatch');
|
|
6258
|
-
* // mm.matcher(pattern[, options]);
|
|
6259
|
-
*
|
|
6260
|
-
* const isMatch = mm.matcher('*.!(*a)');
|
|
6261
|
-
* console.log(isMatch('a.a')); //=> false
|
|
6262
|
-
* console.log(isMatch('a.b')); //=> true
|
|
6263
|
-
* ```
|
|
6264
|
-
* @param {String} `pattern` Glob pattern
|
|
6265
|
-
* @param {Object} `options`
|
|
6266
|
-
* @return {Function} Returns a matcher function.
|
|
6267
|
-
* @api public
|
|
6268
|
-
*/
|
|
6269
|
-
|
|
6270
|
-
micromatch.matcher = (pattern, options) => picomatch(pattern, options);
|
|
6271
|
-
|
|
6272
|
-
/**
|
|
6273
|
-
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
6274
|
-
*
|
|
6275
|
-
* ```js
|
|
6276
|
-
* const mm = require('micromatch');
|
|
6277
|
-
* // mm.isMatch(string, patterns[, options]);
|
|
6278
|
-
*
|
|
6279
|
-
* console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
6280
|
-
* console.log(mm.isMatch('a.a', 'b.*')); //=> false
|
|
6281
|
-
* ```
|
|
6282
|
-
* @param {String} `str` The string to test.
|
|
6283
|
-
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
|
|
6284
|
-
* @param {Object} `[options]` See available [options](#options).
|
|
6285
|
-
* @return {Boolean} Returns true if any patterns match `str`
|
|
6286
|
-
* @api public
|
|
6287
|
-
*/
|
|
6288
|
-
|
|
6289
|
-
micromatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
6290
|
-
|
|
6291
|
-
/**
|
|
6292
|
-
* Backwards compatibility
|
|
6293
|
-
*/
|
|
6294
|
-
|
|
6295
|
-
micromatch.any = micromatch.isMatch;
|
|
6296
|
-
|
|
6297
|
-
/**
|
|
6298
|
-
* Returns a list of strings that _**do not match any**_ of the given `patterns`.
|
|
6299
|
-
*
|
|
6300
|
-
* ```js
|
|
6301
|
-
* const mm = require('micromatch');
|
|
6302
|
-
* // mm.not(list, patterns[, options]);
|
|
6303
|
-
*
|
|
6304
|
-
* console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
|
|
6305
|
-
* //=> ['b.b', 'c.c']
|
|
6306
|
-
* ```
|
|
6307
|
-
* @param {Array} `list` Array of strings to match.
|
|
6308
|
-
* @param {String|Array} `patterns` One or more glob pattern to use for matching.
|
|
6309
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6310
|
-
* @return {Array} Returns an array of strings that **do not match** the given patterns.
|
|
6311
|
-
* @api public
|
|
6312
|
-
*/
|
|
6313
|
-
|
|
6314
|
-
micromatch.not = (list, patterns, options = {}) => {
|
|
6315
|
-
patterns = [].concat(patterns).map(String);
|
|
6316
|
-
let result = new Set();
|
|
6317
|
-
let items = [];
|
|
6318
|
-
|
|
6319
|
-
let onResult = state => {
|
|
6320
|
-
if (options.onResult) options.onResult(state);
|
|
6321
|
-
items.push(state.output);
|
|
6322
|
-
};
|
|
6323
|
-
|
|
6324
|
-
let matches = new Set(micromatch(list, patterns, { ...options, onResult }));
|
|
6325
|
-
|
|
6326
|
-
for (let item of items) {
|
|
6327
|
-
if (!matches.has(item)) {
|
|
6328
|
-
result.add(item);
|
|
6329
|
-
}
|
|
6330
|
-
}
|
|
6331
|
-
return [...result];
|
|
6332
|
-
};
|
|
6333
|
-
|
|
6334
|
-
/**
|
|
6335
|
-
* Returns true if the given `string` contains the given pattern. Similar
|
|
6336
|
-
* to [.isMatch](#isMatch) but the pattern can match any part of the string.
|
|
6337
|
-
*
|
|
6338
|
-
* ```js
|
|
6339
|
-
* var mm = require('micromatch');
|
|
6340
|
-
* // mm.contains(string, pattern[, options]);
|
|
6341
|
-
*
|
|
6342
|
-
* console.log(mm.contains('aa/bb/cc', '*b'));
|
|
6343
|
-
* //=> true
|
|
6344
|
-
* console.log(mm.contains('aa/bb/cc', '*d'));
|
|
6345
|
-
* //=> false
|
|
6346
|
-
* ```
|
|
6347
|
-
* @param {String} `str` The string to match.
|
|
6348
|
-
* @param {String|Array} `patterns` Glob pattern to use for matching.
|
|
6349
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6350
|
-
* @return {Boolean} Returns true if any of the patterns matches any part of `str`.
|
|
6351
|
-
* @api public
|
|
6352
|
-
*/
|
|
6353
|
-
|
|
6354
|
-
micromatch.contains = (str, pattern, options) => {
|
|
6355
|
-
if (typeof str !== 'string') {
|
|
6356
|
-
throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
|
|
6357
|
-
}
|
|
6358
|
-
|
|
6359
|
-
if (Array.isArray(pattern)) {
|
|
6360
|
-
return pattern.some(p => micromatch.contains(str, p, options));
|
|
6361
|
-
}
|
|
6362
|
-
|
|
6363
|
-
if (typeof pattern === 'string') {
|
|
6364
|
-
if (isEmptyString(str) || isEmptyString(pattern)) {
|
|
6365
|
-
return false;
|
|
6366
|
-
}
|
|
6367
|
-
|
|
6368
|
-
if (str.includes(pattern) || (str.startsWith('./') && str.slice(2).includes(pattern))) {
|
|
6369
|
-
return true;
|
|
6370
|
-
}
|
|
6371
|
-
}
|
|
6372
|
-
|
|
6373
|
-
return micromatch.isMatch(str, pattern, { ...options, contains: true });
|
|
6374
|
-
};
|
|
6375
|
-
|
|
6376
|
-
/**
|
|
6377
|
-
* Filter the keys of the given object with the given `glob` pattern
|
|
6378
|
-
* and `options`. Does not attempt to match nested keys. If you need this feature,
|
|
6379
|
-
* use [glob-object][] instead.
|
|
6380
|
-
*
|
|
6381
|
-
* ```js
|
|
6382
|
-
* const mm = require('micromatch');
|
|
6383
|
-
* // mm.matchKeys(object, patterns[, options]);
|
|
6384
|
-
*
|
|
6385
|
-
* const obj = { aa: 'a', ab: 'b', ac: 'c' };
|
|
6386
|
-
* console.log(mm.matchKeys(obj, '*b'));
|
|
6387
|
-
* //=> { ab: 'b' }
|
|
6388
|
-
* ```
|
|
6389
|
-
* @param {Object} `object` The object with keys to filter.
|
|
6390
|
-
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
|
|
6391
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6392
|
-
* @return {Object} Returns an object with only keys that match the given patterns.
|
|
6393
|
-
* @api public
|
|
6394
|
-
*/
|
|
6395
|
-
|
|
6396
|
-
micromatch.matchKeys = (obj, patterns, options) => {
|
|
6397
|
-
if (!utils.isObject(obj)) {
|
|
6398
|
-
throw new TypeError('Expected the first argument to be an object');
|
|
6399
|
-
}
|
|
6400
|
-
let keys = micromatch(Object.keys(obj), patterns, options);
|
|
6401
|
-
let res = {};
|
|
6402
|
-
for (let key of keys) res[key] = obj[key];
|
|
6403
|
-
return res;
|
|
6404
|
-
};
|
|
6405
|
-
|
|
6406
|
-
/**
|
|
6407
|
-
* Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
|
|
6408
|
-
*
|
|
6409
|
-
* ```js
|
|
6410
|
-
* const mm = require('micromatch');
|
|
6411
|
-
* // mm.some(list, patterns[, options]);
|
|
6412
|
-
*
|
|
6413
|
-
* console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
|
|
6414
|
-
* // true
|
|
6415
|
-
* console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
|
|
6416
|
-
* // false
|
|
6417
|
-
* ```
|
|
6418
|
-
* @param {String|Array} `list` The string or array of strings to test. Returns as soon as the first match is found.
|
|
6419
|
-
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
|
|
6420
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6421
|
-
* @return {Boolean} Returns true if any `patterns` matches any of the strings in `list`
|
|
6422
|
-
* @api public
|
|
6423
|
-
*/
|
|
6424
|
-
|
|
6425
|
-
micromatch.some = (list, patterns, options) => {
|
|
6426
|
-
let items = [].concat(list);
|
|
6427
|
-
|
|
6428
|
-
for (let pattern of [].concat(patterns)) {
|
|
6429
|
-
let isMatch = picomatch(String(pattern), options);
|
|
6430
|
-
if (items.some(item => isMatch(item))) {
|
|
6431
|
-
return true;
|
|
6432
|
-
}
|
|
6433
|
-
}
|
|
6434
|
-
return false;
|
|
6435
|
-
};
|
|
6436
|
-
|
|
6437
|
-
/**
|
|
6438
|
-
* Returns true if every string in the given `list` matches
|
|
6439
|
-
* any of the given glob `patterns`.
|
|
6440
|
-
*
|
|
6441
|
-
* ```js
|
|
6442
|
-
* const mm = require('micromatch');
|
|
6443
|
-
* // mm.every(list, patterns[, options]);
|
|
6444
|
-
*
|
|
6445
|
-
* console.log(mm.every('foo.js', ['foo.js']));
|
|
6446
|
-
* // true
|
|
6447
|
-
* console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
|
|
6448
|
-
* // true
|
|
6449
|
-
* console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
|
|
6450
|
-
* // false
|
|
6451
|
-
* console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
|
|
6452
|
-
* // false
|
|
6453
|
-
* ```
|
|
6454
|
-
* @param {String|Array} `list` The string or array of strings to test.
|
|
6455
|
-
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
|
|
6456
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6457
|
-
* @return {Boolean} Returns true if all `patterns` matches all of the strings in `list`
|
|
6458
|
-
* @api public
|
|
6459
|
-
*/
|
|
6460
|
-
|
|
6461
|
-
micromatch.every = (list, patterns, options) => {
|
|
6462
|
-
let items = [].concat(list);
|
|
6463
|
-
|
|
6464
|
-
for (let pattern of [].concat(patterns)) {
|
|
6465
|
-
let isMatch = picomatch(String(pattern), options);
|
|
6466
|
-
if (!items.every(item => isMatch(item))) {
|
|
6467
|
-
return false;
|
|
6468
|
-
}
|
|
6469
|
-
}
|
|
6470
|
-
return true;
|
|
6471
|
-
};
|
|
6472
|
-
|
|
6473
|
-
/**
|
|
6474
|
-
* Returns true if **all** of the given `patterns` match
|
|
6475
|
-
* the specified string.
|
|
6476
|
-
*
|
|
6477
|
-
* ```js
|
|
6478
|
-
* const mm = require('micromatch');
|
|
6479
|
-
* // mm.all(string, patterns[, options]);
|
|
6480
|
-
*
|
|
6481
|
-
* console.log(mm.all('foo.js', ['foo.js']));
|
|
6482
|
-
* // true
|
|
6483
|
-
*
|
|
6484
|
-
* console.log(mm.all('foo.js', ['*.js', '!foo.js']));
|
|
6485
|
-
* // false
|
|
6486
|
-
*
|
|
6487
|
-
* console.log(mm.all('foo.js', ['*.js', 'foo.js']));
|
|
6488
|
-
* // true
|
|
6489
|
-
*
|
|
6490
|
-
* console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
|
|
6491
|
-
* // true
|
|
6492
|
-
* ```
|
|
6493
|
-
* @param {String|Array} `str` The string to test.
|
|
6494
|
-
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
|
|
6495
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6496
|
-
* @return {Boolean} Returns true if any patterns match `str`
|
|
6497
|
-
* @api public
|
|
6498
|
-
*/
|
|
6499
|
-
|
|
6500
|
-
micromatch.all = (str, patterns, options) => {
|
|
6501
|
-
if (typeof str !== 'string') {
|
|
6502
|
-
throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
|
|
6503
|
-
}
|
|
6504
|
-
|
|
6505
|
-
return [].concat(patterns).every(p => picomatch(p, options)(str));
|
|
6506
|
-
};
|
|
6507
|
-
|
|
6508
|
-
/**
|
|
6509
|
-
* Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
|
|
6510
|
-
*
|
|
6511
|
-
* ```js
|
|
6512
|
-
* const mm = require('micromatch');
|
|
6513
|
-
* // mm.capture(pattern, string[, options]);
|
|
6514
|
-
*
|
|
6515
|
-
* console.log(mm.capture('test/*.js', 'test/foo.js'));
|
|
6516
|
-
* //=> ['foo']
|
|
6517
|
-
* console.log(mm.capture('test/*.js', 'foo/bar.css'));
|
|
6518
|
-
* //=> null
|
|
6519
|
-
* ```
|
|
6520
|
-
* @param {String} `glob` Glob pattern to use for matching.
|
|
6521
|
-
* @param {String} `input` String to match
|
|
6522
|
-
* @param {Object} `options` See available [options](#options) for changing how matches are performed
|
|
6523
|
-
* @return {Array|null} Returns an array of captures if the input matches the glob pattern, otherwise `null`.
|
|
6524
|
-
* @api public
|
|
6525
|
-
*/
|
|
6526
|
-
|
|
6527
|
-
micromatch.capture = (glob, input, options) => {
|
|
6528
|
-
let posix = utils.isWindows(options);
|
|
6529
|
-
let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
|
|
6530
|
-
let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);
|
|
6531
|
-
|
|
6532
|
-
if (match) {
|
|
6533
|
-
return match.slice(1).map(v => v === void 0 ? '' : v);
|
|
6534
|
-
}
|
|
6535
|
-
};
|
|
6536
|
-
|
|
6537
|
-
/**
|
|
6538
|
-
* Create a regular expression from the given glob `pattern`.
|
|
6539
|
-
*
|
|
6540
|
-
* ```js
|
|
6541
|
-
* const mm = require('micromatch');
|
|
6542
|
-
* // mm.makeRe(pattern[, options]);
|
|
6543
|
-
*
|
|
6544
|
-
* console.log(mm.makeRe('*.js'));
|
|
6545
|
-
* //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
|
|
6546
|
-
* ```
|
|
6547
|
-
* @param {String} `pattern` A glob pattern to convert to regex.
|
|
6548
|
-
* @param {Object} `options`
|
|
6549
|
-
* @return {RegExp} Returns a regex created from the given pattern.
|
|
6550
|
-
* @api public
|
|
6551
|
-
*/
|
|
6552
|
-
|
|
6553
|
-
micromatch.makeRe = (...args) => picomatch.makeRe(...args);
|
|
6554
|
-
|
|
6555
|
-
/**
|
|
6556
|
-
* Scan a glob pattern to separate the pattern into segments. Used
|
|
6557
|
-
* by the [split](#split) method.
|
|
6558
|
-
*
|
|
6559
|
-
* ```js
|
|
6560
|
-
* const mm = require('micromatch');
|
|
6561
|
-
* const state = mm.scan(pattern[, options]);
|
|
6562
|
-
* ```
|
|
6563
|
-
* @param {String} `pattern`
|
|
6564
|
-
* @param {Object} `options`
|
|
6565
|
-
* @return {Object} Returns an object with
|
|
6566
|
-
* @api public
|
|
6567
|
-
*/
|
|
6568
|
-
|
|
6569
|
-
micromatch.scan = (...args) => picomatch.scan(...args);
|
|
6570
|
-
|
|
6571
|
-
/**
|
|
6572
|
-
* Parse a glob pattern to create the source string for a regular
|
|
6573
|
-
* expression.
|
|
6574
|
-
*
|
|
6575
|
-
* ```js
|
|
6576
|
-
* const mm = require('micromatch');
|
|
6577
|
-
* const state = mm.parse(pattern[, options]);
|
|
6578
|
-
* ```
|
|
6579
|
-
* @param {String} `glob`
|
|
6580
|
-
* @param {Object} `options`
|
|
6581
|
-
* @return {Object} Returns an object with useful properties and output to be used as regex source string.
|
|
6582
|
-
* @api public
|
|
6583
|
-
*/
|
|
6584
|
-
|
|
6585
|
-
micromatch.parse = (patterns, options) => {
|
|
6586
|
-
let res = [];
|
|
6587
|
-
for (let pattern of [].concat(patterns || [])) {
|
|
6588
|
-
for (let str of braces(String(pattern), options)) {
|
|
6589
|
-
res.push(picomatch.parse(str, options));
|
|
6590
|
-
}
|
|
6591
|
-
}
|
|
6592
|
-
return res;
|
|
6593
|
-
};
|
|
6594
|
-
|
|
6595
|
-
/**
|
|
6596
|
-
* Process the given brace `pattern`.
|
|
6597
|
-
*
|
|
6598
|
-
* ```js
|
|
6599
|
-
* const { braces } = require('micromatch');
|
|
6600
|
-
* console.log(braces('foo/{a,b,c}/bar'));
|
|
6601
|
-
* //=> [ 'foo/(a|b|c)/bar' ]
|
|
6602
|
-
*
|
|
6603
|
-
* console.log(braces('foo/{a,b,c}/bar', { expand: true }));
|
|
6604
|
-
* //=> [ 'foo/a/bar', 'foo/b/bar', 'foo/c/bar' ]
|
|
6605
|
-
* ```
|
|
6606
|
-
* @param {String} `pattern` String with brace pattern to process.
|
|
6607
|
-
* @param {Object} `options` Any [options](#options) to change how expansion is performed. See the [braces][] library for all available options.
|
|
6608
|
-
* @return {Array}
|
|
6609
|
-
* @api public
|
|
6610
|
-
*/
|
|
6611
|
-
|
|
6612
|
-
micromatch.braces = (pattern, options) => {
|
|
6613
|
-
if (typeof pattern !== 'string') throw new TypeError('Expected a string');
|
|
6614
|
-
if ((options && options.nobrace === true) || !hasBraces(pattern)) {
|
|
6615
|
-
return [pattern];
|
|
6616
|
-
}
|
|
6617
|
-
return braces(pattern, options);
|
|
6618
|
-
};
|
|
6619
|
-
|
|
6620
|
-
/**
|
|
6621
|
-
* Expand braces
|
|
6622
|
-
*/
|
|
6623
|
-
|
|
6624
|
-
micromatch.braceExpand = (pattern, options) => {
|
|
6625
|
-
if (typeof pattern !== 'string') throw new TypeError('Expected a string');
|
|
6626
|
-
return micromatch.braces(pattern, { ...options, expand: true });
|
|
6627
|
-
};
|
|
6628
|
-
|
|
6629
|
-
/**
|
|
6630
|
-
* Expose micromatch
|
|
6631
|
-
*/
|
|
6632
|
-
|
|
6633
|
-
// exposed for tests
|
|
6634
|
-
micromatch.hasBraces = hasBraces;
|
|
6635
|
-
micromatch_1 = micromatch;
|
|
6636
|
-
return micromatch_1;
|
|
6637
|
-
}
|
|
6638
|
-
|
|
6639
|
-
var micromatchExports = requireMicromatch();
|
|
6640
|
-
var mm = /*@__PURE__*/getDefaultExportFromCjs(micromatchExports);
|
|
6641
|
-
|
|
6642
2513
|
const envsOrder = [
|
|
6643
2514
|
"node",
|
|
6644
2515
|
"jsdom",
|
|
@@ -6646,10 +2517,10 @@ const envsOrder = [
|
|
|
6646
2517
|
"edge-runtime"
|
|
6647
2518
|
];
|
|
6648
2519
|
function getTransformMode(patterns, filename) {
|
|
6649
|
-
if (patterns.web &&
|
|
2520
|
+
if (patterns.web && pm.isMatch(filename, patterns.web)) {
|
|
6650
2521
|
return "web";
|
|
6651
2522
|
}
|
|
6652
|
-
if (patterns.ssr &&
|
|
2523
|
+
if (patterns.ssr && pm.isMatch(filename, patterns.ssr)) {
|
|
6653
2524
|
return "ssr";
|
|
6654
2525
|
}
|
|
6655
2526
|
return undefined;
|
|
@@ -6660,7 +2531,7 @@ async function groupFilesByEnv(files) {
|
|
|
6660
2531
|
let env = code.match(/@(?:vitest|jest)-environment\s+([\w-]+)\b/)?.[1];
|
|
6661
2532
|
if (!env) {
|
|
6662
2533
|
for (const [glob, target] of project.config.environmentMatchGlobs || []) {
|
|
6663
|
-
if (
|
|
2534
|
+
if (pm.isMatch(filepath, glob, { cwd: project.config.root })) {
|
|
6664
2535
|
env = target;
|
|
6665
2536
|
break;
|
|
6666
2537
|
}
|
|
@@ -7132,27 +3003,27 @@ function createThreadsPool(ctx, { execArgv, env }) {
|
|
|
7132
3003
|
};
|
|
7133
3004
|
}
|
|
7134
3005
|
|
|
7135
|
-
function createTypecheckPool(
|
|
3006
|
+
function createTypecheckPool(vitest) {
|
|
7136
3007
|
const promisesMap = new WeakMap();
|
|
7137
3008
|
const rerunTriggered = new WeakSet();
|
|
7138
3009
|
async function onParseEnd(project, { files, sourceErrors }) {
|
|
7139
3010
|
const checker = project.typechecker;
|
|
7140
3011
|
const { packs, events } = checker.getTestPacksAndEvents();
|
|
7141
|
-
await
|
|
3012
|
+
await vitest._testRun.updated(packs, events);
|
|
7142
3013
|
if (!project.config.typecheck.ignoreSourceErrors) {
|
|
7143
|
-
sourceErrors.forEach((error) =>
|
|
3014
|
+
sourceErrors.forEach((error) => vitest.state.catchError(error, "Unhandled Source Error"));
|
|
7144
3015
|
}
|
|
7145
3016
|
const processError = !hasFailed(files) && !sourceErrors.length && checker.getExitCode();
|
|
7146
3017
|
if (processError) {
|
|
7147
3018
|
const error = new Error(checker.getOutput());
|
|
7148
3019
|
error.stack = "";
|
|
7149
|
-
|
|
3020
|
+
vitest.state.catchError(error, "Typecheck Error");
|
|
7150
3021
|
}
|
|
7151
3022
|
promisesMap.get(project)?.resolve();
|
|
7152
3023
|
rerunTriggered.delete(project);
|
|
7153
|
-
if (
|
|
7154
|
-
await
|
|
7155
|
-
await
|
|
3024
|
+
if (vitest.config.watch && !vitest.runningPromise) {
|
|
3025
|
+
await vitest.report("onFinished", files, []);
|
|
3026
|
+
await vitest.report("onWatcherStart", files, [...project.config.typecheck.ignoreSourceErrors ? [] : sourceErrors, ...vitest.state.getUnhandledErrors()]);
|
|
7156
3027
|
}
|
|
7157
3028
|
}
|
|
7158
3029
|
async function createWorkspaceTypechecker(project, files) {
|
|
@@ -7165,27 +3036,26 @@ function createTypecheckPool(ctx) {
|
|
|
7165
3036
|
checker.onParseStart(async () => {
|
|
7166
3037
|
const files = checker.getTestFiles();
|
|
7167
3038
|
for (const file of files) {
|
|
7168
|
-
await
|
|
3039
|
+
await vitest._testRun.enqueued(project, file);
|
|
7169
3040
|
}
|
|
7170
|
-
await
|
|
3041
|
+
await vitest._testRun.collected(project, files);
|
|
7171
3042
|
});
|
|
7172
3043
|
checker.onParseEnd((result) => onParseEnd(project, result));
|
|
7173
3044
|
checker.onWatcherRerun(async () => {
|
|
7174
3045
|
rerunTriggered.add(project);
|
|
7175
|
-
if (!
|
|
7176
|
-
|
|
7177
|
-
await
|
|
3046
|
+
if (!vitest.runningPromise) {
|
|
3047
|
+
vitest.state.clearErrors();
|
|
3048
|
+
await vitest.report("onWatcherRerun", files, "File change detected. Triggering rerun.");
|
|
7178
3049
|
}
|
|
7179
3050
|
await checker.collectTests();
|
|
7180
3051
|
const testFiles = checker.getTestFiles();
|
|
7181
3052
|
for (const file of testFiles) {
|
|
7182
|
-
await
|
|
3053
|
+
await vitest._testRun.enqueued(project, file);
|
|
7183
3054
|
}
|
|
7184
|
-
await
|
|
3055
|
+
await vitest._testRun.collected(project, testFiles);
|
|
7185
3056
|
const { packs, events } = checker.getTestPacksAndEvents();
|
|
7186
|
-
await
|
|
3057
|
+
await vitest._testRun.updated(packs, events);
|
|
7187
3058
|
});
|
|
7188
|
-
await checker.prepare();
|
|
7189
3059
|
return checker;
|
|
7190
3060
|
}
|
|
7191
3061
|
async function startTypechecker(project, files) {
|
|
@@ -7205,10 +3075,7 @@ function createTypecheckPool(ctx) {
|
|
|
7205
3075
|
checker.setFiles(files);
|
|
7206
3076
|
await checker.collectTests();
|
|
7207
3077
|
const testFiles = checker.getTestFiles();
|
|
7208
|
-
|
|
7209
|
-
await ctx._testRun.enqueued(project, file);
|
|
7210
|
-
}
|
|
7211
|
-
await ctx._testRun.collected(project, testFiles);
|
|
3078
|
+
vitest.state.collectFiles(project, testFiles);
|
|
7212
3079
|
}
|
|
7213
3080
|
}
|
|
7214
3081
|
async function runTests(specs) {
|
|
@@ -7234,9 +3101,9 @@ function createTypecheckPool(ctx) {
|
|
|
7234
3101
|
if (project.typechecker && !triggered) {
|
|
7235
3102
|
const testFiles = project.typechecker.getTestFiles();
|
|
7236
3103
|
for (const file of testFiles) {
|
|
7237
|
-
await
|
|
3104
|
+
await vitest._testRun.enqueued(project, file);
|
|
7238
3105
|
}
|
|
7239
|
-
await
|
|
3106
|
+
await vitest._testRun.collected(project, testFiles);
|
|
7240
3107
|
await onParseEnd(project, project.typechecker.getResult());
|
|
7241
3108
|
continue;
|
|
7242
3109
|
}
|
|
@@ -7251,7 +3118,7 @@ function createTypecheckPool(ctx) {
|
|
|
7251
3118
|
runTests,
|
|
7252
3119
|
collectTests,
|
|
7253
3120
|
async close() {
|
|
7254
|
-
const promises =
|
|
3121
|
+
const promises = vitest.projects.map((project) => project.typechecker?.stop());
|
|
7255
3122
|
await Promise.all(promises);
|
|
7256
3123
|
}
|
|
7257
3124
|
};
|
|
@@ -7261,12 +3128,22 @@ function getDefaultThreadsCount(config) {
|
|
|
7261
3128
|
const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
|
|
7262
3129
|
return config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
7263
3130
|
}
|
|
7264
|
-
function getWorkerMemoryLimit(config) {
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
3131
|
+
function getWorkerMemoryLimit(config, pool) {
|
|
3132
|
+
if (pool === "vmForks") {
|
|
3133
|
+
const opts = config.poolOptions?.vmForks ?? {};
|
|
3134
|
+
if (opts.memoryLimit) {
|
|
3135
|
+
return opts.memoryLimit;
|
|
3136
|
+
}
|
|
3137
|
+
const workers = opts.maxForks ?? getDefaultThreadsCount(config);
|
|
3138
|
+
return 1 / workers;
|
|
3139
|
+
} else {
|
|
3140
|
+
const opts = config.poolOptions?.vmThreads ?? {};
|
|
3141
|
+
if (opts.memoryLimit) {
|
|
3142
|
+
return opts.memoryLimit;
|
|
3143
|
+
}
|
|
3144
|
+
const workers = opts.maxThreads ?? getDefaultThreadsCount(config);
|
|
3145
|
+
return 1 / workers;
|
|
7268
3146
|
}
|
|
7269
|
-
return 1 / (config.poolOptions?.vmThreads?.maxThreads ?? getDefaultThreadsCount(config));
|
|
7270
3147
|
}
|
|
7271
3148
|
/**
|
|
7272
3149
|
* Converts a string representing an amount of memory to bytes.
|
|
@@ -7449,7 +3326,7 @@ function createVmForksPool(ctx, { execArgv, env }) {
|
|
|
7449
3326
|
}
|
|
7450
3327
|
function getMemoryLimit$1(config) {
|
|
7451
3328
|
const memory = nodeos.totalmem();
|
|
7452
|
-
const limit = getWorkerMemoryLimit(config);
|
|
3329
|
+
const limit = getWorkerMemoryLimit(config, "vmForks");
|
|
7453
3330
|
if (typeof memory === "number") {
|
|
7454
3331
|
return stringToBytes(limit, config.watch ? memory / 2 : memory);
|
|
7455
3332
|
}
|
|
@@ -7578,7 +3455,7 @@ function createVmThreadsPool(ctx, { execArgv, env }) {
|
|
|
7578
3455
|
}
|
|
7579
3456
|
function getMemoryLimit(config) {
|
|
7580
3457
|
const memory = nodeos.totalmem();
|
|
7581
|
-
const limit = getWorkerMemoryLimit(config);
|
|
3458
|
+
const limit = getWorkerMemoryLimit(config, "vmThreads");
|
|
7582
3459
|
if (typeof memory === "number") {
|
|
7583
3460
|
return stringToBytes(limit, config.watch ? memory / 2 : memory);
|
|
7584
3461
|
}
|
|
@@ -7607,7 +3484,7 @@ function getFilePoolName(project, file) {
|
|
|
7607
3484
|
if (pool === "browser") {
|
|
7608
3485
|
throw new Error("Since Vitest 0.31.0 \"browser\" pool is not supported in \"poolMatchGlobs\". You can create a project to run some of your tests in browser in parallel. Read more: https://vitest.dev/guide/projects");
|
|
7609
3486
|
}
|
|
7610
|
-
if (
|
|
3487
|
+
if (pm.isMatch(file, glob, { cwd: project.config.root })) {
|
|
7611
3488
|
return pool;
|
|
7612
3489
|
}
|
|
7613
3490
|
}
|
|
@@ -7661,6 +3538,7 @@ function createPool(ctx) {
|
|
|
7661
3538
|
options.env[name.toUpperCase()] = options.env[name];
|
|
7662
3539
|
}
|
|
7663
3540
|
}
|
|
3541
|
+
const poolConcurrentPromises = new Map();
|
|
7664
3542
|
const customPools = new Map();
|
|
7665
3543
|
async function resolveCustomPool(filepath) {
|
|
7666
3544
|
if (customPools.has(filepath)) {
|
|
@@ -7680,24 +3558,39 @@ function createPool(ctx) {
|
|
|
7680
3558
|
customPools.set(filepath, poolInstance);
|
|
7681
3559
|
return poolInstance;
|
|
7682
3560
|
}
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
3561
|
+
function getConcurrentPool(pool, fn) {
|
|
3562
|
+
if (poolConcurrentPromises.has(pool)) {
|
|
3563
|
+
return poolConcurrentPromises.get(pool);
|
|
3564
|
+
}
|
|
3565
|
+
const promise = fn().finally(() => {
|
|
3566
|
+
poolConcurrentPromises.delete(pool);
|
|
3567
|
+
});
|
|
3568
|
+
poolConcurrentPromises.set(pool, promise);
|
|
3569
|
+
return promise;
|
|
3570
|
+
}
|
|
3571
|
+
function getCustomPool(pool) {
|
|
3572
|
+
return getConcurrentPool(pool, () => resolveCustomPool(pool));
|
|
3573
|
+
}
|
|
3574
|
+
function getBrowserPool() {
|
|
3575
|
+
return getConcurrentPool("browser", async () => {
|
|
3576
|
+
const { createBrowserPool } = await import('@vitest/browser');
|
|
3577
|
+
return createBrowserPool(ctx);
|
|
3578
|
+
});
|
|
3579
|
+
}
|
|
3580
|
+
const groupedSpecifications = {};
|
|
3581
|
+
const groups = new Set();
|
|
7690
3582
|
const factories = {
|
|
7691
3583
|
vmThreads: () => createVmThreadsPool(ctx, options),
|
|
3584
|
+
vmForks: () => createVmForksPool(ctx, options),
|
|
7692
3585
|
threads: () => createThreadsPool(ctx, options),
|
|
7693
3586
|
forks: () => createForksPool(ctx, options),
|
|
7694
|
-
vmForks: () => createVmForksPool(ctx, options),
|
|
7695
3587
|
typescript: () => createTypecheckPool(ctx)
|
|
7696
3588
|
};
|
|
7697
3589
|
for (const spec of files) {
|
|
7698
|
-
const
|
|
7699
|
-
|
|
7700
|
-
|
|
3590
|
+
const group = spec[0].config.sequence.groupOrder ?? 0;
|
|
3591
|
+
groups.add(group);
|
|
3592
|
+
groupedSpecifications[group] ??= [];
|
|
3593
|
+
groupedSpecifications[group].push(spec);
|
|
7701
3594
|
}
|
|
7702
3595
|
const Sequencer = ctx.config.sequence.sequencer;
|
|
7703
3596
|
const sequencer = new Sequencer(ctx);
|
|
@@ -7707,28 +3600,44 @@ function createPool(ctx) {
|
|
|
7707
3600
|
}
|
|
7708
3601
|
return sequencer.sort(specs);
|
|
7709
3602
|
}
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
const specs = await sortSpecs(files);
|
|
7716
|
-
if (pool in factories) {
|
|
7717
|
-
const factory = factories[pool];
|
|
7718
|
-
pools[pool] ??= factory();
|
|
7719
|
-
return pools[pool][method](specs, invalidate);
|
|
7720
|
-
}
|
|
7721
|
-
if (pool === "browser") {
|
|
7722
|
-
pools[pool] ??= await (async () => {
|
|
7723
|
-
const { createBrowserPool } = await import('@vitest/browser');
|
|
7724
|
-
return createBrowserPool(ctx);
|
|
7725
|
-
})();
|
|
7726
|
-
return pools[pool][method](specs, invalidate);
|
|
3603
|
+
const sortedGroups = Array.from(groups).sort();
|
|
3604
|
+
for (const group of sortedGroups) {
|
|
3605
|
+
const specifications = groupedSpecifications[group];
|
|
3606
|
+
if (!specifications?.length) {
|
|
3607
|
+
continue;
|
|
7727
3608
|
}
|
|
7728
|
-
const
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
3609
|
+
const filesByPool = {
|
|
3610
|
+
forks: [],
|
|
3611
|
+
threads: [],
|
|
3612
|
+
vmThreads: [],
|
|
3613
|
+
vmForks: [],
|
|
3614
|
+
typescript: []
|
|
3615
|
+
};
|
|
3616
|
+
specifications.forEach((specification) => {
|
|
3617
|
+
const pool = specification[2].pool;
|
|
3618
|
+
filesByPool[pool] ??= [];
|
|
3619
|
+
filesByPool[pool].push(specification);
|
|
3620
|
+
});
|
|
3621
|
+
await Promise.all(Object.entries(filesByPool).map(async (entry) => {
|
|
3622
|
+
const [pool, files] = entry;
|
|
3623
|
+
if (!files.length) {
|
|
3624
|
+
return null;
|
|
3625
|
+
}
|
|
3626
|
+
const specs = await sortSpecs(files);
|
|
3627
|
+
if (pool in factories) {
|
|
3628
|
+
const factory = factories[pool];
|
|
3629
|
+
pools[pool] ??= factory();
|
|
3630
|
+
return pools[pool][method](specs, invalidate);
|
|
3631
|
+
}
|
|
3632
|
+
if (pool === "browser") {
|
|
3633
|
+
pools.browser ??= await getBrowserPool();
|
|
3634
|
+
return pools.browser[method](specs, invalidate);
|
|
3635
|
+
}
|
|
3636
|
+
const poolHandler = await getCustomPool(pool);
|
|
3637
|
+
pools[poolHandler.name] ??= poolHandler;
|
|
3638
|
+
return poolHandler[method](specs, invalidate);
|
|
3639
|
+
}));
|
|
3640
|
+
}
|
|
7732
3641
|
}
|
|
7733
3642
|
return {
|
|
7734
3643
|
name: "default",
|
|
@@ -8261,6 +4170,7 @@ function resolveConfig$1(vitest, options, viteConfig) {
|
|
|
8261
4170
|
if (!resolved.sequence?.sequencer) {
|
|
8262
4171
|
resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
|
|
8263
4172
|
}
|
|
4173
|
+
resolved.sequence.groupOrder ??= 0;
|
|
8264
4174
|
resolved.sequence.hooks ??= "stack";
|
|
8265
4175
|
if (resolved.sequence.sequencer === RandomSequencer) {
|
|
8266
4176
|
resolved.sequence.seed ??= Date.now();
|
|
@@ -8544,7 +4454,8 @@ class BaseCoverageProvider {
|
|
|
8544
4454
|
const glob = key;
|
|
8545
4455
|
const globThresholds = resolveGlobThresholds(this.options.thresholds[glob]);
|
|
8546
4456
|
const globCoverageMap = this.createCoverageMap();
|
|
8547
|
-
const
|
|
4457
|
+
const matcher = pm(glob);
|
|
4458
|
+
const matchingFiles = files.filter((file) => matcher(relative(this.ctx.config.root, file)));
|
|
8548
4459
|
for (const file of matchingFiles) {
|
|
8549
4460
|
const fileCoverage = coverageMap.fileCoverageFor(file);
|
|
8550
4461
|
globCoverageMap.addFileCoverage(fileCoverage);
|
|
@@ -8815,4 +4726,4 @@ function resolveMergeConfig(mod) {
|
|
|
8815
4726
|
}
|
|
8816
4727
|
}
|
|
8817
4728
|
|
|
8818
|
-
export { BaseCoverageProvider as B, RandomSequencer as R, VitestCache as V, resolveApiServerConfig as a, BaseSequencer as b, createMethodsRPC as c, isBrowserEnabled as d, groupBy as e, getCoverageProvider as f, getFilePoolName as g, hash as h, isPackageExists as i, createPool as j,
|
|
4729
|
+
export { BaseCoverageProvider as B, RandomSequencer as R, VitestCache as V, resolveApiServerConfig as a, BaseSequencer as b, createMethodsRPC as c, isBrowserEnabled as d, groupBy as e, getCoverageProvider as f, getFilePoolName as g, hash as h, isPackageExists as i, createPool as j, resolveConfig$1 as r, stdout as s, wildcardPatternToRegExp as w };
|