react-doctor 0.2.0-beta.5 → 0.2.0-beta.6
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 +94 -8
- package/dist/cli.js +1919 -187
- package/dist/index.d.ts +55 -0
- package/dist/index.js +1896 -153
- package/dist/skills/react-doctor/SKILL.md +4 -4
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2,9 +2,33 @@ 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
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
31
|
+
//#endregion
|
|
8
32
|
//#region ../types/dist/index.js
|
|
9
33
|
const REACT_NATIVE_DEPENDENCY_NAMES = new Set([
|
|
10
34
|
"react-native",
|
|
@@ -932,7 +956,1661 @@ const isTailwindAtLeast = (detected, required) => {
|
|
|
932
956
|
return detected.minor >= required.minor;
|
|
933
957
|
};
|
|
934
958
|
//#endregion
|
|
959
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/constants.js
|
|
960
|
+
var require_constants = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
961
|
+
const path$3 = __require("path");
|
|
962
|
+
const WIN_SLASH = "\\\\/";
|
|
963
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
964
|
+
/**
|
|
965
|
+
* Posix glob regex
|
|
966
|
+
*/
|
|
967
|
+
const DOT_LITERAL = "\\.";
|
|
968
|
+
const PLUS_LITERAL = "\\+";
|
|
969
|
+
const QMARK_LITERAL = "\\?";
|
|
970
|
+
const SLASH_LITERAL = "\\/";
|
|
971
|
+
const ONE_CHAR = "(?=.)";
|
|
972
|
+
const QMARK = "[^/]";
|
|
973
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
974
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
975
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
976
|
+
const POSIX_CHARS = {
|
|
977
|
+
DOT_LITERAL,
|
|
978
|
+
PLUS_LITERAL,
|
|
979
|
+
QMARK_LITERAL,
|
|
980
|
+
SLASH_LITERAL,
|
|
981
|
+
ONE_CHAR,
|
|
982
|
+
QMARK,
|
|
983
|
+
END_ANCHOR,
|
|
984
|
+
DOTS_SLASH,
|
|
985
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
986
|
+
NO_DOTS: `(?!${START_ANCHOR}${DOTS_SLASH})`,
|
|
987
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`,
|
|
988
|
+
NO_DOTS_SLASH: `(?!${DOTS_SLASH})`,
|
|
989
|
+
QMARK_NO_DOT: `[^.${SLASH_LITERAL}]`,
|
|
990
|
+
STAR: `${QMARK}*?`,
|
|
991
|
+
START_ANCHOR
|
|
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
|
+
};
|
|
1010
|
+
module.exports = {
|
|
1011
|
+
MAX_LENGTH: 1024 * 64,
|
|
1012
|
+
POSIX_REGEX_SOURCE: {
|
|
1013
|
+
alnum: "a-zA-Z0-9",
|
|
1014
|
+
alpha: "a-zA-Z",
|
|
1015
|
+
ascii: "\\x00-\\x7F",
|
|
1016
|
+
blank: " \\t",
|
|
1017
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
1018
|
+
digit: "0-9",
|
|
1019
|
+
graph: "\\x21-\\x7E",
|
|
1020
|
+
lower: "a-z",
|
|
1021
|
+
print: "\\x20-\\x7E ",
|
|
1022
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
1023
|
+
space: " \\t\\r\\n\\v\\f",
|
|
1024
|
+
upper: "A-Z",
|
|
1025
|
+
word: "A-Za-z0-9_",
|
|
1026
|
+
xdigit: "A-Fa-f0-9"
|
|
1027
|
+
},
|
|
1028
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
1029
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
1030
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
1031
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
1032
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
1033
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
1034
|
+
REPLACEMENTS: {
|
|
1035
|
+
"***": "*",
|
|
1036
|
+
"**/**": "**",
|
|
1037
|
+
"**/**/**": "**"
|
|
1038
|
+
},
|
|
1039
|
+
CHAR_0: 48,
|
|
1040
|
+
CHAR_9: 57,
|
|
1041
|
+
CHAR_UPPERCASE_A: 65,
|
|
1042
|
+
CHAR_LOWERCASE_A: 97,
|
|
1043
|
+
CHAR_UPPERCASE_Z: 90,
|
|
1044
|
+
CHAR_LOWERCASE_Z: 122,
|
|
1045
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
1046
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
1047
|
+
CHAR_ASTERISK: 42,
|
|
1048
|
+
CHAR_AMPERSAND: 38,
|
|
1049
|
+
CHAR_AT: 64,
|
|
1050
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
1051
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
1052
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
1053
|
+
CHAR_COLON: 58,
|
|
1054
|
+
CHAR_COMMA: 44,
|
|
1055
|
+
CHAR_DOT: 46,
|
|
1056
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
1057
|
+
CHAR_EQUAL: 61,
|
|
1058
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
1059
|
+
CHAR_FORM_FEED: 12,
|
|
1060
|
+
CHAR_FORWARD_SLASH: 47,
|
|
1061
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
1062
|
+
CHAR_HASH: 35,
|
|
1063
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
1064
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
1065
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
1066
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
1067
|
+
CHAR_LINE_FEED: 10,
|
|
1068
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
1069
|
+
CHAR_PERCENT: 37,
|
|
1070
|
+
CHAR_PLUS: 43,
|
|
1071
|
+
CHAR_QUESTION_MARK: 63,
|
|
1072
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
1073
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
1074
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
1075
|
+
CHAR_SEMICOLON: 59,
|
|
1076
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
1077
|
+
CHAR_SPACE: 32,
|
|
1078
|
+
CHAR_TAB: 9,
|
|
1079
|
+
CHAR_UNDERSCORE: 95,
|
|
1080
|
+
CHAR_VERTICAL_LINE: 124,
|
|
1081
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
1082
|
+
SEP: path$3.sep,
|
|
1083
|
+
/**
|
|
1084
|
+
* Create EXTGLOB_CHARS
|
|
1085
|
+
*/
|
|
1086
|
+
extglobChars(chars) {
|
|
1087
|
+
return {
|
|
1088
|
+
"!": {
|
|
1089
|
+
type: "negate",
|
|
1090
|
+
open: "(?:(?!(?:",
|
|
1091
|
+
close: `))${chars.STAR})`
|
|
1092
|
+
},
|
|
1093
|
+
"?": {
|
|
1094
|
+
type: "qmark",
|
|
1095
|
+
open: "(?:",
|
|
1096
|
+
close: ")?"
|
|
1097
|
+
},
|
|
1098
|
+
"+": {
|
|
1099
|
+
type: "plus",
|
|
1100
|
+
open: "(?:",
|
|
1101
|
+
close: ")+"
|
|
1102
|
+
},
|
|
1103
|
+
"*": {
|
|
1104
|
+
type: "star",
|
|
1105
|
+
open: "(?:",
|
|
1106
|
+
close: ")*"
|
|
1107
|
+
},
|
|
1108
|
+
"@": {
|
|
1109
|
+
type: "at",
|
|
1110
|
+
open: "(?:",
|
|
1111
|
+
close: ")"
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
},
|
|
1115
|
+
/**
|
|
1116
|
+
* Create GLOB_CHARS
|
|
1117
|
+
*/
|
|
1118
|
+
globChars(win32) {
|
|
1119
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
}));
|
|
1123
|
+
//#endregion
|
|
1124
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/utils.js
|
|
1125
|
+
var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
1126
|
+
const path$2 = __require("path");
|
|
1127
|
+
const win32 = process.platform === "win32";
|
|
1128
|
+
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
1129
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
1130
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
1131
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
1132
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
1133
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
1134
|
+
exports.removeBackslashes = (str) => {
|
|
1135
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
1136
|
+
return match === "\\" ? "" : match;
|
|
1137
|
+
});
|
|
1138
|
+
};
|
|
1139
|
+
exports.supportsLookbehinds = () => {
|
|
1140
|
+
const segs = process.version.slice(1).split(".").map(Number);
|
|
1141
|
+
if (segs.length === 3 && segs[0] >= 9 || segs[0] === 8 && segs[1] >= 10) return true;
|
|
1142
|
+
return false;
|
|
1143
|
+
};
|
|
1144
|
+
exports.isWindows = (options) => {
|
|
1145
|
+
if (options && typeof options.windows === "boolean") return options.windows;
|
|
1146
|
+
return win32 === true || path$2.sep === "\\";
|
|
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
|
+
}));
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/scan.js
|
|
1170
|
+
var require_scan = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1171
|
+
const utils = require_utils();
|
|
1172
|
+
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();
|
|
1173
|
+
const isPathSeparator = (code) => {
|
|
1174
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
1175
|
+
};
|
|
1176
|
+
const depth = (token) => {
|
|
1177
|
+
if (token.isPrefix !== true) token.depth = token.isGlobstar ? Infinity : 1;
|
|
1178
|
+
};
|
|
1179
|
+
/**
|
|
1180
|
+
* Quickly scans a glob pattern and returns an object with a handful of
|
|
1181
|
+
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
1182
|
+
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
1183
|
+
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
1184
|
+
*
|
|
1185
|
+
* ```js
|
|
1186
|
+
* const pm = require('picomatch');
|
|
1187
|
+
* console.log(pm.scan('foo/bar/*.js'));
|
|
1188
|
+
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
1189
|
+
* ```
|
|
1190
|
+
* @param {String} `str`
|
|
1191
|
+
* @param {Object} `options`
|
|
1192
|
+
* @return {Object} Returns an object with tokens and regex source string.
|
|
1193
|
+
* @api public
|
|
1194
|
+
*/
|
|
1195
|
+
const scan = (input, options) => {
|
|
1196
|
+
const opts = options || {};
|
|
1197
|
+
const length = input.length - 1;
|
|
1198
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
1199
|
+
const slashes = [];
|
|
1200
|
+
const tokens = [];
|
|
1201
|
+
const parts = [];
|
|
1202
|
+
let str = input;
|
|
1203
|
+
let index = -1;
|
|
1204
|
+
let start = 0;
|
|
1205
|
+
let lastIndex = 0;
|
|
1206
|
+
let isBrace = false;
|
|
1207
|
+
let isBracket = false;
|
|
1208
|
+
let isGlob = false;
|
|
1209
|
+
let isExtglob = false;
|
|
1210
|
+
let isGlobstar = false;
|
|
1211
|
+
let braceEscaped = false;
|
|
1212
|
+
let backslashes = false;
|
|
1213
|
+
let negated = false;
|
|
1214
|
+
let negatedExtglob = false;
|
|
1215
|
+
let finished = false;
|
|
1216
|
+
let braces = 0;
|
|
1217
|
+
let prev;
|
|
1218
|
+
let code;
|
|
1219
|
+
let token = {
|
|
1220
|
+
value: "",
|
|
1221
|
+
depth: 0,
|
|
1222
|
+
isGlob: false
|
|
1223
|
+
};
|
|
1224
|
+
const eos = () => index >= length;
|
|
1225
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
1226
|
+
const advance = () => {
|
|
1227
|
+
prev = code;
|
|
1228
|
+
return str.charCodeAt(++index);
|
|
1229
|
+
};
|
|
1230
|
+
while (index < length) {
|
|
1231
|
+
code = advance();
|
|
1232
|
+
let next;
|
|
1233
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1234
|
+
backslashes = token.backslashes = true;
|
|
1235
|
+
code = advance();
|
|
1236
|
+
if (code === CHAR_LEFT_CURLY_BRACE) braceEscaped = true;
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
1240
|
+
braces++;
|
|
1241
|
+
while (eos() !== true && (code = advance())) {
|
|
1242
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1243
|
+
backslashes = token.backslashes = true;
|
|
1244
|
+
advance();
|
|
1245
|
+
continue;
|
|
1246
|
+
}
|
|
1247
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
1248
|
+
braces++;
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
1252
|
+
isBrace = token.isBrace = true;
|
|
1253
|
+
isGlob = token.isGlob = true;
|
|
1254
|
+
finished = true;
|
|
1255
|
+
if (scanToEnd === true) continue;
|
|
1256
|
+
break;
|
|
1257
|
+
}
|
|
1258
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
1259
|
+
isBrace = token.isBrace = true;
|
|
1260
|
+
isGlob = token.isGlob = true;
|
|
1261
|
+
finished = true;
|
|
1262
|
+
if (scanToEnd === true) continue;
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1265
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
1266
|
+
braces--;
|
|
1267
|
+
if (braces === 0) {
|
|
1268
|
+
braceEscaped = false;
|
|
1269
|
+
isBrace = token.isBrace = true;
|
|
1270
|
+
finished = true;
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
if (scanToEnd === true) continue;
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
1279
|
+
slashes.push(index);
|
|
1280
|
+
tokens.push(token);
|
|
1281
|
+
token = {
|
|
1282
|
+
value: "",
|
|
1283
|
+
depth: 0,
|
|
1284
|
+
isGlob: false
|
|
1285
|
+
};
|
|
1286
|
+
if (finished === true) continue;
|
|
1287
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
1288
|
+
start += 2;
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
lastIndex = index + 1;
|
|
1292
|
+
continue;
|
|
1293
|
+
}
|
|
1294
|
+
if (opts.noext !== true) {
|
|
1295
|
+
if ((code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK) === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
1296
|
+
isGlob = token.isGlob = true;
|
|
1297
|
+
isExtglob = token.isExtglob = true;
|
|
1298
|
+
finished = true;
|
|
1299
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
|
|
1300
|
+
if (scanToEnd === true) {
|
|
1301
|
+
while (eos() !== true && (code = advance())) {
|
|
1302
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1303
|
+
backslashes = token.backslashes = true;
|
|
1304
|
+
code = advance();
|
|
1305
|
+
continue;
|
|
1306
|
+
}
|
|
1307
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1308
|
+
isGlob = token.isGlob = true;
|
|
1309
|
+
finished = true;
|
|
1310
|
+
break;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
break;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
if (code === CHAR_ASTERISK) {
|
|
1319
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
1320
|
+
isGlob = token.isGlob = true;
|
|
1321
|
+
finished = true;
|
|
1322
|
+
if (scanToEnd === true) continue;
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
1326
|
+
isGlob = token.isGlob = true;
|
|
1327
|
+
finished = true;
|
|
1328
|
+
if (scanToEnd === true) continue;
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
1332
|
+
while (eos() !== true && (next = advance())) {
|
|
1333
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
1334
|
+
backslashes = token.backslashes = true;
|
|
1335
|
+
advance();
|
|
1336
|
+
continue;
|
|
1337
|
+
}
|
|
1338
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
1339
|
+
isBracket = token.isBracket = true;
|
|
1340
|
+
isGlob = token.isGlob = true;
|
|
1341
|
+
finished = true;
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
if (scanToEnd === true) continue;
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
1349
|
+
negated = token.negated = true;
|
|
1350
|
+
start++;
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
1354
|
+
isGlob = token.isGlob = true;
|
|
1355
|
+
if (scanToEnd === true) {
|
|
1356
|
+
while (eos() !== true && (code = advance())) {
|
|
1357
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
1358
|
+
backslashes = token.backslashes = true;
|
|
1359
|
+
code = advance();
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1363
|
+
finished = true;
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
continue;
|
|
1368
|
+
}
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
if (isGlob === true) {
|
|
1372
|
+
finished = true;
|
|
1373
|
+
if (scanToEnd === true) continue;
|
|
1374
|
+
break;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
if (opts.noext === true) {
|
|
1378
|
+
isExtglob = false;
|
|
1379
|
+
isGlob = false;
|
|
1380
|
+
}
|
|
1381
|
+
let base = str;
|
|
1382
|
+
let prefix = "";
|
|
1383
|
+
let glob = "";
|
|
1384
|
+
if (start > 0) {
|
|
1385
|
+
prefix = str.slice(0, start);
|
|
1386
|
+
str = str.slice(start);
|
|
1387
|
+
lastIndex -= start;
|
|
1388
|
+
}
|
|
1389
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
1390
|
+
base = str.slice(0, lastIndex);
|
|
1391
|
+
glob = str.slice(lastIndex);
|
|
1392
|
+
} else if (isGlob === true) {
|
|
1393
|
+
base = "";
|
|
1394
|
+
glob = str;
|
|
1395
|
+
} else base = str;
|
|
1396
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
1397
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) base = base.slice(0, -1);
|
|
1398
|
+
}
|
|
1399
|
+
if (opts.unescape === true) {
|
|
1400
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
1401
|
+
if (base && backslashes === true) base = utils.removeBackslashes(base);
|
|
1402
|
+
}
|
|
1403
|
+
const state = {
|
|
1404
|
+
prefix,
|
|
1405
|
+
input,
|
|
1406
|
+
start,
|
|
1407
|
+
base,
|
|
1408
|
+
glob,
|
|
1409
|
+
isBrace,
|
|
1410
|
+
isBracket,
|
|
1411
|
+
isGlob,
|
|
1412
|
+
isExtglob,
|
|
1413
|
+
isGlobstar,
|
|
1414
|
+
negated,
|
|
1415
|
+
negatedExtglob
|
|
1416
|
+
};
|
|
1417
|
+
if (opts.tokens === true) {
|
|
1418
|
+
state.maxDepth = 0;
|
|
1419
|
+
if (!isPathSeparator(code)) tokens.push(token);
|
|
1420
|
+
state.tokens = tokens;
|
|
1421
|
+
}
|
|
1422
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
1423
|
+
let prevIndex;
|
|
1424
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
1425
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
1426
|
+
const i = slashes[idx];
|
|
1427
|
+
const value = input.slice(n, i);
|
|
1428
|
+
if (opts.tokens) {
|
|
1429
|
+
if (idx === 0 && start !== 0) {
|
|
1430
|
+
tokens[idx].isPrefix = true;
|
|
1431
|
+
tokens[idx].value = prefix;
|
|
1432
|
+
} else tokens[idx].value = value;
|
|
1433
|
+
depth(tokens[idx]);
|
|
1434
|
+
state.maxDepth += tokens[idx].depth;
|
|
1435
|
+
}
|
|
1436
|
+
if (idx !== 0 || value !== "") parts.push(value);
|
|
1437
|
+
prevIndex = i;
|
|
1438
|
+
}
|
|
1439
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
1440
|
+
const value = input.slice(prevIndex + 1);
|
|
1441
|
+
parts.push(value);
|
|
1442
|
+
if (opts.tokens) {
|
|
1443
|
+
tokens[tokens.length - 1].value = value;
|
|
1444
|
+
depth(tokens[tokens.length - 1]);
|
|
1445
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
state.slashes = slashes;
|
|
1449
|
+
state.parts = parts;
|
|
1450
|
+
}
|
|
1451
|
+
return state;
|
|
1452
|
+
};
|
|
1453
|
+
module.exports = scan;
|
|
1454
|
+
}));
|
|
1455
|
+
//#endregion
|
|
1456
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/parse.js
|
|
1457
|
+
var require_parse = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1458
|
+
const constants = require_constants();
|
|
1459
|
+
const utils = require_utils();
|
|
1460
|
+
/**
|
|
1461
|
+
* Constants
|
|
1462
|
+
*/
|
|
1463
|
+
const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants;
|
|
1464
|
+
/**
|
|
1465
|
+
* Helpers
|
|
1466
|
+
*/
|
|
1467
|
+
const expandRange = (args, options) => {
|
|
1468
|
+
if (typeof options.expandRange === "function") return options.expandRange(...args, options);
|
|
1469
|
+
args.sort();
|
|
1470
|
+
const value = `[${args.join("-")}]`;
|
|
1471
|
+
try {
|
|
1472
|
+
new RegExp(value);
|
|
1473
|
+
} catch (ex) {
|
|
1474
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
1475
|
+
}
|
|
1476
|
+
return value;
|
|
1477
|
+
};
|
|
1478
|
+
/**
|
|
1479
|
+
* Create the message for a syntax error
|
|
1480
|
+
*/
|
|
1481
|
+
const syntaxError = (type, char) => {
|
|
1482
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
1483
|
+
};
|
|
1484
|
+
/**
|
|
1485
|
+
* Parse the given input string.
|
|
1486
|
+
* @param {String} input
|
|
1487
|
+
* @param {Object} options
|
|
1488
|
+
* @return {Object}
|
|
1489
|
+
*/
|
|
1490
|
+
const parse = (input, options) => {
|
|
1491
|
+
if (typeof input !== "string") throw new TypeError("Expected a string");
|
|
1492
|
+
input = REPLACEMENTS[input] || input;
|
|
1493
|
+
const opts = { ...options };
|
|
1494
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1495
|
+
let len = input.length;
|
|
1496
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1497
|
+
const bos = {
|
|
1498
|
+
type: "bos",
|
|
1499
|
+
value: "",
|
|
1500
|
+
output: opts.prepend || ""
|
|
1501
|
+
};
|
|
1502
|
+
const tokens = [bos];
|
|
1503
|
+
const capture = opts.capture ? "" : "?:";
|
|
1504
|
+
const win32 = utils.isWindows(options);
|
|
1505
|
+
const PLATFORM_CHARS = constants.globChars(win32);
|
|
1506
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
1507
|
+
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;
|
|
1508
|
+
const globstar = (opts) => {
|
|
1509
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1510
|
+
};
|
|
1511
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
1512
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
1513
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
1514
|
+
if (opts.capture) star = `(${star})`;
|
|
1515
|
+
if (typeof opts.noext === "boolean") opts.noextglob = opts.noext;
|
|
1516
|
+
const state = {
|
|
1517
|
+
input,
|
|
1518
|
+
index: -1,
|
|
1519
|
+
start: 0,
|
|
1520
|
+
dot: opts.dot === true,
|
|
1521
|
+
consumed: "",
|
|
1522
|
+
output: "",
|
|
1523
|
+
prefix: "",
|
|
1524
|
+
backtrack: false,
|
|
1525
|
+
negated: false,
|
|
1526
|
+
brackets: 0,
|
|
1527
|
+
braces: 0,
|
|
1528
|
+
parens: 0,
|
|
1529
|
+
quotes: 0,
|
|
1530
|
+
globstar: false,
|
|
1531
|
+
tokens
|
|
1532
|
+
};
|
|
1533
|
+
input = utils.removePrefix(input, state);
|
|
1534
|
+
len = input.length;
|
|
1535
|
+
const extglobs = [];
|
|
1536
|
+
const braces = [];
|
|
1537
|
+
const stack = [];
|
|
1538
|
+
let prev = bos;
|
|
1539
|
+
let value;
|
|
1540
|
+
/**
|
|
1541
|
+
* Tokenizing helpers
|
|
1542
|
+
*/
|
|
1543
|
+
const eos = () => state.index === len - 1;
|
|
1544
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
1545
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
1546
|
+
const remaining = () => input.slice(state.index + 1);
|
|
1547
|
+
const consume = (value = "", num = 0) => {
|
|
1548
|
+
state.consumed += value;
|
|
1549
|
+
state.index += num;
|
|
1550
|
+
};
|
|
1551
|
+
const append = (token) => {
|
|
1552
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1553
|
+
consume(token.value);
|
|
1554
|
+
};
|
|
1555
|
+
const negate = () => {
|
|
1556
|
+
let count = 1;
|
|
1557
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
1558
|
+
advance();
|
|
1559
|
+
state.start++;
|
|
1560
|
+
count++;
|
|
1561
|
+
}
|
|
1562
|
+
if (count % 2 === 0) return false;
|
|
1563
|
+
state.negated = true;
|
|
1564
|
+
state.start++;
|
|
1565
|
+
return true;
|
|
1566
|
+
};
|
|
1567
|
+
const increment = (type) => {
|
|
1568
|
+
state[type]++;
|
|
1569
|
+
stack.push(type);
|
|
1570
|
+
};
|
|
1571
|
+
const decrement = (type) => {
|
|
1572
|
+
state[type]--;
|
|
1573
|
+
stack.pop();
|
|
1574
|
+
};
|
|
1575
|
+
/**
|
|
1576
|
+
* Push tokens onto the tokens array. This helper speeds up
|
|
1577
|
+
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
1578
|
+
* and 2) helping us avoid creating extra tokens when consecutive
|
|
1579
|
+
* characters are plain text. This improves performance and simplifies
|
|
1580
|
+
* lookbehinds.
|
|
1581
|
+
*/
|
|
1582
|
+
const push = (tok) => {
|
|
1583
|
+
if (prev.type === "globstar") {
|
|
1584
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
1585
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
1586
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
1587
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1588
|
+
prev.type = "star";
|
|
1589
|
+
prev.value = "*";
|
|
1590
|
+
prev.output = star;
|
|
1591
|
+
state.output += prev.output;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (extglobs.length && tok.type !== "paren") extglobs[extglobs.length - 1].inner += tok.value;
|
|
1595
|
+
if (tok.value || tok.output) append(tok);
|
|
1596
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
1597
|
+
prev.value += tok.value;
|
|
1598
|
+
prev.output = (prev.output || "") + tok.value;
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
tok.prev = prev;
|
|
1602
|
+
tokens.push(tok);
|
|
1603
|
+
prev = tok;
|
|
1604
|
+
};
|
|
1605
|
+
const extglobOpen = (type, value) => {
|
|
1606
|
+
const token = {
|
|
1607
|
+
...EXTGLOB_CHARS[value],
|
|
1608
|
+
conditions: 1,
|
|
1609
|
+
inner: ""
|
|
1610
|
+
};
|
|
1611
|
+
token.prev = prev;
|
|
1612
|
+
token.parens = state.parens;
|
|
1613
|
+
token.output = state.output;
|
|
1614
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
1615
|
+
increment("parens");
|
|
1616
|
+
push({
|
|
1617
|
+
type,
|
|
1618
|
+
value,
|
|
1619
|
+
output: state.output ? "" : ONE_CHAR
|
|
1620
|
+
});
|
|
1621
|
+
push({
|
|
1622
|
+
type: "paren",
|
|
1623
|
+
extglob: true,
|
|
1624
|
+
value: advance(),
|
|
1625
|
+
output
|
|
1626
|
+
});
|
|
1627
|
+
extglobs.push(token);
|
|
1628
|
+
};
|
|
1629
|
+
const extglobClose = (token) => {
|
|
1630
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
1631
|
+
let rest;
|
|
1632
|
+
if (token.type === "negate") {
|
|
1633
|
+
let extglobStar = star;
|
|
1634
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) extglobStar = globstar(opts);
|
|
1635
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) output = token.close = `)$))${extglobStar}`;
|
|
1636
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) output = token.close = `)${parse(rest, {
|
|
1637
|
+
...options,
|
|
1638
|
+
fastpaths: false
|
|
1639
|
+
}).output})${extglobStar})`;
|
|
1640
|
+
if (token.prev.type === "bos") state.negatedExtglob = true;
|
|
1641
|
+
}
|
|
1642
|
+
push({
|
|
1643
|
+
type: "paren",
|
|
1644
|
+
extglob: true,
|
|
1645
|
+
value,
|
|
1646
|
+
output
|
|
1647
|
+
});
|
|
1648
|
+
decrement("parens");
|
|
1649
|
+
};
|
|
1650
|
+
/**
|
|
1651
|
+
* Fast paths
|
|
1652
|
+
*/
|
|
1653
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
1654
|
+
let backslashes = false;
|
|
1655
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
1656
|
+
if (first === "\\") {
|
|
1657
|
+
backslashes = true;
|
|
1658
|
+
return m;
|
|
1659
|
+
}
|
|
1660
|
+
if (first === "?") {
|
|
1661
|
+
if (esc) return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
1662
|
+
if (index === 0) return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
1663
|
+
return QMARK.repeat(chars.length);
|
|
1664
|
+
}
|
|
1665
|
+
if (first === ".") return DOT_LITERAL.repeat(chars.length);
|
|
1666
|
+
if (first === "*") {
|
|
1667
|
+
if (esc) return esc + first + (rest ? star : "");
|
|
1668
|
+
return star;
|
|
1669
|
+
}
|
|
1670
|
+
return esc ? m : `\\${m}`;
|
|
1671
|
+
});
|
|
1672
|
+
if (backslashes === true) if (opts.unescape === true) output = output.replace(/\\/g, "");
|
|
1673
|
+
else output = output.replace(/\\+/g, (m) => {
|
|
1674
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
1675
|
+
});
|
|
1676
|
+
if (output === input && opts.contains === true) {
|
|
1677
|
+
state.output = input;
|
|
1678
|
+
return state;
|
|
1679
|
+
}
|
|
1680
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
1681
|
+
return state;
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Tokenize input until we reach end-of-string
|
|
1685
|
+
*/
|
|
1686
|
+
while (!eos()) {
|
|
1687
|
+
value = advance();
|
|
1688
|
+
if (value === "\0") continue;
|
|
1689
|
+
/**
|
|
1690
|
+
* Escaped characters
|
|
1691
|
+
*/
|
|
1692
|
+
if (value === "\\") {
|
|
1693
|
+
const next = peek();
|
|
1694
|
+
if (next === "/" && opts.bash !== true) continue;
|
|
1695
|
+
if (next === "." || next === ";") continue;
|
|
1696
|
+
if (!next) {
|
|
1697
|
+
value += "\\";
|
|
1698
|
+
push({
|
|
1699
|
+
type: "text",
|
|
1700
|
+
value
|
|
1701
|
+
});
|
|
1702
|
+
continue;
|
|
1703
|
+
}
|
|
1704
|
+
const match = /^\\+/.exec(remaining());
|
|
1705
|
+
let slashes = 0;
|
|
1706
|
+
if (match && match[0].length > 2) {
|
|
1707
|
+
slashes = match[0].length;
|
|
1708
|
+
state.index += slashes;
|
|
1709
|
+
if (slashes % 2 !== 0) value += "\\";
|
|
1710
|
+
}
|
|
1711
|
+
if (opts.unescape === true) value = advance();
|
|
1712
|
+
else value += advance();
|
|
1713
|
+
if (state.brackets === 0) {
|
|
1714
|
+
push({
|
|
1715
|
+
type: "text",
|
|
1716
|
+
value
|
|
1717
|
+
});
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* If we're inside a regex character class, continue
|
|
1723
|
+
* until we reach the closing bracket.
|
|
1724
|
+
*/
|
|
1725
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
1726
|
+
if (opts.posix !== false && value === ":") {
|
|
1727
|
+
const inner = prev.value.slice(1);
|
|
1728
|
+
if (inner.includes("[")) {
|
|
1729
|
+
prev.posix = true;
|
|
1730
|
+
if (inner.includes(":")) {
|
|
1731
|
+
const idx = prev.value.lastIndexOf("[");
|
|
1732
|
+
const pre = prev.value.slice(0, idx);
|
|
1733
|
+
const posix = POSIX_REGEX_SOURCE[prev.value.slice(idx + 2)];
|
|
1734
|
+
if (posix) {
|
|
1735
|
+
prev.value = pre + posix;
|
|
1736
|
+
state.backtrack = true;
|
|
1737
|
+
advance();
|
|
1738
|
+
if (!bos.output && tokens.indexOf(prev) === 1) bos.output = ONE_CHAR;
|
|
1739
|
+
continue;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") value = `\\${value}`;
|
|
1745
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) value = `\\${value}`;
|
|
1746
|
+
if (opts.posix === true && value === "!" && prev.value === "[") value = "^";
|
|
1747
|
+
prev.value += value;
|
|
1748
|
+
append({ value });
|
|
1749
|
+
continue;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* If we're inside a quoted string, continue
|
|
1753
|
+
* until we reach the closing double quote.
|
|
1754
|
+
*/
|
|
1755
|
+
if (state.quotes === 1 && value !== "\"") {
|
|
1756
|
+
value = utils.escapeRegex(value);
|
|
1757
|
+
prev.value += value;
|
|
1758
|
+
append({ value });
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Double quotes
|
|
1763
|
+
*/
|
|
1764
|
+
if (value === "\"") {
|
|
1765
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
1766
|
+
if (opts.keepQuotes === true) push({
|
|
1767
|
+
type: "text",
|
|
1768
|
+
value
|
|
1769
|
+
});
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Parentheses
|
|
1774
|
+
*/
|
|
1775
|
+
if (value === "(") {
|
|
1776
|
+
increment("parens");
|
|
1777
|
+
push({
|
|
1778
|
+
type: "paren",
|
|
1779
|
+
value
|
|
1780
|
+
});
|
|
1781
|
+
continue;
|
|
1782
|
+
}
|
|
1783
|
+
if (value === ")") {
|
|
1784
|
+
if (state.parens === 0 && opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "("));
|
|
1785
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
1786
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
1787
|
+
extglobClose(extglobs.pop());
|
|
1788
|
+
continue;
|
|
1789
|
+
}
|
|
1790
|
+
push({
|
|
1791
|
+
type: "paren",
|
|
1792
|
+
value,
|
|
1793
|
+
output: state.parens ? ")" : "\\)"
|
|
1794
|
+
});
|
|
1795
|
+
decrement("parens");
|
|
1796
|
+
continue;
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Square brackets
|
|
1800
|
+
*/
|
|
1801
|
+
if (value === "[") {
|
|
1802
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
1803
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1804
|
+
value = `\\${value}`;
|
|
1805
|
+
} else increment("brackets");
|
|
1806
|
+
push({
|
|
1807
|
+
type: "bracket",
|
|
1808
|
+
value
|
|
1809
|
+
});
|
|
1810
|
+
continue;
|
|
1811
|
+
}
|
|
1812
|
+
if (value === "]") {
|
|
1813
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
1814
|
+
push({
|
|
1815
|
+
type: "text",
|
|
1816
|
+
value,
|
|
1817
|
+
output: `\\${value}`
|
|
1818
|
+
});
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
if (state.brackets === 0) {
|
|
1822
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "["));
|
|
1823
|
+
push({
|
|
1824
|
+
type: "text",
|
|
1825
|
+
value,
|
|
1826
|
+
output: `\\${value}`
|
|
1827
|
+
});
|
|
1828
|
+
continue;
|
|
1829
|
+
}
|
|
1830
|
+
decrement("brackets");
|
|
1831
|
+
const prevValue = prev.value.slice(1);
|
|
1832
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) value = `/${value}`;
|
|
1833
|
+
prev.value += value;
|
|
1834
|
+
append({ value });
|
|
1835
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) continue;
|
|
1836
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
1837
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
1838
|
+
if (opts.literalBrackets === true) {
|
|
1839
|
+
state.output += escaped;
|
|
1840
|
+
prev.value = escaped;
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1844
|
+
state.output += prev.value;
|
|
1845
|
+
continue;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Braces
|
|
1849
|
+
*/
|
|
1850
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1851
|
+
increment("braces");
|
|
1852
|
+
const open = {
|
|
1853
|
+
type: "brace",
|
|
1854
|
+
value,
|
|
1855
|
+
output: "(",
|
|
1856
|
+
outputIndex: state.output.length,
|
|
1857
|
+
tokensIndex: state.tokens.length
|
|
1858
|
+
};
|
|
1859
|
+
braces.push(open);
|
|
1860
|
+
push(open);
|
|
1861
|
+
continue;
|
|
1862
|
+
}
|
|
1863
|
+
if (value === "}") {
|
|
1864
|
+
const brace = braces[braces.length - 1];
|
|
1865
|
+
if (opts.nobrace === true || !brace) {
|
|
1866
|
+
push({
|
|
1867
|
+
type: "text",
|
|
1868
|
+
value,
|
|
1869
|
+
output: value
|
|
1870
|
+
});
|
|
1871
|
+
continue;
|
|
1872
|
+
}
|
|
1873
|
+
let output = ")";
|
|
1874
|
+
if (brace.dots === true) {
|
|
1875
|
+
const arr = tokens.slice();
|
|
1876
|
+
const range = [];
|
|
1877
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1878
|
+
tokens.pop();
|
|
1879
|
+
if (arr[i].type === "brace") break;
|
|
1880
|
+
if (arr[i].type !== "dots") range.unshift(arr[i].value);
|
|
1881
|
+
}
|
|
1882
|
+
output = expandRange(range, opts);
|
|
1883
|
+
state.backtrack = true;
|
|
1884
|
+
}
|
|
1885
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1886
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1887
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1888
|
+
brace.value = brace.output = "\\{";
|
|
1889
|
+
value = output = "\\}";
|
|
1890
|
+
state.output = out;
|
|
1891
|
+
for (const t of toks) state.output += t.output || t.value;
|
|
1892
|
+
}
|
|
1893
|
+
push({
|
|
1894
|
+
type: "brace",
|
|
1895
|
+
value,
|
|
1896
|
+
output
|
|
1897
|
+
});
|
|
1898
|
+
decrement("braces");
|
|
1899
|
+
braces.pop();
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Pipes
|
|
1904
|
+
*/
|
|
1905
|
+
if (value === "|") {
|
|
1906
|
+
if (extglobs.length > 0) extglobs[extglobs.length - 1].conditions++;
|
|
1907
|
+
push({
|
|
1908
|
+
type: "text",
|
|
1909
|
+
value
|
|
1910
|
+
});
|
|
1911
|
+
continue;
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Commas
|
|
1915
|
+
*/
|
|
1916
|
+
if (value === ",") {
|
|
1917
|
+
let output = value;
|
|
1918
|
+
const brace = braces[braces.length - 1];
|
|
1919
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1920
|
+
brace.comma = true;
|
|
1921
|
+
output = "|";
|
|
1922
|
+
}
|
|
1923
|
+
push({
|
|
1924
|
+
type: "comma",
|
|
1925
|
+
value,
|
|
1926
|
+
output
|
|
1927
|
+
});
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Slashes
|
|
1932
|
+
*/
|
|
1933
|
+
if (value === "/") {
|
|
1934
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1935
|
+
state.start = state.index + 1;
|
|
1936
|
+
state.consumed = "";
|
|
1937
|
+
state.output = "";
|
|
1938
|
+
tokens.pop();
|
|
1939
|
+
prev = bos;
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
push({
|
|
1943
|
+
type: "slash",
|
|
1944
|
+
value,
|
|
1945
|
+
output: SLASH_LITERAL
|
|
1946
|
+
});
|
|
1947
|
+
continue;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Dots
|
|
1951
|
+
*/
|
|
1952
|
+
if (value === ".") {
|
|
1953
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1954
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1955
|
+
const brace = braces[braces.length - 1];
|
|
1956
|
+
prev.type = "dots";
|
|
1957
|
+
prev.output += value;
|
|
1958
|
+
prev.value += value;
|
|
1959
|
+
brace.dots = true;
|
|
1960
|
+
continue;
|
|
1961
|
+
}
|
|
1962
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1963
|
+
push({
|
|
1964
|
+
type: "text",
|
|
1965
|
+
value,
|
|
1966
|
+
output: DOT_LITERAL
|
|
1967
|
+
});
|
|
1968
|
+
continue;
|
|
1969
|
+
}
|
|
1970
|
+
push({
|
|
1971
|
+
type: "dot",
|
|
1972
|
+
value,
|
|
1973
|
+
output: DOT_LITERAL
|
|
1974
|
+
});
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Question marks
|
|
1979
|
+
*/
|
|
1980
|
+
if (value === "?") {
|
|
1981
|
+
if (!(prev && prev.value === "(") && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1982
|
+
extglobOpen("qmark", value);
|
|
1983
|
+
continue;
|
|
1984
|
+
}
|
|
1985
|
+
if (prev && prev.type === "paren") {
|
|
1986
|
+
const next = peek();
|
|
1987
|
+
let output = value;
|
|
1988
|
+
if (next === "<" && !utils.supportsLookbehinds()) throw new Error("Node.js v10 or higher is required for regex lookbehinds");
|
|
1989
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) output = `\\${value}`;
|
|
1990
|
+
push({
|
|
1991
|
+
type: "text",
|
|
1992
|
+
value,
|
|
1993
|
+
output
|
|
1994
|
+
});
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1998
|
+
push({
|
|
1999
|
+
type: "qmark",
|
|
2000
|
+
value,
|
|
2001
|
+
output: QMARK_NO_DOT
|
|
2002
|
+
});
|
|
2003
|
+
continue;
|
|
2004
|
+
}
|
|
2005
|
+
push({
|
|
2006
|
+
type: "qmark",
|
|
2007
|
+
value,
|
|
2008
|
+
output: QMARK
|
|
2009
|
+
});
|
|
2010
|
+
continue;
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Exclamation
|
|
2014
|
+
*/
|
|
2015
|
+
if (value === "!") {
|
|
2016
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
2017
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
2018
|
+
extglobOpen("negate", value);
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
2023
|
+
negate();
|
|
2024
|
+
continue;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Plus
|
|
2029
|
+
*/
|
|
2030
|
+
if (value === "+") {
|
|
2031
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2032
|
+
extglobOpen("plus", value);
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
2036
|
+
push({
|
|
2037
|
+
type: "plus",
|
|
2038
|
+
value,
|
|
2039
|
+
output: PLUS_LITERAL
|
|
2040
|
+
});
|
|
2041
|
+
continue;
|
|
2042
|
+
}
|
|
2043
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
2044
|
+
push({
|
|
2045
|
+
type: "plus",
|
|
2046
|
+
value
|
|
2047
|
+
});
|
|
2048
|
+
continue;
|
|
2049
|
+
}
|
|
2050
|
+
push({
|
|
2051
|
+
type: "plus",
|
|
2052
|
+
value: PLUS_LITERAL
|
|
2053
|
+
});
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Plain text
|
|
2058
|
+
*/
|
|
2059
|
+
if (value === "@") {
|
|
2060
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2061
|
+
push({
|
|
2062
|
+
type: "at",
|
|
2063
|
+
extglob: true,
|
|
2064
|
+
value,
|
|
2065
|
+
output: ""
|
|
2066
|
+
});
|
|
2067
|
+
continue;
|
|
2068
|
+
}
|
|
2069
|
+
push({
|
|
2070
|
+
type: "text",
|
|
2071
|
+
value
|
|
2072
|
+
});
|
|
2073
|
+
continue;
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Plain text
|
|
2077
|
+
*/
|
|
2078
|
+
if (value !== "*") {
|
|
2079
|
+
if (value === "$" || value === "^") value = `\\${value}`;
|
|
2080
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
2081
|
+
if (match) {
|
|
2082
|
+
value += match[0];
|
|
2083
|
+
state.index += match[0].length;
|
|
2084
|
+
}
|
|
2085
|
+
push({
|
|
2086
|
+
type: "text",
|
|
2087
|
+
value
|
|
2088
|
+
});
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Stars
|
|
2093
|
+
*/
|
|
2094
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
2095
|
+
prev.type = "star";
|
|
2096
|
+
prev.star = true;
|
|
2097
|
+
prev.value += value;
|
|
2098
|
+
prev.output = star;
|
|
2099
|
+
state.backtrack = true;
|
|
2100
|
+
state.globstar = true;
|
|
2101
|
+
consume(value);
|
|
2102
|
+
continue;
|
|
2103
|
+
}
|
|
2104
|
+
let rest = remaining();
|
|
2105
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
2106
|
+
extglobOpen("star", value);
|
|
2107
|
+
continue;
|
|
2108
|
+
}
|
|
2109
|
+
if (prev.type === "star") {
|
|
2110
|
+
if (opts.noglobstar === true) {
|
|
2111
|
+
consume(value);
|
|
2112
|
+
continue;
|
|
2113
|
+
}
|
|
2114
|
+
const prior = prev.prev;
|
|
2115
|
+
const before = prior.prev;
|
|
2116
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
2117
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
2118
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
2119
|
+
push({
|
|
2120
|
+
type: "star",
|
|
2121
|
+
value,
|
|
2122
|
+
output: ""
|
|
2123
|
+
});
|
|
2124
|
+
continue;
|
|
2125
|
+
}
|
|
2126
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
2127
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
2128
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
2129
|
+
push({
|
|
2130
|
+
type: "star",
|
|
2131
|
+
value,
|
|
2132
|
+
output: ""
|
|
2133
|
+
});
|
|
2134
|
+
continue;
|
|
2135
|
+
}
|
|
2136
|
+
while (rest.slice(0, 3) === "/**") {
|
|
2137
|
+
const after = input[state.index + 4];
|
|
2138
|
+
if (after && after !== "/") break;
|
|
2139
|
+
rest = rest.slice(3);
|
|
2140
|
+
consume("/**", 3);
|
|
2141
|
+
}
|
|
2142
|
+
if (prior.type === "bos" && eos()) {
|
|
2143
|
+
prev.type = "globstar";
|
|
2144
|
+
prev.value += value;
|
|
2145
|
+
prev.output = globstar(opts);
|
|
2146
|
+
state.output = prev.output;
|
|
2147
|
+
state.globstar = true;
|
|
2148
|
+
consume(value);
|
|
2149
|
+
continue;
|
|
2150
|
+
}
|
|
2151
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
2152
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
2153
|
+
prior.output = `(?:${prior.output}`;
|
|
2154
|
+
prev.type = "globstar";
|
|
2155
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
2156
|
+
prev.value += value;
|
|
2157
|
+
state.globstar = true;
|
|
2158
|
+
state.output += prior.output + prev.output;
|
|
2159
|
+
consume(value);
|
|
2160
|
+
continue;
|
|
2161
|
+
}
|
|
2162
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
2163
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
2164
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
2165
|
+
prior.output = `(?:${prior.output}`;
|
|
2166
|
+
prev.type = "globstar";
|
|
2167
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
2168
|
+
prev.value += value;
|
|
2169
|
+
state.output += prior.output + prev.output;
|
|
2170
|
+
state.globstar = true;
|
|
2171
|
+
consume(value + advance());
|
|
2172
|
+
push({
|
|
2173
|
+
type: "slash",
|
|
2174
|
+
value: "/",
|
|
2175
|
+
output: ""
|
|
2176
|
+
});
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
2180
|
+
prev.type = "globstar";
|
|
2181
|
+
prev.value += value;
|
|
2182
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
2183
|
+
state.output = prev.output;
|
|
2184
|
+
state.globstar = true;
|
|
2185
|
+
consume(value + advance());
|
|
2186
|
+
push({
|
|
2187
|
+
type: "slash",
|
|
2188
|
+
value: "/",
|
|
2189
|
+
output: ""
|
|
2190
|
+
});
|
|
2191
|
+
continue;
|
|
2192
|
+
}
|
|
2193
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
2194
|
+
prev.type = "globstar";
|
|
2195
|
+
prev.output = globstar(opts);
|
|
2196
|
+
prev.value += value;
|
|
2197
|
+
state.output += prev.output;
|
|
2198
|
+
state.globstar = true;
|
|
2199
|
+
consume(value);
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2202
|
+
const token = {
|
|
2203
|
+
type: "star",
|
|
2204
|
+
value,
|
|
2205
|
+
output: star
|
|
2206
|
+
};
|
|
2207
|
+
if (opts.bash === true) {
|
|
2208
|
+
token.output = ".*?";
|
|
2209
|
+
if (prev.type === "bos" || prev.type === "slash") token.output = nodot + token.output;
|
|
2210
|
+
push(token);
|
|
2211
|
+
continue;
|
|
2212
|
+
}
|
|
2213
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
2214
|
+
token.output = value;
|
|
2215
|
+
push(token);
|
|
2216
|
+
continue;
|
|
2217
|
+
}
|
|
2218
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
2219
|
+
if (prev.type === "dot") {
|
|
2220
|
+
state.output += NO_DOT_SLASH;
|
|
2221
|
+
prev.output += NO_DOT_SLASH;
|
|
2222
|
+
} else if (opts.dot === true) {
|
|
2223
|
+
state.output += NO_DOTS_SLASH;
|
|
2224
|
+
prev.output += NO_DOTS_SLASH;
|
|
2225
|
+
} else {
|
|
2226
|
+
state.output += nodot;
|
|
2227
|
+
prev.output += nodot;
|
|
2228
|
+
}
|
|
2229
|
+
if (peek() !== "*") {
|
|
2230
|
+
state.output += ONE_CHAR;
|
|
2231
|
+
prev.output += ONE_CHAR;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
push(token);
|
|
2235
|
+
}
|
|
2236
|
+
while (state.brackets > 0) {
|
|
2237
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
2238
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
2239
|
+
decrement("brackets");
|
|
2240
|
+
}
|
|
2241
|
+
while (state.parens > 0) {
|
|
2242
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
2243
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
2244
|
+
decrement("parens");
|
|
2245
|
+
}
|
|
2246
|
+
while (state.braces > 0) {
|
|
2247
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
2248
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
2249
|
+
decrement("braces");
|
|
2250
|
+
}
|
|
2251
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) push({
|
|
2252
|
+
type: "maybe_slash",
|
|
2253
|
+
value: "",
|
|
2254
|
+
output: `${SLASH_LITERAL}?`
|
|
2255
|
+
});
|
|
2256
|
+
if (state.backtrack === true) {
|
|
2257
|
+
state.output = "";
|
|
2258
|
+
for (const token of state.tokens) {
|
|
2259
|
+
state.output += token.output != null ? token.output : token.value;
|
|
2260
|
+
if (token.suffix) state.output += token.suffix;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
return state;
|
|
2264
|
+
};
|
|
2265
|
+
/**
|
|
2266
|
+
* Fast paths for creating regular expressions for common glob patterns.
|
|
2267
|
+
* This can significantly speed up processing and has very little downside
|
|
2268
|
+
* impact when none of the fast paths match.
|
|
2269
|
+
*/
|
|
2270
|
+
parse.fastpaths = (input, options) => {
|
|
2271
|
+
const opts = { ...options };
|
|
2272
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
2273
|
+
const len = input.length;
|
|
2274
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
2275
|
+
input = REPLACEMENTS[input] || input;
|
|
2276
|
+
const win32 = utils.isWindows(options);
|
|
2277
|
+
const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants.globChars(win32);
|
|
2278
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
2279
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
2280
|
+
const capture = opts.capture ? "" : "?:";
|
|
2281
|
+
const state = {
|
|
2282
|
+
negated: false,
|
|
2283
|
+
prefix: ""
|
|
2284
|
+
};
|
|
2285
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
2286
|
+
if (opts.capture) star = `(${star})`;
|
|
2287
|
+
const globstar = (opts) => {
|
|
2288
|
+
if (opts.noglobstar === true) return star;
|
|
2289
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
2290
|
+
};
|
|
2291
|
+
const create = (str) => {
|
|
2292
|
+
switch (str) {
|
|
2293
|
+
case "*": return `${nodot}${ONE_CHAR}${star}`;
|
|
2294
|
+
case ".*": return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2295
|
+
case "*.*": return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2296
|
+
case "*/*": return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
2297
|
+
case "**": return nodot + globstar(opts);
|
|
2298
|
+
case "**/*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
2299
|
+
case "**/*.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2300
|
+
case "**/.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2301
|
+
default: {
|
|
2302
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
2303
|
+
if (!match) return;
|
|
2304
|
+
const source = create(match[1]);
|
|
2305
|
+
if (!source) return;
|
|
2306
|
+
return source + DOT_LITERAL + match[2];
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2310
|
+
let source = create(utils.removePrefix(input, state));
|
|
2311
|
+
if (source && opts.strictSlashes !== true) source += `${SLASH_LITERAL}?`;
|
|
2312
|
+
return source;
|
|
2313
|
+
};
|
|
2314
|
+
module.exports = parse;
|
|
2315
|
+
}));
|
|
2316
|
+
//#endregion
|
|
2317
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/picomatch.js
|
|
2318
|
+
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
2319
|
+
const path$1 = __require("path");
|
|
2320
|
+
const scan = require_scan();
|
|
2321
|
+
const parse = require_parse();
|
|
2322
|
+
const utils = require_utils();
|
|
2323
|
+
const constants = require_constants();
|
|
2324
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
2325
|
+
/**
|
|
2326
|
+
* Creates a matcher function from one or more glob patterns. The
|
|
2327
|
+
* returned function takes a string to match as its first argument,
|
|
2328
|
+
* and returns true if the string is a match. The returned matcher
|
|
2329
|
+
* function also takes a boolean as the second argument that, when true,
|
|
2330
|
+
* returns an object with additional information.
|
|
2331
|
+
*
|
|
2332
|
+
* ```js
|
|
2333
|
+
* const picomatch = require('picomatch');
|
|
2334
|
+
* // picomatch(glob[, options]);
|
|
2335
|
+
*
|
|
2336
|
+
* const isMatch = picomatch('*.!(*a)');
|
|
2337
|
+
* console.log(isMatch('a.a')); //=> false
|
|
2338
|
+
* console.log(isMatch('a.b')); //=> true
|
|
2339
|
+
* ```
|
|
2340
|
+
* @name picomatch
|
|
2341
|
+
* @param {String|Array} `globs` One or more glob patterns.
|
|
2342
|
+
* @param {Object=} `options`
|
|
2343
|
+
* @return {Function=} Returns a matcher function.
|
|
2344
|
+
* @api public
|
|
2345
|
+
*/
|
|
2346
|
+
const picomatch = (glob, options, returnState = false) => {
|
|
2347
|
+
if (Array.isArray(glob)) {
|
|
2348
|
+
const fns = glob.map((input) => picomatch(input, options, returnState));
|
|
2349
|
+
const arrayMatcher = (str) => {
|
|
2350
|
+
for (const isMatch of fns) {
|
|
2351
|
+
const state = isMatch(str);
|
|
2352
|
+
if (state) return state;
|
|
2353
|
+
}
|
|
2354
|
+
return false;
|
|
2355
|
+
};
|
|
2356
|
+
return arrayMatcher;
|
|
2357
|
+
}
|
|
2358
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
2359
|
+
if (glob === "" || typeof glob !== "string" && !isState) throw new TypeError("Expected pattern to be a non-empty string");
|
|
2360
|
+
const opts = options || {};
|
|
2361
|
+
const posix = utils.isWindows(options);
|
|
2362
|
+
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
2363
|
+
const state = regex.state;
|
|
2364
|
+
delete regex.state;
|
|
2365
|
+
let isIgnored = () => false;
|
|
2366
|
+
if (opts.ignore) {
|
|
2367
|
+
const ignoreOpts = {
|
|
2368
|
+
...options,
|
|
2369
|
+
ignore: null,
|
|
2370
|
+
onMatch: null,
|
|
2371
|
+
onResult: null
|
|
2372
|
+
};
|
|
2373
|
+
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
2374
|
+
}
|
|
2375
|
+
const matcher = (input, returnObject = false) => {
|
|
2376
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, {
|
|
2377
|
+
glob,
|
|
2378
|
+
posix
|
|
2379
|
+
});
|
|
2380
|
+
const result = {
|
|
2381
|
+
glob,
|
|
2382
|
+
state,
|
|
2383
|
+
regex,
|
|
2384
|
+
posix,
|
|
2385
|
+
input,
|
|
2386
|
+
output,
|
|
2387
|
+
match,
|
|
2388
|
+
isMatch
|
|
2389
|
+
};
|
|
2390
|
+
if (typeof opts.onResult === "function") opts.onResult(result);
|
|
2391
|
+
if (isMatch === false) {
|
|
2392
|
+
result.isMatch = false;
|
|
2393
|
+
return returnObject ? result : false;
|
|
2394
|
+
}
|
|
2395
|
+
if (isIgnored(input)) {
|
|
2396
|
+
if (typeof opts.onIgnore === "function") opts.onIgnore(result);
|
|
2397
|
+
result.isMatch = false;
|
|
2398
|
+
return returnObject ? result : false;
|
|
2399
|
+
}
|
|
2400
|
+
if (typeof opts.onMatch === "function") opts.onMatch(result);
|
|
2401
|
+
return returnObject ? result : true;
|
|
2402
|
+
};
|
|
2403
|
+
if (returnState) matcher.state = state;
|
|
2404
|
+
return matcher;
|
|
2405
|
+
};
|
|
2406
|
+
/**
|
|
2407
|
+
* Test `input` with the given `regex`. This is used by the main
|
|
2408
|
+
* `picomatch()` function to test the input string.
|
|
2409
|
+
*
|
|
2410
|
+
* ```js
|
|
2411
|
+
* const picomatch = require('picomatch');
|
|
2412
|
+
* // picomatch.test(input, regex[, options]);
|
|
2413
|
+
*
|
|
2414
|
+
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
2415
|
+
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
2416
|
+
* ```
|
|
2417
|
+
* @param {String} `input` String to test.
|
|
2418
|
+
* @param {RegExp} `regex`
|
|
2419
|
+
* @return {Object} Returns an object with matching info.
|
|
2420
|
+
* @api public
|
|
2421
|
+
*/
|
|
2422
|
+
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2423
|
+
if (typeof input !== "string") throw new TypeError("Expected input to be a string");
|
|
2424
|
+
if (input === "") return {
|
|
2425
|
+
isMatch: false,
|
|
2426
|
+
output: ""
|
|
2427
|
+
};
|
|
2428
|
+
const opts = options || {};
|
|
2429
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
2430
|
+
let match = input === glob;
|
|
2431
|
+
let output = match && format ? format(input) : input;
|
|
2432
|
+
if (match === false) {
|
|
2433
|
+
output = format ? format(input) : input;
|
|
2434
|
+
match = output === glob;
|
|
2435
|
+
}
|
|
2436
|
+
if (match === false || opts.capture === true) if (opts.matchBase === true || opts.basename === true) match = picomatch.matchBase(input, regex, options, posix);
|
|
2437
|
+
else match = regex.exec(output);
|
|
2438
|
+
return {
|
|
2439
|
+
isMatch: Boolean(match),
|
|
2440
|
+
match,
|
|
2441
|
+
output
|
|
2442
|
+
};
|
|
2443
|
+
};
|
|
2444
|
+
/**
|
|
2445
|
+
* Match the basename of a filepath.
|
|
2446
|
+
*
|
|
2447
|
+
* ```js
|
|
2448
|
+
* const picomatch = require('picomatch');
|
|
2449
|
+
* // picomatch.matchBase(input, glob[, options]);
|
|
2450
|
+
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
2451
|
+
* ```
|
|
2452
|
+
* @param {String} `input` String to test.
|
|
2453
|
+
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
2454
|
+
* @return {Boolean}
|
|
2455
|
+
* @api public
|
|
2456
|
+
*/
|
|
2457
|
+
picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
|
|
2458
|
+
return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(path$1.basename(input));
|
|
2459
|
+
};
|
|
2460
|
+
/**
|
|
2461
|
+
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
2462
|
+
*
|
|
2463
|
+
* ```js
|
|
2464
|
+
* const picomatch = require('picomatch');
|
|
2465
|
+
* // picomatch.isMatch(string, patterns[, options]);
|
|
2466
|
+
*
|
|
2467
|
+
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
2468
|
+
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
2469
|
+
* ```
|
|
2470
|
+
* @param {String|Array} str The string to test.
|
|
2471
|
+
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
2472
|
+
* @param {Object} [options] See available [options](#options).
|
|
2473
|
+
* @return {Boolean} Returns true if any patterns match `str`
|
|
2474
|
+
* @api public
|
|
2475
|
+
*/
|
|
2476
|
+
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
2477
|
+
/**
|
|
2478
|
+
* Parse a glob pattern to create the source string for a regular
|
|
2479
|
+
* expression.
|
|
2480
|
+
*
|
|
2481
|
+
* ```js
|
|
2482
|
+
* const picomatch = require('picomatch');
|
|
2483
|
+
* const result = picomatch.parse(pattern[, options]);
|
|
2484
|
+
* ```
|
|
2485
|
+
* @param {String} `pattern`
|
|
2486
|
+
* @param {Object} `options`
|
|
2487
|
+
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
2488
|
+
* @api public
|
|
2489
|
+
*/
|
|
2490
|
+
picomatch.parse = (pattern, options) => {
|
|
2491
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
|
|
2492
|
+
return parse(pattern, {
|
|
2493
|
+
...options,
|
|
2494
|
+
fastpaths: false
|
|
2495
|
+
});
|
|
2496
|
+
};
|
|
2497
|
+
/**
|
|
2498
|
+
* Scan a glob pattern to separate the pattern into segments.
|
|
2499
|
+
*
|
|
2500
|
+
* ```js
|
|
2501
|
+
* const picomatch = require('picomatch');
|
|
2502
|
+
* // picomatch.scan(input[, options]);
|
|
2503
|
+
*
|
|
2504
|
+
* const result = picomatch.scan('!./foo/*.js');
|
|
2505
|
+
* console.log(result);
|
|
2506
|
+
* { prefix: '!./',
|
|
2507
|
+
* input: '!./foo/*.js',
|
|
2508
|
+
* start: 3,
|
|
2509
|
+
* base: 'foo',
|
|
2510
|
+
* glob: '*.js',
|
|
2511
|
+
* isBrace: false,
|
|
2512
|
+
* isBracket: false,
|
|
2513
|
+
* isGlob: true,
|
|
2514
|
+
* isExtglob: false,
|
|
2515
|
+
* isGlobstar: false,
|
|
2516
|
+
* negated: true }
|
|
2517
|
+
* ```
|
|
2518
|
+
* @param {String} `input` Glob pattern to scan.
|
|
2519
|
+
* @param {Object} `options`
|
|
2520
|
+
* @return {Object} Returns an object with
|
|
2521
|
+
* @api public
|
|
2522
|
+
*/
|
|
2523
|
+
picomatch.scan = (input, options) => scan(input, options);
|
|
2524
|
+
/**
|
|
2525
|
+
* Compile a regular expression from the `state` object returned by the
|
|
2526
|
+
* [parse()](#parse) method.
|
|
2527
|
+
*
|
|
2528
|
+
* @param {Object} `state`
|
|
2529
|
+
* @param {Object} `options`
|
|
2530
|
+
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
2531
|
+
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
2532
|
+
* @return {RegExp}
|
|
2533
|
+
* @api public
|
|
2534
|
+
*/
|
|
2535
|
+
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
2536
|
+
if (returnOutput === true) return state.output;
|
|
2537
|
+
const opts = options || {};
|
|
2538
|
+
const prepend = opts.contains ? "" : "^";
|
|
2539
|
+
const append = opts.contains ? "" : "$";
|
|
2540
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
2541
|
+
if (state && state.negated === true) source = `^(?!${source}).*$`;
|
|
2542
|
+
const regex = picomatch.toRegex(source, options);
|
|
2543
|
+
if (returnState === true) regex.state = state;
|
|
2544
|
+
return regex;
|
|
2545
|
+
};
|
|
2546
|
+
/**
|
|
2547
|
+
* Create a regular expression from a parsed glob pattern.
|
|
2548
|
+
*
|
|
2549
|
+
* ```js
|
|
2550
|
+
* const picomatch = require('picomatch');
|
|
2551
|
+
* const state = picomatch.parse('*.js');
|
|
2552
|
+
* // picomatch.compileRe(state[, options]);
|
|
2553
|
+
*
|
|
2554
|
+
* console.log(picomatch.compileRe(state));
|
|
2555
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2556
|
+
* ```
|
|
2557
|
+
* @param {String} `state` The object returned from the `.parse` method.
|
|
2558
|
+
* @param {Object} `options`
|
|
2559
|
+
* @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.
|
|
2560
|
+
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
2561
|
+
* @return {RegExp} Returns a regex created from the given pattern.
|
|
2562
|
+
* @api public
|
|
2563
|
+
*/
|
|
2564
|
+
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
2565
|
+
if (!input || typeof input !== "string") throw new TypeError("Expected a non-empty string");
|
|
2566
|
+
let parsed = {
|
|
2567
|
+
negated: false,
|
|
2568
|
+
fastpaths: true
|
|
2569
|
+
};
|
|
2570
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) parsed.output = parse.fastpaths(input, options);
|
|
2571
|
+
if (!parsed.output) parsed = parse(input, options);
|
|
2572
|
+
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
2573
|
+
};
|
|
2574
|
+
/**
|
|
2575
|
+
* Create a regular expression from the given regex source string.
|
|
2576
|
+
*
|
|
2577
|
+
* ```js
|
|
2578
|
+
* const picomatch = require('picomatch');
|
|
2579
|
+
* // picomatch.toRegex(source[, options]);
|
|
2580
|
+
*
|
|
2581
|
+
* const { output } = picomatch.parse('*.js');
|
|
2582
|
+
* console.log(picomatch.toRegex(output));
|
|
2583
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2584
|
+
* ```
|
|
2585
|
+
* @param {String} `source` Regular expression source string.
|
|
2586
|
+
* @param {Object} `options`
|
|
2587
|
+
* @return {RegExp}
|
|
2588
|
+
* @api public
|
|
2589
|
+
*/
|
|
2590
|
+
picomatch.toRegex = (source, options) => {
|
|
2591
|
+
try {
|
|
2592
|
+
const opts = options || {};
|
|
2593
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
2594
|
+
} catch (err) {
|
|
2595
|
+
if (options && options.debug === true) throw err;
|
|
2596
|
+
return /$^/;
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2599
|
+
/**
|
|
2600
|
+
* Picomatch constants.
|
|
2601
|
+
* @return {Object}
|
|
2602
|
+
*/
|
|
2603
|
+
picomatch.constants = constants;
|
|
2604
|
+
/**
|
|
2605
|
+
* Expose "picomatch"
|
|
2606
|
+
*/
|
|
2607
|
+
module.exports = picomatch;
|
|
2608
|
+
}));
|
|
2609
|
+
//#endregion
|
|
935
2610
|
//#region ../core/dist/index.js
|
|
2611
|
+
var import_picomatch = /* @__PURE__ */ __toESM$1((/* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
2612
|
+
module.exports = require_picomatch$1();
|
|
2613
|
+
})))(), 1);
|
|
936
2614
|
var __create = Object.create;
|
|
937
2615
|
var __defProp = Object.defineProperty;
|
|
938
2616
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -954,30 +2632,53 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
954
2632
|
value: mod,
|
|
955
2633
|
enumerable: true
|
|
956
2634
|
}) : 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
|
-
|
|
2635
|
+
const JSX_FILE_PATTERN = /\.(tsx|jsx)$/;
|
|
2636
|
+
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
2637
|
+
const FETCH_TIMEOUT_MS = 1e4;
|
|
2638
|
+
const DEFAULT_BRANCH_CANDIDATES = ["main", "master"];
|
|
2639
|
+
const ADOPTABLE_LINT_CONFIG_FILENAMES = [".oxlintrc.json", ".eslintrc.json"];
|
|
2640
|
+
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
2641
|
+
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
2642
|
+
var InvalidGlobPatternError = class extends Error {
|
|
2643
|
+
pattern;
|
|
2644
|
+
reason;
|
|
2645
|
+
constructor(pattern, reason) {
|
|
2646
|
+
super(`Invalid glob pattern ${JSON.stringify(pattern)}: ${reason}`);
|
|
2647
|
+
this.name = "InvalidGlobPatternError";
|
|
2648
|
+
this.pattern = pattern;
|
|
2649
|
+
this.reason = reason;
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
const assertGlobPattern = (condition, pattern, reason) => {
|
|
2653
|
+
if (!condition) throw new InvalidGlobPatternError(pattern, reason);
|
|
2654
|
+
};
|
|
2655
|
+
const countGlobWildcards = (pattern) => (pattern.match(/[*?]/g) ?? []).length;
|
|
2656
|
+
const normalizeGlobPattern = (pattern) => pattern.replace(/\\/g, "/").replace(/^\//, "");
|
|
2657
|
+
const PICOMATCH_OPTIONS = {
|
|
2658
|
+
dot: true,
|
|
2659
|
+
strictSlashes: false,
|
|
2660
|
+
windows: false
|
|
2661
|
+
};
|
|
2662
|
+
const compileGlobPattern = (rawPattern) => {
|
|
2663
|
+
assertGlobPattern(typeof rawPattern === "string" && rawPattern.length > 0, String(rawPattern), "pattern must be a non-empty string.");
|
|
2664
|
+
assertGlobPattern(rawPattern.length <= MAX_GLOB_PATTERN_LENGTH_CHARS, rawPattern, `pattern length ${rawPattern.length} exceeds the maximum of ${MAX_GLOB_PATTERN_LENGTH_CHARS} characters.`);
|
|
2665
|
+
const wildcardCount = countGlobWildcards(rawPattern);
|
|
2666
|
+
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.`);
|
|
2667
|
+
try {
|
|
2668
|
+
return import_picomatch.default.makeRe(normalizeGlobPattern(rawPattern), PICOMATCH_OPTIONS);
|
|
2669
|
+
} catch (caughtError) {
|
|
2670
|
+
throw new InvalidGlobPatternError(rawPattern, caughtError instanceof Error ? caughtError.message : String(caughtError));
|
|
978
2671
|
}
|
|
979
|
-
|
|
980
|
-
|
|
2672
|
+
};
|
|
2673
|
+
const compileGlobPatternsLenient = (patterns, onInvalid) => {
|
|
2674
|
+
const compiled = [];
|
|
2675
|
+
for (const pattern of patterns) try {
|
|
2676
|
+
compiled.push(compileGlobPattern(pattern));
|
|
2677
|
+
} catch (caughtError) {
|
|
2678
|
+
if (!(caughtError instanceof InvalidGlobPatternError)) throw caughtError;
|
|
2679
|
+
onInvalid(caughtError);
|
|
2680
|
+
}
|
|
2681
|
+
return compiled;
|
|
981
2682
|
};
|
|
982
2683
|
const toRelativePath = (filePath, rootDirectory) => {
|
|
983
2684
|
const normalizedFilePath = filePath.replace(/\\/g, "/");
|
|
@@ -985,22 +2686,22 @@ const toRelativePath = (filePath, rootDirectory) => {
|
|
|
985
2686
|
if (normalizedFilePath.startsWith(normalizedRoot)) return normalizedFilePath.slice(normalizedRoot.length);
|
|
986
2687
|
return normalizedFilePath.replace(/^\.\//, "");
|
|
987
2688
|
};
|
|
988
|
-
const
|
|
2689
|
+
const warnConfigIssue = (message) => {
|
|
989
2690
|
process.stderr.write(`[react-doctor] ${message}\n`);
|
|
990
2691
|
};
|
|
991
2692
|
const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
992
2693
|
const collectStringList = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
993
2694
|
const validateOverrideEntry = (entry, index) => {
|
|
994
2695
|
if (!isPlainObject(entry)) {
|
|
995
|
-
|
|
2696
|
+
warnConfigIssue(`ignore.overrides[${index}] must be an object with { files, rules }; ignoring this entry.`);
|
|
996
2697
|
return null;
|
|
997
2698
|
}
|
|
998
2699
|
if (!isStringArray(entry.files)) {
|
|
999
|
-
|
|
2700
|
+
warnConfigIssue(`ignore.overrides[${index}].files must be an array of strings; ignoring this entry.`);
|
|
1000
2701
|
return null;
|
|
1001
2702
|
}
|
|
1002
2703
|
if (entry.rules !== void 0 && !isStringArray(entry.rules)) {
|
|
1003
|
-
|
|
2704
|
+
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
2705
|
return { files: entry.files };
|
|
1005
2706
|
}
|
|
1006
2707
|
return entry.rules === void 0 ? { files: entry.files } : {
|
|
@@ -1012,13 +2713,13 @@ const compileIgnoreOverrides = (userConfig) => {
|
|
|
1012
2713
|
const overrides = userConfig?.ignore?.overrides;
|
|
1013
2714
|
if (overrides === void 0) return [];
|
|
1014
2715
|
if (!Array.isArray(overrides)) {
|
|
1015
|
-
|
|
2716
|
+
warnConfigIssue(`ignore.overrides must be an array of { files, rules } entries; ignoring.`);
|
|
1016
2717
|
return [];
|
|
1017
2718
|
}
|
|
1018
2719
|
return overrides.flatMap((entry, index) => {
|
|
1019
2720
|
const validated = validateOverrideEntry(entry, index);
|
|
1020
2721
|
if (!validated) return [];
|
|
1021
|
-
const filePatterns = collectStringList(validated.files)
|
|
2722
|
+
const filePatterns = compileGlobPatternsLenient(collectStringList(validated.files), (error) => warnConfigIssue(`ignore.overrides[${index}]: ${error.message}`));
|
|
1022
2723
|
if (filePatterns.length === 0) return [];
|
|
1023
2724
|
return [{
|
|
1024
2725
|
filePatterns,
|
|
@@ -1032,12 +2733,94 @@ const isDiagnosticIgnoredByOverrides = (diagnostic, rootDirectory, overrides) =>
|
|
|
1032
2733
|
const ruleIdentifier = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
1033
2734
|
return overrides.some((override) => override.filePatterns.some((pattern) => pattern.test(relativeFilePath)) && (override.ruleIds.size === 0 || override.ruleIds.has(ruleIdentifier)));
|
|
1034
2735
|
};
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
2736
|
+
/**
|
|
2737
|
+
* Assembles the internal `RuleSeverityControls` shape from a user
|
|
2738
|
+
* config's top-level `rules` and `categories` fields — the
|
|
2739
|
+
* ESLint / oxlint-shaped severity surface.
|
|
2740
|
+
*
|
|
2741
|
+
* Returns `undefined` when neither field is present so the common
|
|
2742
|
+
* path (no severity config at all) stays allocation-free for
|
|
2743
|
+
* downstream consumers.
|
|
2744
|
+
*/
|
|
2745
|
+
const buildRuleSeverityControls = (config) => {
|
|
2746
|
+
if (!config) return void 0;
|
|
2747
|
+
if (config.rules === void 0 && config.categories === void 0) return void 0;
|
|
2748
|
+
return {
|
|
2749
|
+
...config.rules !== void 0 ? { rules: config.rules } : {},
|
|
2750
|
+
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2751
|
+
};
|
|
2752
|
+
};
|
|
2753
|
+
/**
|
|
2754
|
+
* Projects a diagnostic onto the three axes rule-targeted controls
|
|
2755
|
+
* reason about:
|
|
2756
|
+
*
|
|
2757
|
+
* - `ruleKey` — the fully-qualified `"<plugin>/<rule>"` form users
|
|
2758
|
+
* put in config files (consumed by top-level `rules` severity and
|
|
2759
|
+
* `surfaces.*.{include,exclude}Rules`).
|
|
2760
|
+
* - `category` — the diagnostic's category label (consumed by
|
|
2761
|
+
* top-level `categories` severity and
|
|
2762
|
+
* `surfaces.*.{include,exclude}Categories`).
|
|
2763
|
+
* - `tags` — behavioral tags from the rule registry (consumed by
|
|
2764
|
+
* `ignore.tags` and `surfaces.*.{include,exclude}Tags`). Empty
|
|
2765
|
+
* for non-`react-doctor` plugins.
|
|
2766
|
+
*/
|
|
2767
|
+
const getDiagnosticRuleIdentity = (diagnostic) => ({
|
|
2768
|
+
ruleKey: `${diagnostic.plugin}/${diagnostic.rule}`,
|
|
2769
|
+
category: diagnostic.category,
|
|
2770
|
+
tags: diagnostic.plugin === "react-doctor" ? reactDoctorPlugin.rules[diagnostic.rule]?.tags ?? [] : []
|
|
2771
|
+
});
|
|
2772
|
+
/**
|
|
2773
|
+
* Resolves the user-configured severity override for a rule.
|
|
2774
|
+
* Per-rule overrides win over per-category overrides. Returns
|
|
2775
|
+
* `undefined` when neither channel matches — callers should fall
|
|
2776
|
+
* back to the rule's built-in severity.
|
|
2777
|
+
*/
|
|
2778
|
+
const resolveRuleSeverityOverride = (input, controls) => {
|
|
2779
|
+
if (!controls) return void 0;
|
|
2780
|
+
return controls.rules?.[input.ruleKey] ?? (input.category !== void 0 ? controls.categories?.[input.category] : void 0);
|
|
2781
|
+
};
|
|
2782
|
+
const SEVERITY_FOR_OVERRIDE = {
|
|
2783
|
+
error: "error",
|
|
2784
|
+
warn: "warning"
|
|
2785
|
+
};
|
|
2786
|
+
const restampSeverity = (diagnostic, override) => {
|
|
2787
|
+
const targetSeverity = SEVERITY_FOR_OVERRIDE[override];
|
|
2788
|
+
if (diagnostic.severity === targetSeverity) return diagnostic;
|
|
2789
|
+
return {
|
|
2790
|
+
...diagnostic,
|
|
2791
|
+
severity: targetSeverity
|
|
2792
|
+
};
|
|
2793
|
+
};
|
|
2794
|
+
/**
|
|
2795
|
+
* Applies the user's top-level `rules` / `categories` / `tags`
|
|
2796
|
+
* severity config to a post-lint diagnostic list:
|
|
2797
|
+
*
|
|
2798
|
+
* - `"off"` drops the diagnostic entirely. For react-doctor rules
|
|
2799
|
+
* this also happens at lint-registration time; this post-filter
|
|
2800
|
+
* covers external plugins (`react/*`, `jsx-a11y/*`, custom adopted
|
|
2801
|
+
* configs) whose severities the lint config can't reach.
|
|
2802
|
+
* - `"warn"` / `"error"` re-stamps `diagnostic.severity` so downstream
|
|
2803
|
+
* consumers — `--fail-on`, the score input, the CLI summary — see
|
|
2804
|
+
* the user-chosen severity rather than the rule's built-in one.
|
|
2805
|
+
*
|
|
2806
|
+
* Returns the input array by identity when no controls are configured
|
|
2807
|
+
* so the common path stays allocation-free.
|
|
2808
|
+
*/
|
|
2809
|
+
const applySeverityControls = (diagnostics, config) => {
|
|
2810
|
+
const controls = buildRuleSeverityControls(config);
|
|
2811
|
+
if (!controls) return diagnostics;
|
|
2812
|
+
const adjusted = [];
|
|
2813
|
+
for (const diagnostic of diagnostics) {
|
|
2814
|
+
const { ruleKey, category } = getDiagnosticRuleIdentity(diagnostic);
|
|
2815
|
+
const override = resolveRuleSeverityOverride({
|
|
2816
|
+
ruleKey,
|
|
2817
|
+
category
|
|
2818
|
+
}, controls);
|
|
2819
|
+
if (override === "off") continue;
|
|
2820
|
+
adjusted.push(override === void 0 ? diagnostic : restampSeverity(diagnostic, override));
|
|
2821
|
+
}
|
|
2822
|
+
return adjusted;
|
|
2823
|
+
};
|
|
1041
2824
|
const estimateArgsLength = (args) => args.reduce((total, argument) => total + argument.length + 1, 0);
|
|
1042
2825
|
const batchIncludePaths = (baseArgs, includePaths) => {
|
|
1043
2826
|
const baseArgsLength = estimateArgsLength(baseArgs);
|
|
@@ -1709,7 +3492,7 @@ const evaluateSuppression = (lines, diagnosticLineIndex, ruleId) => {
|
|
|
1709
3492
|
const compileIgnoredFilePatterns = (userConfig) => {
|
|
1710
3493
|
const files = userConfig?.ignore?.files;
|
|
1711
3494
|
if (!Array.isArray(files)) return [];
|
|
1712
|
-
return files.filter((entry) => typeof entry === "string")
|
|
3495
|
+
return compileGlobPatternsLenient(files.filter((entry) => typeof entry === "string"), (error) => warnConfigIssue(`ignore.files: ${error.message}`));
|
|
1713
3496
|
};
|
|
1714
3497
|
const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
|
|
1715
3498
|
if (patterns.length === 0) return false;
|
|
@@ -1873,8 +3656,8 @@ const shouldAutoSuppress = (diagnostic) => {
|
|
|
1873
3656
|
return false;
|
|
1874
3657
|
};
|
|
1875
3658
|
const mergeAndFilterDiagnostics = (mergedDiagnostics, directory, userConfig, readFileLinesSync, options = {}) => {
|
|
1876
|
-
const
|
|
1877
|
-
const filtered = userConfig ? filterIgnoredDiagnostics(
|
|
3659
|
+
const severityAdjusted = applySeverityControls(mergedDiagnostics.filter((diagnostic) => !shouldAutoSuppress(diagnostic)), userConfig);
|
|
3660
|
+
const filtered = userConfig ? filterIgnoredDiagnostics(severityAdjusted, userConfig, directory, readFileLinesSync) : severityAdjusted;
|
|
1878
3661
|
if (options.respectInlineDisables === false) return filtered;
|
|
1879
3662
|
return filterInlineSuppressions(filtered, directory, readFileLinesSync);
|
|
1880
3663
|
};
|
|
@@ -2028,6 +3811,11 @@ const getDiffInfo = (directory, explicitBaseBranch) => {
|
|
|
2028
3811
|
};
|
|
2029
3812
|
const filterSourceFiles = (filePaths) => filePaths.filter((filePath) => SOURCE_FILE_PATTERN.test(filePath));
|
|
2030
3813
|
const computeJsxIncludePaths = (includePaths) => includePaths.length > 0 ? includePaths.filter((filePath) => JSX_FILE_PATTERN.test(filePath)) : void 0;
|
|
3814
|
+
const VALID_RULE_SEVERITIES = [
|
|
3815
|
+
"error",
|
|
3816
|
+
"warn",
|
|
3817
|
+
"off"
|
|
3818
|
+
];
|
|
2031
3819
|
const BOOLEAN_FIELD_NAMES = [
|
|
2032
3820
|
"lint",
|
|
2033
3821
|
"verbose",
|
|
@@ -2038,18 +3826,27 @@ const BOOLEAN_FIELD_NAMES = [
|
|
|
2038
3826
|
"offline"
|
|
2039
3827
|
];
|
|
2040
3828
|
const STRING_FIELD_NAMES = ["rootDir"];
|
|
3829
|
+
const SURFACE_CONTROL_FIELD_NAMES = [
|
|
3830
|
+
"includeTags",
|
|
3831
|
+
"excludeTags",
|
|
3832
|
+
"includeCategories",
|
|
3833
|
+
"excludeCategories",
|
|
3834
|
+
"includeRules",
|
|
3835
|
+
"excludeRules"
|
|
3836
|
+
];
|
|
3837
|
+
const SEVERITY_FIELD_NAMES = ["rules", "categories"];
|
|
2041
3838
|
const warnConfigField = (message) => {
|
|
2042
3839
|
process.stderr.write(`[react-doctor] ${message}\n`);
|
|
2043
3840
|
};
|
|
3841
|
+
const isPlainObject$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3842
|
+
const formatType = (value) => typeof value === "string" ? `"${value}"` : typeof value;
|
|
3843
|
+
const isRuleSeverity = (value) => typeof value === "string" && VALID_RULE_SEVERITIES.includes(value);
|
|
2044
3844
|
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;
|
|
3845
|
+
if (typeof value === "boolean") return value;
|
|
3846
|
+
if (value === "true" || value === "false") {
|
|
3847
|
+
const coerced = value === "true";
|
|
3848
|
+
warnConfigField(`config field "${fieldName}" is the string "${value}"; treating as boolean ${coerced}.`);
|
|
3849
|
+
return coerced;
|
|
2053
3850
|
}
|
|
2054
3851
|
warnConfigField(`config field "${fieldName}" must be a boolean (got ${typeof value}); ignoring this field.`);
|
|
2055
3852
|
};
|
|
@@ -2057,47 +3854,32 @@ const validateString = (fieldName, value) => {
|
|
|
2057
3854
|
if (typeof value === "string") return value;
|
|
2058
3855
|
warnConfigField(`config field "${fieldName}" must be a string (got ${typeof value}); ignoring this field.`);
|
|
2059
3856
|
};
|
|
2060
|
-
const SURFACE_CONTROL_FIELD_NAMES = [
|
|
2061
|
-
"includeTags",
|
|
2062
|
-
"excludeTags",
|
|
2063
|
-
"includeCategories",
|
|
2064
|
-
"excludeCategories",
|
|
2065
|
-
"includeRules",
|
|
2066
|
-
"excludeRules"
|
|
2067
|
-
];
|
|
2068
3857
|
const validateStringArrayField = (fieldName, value) => {
|
|
2069
|
-
if (value === void 0) return void 0;
|
|
2070
3858
|
if (!Array.isArray(value)) {
|
|
2071
3859
|
warnConfigField(`config field "${fieldName}" must be an array of strings (got ${typeof value}); ignoring this field.`);
|
|
2072
3860
|
return;
|
|
2073
3861
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2080
|
-
collected.push(entry);
|
|
2081
|
-
}
|
|
2082
|
-
return collected;
|
|
3862
|
+
return value.filter((entry) => {
|
|
3863
|
+
if (typeof entry === "string") return true;
|
|
3864
|
+
warnConfigField(`config field "${fieldName}" contains a non-string entry (${typeof entry}); ignoring the entry.`);
|
|
3865
|
+
return false;
|
|
3866
|
+
});
|
|
2083
3867
|
};
|
|
2084
3868
|
const validateSurfaceControls = (surface, rawControls) => {
|
|
2085
|
-
if (rawControls
|
|
2086
|
-
if (typeof rawControls !== "object" || rawControls === null || Array.isArray(rawControls)) {
|
|
3869
|
+
if (!isPlainObject$1(rawControls)) {
|
|
2087
3870
|
warnConfigField(`config field "surfaces.${surface}" must be an object (got ${typeof rawControls}); ignoring this surface.`);
|
|
2088
3871
|
return;
|
|
2089
3872
|
}
|
|
2090
3873
|
const validated = {};
|
|
2091
3874
|
for (const fieldName of SURFACE_CONTROL_FIELD_NAMES) {
|
|
2092
|
-
|
|
2093
|
-
const
|
|
2094
|
-
if (
|
|
3875
|
+
if (rawControls[fieldName] === void 0) continue;
|
|
3876
|
+
const result = validateStringArrayField(`surfaces.${surface}.${fieldName}`, rawControls[fieldName]);
|
|
3877
|
+
if (result !== void 0) validated[fieldName] = result;
|
|
2095
3878
|
}
|
|
2096
3879
|
return validated;
|
|
2097
3880
|
};
|
|
2098
3881
|
const validateSurfacesField = (rawSurfaces) => {
|
|
2099
|
-
if (rawSurfaces
|
|
2100
|
-
if (typeof rawSurfaces !== "object" || rawSurfaces === null || Array.isArray(rawSurfaces)) {
|
|
3882
|
+
if (!isPlainObject$1(rawSurfaces)) {
|
|
2101
3883
|
warnConfigField(`config field "surfaces" must be an object (got ${typeof rawSurfaces}); ignoring this field.`);
|
|
2102
3884
|
return;
|
|
2103
3885
|
}
|
|
@@ -2112,27 +3894,38 @@ const validateSurfacesField = (rawSurfaces) => {
|
|
|
2112
3894
|
}
|
|
2113
3895
|
return validated;
|
|
2114
3896
|
};
|
|
3897
|
+
const validateSeverityMap = (fieldName, rawMap) => {
|
|
3898
|
+
if (!isPlainObject$1(rawMap)) {
|
|
3899
|
+
warnConfigField(`config field "${fieldName}" must be an object (got ${typeof rawMap}); ignoring this field.`);
|
|
3900
|
+
return;
|
|
3901
|
+
}
|
|
3902
|
+
const validated = {};
|
|
3903
|
+
for (const [key, value] of Object.entries(rawMap)) {
|
|
3904
|
+
if (key.length === 0) {
|
|
3905
|
+
warnConfigField(`config field "${fieldName}" has an empty key; ignoring the entry.`);
|
|
3906
|
+
continue;
|
|
3907
|
+
}
|
|
3908
|
+
if (!isRuleSeverity(value)) {
|
|
3909
|
+
warnConfigField(`config field "${fieldName}.${key}" must be one of: ${VALID_RULE_SEVERITIES.join(", ")} (got ${formatType(value)}); ignoring the entry.`);
|
|
3910
|
+
continue;
|
|
3911
|
+
}
|
|
3912
|
+
validated[key] = value;
|
|
3913
|
+
}
|
|
3914
|
+
return validated;
|
|
3915
|
+
};
|
|
3916
|
+
const applyFieldValidator = (config, validated, fieldName, validator) => {
|
|
3917
|
+
const raw = config[fieldName];
|
|
3918
|
+
if (raw === void 0) return;
|
|
3919
|
+
const result = validator(raw);
|
|
3920
|
+
if (result === void 0) delete validated[fieldName];
|
|
3921
|
+
else validated[fieldName] = result;
|
|
3922
|
+
};
|
|
2115
3923
|
const validateConfigTypes = (config) => {
|
|
2116
3924
|
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
|
-
}
|
|
3925
|
+
for (const fieldName of BOOLEAN_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => coerceMaybeBooleanString(fieldName, value));
|
|
3926
|
+
for (const fieldName of STRING_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateString(fieldName, value));
|
|
3927
|
+
applyFieldValidator(config, validated, "surfaces", validateSurfacesField);
|
|
3928
|
+
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value));
|
|
2136
3929
|
return validated;
|
|
2137
3930
|
};
|
|
2138
3931
|
const CONFIG_FILENAME = "react-doctor.config.json";
|
|
@@ -2452,69 +4245,11 @@ const filterRulesToAvailable = (rules, pluginNamespace, availableRuleNames) => {
|
|
|
2452
4245
|
}
|
|
2453
4246
|
return filtered;
|
|
2454
4247
|
};
|
|
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
4248
|
const resolveSettingsRootDirectory = (rootDirectory) => {
|
|
2514
4249
|
if (!fs.existsSync(rootDirectory)) return rootDirectory;
|
|
2515
4250
|
return fs.realpathSync(rootDirectory);
|
|
2516
4251
|
};
|
|
2517
|
-
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames }) => {
|
|
4252
|
+
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames, severityControls }) => {
|
|
2518
4253
|
const reactHooksJsPlugin = resolveReactHooksJsPlugin(project.hasReactCompiler, customRulesOnly);
|
|
2519
4254
|
const reactCompilerRules = reactHooksJsPlugin ? filterRulesToAvailable(REACT_COMPILER_RULES, "react-hooks-js", reactHooksJsPlugin.availableRuleNames) : {};
|
|
2520
4255
|
const youMightNotNeedEffectPlugin = resolveYouMightNotNeedEffectPlugin(customRulesOnly);
|
|
@@ -2528,7 +4263,12 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
2528
4263
|
const fullKey = `react-doctor/${ruleId}`;
|
|
2529
4264
|
if (rule.framework !== "global" && !rule.requires) continue;
|
|
2530
4265
|
if (!shouldEnableRule(rule.requires, rule.tags, capabilities, ignoredTags)) continue;
|
|
2531
|
-
|
|
4266
|
+
const severity = resolveRuleSeverityOverride({
|
|
4267
|
+
ruleKey: fullKey,
|
|
4268
|
+
category: rule.category
|
|
4269
|
+
}, severityControls) ?? rule.severity;
|
|
4270
|
+
if (severity === "off") continue;
|
|
4271
|
+
enabledReactDoctorRules[fullKey] = severity;
|
|
2532
4272
|
}
|
|
2533
4273
|
return {
|
|
2534
4274
|
...extendsPaths.length > 0 ? { extends: extendsPaths } : {},
|
|
@@ -3062,6 +4802,7 @@ const validateRuleRegistration = () => {
|
|
|
3062
4802
|
const runOxlint = async (options) => {
|
|
3063
4803
|
const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), userConfig, onPartialFailure } = options;
|
|
3064
4804
|
const serverAuthFunctionNames = Array.isArray(userConfig?.serverAuthFunctionNames) ? userConfig.serverAuthFunctionNames.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
4805
|
+
const severityControls = buildRuleSeverityControls(userConfig);
|
|
3065
4806
|
validateRuleRegistration();
|
|
3066
4807
|
if (includePaths !== void 0 && includePaths.length === 0) return [];
|
|
3067
4808
|
const configDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
@@ -3074,7 +4815,8 @@ const runOxlint = async (options) => {
|
|
|
3074
4815
|
customRulesOnly,
|
|
3075
4816
|
extendsPaths,
|
|
3076
4817
|
ignoredTags,
|
|
3077
|
-
serverAuthFunctionNames
|
|
4818
|
+
serverAuthFunctionNames,
|
|
4819
|
+
severityControls
|
|
3078
4820
|
});
|
|
3079
4821
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
3080
4822
|
try {
|
|
@@ -3142,7 +4884,8 @@ const runOxlint = async (options) => {
|
|
|
3142
4884
|
customRulesOnly,
|
|
3143
4885
|
extendsPaths: [],
|
|
3144
4886
|
ignoredTags,
|
|
3145
|
-
serverAuthFunctionNames
|
|
4887
|
+
serverAuthFunctionNames,
|
|
4888
|
+
severityControls
|
|
3146
4889
|
}));
|
|
3147
4890
|
return await spawnLintBatches();
|
|
3148
4891
|
}
|