react-doctor 0.2.0-beta.4 → 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 +140 -8
- package/dist/cli.js +2102 -152
- package/dist/index.d.ts +149 -0
- package/dist/index.js +2035 -133
- package/dist/skills/react-doctor/SKILL.md +4 -4
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Command } from "commander";
|
|
|
3
3
|
import fs, { accessSync, constants, existsSync, mkdirSync, mkdtempSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path, { join } from "node:path";
|
|
5
5
|
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
-
import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES } from "oxlint-plugin-react-doctor";
|
|
6
|
+
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";
|
|
7
7
|
import os, { tmpdir } from "node:os";
|
|
8
8
|
import * as ts from "typescript";
|
|
9
9
|
import { performance } from "node:perf_hooks";
|
|
@@ -12,6 +12,49 @@ import { randomUUID } from "node:crypto";
|
|
|
12
12
|
import basePrompts from "prompts";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { SKILL_MANIFEST_FILE, detectInstalledSkillAgents, getSkillAgentConfig, getSkillAgentTypes, installSkillsFromSource } from "agent-install";
|
|
15
|
+
//#region \0rolldown/runtime.js
|
|
16
|
+
var __create$1 = Object.create;
|
|
17
|
+
var __defProp$1 = Object.defineProperty;
|
|
18
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
19
|
+
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
20
|
+
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
21
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
22
|
+
var __commonJSMin$1 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
23
|
+
var __copyProps$1 = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
|
+
key = keys[i];
|
|
26
|
+
if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
|
|
34
|
+
value: mod,
|
|
35
|
+
enumerable: true
|
|
36
|
+
}) : target, mod));
|
|
37
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region ../types/dist/index.js
|
|
40
|
+
const REACT_NATIVE_DEPENDENCY_NAMES = new Set([
|
|
41
|
+
"react-native",
|
|
42
|
+
"react-native-tvos",
|
|
43
|
+
"expo",
|
|
44
|
+
"expo-router",
|
|
45
|
+
"@expo/cli",
|
|
46
|
+
"@expo/metro-config",
|
|
47
|
+
"@expo/metro-runtime",
|
|
48
|
+
"react-native-windows",
|
|
49
|
+
"react-native-macos"
|
|
50
|
+
]);
|
|
51
|
+
const REACT_NATIVE_DEPENDENCY_PREFIXES = ["@react-native/", "@react-native-"];
|
|
52
|
+
const isReactNativeDependencyName = (dependencyName) => {
|
|
53
|
+
if (REACT_NATIVE_DEPENDENCY_NAMES.has(dependencyName)) return true;
|
|
54
|
+
for (const prefix of REACT_NATIVE_DEPENDENCY_PREFIXES) if (dependencyName.startsWith(prefix)) return true;
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
15
58
|
//#region ../project-info/dist/index.js
|
|
16
59
|
var ReactDoctorError = class extends Error {
|
|
17
60
|
name = "ReactDoctorError";
|
|
@@ -648,6 +691,34 @@ const findDependencyInfoFromMonorepoRoot = (directory) => {
|
|
|
648
691
|
framework: rootInfo.framework !== "unknown" ? rootInfo.framework : workspaceInfo.framework
|
|
649
692
|
};
|
|
650
693
|
};
|
|
694
|
+
const containsAnyReactNativeDependency = (section) => {
|
|
695
|
+
if (!section) return false;
|
|
696
|
+
for (const dependencyName of Object.keys(section)) if (isReactNativeDependencyName(dependencyName)) return true;
|
|
697
|
+
return false;
|
|
698
|
+
};
|
|
699
|
+
const isPackageJsonReactNativeAware = (packageJson) => {
|
|
700
|
+
if (typeof packageJson["react-native"] === "string") return true;
|
|
701
|
+
if (containsAnyReactNativeDependency(packageJson.dependencies)) return true;
|
|
702
|
+
if (containsAnyReactNativeDependency(packageJson.devDependencies)) return true;
|
|
703
|
+
if (containsAnyReactNativeDependency(packageJson.peerDependencies)) return true;
|
|
704
|
+
if (containsAnyReactNativeDependency(packageJson.optionalDependencies)) return true;
|
|
705
|
+
return false;
|
|
706
|
+
};
|
|
707
|
+
const hasReactNativeWorkspaceAnywhere = (rootDirectory, rootPackageJson) => {
|
|
708
|
+
if (isPackageJsonReactNativeAware(rootPackageJson)) return true;
|
|
709
|
+
const patterns = getWorkspacePatterns(rootDirectory, rootPackageJson);
|
|
710
|
+
if (patterns.length === 0) return false;
|
|
711
|
+
const visitedDirectories = /* @__PURE__ */ new Set();
|
|
712
|
+
for (const pattern of patterns) {
|
|
713
|
+
const directories = resolveWorkspaceDirectories(rootDirectory, pattern);
|
|
714
|
+
for (const workspaceDirectory of directories) {
|
|
715
|
+
if (visitedDirectories.has(workspaceDirectory)) continue;
|
|
716
|
+
visitedDirectories.add(workspaceDirectory);
|
|
717
|
+
if (isPackageJsonReactNativeAware(readPackageJson(path.join(workspaceDirectory, "package.json")))) return true;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return false;
|
|
721
|
+
};
|
|
651
722
|
const TANSTACK_QUERY_PACKAGES = new Set([
|
|
652
723
|
"@tanstack/react-query",
|
|
653
724
|
"@tanstack/query-core",
|
|
@@ -820,6 +891,7 @@ const discoverProject = (directory) => {
|
|
|
820
891
|
const projectName = packageJson.name ?? path.basename(directory);
|
|
821
892
|
const hasTypeScript = fs.existsSync(path.join(directory, "tsconfig.json"));
|
|
822
893
|
const sourceFileCount = countSourceFiles(directory);
|
|
894
|
+
const hasReactNativeWorkspace = framework === "expo" || framework === "react-native" || hasReactNativeWorkspaceAnywhere(directory, packageJson);
|
|
823
895
|
const projectInfo = {
|
|
824
896
|
rootDirectory: directory,
|
|
825
897
|
projectName,
|
|
@@ -830,6 +902,7 @@ const discoverProject = (directory) => {
|
|
|
830
902
|
hasTypeScript,
|
|
831
903
|
hasReactCompiler: detectReactCompiler(directory, packageJson),
|
|
832
904
|
hasTanStackQuery: hasTanStackQuery(packageJson),
|
|
905
|
+
hasReactNativeWorkspace,
|
|
833
906
|
sourceFileCount
|
|
834
907
|
};
|
|
835
908
|
cachedProjectInfos.set(directory, projectInfo);
|
|
@@ -865,7 +938,1661 @@ const isTailwindAtLeast = (detected, required) => {
|
|
|
865
938
|
return detected.minor >= required.minor;
|
|
866
939
|
};
|
|
867
940
|
//#endregion
|
|
941
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/constants.js
|
|
942
|
+
var require_constants = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
943
|
+
const path$3 = __require("path");
|
|
944
|
+
const WIN_SLASH = "\\\\/";
|
|
945
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
946
|
+
/**
|
|
947
|
+
* Posix glob regex
|
|
948
|
+
*/
|
|
949
|
+
const DOT_LITERAL = "\\.";
|
|
950
|
+
const PLUS_LITERAL = "\\+";
|
|
951
|
+
const QMARK_LITERAL = "\\?";
|
|
952
|
+
const SLASH_LITERAL = "\\/";
|
|
953
|
+
const ONE_CHAR = "(?=.)";
|
|
954
|
+
const QMARK = "[^/]";
|
|
955
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
956
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
957
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
958
|
+
const POSIX_CHARS = {
|
|
959
|
+
DOT_LITERAL,
|
|
960
|
+
PLUS_LITERAL,
|
|
961
|
+
QMARK_LITERAL,
|
|
962
|
+
SLASH_LITERAL,
|
|
963
|
+
ONE_CHAR,
|
|
964
|
+
QMARK,
|
|
965
|
+
END_ANCHOR,
|
|
966
|
+
DOTS_SLASH,
|
|
967
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
968
|
+
NO_DOTS: `(?!${START_ANCHOR}${DOTS_SLASH})`,
|
|
969
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`,
|
|
970
|
+
NO_DOTS_SLASH: `(?!${DOTS_SLASH})`,
|
|
971
|
+
QMARK_NO_DOT: `[^.${SLASH_LITERAL}]`,
|
|
972
|
+
STAR: `${QMARK}*?`,
|
|
973
|
+
START_ANCHOR
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* Windows glob regex
|
|
977
|
+
*/
|
|
978
|
+
const WINDOWS_CHARS = {
|
|
979
|
+
...POSIX_CHARS,
|
|
980
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
981
|
+
QMARK: WIN_NO_SLASH,
|
|
982
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
983
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
984
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
985
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
986
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
987
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
988
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
989
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
990
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
|
|
991
|
+
};
|
|
992
|
+
module.exports = {
|
|
993
|
+
MAX_LENGTH: 1024 * 64,
|
|
994
|
+
POSIX_REGEX_SOURCE: {
|
|
995
|
+
alnum: "a-zA-Z0-9",
|
|
996
|
+
alpha: "a-zA-Z",
|
|
997
|
+
ascii: "\\x00-\\x7F",
|
|
998
|
+
blank: " \\t",
|
|
999
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
1000
|
+
digit: "0-9",
|
|
1001
|
+
graph: "\\x21-\\x7E",
|
|
1002
|
+
lower: "a-z",
|
|
1003
|
+
print: "\\x20-\\x7E ",
|
|
1004
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
1005
|
+
space: " \\t\\r\\n\\v\\f",
|
|
1006
|
+
upper: "A-Z",
|
|
1007
|
+
word: "A-Za-z0-9_",
|
|
1008
|
+
xdigit: "A-Fa-f0-9"
|
|
1009
|
+
},
|
|
1010
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
1011
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
1012
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
1013
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
1014
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
1015
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
1016
|
+
REPLACEMENTS: {
|
|
1017
|
+
"***": "*",
|
|
1018
|
+
"**/**": "**",
|
|
1019
|
+
"**/**/**": "**"
|
|
1020
|
+
},
|
|
1021
|
+
CHAR_0: 48,
|
|
1022
|
+
CHAR_9: 57,
|
|
1023
|
+
CHAR_UPPERCASE_A: 65,
|
|
1024
|
+
CHAR_LOWERCASE_A: 97,
|
|
1025
|
+
CHAR_UPPERCASE_Z: 90,
|
|
1026
|
+
CHAR_LOWERCASE_Z: 122,
|
|
1027
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
1028
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
1029
|
+
CHAR_ASTERISK: 42,
|
|
1030
|
+
CHAR_AMPERSAND: 38,
|
|
1031
|
+
CHAR_AT: 64,
|
|
1032
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
1033
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
1034
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
1035
|
+
CHAR_COLON: 58,
|
|
1036
|
+
CHAR_COMMA: 44,
|
|
1037
|
+
CHAR_DOT: 46,
|
|
1038
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
1039
|
+
CHAR_EQUAL: 61,
|
|
1040
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
1041
|
+
CHAR_FORM_FEED: 12,
|
|
1042
|
+
CHAR_FORWARD_SLASH: 47,
|
|
1043
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
1044
|
+
CHAR_HASH: 35,
|
|
1045
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
1046
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
1047
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
1048
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
1049
|
+
CHAR_LINE_FEED: 10,
|
|
1050
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
1051
|
+
CHAR_PERCENT: 37,
|
|
1052
|
+
CHAR_PLUS: 43,
|
|
1053
|
+
CHAR_QUESTION_MARK: 63,
|
|
1054
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
1055
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
1056
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
1057
|
+
CHAR_SEMICOLON: 59,
|
|
1058
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
1059
|
+
CHAR_SPACE: 32,
|
|
1060
|
+
CHAR_TAB: 9,
|
|
1061
|
+
CHAR_UNDERSCORE: 95,
|
|
1062
|
+
CHAR_VERTICAL_LINE: 124,
|
|
1063
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
1064
|
+
SEP: path$3.sep,
|
|
1065
|
+
/**
|
|
1066
|
+
* Create EXTGLOB_CHARS
|
|
1067
|
+
*/
|
|
1068
|
+
extglobChars(chars) {
|
|
1069
|
+
return {
|
|
1070
|
+
"!": {
|
|
1071
|
+
type: "negate",
|
|
1072
|
+
open: "(?:(?!(?:",
|
|
1073
|
+
close: `))${chars.STAR})`
|
|
1074
|
+
},
|
|
1075
|
+
"?": {
|
|
1076
|
+
type: "qmark",
|
|
1077
|
+
open: "(?:",
|
|
1078
|
+
close: ")?"
|
|
1079
|
+
},
|
|
1080
|
+
"+": {
|
|
1081
|
+
type: "plus",
|
|
1082
|
+
open: "(?:",
|
|
1083
|
+
close: ")+"
|
|
1084
|
+
},
|
|
1085
|
+
"*": {
|
|
1086
|
+
type: "star",
|
|
1087
|
+
open: "(?:",
|
|
1088
|
+
close: ")*"
|
|
1089
|
+
},
|
|
1090
|
+
"@": {
|
|
1091
|
+
type: "at",
|
|
1092
|
+
open: "(?:",
|
|
1093
|
+
close: ")"
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
},
|
|
1097
|
+
/**
|
|
1098
|
+
* Create GLOB_CHARS
|
|
1099
|
+
*/
|
|
1100
|
+
globChars(win32) {
|
|
1101
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
}));
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/utils.js
|
|
1107
|
+
var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
1108
|
+
const path$2 = __require("path");
|
|
1109
|
+
const win32 = process.platform === "win32";
|
|
1110
|
+
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
1111
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
1112
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
1113
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
1114
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
1115
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
1116
|
+
exports.removeBackslashes = (str) => {
|
|
1117
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
1118
|
+
return match === "\\" ? "" : match;
|
|
1119
|
+
});
|
|
1120
|
+
};
|
|
1121
|
+
exports.supportsLookbehinds = () => {
|
|
1122
|
+
const segs = process.version.slice(1).split(".").map(Number);
|
|
1123
|
+
if (segs.length === 3 && segs[0] >= 9 || segs[0] === 8 && segs[1] >= 10) return true;
|
|
1124
|
+
return false;
|
|
1125
|
+
};
|
|
1126
|
+
exports.isWindows = (options) => {
|
|
1127
|
+
if (options && typeof options.windows === "boolean") return options.windows;
|
|
1128
|
+
return win32 === true || path$2.sep === "\\";
|
|
1129
|
+
};
|
|
1130
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
1131
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
1132
|
+
if (idx === -1) return input;
|
|
1133
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
1134
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
1135
|
+
};
|
|
1136
|
+
exports.removePrefix = (input, state = {}) => {
|
|
1137
|
+
let output = input;
|
|
1138
|
+
if (output.startsWith("./")) {
|
|
1139
|
+
output = output.slice(2);
|
|
1140
|
+
state.prefix = "./";
|
|
1141
|
+
}
|
|
1142
|
+
return output;
|
|
1143
|
+
};
|
|
1144
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
1145
|
+
let output = `${options.contains ? "" : "^"}(?:${input})${options.contains ? "" : "$"}`;
|
|
1146
|
+
if (state.negated === true) output = `(?:^(?!${output}).*$)`;
|
|
1147
|
+
return output;
|
|
1148
|
+
};
|
|
1149
|
+
}));
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/scan.js
|
|
1152
|
+
var require_scan = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1153
|
+
const utils = require_utils();
|
|
1154
|
+
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();
|
|
1155
|
+
const isPathSeparator = (code) => {
|
|
1156
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
1157
|
+
};
|
|
1158
|
+
const depth = (token) => {
|
|
1159
|
+
if (token.isPrefix !== true) token.depth = token.isGlobstar ? Infinity : 1;
|
|
1160
|
+
};
|
|
1161
|
+
/**
|
|
1162
|
+
* Quickly scans a glob pattern and returns an object with a handful of
|
|
1163
|
+
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
1164
|
+
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
1165
|
+
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
1166
|
+
*
|
|
1167
|
+
* ```js
|
|
1168
|
+
* const pm = require('picomatch');
|
|
1169
|
+
* console.log(pm.scan('foo/bar/*.js'));
|
|
1170
|
+
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
1171
|
+
* ```
|
|
1172
|
+
* @param {String} `str`
|
|
1173
|
+
* @param {Object} `options`
|
|
1174
|
+
* @return {Object} Returns an object with tokens and regex source string.
|
|
1175
|
+
* @api public
|
|
1176
|
+
*/
|
|
1177
|
+
const scan = (input, options) => {
|
|
1178
|
+
const opts = options || {};
|
|
1179
|
+
const length = input.length - 1;
|
|
1180
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
1181
|
+
const slashes = [];
|
|
1182
|
+
const tokens = [];
|
|
1183
|
+
const parts = [];
|
|
1184
|
+
let str = input;
|
|
1185
|
+
let index = -1;
|
|
1186
|
+
let start = 0;
|
|
1187
|
+
let lastIndex = 0;
|
|
1188
|
+
let isBrace = false;
|
|
1189
|
+
let isBracket = false;
|
|
1190
|
+
let isGlob = false;
|
|
1191
|
+
let isExtglob = false;
|
|
1192
|
+
let isGlobstar = false;
|
|
1193
|
+
let braceEscaped = false;
|
|
1194
|
+
let backslashes = false;
|
|
1195
|
+
let negated = false;
|
|
1196
|
+
let negatedExtglob = false;
|
|
1197
|
+
let finished = false;
|
|
1198
|
+
let braces = 0;
|
|
1199
|
+
let prev;
|
|
1200
|
+
let code;
|
|
1201
|
+
let token = {
|
|
1202
|
+
value: "",
|
|
1203
|
+
depth: 0,
|
|
1204
|
+
isGlob: false
|
|
1205
|
+
};
|
|
1206
|
+
const eos = () => index >= length;
|
|
1207
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
1208
|
+
const advance = () => {
|
|
1209
|
+
prev = code;
|
|
1210
|
+
return str.charCodeAt(++index);
|
|
1211
|
+
};
|
|
1212
|
+
while (index < length) {
|
|
1213
|
+
code = advance();
|
|
1214
|
+
let next;
|
|
1215
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1216
|
+
backslashes = token.backslashes = true;
|
|
1217
|
+
code = advance();
|
|
1218
|
+
if (code === CHAR_LEFT_CURLY_BRACE) braceEscaped = true;
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
1222
|
+
braces++;
|
|
1223
|
+
while (eos() !== true && (code = advance())) {
|
|
1224
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1225
|
+
backslashes = token.backslashes = true;
|
|
1226
|
+
advance();
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1229
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
1230
|
+
braces++;
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
1234
|
+
isBrace = token.isBrace = true;
|
|
1235
|
+
isGlob = token.isGlob = true;
|
|
1236
|
+
finished = true;
|
|
1237
|
+
if (scanToEnd === true) continue;
|
|
1238
|
+
break;
|
|
1239
|
+
}
|
|
1240
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
1241
|
+
isBrace = token.isBrace = true;
|
|
1242
|
+
isGlob = token.isGlob = true;
|
|
1243
|
+
finished = true;
|
|
1244
|
+
if (scanToEnd === true) continue;
|
|
1245
|
+
break;
|
|
1246
|
+
}
|
|
1247
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
1248
|
+
braces--;
|
|
1249
|
+
if (braces === 0) {
|
|
1250
|
+
braceEscaped = false;
|
|
1251
|
+
isBrace = token.isBrace = true;
|
|
1252
|
+
finished = true;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
if (scanToEnd === true) continue;
|
|
1258
|
+
break;
|
|
1259
|
+
}
|
|
1260
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
1261
|
+
slashes.push(index);
|
|
1262
|
+
tokens.push(token);
|
|
1263
|
+
token = {
|
|
1264
|
+
value: "",
|
|
1265
|
+
depth: 0,
|
|
1266
|
+
isGlob: false
|
|
1267
|
+
};
|
|
1268
|
+
if (finished === true) continue;
|
|
1269
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
1270
|
+
start += 2;
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
lastIndex = index + 1;
|
|
1274
|
+
continue;
|
|
1275
|
+
}
|
|
1276
|
+
if (opts.noext !== true) {
|
|
1277
|
+
if ((code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK) === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
1278
|
+
isGlob = token.isGlob = true;
|
|
1279
|
+
isExtglob = token.isExtglob = true;
|
|
1280
|
+
finished = true;
|
|
1281
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
|
|
1282
|
+
if (scanToEnd === true) {
|
|
1283
|
+
while (eos() !== true && (code = advance())) {
|
|
1284
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
1285
|
+
backslashes = token.backslashes = true;
|
|
1286
|
+
code = advance();
|
|
1287
|
+
continue;
|
|
1288
|
+
}
|
|
1289
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1290
|
+
isGlob = token.isGlob = true;
|
|
1291
|
+
finished = true;
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
if (code === CHAR_ASTERISK) {
|
|
1301
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
1302
|
+
isGlob = token.isGlob = true;
|
|
1303
|
+
finished = true;
|
|
1304
|
+
if (scanToEnd === true) continue;
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
1308
|
+
isGlob = token.isGlob = true;
|
|
1309
|
+
finished = true;
|
|
1310
|
+
if (scanToEnd === true) continue;
|
|
1311
|
+
break;
|
|
1312
|
+
}
|
|
1313
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
1314
|
+
while (eos() !== true && (next = advance())) {
|
|
1315
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
1316
|
+
backslashes = token.backslashes = true;
|
|
1317
|
+
advance();
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
1321
|
+
isBracket = token.isBracket = true;
|
|
1322
|
+
isGlob = token.isGlob = true;
|
|
1323
|
+
finished = true;
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (scanToEnd === true) continue;
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
1331
|
+
negated = token.negated = true;
|
|
1332
|
+
start++;
|
|
1333
|
+
continue;
|
|
1334
|
+
}
|
|
1335
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
1336
|
+
isGlob = token.isGlob = true;
|
|
1337
|
+
if (scanToEnd === true) {
|
|
1338
|
+
while (eos() !== true && (code = advance())) {
|
|
1339
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
1340
|
+
backslashes = token.backslashes = true;
|
|
1341
|
+
code = advance();
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1345
|
+
finished = true;
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
break;
|
|
1352
|
+
}
|
|
1353
|
+
if (isGlob === true) {
|
|
1354
|
+
finished = true;
|
|
1355
|
+
if (scanToEnd === true) continue;
|
|
1356
|
+
break;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if (opts.noext === true) {
|
|
1360
|
+
isExtglob = false;
|
|
1361
|
+
isGlob = false;
|
|
1362
|
+
}
|
|
1363
|
+
let base = str;
|
|
1364
|
+
let prefix = "";
|
|
1365
|
+
let glob = "";
|
|
1366
|
+
if (start > 0) {
|
|
1367
|
+
prefix = str.slice(0, start);
|
|
1368
|
+
str = str.slice(start);
|
|
1369
|
+
lastIndex -= start;
|
|
1370
|
+
}
|
|
1371
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
1372
|
+
base = str.slice(0, lastIndex);
|
|
1373
|
+
glob = str.slice(lastIndex);
|
|
1374
|
+
} else if (isGlob === true) {
|
|
1375
|
+
base = "";
|
|
1376
|
+
glob = str;
|
|
1377
|
+
} else base = str;
|
|
1378
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
1379
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) base = base.slice(0, -1);
|
|
1380
|
+
}
|
|
1381
|
+
if (opts.unescape === true) {
|
|
1382
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
1383
|
+
if (base && backslashes === true) base = utils.removeBackslashes(base);
|
|
1384
|
+
}
|
|
1385
|
+
const state = {
|
|
1386
|
+
prefix,
|
|
1387
|
+
input,
|
|
1388
|
+
start,
|
|
1389
|
+
base,
|
|
1390
|
+
glob,
|
|
1391
|
+
isBrace,
|
|
1392
|
+
isBracket,
|
|
1393
|
+
isGlob,
|
|
1394
|
+
isExtglob,
|
|
1395
|
+
isGlobstar,
|
|
1396
|
+
negated,
|
|
1397
|
+
negatedExtglob
|
|
1398
|
+
};
|
|
1399
|
+
if (opts.tokens === true) {
|
|
1400
|
+
state.maxDepth = 0;
|
|
1401
|
+
if (!isPathSeparator(code)) tokens.push(token);
|
|
1402
|
+
state.tokens = tokens;
|
|
1403
|
+
}
|
|
1404
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
1405
|
+
let prevIndex;
|
|
1406
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
1407
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
1408
|
+
const i = slashes[idx];
|
|
1409
|
+
const value = input.slice(n, i);
|
|
1410
|
+
if (opts.tokens) {
|
|
1411
|
+
if (idx === 0 && start !== 0) {
|
|
1412
|
+
tokens[idx].isPrefix = true;
|
|
1413
|
+
tokens[idx].value = prefix;
|
|
1414
|
+
} else tokens[idx].value = value;
|
|
1415
|
+
depth(tokens[idx]);
|
|
1416
|
+
state.maxDepth += tokens[idx].depth;
|
|
1417
|
+
}
|
|
1418
|
+
if (idx !== 0 || value !== "") parts.push(value);
|
|
1419
|
+
prevIndex = i;
|
|
1420
|
+
}
|
|
1421
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
1422
|
+
const value = input.slice(prevIndex + 1);
|
|
1423
|
+
parts.push(value);
|
|
1424
|
+
if (opts.tokens) {
|
|
1425
|
+
tokens[tokens.length - 1].value = value;
|
|
1426
|
+
depth(tokens[tokens.length - 1]);
|
|
1427
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
state.slashes = slashes;
|
|
1431
|
+
state.parts = parts;
|
|
1432
|
+
}
|
|
1433
|
+
return state;
|
|
1434
|
+
};
|
|
1435
|
+
module.exports = scan;
|
|
1436
|
+
}));
|
|
1437
|
+
//#endregion
|
|
1438
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/parse.js
|
|
1439
|
+
var require_parse = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1440
|
+
const constants = require_constants();
|
|
1441
|
+
const utils = require_utils();
|
|
1442
|
+
/**
|
|
1443
|
+
* Constants
|
|
1444
|
+
*/
|
|
1445
|
+
const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants;
|
|
1446
|
+
/**
|
|
1447
|
+
* Helpers
|
|
1448
|
+
*/
|
|
1449
|
+
const expandRange = (args, options) => {
|
|
1450
|
+
if (typeof options.expandRange === "function") return options.expandRange(...args, options);
|
|
1451
|
+
args.sort();
|
|
1452
|
+
const value = `[${args.join("-")}]`;
|
|
1453
|
+
try {
|
|
1454
|
+
new RegExp(value);
|
|
1455
|
+
} catch (ex) {
|
|
1456
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
1457
|
+
}
|
|
1458
|
+
return value;
|
|
1459
|
+
};
|
|
1460
|
+
/**
|
|
1461
|
+
* Create the message for a syntax error
|
|
1462
|
+
*/
|
|
1463
|
+
const syntaxError = (type, char) => {
|
|
1464
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
1465
|
+
};
|
|
1466
|
+
/**
|
|
1467
|
+
* Parse the given input string.
|
|
1468
|
+
* @param {String} input
|
|
1469
|
+
* @param {Object} options
|
|
1470
|
+
* @return {Object}
|
|
1471
|
+
*/
|
|
1472
|
+
const parse = (input, options) => {
|
|
1473
|
+
if (typeof input !== "string") throw new TypeError("Expected a string");
|
|
1474
|
+
input = REPLACEMENTS[input] || input;
|
|
1475
|
+
const opts = { ...options };
|
|
1476
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1477
|
+
let len = input.length;
|
|
1478
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1479
|
+
const bos = {
|
|
1480
|
+
type: "bos",
|
|
1481
|
+
value: "",
|
|
1482
|
+
output: opts.prepend || ""
|
|
1483
|
+
};
|
|
1484
|
+
const tokens = [bos];
|
|
1485
|
+
const capture = opts.capture ? "" : "?:";
|
|
1486
|
+
const win32 = utils.isWindows(options);
|
|
1487
|
+
const PLATFORM_CHARS = constants.globChars(win32);
|
|
1488
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
1489
|
+
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;
|
|
1490
|
+
const globstar = (opts) => {
|
|
1491
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1492
|
+
};
|
|
1493
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
1494
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
1495
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
1496
|
+
if (opts.capture) star = `(${star})`;
|
|
1497
|
+
if (typeof opts.noext === "boolean") opts.noextglob = opts.noext;
|
|
1498
|
+
const state = {
|
|
1499
|
+
input,
|
|
1500
|
+
index: -1,
|
|
1501
|
+
start: 0,
|
|
1502
|
+
dot: opts.dot === true,
|
|
1503
|
+
consumed: "",
|
|
1504
|
+
output: "",
|
|
1505
|
+
prefix: "",
|
|
1506
|
+
backtrack: false,
|
|
1507
|
+
negated: false,
|
|
1508
|
+
brackets: 0,
|
|
1509
|
+
braces: 0,
|
|
1510
|
+
parens: 0,
|
|
1511
|
+
quotes: 0,
|
|
1512
|
+
globstar: false,
|
|
1513
|
+
tokens
|
|
1514
|
+
};
|
|
1515
|
+
input = utils.removePrefix(input, state);
|
|
1516
|
+
len = input.length;
|
|
1517
|
+
const extglobs = [];
|
|
1518
|
+
const braces = [];
|
|
1519
|
+
const stack = [];
|
|
1520
|
+
let prev = bos;
|
|
1521
|
+
let value;
|
|
1522
|
+
/**
|
|
1523
|
+
* Tokenizing helpers
|
|
1524
|
+
*/
|
|
1525
|
+
const eos = () => state.index === len - 1;
|
|
1526
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
1527
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
1528
|
+
const remaining = () => input.slice(state.index + 1);
|
|
1529
|
+
const consume = (value = "", num = 0) => {
|
|
1530
|
+
state.consumed += value;
|
|
1531
|
+
state.index += num;
|
|
1532
|
+
};
|
|
1533
|
+
const append = (token) => {
|
|
1534
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1535
|
+
consume(token.value);
|
|
1536
|
+
};
|
|
1537
|
+
const negate = () => {
|
|
1538
|
+
let count = 1;
|
|
1539
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
1540
|
+
advance();
|
|
1541
|
+
state.start++;
|
|
1542
|
+
count++;
|
|
1543
|
+
}
|
|
1544
|
+
if (count % 2 === 0) return false;
|
|
1545
|
+
state.negated = true;
|
|
1546
|
+
state.start++;
|
|
1547
|
+
return true;
|
|
1548
|
+
};
|
|
1549
|
+
const increment = (type) => {
|
|
1550
|
+
state[type]++;
|
|
1551
|
+
stack.push(type);
|
|
1552
|
+
};
|
|
1553
|
+
const decrement = (type) => {
|
|
1554
|
+
state[type]--;
|
|
1555
|
+
stack.pop();
|
|
1556
|
+
};
|
|
1557
|
+
/**
|
|
1558
|
+
* Push tokens onto the tokens array. This helper speeds up
|
|
1559
|
+
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
1560
|
+
* and 2) helping us avoid creating extra tokens when consecutive
|
|
1561
|
+
* characters are plain text. This improves performance and simplifies
|
|
1562
|
+
* lookbehinds.
|
|
1563
|
+
*/
|
|
1564
|
+
const push = (tok) => {
|
|
1565
|
+
if (prev.type === "globstar") {
|
|
1566
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
1567
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
1568
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
1569
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1570
|
+
prev.type = "star";
|
|
1571
|
+
prev.value = "*";
|
|
1572
|
+
prev.output = star;
|
|
1573
|
+
state.output += prev.output;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
if (extglobs.length && tok.type !== "paren") extglobs[extglobs.length - 1].inner += tok.value;
|
|
1577
|
+
if (tok.value || tok.output) append(tok);
|
|
1578
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
1579
|
+
prev.value += tok.value;
|
|
1580
|
+
prev.output = (prev.output || "") + tok.value;
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
tok.prev = prev;
|
|
1584
|
+
tokens.push(tok);
|
|
1585
|
+
prev = tok;
|
|
1586
|
+
};
|
|
1587
|
+
const extglobOpen = (type, value) => {
|
|
1588
|
+
const token = {
|
|
1589
|
+
...EXTGLOB_CHARS[value],
|
|
1590
|
+
conditions: 1,
|
|
1591
|
+
inner: ""
|
|
1592
|
+
};
|
|
1593
|
+
token.prev = prev;
|
|
1594
|
+
token.parens = state.parens;
|
|
1595
|
+
token.output = state.output;
|
|
1596
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
1597
|
+
increment("parens");
|
|
1598
|
+
push({
|
|
1599
|
+
type,
|
|
1600
|
+
value,
|
|
1601
|
+
output: state.output ? "" : ONE_CHAR
|
|
1602
|
+
});
|
|
1603
|
+
push({
|
|
1604
|
+
type: "paren",
|
|
1605
|
+
extglob: true,
|
|
1606
|
+
value: advance(),
|
|
1607
|
+
output
|
|
1608
|
+
});
|
|
1609
|
+
extglobs.push(token);
|
|
1610
|
+
};
|
|
1611
|
+
const extglobClose = (token) => {
|
|
1612
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
1613
|
+
let rest;
|
|
1614
|
+
if (token.type === "negate") {
|
|
1615
|
+
let extglobStar = star;
|
|
1616
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) extglobStar = globstar(opts);
|
|
1617
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) output = token.close = `)$))${extglobStar}`;
|
|
1618
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) output = token.close = `)${parse(rest, {
|
|
1619
|
+
...options,
|
|
1620
|
+
fastpaths: false
|
|
1621
|
+
}).output})${extglobStar})`;
|
|
1622
|
+
if (token.prev.type === "bos") state.negatedExtglob = true;
|
|
1623
|
+
}
|
|
1624
|
+
push({
|
|
1625
|
+
type: "paren",
|
|
1626
|
+
extglob: true,
|
|
1627
|
+
value,
|
|
1628
|
+
output
|
|
1629
|
+
});
|
|
1630
|
+
decrement("parens");
|
|
1631
|
+
};
|
|
1632
|
+
/**
|
|
1633
|
+
* Fast paths
|
|
1634
|
+
*/
|
|
1635
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
1636
|
+
let backslashes = false;
|
|
1637
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
1638
|
+
if (first === "\\") {
|
|
1639
|
+
backslashes = true;
|
|
1640
|
+
return m;
|
|
1641
|
+
}
|
|
1642
|
+
if (first === "?") {
|
|
1643
|
+
if (esc) return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
1644
|
+
if (index === 0) return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
1645
|
+
return QMARK.repeat(chars.length);
|
|
1646
|
+
}
|
|
1647
|
+
if (first === ".") return DOT_LITERAL.repeat(chars.length);
|
|
1648
|
+
if (first === "*") {
|
|
1649
|
+
if (esc) return esc + first + (rest ? star : "");
|
|
1650
|
+
return star;
|
|
1651
|
+
}
|
|
1652
|
+
return esc ? m : `\\${m}`;
|
|
1653
|
+
});
|
|
1654
|
+
if (backslashes === true) if (opts.unescape === true) output = output.replace(/\\/g, "");
|
|
1655
|
+
else output = output.replace(/\\+/g, (m) => {
|
|
1656
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
1657
|
+
});
|
|
1658
|
+
if (output === input && opts.contains === true) {
|
|
1659
|
+
state.output = input;
|
|
1660
|
+
return state;
|
|
1661
|
+
}
|
|
1662
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
1663
|
+
return state;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Tokenize input until we reach end-of-string
|
|
1667
|
+
*/
|
|
1668
|
+
while (!eos()) {
|
|
1669
|
+
value = advance();
|
|
1670
|
+
if (value === "\0") continue;
|
|
1671
|
+
/**
|
|
1672
|
+
* Escaped characters
|
|
1673
|
+
*/
|
|
1674
|
+
if (value === "\\") {
|
|
1675
|
+
const next = peek();
|
|
1676
|
+
if (next === "/" && opts.bash !== true) continue;
|
|
1677
|
+
if (next === "." || next === ";") continue;
|
|
1678
|
+
if (!next) {
|
|
1679
|
+
value += "\\";
|
|
1680
|
+
push({
|
|
1681
|
+
type: "text",
|
|
1682
|
+
value
|
|
1683
|
+
});
|
|
1684
|
+
continue;
|
|
1685
|
+
}
|
|
1686
|
+
const match = /^\\+/.exec(remaining());
|
|
1687
|
+
let slashes = 0;
|
|
1688
|
+
if (match && match[0].length > 2) {
|
|
1689
|
+
slashes = match[0].length;
|
|
1690
|
+
state.index += slashes;
|
|
1691
|
+
if (slashes % 2 !== 0) value += "\\";
|
|
1692
|
+
}
|
|
1693
|
+
if (opts.unescape === true) value = advance();
|
|
1694
|
+
else value += advance();
|
|
1695
|
+
if (state.brackets === 0) {
|
|
1696
|
+
push({
|
|
1697
|
+
type: "text",
|
|
1698
|
+
value
|
|
1699
|
+
});
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* If we're inside a regex character class, continue
|
|
1705
|
+
* until we reach the closing bracket.
|
|
1706
|
+
*/
|
|
1707
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
1708
|
+
if (opts.posix !== false && value === ":") {
|
|
1709
|
+
const inner = prev.value.slice(1);
|
|
1710
|
+
if (inner.includes("[")) {
|
|
1711
|
+
prev.posix = true;
|
|
1712
|
+
if (inner.includes(":")) {
|
|
1713
|
+
const idx = prev.value.lastIndexOf("[");
|
|
1714
|
+
const pre = prev.value.slice(0, idx);
|
|
1715
|
+
const posix = POSIX_REGEX_SOURCE[prev.value.slice(idx + 2)];
|
|
1716
|
+
if (posix) {
|
|
1717
|
+
prev.value = pre + posix;
|
|
1718
|
+
state.backtrack = true;
|
|
1719
|
+
advance();
|
|
1720
|
+
if (!bos.output && tokens.indexOf(prev) === 1) bos.output = ONE_CHAR;
|
|
1721
|
+
continue;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") value = `\\${value}`;
|
|
1727
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) value = `\\${value}`;
|
|
1728
|
+
if (opts.posix === true && value === "!" && prev.value === "[") value = "^";
|
|
1729
|
+
prev.value += value;
|
|
1730
|
+
append({ value });
|
|
1731
|
+
continue;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* If we're inside a quoted string, continue
|
|
1735
|
+
* until we reach the closing double quote.
|
|
1736
|
+
*/
|
|
1737
|
+
if (state.quotes === 1 && value !== "\"") {
|
|
1738
|
+
value = utils.escapeRegex(value);
|
|
1739
|
+
prev.value += value;
|
|
1740
|
+
append({ value });
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
/**
|
|
1744
|
+
* Double quotes
|
|
1745
|
+
*/
|
|
1746
|
+
if (value === "\"") {
|
|
1747
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
1748
|
+
if (opts.keepQuotes === true) push({
|
|
1749
|
+
type: "text",
|
|
1750
|
+
value
|
|
1751
|
+
});
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Parentheses
|
|
1756
|
+
*/
|
|
1757
|
+
if (value === "(") {
|
|
1758
|
+
increment("parens");
|
|
1759
|
+
push({
|
|
1760
|
+
type: "paren",
|
|
1761
|
+
value
|
|
1762
|
+
});
|
|
1763
|
+
continue;
|
|
1764
|
+
}
|
|
1765
|
+
if (value === ")") {
|
|
1766
|
+
if (state.parens === 0 && opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "("));
|
|
1767
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
1768
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
1769
|
+
extglobClose(extglobs.pop());
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
push({
|
|
1773
|
+
type: "paren",
|
|
1774
|
+
value,
|
|
1775
|
+
output: state.parens ? ")" : "\\)"
|
|
1776
|
+
});
|
|
1777
|
+
decrement("parens");
|
|
1778
|
+
continue;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Square brackets
|
|
1782
|
+
*/
|
|
1783
|
+
if (value === "[") {
|
|
1784
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
1785
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1786
|
+
value = `\\${value}`;
|
|
1787
|
+
} else increment("brackets");
|
|
1788
|
+
push({
|
|
1789
|
+
type: "bracket",
|
|
1790
|
+
value
|
|
1791
|
+
});
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
if (value === "]") {
|
|
1795
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
1796
|
+
push({
|
|
1797
|
+
type: "text",
|
|
1798
|
+
value,
|
|
1799
|
+
output: `\\${value}`
|
|
1800
|
+
});
|
|
1801
|
+
continue;
|
|
1802
|
+
}
|
|
1803
|
+
if (state.brackets === 0) {
|
|
1804
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "["));
|
|
1805
|
+
push({
|
|
1806
|
+
type: "text",
|
|
1807
|
+
value,
|
|
1808
|
+
output: `\\${value}`
|
|
1809
|
+
});
|
|
1810
|
+
continue;
|
|
1811
|
+
}
|
|
1812
|
+
decrement("brackets");
|
|
1813
|
+
const prevValue = prev.value.slice(1);
|
|
1814
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) value = `/${value}`;
|
|
1815
|
+
prev.value += value;
|
|
1816
|
+
append({ value });
|
|
1817
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) continue;
|
|
1818
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
1819
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
1820
|
+
if (opts.literalBrackets === true) {
|
|
1821
|
+
state.output += escaped;
|
|
1822
|
+
prev.value = escaped;
|
|
1823
|
+
continue;
|
|
1824
|
+
}
|
|
1825
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1826
|
+
state.output += prev.value;
|
|
1827
|
+
continue;
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Braces
|
|
1831
|
+
*/
|
|
1832
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1833
|
+
increment("braces");
|
|
1834
|
+
const open = {
|
|
1835
|
+
type: "brace",
|
|
1836
|
+
value,
|
|
1837
|
+
output: "(",
|
|
1838
|
+
outputIndex: state.output.length,
|
|
1839
|
+
tokensIndex: state.tokens.length
|
|
1840
|
+
};
|
|
1841
|
+
braces.push(open);
|
|
1842
|
+
push(open);
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
if (value === "}") {
|
|
1846
|
+
const brace = braces[braces.length - 1];
|
|
1847
|
+
if (opts.nobrace === true || !brace) {
|
|
1848
|
+
push({
|
|
1849
|
+
type: "text",
|
|
1850
|
+
value,
|
|
1851
|
+
output: value
|
|
1852
|
+
});
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
let output = ")";
|
|
1856
|
+
if (brace.dots === true) {
|
|
1857
|
+
const arr = tokens.slice();
|
|
1858
|
+
const range = [];
|
|
1859
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1860
|
+
tokens.pop();
|
|
1861
|
+
if (arr[i].type === "brace") break;
|
|
1862
|
+
if (arr[i].type !== "dots") range.unshift(arr[i].value);
|
|
1863
|
+
}
|
|
1864
|
+
output = expandRange(range, opts);
|
|
1865
|
+
state.backtrack = true;
|
|
1866
|
+
}
|
|
1867
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1868
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1869
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1870
|
+
brace.value = brace.output = "\\{";
|
|
1871
|
+
value = output = "\\}";
|
|
1872
|
+
state.output = out;
|
|
1873
|
+
for (const t of toks) state.output += t.output || t.value;
|
|
1874
|
+
}
|
|
1875
|
+
push({
|
|
1876
|
+
type: "brace",
|
|
1877
|
+
value,
|
|
1878
|
+
output
|
|
1879
|
+
});
|
|
1880
|
+
decrement("braces");
|
|
1881
|
+
braces.pop();
|
|
1882
|
+
continue;
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Pipes
|
|
1886
|
+
*/
|
|
1887
|
+
if (value === "|") {
|
|
1888
|
+
if (extglobs.length > 0) extglobs[extglobs.length - 1].conditions++;
|
|
1889
|
+
push({
|
|
1890
|
+
type: "text",
|
|
1891
|
+
value
|
|
1892
|
+
});
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Commas
|
|
1897
|
+
*/
|
|
1898
|
+
if (value === ",") {
|
|
1899
|
+
let output = value;
|
|
1900
|
+
const brace = braces[braces.length - 1];
|
|
1901
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1902
|
+
brace.comma = true;
|
|
1903
|
+
output = "|";
|
|
1904
|
+
}
|
|
1905
|
+
push({
|
|
1906
|
+
type: "comma",
|
|
1907
|
+
value,
|
|
1908
|
+
output
|
|
1909
|
+
});
|
|
1910
|
+
continue;
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Slashes
|
|
1914
|
+
*/
|
|
1915
|
+
if (value === "/") {
|
|
1916
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1917
|
+
state.start = state.index + 1;
|
|
1918
|
+
state.consumed = "";
|
|
1919
|
+
state.output = "";
|
|
1920
|
+
tokens.pop();
|
|
1921
|
+
prev = bos;
|
|
1922
|
+
continue;
|
|
1923
|
+
}
|
|
1924
|
+
push({
|
|
1925
|
+
type: "slash",
|
|
1926
|
+
value,
|
|
1927
|
+
output: SLASH_LITERAL
|
|
1928
|
+
});
|
|
1929
|
+
continue;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Dots
|
|
1933
|
+
*/
|
|
1934
|
+
if (value === ".") {
|
|
1935
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1936
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1937
|
+
const brace = braces[braces.length - 1];
|
|
1938
|
+
prev.type = "dots";
|
|
1939
|
+
prev.output += value;
|
|
1940
|
+
prev.value += value;
|
|
1941
|
+
brace.dots = true;
|
|
1942
|
+
continue;
|
|
1943
|
+
}
|
|
1944
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1945
|
+
push({
|
|
1946
|
+
type: "text",
|
|
1947
|
+
value,
|
|
1948
|
+
output: DOT_LITERAL
|
|
1949
|
+
});
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
push({
|
|
1953
|
+
type: "dot",
|
|
1954
|
+
value,
|
|
1955
|
+
output: DOT_LITERAL
|
|
1956
|
+
});
|
|
1957
|
+
continue;
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Question marks
|
|
1961
|
+
*/
|
|
1962
|
+
if (value === "?") {
|
|
1963
|
+
if (!(prev && prev.value === "(") && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1964
|
+
extglobOpen("qmark", value);
|
|
1965
|
+
continue;
|
|
1966
|
+
}
|
|
1967
|
+
if (prev && prev.type === "paren") {
|
|
1968
|
+
const next = peek();
|
|
1969
|
+
let output = value;
|
|
1970
|
+
if (next === "<" && !utils.supportsLookbehinds()) throw new Error("Node.js v10 or higher is required for regex lookbehinds");
|
|
1971
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) output = `\\${value}`;
|
|
1972
|
+
push({
|
|
1973
|
+
type: "text",
|
|
1974
|
+
value,
|
|
1975
|
+
output
|
|
1976
|
+
});
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1979
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1980
|
+
push({
|
|
1981
|
+
type: "qmark",
|
|
1982
|
+
value,
|
|
1983
|
+
output: QMARK_NO_DOT
|
|
1984
|
+
});
|
|
1985
|
+
continue;
|
|
1986
|
+
}
|
|
1987
|
+
push({
|
|
1988
|
+
type: "qmark",
|
|
1989
|
+
value,
|
|
1990
|
+
output: QMARK
|
|
1991
|
+
});
|
|
1992
|
+
continue;
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* Exclamation
|
|
1996
|
+
*/
|
|
1997
|
+
if (value === "!") {
|
|
1998
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1999
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
2000
|
+
extglobOpen("negate", value);
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
2005
|
+
negate();
|
|
2006
|
+
continue;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Plus
|
|
2011
|
+
*/
|
|
2012
|
+
if (value === "+") {
|
|
2013
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2014
|
+
extglobOpen("plus", value);
|
|
2015
|
+
continue;
|
|
2016
|
+
}
|
|
2017
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
2018
|
+
push({
|
|
2019
|
+
type: "plus",
|
|
2020
|
+
value,
|
|
2021
|
+
output: PLUS_LITERAL
|
|
2022
|
+
});
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
2026
|
+
push({
|
|
2027
|
+
type: "plus",
|
|
2028
|
+
value
|
|
2029
|
+
});
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
push({
|
|
2033
|
+
type: "plus",
|
|
2034
|
+
value: PLUS_LITERAL
|
|
2035
|
+
});
|
|
2036
|
+
continue;
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Plain text
|
|
2040
|
+
*/
|
|
2041
|
+
if (value === "@") {
|
|
2042
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
2043
|
+
push({
|
|
2044
|
+
type: "at",
|
|
2045
|
+
extglob: true,
|
|
2046
|
+
value,
|
|
2047
|
+
output: ""
|
|
2048
|
+
});
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
push({
|
|
2052
|
+
type: "text",
|
|
2053
|
+
value
|
|
2054
|
+
});
|
|
2055
|
+
continue;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Plain text
|
|
2059
|
+
*/
|
|
2060
|
+
if (value !== "*") {
|
|
2061
|
+
if (value === "$" || value === "^") value = `\\${value}`;
|
|
2062
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
2063
|
+
if (match) {
|
|
2064
|
+
value += match[0];
|
|
2065
|
+
state.index += match[0].length;
|
|
2066
|
+
}
|
|
2067
|
+
push({
|
|
2068
|
+
type: "text",
|
|
2069
|
+
value
|
|
2070
|
+
});
|
|
2071
|
+
continue;
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* Stars
|
|
2075
|
+
*/
|
|
2076
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
2077
|
+
prev.type = "star";
|
|
2078
|
+
prev.star = true;
|
|
2079
|
+
prev.value += value;
|
|
2080
|
+
prev.output = star;
|
|
2081
|
+
state.backtrack = true;
|
|
2082
|
+
state.globstar = true;
|
|
2083
|
+
consume(value);
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
let rest = remaining();
|
|
2087
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
2088
|
+
extglobOpen("star", value);
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2091
|
+
if (prev.type === "star") {
|
|
2092
|
+
if (opts.noglobstar === true) {
|
|
2093
|
+
consume(value);
|
|
2094
|
+
continue;
|
|
2095
|
+
}
|
|
2096
|
+
const prior = prev.prev;
|
|
2097
|
+
const before = prior.prev;
|
|
2098
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
2099
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
2100
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
2101
|
+
push({
|
|
2102
|
+
type: "star",
|
|
2103
|
+
value,
|
|
2104
|
+
output: ""
|
|
2105
|
+
});
|
|
2106
|
+
continue;
|
|
2107
|
+
}
|
|
2108
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
2109
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
2110
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
2111
|
+
push({
|
|
2112
|
+
type: "star",
|
|
2113
|
+
value,
|
|
2114
|
+
output: ""
|
|
2115
|
+
});
|
|
2116
|
+
continue;
|
|
2117
|
+
}
|
|
2118
|
+
while (rest.slice(0, 3) === "/**") {
|
|
2119
|
+
const after = input[state.index + 4];
|
|
2120
|
+
if (after && after !== "/") break;
|
|
2121
|
+
rest = rest.slice(3);
|
|
2122
|
+
consume("/**", 3);
|
|
2123
|
+
}
|
|
2124
|
+
if (prior.type === "bos" && eos()) {
|
|
2125
|
+
prev.type = "globstar";
|
|
2126
|
+
prev.value += value;
|
|
2127
|
+
prev.output = globstar(opts);
|
|
2128
|
+
state.output = prev.output;
|
|
2129
|
+
state.globstar = true;
|
|
2130
|
+
consume(value);
|
|
2131
|
+
continue;
|
|
2132
|
+
}
|
|
2133
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
2134
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
2135
|
+
prior.output = `(?:${prior.output}`;
|
|
2136
|
+
prev.type = "globstar";
|
|
2137
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
2138
|
+
prev.value += value;
|
|
2139
|
+
state.globstar = true;
|
|
2140
|
+
state.output += prior.output + prev.output;
|
|
2141
|
+
consume(value);
|
|
2142
|
+
continue;
|
|
2143
|
+
}
|
|
2144
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
2145
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
2146
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
2147
|
+
prior.output = `(?:${prior.output}`;
|
|
2148
|
+
prev.type = "globstar";
|
|
2149
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
2150
|
+
prev.value += value;
|
|
2151
|
+
state.output += prior.output + prev.output;
|
|
2152
|
+
state.globstar = true;
|
|
2153
|
+
consume(value + advance());
|
|
2154
|
+
push({
|
|
2155
|
+
type: "slash",
|
|
2156
|
+
value: "/",
|
|
2157
|
+
output: ""
|
|
2158
|
+
});
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
2161
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
2162
|
+
prev.type = "globstar";
|
|
2163
|
+
prev.value += value;
|
|
2164
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
2165
|
+
state.output = prev.output;
|
|
2166
|
+
state.globstar = true;
|
|
2167
|
+
consume(value + advance());
|
|
2168
|
+
push({
|
|
2169
|
+
type: "slash",
|
|
2170
|
+
value: "/",
|
|
2171
|
+
output: ""
|
|
2172
|
+
});
|
|
2173
|
+
continue;
|
|
2174
|
+
}
|
|
2175
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
2176
|
+
prev.type = "globstar";
|
|
2177
|
+
prev.output = globstar(opts);
|
|
2178
|
+
prev.value += value;
|
|
2179
|
+
state.output += prev.output;
|
|
2180
|
+
state.globstar = true;
|
|
2181
|
+
consume(value);
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
const token = {
|
|
2185
|
+
type: "star",
|
|
2186
|
+
value,
|
|
2187
|
+
output: star
|
|
2188
|
+
};
|
|
2189
|
+
if (opts.bash === true) {
|
|
2190
|
+
token.output = ".*?";
|
|
2191
|
+
if (prev.type === "bos" || prev.type === "slash") token.output = nodot + token.output;
|
|
2192
|
+
push(token);
|
|
2193
|
+
continue;
|
|
2194
|
+
}
|
|
2195
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
2196
|
+
token.output = value;
|
|
2197
|
+
push(token);
|
|
2198
|
+
continue;
|
|
2199
|
+
}
|
|
2200
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
2201
|
+
if (prev.type === "dot") {
|
|
2202
|
+
state.output += NO_DOT_SLASH;
|
|
2203
|
+
prev.output += NO_DOT_SLASH;
|
|
2204
|
+
} else if (opts.dot === true) {
|
|
2205
|
+
state.output += NO_DOTS_SLASH;
|
|
2206
|
+
prev.output += NO_DOTS_SLASH;
|
|
2207
|
+
} else {
|
|
2208
|
+
state.output += nodot;
|
|
2209
|
+
prev.output += nodot;
|
|
2210
|
+
}
|
|
2211
|
+
if (peek() !== "*") {
|
|
2212
|
+
state.output += ONE_CHAR;
|
|
2213
|
+
prev.output += ONE_CHAR;
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
push(token);
|
|
2217
|
+
}
|
|
2218
|
+
while (state.brackets > 0) {
|
|
2219
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
2220
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
2221
|
+
decrement("brackets");
|
|
2222
|
+
}
|
|
2223
|
+
while (state.parens > 0) {
|
|
2224
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
2225
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
2226
|
+
decrement("parens");
|
|
2227
|
+
}
|
|
2228
|
+
while (state.braces > 0) {
|
|
2229
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
2230
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
2231
|
+
decrement("braces");
|
|
2232
|
+
}
|
|
2233
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) push({
|
|
2234
|
+
type: "maybe_slash",
|
|
2235
|
+
value: "",
|
|
2236
|
+
output: `${SLASH_LITERAL}?`
|
|
2237
|
+
});
|
|
2238
|
+
if (state.backtrack === true) {
|
|
2239
|
+
state.output = "";
|
|
2240
|
+
for (const token of state.tokens) {
|
|
2241
|
+
state.output += token.output != null ? token.output : token.value;
|
|
2242
|
+
if (token.suffix) state.output += token.suffix;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
return state;
|
|
2246
|
+
};
|
|
2247
|
+
/**
|
|
2248
|
+
* Fast paths for creating regular expressions for common glob patterns.
|
|
2249
|
+
* This can significantly speed up processing and has very little downside
|
|
2250
|
+
* impact when none of the fast paths match.
|
|
2251
|
+
*/
|
|
2252
|
+
parse.fastpaths = (input, options) => {
|
|
2253
|
+
const opts = { ...options };
|
|
2254
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
2255
|
+
const len = input.length;
|
|
2256
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
2257
|
+
input = REPLACEMENTS[input] || input;
|
|
2258
|
+
const win32 = utils.isWindows(options);
|
|
2259
|
+
const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants.globChars(win32);
|
|
2260
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
2261
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
2262
|
+
const capture = opts.capture ? "" : "?:";
|
|
2263
|
+
const state = {
|
|
2264
|
+
negated: false,
|
|
2265
|
+
prefix: ""
|
|
2266
|
+
};
|
|
2267
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
2268
|
+
if (opts.capture) star = `(${star})`;
|
|
2269
|
+
const globstar = (opts) => {
|
|
2270
|
+
if (opts.noglobstar === true) return star;
|
|
2271
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
2272
|
+
};
|
|
2273
|
+
const create = (str) => {
|
|
2274
|
+
switch (str) {
|
|
2275
|
+
case "*": return `${nodot}${ONE_CHAR}${star}`;
|
|
2276
|
+
case ".*": return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2277
|
+
case "*.*": return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2278
|
+
case "*/*": return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
2279
|
+
case "**": return nodot + globstar(opts);
|
|
2280
|
+
case "**/*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
2281
|
+
case "**/*.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2282
|
+
case "**/.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
2283
|
+
default: {
|
|
2284
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
2285
|
+
if (!match) return;
|
|
2286
|
+
const source = create(match[1]);
|
|
2287
|
+
if (!source) return;
|
|
2288
|
+
return source + DOT_LITERAL + match[2];
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
};
|
|
2292
|
+
let source = create(utils.removePrefix(input, state));
|
|
2293
|
+
if (source && opts.strictSlashes !== true) source += `${SLASH_LITERAL}?`;
|
|
2294
|
+
return source;
|
|
2295
|
+
};
|
|
2296
|
+
module.exports = parse;
|
|
2297
|
+
}));
|
|
2298
|
+
//#endregion
|
|
2299
|
+
//#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/picomatch.js
|
|
2300
|
+
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
2301
|
+
const path$1 = __require("path");
|
|
2302
|
+
const scan = require_scan();
|
|
2303
|
+
const parse = require_parse();
|
|
2304
|
+
const utils = require_utils();
|
|
2305
|
+
const constants = require_constants();
|
|
2306
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
2307
|
+
/**
|
|
2308
|
+
* Creates a matcher function from one or more glob patterns. The
|
|
2309
|
+
* returned function takes a string to match as its first argument,
|
|
2310
|
+
* and returns true if the string is a match. The returned matcher
|
|
2311
|
+
* function also takes a boolean as the second argument that, when true,
|
|
2312
|
+
* returns an object with additional information.
|
|
2313
|
+
*
|
|
2314
|
+
* ```js
|
|
2315
|
+
* const picomatch = require('picomatch');
|
|
2316
|
+
* // picomatch(glob[, options]);
|
|
2317
|
+
*
|
|
2318
|
+
* const isMatch = picomatch('*.!(*a)');
|
|
2319
|
+
* console.log(isMatch('a.a')); //=> false
|
|
2320
|
+
* console.log(isMatch('a.b')); //=> true
|
|
2321
|
+
* ```
|
|
2322
|
+
* @name picomatch
|
|
2323
|
+
* @param {String|Array} `globs` One or more glob patterns.
|
|
2324
|
+
* @param {Object=} `options`
|
|
2325
|
+
* @return {Function=} Returns a matcher function.
|
|
2326
|
+
* @api public
|
|
2327
|
+
*/
|
|
2328
|
+
const picomatch = (glob, options, returnState = false) => {
|
|
2329
|
+
if (Array.isArray(glob)) {
|
|
2330
|
+
const fns = glob.map((input) => picomatch(input, options, returnState));
|
|
2331
|
+
const arrayMatcher = (str) => {
|
|
2332
|
+
for (const isMatch of fns) {
|
|
2333
|
+
const state = isMatch(str);
|
|
2334
|
+
if (state) return state;
|
|
2335
|
+
}
|
|
2336
|
+
return false;
|
|
2337
|
+
};
|
|
2338
|
+
return arrayMatcher;
|
|
2339
|
+
}
|
|
2340
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
2341
|
+
if (glob === "" || typeof glob !== "string" && !isState) throw new TypeError("Expected pattern to be a non-empty string");
|
|
2342
|
+
const opts = options || {};
|
|
2343
|
+
const posix = utils.isWindows(options);
|
|
2344
|
+
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
2345
|
+
const state = regex.state;
|
|
2346
|
+
delete regex.state;
|
|
2347
|
+
let isIgnored = () => false;
|
|
2348
|
+
if (opts.ignore) {
|
|
2349
|
+
const ignoreOpts = {
|
|
2350
|
+
...options,
|
|
2351
|
+
ignore: null,
|
|
2352
|
+
onMatch: null,
|
|
2353
|
+
onResult: null
|
|
2354
|
+
};
|
|
2355
|
+
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
2356
|
+
}
|
|
2357
|
+
const matcher = (input, returnObject = false) => {
|
|
2358
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, {
|
|
2359
|
+
glob,
|
|
2360
|
+
posix
|
|
2361
|
+
});
|
|
2362
|
+
const result = {
|
|
2363
|
+
glob,
|
|
2364
|
+
state,
|
|
2365
|
+
regex,
|
|
2366
|
+
posix,
|
|
2367
|
+
input,
|
|
2368
|
+
output,
|
|
2369
|
+
match,
|
|
2370
|
+
isMatch
|
|
2371
|
+
};
|
|
2372
|
+
if (typeof opts.onResult === "function") opts.onResult(result);
|
|
2373
|
+
if (isMatch === false) {
|
|
2374
|
+
result.isMatch = false;
|
|
2375
|
+
return returnObject ? result : false;
|
|
2376
|
+
}
|
|
2377
|
+
if (isIgnored(input)) {
|
|
2378
|
+
if (typeof opts.onIgnore === "function") opts.onIgnore(result);
|
|
2379
|
+
result.isMatch = false;
|
|
2380
|
+
return returnObject ? result : false;
|
|
2381
|
+
}
|
|
2382
|
+
if (typeof opts.onMatch === "function") opts.onMatch(result);
|
|
2383
|
+
return returnObject ? result : true;
|
|
2384
|
+
};
|
|
2385
|
+
if (returnState) matcher.state = state;
|
|
2386
|
+
return matcher;
|
|
2387
|
+
};
|
|
2388
|
+
/**
|
|
2389
|
+
* Test `input` with the given `regex`. This is used by the main
|
|
2390
|
+
* `picomatch()` function to test the input string.
|
|
2391
|
+
*
|
|
2392
|
+
* ```js
|
|
2393
|
+
* const picomatch = require('picomatch');
|
|
2394
|
+
* // picomatch.test(input, regex[, options]);
|
|
2395
|
+
*
|
|
2396
|
+
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
2397
|
+
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
2398
|
+
* ```
|
|
2399
|
+
* @param {String} `input` String to test.
|
|
2400
|
+
* @param {RegExp} `regex`
|
|
2401
|
+
* @return {Object} Returns an object with matching info.
|
|
2402
|
+
* @api public
|
|
2403
|
+
*/
|
|
2404
|
+
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2405
|
+
if (typeof input !== "string") throw new TypeError("Expected input to be a string");
|
|
2406
|
+
if (input === "") return {
|
|
2407
|
+
isMatch: false,
|
|
2408
|
+
output: ""
|
|
2409
|
+
};
|
|
2410
|
+
const opts = options || {};
|
|
2411
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
2412
|
+
let match = input === glob;
|
|
2413
|
+
let output = match && format ? format(input) : input;
|
|
2414
|
+
if (match === false) {
|
|
2415
|
+
output = format ? format(input) : input;
|
|
2416
|
+
match = output === glob;
|
|
2417
|
+
}
|
|
2418
|
+
if (match === false || opts.capture === true) if (opts.matchBase === true || opts.basename === true) match = picomatch.matchBase(input, regex, options, posix);
|
|
2419
|
+
else match = regex.exec(output);
|
|
2420
|
+
return {
|
|
2421
|
+
isMatch: Boolean(match),
|
|
2422
|
+
match,
|
|
2423
|
+
output
|
|
2424
|
+
};
|
|
2425
|
+
};
|
|
2426
|
+
/**
|
|
2427
|
+
* Match the basename of a filepath.
|
|
2428
|
+
*
|
|
2429
|
+
* ```js
|
|
2430
|
+
* const picomatch = require('picomatch');
|
|
2431
|
+
* // picomatch.matchBase(input, glob[, options]);
|
|
2432
|
+
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
2433
|
+
* ```
|
|
2434
|
+
* @param {String} `input` String to test.
|
|
2435
|
+
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
2436
|
+
* @return {Boolean}
|
|
2437
|
+
* @api public
|
|
2438
|
+
*/
|
|
2439
|
+
picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
|
|
2440
|
+
return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(path$1.basename(input));
|
|
2441
|
+
};
|
|
2442
|
+
/**
|
|
2443
|
+
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
2444
|
+
*
|
|
2445
|
+
* ```js
|
|
2446
|
+
* const picomatch = require('picomatch');
|
|
2447
|
+
* // picomatch.isMatch(string, patterns[, options]);
|
|
2448
|
+
*
|
|
2449
|
+
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
2450
|
+
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
2451
|
+
* ```
|
|
2452
|
+
* @param {String|Array} str The string to test.
|
|
2453
|
+
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
2454
|
+
* @param {Object} [options] See available [options](#options).
|
|
2455
|
+
* @return {Boolean} Returns true if any patterns match `str`
|
|
2456
|
+
* @api public
|
|
2457
|
+
*/
|
|
2458
|
+
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
2459
|
+
/**
|
|
2460
|
+
* Parse a glob pattern to create the source string for a regular
|
|
2461
|
+
* expression.
|
|
2462
|
+
*
|
|
2463
|
+
* ```js
|
|
2464
|
+
* const picomatch = require('picomatch');
|
|
2465
|
+
* const result = picomatch.parse(pattern[, options]);
|
|
2466
|
+
* ```
|
|
2467
|
+
* @param {String} `pattern`
|
|
2468
|
+
* @param {Object} `options`
|
|
2469
|
+
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
2470
|
+
* @api public
|
|
2471
|
+
*/
|
|
2472
|
+
picomatch.parse = (pattern, options) => {
|
|
2473
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
|
|
2474
|
+
return parse(pattern, {
|
|
2475
|
+
...options,
|
|
2476
|
+
fastpaths: false
|
|
2477
|
+
});
|
|
2478
|
+
};
|
|
2479
|
+
/**
|
|
2480
|
+
* Scan a glob pattern to separate the pattern into segments.
|
|
2481
|
+
*
|
|
2482
|
+
* ```js
|
|
2483
|
+
* const picomatch = require('picomatch');
|
|
2484
|
+
* // picomatch.scan(input[, options]);
|
|
2485
|
+
*
|
|
2486
|
+
* const result = picomatch.scan('!./foo/*.js');
|
|
2487
|
+
* console.log(result);
|
|
2488
|
+
* { prefix: '!./',
|
|
2489
|
+
* input: '!./foo/*.js',
|
|
2490
|
+
* start: 3,
|
|
2491
|
+
* base: 'foo',
|
|
2492
|
+
* glob: '*.js',
|
|
2493
|
+
* isBrace: false,
|
|
2494
|
+
* isBracket: false,
|
|
2495
|
+
* isGlob: true,
|
|
2496
|
+
* isExtglob: false,
|
|
2497
|
+
* isGlobstar: false,
|
|
2498
|
+
* negated: true }
|
|
2499
|
+
* ```
|
|
2500
|
+
* @param {String} `input` Glob pattern to scan.
|
|
2501
|
+
* @param {Object} `options`
|
|
2502
|
+
* @return {Object} Returns an object with
|
|
2503
|
+
* @api public
|
|
2504
|
+
*/
|
|
2505
|
+
picomatch.scan = (input, options) => scan(input, options);
|
|
2506
|
+
/**
|
|
2507
|
+
* Compile a regular expression from the `state` object returned by the
|
|
2508
|
+
* [parse()](#parse) method.
|
|
2509
|
+
*
|
|
2510
|
+
* @param {Object} `state`
|
|
2511
|
+
* @param {Object} `options`
|
|
2512
|
+
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
2513
|
+
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
2514
|
+
* @return {RegExp}
|
|
2515
|
+
* @api public
|
|
2516
|
+
*/
|
|
2517
|
+
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
2518
|
+
if (returnOutput === true) return state.output;
|
|
2519
|
+
const opts = options || {};
|
|
2520
|
+
const prepend = opts.contains ? "" : "^";
|
|
2521
|
+
const append = opts.contains ? "" : "$";
|
|
2522
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
2523
|
+
if (state && state.negated === true) source = `^(?!${source}).*$`;
|
|
2524
|
+
const regex = picomatch.toRegex(source, options);
|
|
2525
|
+
if (returnState === true) regex.state = state;
|
|
2526
|
+
return regex;
|
|
2527
|
+
};
|
|
2528
|
+
/**
|
|
2529
|
+
* Create a regular expression from a parsed glob pattern.
|
|
2530
|
+
*
|
|
2531
|
+
* ```js
|
|
2532
|
+
* const picomatch = require('picomatch');
|
|
2533
|
+
* const state = picomatch.parse('*.js');
|
|
2534
|
+
* // picomatch.compileRe(state[, options]);
|
|
2535
|
+
*
|
|
2536
|
+
* console.log(picomatch.compileRe(state));
|
|
2537
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2538
|
+
* ```
|
|
2539
|
+
* @param {String} `state` The object returned from the `.parse` method.
|
|
2540
|
+
* @param {Object} `options`
|
|
2541
|
+
* @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.
|
|
2542
|
+
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
2543
|
+
* @return {RegExp} Returns a regex created from the given pattern.
|
|
2544
|
+
* @api public
|
|
2545
|
+
*/
|
|
2546
|
+
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
2547
|
+
if (!input || typeof input !== "string") throw new TypeError("Expected a non-empty string");
|
|
2548
|
+
let parsed = {
|
|
2549
|
+
negated: false,
|
|
2550
|
+
fastpaths: true
|
|
2551
|
+
};
|
|
2552
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) parsed.output = parse.fastpaths(input, options);
|
|
2553
|
+
if (!parsed.output) parsed = parse(input, options);
|
|
2554
|
+
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
2555
|
+
};
|
|
2556
|
+
/**
|
|
2557
|
+
* Create a regular expression from the given regex source string.
|
|
2558
|
+
*
|
|
2559
|
+
* ```js
|
|
2560
|
+
* const picomatch = require('picomatch');
|
|
2561
|
+
* // picomatch.toRegex(source[, options]);
|
|
2562
|
+
*
|
|
2563
|
+
* const { output } = picomatch.parse('*.js');
|
|
2564
|
+
* console.log(picomatch.toRegex(output));
|
|
2565
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2566
|
+
* ```
|
|
2567
|
+
* @param {String} `source` Regular expression source string.
|
|
2568
|
+
* @param {Object} `options`
|
|
2569
|
+
* @return {RegExp}
|
|
2570
|
+
* @api public
|
|
2571
|
+
*/
|
|
2572
|
+
picomatch.toRegex = (source, options) => {
|
|
2573
|
+
try {
|
|
2574
|
+
const opts = options || {};
|
|
2575
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
2576
|
+
} catch (err) {
|
|
2577
|
+
if (options && options.debug === true) throw err;
|
|
2578
|
+
return /$^/;
|
|
2579
|
+
}
|
|
2580
|
+
};
|
|
2581
|
+
/**
|
|
2582
|
+
* Picomatch constants.
|
|
2583
|
+
* @return {Object}
|
|
2584
|
+
*/
|
|
2585
|
+
picomatch.constants = constants;
|
|
2586
|
+
/**
|
|
2587
|
+
* Expose "picomatch"
|
|
2588
|
+
*/
|
|
2589
|
+
module.exports = picomatch;
|
|
2590
|
+
}));
|
|
2591
|
+
//#endregion
|
|
868
2592
|
//#region ../core/dist/index.js
|
|
2593
|
+
var import_picomatch = /* @__PURE__ */ __toESM$1((/* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
2594
|
+
module.exports = require_picomatch$1();
|
|
2595
|
+
})))(), 1);
|
|
869
2596
|
var __create = Object.create;
|
|
870
2597
|
var __defProp = Object.defineProperty;
|
|
871
2598
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -887,30 +2614,59 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
887
2614
|
value: mod,
|
|
888
2615
|
enumerable: true
|
|
889
2616
|
}) : target, mod));
|
|
890
|
-
const
|
|
891
|
-
const
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
2617
|
+
const JSX_FILE_PATTERN = /\.(tsx|jsx)$/;
|
|
2618
|
+
const MILLISECONDS_PER_SECOND = 1e3;
|
|
2619
|
+
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
2620
|
+
const SHARE_BASE_URL = "https://www.react.doctor/share";
|
|
2621
|
+
const FETCH_TIMEOUT_MS = 1e4;
|
|
2622
|
+
const DEFAULT_BRANCH_CANDIDATES = ["main", "master"];
|
|
2623
|
+
const ADOPTABLE_LINT_CONFIG_FILENAMES = [".oxlintrc.json", ".eslintrc.json"];
|
|
2624
|
+
const OXLINT_NODE_REQUIREMENT = "^20.19.0 || >=22.12.0";
|
|
2625
|
+
const GIT_SHOW_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
|
|
2626
|
+
const CANONICAL_GITHUB_URL = "https://github.com/millionco/react-doctor";
|
|
2627
|
+
const SKILL_NAME = "react-doctor";
|
|
2628
|
+
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
2629
|
+
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
2630
|
+
var InvalidGlobPatternError = class extends Error {
|
|
2631
|
+
pattern;
|
|
2632
|
+
reason;
|
|
2633
|
+
constructor(pattern, reason) {
|
|
2634
|
+
super(`Invalid glob pattern ${JSON.stringify(pattern)}: ${reason}`);
|
|
2635
|
+
this.name = "InvalidGlobPatternError";
|
|
2636
|
+
this.pattern = pattern;
|
|
2637
|
+
this.reason = reason;
|
|
2638
|
+
}
|
|
2639
|
+
};
|
|
2640
|
+
const assertGlobPattern = (condition, pattern, reason) => {
|
|
2641
|
+
if (!condition) throw new InvalidGlobPatternError(pattern, reason);
|
|
2642
|
+
};
|
|
2643
|
+
const countGlobWildcards = (pattern) => (pattern.match(/[*?]/g) ?? []).length;
|
|
2644
|
+
const normalizeGlobPattern = (pattern) => pattern.replace(/\\/g, "/").replace(/^\//, "");
|
|
2645
|
+
const PICOMATCH_OPTIONS = {
|
|
2646
|
+
dot: true,
|
|
2647
|
+
strictSlashes: false,
|
|
2648
|
+
windows: false
|
|
2649
|
+
};
|
|
2650
|
+
const compileGlobPattern = (rawPattern) => {
|
|
2651
|
+
assertGlobPattern(typeof rawPattern === "string" && rawPattern.length > 0, String(rawPattern), "pattern must be a non-empty string.");
|
|
2652
|
+
assertGlobPattern(rawPattern.length <= MAX_GLOB_PATTERN_LENGTH_CHARS, rawPattern, `pattern length ${rawPattern.length} exceeds the maximum of ${MAX_GLOB_PATTERN_LENGTH_CHARS} characters.`);
|
|
2653
|
+
const wildcardCount = countGlobWildcards(rawPattern);
|
|
2654
|
+
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.`);
|
|
2655
|
+
try {
|
|
2656
|
+
return import_picomatch.default.makeRe(normalizeGlobPattern(rawPattern), PICOMATCH_OPTIONS);
|
|
2657
|
+
} catch (caughtError) {
|
|
2658
|
+
throw new InvalidGlobPatternError(rawPattern, caughtError instanceof Error ? caughtError.message : String(caughtError));
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
const compileGlobPatternsLenient = (patterns, onInvalid) => {
|
|
2662
|
+
const compiled = [];
|
|
2663
|
+
for (const pattern of patterns) try {
|
|
2664
|
+
compiled.push(compileGlobPattern(pattern));
|
|
2665
|
+
} catch (caughtError) {
|
|
2666
|
+
if (!(caughtError instanceof InvalidGlobPatternError)) throw caughtError;
|
|
2667
|
+
onInvalid(caughtError);
|
|
911
2668
|
}
|
|
912
|
-
|
|
913
|
-
return new RegExp(regexSource);
|
|
2669
|
+
return compiled;
|
|
914
2670
|
};
|
|
915
2671
|
const toRelativePath = (filePath, rootDirectory) => {
|
|
916
2672
|
const normalizedFilePath = filePath.replace(/\\/g, "/");
|
|
@@ -918,22 +2674,22 @@ const toRelativePath = (filePath, rootDirectory) => {
|
|
|
918
2674
|
if (normalizedFilePath.startsWith(normalizedRoot)) return normalizedFilePath.slice(normalizedRoot.length);
|
|
919
2675
|
return normalizedFilePath.replace(/^\.\//, "");
|
|
920
2676
|
};
|
|
921
|
-
const
|
|
2677
|
+
const warnConfigIssue = (message) => {
|
|
922
2678
|
process.stderr.write(`[react-doctor] ${message}\n`);
|
|
923
2679
|
};
|
|
924
2680
|
const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
925
2681
|
const collectStringList = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
926
2682
|
const validateOverrideEntry = (entry, index) => {
|
|
927
2683
|
if (!isPlainObject(entry)) {
|
|
928
|
-
|
|
2684
|
+
warnConfigIssue(`ignore.overrides[${index}] must be an object with { files, rules }; ignoring this entry.`);
|
|
929
2685
|
return null;
|
|
930
2686
|
}
|
|
931
2687
|
if (!isStringArray(entry.files)) {
|
|
932
|
-
|
|
2688
|
+
warnConfigIssue(`ignore.overrides[${index}].files must be an array of strings; ignoring this entry.`);
|
|
933
2689
|
return null;
|
|
934
2690
|
}
|
|
935
2691
|
if (entry.rules !== void 0 && !isStringArray(entry.rules)) {
|
|
936
|
-
|
|
2692
|
+
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).`);
|
|
937
2693
|
return { files: entry.files };
|
|
938
2694
|
}
|
|
939
2695
|
return entry.rules === void 0 ? { files: entry.files } : {
|
|
@@ -945,13 +2701,13 @@ const compileIgnoreOverrides = (userConfig) => {
|
|
|
945
2701
|
const overrides = userConfig?.ignore?.overrides;
|
|
946
2702
|
if (overrides === void 0) return [];
|
|
947
2703
|
if (!Array.isArray(overrides)) {
|
|
948
|
-
|
|
2704
|
+
warnConfigIssue(`ignore.overrides must be an array of { files, rules } entries; ignoring.`);
|
|
949
2705
|
return [];
|
|
950
2706
|
}
|
|
951
2707
|
return overrides.flatMap((entry, index) => {
|
|
952
2708
|
const validated = validateOverrideEntry(entry, index);
|
|
953
2709
|
if (!validated) return [];
|
|
954
|
-
const filePatterns = collectStringList(validated.files)
|
|
2710
|
+
const filePatterns = compileGlobPatternsLenient(collectStringList(validated.files), (error) => warnConfigIssue(`ignore.overrides[${index}]: ${error.message}`));
|
|
955
2711
|
if (filePatterns.length === 0) return [];
|
|
956
2712
|
return [{
|
|
957
2713
|
filePatterns,
|
|
@@ -965,18 +2721,94 @@ const isDiagnosticIgnoredByOverrides = (diagnostic, rootDirectory, overrides) =>
|
|
|
965
2721
|
const ruleIdentifier = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
966
2722
|
return overrides.some((override) => override.filePatterns.some((pattern) => pattern.test(relativeFilePath)) && (override.ruleIds.size === 0 || override.ruleIds.has(ruleIdentifier)));
|
|
967
2723
|
};
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
2724
|
+
/**
|
|
2725
|
+
* Assembles the internal `RuleSeverityControls` shape from a user
|
|
2726
|
+
* config's top-level `rules` and `categories` fields — the
|
|
2727
|
+
* ESLint / oxlint-shaped severity surface.
|
|
2728
|
+
*
|
|
2729
|
+
* Returns `undefined` when neither field is present so the common
|
|
2730
|
+
* path (no severity config at all) stays allocation-free for
|
|
2731
|
+
* downstream consumers.
|
|
2732
|
+
*/
|
|
2733
|
+
const buildRuleSeverityControls = (config) => {
|
|
2734
|
+
if (!config) return void 0;
|
|
2735
|
+
if (config.rules === void 0 && config.categories === void 0) return void 0;
|
|
2736
|
+
return {
|
|
2737
|
+
...config.rules !== void 0 ? { rules: config.rules } : {},
|
|
2738
|
+
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2739
|
+
};
|
|
2740
|
+
};
|
|
2741
|
+
/**
|
|
2742
|
+
* Projects a diagnostic onto the three axes rule-targeted controls
|
|
2743
|
+
* reason about:
|
|
2744
|
+
*
|
|
2745
|
+
* - `ruleKey` — the fully-qualified `"<plugin>/<rule>"` form users
|
|
2746
|
+
* put in config files (consumed by top-level `rules` severity and
|
|
2747
|
+
* `surfaces.*.{include,exclude}Rules`).
|
|
2748
|
+
* - `category` — the diagnostic's category label (consumed by
|
|
2749
|
+
* top-level `categories` severity and
|
|
2750
|
+
* `surfaces.*.{include,exclude}Categories`).
|
|
2751
|
+
* - `tags` — behavioral tags from the rule registry (consumed by
|
|
2752
|
+
* `ignore.tags` and `surfaces.*.{include,exclude}Tags`). Empty
|
|
2753
|
+
* for non-`react-doctor` plugins.
|
|
2754
|
+
*/
|
|
2755
|
+
const getDiagnosticRuleIdentity = (diagnostic) => ({
|
|
2756
|
+
ruleKey: `${diagnostic.plugin}/${diagnostic.rule}`,
|
|
2757
|
+
category: diagnostic.category,
|
|
2758
|
+
tags: diagnostic.plugin === "react-doctor" ? reactDoctorPlugin.rules[diagnostic.rule]?.tags ?? [] : []
|
|
2759
|
+
});
|
|
2760
|
+
/**
|
|
2761
|
+
* Resolves the user-configured severity override for a rule.
|
|
2762
|
+
* Per-rule overrides win over per-category overrides. Returns
|
|
2763
|
+
* `undefined` when neither channel matches — callers should fall
|
|
2764
|
+
* back to the rule's built-in severity.
|
|
2765
|
+
*/
|
|
2766
|
+
const resolveRuleSeverityOverride = (input, controls) => {
|
|
2767
|
+
if (!controls) return void 0;
|
|
2768
|
+
return controls.rules?.[input.ruleKey] ?? (input.category !== void 0 ? controls.categories?.[input.category] : void 0);
|
|
2769
|
+
};
|
|
2770
|
+
const SEVERITY_FOR_OVERRIDE = {
|
|
2771
|
+
error: "error",
|
|
2772
|
+
warn: "warning"
|
|
2773
|
+
};
|
|
2774
|
+
const restampSeverity = (diagnostic, override) => {
|
|
2775
|
+
const targetSeverity = SEVERITY_FOR_OVERRIDE[override];
|
|
2776
|
+
if (diagnostic.severity === targetSeverity) return diagnostic;
|
|
2777
|
+
return {
|
|
2778
|
+
...diagnostic,
|
|
2779
|
+
severity: targetSeverity
|
|
2780
|
+
};
|
|
2781
|
+
};
|
|
2782
|
+
/**
|
|
2783
|
+
* Applies the user's top-level `rules` / `categories` / `tags`
|
|
2784
|
+
* severity config to a post-lint diagnostic list:
|
|
2785
|
+
*
|
|
2786
|
+
* - `"off"` drops the diagnostic entirely. For react-doctor rules
|
|
2787
|
+
* this also happens at lint-registration time; this post-filter
|
|
2788
|
+
* covers external plugins (`react/*`, `jsx-a11y/*`, custom adopted
|
|
2789
|
+
* configs) whose severities the lint config can't reach.
|
|
2790
|
+
* - `"warn"` / `"error"` re-stamps `diagnostic.severity` so downstream
|
|
2791
|
+
* consumers — `--fail-on`, the score input, the CLI summary — see
|
|
2792
|
+
* the user-chosen severity rather than the rule's built-in one.
|
|
2793
|
+
*
|
|
2794
|
+
* Returns the input array by identity when no controls are configured
|
|
2795
|
+
* so the common path stays allocation-free.
|
|
2796
|
+
*/
|
|
2797
|
+
const applySeverityControls = (diagnostics, config) => {
|
|
2798
|
+
const controls = buildRuleSeverityControls(config);
|
|
2799
|
+
if (!controls) return diagnostics;
|
|
2800
|
+
const adjusted = [];
|
|
2801
|
+
for (const diagnostic of diagnostics) {
|
|
2802
|
+
const { ruleKey, category } = getDiagnosticRuleIdentity(diagnostic);
|
|
2803
|
+
const override = resolveRuleSeverityOverride({
|
|
2804
|
+
ruleKey,
|
|
2805
|
+
category
|
|
2806
|
+
}, controls);
|
|
2807
|
+
if (override === "off") continue;
|
|
2808
|
+
adjusted.push(override === void 0 ? diagnostic : restampSeverity(diagnostic, override));
|
|
2809
|
+
}
|
|
2810
|
+
return adjusted;
|
|
2811
|
+
};
|
|
980
2812
|
const estimateArgsLength = (args) => args.reduce((total, argument) => total + argument.length + 1, 0);
|
|
981
2813
|
const batchIncludePaths = (baseArgs, includePaths) => {
|
|
982
2814
|
const baseArgsLength = estimateArgsLength(baseArgs);
|
|
@@ -1658,7 +3490,7 @@ const evaluateSuppression = (lines, diagnosticLineIndex, ruleId) => {
|
|
|
1658
3490
|
const compileIgnoredFilePatterns = (userConfig) => {
|
|
1659
3491
|
const files = userConfig?.ignore?.files;
|
|
1660
3492
|
if (!Array.isArray(files)) return [];
|
|
1661
|
-
return files.filter((entry) => typeof entry === "string")
|
|
3493
|
+
return compileGlobPatternsLenient(files.filter((entry) => typeof entry === "string"), (error) => warnConfigIssue(`ignore.files: ${error.message}`));
|
|
1662
3494
|
};
|
|
1663
3495
|
const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
|
|
1664
3496
|
if (patterns.length === 0) return false;
|
|
@@ -1819,8 +3651,8 @@ const shouldAutoSuppress = (diagnostic) => {
|
|
|
1819
3651
|
return false;
|
|
1820
3652
|
};
|
|
1821
3653
|
const mergeAndFilterDiagnostics = (mergedDiagnostics, directory, userConfig, readFileLinesSync, options = {}) => {
|
|
1822
|
-
const
|
|
1823
|
-
const filtered = userConfig ? filterIgnoredDiagnostics(
|
|
3654
|
+
const severityAdjusted = applySeverityControls(mergedDiagnostics.filter((diagnostic) => !shouldAutoSuppress(diagnostic)), userConfig);
|
|
3655
|
+
const filtered = userConfig ? filterIgnoredDiagnostics(severityAdjusted, userConfig, directory, readFileLinesSync) : severityAdjusted;
|
|
1824
3656
|
if (options.respectInlineDisables === false) return filtered;
|
|
1825
3657
|
return filterInlineSuppressions(filtered, directory, readFileLinesSync);
|
|
1826
3658
|
};
|
|
@@ -1850,6 +3682,60 @@ const detectUserLintConfigPaths = (rootDirectory) => {
|
|
|
1850
3682
|
}
|
|
1851
3683
|
return [];
|
|
1852
3684
|
};
|
|
3685
|
+
const DIAGNOSTIC_SURFACES = [
|
|
3686
|
+
"cli",
|
|
3687
|
+
"prComment",
|
|
3688
|
+
"score",
|
|
3689
|
+
"ciFailure"
|
|
3690
|
+
];
|
|
3691
|
+
const isDiagnosticSurface = (value) => typeof value === "string" && DIAGNOSTIC_SURFACES.includes(value);
|
|
3692
|
+
/**
|
|
3693
|
+
* Built-in surface exclusions applied before any user config.
|
|
3694
|
+
*
|
|
3695
|
+
* `design`-tagged rules are weak-signal style cleanup — they still ship
|
|
3696
|
+
* to the local CLI so developers see them while editing, but they're
|
|
3697
|
+
* removed from the PR comment surface, the score, and the CI gate so
|
|
3698
|
+
* they can't bury real React findings or fail a build over a Tailwind
|
|
3699
|
+
* shorthand. Override per-surface via `config.surfaces.<surface>` to
|
|
3700
|
+
* promote individual rules back in by tag, category, or rule id.
|
|
3701
|
+
*/
|
|
3702
|
+
const DEFAULT_SURFACE_EXCLUDED_TAGS = {
|
|
3703
|
+
cli: [],
|
|
3704
|
+
prComment: ["design"],
|
|
3705
|
+
score: ["design"],
|
|
3706
|
+
ciFailure: ["design"]
|
|
3707
|
+
};
|
|
3708
|
+
const toStringSet = (values) => {
|
|
3709
|
+
if (!values || values.length === 0) return /* @__PURE__ */ new Set();
|
|
3710
|
+
return new Set(values.filter((value) => typeof value === "string" && value.length > 0));
|
|
3711
|
+
};
|
|
3712
|
+
const buildResolvedControls = (surface, userControls) => {
|
|
3713
|
+
const excludeTags = new Set(DEFAULT_SURFACE_EXCLUDED_TAGS[surface]);
|
|
3714
|
+
const includeTags = toStringSet(userControls?.includeTags);
|
|
3715
|
+
for (const tag of includeTags) excludeTags.delete(tag);
|
|
3716
|
+
for (const tag of toStringSet(userControls?.excludeTags)) excludeTags.add(tag);
|
|
3717
|
+
return {
|
|
3718
|
+
includeTags,
|
|
3719
|
+
excludeTags,
|
|
3720
|
+
includeCategories: toStringSet(userControls?.includeCategories),
|
|
3721
|
+
excludeCategories: toStringSet(userControls?.excludeCategories),
|
|
3722
|
+
includeRuleKeys: toStringSet(userControls?.includeRules),
|
|
3723
|
+
excludeRuleKeys: toStringSet(userControls?.excludeRules)
|
|
3724
|
+
};
|
|
3725
|
+
};
|
|
3726
|
+
const intersects = (values, candidates) => values.some((value) => candidates.has(value));
|
|
3727
|
+
const isDiagnosticOnSurface = (diagnostic, surface, config) => {
|
|
3728
|
+
const resolved = buildResolvedControls(surface, config?.surfaces?.[surface]);
|
|
3729
|
+
const { ruleKey, category, tags } = getDiagnosticRuleIdentity(diagnostic);
|
|
3730
|
+
if (resolved.includeRuleKeys.has(ruleKey)) return true;
|
|
3731
|
+
if (resolved.includeCategories.has(category)) return true;
|
|
3732
|
+
if (intersects(tags, resolved.includeTags)) return true;
|
|
3733
|
+
if (resolved.excludeRuleKeys.has(ruleKey)) return false;
|
|
3734
|
+
if (resolved.excludeCategories.has(category)) return false;
|
|
3735
|
+
if (intersects(tags, resolved.excludeTags)) return false;
|
|
3736
|
+
return true;
|
|
3737
|
+
};
|
|
3738
|
+
const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
|
|
1853
3739
|
const runGit = (cwd, args) => {
|
|
1854
3740
|
const result = spawnSync("git", args, {
|
|
1855
3741
|
cwd,
|
|
@@ -1967,6 +3853,11 @@ const getDiffInfo = (directory, explicitBaseBranch) => {
|
|
|
1967
3853
|
};
|
|
1968
3854
|
const filterSourceFiles = (filePaths) => filePaths.filter((filePath) => SOURCE_FILE_PATTERN.test(filePath));
|
|
1969
3855
|
const computeJsxIncludePaths = (includePaths) => includePaths.length > 0 ? includePaths.filter((filePath) => JSX_FILE_PATTERN.test(filePath)) : void 0;
|
|
3856
|
+
const VALID_RULE_SEVERITIES = [
|
|
3857
|
+
"error",
|
|
3858
|
+
"warn",
|
|
3859
|
+
"off"
|
|
3860
|
+
];
|
|
1970
3861
|
const BOOLEAN_FIELD_NAMES = [
|
|
1971
3862
|
"lint",
|
|
1972
3863
|
"verbose",
|
|
@@ -1977,18 +3868,27 @@ const BOOLEAN_FIELD_NAMES = [
|
|
|
1977
3868
|
"offline"
|
|
1978
3869
|
];
|
|
1979
3870
|
const STRING_FIELD_NAMES = ["rootDir"];
|
|
3871
|
+
const SURFACE_CONTROL_FIELD_NAMES = [
|
|
3872
|
+
"includeTags",
|
|
3873
|
+
"excludeTags",
|
|
3874
|
+
"includeCategories",
|
|
3875
|
+
"excludeCategories",
|
|
3876
|
+
"includeRules",
|
|
3877
|
+
"excludeRules"
|
|
3878
|
+
];
|
|
3879
|
+
const SEVERITY_FIELD_NAMES = ["rules", "categories"];
|
|
1980
3880
|
const warnConfigField = (message) => {
|
|
1981
3881
|
process.stderr.write(`[react-doctor] ${message}\n`);
|
|
1982
3882
|
};
|
|
3883
|
+
const isPlainObject$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3884
|
+
const formatType = (value) => typeof value === "string" ? `"${value}"` : typeof value;
|
|
3885
|
+
const isRuleSeverity = (value) => typeof value === "string" && VALID_RULE_SEVERITIES.includes(value);
|
|
1983
3886
|
const coerceMaybeBooleanString = (fieldName, value) => {
|
|
1984
|
-
if (typeof value === "boolean"
|
|
1985
|
-
if (value === "true") {
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
if (value === "false") {
|
|
1990
|
-
warnConfigField(`config field "${fieldName}" is the string "false"; treating as boolean false.`);
|
|
1991
|
-
return false;
|
|
3887
|
+
if (typeof value === "boolean") return value;
|
|
3888
|
+
if (value === "true" || value === "false") {
|
|
3889
|
+
const coerced = value === "true";
|
|
3890
|
+
warnConfigField(`config field "${fieldName}" is the string "${value}"; treating as boolean ${coerced}.`);
|
|
3891
|
+
return coerced;
|
|
1992
3892
|
}
|
|
1993
3893
|
warnConfigField(`config field "${fieldName}" must be a boolean (got ${typeof value}); ignoring this field.`);
|
|
1994
3894
|
};
|
|
@@ -1996,22 +3896,78 @@ const validateString = (fieldName, value) => {
|
|
|
1996
3896
|
if (typeof value === "string") return value;
|
|
1997
3897
|
warnConfigField(`config field "${fieldName}" must be a string (got ${typeof value}); ignoring this field.`);
|
|
1998
3898
|
};
|
|
3899
|
+
const validateStringArrayField = (fieldName, value) => {
|
|
3900
|
+
if (!Array.isArray(value)) {
|
|
3901
|
+
warnConfigField(`config field "${fieldName}" must be an array of strings (got ${typeof value}); ignoring this field.`);
|
|
3902
|
+
return;
|
|
3903
|
+
}
|
|
3904
|
+
return value.filter((entry) => {
|
|
3905
|
+
if (typeof entry === "string") return true;
|
|
3906
|
+
warnConfigField(`config field "${fieldName}" contains a non-string entry (${typeof entry}); ignoring the entry.`);
|
|
3907
|
+
return false;
|
|
3908
|
+
});
|
|
3909
|
+
};
|
|
3910
|
+
const validateSurfaceControls = (surface, rawControls) => {
|
|
3911
|
+
if (!isPlainObject$1(rawControls)) {
|
|
3912
|
+
warnConfigField(`config field "surfaces.${surface}" must be an object (got ${typeof rawControls}); ignoring this surface.`);
|
|
3913
|
+
return;
|
|
3914
|
+
}
|
|
3915
|
+
const validated = {};
|
|
3916
|
+
for (const fieldName of SURFACE_CONTROL_FIELD_NAMES) {
|
|
3917
|
+
if (rawControls[fieldName] === void 0) continue;
|
|
3918
|
+
const result = validateStringArrayField(`surfaces.${surface}.${fieldName}`, rawControls[fieldName]);
|
|
3919
|
+
if (result !== void 0) validated[fieldName] = result;
|
|
3920
|
+
}
|
|
3921
|
+
return validated;
|
|
3922
|
+
};
|
|
3923
|
+
const validateSurfacesField = (rawSurfaces) => {
|
|
3924
|
+
if (!isPlainObject$1(rawSurfaces)) {
|
|
3925
|
+
warnConfigField(`config field "surfaces" must be an object (got ${typeof rawSurfaces}); ignoring this field.`);
|
|
3926
|
+
return;
|
|
3927
|
+
}
|
|
3928
|
+
const validated = {};
|
|
3929
|
+
for (const [key, value] of Object.entries(rawSurfaces)) {
|
|
3930
|
+
if (!isDiagnosticSurface(key)) {
|
|
3931
|
+
warnConfigField(`config field "surfaces.${key}" is not a known surface (expected one of: ${DIAGNOSTIC_SURFACES.join(", ")}); ignoring.`);
|
|
3932
|
+
continue;
|
|
3933
|
+
}
|
|
3934
|
+
const controls = validateSurfaceControls(key, value);
|
|
3935
|
+
if (controls !== void 0) validated[key] = controls;
|
|
3936
|
+
}
|
|
3937
|
+
return validated;
|
|
3938
|
+
};
|
|
3939
|
+
const validateSeverityMap = (fieldName, rawMap) => {
|
|
3940
|
+
if (!isPlainObject$1(rawMap)) {
|
|
3941
|
+
warnConfigField(`config field "${fieldName}" must be an object (got ${typeof rawMap}); ignoring this field.`);
|
|
3942
|
+
return;
|
|
3943
|
+
}
|
|
3944
|
+
const validated = {};
|
|
3945
|
+
for (const [key, value] of Object.entries(rawMap)) {
|
|
3946
|
+
if (key.length === 0) {
|
|
3947
|
+
warnConfigField(`config field "${fieldName}" has an empty key; ignoring the entry.`);
|
|
3948
|
+
continue;
|
|
3949
|
+
}
|
|
3950
|
+
if (!isRuleSeverity(value)) {
|
|
3951
|
+
warnConfigField(`config field "${fieldName}.${key}" must be one of: ${VALID_RULE_SEVERITIES.join(", ")} (got ${formatType(value)}); ignoring the entry.`);
|
|
3952
|
+
continue;
|
|
3953
|
+
}
|
|
3954
|
+
validated[key] = value;
|
|
3955
|
+
}
|
|
3956
|
+
return validated;
|
|
3957
|
+
};
|
|
3958
|
+
const applyFieldValidator = (config, validated, fieldName, validator) => {
|
|
3959
|
+
const raw = config[fieldName];
|
|
3960
|
+
if (raw === void 0) return;
|
|
3961
|
+
const result = validator(raw);
|
|
3962
|
+
if (result === void 0) delete validated[fieldName];
|
|
3963
|
+
else validated[fieldName] = result;
|
|
3964
|
+
};
|
|
1999
3965
|
const validateConfigTypes = (config) => {
|
|
2000
3966
|
const validated = { ...config };
|
|
2001
|
-
for (const fieldName of BOOLEAN_FIELD_NAMES)
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
if (coerced === void 0) delete validated[fieldName];
|
|
2006
|
-
else validated[fieldName] = coerced;
|
|
2007
|
-
}
|
|
2008
|
-
for (const fieldName of STRING_FIELD_NAMES) {
|
|
2009
|
-
const original = config[fieldName];
|
|
2010
|
-
if (original === void 0) continue;
|
|
2011
|
-
const validatedString = validateString(fieldName, original);
|
|
2012
|
-
if (validatedString === void 0) delete validated[fieldName];
|
|
2013
|
-
else validated[fieldName] = validatedString;
|
|
2014
|
-
}
|
|
3967
|
+
for (const fieldName of BOOLEAN_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => coerceMaybeBooleanString(fieldName, value));
|
|
3968
|
+
for (const fieldName of STRING_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateString(fieldName, value));
|
|
3969
|
+
applyFieldValidator(config, validated, "surfaces", validateSurfacesField);
|
|
3970
|
+
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value));
|
|
2015
3971
|
return validated;
|
|
2016
3972
|
};
|
|
2017
3973
|
const CONFIG_FILENAME = "react-doctor.config.json";
|
|
@@ -2313,7 +4269,7 @@ const dedupeDiagnostics = (diagnostics) => {
|
|
|
2313
4269
|
const buildCapabilities = (project) => {
|
|
2314
4270
|
const capabilities = /* @__PURE__ */ new Set();
|
|
2315
4271
|
capabilities.add(project.framework);
|
|
2316
|
-
if (project.framework === "expo" || project.framework === "react-native") capabilities.add("react-native");
|
|
4272
|
+
if (project.framework === "expo" || project.framework === "react-native" || project.hasReactNativeWorkspace) capabilities.add("react-native");
|
|
2317
4273
|
const reactMajor = project.reactMajorVersion;
|
|
2318
4274
|
if (reactMajor !== null) for (let major = 17; major <= reactMajor; major++) capabilities.add(`react:${major}`);
|
|
2319
4275
|
if (project.tailwindVersion !== null) {
|
|
@@ -2395,65 +4351,11 @@ const filterRulesToAvailable = (rules, pluginNamespace, availableRuleNames) => {
|
|
|
2395
4351
|
}
|
|
2396
4352
|
return filtered;
|
|
2397
4353
|
};
|
|
2398
|
-
const
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
"react-hooks-js/hooks": "error",
|
|
2404
|
-
"react-hooks-js/set-state-in-effect": "error",
|
|
2405
|
-
"react-hooks-js/globals": "error",
|
|
2406
|
-
"react-hooks-js/error-boundaries": "error",
|
|
2407
|
-
"react-hooks-js/preserve-manual-memoization": "error",
|
|
2408
|
-
"react-hooks-js/unsupported-syntax": "error",
|
|
2409
|
-
"react-hooks-js/component-hook-factories": "error",
|
|
2410
|
-
"react-hooks-js/static-components": "error",
|
|
2411
|
-
"react-hooks-js/use-memo": "error",
|
|
2412
|
-
"react-hooks-js/void-use-memo": "error",
|
|
2413
|
-
"react-hooks-js/incompatible-library": "error",
|
|
2414
|
-
"react-hooks-js/todo": "error"
|
|
2415
|
-
};
|
|
2416
|
-
const YOU_MIGHT_NOT_NEED_EFFECT_RULES = {
|
|
2417
|
-
"effect/no-derived-state": "warn",
|
|
2418
|
-
"effect/no-chain-state-updates": "warn",
|
|
2419
|
-
"effect/no-event-handler": "warn",
|
|
2420
|
-
"effect/no-adjust-state-on-prop-change": "warn",
|
|
2421
|
-
"effect/no-reset-all-state-on-prop-change": "warn",
|
|
2422
|
-
"effect/no-pass-live-state-to-parent": "warn",
|
|
2423
|
-
"effect/no-pass-data-to-parent": "warn",
|
|
2424
|
-
"effect/no-initialize-state": "warn"
|
|
2425
|
-
};
|
|
2426
|
-
const BUILTIN_REACT_RULES = {
|
|
2427
|
-
"react/rules-of-hooks": "error",
|
|
2428
|
-
"react/no-direct-mutation-state": "error",
|
|
2429
|
-
"react/jsx-no-duplicate-props": "error",
|
|
2430
|
-
"react/jsx-key": "error",
|
|
2431
|
-
"react/no-children-prop": "warn",
|
|
2432
|
-
"react/no-danger": "warn",
|
|
2433
|
-
"react/jsx-no-script-url": "error",
|
|
2434
|
-
"react/no-render-return-value": "warn",
|
|
2435
|
-
"react/no-string-refs": "warn",
|
|
2436
|
-
"react/no-is-mounted": "warn",
|
|
2437
|
-
"react/require-render-return": "error",
|
|
2438
|
-
"react/no-unknown-property": "warn"
|
|
2439
|
-
};
|
|
2440
|
-
const BUILTIN_A11Y_RULES = {
|
|
2441
|
-
"jsx-a11y/alt-text": "error",
|
|
2442
|
-
"jsx-a11y/anchor-is-valid": "warn",
|
|
2443
|
-
"jsx-a11y/click-events-have-key-events": "warn",
|
|
2444
|
-
"jsx-a11y/no-static-element-interactions": "warn",
|
|
2445
|
-
"jsx-a11y/role-has-required-aria-props": "error",
|
|
2446
|
-
"jsx-a11y/no-autofocus": "warn",
|
|
2447
|
-
"jsx-a11y/heading-has-content": "warn",
|
|
2448
|
-
"jsx-a11y/html-has-lang": "warn",
|
|
2449
|
-
"jsx-a11y/no-redundant-roles": "warn",
|
|
2450
|
-
"jsx-a11y/scope": "warn",
|
|
2451
|
-
"jsx-a11y/tabindex-no-positive": "warn",
|
|
2452
|
-
"jsx-a11y/label-has-associated-control": "warn",
|
|
2453
|
-
"jsx-a11y/no-distracting-elements": "error",
|
|
2454
|
-
"jsx-a11y/iframe-has-title": "warn"
|
|
2455
|
-
};
|
|
2456
|
-
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set() }) => {
|
|
4354
|
+
const resolveSettingsRootDirectory = (rootDirectory) => {
|
|
4355
|
+
if (!fs.existsSync(rootDirectory)) return rootDirectory;
|
|
4356
|
+
return fs.realpathSync(rootDirectory);
|
|
4357
|
+
};
|
|
4358
|
+
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames, severityControls }) => {
|
|
2457
4359
|
const reactHooksJsPlugin = resolveReactHooksJsPlugin(project.hasReactCompiler, customRulesOnly);
|
|
2458
4360
|
const reactCompilerRules = reactHooksJsPlugin ? filterRulesToAvailable(REACT_COMPILER_RULES, "react-hooks-js", reactHooksJsPlugin.availableRuleNames) : {};
|
|
2459
4361
|
const youMightNotNeedEffectPlugin = resolveYouMightNotNeedEffectPlugin(customRulesOnly);
|
|
@@ -2467,7 +4369,12 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
2467
4369
|
const fullKey = `react-doctor/${ruleId}`;
|
|
2468
4370
|
if (rule.framework !== "global" && !rule.requires) continue;
|
|
2469
4371
|
if (!shouldEnableRule(rule.requires, rule.tags, capabilities, ignoredTags)) continue;
|
|
2470
|
-
|
|
4372
|
+
const severity = resolveRuleSeverityOverride({
|
|
4373
|
+
ruleKey: fullKey,
|
|
4374
|
+
category: rule.category
|
|
4375
|
+
}, severityControls) ?? rule.severity;
|
|
4376
|
+
if (severity === "off") continue;
|
|
4377
|
+
enabledReactDoctorRules[fullKey] = severity;
|
|
2471
4378
|
}
|
|
2472
4379
|
return {
|
|
2473
4380
|
...extendsPaths.length > 0 ? { extends: extendsPaths } : {},
|
|
@@ -2482,6 +4389,11 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
2482
4389
|
},
|
|
2483
4390
|
plugins: customRulesOnly ? [] : ["react", "jsx-a11y"],
|
|
2484
4391
|
jsPlugins: [...jsPlugins, pluginPath],
|
|
4392
|
+
settings: { "react-doctor": {
|
|
4393
|
+
framework: project.framework,
|
|
4394
|
+
rootDirectory: resolveSettingsRootDirectory(project.rootDirectory),
|
|
4395
|
+
...serverAuthFunctionNames && serverAuthFunctionNames.length > 0 ? { serverAuthFunctionNames: [...serverAuthFunctionNames] } : {}
|
|
4396
|
+
} },
|
|
2485
4397
|
rules: {
|
|
2486
4398
|
...customRulesOnly ? {} : BUILTIN_REACT_RULES,
|
|
2487
4399
|
...customRulesOnly ? {} : BUILTIN_A11Y_RULES,
|
|
@@ -2784,7 +4696,25 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
2784
4696
|
const bindingResolution = resolveUseCallBinding(sourceText, absolutePath, primaryLabel.span.offset);
|
|
2785
4697
|
return bindingResolution !== null && !bindingResolution.isReactUseBinding;
|
|
2786
4698
|
};
|
|
2787
|
-
const
|
|
4699
|
+
const getPublicEnvPrefix = (framework) => {
|
|
4700
|
+
switch (framework) {
|
|
4701
|
+
case "nextjs": return "NEXT_PUBLIC_*";
|
|
4702
|
+
case "vite":
|
|
4703
|
+
case "tanstack-start": return "VITE_*";
|
|
4704
|
+
case "cra": return "REACT_APP_*";
|
|
4705
|
+
case "gatsby": return "GATSBY_*";
|
|
4706
|
+
default: return null;
|
|
4707
|
+
}
|
|
4708
|
+
};
|
|
4709
|
+
const buildNoSecretsRecommendation = (project, fallbackRecommendation) => {
|
|
4710
|
+
const publicEnvPrefix = getPublicEnvPrefix(project.framework);
|
|
4711
|
+
if (!publicEnvPrefix) return fallbackRecommendation;
|
|
4712
|
+
return `Move secrets to server-only code. In ${formatFrameworkName(project.framework)}, only \`${publicEnvPrefix}\` env vars are exposed to the browser, and they must not contain secrets`;
|
|
4713
|
+
};
|
|
4714
|
+
const getRuleRecommendation = (ruleName, project) => {
|
|
4715
|
+
if (ruleName === "no-secrets-in-client-code") return buildNoSecretsRecommendation(project, reactDoctorPlugin.rules["no-secrets-in-client-code"]?.recommendation ?? "Move secrets to server-only code");
|
|
4716
|
+
return reactDoctorPlugin.rules[ruleName]?.recommendation;
|
|
4717
|
+
};
|
|
2788
4718
|
const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
|
|
2789
4719
|
const esmRequire = createRequire(import.meta.url);
|
|
2790
4720
|
const PLUGIN_CATEGORY_MAP = {
|
|
@@ -2809,14 +4739,14 @@ const PLUGIN_CATEGORY_MAP = {
|
|
|
2809
4739
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
2810
4740
|
const REACT_COMPILER_MESSAGE = "React Compiler can't optimize this code";
|
|
2811
4741
|
const lookupOwnString = (record, key) => Object.hasOwn(record, key) ? record[key] : void 0;
|
|
2812
|
-
const cleanDiagnosticMessage = (message, help, plugin, rule) => {
|
|
4742
|
+
const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
2813
4743
|
if (plugin === "react-hooks-js") return {
|
|
2814
4744
|
message: REACT_COMPILER_MESSAGE,
|
|
2815
4745
|
help: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || help
|
|
2816
4746
|
};
|
|
2817
4747
|
return {
|
|
2818
4748
|
message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
|
|
2819
|
-
help: help || getRuleRecommendation(rule) || ""
|
|
4749
|
+
help: help || getRuleRecommendation(rule, project) || ""
|
|
2820
4750
|
};
|
|
2821
4751
|
};
|
|
2822
4752
|
const parseRuleCode = (code) => {
|
|
@@ -2919,7 +4849,7 @@ const isOxlintOutput = (value) => {
|
|
|
2919
4849
|
const candidate = value;
|
|
2920
4850
|
return Array.isArray(candidate.diagnostics);
|
|
2921
4851
|
};
|
|
2922
|
-
const parseOxlintOutput = (stdout, rootDirectory) => {
|
|
4852
|
+
const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
2923
4853
|
if (!stdout) return [];
|
|
2924
4854
|
const jsonStart = stdout.indexOf("{");
|
|
2925
4855
|
const sanitizedStdout = jsonStart > 0 ? stdout.slice(jsonStart) : stdout;
|
|
@@ -2933,7 +4863,7 @@ const parseOxlintOutput = (stdout, rootDirectory) => {
|
|
|
2933
4863
|
return parsed.diagnostics.filter((diagnostic) => diagnostic.code && SOURCE_FILE_PATTERN.test(diagnostic.filename) && !shouldSuppressLocalUseHookDiagnostic(diagnostic, rootDirectory)).map((diagnostic) => {
|
|
2934
4864
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
2935
4865
|
const primaryLabel = diagnostic.labels[0];
|
|
2936
|
-
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule);
|
|
4866
|
+
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
2937
4867
|
return {
|
|
2938
4868
|
filePath: diagnostic.filename,
|
|
2939
4869
|
plugin,
|
|
@@ -2963,7 +4893,7 @@ const validateRuleRegistration = () => {
|
|
|
2963
4893
|
for (const fullKey of ALL_REACT_DOCTOR_RULE_KEYS) {
|
|
2964
4894
|
const ruleName = fullKey.replace(/^react-doctor\//, "");
|
|
2965
4895
|
if (!getRuleCategory(ruleName)) missingCategory.push(fullKey);
|
|
2966
|
-
if (!
|
|
4896
|
+
if (!reactDoctorPlugin.rules[ruleName]?.recommendation) missingHelp.push(fullKey);
|
|
2967
4897
|
if (FRAMEWORK_SPECIFIC_RULE_KEYS.has(fullKey) && !reactDoctorPlugin.rules[ruleName]?.requires) missingMetadata.push(fullKey);
|
|
2968
4898
|
}
|
|
2969
4899
|
if (missingCategory.length > 0 || missingHelp.length > 0 || missingMetadata.length > 0) {
|
|
@@ -2976,7 +4906,9 @@ const validateRuleRegistration = () => {
|
|
|
2976
4906
|
}
|
|
2977
4907
|
};
|
|
2978
4908
|
const runOxlint = async (options) => {
|
|
2979
|
-
const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), onPartialFailure } = options;
|
|
4909
|
+
const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), userConfig, onPartialFailure } = options;
|
|
4910
|
+
const serverAuthFunctionNames = Array.isArray(userConfig?.serverAuthFunctionNames) ? userConfig.serverAuthFunctionNames.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
4911
|
+
const severityControls = buildRuleSeverityControls(userConfig);
|
|
2980
4912
|
validateRuleRegistration();
|
|
2981
4913
|
if (includePaths !== void 0 && includePaths.length === 0) return [];
|
|
2982
4914
|
const configDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
@@ -2988,7 +4920,9 @@ const runOxlint = async (options) => {
|
|
|
2988
4920
|
project,
|
|
2989
4921
|
customRulesOnly,
|
|
2990
4922
|
extendsPaths,
|
|
2991
|
-
ignoredTags
|
|
4923
|
+
ignoredTags,
|
|
4924
|
+
serverAuthFunctionNames,
|
|
4925
|
+
severityControls
|
|
2992
4926
|
});
|
|
2993
4927
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
2994
4928
|
try {
|
|
@@ -3025,7 +4959,7 @@ const runOxlint = async (options) => {
|
|
|
3025
4959
|
const spawnLintBatch = async (batch) => {
|
|
3026
4960
|
const batchArgs = [...baseArgs, ...batch];
|
|
3027
4961
|
try {
|
|
3028
|
-
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath), rootDirectory);
|
|
4962
|
+
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath), project, rootDirectory);
|
|
3029
4963
|
} catch (error) {
|
|
3030
4964
|
if (!isSplittableOxlintBatchError(error)) throw error;
|
|
3031
4965
|
if (batch.length <= 1) {
|
|
@@ -3055,7 +4989,9 @@ const runOxlint = async (options) => {
|
|
|
3055
4989
|
project,
|
|
3056
4990
|
customRulesOnly,
|
|
3057
4991
|
extendsPaths: [],
|
|
3058
|
-
ignoredTags
|
|
4992
|
+
ignoredTags,
|
|
4993
|
+
serverAuthFunctionNames,
|
|
4994
|
+
severityControls
|
|
3059
4995
|
}));
|
|
3060
4996
|
return await spawnLintBatches();
|
|
3061
4997
|
}
|
|
@@ -3484,7 +5420,7 @@ const shouldSelectAllChoices = (choiceStates) => {
|
|
|
3484
5420
|
};
|
|
3485
5421
|
//#endregion
|
|
3486
5422
|
//#region src/cli/utils/prompts.ts
|
|
3487
|
-
const require = createRequire(import.meta.url);
|
|
5423
|
+
const require$1 = createRequire(import.meta.url);
|
|
3488
5424
|
const PROMPTS_MULTISELECT_MODULE_PATH = "prompts/lib/elements/multiselect";
|
|
3489
5425
|
let didPatchMultiselectToggleAll = false;
|
|
3490
5426
|
let didPatchMultiselectSubmit = false;
|
|
@@ -3497,7 +5433,7 @@ const onCancel = () => {
|
|
|
3497
5433
|
const patchMultiselectToggleAll = () => {
|
|
3498
5434
|
if (didPatchMultiselectToggleAll) return;
|
|
3499
5435
|
didPatchMultiselectToggleAll = true;
|
|
3500
|
-
const multiselectPromptConstructor = require(PROMPTS_MULTISELECT_MODULE_PATH);
|
|
5436
|
+
const multiselectPromptConstructor = require$1(PROMPTS_MULTISELECT_MODULE_PATH);
|
|
3501
5437
|
multiselectPromptConstructor.prototype.toggleAll = function() {
|
|
3502
5438
|
const isCurrentChoiceDisabled = Boolean(this.value[this.cursor]?.disabled);
|
|
3503
5439
|
if (this.maxChoices !== void 0 || isCurrentChoiceDisabled) {
|
|
@@ -3515,7 +5451,7 @@ const patchMultiselectToggleAll = () => {
|
|
|
3515
5451
|
const patchMultiselectSubmit = () => {
|
|
3516
5452
|
if (didPatchMultiselectSubmit) return;
|
|
3517
5453
|
didPatchMultiselectSubmit = true;
|
|
3518
|
-
const multiselectPromptConstructor = require(PROMPTS_MULTISELECT_MODULE_PATH);
|
|
5454
|
+
const multiselectPromptConstructor = require$1(PROMPTS_MULTISELECT_MODULE_PATH);
|
|
3519
5455
|
const originalSubmit = multiselectPromptConstructor.prototype.submit;
|
|
3520
5456
|
multiselectPromptConstructor.prototype.submit = function() {
|
|
3521
5457
|
if (shouldAutoSelectCurrentChoice(this.value, this.cursor)) this.value[this.cursor].selected = true;
|
|
@@ -3585,7 +5521,8 @@ const mergeInspectOptions = (inputOptions, userConfig) => ({
|
|
|
3585
5521
|
share: userConfig?.share ?? true,
|
|
3586
5522
|
respectInlineDisables: inputOptions.respectInlineDisables ?? userConfig?.respectInlineDisables ?? true,
|
|
3587
5523
|
adoptExistingLintConfig: userConfig?.adoptExistingLintConfig ?? true,
|
|
3588
|
-
ignoredTags: buildIgnoredTags(userConfig)
|
|
5524
|
+
ignoredTags: buildIgnoredTags(userConfig),
|
|
5525
|
+
outputSurface: inputOptions.outputSurface ?? "cli"
|
|
3589
5526
|
});
|
|
3590
5527
|
const inspect = async (directory, inputOptions = {}) => {
|
|
3591
5528
|
const startTime = performance.now();
|
|
@@ -3643,6 +5580,7 @@ const runInspect = async (directory, options, userConfig, startTime) => {
|
|
|
3643
5580
|
respectInlineDisables: options.respectInlineDisables,
|
|
3644
5581
|
adoptExistingLintConfig: options.adoptExistingLintConfig,
|
|
3645
5582
|
ignoredTags: options.ignoredTags,
|
|
5583
|
+
userConfig,
|
|
3646
5584
|
onPartialFailure: (reason) => lintPartialFailures.push(reason)
|
|
3647
5585
|
});
|
|
3648
5586
|
lintSpinner?.succeed("Running lint checks.");
|
|
@@ -3670,7 +5608,8 @@ const runInspect = async (directory, options, userConfig, startTime) => {
|
|
|
3670
5608
|
const skippedChecks = [];
|
|
3671
5609
|
if (didLintFail) skippedChecks.push("lint");
|
|
3672
5610
|
const hasSkippedChecks = skippedChecks.length > 0;
|
|
3673
|
-
const
|
|
5611
|
+
const scoreDiagnostics = filterDiagnosticsForSurface(diagnostics, "score", userConfig);
|
|
5612
|
+
const scoreResult = options.offline ? null : await calculateScore(scoreDiagnostics);
|
|
3674
5613
|
const noScoreMessage = options.offline ? "Score unavailable in offline mode." : "Score unavailable (could not reach the score API).";
|
|
3675
5614
|
const skippedCheckReasons = {};
|
|
3676
5615
|
if (didLintFail && lintFailureReason !== null) skippedCheckReasons.lint = lintFailureReason;
|
|
@@ -3688,11 +5627,14 @@ const runInspect = async (directory, options, userConfig, startTime) => {
|
|
|
3688
5627
|
else logger.dim(noScoreMessage);
|
|
3689
5628
|
return buildResult();
|
|
3690
5629
|
}
|
|
3691
|
-
|
|
5630
|
+
const surfaceDiagnostics = filterDiagnosticsForSurface(diagnostics, options.outputSurface, userConfig);
|
|
5631
|
+
const demotedDiagnosticCount = diagnostics.length - surfaceDiagnostics.length;
|
|
5632
|
+
if (surfaceDiagnostics.length === 0) {
|
|
3692
5633
|
if (hasSkippedChecks) {
|
|
3693
5634
|
const skippedLabel = skippedChecks.join(" and ");
|
|
3694
5635
|
logger.warn(`No issues detected, but ${skippedLabel} checks failed — results are incomplete.`);
|
|
3695
|
-
} else logger.success(
|
|
5636
|
+
} else if (demotedDiagnosticCount > 0) logger.success(`No issues found! (${demotedDiagnosticCount} demoted from the ${options.outputSurface} surface — see config.surfaces.)`);
|
|
5637
|
+
else logger.success("No issues found!");
|
|
3696
5638
|
logger.break();
|
|
3697
5639
|
if (hasSkippedChecks) {
|
|
3698
5640
|
printBrandingOnlyHeader();
|
|
@@ -3702,10 +5644,14 @@ const runInspect = async (directory, options, userConfig, startTime) => {
|
|
|
3702
5644
|
return buildResult();
|
|
3703
5645
|
}
|
|
3704
5646
|
logger.break();
|
|
3705
|
-
printDiagnostics(
|
|
5647
|
+
printDiagnostics(surfaceDiagnostics, options.verbose, directory);
|
|
5648
|
+
if (demotedDiagnosticCount > 0) {
|
|
5649
|
+
logger.log(highlighter.gray(` ${demotedDiagnosticCount} demoted from the ${options.outputSurface} surface (e.g. design cleanup) — run \`npx react-doctor@latest .\` locally for the full list.`));
|
|
5650
|
+
logger.break();
|
|
5651
|
+
}
|
|
3706
5652
|
const displayedSourceFileCount = isDiffMode ? includePaths.length : lintSourceFileCount;
|
|
3707
5653
|
const shouldShowShareLink = !options.offline && options.share;
|
|
3708
|
-
printSummary(
|
|
5654
|
+
printSummary(surfaceDiagnostics, elapsedMilliseconds, scoreResult, projectInfo.projectName, displayedSourceFileCount, noScoreMessage, !shouldShowShareLink);
|
|
3709
5655
|
if (hasSkippedChecks) {
|
|
3710
5656
|
const skippedLabel = skippedChecks.join(" and ");
|
|
3711
5657
|
logger.break();
|
|
@@ -3805,7 +5751,7 @@ const CI_ENVIRONMENT_VARIABLES = [
|
|
|
3805
5751
|
const isCiEnvironment = () => CI_ENVIRONMENT_VARIABLES.some((envVariable) => Boolean(process.env[envVariable])) || process.env.CI === "true";
|
|
3806
5752
|
//#endregion
|
|
3807
5753
|
//#region src/cli/utils/version.ts
|
|
3808
|
-
const VERSION = "0.2.0-beta.
|
|
5754
|
+
const VERSION = "0.2.0-beta.6";
|
|
3809
5755
|
//#endregion
|
|
3810
5756
|
//#region src/cli/utils/json-mode.ts
|
|
3811
5757
|
let context = null;
|
|
@@ -3871,7 +5817,8 @@ const resolveCliInspectOptions = (flags, userConfig) => ({
|
|
|
3871
5817
|
scoreOnly: Boolean(flags.score),
|
|
3872
5818
|
offline: Boolean(flags.offline) || (userConfig?.offline ?? false) || isCiEnvironment(),
|
|
3873
5819
|
silent: Boolean(flags.json),
|
|
3874
|
-
respectInlineDisables: flags.respectInlineDisables ?? userConfig?.respectInlineDisables ?? true
|
|
5820
|
+
respectInlineDisables: flags.respectInlineDisables ?? userConfig?.respectInlineDisables ?? true,
|
|
5821
|
+
outputSurface: flags.prComment ? "prComment" : "cli"
|
|
3875
5822
|
});
|
|
3876
5823
|
//#endregion
|
|
3877
5824
|
//#region src/cli/utils/resolve-diff-mode.ts
|
|
@@ -4096,6 +6043,7 @@ const validateModeFlags = (flags) => {
|
|
|
4096
6043
|
if (exclusiveModes.length > 1) throw new Error(`Cannot combine ${exclusiveModes.join(" and ")}; pick one mode.`);
|
|
4097
6044
|
if (flags.yes && flags.full) throw new Error("Cannot combine --yes and --full; pick one.");
|
|
4098
6045
|
if (flags.score && flags.json) throw new Error("Cannot combine --score and --json; pick one output mode.");
|
|
6046
|
+
if (flags.prComment && (flags.json || flags.score)) throw new Error("--pr-comment cannot be combined with --json or --score.");
|
|
4099
6047
|
if (flags.annotations && (flags.json || flags.score)) throw new Error("--annotations cannot be combined with --json or --score.");
|
|
4100
6048
|
if (flags.explain !== void 0 && flags.why !== void 0) throw new Error("Use --explain or --why, not both — they're aliases of the same flag.");
|
|
4101
6049
|
if ((flags.explain ?? flags.why) !== void 0 && (flags.json || flags.score || flags.annotations || flags.staged)) throw new Error("--explain cannot be combined with --json, --score, --annotations, or --staged.");
|
|
@@ -4193,7 +6141,8 @@ const inspectAction = async (directory, flags) => {
|
|
|
4193
6141
|
totalElapsedMilliseconds: performance.now() - startTime
|
|
4194
6142
|
}));
|
|
4195
6143
|
if (flags.annotations) printAnnotations(remappedDiagnostics, isJsonMode);
|
|
4196
|
-
|
|
6144
|
+
const ciFailureDiagnostics = filterDiagnosticsForSurface(remappedDiagnostics, "ciFailure", userConfig);
|
|
6145
|
+
if (!isScoreOnly && shouldFailForDiagnostics(ciFailureDiagnostics, resolveFailOnLevel(flags, userConfig))) process.exitCode = 1;
|
|
4197
6146
|
} finally {
|
|
4198
6147
|
snapshot.cleanup();
|
|
4199
6148
|
}
|
|
@@ -4256,7 +6205,8 @@ const inspectAction = async (directory, flags) => {
|
|
|
4256
6205
|
totalElapsedMilliseconds: performance.now() - startTime
|
|
4257
6206
|
}));
|
|
4258
6207
|
if (flags.annotations) printAnnotations(allDiagnostics, isJsonMode);
|
|
4259
|
-
|
|
6208
|
+
const ciFailureDiagnostics = filterDiagnosticsForSurface(allDiagnostics, "ciFailure", userConfig);
|
|
6209
|
+
if (!isScoreOnly && shouldFailForDiagnostics(ciFailureDiagnostics, resolveFailOnLevel(flags, userConfig))) process.exitCode = 1;
|
|
4260
6210
|
} catch (error) {
|
|
4261
6211
|
if (isJsonMode) {
|
|
4262
6212
|
writeJsonErrorReport(error);
|
|
@@ -4387,7 +6337,7 @@ const exitGracefully = () => {
|
|
|
4387
6337
|
//#region src/cli/index.ts
|
|
4388
6338
|
process.on("SIGINT", exitGracefully);
|
|
4389
6339
|
process.on("SIGTERM", exitGracefully);
|
|
4390
|
-
const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--full", "force a full scan (overrides any `diff` value in config or `--diff`)").option("--project <name>", "select workspace project (comma-separated for multiple)").option("--diff [base]", "scan only files changed vs base branch (pass `false` to disable; overridden by --full)").option("--offline", "skip the score API and the share URL (no score is shown)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--fail-on <level>", "exit with error code on diagnostics: error, warning, none (default: error)").option("--annotations", "output diagnostics as GitHub Actions annotations").option("--explain <file:line>", "diagnose why a rule fired or why a suppression didn't apply at a specific location").option("--why <file:line>", "alias for --explain").option("--respect-inline-disables", "respect inline `// eslint-disable*` / `// oxlint-disable*` comments (default)").option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").addHelpText("after", `
|
|
6340
|
+
const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--full", "force a full scan (overrides any `diff` value in config or `--diff`)").option("--project <name>", "select workspace project (comma-separated for multiple)").option("--diff [base]", "scan only files changed vs base branch (pass `false` to disable; overridden by --full)").option("--offline", "skip the score API and the share URL (no score is shown)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--fail-on <level>", "exit with error code on diagnostics: error, warning, none (default: error)").option("--annotations", "output diagnostics as GitHub Actions annotations").option("--pr-comment", "tune CLI output for sticky PR comments (drops weak-signal rule families like `design` from the printed list and the fail-on gate; configure via config.surfaces)").option("--explain <file:line>", "diagnose why a rule fired or why a suppression didn't apply at a specific location").option("--why <file:line>", "alias for --explain").option("--respect-inline-disables", "respect inline `// eslint-disable*` / `// oxlint-disable*` comments (default)").option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").addHelpText("after", `
|
|
4391
6341
|
${highlighter.dim("Configuration:")}
|
|
4392
6342
|
Place a ${highlighter.info("react-doctor.config.json")} (or ${highlighter.info("\"reactDoctor\"")} key in your package.json) in the project root.
|
|
4393
6343
|
CLI flags always override config values. See the README for the full schema.
|