react-doctor 0.2.0-beta.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -14
- package/dist/cli.js +2145 -187
- package/dist/index.d.ts +55 -0
- package/dist/index.js +2113 -153
- package/dist/skills/react-doctor/SKILL.md +4 -4
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2,9 +2,32 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
-
import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES } from "oxlint-plugin-react-doctor";
|
|
5
|
+
import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, BUILTIN_A11Y_RULES, BUILTIN_REACT_RULES, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES, REACT_COMPILER_RULES, YOU_MIGHT_NOT_NEED_EFFECT_RULES } from "oxlint-plugin-react-doctor";
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import * as ts from "typescript";
|
|
8
|
+
//#region \0rolldown/runtime.js
|
|
9
|
+
var __create$1 = Object.create;
|
|
10
|
+
var __defProp$1 = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
14
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __commonJSMin$1 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
16
|
+
var __copyProps$1 = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
+
key = keys[i];
|
|
19
|
+
if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
|
|
27
|
+
value: mod,
|
|
28
|
+
enumerable: true
|
|
29
|
+
}) : target, mod));
|
|
30
|
+
//#endregion
|
|
8
31
|
//#region ../types/dist/index.js
|
|
9
32
|
const REACT_NATIVE_DEPENDENCY_NAMES = new Set([
|
|
10
33
|
"react-native",
|
|
@@ -932,7 +955,1879 @@ const isTailwindAtLeast = (detected, required) => {
|
|
|
932
955
|
return detected.minor >= required.minor;
|
|
933
956
|
};
|
|
934
957
|
//#endregion
|
|
958
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/constants.js
|
|
959
|
+
var require_constants = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
960
|
+
const WIN_SLASH = "\\\\/";
|
|
961
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
962
|
+
const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
963
|
+
/**
|
|
964
|
+
* Posix glob regex
|
|
965
|
+
*/
|
|
966
|
+
const DOT_LITERAL = "\\.";
|
|
967
|
+
const PLUS_LITERAL = "\\+";
|
|
968
|
+
const QMARK_LITERAL = "\\?";
|
|
969
|
+
const SLASH_LITERAL = "\\/";
|
|
970
|
+
const ONE_CHAR = "(?=.)";
|
|
971
|
+
const QMARK = "[^/]";
|
|
972
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
973
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
974
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
975
|
+
const POSIX_CHARS = {
|
|
976
|
+
DOT_LITERAL,
|
|
977
|
+
PLUS_LITERAL,
|
|
978
|
+
QMARK_LITERAL,
|
|
979
|
+
SLASH_LITERAL,
|
|
980
|
+
ONE_CHAR,
|
|
981
|
+
QMARK,
|
|
982
|
+
END_ANCHOR,
|
|
983
|
+
DOTS_SLASH,
|
|
984
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
985
|
+
NO_DOTS: `(?!${START_ANCHOR}${DOTS_SLASH})`,
|
|
986
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`,
|
|
987
|
+
NO_DOTS_SLASH: `(?!${DOTS_SLASH})`,
|
|
988
|
+
QMARK_NO_DOT: `[^.${SLASH_LITERAL}]`,
|
|
989
|
+
STAR: `${QMARK}*?`,
|
|
990
|
+
START_ANCHOR,
|
|
991
|
+
SEP: "/"
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
* Windows glob regex
|
|
995
|
+
*/
|
|
996
|
+
const WINDOWS_CHARS = {
|
|
997
|
+
...POSIX_CHARS,
|
|
998
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
999
|
+
QMARK: WIN_NO_SLASH,
|
|
1000
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
1001
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
1002
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
1003
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
1004
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
1005
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
1006
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
1007
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
1008
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
1009
|
+
SEP: "\\"
|
|
1010
|
+
};
|
|
1011
|
+
module.exports = {
|
|
1012
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
1013
|
+
MAX_LENGTH: 1024 * 64,
|
|
1014
|
+
POSIX_REGEX_SOURCE: {
|
|
1015
|
+
__proto__: null,
|
|
1016
|
+
alnum: "a-zA-Z0-9",
|
|
1017
|
+
alpha: "a-zA-Z",
|
|
1018
|
+
ascii: "\\x00-\\x7F",
|
|
1019
|
+
blank: " \\t",
|
|
1020
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
1021
|
+
digit: "0-9",
|
|
1022
|
+
graph: "\\x21-\\x7E",
|
|
1023
|
+
lower: "a-z",
|
|
1024
|
+
print: "\\x20-\\x7E ",
|
|
1025
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
1026
|
+
space: " \\t\\r\\n\\v\\f",
|
|
1027
|
+
upper: "A-Z",
|
|
1028
|
+
word: "A-Za-z0-9_",
|
|
1029
|
+
xdigit: "A-Fa-f0-9"
|
|
1030
|
+
},
|
|
1031
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
1032
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
1033
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
1034
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
1035
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
1036
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
1037
|
+
REPLACEMENTS: {
|
|
1038
|
+
__proto__: null,
|
|
1039
|
+
"***": "*",
|
|
1040
|
+
"**/**": "**",
|
|
1041
|
+
"**/**/**": "**"
|
|
1042
|
+
},
|
|
1043
|
+
CHAR_0: 48,
|
|
1044
|
+
CHAR_9: 57,
|
|
1045
|
+
CHAR_UPPERCASE_A: 65,
|
|
1046
|
+
CHAR_LOWERCASE_A: 97,
|
|
1047
|
+
CHAR_UPPERCASE_Z: 90,
|
|
1048
|
+
CHAR_LOWERCASE_Z: 122,
|
|
1049
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
1050
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
1051
|
+
CHAR_ASTERISK: 42,
|
|
1052
|
+
CHAR_AMPERSAND: 38,
|
|
1053
|
+
CHAR_AT: 64,
|
|
1054
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
1055
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
1056
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
1057
|
+
CHAR_COLON: 58,
|
|
1058
|
+
CHAR_COMMA: 44,
|
|
1059
|
+
CHAR_DOT: 46,
|
|
1060
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
1061
|
+
CHAR_EQUAL: 61,
|
|
1062
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
1063
|
+
CHAR_FORM_FEED: 12,
|
|
1064
|
+
CHAR_FORWARD_SLASH: 47,
|
|
1065
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
1066
|
+
CHAR_HASH: 35,
|
|
1067
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
1068
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
1069
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
1070
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
1071
|
+
CHAR_LINE_FEED: 10,
|
|
1072
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
1073
|
+
CHAR_PERCENT: 37,
|
|
1074
|
+
CHAR_PLUS: 43,
|
|
1075
|
+
CHAR_QUESTION_MARK: 63,
|
|
1076
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
1077
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
1078
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
1079
|
+
CHAR_SEMICOLON: 59,
|
|
1080
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
1081
|
+
CHAR_SPACE: 32,
|
|
1082
|
+
CHAR_TAB: 9,
|
|
1083
|
+
CHAR_UNDERSCORE: 95,
|
|
1084
|
+
CHAR_VERTICAL_LINE: 124,
|
|
1085
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
1086
|
+
/**
|
|
1087
|
+
* Create EXTGLOB_CHARS
|
|
1088
|
+
*/
|
|
1089
|
+
extglobChars(chars) {
|
|
1090
|
+
return {
|
|
1091
|
+
"!": {
|
|
1092
|
+
type: "negate",
|
|
1093
|
+
open: "(?:(?!(?:",
|
|
1094
|
+
close: `))${chars.STAR})`
|
|
1095
|
+
},
|
|
1096
|
+
"?": {
|
|
1097
|
+
type: "qmark",
|
|
1098
|
+
open: "(?:",
|
|
1099
|
+
close: ")?"
|
|
1100
|
+
},
|
|
1101
|
+
"+": {
|
|
1102
|
+
type: "plus",
|
|
1103
|
+
open: "(?:",
|
|
1104
|
+
close: ")+"
|
|
1105
|
+
},
|
|
1106
|
+
"*": {
|
|
1107
|
+
type: "star",
|
|
1108
|
+
open: "(?:",
|
|
1109
|
+
close: ")*"
|
|
1110
|
+
},
|
|
1111
|
+
"@": {
|
|
1112
|
+
type: "at",
|
|
1113
|
+
open: "(?:",
|
|
1114
|
+
close: ")"
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
},
|
|
1118
|
+
/**
|
|
1119
|
+
* Create GLOB_CHARS
|
|
1120
|
+
*/
|
|
1121
|
+
globChars(win32) {
|
|
1122
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
}));
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/utils.js
|
|
1128
|
+
var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
1129
|
+
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
1130
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
1131
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
1132
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
1133
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
1134
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
1135
|
+
exports.isWindows = () => {
|
|
1136
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
1137
|
+
const platform = navigator.platform.toLowerCase();
|
|
1138
|
+
return platform === "win32" || platform === "windows";
|
|
1139
|
+
}
|
|
1140
|
+
if (typeof process !== "undefined" && process.platform) return process.platform === "win32";
|
|
1141
|
+
return false;
|
|
1142
|
+
};
|
|
1143
|
+
exports.removeBackslashes = (str) => {
|
|
1144
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
1145
|
+
return match === "\\" ? "" : match;
|
|
1146
|
+
});
|
|
1147
|
+
};
|
|
1148
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
1149
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
1150
|
+
if (idx === -1) return input;
|
|
1151
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
1152
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
1153
|
+
};
|
|
1154
|
+
exports.removePrefix = (input, state = {}) => {
|
|
1155
|
+
let output = input;
|
|
1156
|
+
if (output.startsWith("./")) {
|
|
1157
|
+
output = output.slice(2);
|
|
1158
|
+
state.prefix = "./";
|
|
1159
|
+
}
|
|
1160
|
+
return output;
|
|
1161
|
+
};
|
|
1162
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
1163
|
+
let output = `${options.contains ? "" : "^"}(?:${input})${options.contains ? "" : "$"}`;
|
|
1164
|
+
if (state.negated === true) output = `(?:^(?!${output}).*$)`;
|
|
1165
|
+
return output;
|
|
1166
|
+
};
|
|
1167
|
+
exports.basename = (path, { windows } = {}) => {
|
|
1168
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
1169
|
+
const last = segs[segs.length - 1];
|
|
1170
|
+
if (last === "") return segs[segs.length - 2];
|
|
1171
|
+
return last;
|
|
1172
|
+
};
|
|
1173
|
+
}));
|
|
1174
|
+
//#endregion
|
|
1175
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/scan.js
|
|
1176
|
+
var require_scan = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1177
|
+
const utils = require_utils();
|
|
1178
|
+
const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA, CHAR_DOT, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE, CHAR_LEFT_PARENTHESES, CHAR_LEFT_SQUARE_BRACKET, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE, CHAR_RIGHT_PARENTHESES, CHAR_RIGHT_SQUARE_BRACKET } = require_constants();
|
|
1179
|
+
const isPathSeparator = (code) => {
|
|
1180
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
1181
|
+
};
|
|
1182
|
+
const depth = (token) => {
|
|
1183
|
+
if (token.isPrefix !== true) token.depth = token.isGlobstar ? Infinity : 1;
|
|
1184
|
+
};
|
|
1185
|
+
/**
|
|
1186
|
+
* Quickly scans a glob pattern and returns an object with a handful of
|
|
1187
|
+
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
1188
|
+
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
1189
|
+
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
1190
|
+
*
|
|
1191
|
+
* ```js
|
|
1192
|
+
* const pm = require('picomatch');
|
|
1193
|
+
* console.log(pm.scan('foo/bar/*.js'));
|
|
1194
|
+
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
1195
|
+
* ```
|
|
1196
|
+
* @param {String} `str`
|
|
1197
|
+
* @param {Object} `options`
|
|
1198
|
+
* @return {Object} Returns an object with tokens and regex source string.
|
|
1199
|
+
* @api public
|
|
1200
|
+
*/
|
|
1201
|
+
const scan = (input, options) => {
|
|
1202
|
+
const opts = options || {};
|
|
1203
|
+
const length = input.length - 1;
|
|
1204
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
1205
|
+
const slashes = [];
|
|
1206
|
+
const tokens = [];
|
|
1207
|
+
const parts = [];
|
|
1208
|
+
let str = input;
|
|
1209
|
+
let index = -1;
|
|
1210
|
+
let start = 0;
|
|
1211
|
+
let lastIndex = 0;
|
|
1212
|
+
let isBrace = false;
|
|
1213
|
+
let isBracket = false;
|
|
1214
|
+
let isGlob = false;
|
|
1215
|
+
let isExtglob = false;
|
|
1216
|
+
let isGlobstar = false;
|
|
1217
|
+
let braceEscaped = false;
|
|
1218
|
+
let backslashes = false;
|
|
1219
|
+
let negated = false;
|
|
1220
|
+
let negatedExtglob = false;
|
|
1221
|
+
let finished = false;
|
|
1222
|
+
let braces = 0;
|
|
1223
|
+
let prev;
|
|
1224
|
+
let code;
|
|
1225
|
+
let token = {
|
|
1226
|
+
value: "",
|
|
1227
|
+
depth: 0,
|
|
1228
|
+
isGlob: false
|
|
1229
|
+
};
|
|
1230
|
+
const eos = () => index >= length;
|
|
1231
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
1232
|
+
const advance = () => {
|
|
1233
|
+
prev = code;
|
|
1234
|
+
return str.charCodeAt(++index);
|
|
1235
|
+
};
|
|
1236
|
+
while (index < length) {
|
|
1237
|
+
code = advance();
|
|
1238
|
+
let next;
|
|
1239
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1240
|
+
backslashes = token.backslashes = true;
|
|
1241
|
+
code = advance();
|
|
1242
|
+
if (code === CHAR_LEFT_CURLY_BRACE) braceEscaped = true;
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
1246
|
+
braces++;
|
|
1247
|
+
while (eos() !== true && (code = advance())) {
|
|
1248
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1249
|
+
backslashes = token.backslashes = true;
|
|
1250
|
+
advance();
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
1254
|
+
braces++;
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
1258
|
+
isBrace = token.isBrace = true;
|
|
1259
|
+
isGlob = token.isGlob = true;
|
|
1260
|
+
finished = true;
|
|
1261
|
+
if (scanToEnd === true) continue;
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1264
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
1265
|
+
isBrace = token.isBrace = true;
|
|
1266
|
+
isGlob = token.isGlob = true;
|
|
1267
|
+
finished = true;
|
|
1268
|
+
if (scanToEnd === true) continue;
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
1272
|
+
braces--;
|
|
1273
|
+
if (braces === 0) {
|
|
1274
|
+
braceEscaped = false;
|
|
1275
|
+
isBrace = token.isBrace = true;
|
|
1276
|
+
finished = true;
|
|
1277
|
+
break;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
if (scanToEnd === true) continue;
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
1285
|
+
slashes.push(index);
|
|
1286
|
+
tokens.push(token);
|
|
1287
|
+
token = {
|
|
1288
|
+
value: "",
|
|
1289
|
+
depth: 0,
|
|
1290
|
+
isGlob: false
|
|
1291
|
+
};
|
|
1292
|
+
if (finished === true) continue;
|
|
1293
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
1294
|
+
start += 2;
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
lastIndex = index + 1;
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
if (opts.noext !== true) {
|
|
1301
|
+
if ((code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK) === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
1302
|
+
isGlob = token.isGlob = true;
|
|
1303
|
+
isExtglob = token.isExtglob = true;
|
|
1304
|
+
finished = true;
|
|
1305
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
|
|
1306
|
+
if (scanToEnd === true) {
|
|
1307
|
+
while (eos() !== true && (code = advance())) {
|
|
1308
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1309
|
+
backslashes = token.backslashes = true;
|
|
1310
|
+
code = advance();
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
1313
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1314
|
+
isGlob = token.isGlob = true;
|
|
1315
|
+
finished = true;
|
|
1316
|
+
break;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
continue;
|
|
1320
|
+
}
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
if (code === CHAR_ASTERISK) {
|
|
1325
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
1326
|
+
isGlob = token.isGlob = true;
|
|
1327
|
+
finished = true;
|
|
1328
|
+
if (scanToEnd === true) continue;
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
1332
|
+
isGlob = token.isGlob = true;
|
|
1333
|
+
finished = true;
|
|
1334
|
+
if (scanToEnd === true) continue;
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
1338
|
+
while (eos() !== true && (next = advance())) {
|
|
1339
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
1340
|
+
backslashes = token.backslashes = true;
|
|
1341
|
+
advance();
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
1345
|
+
isBracket = token.isBracket = true;
|
|
1346
|
+
isGlob = token.isGlob = true;
|
|
1347
|
+
finished = true;
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
if (scanToEnd === true) continue;
|
|
1352
|
+
break;
|
|
1353
|
+
}
|
|
1354
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
1355
|
+
negated = token.negated = true;
|
|
1356
|
+
start++;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
1360
|
+
isGlob = token.isGlob = true;
|
|
1361
|
+
if (scanToEnd === true) {
|
|
1362
|
+
while (eos() !== true && (code = advance())) {
|
|
1363
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
1364
|
+
backslashes = token.backslashes = true;
|
|
1365
|
+
code = advance();
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1369
|
+
finished = true;
|
|
1370
|
+
break;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
if (isGlob === true) {
|
|
1378
|
+
finished = true;
|
|
1379
|
+
if (scanToEnd === true) continue;
|
|
1380
|
+
break;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if (opts.noext === true) {
|
|
1384
|
+
isExtglob = false;
|
|
1385
|
+
isGlob = false;
|
|
1386
|
+
}
|
|
1387
|
+
let base = str;
|
|
1388
|
+
let prefix = "";
|
|
1389
|
+
let glob = "";
|
|
1390
|
+
if (start > 0) {
|
|
1391
|
+
prefix = str.slice(0, start);
|
|
1392
|
+
str = str.slice(start);
|
|
1393
|
+
lastIndex -= start;
|
|
1394
|
+
}
|
|
1395
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
1396
|
+
base = str.slice(0, lastIndex);
|
|
1397
|
+
glob = str.slice(lastIndex);
|
|
1398
|
+
} else if (isGlob === true) {
|
|
1399
|
+
base = "";
|
|
1400
|
+
glob = str;
|
|
1401
|
+
} else base = str;
|
|
1402
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
1403
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) base = base.slice(0, -1);
|
|
1404
|
+
}
|
|
1405
|
+
if (opts.unescape === true) {
|
|
1406
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
1407
|
+
if (base && backslashes === true) base = utils.removeBackslashes(base);
|
|
1408
|
+
}
|
|
1409
|
+
const state = {
|
|
1410
|
+
prefix,
|
|
1411
|
+
input,
|
|
1412
|
+
start,
|
|
1413
|
+
base,
|
|
1414
|
+
glob,
|
|
1415
|
+
isBrace,
|
|
1416
|
+
isBracket,
|
|
1417
|
+
isGlob,
|
|
1418
|
+
isExtglob,
|
|
1419
|
+
isGlobstar,
|
|
1420
|
+
negated,
|
|
1421
|
+
negatedExtglob
|
|
1422
|
+
};
|
|
1423
|
+
if (opts.tokens === true) {
|
|
1424
|
+
state.maxDepth = 0;
|
|
1425
|
+
if (!isPathSeparator(code)) tokens.push(token);
|
|
1426
|
+
state.tokens = tokens;
|
|
1427
|
+
}
|
|
1428
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
1429
|
+
let prevIndex;
|
|
1430
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
1431
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
1432
|
+
const i = slashes[idx];
|
|
1433
|
+
const value = input.slice(n, i);
|
|
1434
|
+
if (opts.tokens) {
|
|
1435
|
+
if (idx === 0 && start !== 0) {
|
|
1436
|
+
tokens[idx].isPrefix = true;
|
|
1437
|
+
tokens[idx].value = prefix;
|
|
1438
|
+
} else tokens[idx].value = value;
|
|
1439
|
+
depth(tokens[idx]);
|
|
1440
|
+
state.maxDepth += tokens[idx].depth;
|
|
1441
|
+
}
|
|
1442
|
+
if (idx !== 0 || value !== "") parts.push(value);
|
|
1443
|
+
prevIndex = i;
|
|
1444
|
+
}
|
|
1445
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
1446
|
+
const value = input.slice(prevIndex + 1);
|
|
1447
|
+
parts.push(value);
|
|
1448
|
+
if (opts.tokens) {
|
|
1449
|
+
tokens[tokens.length - 1].value = value;
|
|
1450
|
+
depth(tokens[tokens.length - 1]);
|
|
1451
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
state.slashes = slashes;
|
|
1455
|
+
state.parts = parts;
|
|
1456
|
+
}
|
|
1457
|
+
return state;
|
|
1458
|
+
};
|
|
1459
|
+
module.exports = scan;
|
|
1460
|
+
}));
|
|
1461
|
+
//#endregion
|
|
1462
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/parse.js
|
|
1463
|
+
var require_parse = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1464
|
+
const constants = require_constants();
|
|
1465
|
+
const utils = require_utils();
|
|
1466
|
+
/**
|
|
1467
|
+
* Constants
|
|
1468
|
+
*/
|
|
1469
|
+
const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants;
|
|
1470
|
+
/**
|
|
1471
|
+
* Helpers
|
|
1472
|
+
*/
|
|
1473
|
+
const expandRange = (args, options) => {
|
|
1474
|
+
if (typeof options.expandRange === "function") return options.expandRange(...args, options);
|
|
1475
|
+
args.sort();
|
|
1476
|
+
const value = `[${args.join("-")}]`;
|
|
1477
|
+
try {
|
|
1478
|
+
new RegExp(value);
|
|
1479
|
+
} catch (ex) {
|
|
1480
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
1481
|
+
}
|
|
1482
|
+
return value;
|
|
1483
|
+
};
|
|
1484
|
+
/**
|
|
1485
|
+
* Create the message for a syntax error
|
|
1486
|
+
*/
|
|
1487
|
+
const syntaxError = (type, char) => {
|
|
1488
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
1489
|
+
};
|
|
1490
|
+
const splitTopLevel = (input) => {
|
|
1491
|
+
const parts = [];
|
|
1492
|
+
let bracket = 0;
|
|
1493
|
+
let paren = 0;
|
|
1494
|
+
let quote = 0;
|
|
1495
|
+
let value = "";
|
|
1496
|
+
let escaped = false;
|
|
1497
|
+
for (const ch of input) {
|
|
1498
|
+
if (escaped === true) {
|
|
1499
|
+
value += ch;
|
|
1500
|
+
escaped = false;
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
if (ch === "\\") {
|
|
1504
|
+
value += ch;
|
|
1505
|
+
escaped = true;
|
|
1506
|
+
continue;
|
|
1507
|
+
}
|
|
1508
|
+
if (ch === "\"") {
|
|
1509
|
+
quote = quote === 1 ? 0 : 1;
|
|
1510
|
+
value += ch;
|
|
1511
|
+
continue;
|
|
1512
|
+
}
|
|
1513
|
+
if (quote === 0) {
|
|
1514
|
+
if (ch === "[") bracket++;
|
|
1515
|
+
else if (ch === "]" && bracket > 0) bracket--;
|
|
1516
|
+
else if (bracket === 0) {
|
|
1517
|
+
if (ch === "(") paren++;
|
|
1518
|
+
else if (ch === ")" && paren > 0) paren--;
|
|
1519
|
+
else if (ch === "|" && paren === 0) {
|
|
1520
|
+
parts.push(value);
|
|
1521
|
+
value = "";
|
|
1522
|
+
continue;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
value += ch;
|
|
1527
|
+
}
|
|
1528
|
+
parts.push(value);
|
|
1529
|
+
return parts;
|
|
1530
|
+
};
|
|
1531
|
+
const isPlainBranch = (branch) => {
|
|
1532
|
+
let escaped = false;
|
|
1533
|
+
for (const ch of branch) {
|
|
1534
|
+
if (escaped === true) {
|
|
1535
|
+
escaped = false;
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1538
|
+
if (ch === "\\") {
|
|
1539
|
+
escaped = true;
|
|
1540
|
+
continue;
|
|
1541
|
+
}
|
|
1542
|
+
if (/[?*+@!()[\]{}]/.test(ch)) return false;
|
|
1543
|
+
}
|
|
1544
|
+
return true;
|
|
1545
|
+
};
|
|
1546
|
+
const normalizeSimpleBranch = (branch) => {
|
|
1547
|
+
let value = branch.trim();
|
|
1548
|
+
let changed = true;
|
|
1549
|
+
while (changed === true) {
|
|
1550
|
+
changed = false;
|
|
1551
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
1552
|
+
value = value.slice(2, -1);
|
|
1553
|
+
changed = true;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
if (!isPlainBranch(value)) return;
|
|
1557
|
+
return value.replace(/\\(.)/g, "$1");
|
|
1558
|
+
};
|
|
1559
|
+
const hasRepeatedCharPrefixOverlap = (branches) => {
|
|
1560
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
1561
|
+
for (let i = 0; i < values.length; i++) for (let j = i + 1; j < values.length; j++) {
|
|
1562
|
+
const a = values[i];
|
|
1563
|
+
const b = values[j];
|
|
1564
|
+
const char = a[0];
|
|
1565
|
+
if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) continue;
|
|
1566
|
+
if (a === b || a.startsWith(b) || b.startsWith(a)) return true;
|
|
1567
|
+
}
|
|
1568
|
+
return false;
|
|
1569
|
+
};
|
|
1570
|
+
const parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
1571
|
+
if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") return;
|
|
1572
|
+
let bracket = 0;
|
|
1573
|
+
let paren = 0;
|
|
1574
|
+
let quote = 0;
|
|
1575
|
+
let escaped = false;
|
|
1576
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
1577
|
+
const ch = pattern[i];
|
|
1578
|
+
if (escaped === true) {
|
|
1579
|
+
escaped = false;
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1582
|
+
if (ch === "\\") {
|
|
1583
|
+
escaped = true;
|
|
1584
|
+
continue;
|
|
1585
|
+
}
|
|
1586
|
+
if (ch === "\"") {
|
|
1587
|
+
quote = quote === 1 ? 0 : 1;
|
|
1588
|
+
continue;
|
|
1589
|
+
}
|
|
1590
|
+
if (quote === 1) continue;
|
|
1591
|
+
if (ch === "[") {
|
|
1592
|
+
bracket++;
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
if (ch === "]" && bracket > 0) {
|
|
1596
|
+
bracket--;
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
if (bracket > 0) continue;
|
|
1600
|
+
if (ch === "(") {
|
|
1601
|
+
paren++;
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
if (ch === ")") {
|
|
1605
|
+
paren--;
|
|
1606
|
+
if (paren === 0) {
|
|
1607
|
+
if (requireEnd === true && i !== pattern.length - 1) return;
|
|
1608
|
+
return {
|
|
1609
|
+
type: pattern[0],
|
|
1610
|
+
body: pattern.slice(2, i),
|
|
1611
|
+
end: i
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
const getStarExtglobSequenceOutput = (pattern) => {
|
|
1618
|
+
let index = 0;
|
|
1619
|
+
const chars = [];
|
|
1620
|
+
while (index < pattern.length) {
|
|
1621
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
1622
|
+
if (!match || match.type !== "*") return;
|
|
1623
|
+
const branches = splitTopLevel(match.body).map((branch) => branch.trim());
|
|
1624
|
+
if (branches.length !== 1) return;
|
|
1625
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
1626
|
+
if (!branch || branch.length !== 1) return;
|
|
1627
|
+
chars.push(branch);
|
|
1628
|
+
index += match.end + 1;
|
|
1629
|
+
}
|
|
1630
|
+
if (chars.length < 1) return;
|
|
1631
|
+
return `${chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`}*`;
|
|
1632
|
+
};
|
|
1633
|
+
const repeatedExtglobRecursion = (pattern) => {
|
|
1634
|
+
let depth = 0;
|
|
1635
|
+
let value = pattern.trim();
|
|
1636
|
+
let match = parseRepeatedExtglob(value);
|
|
1637
|
+
while (match) {
|
|
1638
|
+
depth++;
|
|
1639
|
+
value = match.body.trim();
|
|
1640
|
+
match = parseRepeatedExtglob(value);
|
|
1641
|
+
}
|
|
1642
|
+
return depth;
|
|
1643
|
+
};
|
|
1644
|
+
const analyzeRepeatedExtglob = (body, options) => {
|
|
1645
|
+
if (options.maxExtglobRecursion === false) return { risky: false };
|
|
1646
|
+
const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
1647
|
+
const branches = splitTopLevel(body).map((branch) => branch.trim());
|
|
1648
|
+
if (branches.length > 1) {
|
|
1649
|
+
if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) return { risky: true };
|
|
1650
|
+
}
|
|
1651
|
+
for (const branch of branches) {
|
|
1652
|
+
const safeOutput = getStarExtglobSequenceOutput(branch);
|
|
1653
|
+
if (safeOutput) return {
|
|
1654
|
+
risky: true,
|
|
1655
|
+
safeOutput
|
|
1656
|
+
};
|
|
1657
|
+
if (repeatedExtglobRecursion(branch) > max) return { risky: true };
|
|
1658
|
+
}
|
|
1659
|
+
return { risky: false };
|
|
1660
|
+
};
|
|
1661
|
+
/**
|
|
1662
|
+
* Parse the given input string.
|
|
1663
|
+
* @param {String} input
|
|
1664
|
+
* @param {Object} options
|
|
1665
|
+
* @return {Object}
|
|
1666
|
+
*/
|
|
1667
|
+
const parse = (input, options) => {
|
|
1668
|
+
if (typeof input !== "string") throw new TypeError("Expected a string");
|
|
1669
|
+
input = REPLACEMENTS[input] || input;
|
|
1670
|
+
const opts = { ...options };
|
|
1671
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1672
|
+
let len = input.length;
|
|
1673
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1674
|
+
const bos = {
|
|
1675
|
+
type: "bos",
|
|
1676
|
+
value: "",
|
|
1677
|
+
output: opts.prepend || ""
|
|
1678
|
+
};
|
|
1679
|
+
const tokens = [bos];
|
|
1680
|
+
const capture = opts.capture ? "" : "?:";
|
|
1681
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
1682
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
1683
|
+
const { DOT_LITERAL, PLUS_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOT_SLASH, NO_DOTS_SLASH, QMARK, QMARK_NO_DOT, STAR, START_ANCHOR } = PLATFORM_CHARS;
|
|
1684
|
+
const globstar = (opts) => {
|
|
1685
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1686
|
+
};
|
|
1687
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
1688
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
1689
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
1690
|
+
if (opts.capture) star = `(${star})`;
|
|
1691
|
+
if (typeof opts.noext === "boolean") opts.noextglob = opts.noext;
|
|
1692
|
+
const state = {
|
|
1693
|
+
input,
|
|
1694
|
+
index: -1,
|
|
1695
|
+
start: 0,
|
|
1696
|
+
dot: opts.dot === true,
|
|
1697
|
+
consumed: "",
|
|
1698
|
+
output: "",
|
|
1699
|
+
prefix: "",
|
|
1700
|
+
backtrack: false,
|
|
1701
|
+
negated: false,
|
|
1702
|
+
brackets: 0,
|
|
1703
|
+
braces: 0,
|
|
1704
|
+
parens: 0,
|
|
1705
|
+
quotes: 0,
|
|
1706
|
+
globstar: false,
|
|
1707
|
+
tokens
|
|
1708
|
+
};
|
|
1709
|
+
input = utils.removePrefix(input, state);
|
|
1710
|
+
len = input.length;
|
|
1711
|
+
const extglobs = [];
|
|
1712
|
+
const braces = [];
|
|
1713
|
+
const stack = [];
|
|
1714
|
+
let prev = bos;
|
|
1715
|
+
let value;
|
|
1716
|
+
/**
|
|
1717
|
+
* Tokenizing helpers
|
|
1718
|
+
*/
|
|
1719
|
+
const eos = () => state.index === len - 1;
|
|
1720
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
1721
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
1722
|
+
const remaining = () => input.slice(state.index + 1);
|
|
1723
|
+
const consume = (value = "", num = 0) => {
|
|
1724
|
+
state.consumed += value;
|
|
1725
|
+
state.index += num;
|
|
1726
|
+
};
|
|
1727
|
+
const append = (token) => {
|
|
1728
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1729
|
+
consume(token.value);
|
|
1730
|
+
};
|
|
1731
|
+
const negate = () => {
|
|
1732
|
+
let count = 1;
|
|
1733
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
1734
|
+
advance();
|
|
1735
|
+
state.start++;
|
|
1736
|
+
count++;
|
|
1737
|
+
}
|
|
1738
|
+
if (count % 2 === 0) return false;
|
|
1739
|
+
state.negated = true;
|
|
1740
|
+
state.start++;
|
|
1741
|
+
return true;
|
|
1742
|
+
};
|
|
1743
|
+
const increment = (type) => {
|
|
1744
|
+
state[type]++;
|
|
1745
|
+
stack.push(type);
|
|
1746
|
+
};
|
|
1747
|
+
const decrement = (type) => {
|
|
1748
|
+
state[type]--;
|
|
1749
|
+
stack.pop();
|
|
1750
|
+
};
|
|
1751
|
+
/**
|
|
1752
|
+
* Push tokens onto the tokens array. This helper speeds up
|
|
1753
|
+
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
1754
|
+
* and 2) helping us avoid creating extra tokens when consecutive
|
|
1755
|
+
* characters are plain text. This improves performance and simplifies
|
|
1756
|
+
* lookbehinds.
|
|
1757
|
+
*/
|
|
1758
|
+
const push = (tok) => {
|
|
1759
|
+
if (prev.type === "globstar") {
|
|
1760
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
1761
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
1762
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
1763
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1764
|
+
prev.type = "star";
|
|
1765
|
+
prev.value = "*";
|
|
1766
|
+
prev.output = star;
|
|
1767
|
+
state.output += prev.output;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
if (extglobs.length && tok.type !== "paren") extglobs[extglobs.length - 1].inner += tok.value;
|
|
1771
|
+
if (tok.value || tok.output) append(tok);
|
|
1772
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
1773
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
1774
|
+
prev.value += tok.value;
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
tok.prev = prev;
|
|
1778
|
+
tokens.push(tok);
|
|
1779
|
+
prev = tok;
|
|
1780
|
+
};
|
|
1781
|
+
const extglobOpen = (type, value) => {
|
|
1782
|
+
const token = {
|
|
1783
|
+
...EXTGLOB_CHARS[value],
|
|
1784
|
+
conditions: 1,
|
|
1785
|
+
inner: ""
|
|
1786
|
+
};
|
|
1787
|
+
token.prev = prev;
|
|
1788
|
+
token.parens = state.parens;
|
|
1789
|
+
token.output = state.output;
|
|
1790
|
+
token.startIndex = state.index;
|
|
1791
|
+
token.tokensIndex = tokens.length;
|
|
1792
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
1793
|
+
increment("parens");
|
|
1794
|
+
push({
|
|
1795
|
+
type,
|
|
1796
|
+
value,
|
|
1797
|
+
output: state.output ? "" : ONE_CHAR
|
|
1798
|
+
});
|
|
1799
|
+
push({
|
|
1800
|
+
type: "paren",
|
|
1801
|
+
extglob: true,
|
|
1802
|
+
value: advance(),
|
|
1803
|
+
output
|
|
1804
|
+
});
|
|
1805
|
+
extglobs.push(token);
|
|
1806
|
+
};
|
|
1807
|
+
const extglobClose = (token) => {
|
|
1808
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
1809
|
+
const analysis = analyzeRepeatedExtglob(input.slice(token.startIndex + 2, state.index), opts);
|
|
1810
|
+
if ((token.type === "plus" || token.type === "star") && analysis.risky) {
|
|
1811
|
+
const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
|
|
1812
|
+
const open = tokens[token.tokensIndex];
|
|
1813
|
+
open.type = "text";
|
|
1814
|
+
open.value = literal;
|
|
1815
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
1816
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
1817
|
+
tokens[i].value = "";
|
|
1818
|
+
tokens[i].output = "";
|
|
1819
|
+
delete tokens[i].suffix;
|
|
1820
|
+
}
|
|
1821
|
+
state.output = token.output + open.output;
|
|
1822
|
+
state.backtrack = true;
|
|
1823
|
+
push({
|
|
1824
|
+
type: "paren",
|
|
1825
|
+
extglob: true,
|
|
1826
|
+
value,
|
|
1827
|
+
output: ""
|
|
1828
|
+
});
|
|
1829
|
+
decrement("parens");
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
1833
|
+
let rest;
|
|
1834
|
+
if (token.type === "negate") {
|
|
1835
|
+
let extglobStar = star;
|
|
1836
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) extglobStar = globstar(opts);
|
|
1837
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) output = token.close = `)$))${extglobStar}`;
|
|
1838
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) output = token.close = `)${parse(rest, {
|
|
1839
|
+
...options,
|
|
1840
|
+
fastpaths: false
|
|
1841
|
+
}).output})${extglobStar})`;
|
|
1842
|
+
if (token.prev.type === "bos") state.negatedExtglob = true;
|
|
1843
|
+
}
|
|
1844
|
+
push({
|
|
1845
|
+
type: "paren",
|
|
1846
|
+
extglob: true,
|
|
1847
|
+
value,
|
|
1848
|
+
output
|
|
1849
|
+
});
|
|
1850
|
+
decrement("parens");
|
|
1851
|
+
};
|
|
1852
|
+
/**
|
|
1853
|
+
* Fast paths
|
|
1854
|
+
*/
|
|
1855
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
1856
|
+
let backslashes = false;
|
|
1857
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
1858
|
+
if (first === "\\") {
|
|
1859
|
+
backslashes = true;
|
|
1860
|
+
return m;
|
|
1861
|
+
}
|
|
1862
|
+
if (first === "?") {
|
|
1863
|
+
if (esc) return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
1864
|
+
if (index === 0) return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
1865
|
+
return QMARK.repeat(chars.length);
|
|
1866
|
+
}
|
|
1867
|
+
if (first === ".") return DOT_LITERAL.repeat(chars.length);
|
|
1868
|
+
if (first === "*") {
|
|
1869
|
+
if (esc) return esc + first + (rest ? star : "");
|
|
1870
|
+
return star;
|
|
1871
|
+
}
|
|
1872
|
+
return esc ? m : `\\${m}`;
|
|
1873
|
+
});
|
|
1874
|
+
if (backslashes === true) if (opts.unescape === true) output = output.replace(/\\/g, "");
|
|
1875
|
+
else output = output.replace(/\\+/g, (m) => {
|
|
1876
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
1877
|
+
});
|
|
1878
|
+
if (output === input && opts.contains === true) {
|
|
1879
|
+
state.output = input;
|
|
1880
|
+
return state;
|
|
1881
|
+
}
|
|
1882
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
1883
|
+
return state;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Tokenize input until we reach end-of-string
|
|
1887
|
+
*/
|
|
1888
|
+
while (!eos()) {
|
|
1889
|
+
value = advance();
|
|
1890
|
+
if (value === "\0") continue;
|
|
1891
|
+
/**
|
|
1892
|
+
* Escaped characters
|
|
1893
|
+
*/
|
|
1894
|
+
if (value === "\\") {
|
|
1895
|
+
const next = peek();
|
|
1896
|
+
if (next === "/" && opts.bash !== true) continue;
|
|
1897
|
+
if (next === "." || next === ";") continue;
|
|
1898
|
+
if (!next) {
|
|
1899
|
+
value += "\\";
|
|
1900
|
+
push({
|
|
1901
|
+
type: "text",
|
|
1902
|
+
value
|
|
1903
|
+
});
|
|
1904
|
+
continue;
|
|
1905
|
+
}
|
|
1906
|
+
const match = /^\\+/.exec(remaining());
|
|
1907
|
+
let slashes = 0;
|
|
1908
|
+
if (match && match[0].length > 2) {
|
|
1909
|
+
slashes = match[0].length;
|
|
1910
|
+
state.index += slashes;
|
|
1911
|
+
if (slashes % 2 !== 0) value += "\\";
|
|
1912
|
+
}
|
|
1913
|
+
if (opts.unescape === true) value = advance();
|
|
1914
|
+
else value += advance();
|
|
1915
|
+
if (state.brackets === 0) {
|
|
1916
|
+
push({
|
|
1917
|
+
type: "text",
|
|
1918
|
+
value
|
|
1919
|
+
});
|
|
1920
|
+
continue;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* If we're inside a regex character class, continue
|
|
1925
|
+
* until we reach the closing bracket.
|
|
1926
|
+
*/
|
|
1927
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
1928
|
+
if (opts.posix !== false && value === ":") {
|
|
1929
|
+
const inner = prev.value.slice(1);
|
|
1930
|
+
if (inner.includes("[")) {
|
|
1931
|
+
prev.posix = true;
|
|
1932
|
+
if (inner.includes(":")) {
|
|
1933
|
+
const idx = prev.value.lastIndexOf("[");
|
|
1934
|
+
const pre = prev.value.slice(0, idx);
|
|
1935
|
+
const posix = POSIX_REGEX_SOURCE[prev.value.slice(idx + 2)];
|
|
1936
|
+
if (posix) {
|
|
1937
|
+
prev.value = pre + posix;
|
|
1938
|
+
state.backtrack = true;
|
|
1939
|
+
advance();
|
|
1940
|
+
if (!bos.output && tokens.indexOf(prev) === 1) bos.output = ONE_CHAR;
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") value = `\\${value}`;
|
|
1947
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) value = `\\${value}`;
|
|
1948
|
+
if (opts.posix === true && value === "!" && prev.value === "[") value = "^";
|
|
1949
|
+
prev.value += value;
|
|
1950
|
+
append({ value });
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
* If we're inside a quoted string, continue
|
|
1955
|
+
* until we reach the closing double quote.
|
|
1956
|
+
*/
|
|
1957
|
+
if (state.quotes === 1 && value !== "\"") {
|
|
1958
|
+
value = utils.escapeRegex(value);
|
|
1959
|
+
prev.value += value;
|
|
1960
|
+
append({ value });
|
|
1961
|
+
continue;
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Double quotes
|
|
1965
|
+
*/
|
|
1966
|
+
if (value === "\"") {
|
|
1967
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
1968
|
+
if (opts.keepQuotes === true) push({
|
|
1969
|
+
type: "text",
|
|
1970
|
+
value
|
|
1971
|
+
});
|
|
1972
|
+
continue;
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Parentheses
|
|
1976
|
+
*/
|
|
1977
|
+
if (value === "(") {
|
|
1978
|
+
increment("parens");
|
|
1979
|
+
push({
|
|
1980
|
+
type: "paren",
|
|
1981
|
+
value
|
|
1982
|
+
});
|
|
1983
|
+
continue;
|
|
1984
|
+
}
|
|
1985
|
+
if (value === ")") {
|
|
1986
|
+
if (state.parens === 0 && opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "("));
|
|
1987
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
1988
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
1989
|
+
extglobClose(extglobs.pop());
|
|
1990
|
+
continue;
|
|
1991
|
+
}
|
|
1992
|
+
push({
|
|
1993
|
+
type: "paren",
|
|
1994
|
+
value,
|
|
1995
|
+
output: state.parens ? ")" : "\\)"
|
|
1996
|
+
});
|
|
1997
|
+
decrement("parens");
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Square brackets
|
|
2002
|
+
*/
|
|
2003
|
+
if (value === "[") {
|
|
2004
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
2005
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
2006
|
+
value = `\\${value}`;
|
|
2007
|
+
} else increment("brackets");
|
|
2008
|
+
push({
|
|
2009
|
+
type: "bracket",
|
|
2010
|
+
value
|
|
2011
|
+
});
|
|
2012
|
+
continue;
|
|
2013
|
+
}
|
|
2014
|
+
if (value === "]") {
|
|
2015
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
2016
|
+
push({
|
|
2017
|
+
type: "text",
|
|
2018
|
+
value,
|
|
2019
|
+
output: `\\${value}`
|
|
2020
|
+
});
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
2023
|
+
if (state.brackets === 0) {
|
|
2024
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "["));
|
|
2025
|
+
push({
|
|
2026
|
+
type: "text",
|
|
2027
|
+
value,
|
|
2028
|
+
output: `\\${value}`
|
|
2029
|
+
});
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
decrement("brackets");
|
|
2033
|
+
const prevValue = prev.value.slice(1);
|
|
2034
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) value = `/${value}`;
|
|
2035
|
+
prev.value += value;
|
|
2036
|
+
append({ value });
|
|
2037
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) continue;
|
|
2038
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
2039
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
2040
|
+
if (opts.literalBrackets === true) {
|
|
2041
|
+
state.output += escaped;
|
|
2042
|
+
prev.value = escaped;
|
|
2043
|
+
continue;
|
|
2044
|
+
}
|
|
2045
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
2046
|
+
state.output += prev.value;
|
|
2047
|
+
continue;
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Braces
|
|
2051
|
+
*/
|
|
2052
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
2053
|
+
increment("braces");
|
|
2054
|
+
const open = {
|
|
2055
|
+
type: "brace",
|
|
2056
|
+
value,
|
|
2057
|
+
output: "(",
|
|
2058
|
+
outputIndex: state.output.length,
|
|
2059
|
+
tokensIndex: state.tokens.length
|
|
2060
|
+
};
|
|
2061
|
+
braces.push(open);
|
|
2062
|
+
push(open);
|
|
2063
|
+
continue;
|
|
2064
|
+
}
|
|
2065
|
+
if (value === "}") {
|
|
2066
|
+
const brace = braces[braces.length - 1];
|
|
2067
|
+
if (opts.nobrace === true || !brace) {
|
|
2068
|
+
push({
|
|
2069
|
+
type: "text",
|
|
2070
|
+
value,
|
|
2071
|
+
output: value
|
|
2072
|
+
});
|
|
2073
|
+
continue;
|
|
2074
|
+
}
|
|
2075
|
+
let output = ")";
|
|
2076
|
+
if (brace.dots === true) {
|
|
2077
|
+
const arr = tokens.slice();
|
|
2078
|
+
const range = [];
|
|
2079
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
2080
|
+
tokens.pop();
|
|
2081
|
+
if (arr[i].type === "brace") break;
|
|
2082
|
+
if (arr[i].type !== "dots") range.unshift(arr[i].value);
|
|
2083
|
+
}
|
|
2084
|
+
output = expandRange(range, opts);
|
|
2085
|
+
state.backtrack = true;
|
|
2086
|
+
}
|
|
2087
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
2088
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
2089
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
2090
|
+
brace.value = brace.output = "\\{";
|
|
2091
|
+
value = output = "\\}";
|
|
2092
|
+
state.output = out;
|
|
2093
|
+
for (const t of toks) state.output += t.output || t.value;
|
|
2094
|
+
}
|
|
2095
|
+
push({
|
|
2096
|
+
type: "brace",
|
|
2097
|
+
value,
|
|
2098
|
+
output
|
|
2099
|
+
});
|
|
2100
|
+
decrement("braces");
|
|
2101
|
+
braces.pop();
|
|
2102
|
+
continue;
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Pipes
|
|
2106
|
+
*/
|
|
2107
|
+
if (value === "|") {
|
|
2108
|
+
if (extglobs.length > 0) extglobs[extglobs.length - 1].conditions++;
|
|
2109
|
+
push({
|
|
2110
|
+
type: "text",
|
|
2111
|
+
value
|
|
2112
|
+
});
|
|
2113
|
+
continue;
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Commas
|
|
2117
|
+
*/
|
|
2118
|
+
if (value === ",") {
|
|
2119
|
+
let output = value;
|
|
2120
|
+
const brace = braces[braces.length - 1];
|
|
2121
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
2122
|
+
brace.comma = true;
|
|
2123
|
+
output = "|";
|
|
2124
|
+
}
|
|
2125
|
+
push({
|
|
2126
|
+
type: "comma",
|
|
2127
|
+
value,
|
|
2128
|
+
output
|
|
2129
|
+
});
|
|
2130
|
+
continue;
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* Slashes
|
|
2134
|
+
*/
|
|
2135
|
+
if (value === "/") {
|
|
2136
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
2137
|
+
state.start = state.index + 1;
|
|
2138
|
+
state.consumed = "";
|
|
2139
|
+
state.output = "";
|
|
2140
|
+
tokens.pop();
|
|
2141
|
+
prev = bos;
|
|
2142
|
+
continue;
|
|
2143
|
+
}
|
|
2144
|
+
push({
|
|
2145
|
+
type: "slash",
|
|
2146
|
+
value,
|
|
2147
|
+
output: SLASH_LITERAL
|
|
2148
|
+
});
|
|
2149
|
+
continue;
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* Dots
|
|
2153
|
+
*/
|
|
2154
|
+
if (value === ".") {
|
|
2155
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
2156
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
2157
|
+
const brace = braces[braces.length - 1];
|
|
2158
|
+
prev.type = "dots";
|
|
2159
|
+
prev.output += value;
|
|
2160
|
+
prev.value += value;
|
|
2161
|
+
brace.dots = true;
|
|
2162
|
+
continue;
|
|
2163
|
+
}
|
|
2164
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
2165
|
+
push({
|
|
2166
|
+
type: "text",
|
|
2167
|
+
value,
|
|
2168
|
+
output: DOT_LITERAL
|
|
2169
|
+
});
|
|
2170
|
+
continue;
|
|
2171
|
+
}
|
|
2172
|
+
push({
|
|
2173
|
+
type: "dot",
|
|
2174
|
+
value,
|
|
2175
|
+
output: DOT_LITERAL
|
|
2176
|
+
});
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Question marks
|
|
2181
|
+
*/
|
|
2182
|
+
if (value === "?") {
|
|
2183
|
+
if (!(prev && prev.value === "(") && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2184
|
+
extglobOpen("qmark", value);
|
|
2185
|
+
continue;
|
|
2186
|
+
}
|
|
2187
|
+
if (prev && prev.type === "paren") {
|
|
2188
|
+
const next = peek();
|
|
2189
|
+
let output = value;
|
|
2190
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) output = `\\${value}`;
|
|
2191
|
+
push({
|
|
2192
|
+
type: "text",
|
|
2193
|
+
value,
|
|
2194
|
+
output
|
|
2195
|
+
});
|
|
2196
|
+
continue;
|
|
2197
|
+
}
|
|
2198
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
2199
|
+
push({
|
|
2200
|
+
type: "qmark",
|
|
2201
|
+
value,
|
|
2202
|
+
output: QMARK_NO_DOT
|
|
2203
|
+
});
|
|
2204
|
+
continue;
|
|
2205
|
+
}
|
|
2206
|
+
push({
|
|
2207
|
+
type: "qmark",
|
|
2208
|
+
value,
|
|
2209
|
+
output: QMARK
|
|
2210
|
+
});
|
|
2211
|
+
continue;
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* Exclamation
|
|
2215
|
+
*/
|
|
2216
|
+
if (value === "!") {
|
|
2217
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
2218
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
2219
|
+
extglobOpen("negate", value);
|
|
2220
|
+
continue;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
2224
|
+
negate();
|
|
2225
|
+
continue;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Plus
|
|
2230
|
+
*/
|
|
2231
|
+
if (value === "+") {
|
|
2232
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2233
|
+
extglobOpen("plus", value);
|
|
2234
|
+
continue;
|
|
2235
|
+
}
|
|
2236
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
2237
|
+
push({
|
|
2238
|
+
type: "plus",
|
|
2239
|
+
value,
|
|
2240
|
+
output: PLUS_LITERAL
|
|
2241
|
+
});
|
|
2242
|
+
continue;
|
|
2243
|
+
}
|
|
2244
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
2245
|
+
push({
|
|
2246
|
+
type: "plus",
|
|
2247
|
+
value
|
|
2248
|
+
});
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
push({
|
|
2252
|
+
type: "plus",
|
|
2253
|
+
value: PLUS_LITERAL
|
|
2254
|
+
});
|
|
2255
|
+
continue;
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* Plain text
|
|
2259
|
+
*/
|
|
2260
|
+
if (value === "@") {
|
|
2261
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2262
|
+
push({
|
|
2263
|
+
type: "at",
|
|
2264
|
+
extglob: true,
|
|
2265
|
+
value,
|
|
2266
|
+
output: ""
|
|
2267
|
+
});
|
|
2268
|
+
continue;
|
|
2269
|
+
}
|
|
2270
|
+
push({
|
|
2271
|
+
type: "text",
|
|
2272
|
+
value
|
|
2273
|
+
});
|
|
2274
|
+
continue;
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Plain text
|
|
2278
|
+
*/
|
|
2279
|
+
if (value !== "*") {
|
|
2280
|
+
if (value === "$" || value === "^") value = `\\${value}`;
|
|
2281
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
2282
|
+
if (match) {
|
|
2283
|
+
value += match[0];
|
|
2284
|
+
state.index += match[0].length;
|
|
2285
|
+
}
|
|
2286
|
+
push({
|
|
2287
|
+
type: "text",
|
|
2288
|
+
value
|
|
2289
|
+
});
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Stars
|
|
2294
|
+
*/
|
|
2295
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
2296
|
+
prev.type = "star";
|
|
2297
|
+
prev.star = true;
|
|
2298
|
+
prev.value += value;
|
|
2299
|
+
prev.output = star;
|
|
2300
|
+
state.backtrack = true;
|
|
2301
|
+
state.globstar = true;
|
|
2302
|
+
consume(value);
|
|
2303
|
+
continue;
|
|
2304
|
+
}
|
|
2305
|
+
let rest = remaining();
|
|
2306
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
2307
|
+
extglobOpen("star", value);
|
|
2308
|
+
continue;
|
|
2309
|
+
}
|
|
2310
|
+
if (prev.type === "star") {
|
|
2311
|
+
if (opts.noglobstar === true) {
|
|
2312
|
+
consume(value);
|
|
2313
|
+
continue;
|
|
2314
|
+
}
|
|
2315
|
+
const prior = prev.prev;
|
|
2316
|
+
const before = prior.prev;
|
|
2317
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
2318
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
2319
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
2320
|
+
push({
|
|
2321
|
+
type: "star",
|
|
2322
|
+
value,
|
|
2323
|
+
output: ""
|
|
2324
|
+
});
|
|
2325
|
+
continue;
|
|
2326
|
+
}
|
|
2327
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
2328
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
2329
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
2330
|
+
push({
|
|
2331
|
+
type: "star",
|
|
2332
|
+
value,
|
|
2333
|
+
output: ""
|
|
2334
|
+
});
|
|
2335
|
+
continue;
|
|
2336
|
+
}
|
|
2337
|
+
while (rest.slice(0, 3) === "/**") {
|
|
2338
|
+
const after = input[state.index + 4];
|
|
2339
|
+
if (after && after !== "/") break;
|
|
2340
|
+
rest = rest.slice(3);
|
|
2341
|
+
consume("/**", 3);
|
|
2342
|
+
}
|
|
2343
|
+
if (prior.type === "bos" && eos()) {
|
|
2344
|
+
prev.type = "globstar";
|
|
2345
|
+
prev.value += value;
|
|
2346
|
+
prev.output = globstar(opts);
|
|
2347
|
+
state.output = prev.output;
|
|
2348
|
+
state.globstar = true;
|
|
2349
|
+
consume(value);
|
|
2350
|
+
continue;
|
|
2351
|
+
}
|
|
2352
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
2353
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
2354
|
+
prior.output = `(?:${prior.output}`;
|
|
2355
|
+
prev.type = "globstar";
|
|
2356
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
2357
|
+
prev.value += value;
|
|
2358
|
+
state.globstar = true;
|
|
2359
|
+
state.output += prior.output + prev.output;
|
|
2360
|
+
consume(value);
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
2364
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
2365
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
2366
|
+
prior.output = `(?:${prior.output}`;
|
|
2367
|
+
prev.type = "globstar";
|
|
2368
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
2369
|
+
prev.value += value;
|
|
2370
|
+
state.output += prior.output + prev.output;
|
|
2371
|
+
state.globstar = true;
|
|
2372
|
+
consume(value + advance());
|
|
2373
|
+
push({
|
|
2374
|
+
type: "slash",
|
|
2375
|
+
value: "/",
|
|
2376
|
+
output: ""
|
|
2377
|
+
});
|
|
2378
|
+
continue;
|
|
2379
|
+
}
|
|
2380
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
2381
|
+
prev.type = "globstar";
|
|
2382
|
+
prev.value += value;
|
|
2383
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
2384
|
+
state.output = prev.output;
|
|
2385
|
+
state.globstar = true;
|
|
2386
|
+
consume(value + advance());
|
|
2387
|
+
push({
|
|
2388
|
+
type: "slash",
|
|
2389
|
+
value: "/",
|
|
2390
|
+
output: ""
|
|
2391
|
+
});
|
|
2392
|
+
continue;
|
|
2393
|
+
}
|
|
2394
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
2395
|
+
prev.type = "globstar";
|
|
2396
|
+
prev.output = globstar(opts);
|
|
2397
|
+
prev.value += value;
|
|
2398
|
+
state.output += prev.output;
|
|
2399
|
+
state.globstar = true;
|
|
2400
|
+
consume(value);
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
const token = {
|
|
2404
|
+
type: "star",
|
|
2405
|
+
value,
|
|
2406
|
+
output: star
|
|
2407
|
+
};
|
|
2408
|
+
if (opts.bash === true) {
|
|
2409
|
+
token.output = ".*?";
|
|
2410
|
+
if (prev.type === "bos" || prev.type === "slash") token.output = nodot + token.output;
|
|
2411
|
+
push(token);
|
|
2412
|
+
continue;
|
|
2413
|
+
}
|
|
2414
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
2415
|
+
token.output = value;
|
|
2416
|
+
push(token);
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
2420
|
+
if (prev.type === "dot") {
|
|
2421
|
+
state.output += NO_DOT_SLASH;
|
|
2422
|
+
prev.output += NO_DOT_SLASH;
|
|
2423
|
+
} else if (opts.dot === true) {
|
|
2424
|
+
state.output += NO_DOTS_SLASH;
|
|
2425
|
+
prev.output += NO_DOTS_SLASH;
|
|
2426
|
+
} else {
|
|
2427
|
+
state.output += nodot;
|
|
2428
|
+
prev.output += nodot;
|
|
2429
|
+
}
|
|
2430
|
+
if (peek() !== "*") {
|
|
2431
|
+
state.output += ONE_CHAR;
|
|
2432
|
+
prev.output += ONE_CHAR;
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
push(token);
|
|
2436
|
+
}
|
|
2437
|
+
while (state.brackets > 0) {
|
|
2438
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
2439
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
2440
|
+
decrement("brackets");
|
|
2441
|
+
}
|
|
2442
|
+
while (state.parens > 0) {
|
|
2443
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
2444
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
2445
|
+
decrement("parens");
|
|
2446
|
+
}
|
|
2447
|
+
while (state.braces > 0) {
|
|
2448
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
2449
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
2450
|
+
decrement("braces");
|
|
2451
|
+
}
|
|
2452
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) push({
|
|
2453
|
+
type: "maybe_slash",
|
|
2454
|
+
value: "",
|
|
2455
|
+
output: `${SLASH_LITERAL}?`
|
|
2456
|
+
});
|
|
2457
|
+
if (state.backtrack === true) {
|
|
2458
|
+
state.output = "";
|
|
2459
|
+
for (const token of state.tokens) {
|
|
2460
|
+
state.output += token.output != null ? token.output : token.value;
|
|
2461
|
+
if (token.suffix) state.output += token.suffix;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
return state;
|
|
2465
|
+
};
|
|
2466
|
+
/**
|
|
2467
|
+
* Fast paths for creating regular expressions for common glob patterns.
|
|
2468
|
+
* This can significantly speed up processing and has very little downside
|
|
2469
|
+
* impact when none of the fast paths match.
|
|
2470
|
+
*/
|
|
2471
|
+
parse.fastpaths = (input, options) => {
|
|
2472
|
+
const opts = { ...options };
|
|
2473
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
2474
|
+
const len = input.length;
|
|
2475
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
2476
|
+
input = REPLACEMENTS[input] || input;
|
|
2477
|
+
const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants.globChars(opts.windows);
|
|
2478
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
2479
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
2480
|
+
const capture = opts.capture ? "" : "?:";
|
|
2481
|
+
const state = {
|
|
2482
|
+
negated: false,
|
|
2483
|
+
prefix: ""
|
|
2484
|
+
};
|
|
2485
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
2486
|
+
if (opts.capture) star = `(${star})`;
|
|
2487
|
+
const globstar = (opts) => {
|
|
2488
|
+
if (opts.noglobstar === true) return star;
|
|
2489
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
2490
|
+
};
|
|
2491
|
+
const create = (str) => {
|
|
2492
|
+
switch (str) {
|
|
2493
|
+
case "*": return `${nodot}${ONE_CHAR}${star}`;
|
|
2494
|
+
case ".*": return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2495
|
+
case "*.*": return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2496
|
+
case "*/*": return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
2497
|
+
case "**": return nodot + globstar(opts);
|
|
2498
|
+
case "**/*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
2499
|
+
case "**/*.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2500
|
+
case "**/.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2501
|
+
default: {
|
|
2502
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
2503
|
+
if (!match) return;
|
|
2504
|
+
const source = create(match[1]);
|
|
2505
|
+
if (!source) return;
|
|
2506
|
+
return source + DOT_LITERAL + match[2];
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
};
|
|
2510
|
+
let source = create(utils.removePrefix(input, state));
|
|
2511
|
+
if (source && opts.strictSlashes !== true) source += `${SLASH_LITERAL}?`;
|
|
2512
|
+
return source;
|
|
2513
|
+
};
|
|
2514
|
+
module.exports = parse;
|
|
2515
|
+
}));
|
|
2516
|
+
//#endregion
|
|
2517
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/picomatch.js
|
|
2518
|
+
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
2519
|
+
const scan = require_scan();
|
|
2520
|
+
const parse = require_parse();
|
|
2521
|
+
const utils = require_utils();
|
|
2522
|
+
const constants = require_constants();
|
|
2523
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
2524
|
+
/**
|
|
2525
|
+
* Creates a matcher function from one or more glob patterns. The
|
|
2526
|
+
* returned function takes a string to match as its first argument,
|
|
2527
|
+
* and returns true if the string is a match. The returned matcher
|
|
2528
|
+
* function also takes a boolean as the second argument that, when true,
|
|
2529
|
+
* returns an object with additional information.
|
|
2530
|
+
*
|
|
2531
|
+
* ```js
|
|
2532
|
+
* const picomatch = require('picomatch');
|
|
2533
|
+
* // picomatch(glob[, options]);
|
|
2534
|
+
*
|
|
2535
|
+
* const isMatch = picomatch('*.!(*a)');
|
|
2536
|
+
* console.log(isMatch('a.a')); //=> false
|
|
2537
|
+
* console.log(isMatch('a.b')); //=> true
|
|
2538
|
+
* ```
|
|
2539
|
+
* @name picomatch
|
|
2540
|
+
* @param {String|Array} `globs` One or more glob patterns.
|
|
2541
|
+
* @param {Object=} `options`
|
|
2542
|
+
* @return {Function=} Returns a matcher function.
|
|
2543
|
+
* @api public
|
|
2544
|
+
*/
|
|
2545
|
+
const picomatch = (glob, options, returnState = false) => {
|
|
2546
|
+
if (Array.isArray(glob)) {
|
|
2547
|
+
const fns = glob.map((input) => picomatch(input, options, returnState));
|
|
2548
|
+
const arrayMatcher = (str) => {
|
|
2549
|
+
for (const isMatch of fns) {
|
|
2550
|
+
const state = isMatch(str);
|
|
2551
|
+
if (state) return state;
|
|
2552
|
+
}
|
|
2553
|
+
return false;
|
|
2554
|
+
};
|
|
2555
|
+
return arrayMatcher;
|
|
2556
|
+
}
|
|
2557
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
2558
|
+
if (glob === "" || typeof glob !== "string" && !isState) throw new TypeError("Expected pattern to be a non-empty string");
|
|
2559
|
+
const opts = options || {};
|
|
2560
|
+
const posix = opts.windows;
|
|
2561
|
+
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
2562
|
+
const state = regex.state;
|
|
2563
|
+
delete regex.state;
|
|
2564
|
+
let isIgnored = () => false;
|
|
2565
|
+
if (opts.ignore) {
|
|
2566
|
+
const ignoreOpts = {
|
|
2567
|
+
...options,
|
|
2568
|
+
ignore: null,
|
|
2569
|
+
onMatch: null,
|
|
2570
|
+
onResult: null
|
|
2571
|
+
};
|
|
2572
|
+
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
2573
|
+
}
|
|
2574
|
+
const matcher = (input, returnObject = false) => {
|
|
2575
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, {
|
|
2576
|
+
glob,
|
|
2577
|
+
posix
|
|
2578
|
+
});
|
|
2579
|
+
const result = {
|
|
2580
|
+
glob,
|
|
2581
|
+
state,
|
|
2582
|
+
regex,
|
|
2583
|
+
posix,
|
|
2584
|
+
input,
|
|
2585
|
+
output,
|
|
2586
|
+
match,
|
|
2587
|
+
isMatch
|
|
2588
|
+
};
|
|
2589
|
+
if (typeof opts.onResult === "function") opts.onResult(result);
|
|
2590
|
+
if (isMatch === false) {
|
|
2591
|
+
result.isMatch = false;
|
|
2592
|
+
return returnObject ? result : false;
|
|
2593
|
+
}
|
|
2594
|
+
if (isIgnored(input)) {
|
|
2595
|
+
if (typeof opts.onIgnore === "function") opts.onIgnore(result);
|
|
2596
|
+
result.isMatch = false;
|
|
2597
|
+
return returnObject ? result : false;
|
|
2598
|
+
}
|
|
2599
|
+
if (typeof opts.onMatch === "function") opts.onMatch(result);
|
|
2600
|
+
return returnObject ? result : true;
|
|
2601
|
+
};
|
|
2602
|
+
if (returnState) matcher.state = state;
|
|
2603
|
+
return matcher;
|
|
2604
|
+
};
|
|
2605
|
+
/**
|
|
2606
|
+
* Test `input` with the given `regex`. This is used by the main
|
|
2607
|
+
* `picomatch()` function to test the input string.
|
|
2608
|
+
*
|
|
2609
|
+
* ```js
|
|
2610
|
+
* const picomatch = require('picomatch');
|
|
2611
|
+
* // picomatch.test(input, regex[, options]);
|
|
2612
|
+
*
|
|
2613
|
+
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
2614
|
+
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
2615
|
+
* ```
|
|
2616
|
+
* @param {String} `input` String to test.
|
|
2617
|
+
* @param {RegExp} `regex`
|
|
2618
|
+
* @return {Object} Returns an object with matching info.
|
|
2619
|
+
* @api public
|
|
2620
|
+
*/
|
|
2621
|
+
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2622
|
+
if (typeof input !== "string") throw new TypeError("Expected input to be a string");
|
|
2623
|
+
if (input === "") return {
|
|
2624
|
+
isMatch: false,
|
|
2625
|
+
output: ""
|
|
2626
|
+
};
|
|
2627
|
+
const opts = options || {};
|
|
2628
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
2629
|
+
let match = input === glob;
|
|
2630
|
+
let output = match && format ? format(input) : input;
|
|
2631
|
+
if (match === false) {
|
|
2632
|
+
output = format ? format(input) : input;
|
|
2633
|
+
match = output === glob;
|
|
2634
|
+
}
|
|
2635
|
+
if (match === false || opts.capture === true) if (opts.matchBase === true || opts.basename === true) match = picomatch.matchBase(input, regex, options, posix);
|
|
2636
|
+
else match = regex.exec(output);
|
|
2637
|
+
return {
|
|
2638
|
+
isMatch: Boolean(match),
|
|
2639
|
+
match,
|
|
2640
|
+
output
|
|
2641
|
+
};
|
|
2642
|
+
};
|
|
2643
|
+
/**
|
|
2644
|
+
* Match the basename of a filepath.
|
|
2645
|
+
*
|
|
2646
|
+
* ```js
|
|
2647
|
+
* const picomatch = require('picomatch');
|
|
2648
|
+
* // picomatch.matchBase(input, glob[, options]);
|
|
2649
|
+
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
2650
|
+
* ```
|
|
2651
|
+
* @param {String} `input` String to test.
|
|
2652
|
+
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
2653
|
+
* @return {Boolean}
|
|
2654
|
+
* @api public
|
|
2655
|
+
*/
|
|
2656
|
+
picomatch.matchBase = (input, glob, options) => {
|
|
2657
|
+
return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(utils.basename(input));
|
|
2658
|
+
};
|
|
2659
|
+
/**
|
|
2660
|
+
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
2661
|
+
*
|
|
2662
|
+
* ```js
|
|
2663
|
+
* const picomatch = require('picomatch');
|
|
2664
|
+
* // picomatch.isMatch(string, patterns[, options]);
|
|
2665
|
+
*
|
|
2666
|
+
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
2667
|
+
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
2668
|
+
* ```
|
|
2669
|
+
* @param {String|Array} str The string to test.
|
|
2670
|
+
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
2671
|
+
* @param {Object} [options] See available [options](#options).
|
|
2672
|
+
* @return {Boolean} Returns true if any patterns match `str`
|
|
2673
|
+
* @api public
|
|
2674
|
+
*/
|
|
2675
|
+
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
2676
|
+
/**
|
|
2677
|
+
* Parse a glob pattern to create the source string for a regular
|
|
2678
|
+
* expression.
|
|
2679
|
+
*
|
|
2680
|
+
* ```js
|
|
2681
|
+
* const picomatch = require('picomatch');
|
|
2682
|
+
* const result = picomatch.parse(pattern[, options]);
|
|
2683
|
+
* ```
|
|
2684
|
+
* @param {String} `pattern`
|
|
2685
|
+
* @param {Object} `options`
|
|
2686
|
+
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
2687
|
+
* @api public
|
|
2688
|
+
*/
|
|
2689
|
+
picomatch.parse = (pattern, options) => {
|
|
2690
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
|
|
2691
|
+
return parse(pattern, {
|
|
2692
|
+
...options,
|
|
2693
|
+
fastpaths: false
|
|
2694
|
+
});
|
|
2695
|
+
};
|
|
2696
|
+
/**
|
|
2697
|
+
* Scan a glob pattern to separate the pattern into segments.
|
|
2698
|
+
*
|
|
2699
|
+
* ```js
|
|
2700
|
+
* const picomatch = require('picomatch');
|
|
2701
|
+
* // picomatch.scan(input[, options]);
|
|
2702
|
+
*
|
|
2703
|
+
* const result = picomatch.scan('!./foo/*.js');
|
|
2704
|
+
* console.log(result);
|
|
2705
|
+
* { prefix: '!./',
|
|
2706
|
+
* input: '!./foo/*.js',
|
|
2707
|
+
* start: 3,
|
|
2708
|
+
* base: 'foo',
|
|
2709
|
+
* glob: '*.js',
|
|
2710
|
+
* isBrace: false,
|
|
2711
|
+
* isBracket: false,
|
|
2712
|
+
* isGlob: true,
|
|
2713
|
+
* isExtglob: false,
|
|
2714
|
+
* isGlobstar: false,
|
|
2715
|
+
* negated: true }
|
|
2716
|
+
* ```
|
|
2717
|
+
* @param {String} `input` Glob pattern to scan.
|
|
2718
|
+
* @param {Object} `options`
|
|
2719
|
+
* @return {Object} Returns an object with
|
|
2720
|
+
* @api public
|
|
2721
|
+
*/
|
|
2722
|
+
picomatch.scan = (input, options) => scan(input, options);
|
|
2723
|
+
/**
|
|
2724
|
+
* Compile a regular expression from the `state` object returned by the
|
|
2725
|
+
* [parse()](#parse) method.
|
|
2726
|
+
*
|
|
2727
|
+
* ```js
|
|
2728
|
+
* const picomatch = require('picomatch');
|
|
2729
|
+
* const state = picomatch.parse('*.js');
|
|
2730
|
+
* // picomatch.compileRe(state[, options]);
|
|
2731
|
+
*
|
|
2732
|
+
* console.log(picomatch.compileRe(state));
|
|
2733
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2734
|
+
* ```
|
|
2735
|
+
* @param {Object} `state`
|
|
2736
|
+
* @param {Object} `options`
|
|
2737
|
+
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
2738
|
+
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
2739
|
+
* @return {RegExp}
|
|
2740
|
+
* @api public
|
|
2741
|
+
*/
|
|
2742
|
+
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
2743
|
+
if (returnOutput === true) return state.output;
|
|
2744
|
+
const opts = options || {};
|
|
2745
|
+
const prepend = opts.contains ? "" : "^";
|
|
2746
|
+
const append = opts.contains ? "" : "$";
|
|
2747
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
2748
|
+
if (state && state.negated === true) source = `^(?!${source}).*$`;
|
|
2749
|
+
const regex = picomatch.toRegex(source, options);
|
|
2750
|
+
if (returnState === true) regex.state = state;
|
|
2751
|
+
return regex;
|
|
2752
|
+
};
|
|
2753
|
+
/**
|
|
2754
|
+
* Create a regular expression from a parsed glob pattern.
|
|
2755
|
+
*
|
|
2756
|
+
* ```js
|
|
2757
|
+
* const picomatch = require('picomatch');
|
|
2758
|
+
* // picomatch.makeRe(state[, options]);
|
|
2759
|
+
*
|
|
2760
|
+
* const result = picomatch.makeRe('*.js');
|
|
2761
|
+
* console.log(result);
|
|
2762
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2763
|
+
* ```
|
|
2764
|
+
* @param {String} `state` The object returned from the `.parse` method.
|
|
2765
|
+
* @param {Object} `options`
|
|
2766
|
+
* @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.
|
|
2767
|
+
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
2768
|
+
* @return {RegExp} Returns a regex created from the given pattern.
|
|
2769
|
+
* @api public
|
|
2770
|
+
*/
|
|
2771
|
+
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
2772
|
+
if (!input || typeof input !== "string") throw new TypeError("Expected a non-empty string");
|
|
2773
|
+
let parsed = {
|
|
2774
|
+
negated: false,
|
|
2775
|
+
fastpaths: true
|
|
2776
|
+
};
|
|
2777
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) parsed.output = parse.fastpaths(input, options);
|
|
2778
|
+
if (!parsed.output) parsed = parse(input, options);
|
|
2779
|
+
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
2780
|
+
};
|
|
2781
|
+
/**
|
|
2782
|
+
* Create a regular expression from the given regex source string.
|
|
2783
|
+
*
|
|
2784
|
+
* ```js
|
|
2785
|
+
* const picomatch = require('picomatch');
|
|
2786
|
+
* // picomatch.toRegex(source[, options]);
|
|
2787
|
+
*
|
|
2788
|
+
* const { output } = picomatch.parse('*.js');
|
|
2789
|
+
* console.log(picomatch.toRegex(output));
|
|
2790
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2791
|
+
* ```
|
|
2792
|
+
* @param {String} `source` Regular expression source string.
|
|
2793
|
+
* @param {Object} `options`
|
|
2794
|
+
* @return {RegExp}
|
|
2795
|
+
* @api public
|
|
2796
|
+
*/
|
|
2797
|
+
picomatch.toRegex = (source, options) => {
|
|
2798
|
+
try {
|
|
2799
|
+
const opts = options || {};
|
|
2800
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
2801
|
+
} catch (err) {
|
|
2802
|
+
if (options && options.debug === true) throw err;
|
|
2803
|
+
return /$^/;
|
|
2804
|
+
}
|
|
2805
|
+
};
|
|
2806
|
+
/**
|
|
2807
|
+
* Picomatch constants.
|
|
2808
|
+
* @return {Object}
|
|
2809
|
+
*/
|
|
2810
|
+
picomatch.constants = constants;
|
|
2811
|
+
/**
|
|
2812
|
+
* Expose "picomatch"
|
|
2813
|
+
*/
|
|
2814
|
+
module.exports = picomatch;
|
|
2815
|
+
}));
|
|
2816
|
+
//#endregion
|
|
935
2817
|
//#region ../core/dist/index.js
|
|
2818
|
+
var import_picomatch = /* @__PURE__ */ __toESM$1((/* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
2819
|
+
const pico = require_picomatch$1();
|
|
2820
|
+
const utils = require_utils();
|
|
2821
|
+
function picomatch(glob, options, returnState = false) {
|
|
2822
|
+
if (options && (options.windows === null || options.windows === void 0)) options = {
|
|
2823
|
+
...options,
|
|
2824
|
+
windows: utils.isWindows()
|
|
2825
|
+
};
|
|
2826
|
+
return pico(glob, options, returnState);
|
|
2827
|
+
}
|
|
2828
|
+
Object.assign(picomatch, pico);
|
|
2829
|
+
module.exports = picomatch;
|
|
2830
|
+
})))(), 1);
|
|
936
2831
|
var __create = Object.create;
|
|
937
2832
|
var __defProp = Object.defineProperty;
|
|
938
2833
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -954,30 +2849,53 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
954
2849
|
value: mod,
|
|
955
2850
|
enumerable: true
|
|
956
2851
|
}) : target, mod));
|
|
957
|
-
const
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
2852
|
+
const JSX_FILE_PATTERN = /\.(tsx|jsx)$/;
|
|
2853
|
+
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
2854
|
+
const FETCH_TIMEOUT_MS = 1e4;
|
|
2855
|
+
const DEFAULT_BRANCH_CANDIDATES = ["main", "master"];
|
|
2856
|
+
const ADOPTABLE_LINT_CONFIG_FILENAMES = [".oxlintrc.json", ".eslintrc.json"];
|
|
2857
|
+
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
2858
|
+
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
2859
|
+
var InvalidGlobPatternError = class extends Error {
|
|
2860
|
+
pattern;
|
|
2861
|
+
reason;
|
|
2862
|
+
constructor(pattern, reason) {
|
|
2863
|
+
super(`Invalid glob pattern ${JSON.stringify(pattern)}: ${reason}`);
|
|
2864
|
+
this.name = "InvalidGlobPatternError";
|
|
2865
|
+
this.pattern = pattern;
|
|
2866
|
+
this.reason = reason;
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
const assertGlobPattern = (condition, pattern, reason) => {
|
|
2870
|
+
if (!condition) throw new InvalidGlobPatternError(pattern, reason);
|
|
2871
|
+
};
|
|
2872
|
+
const countGlobWildcards = (pattern) => (pattern.match(/[*?]/g) ?? []).length;
|
|
2873
|
+
const normalizeGlobPattern = (pattern) => pattern.replace(/\\/g, "/").replace(/^\//, "");
|
|
2874
|
+
const PICOMATCH_OPTIONS = {
|
|
2875
|
+
dot: true,
|
|
2876
|
+
strictSlashes: false,
|
|
2877
|
+
windows: false
|
|
2878
|
+
};
|
|
2879
|
+
const compileGlobPattern = (rawPattern) => {
|
|
2880
|
+
assertGlobPattern(typeof rawPattern === "string" && rawPattern.length > 0, String(rawPattern), "pattern must be a non-empty string.");
|
|
2881
|
+
assertGlobPattern(rawPattern.length <= MAX_GLOB_PATTERN_LENGTH_CHARS, rawPattern, `pattern length ${rawPattern.length} exceeds the maximum of ${MAX_GLOB_PATTERN_LENGTH_CHARS} characters.`);
|
|
2882
|
+
const wildcardCount = countGlobWildcards(rawPattern);
|
|
2883
|
+
assertGlobPattern(wildcardCount <= 24, rawPattern, `pattern uses ${wildcardCount} wildcards (\`*\` / \`?\`), exceeding the maximum of 24. This guards against catastrophic backtracking from pathological patterns; split the pattern into multiple smaller entries.`);
|
|
2884
|
+
try {
|
|
2885
|
+
return import_picomatch.default.makeRe(normalizeGlobPattern(rawPattern), PICOMATCH_OPTIONS);
|
|
2886
|
+
} catch (caughtError) {
|
|
2887
|
+
throw new InvalidGlobPatternError(rawPattern, caughtError instanceof Error ? caughtError.message : String(caughtError));
|
|
2888
|
+
}
|
|
2889
|
+
};
|
|
2890
|
+
const compileGlobPatternsLenient = (patterns, onInvalid) => {
|
|
2891
|
+
const compiled = [];
|
|
2892
|
+
for (const pattern of patterns) try {
|
|
2893
|
+
compiled.push(compileGlobPattern(pattern));
|
|
2894
|
+
} catch (caughtError) {
|
|
2895
|
+
if (!(caughtError instanceof InvalidGlobPatternError)) throw caughtError;
|
|
2896
|
+
onInvalid(caughtError);
|
|
978
2897
|
}
|
|
979
|
-
|
|
980
|
-
return new RegExp(regexSource);
|
|
2898
|
+
return compiled;
|
|
981
2899
|
};
|
|
982
2900
|
const toRelativePath = (filePath, rootDirectory) => {
|
|
983
2901
|
const normalizedFilePath = filePath.replace(/\\/g, "/");
|
|
@@ -985,22 +2903,22 @@ const toRelativePath = (filePath, rootDirectory) => {
|
|
|
985
2903
|
if (normalizedFilePath.startsWith(normalizedRoot)) return normalizedFilePath.slice(normalizedRoot.length);
|
|
986
2904
|
return normalizedFilePath.replace(/^\.\//, "");
|
|
987
2905
|
};
|
|
988
|
-
const
|
|
2906
|
+
const warnConfigIssue = (message) => {
|
|
989
2907
|
process.stderr.write(`[react-doctor] ${message}\n`);
|
|
990
2908
|
};
|
|
991
2909
|
const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
992
2910
|
const collectStringList = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
993
2911
|
const validateOverrideEntry = (entry, index) => {
|
|
994
2912
|
if (!isPlainObject(entry)) {
|
|
995
|
-
|
|
2913
|
+
warnConfigIssue(`ignore.overrides[${index}] must be an object with { files, rules }; ignoring this entry.`);
|
|
996
2914
|
return null;
|
|
997
2915
|
}
|
|
998
2916
|
if (!isStringArray(entry.files)) {
|
|
999
|
-
|
|
2917
|
+
warnConfigIssue(`ignore.overrides[${index}].files must be an array of strings; ignoring this entry.`);
|
|
1000
2918
|
return null;
|
|
1001
2919
|
}
|
|
1002
2920
|
if (entry.rules !== void 0 && !isStringArray(entry.rules)) {
|
|
1003
|
-
|
|
2921
|
+
warnConfigIssue(`ignore.overrides[${index}].rules must be an array of "plugin/rule" strings or omitted; treating as missing (override would suppress every rule for the matched files).`);
|
|
1004
2922
|
return { files: entry.files };
|
|
1005
2923
|
}
|
|
1006
2924
|
return entry.rules === void 0 ? { files: entry.files } : {
|
|
@@ -1012,13 +2930,13 @@ const compileIgnoreOverrides = (userConfig) => {
|
|
|
1012
2930
|
const overrides = userConfig?.ignore?.overrides;
|
|
1013
2931
|
if (overrides === void 0) return [];
|
|
1014
2932
|
if (!Array.isArray(overrides)) {
|
|
1015
|
-
|
|
2933
|
+
warnConfigIssue(`ignore.overrides must be an array of { files, rules } entries; ignoring.`);
|
|
1016
2934
|
return [];
|
|
1017
2935
|
}
|
|
1018
2936
|
return overrides.flatMap((entry, index) => {
|
|
1019
2937
|
const validated = validateOverrideEntry(entry, index);
|
|
1020
2938
|
if (!validated) return [];
|
|
1021
|
-
const filePatterns = collectStringList(validated.files)
|
|
2939
|
+
const filePatterns = compileGlobPatternsLenient(collectStringList(validated.files), (error) => warnConfigIssue(`ignore.overrides[${index}]: ${error.message}`));
|
|
1022
2940
|
if (filePatterns.length === 0) return [];
|
|
1023
2941
|
return [{
|
|
1024
2942
|
filePatterns,
|
|
@@ -1032,12 +2950,94 @@ const isDiagnosticIgnoredByOverrides = (diagnostic, rootDirectory, overrides) =>
|
|
|
1032
2950
|
const ruleIdentifier = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
1033
2951
|
return overrides.some((override) => override.filePatterns.some((pattern) => pattern.test(relativeFilePath)) && (override.ruleIds.size === 0 || override.ruleIds.has(ruleIdentifier)));
|
|
1034
2952
|
};
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
2953
|
+
/**
|
|
2954
|
+
* Assembles the internal `RuleSeverityControls` shape from a user
|
|
2955
|
+
* config's top-level `rules` and `categories` fields — the
|
|
2956
|
+
* ESLint / oxlint-shaped severity surface.
|
|
2957
|
+
*
|
|
2958
|
+
* Returns `undefined` when neither field is present so the common
|
|
2959
|
+
* path (no severity config at all) stays allocation-free for
|
|
2960
|
+
* downstream consumers.
|
|
2961
|
+
*/
|
|
2962
|
+
const buildRuleSeverityControls = (config) => {
|
|
2963
|
+
if (!config) return void 0;
|
|
2964
|
+
if (config.rules === void 0 && config.categories === void 0) return void 0;
|
|
2965
|
+
return {
|
|
2966
|
+
...config.rules !== void 0 ? { rules: config.rules } : {},
|
|
2967
|
+
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2968
|
+
};
|
|
2969
|
+
};
|
|
2970
|
+
/**
|
|
2971
|
+
* Projects a diagnostic onto the three axes rule-targeted controls
|
|
2972
|
+
* reason about:
|
|
2973
|
+
*
|
|
2974
|
+
* - `ruleKey` — the fully-qualified `"<plugin>/<rule>"` form users
|
|
2975
|
+
* put in config files (consumed by top-level `rules` severity and
|
|
2976
|
+
* `surfaces.*.{include,exclude}Rules`).
|
|
2977
|
+
* - `category` — the diagnostic's category label (consumed by
|
|
2978
|
+
* top-level `categories` severity and
|
|
2979
|
+
* `surfaces.*.{include,exclude}Categories`).
|
|
2980
|
+
* - `tags` — behavioral tags from the rule registry (consumed by
|
|
2981
|
+
* `ignore.tags` and `surfaces.*.{include,exclude}Tags`). Empty
|
|
2982
|
+
* for non-`react-doctor` plugins.
|
|
2983
|
+
*/
|
|
2984
|
+
const getDiagnosticRuleIdentity = (diagnostic) => ({
|
|
2985
|
+
ruleKey: `${diagnostic.plugin}/${diagnostic.rule}`,
|
|
2986
|
+
category: diagnostic.category,
|
|
2987
|
+
tags: diagnostic.plugin === "react-doctor" ? reactDoctorPlugin.rules[diagnostic.rule]?.tags ?? [] : []
|
|
2988
|
+
});
|
|
2989
|
+
/**
|
|
2990
|
+
* Resolves the user-configured severity override for a rule.
|
|
2991
|
+
* Per-rule overrides win over per-category overrides. Returns
|
|
2992
|
+
* `undefined` when neither channel matches — callers should fall
|
|
2993
|
+
* back to the rule's built-in severity.
|
|
2994
|
+
*/
|
|
2995
|
+
const resolveRuleSeverityOverride = (input, controls) => {
|
|
2996
|
+
if (!controls) return void 0;
|
|
2997
|
+
return controls.rules?.[input.ruleKey] ?? (input.category !== void 0 ? controls.categories?.[input.category] : void 0);
|
|
2998
|
+
};
|
|
2999
|
+
const SEVERITY_FOR_OVERRIDE = {
|
|
3000
|
+
error: "error",
|
|
3001
|
+
warn: "warning"
|
|
3002
|
+
};
|
|
3003
|
+
const restampSeverity = (diagnostic, override) => {
|
|
3004
|
+
const targetSeverity = SEVERITY_FOR_OVERRIDE[override];
|
|
3005
|
+
if (diagnostic.severity === targetSeverity) return diagnostic;
|
|
3006
|
+
return {
|
|
3007
|
+
...diagnostic,
|
|
3008
|
+
severity: targetSeverity
|
|
3009
|
+
};
|
|
3010
|
+
};
|
|
3011
|
+
/**
|
|
3012
|
+
* Applies the user's top-level `rules` / `categories` / `tags`
|
|
3013
|
+
* severity config to a post-lint diagnostic list:
|
|
3014
|
+
*
|
|
3015
|
+
* - `"off"` drops the diagnostic entirely. For react-doctor rules
|
|
3016
|
+
* this also happens at lint-registration time; this post-filter
|
|
3017
|
+
* covers external plugins (`react/*`, `jsx-a11y/*`, custom adopted
|
|
3018
|
+
* configs) whose severities the lint config can't reach.
|
|
3019
|
+
* - `"warn"` / `"error"` re-stamps `diagnostic.severity` so downstream
|
|
3020
|
+
* consumers — `--fail-on`, the score input, the CLI summary — see
|
|
3021
|
+
* the user-chosen severity rather than the rule's built-in one.
|
|
3022
|
+
*
|
|
3023
|
+
* Returns the input array by identity when no controls are configured
|
|
3024
|
+
* so the common path stays allocation-free.
|
|
3025
|
+
*/
|
|
3026
|
+
const applySeverityControls = (diagnostics, config) => {
|
|
3027
|
+
const controls = buildRuleSeverityControls(config);
|
|
3028
|
+
if (!controls) return diagnostics;
|
|
3029
|
+
const adjusted = [];
|
|
3030
|
+
for (const diagnostic of diagnostics) {
|
|
3031
|
+
const { ruleKey, category } = getDiagnosticRuleIdentity(diagnostic);
|
|
3032
|
+
const override = resolveRuleSeverityOverride({
|
|
3033
|
+
ruleKey,
|
|
3034
|
+
category
|
|
3035
|
+
}, controls);
|
|
3036
|
+
if (override === "off") continue;
|
|
3037
|
+
adjusted.push(override === void 0 ? diagnostic : restampSeverity(diagnostic, override));
|
|
3038
|
+
}
|
|
3039
|
+
return adjusted;
|
|
3040
|
+
};
|
|
1041
3041
|
const estimateArgsLength = (args) => args.reduce((total, argument) => total + argument.length + 1, 0);
|
|
1042
3042
|
const batchIncludePaths = (baseArgs, includePaths) => {
|
|
1043
3043
|
const baseArgsLength = estimateArgsLength(baseArgs);
|
|
@@ -1709,7 +3709,7 @@ const evaluateSuppression = (lines, diagnosticLineIndex, ruleId) => {
|
|
|
1709
3709
|
const compileIgnoredFilePatterns = (userConfig) => {
|
|
1710
3710
|
const files = userConfig?.ignore?.files;
|
|
1711
3711
|
if (!Array.isArray(files)) return [];
|
|
1712
|
-
return files.filter((entry) => typeof entry === "string")
|
|
3712
|
+
return compileGlobPatternsLenient(files.filter((entry) => typeof entry === "string"), (error) => warnConfigIssue(`ignore.files: ${error.message}`));
|
|
1713
3713
|
};
|
|
1714
3714
|
const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
|
|
1715
3715
|
if (patterns.length === 0) return false;
|
|
@@ -1873,8 +3873,8 @@ const shouldAutoSuppress = (diagnostic) => {
|
|
|
1873
3873
|
return false;
|
|
1874
3874
|
};
|
|
1875
3875
|
const mergeAndFilterDiagnostics = (mergedDiagnostics, directory, userConfig, readFileLinesSync, options = {}) => {
|
|
1876
|
-
const
|
|
1877
|
-
const filtered = userConfig ? filterIgnoredDiagnostics(
|
|
3876
|
+
const severityAdjusted = applySeverityControls(mergedDiagnostics.filter((diagnostic) => !shouldAutoSuppress(diagnostic)), userConfig);
|
|
3877
|
+
const filtered = userConfig ? filterIgnoredDiagnostics(severityAdjusted, userConfig, directory, readFileLinesSync) : severityAdjusted;
|
|
1878
3878
|
if (options.respectInlineDisables === false) return filtered;
|
|
1879
3879
|
return filterInlineSuppressions(filtered, directory, readFileLinesSync);
|
|
1880
3880
|
};
|
|
@@ -2028,6 +4028,11 @@ const getDiffInfo = (directory, explicitBaseBranch) => {
|
|
|
2028
4028
|
};
|
|
2029
4029
|
const filterSourceFiles = (filePaths) => filePaths.filter((filePath) => SOURCE_FILE_PATTERN.test(filePath));
|
|
2030
4030
|
const computeJsxIncludePaths = (includePaths) => includePaths.length > 0 ? includePaths.filter((filePath) => JSX_FILE_PATTERN.test(filePath)) : void 0;
|
|
4031
|
+
const VALID_RULE_SEVERITIES = [
|
|
4032
|
+
"error",
|
|
4033
|
+
"warn",
|
|
4034
|
+
"off"
|
|
4035
|
+
];
|
|
2031
4036
|
const BOOLEAN_FIELD_NAMES = [
|
|
2032
4037
|
"lint",
|
|
2033
4038
|
"verbose",
|
|
@@ -2038,18 +4043,27 @@ const BOOLEAN_FIELD_NAMES = [
|
|
|
2038
4043
|
"offline"
|
|
2039
4044
|
];
|
|
2040
4045
|
const STRING_FIELD_NAMES = ["rootDir"];
|
|
4046
|
+
const SURFACE_CONTROL_FIELD_NAMES = [
|
|
4047
|
+
"includeTags",
|
|
4048
|
+
"excludeTags",
|
|
4049
|
+
"includeCategories",
|
|
4050
|
+
"excludeCategories",
|
|
4051
|
+
"includeRules",
|
|
4052
|
+
"excludeRules"
|
|
4053
|
+
];
|
|
4054
|
+
const SEVERITY_FIELD_NAMES = ["rules", "categories"];
|
|
2041
4055
|
const warnConfigField = (message) => {
|
|
2042
4056
|
process.stderr.write(`[react-doctor] ${message}\n`);
|
|
2043
4057
|
};
|
|
4058
|
+
const isPlainObject$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4059
|
+
const formatType = (value) => typeof value === "string" ? `"${value}"` : typeof value;
|
|
4060
|
+
const isRuleSeverity = (value) => typeof value === "string" && VALID_RULE_SEVERITIES.includes(value);
|
|
2044
4061
|
const coerceMaybeBooleanString = (fieldName, value) => {
|
|
2045
|
-
if (typeof value === "boolean"
|
|
2046
|
-
if (value === "true") {
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
if (value === "false") {
|
|
2051
|
-
warnConfigField(`config field "${fieldName}" is the string "false"; treating as boolean false.`);
|
|
2052
|
-
return false;
|
|
4062
|
+
if (typeof value === "boolean") return value;
|
|
4063
|
+
if (value === "true" || value === "false") {
|
|
4064
|
+
const coerced = value === "true";
|
|
4065
|
+
warnConfigField(`config field "${fieldName}" is the string "${value}"; treating as boolean ${coerced}.`);
|
|
4066
|
+
return coerced;
|
|
2053
4067
|
}
|
|
2054
4068
|
warnConfigField(`config field "${fieldName}" must be a boolean (got ${typeof value}); ignoring this field.`);
|
|
2055
4069
|
};
|
|
@@ -2057,47 +4071,32 @@ const validateString = (fieldName, value) => {
|
|
|
2057
4071
|
if (typeof value === "string") return value;
|
|
2058
4072
|
warnConfigField(`config field "${fieldName}" must be a string (got ${typeof value}); ignoring this field.`);
|
|
2059
4073
|
};
|
|
2060
|
-
const SURFACE_CONTROL_FIELD_NAMES = [
|
|
2061
|
-
"includeTags",
|
|
2062
|
-
"excludeTags",
|
|
2063
|
-
"includeCategories",
|
|
2064
|
-
"excludeCategories",
|
|
2065
|
-
"includeRules",
|
|
2066
|
-
"excludeRules"
|
|
2067
|
-
];
|
|
2068
4074
|
const validateStringArrayField = (fieldName, value) => {
|
|
2069
|
-
if (value === void 0) return void 0;
|
|
2070
4075
|
if (!Array.isArray(value)) {
|
|
2071
4076
|
warnConfigField(`config field "${fieldName}" must be an array of strings (got ${typeof value}); ignoring this field.`);
|
|
2072
4077
|
return;
|
|
2073
4078
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2080
|
-
collected.push(entry);
|
|
2081
|
-
}
|
|
2082
|
-
return collected;
|
|
4079
|
+
return value.filter((entry) => {
|
|
4080
|
+
if (typeof entry === "string") return true;
|
|
4081
|
+
warnConfigField(`config field "${fieldName}" contains a non-string entry (${typeof entry}); ignoring the entry.`);
|
|
4082
|
+
return false;
|
|
4083
|
+
});
|
|
2083
4084
|
};
|
|
2084
4085
|
const validateSurfaceControls = (surface, rawControls) => {
|
|
2085
|
-
if (rawControls
|
|
2086
|
-
if (typeof rawControls !== "object" || rawControls === null || Array.isArray(rawControls)) {
|
|
4086
|
+
if (!isPlainObject$1(rawControls)) {
|
|
2087
4087
|
warnConfigField(`config field "surfaces.${surface}" must be an object (got ${typeof rawControls}); ignoring this surface.`);
|
|
2088
4088
|
return;
|
|
2089
4089
|
}
|
|
2090
4090
|
const validated = {};
|
|
2091
4091
|
for (const fieldName of SURFACE_CONTROL_FIELD_NAMES) {
|
|
2092
|
-
|
|
2093
|
-
const
|
|
2094
|
-
if (
|
|
4092
|
+
if (rawControls[fieldName] === void 0) continue;
|
|
4093
|
+
const result = validateStringArrayField(`surfaces.${surface}.${fieldName}`, rawControls[fieldName]);
|
|
4094
|
+
if (result !== void 0) validated[fieldName] = result;
|
|
2095
4095
|
}
|
|
2096
4096
|
return validated;
|
|
2097
4097
|
};
|
|
2098
4098
|
const validateSurfacesField = (rawSurfaces) => {
|
|
2099
|
-
if (rawSurfaces
|
|
2100
|
-
if (typeof rawSurfaces !== "object" || rawSurfaces === null || Array.isArray(rawSurfaces)) {
|
|
4099
|
+
if (!isPlainObject$1(rawSurfaces)) {
|
|
2101
4100
|
warnConfigField(`config field "surfaces" must be an object (got ${typeof rawSurfaces}); ignoring this field.`);
|
|
2102
4101
|
return;
|
|
2103
4102
|
}
|
|
@@ -2112,27 +4111,38 @@ const validateSurfacesField = (rawSurfaces) => {
|
|
|
2112
4111
|
}
|
|
2113
4112
|
return validated;
|
|
2114
4113
|
};
|
|
4114
|
+
const validateSeverityMap = (fieldName, rawMap) => {
|
|
4115
|
+
if (!isPlainObject$1(rawMap)) {
|
|
4116
|
+
warnConfigField(`config field "${fieldName}" must be an object (got ${typeof rawMap}); ignoring this field.`);
|
|
4117
|
+
return;
|
|
4118
|
+
}
|
|
4119
|
+
const validated = {};
|
|
4120
|
+
for (const [key, value] of Object.entries(rawMap)) {
|
|
4121
|
+
if (key.length === 0) {
|
|
4122
|
+
warnConfigField(`config field "${fieldName}" has an empty key; ignoring the entry.`);
|
|
4123
|
+
continue;
|
|
4124
|
+
}
|
|
4125
|
+
if (!isRuleSeverity(value)) {
|
|
4126
|
+
warnConfigField(`config field "${fieldName}.${key}" must be one of: ${VALID_RULE_SEVERITIES.join(", ")} (got ${formatType(value)}); ignoring the entry.`);
|
|
4127
|
+
continue;
|
|
4128
|
+
}
|
|
4129
|
+
validated[key] = value;
|
|
4130
|
+
}
|
|
4131
|
+
return validated;
|
|
4132
|
+
};
|
|
4133
|
+
const applyFieldValidator = (config, validated, fieldName, validator) => {
|
|
4134
|
+
const raw = config[fieldName];
|
|
4135
|
+
if (raw === void 0) return;
|
|
4136
|
+
const result = validator(raw);
|
|
4137
|
+
if (result === void 0) delete validated[fieldName];
|
|
4138
|
+
else validated[fieldName] = result;
|
|
4139
|
+
};
|
|
2115
4140
|
const validateConfigTypes = (config) => {
|
|
2116
4141
|
const validated = { ...config };
|
|
2117
|
-
for (const fieldName of BOOLEAN_FIELD_NAMES)
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
if (coerced === void 0) delete validated[fieldName];
|
|
2122
|
-
else validated[fieldName] = coerced;
|
|
2123
|
-
}
|
|
2124
|
-
for (const fieldName of STRING_FIELD_NAMES) {
|
|
2125
|
-
const original = config[fieldName];
|
|
2126
|
-
if (original === void 0) continue;
|
|
2127
|
-
const validatedString = validateString(fieldName, original);
|
|
2128
|
-
if (validatedString === void 0) delete validated[fieldName];
|
|
2129
|
-
else validated[fieldName] = validatedString;
|
|
2130
|
-
}
|
|
2131
|
-
if (config.surfaces !== void 0) {
|
|
2132
|
-
const validatedSurfaces = validateSurfacesField(config.surfaces);
|
|
2133
|
-
if (validatedSurfaces === void 0) delete validated.surfaces;
|
|
2134
|
-
else validated.surfaces = validatedSurfaces;
|
|
2135
|
-
}
|
|
4142
|
+
for (const fieldName of BOOLEAN_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => coerceMaybeBooleanString(fieldName, value));
|
|
4143
|
+
for (const fieldName of STRING_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateString(fieldName, value));
|
|
4144
|
+
applyFieldValidator(config, validated, "surfaces", validateSurfacesField);
|
|
4145
|
+
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value));
|
|
2136
4146
|
return validated;
|
|
2137
4147
|
};
|
|
2138
4148
|
const CONFIG_FILENAME = "react-doctor.config.json";
|
|
@@ -2452,69 +4462,11 @@ const filterRulesToAvailable = (rules, pluginNamespace, availableRuleNames) => {
|
|
|
2452
4462
|
}
|
|
2453
4463
|
return filtered;
|
|
2454
4464
|
};
|
|
2455
|
-
const REACT_COMPILER_RULES = {
|
|
2456
|
-
"react-hooks-js/set-state-in-render": "error",
|
|
2457
|
-
"react-hooks-js/immutability": "error",
|
|
2458
|
-
"react-hooks-js/refs": "error",
|
|
2459
|
-
"react-hooks-js/purity": "error",
|
|
2460
|
-
"react-hooks-js/hooks": "error",
|
|
2461
|
-
"react-hooks-js/set-state-in-effect": "error",
|
|
2462
|
-
"react-hooks-js/globals": "error",
|
|
2463
|
-
"react-hooks-js/error-boundaries": "error",
|
|
2464
|
-
"react-hooks-js/preserve-manual-memoization": "error",
|
|
2465
|
-
"react-hooks-js/unsupported-syntax": "error",
|
|
2466
|
-
"react-hooks-js/component-hook-factories": "error",
|
|
2467
|
-
"react-hooks-js/static-components": "error",
|
|
2468
|
-
"react-hooks-js/use-memo": "error",
|
|
2469
|
-
"react-hooks-js/void-use-memo": "error",
|
|
2470
|
-
"react-hooks-js/incompatible-library": "error",
|
|
2471
|
-
"react-hooks-js/todo": "error"
|
|
2472
|
-
};
|
|
2473
|
-
const YOU_MIGHT_NOT_NEED_EFFECT_RULES = {
|
|
2474
|
-
"effect/no-derived-state": "warn",
|
|
2475
|
-
"effect/no-chain-state-updates": "warn",
|
|
2476
|
-
"effect/no-event-handler": "warn",
|
|
2477
|
-
"effect/no-adjust-state-on-prop-change": "warn",
|
|
2478
|
-
"effect/no-reset-all-state-on-prop-change": "warn",
|
|
2479
|
-
"effect/no-pass-live-state-to-parent": "warn",
|
|
2480
|
-
"effect/no-pass-data-to-parent": "warn",
|
|
2481
|
-
"effect/no-initialize-state": "warn"
|
|
2482
|
-
};
|
|
2483
|
-
const BUILTIN_REACT_RULES = {
|
|
2484
|
-
"react/rules-of-hooks": "error",
|
|
2485
|
-
"react/no-direct-mutation-state": "error",
|
|
2486
|
-
"react/jsx-no-duplicate-props": "error",
|
|
2487
|
-
"react/jsx-key": "error",
|
|
2488
|
-
"react/no-children-prop": "warn",
|
|
2489
|
-
"react/no-danger": "warn",
|
|
2490
|
-
"react/jsx-no-script-url": "error",
|
|
2491
|
-
"react/no-render-return-value": "warn",
|
|
2492
|
-
"react/no-string-refs": "warn",
|
|
2493
|
-
"react/no-is-mounted": "warn",
|
|
2494
|
-
"react/require-render-return": "error",
|
|
2495
|
-
"react/no-unknown-property": "warn"
|
|
2496
|
-
};
|
|
2497
|
-
const BUILTIN_A11Y_RULES = {
|
|
2498
|
-
"jsx-a11y/alt-text": "error",
|
|
2499
|
-
"jsx-a11y/anchor-is-valid": "warn",
|
|
2500
|
-
"jsx-a11y/click-events-have-key-events": "warn",
|
|
2501
|
-
"jsx-a11y/no-static-element-interactions": "warn",
|
|
2502
|
-
"jsx-a11y/role-has-required-aria-props": "error",
|
|
2503
|
-
"jsx-a11y/no-autofocus": "warn",
|
|
2504
|
-
"jsx-a11y/heading-has-content": "warn",
|
|
2505
|
-
"jsx-a11y/html-has-lang": "warn",
|
|
2506
|
-
"jsx-a11y/no-redundant-roles": "warn",
|
|
2507
|
-
"jsx-a11y/scope": "warn",
|
|
2508
|
-
"jsx-a11y/tabindex-no-positive": "warn",
|
|
2509
|
-
"jsx-a11y/label-has-associated-control": "warn",
|
|
2510
|
-
"jsx-a11y/no-distracting-elements": "error",
|
|
2511
|
-
"jsx-a11y/iframe-has-title": "warn"
|
|
2512
|
-
};
|
|
2513
4465
|
const resolveSettingsRootDirectory = (rootDirectory) => {
|
|
2514
4466
|
if (!fs.existsSync(rootDirectory)) return rootDirectory;
|
|
2515
4467
|
return fs.realpathSync(rootDirectory);
|
|
2516
4468
|
};
|
|
2517
|
-
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames }) => {
|
|
4469
|
+
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames, severityControls }) => {
|
|
2518
4470
|
const reactHooksJsPlugin = resolveReactHooksJsPlugin(project.hasReactCompiler, customRulesOnly);
|
|
2519
4471
|
const reactCompilerRules = reactHooksJsPlugin ? filterRulesToAvailable(REACT_COMPILER_RULES, "react-hooks-js", reactHooksJsPlugin.availableRuleNames) : {};
|
|
2520
4472
|
const youMightNotNeedEffectPlugin = resolveYouMightNotNeedEffectPlugin(customRulesOnly);
|
|
@@ -2528,7 +4480,12 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
2528
4480
|
const fullKey = `react-doctor/${ruleId}`;
|
|
2529
4481
|
if (rule.framework !== "global" && !rule.requires) continue;
|
|
2530
4482
|
if (!shouldEnableRule(rule.requires, rule.tags, capabilities, ignoredTags)) continue;
|
|
2531
|
-
|
|
4483
|
+
const severity = resolveRuleSeverityOverride({
|
|
4484
|
+
ruleKey: fullKey,
|
|
4485
|
+
category: rule.category
|
|
4486
|
+
}, severityControls) ?? rule.severity;
|
|
4487
|
+
if (severity === "off") continue;
|
|
4488
|
+
enabledReactDoctorRules[fullKey] = severity;
|
|
2532
4489
|
}
|
|
2533
4490
|
return {
|
|
2534
4491
|
...extendsPaths.length > 0 ? { extends: extendsPaths } : {},
|
|
@@ -3062,6 +5019,7 @@ const validateRuleRegistration = () => {
|
|
|
3062
5019
|
const runOxlint = async (options) => {
|
|
3063
5020
|
const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), userConfig, onPartialFailure } = options;
|
|
3064
5021
|
const serverAuthFunctionNames = Array.isArray(userConfig?.serverAuthFunctionNames) ? userConfig.serverAuthFunctionNames.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
5022
|
+
const severityControls = buildRuleSeverityControls(userConfig);
|
|
3065
5023
|
validateRuleRegistration();
|
|
3066
5024
|
if (includePaths !== void 0 && includePaths.length === 0) return [];
|
|
3067
5025
|
const configDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
@@ -3074,7 +5032,8 @@ const runOxlint = async (options) => {
|
|
|
3074
5032
|
customRulesOnly,
|
|
3075
5033
|
extendsPaths,
|
|
3076
5034
|
ignoredTags,
|
|
3077
|
-
serverAuthFunctionNames
|
|
5035
|
+
serverAuthFunctionNames,
|
|
5036
|
+
severityControls
|
|
3078
5037
|
});
|
|
3079
5038
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
3080
5039
|
try {
|
|
@@ -3142,7 +5101,8 @@ const runOxlint = async (options) => {
|
|
|
3142
5101
|
customRulesOnly,
|
|
3143
5102
|
extendsPaths: [],
|
|
3144
5103
|
ignoredTags,
|
|
3145
|
-
serverAuthFunctionNames
|
|
5104
|
+
serverAuthFunctionNames,
|
|
5105
|
+
severityControls
|
|
3146
5106
|
}));
|
|
3147
5107
|
return await spawnLintBatches();
|
|
3148
5108
|
}
|