partially revert "Array support for find + ResurrectHome: View Server Home Button on Server Guide (#2283)"
This reverts commit 5636f9d979
.
It breaks Vesktop which is not acceptable. Need to resolve this conflict and add this back later
This commit is contained in:
parent
5636f9d979
commit
89dc74d5d7
|
@ -299,9 +299,6 @@ function runTime(token: string) {
|
||||||
delete patch.predicate;
|
delete patch.predicate;
|
||||||
delete patch.group;
|
delete patch.group;
|
||||||
|
|
||||||
if (!Array.isArray(patch.find))
|
|
||||||
patch.find = [patch.find];
|
|
||||||
|
|
||||||
if (!Array.isArray(patch.replacement))
|
if (!Array.isArray(patch.replacement))
|
||||||
patch.replacement = [patch.replacement];
|
patch.replacement = [patch.replacement];
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,8 @@ if (IS_DEV) {
|
||||||
var differ = require("diff") as typeof import("diff");
|
var differ = require("diff") as typeof import("diff");
|
||||||
}
|
}
|
||||||
|
|
||||||
const findCandidates = debounce(function ({ finds, setModule, setError }) {
|
const findCandidates = debounce(function ({ find, setModule, setError }) {
|
||||||
const candidates = search(...finds);
|
const candidates = search(find);
|
||||||
const keys = Object.keys(candidates);
|
const keys = Object.keys(candidates);
|
||||||
const len = keys.length;
|
const len = keys.length;
|
||||||
if (len === 0)
|
if (len === 0)
|
||||||
|
@ -180,8 +180,7 @@ function ReplacementInput({ replacement, setReplacement, replacementError }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* FormTitle adds a class if className is not set, so we set it to an empty string to prevent that */}
|
<Forms.FormTitle>replacement</Forms.FormTitle>
|
||||||
<Forms.FormTitle className="">replacement</Forms.FormTitle>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
value={replacement?.toString()}
|
value={replacement?.toString()}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
@ -189,7 +188,7 @@ function ReplacementInput({ replacement, setReplacement, replacementError }) {
|
||||||
/>
|
/>
|
||||||
{!isFunc && (
|
{!isFunc && (
|
||||||
<div className="vc-text-selectable">
|
<div className="vc-text-selectable">
|
||||||
<Forms.FormTitle className={Margins.top8}>Cheat Sheet</Forms.FormTitle>
|
<Forms.FormTitle>Cheat Sheet</Forms.FormTitle>
|
||||||
{Object.entries({
|
{Object.entries({
|
||||||
"\\i": "Special regex escape sequence that matches identifiers (varnames, classnames, etc.)",
|
"\\i": "Special regex escape sequence that matches identifiers (varnames, classnames, etc.)",
|
||||||
"$$": "Insert a $",
|
"$$": "Insert a $",
|
||||||
|
@ -221,12 +220,11 @@ function ReplacementInput({ replacement, setReplacement, replacementError }) {
|
||||||
|
|
||||||
interface FullPatchInputProps {
|
interface FullPatchInputProps {
|
||||||
setFind(v: string): void;
|
setFind(v: string): void;
|
||||||
setFinds(v: string[]): void;
|
|
||||||
setMatch(v: string): void;
|
setMatch(v: string): void;
|
||||||
setReplacement(v: string | ReplaceFn): void;
|
setReplacement(v: string | ReplaceFn): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function FullPatchInput({ setFind, setFinds, setMatch, setReplacement }: FullPatchInputProps) {
|
function FullPatchInput({ setFind, setMatch, setReplacement }: FullPatchInputProps) {
|
||||||
const [fullPatch, setFullPatch] = React.useState<string>("");
|
const [fullPatch, setFullPatch] = React.useState<string>("");
|
||||||
const [fullPatchError, setFullPatchError] = React.useState<string>("");
|
const [fullPatchError, setFullPatchError] = React.useState<string>("");
|
||||||
|
|
||||||
|
@ -258,8 +256,7 @@ function FullPatchInput({ setFind, setFinds, setMatch, setReplacement }: FullPat
|
||||||
if (!parsed.replacement.match) throw new Error("No 'replacement.match' field");
|
if (!parsed.replacement.match) throw new Error("No 'replacement.match' field");
|
||||||
if (!parsed.replacement.replace) throw new Error("No 'replacement.replace' field");
|
if (!parsed.replacement.replace) throw new Error("No 'replacement.replace' field");
|
||||||
|
|
||||||
setFind(JSON.stringify(parsed.find));
|
setFind(parsed.find);
|
||||||
setFinds(parsed.find instanceof Array ? parsed.find : [parsed.find]);
|
|
||||||
setMatch(parsed.replacement.match instanceof RegExp ? parsed.replacement.match.source : parsed.replacement.match);
|
setMatch(parsed.replacement.match instanceof RegExp ? parsed.replacement.match.source : parsed.replacement.match);
|
||||||
setReplacement(parsed.replacement.replace);
|
setReplacement(parsed.replacement.replace);
|
||||||
setFullPatchError("");
|
setFullPatchError("");
|
||||||
|
@ -269,7 +266,7 @@ function FullPatchInput({ setFind, setFinds, setMatch, setReplacement }: FullPat
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Forms.FormText className={Margins.bottom8}>Paste your full JSON patch here to fill out the fields</Forms.FormText>
|
<Forms.FormText>Paste your full JSON patch here to fill out the fields</Forms.FormText>
|
||||||
<TextArea value={fullPatch} onChange={setFullPatch} onBlur={update} />
|
<TextArea value={fullPatch} onChange={setFullPatch} onBlur={update} />
|
||||||
{fullPatchError !== "" && <Forms.FormText style={{ color: "var(--text-danger)" }}>{fullPatchError}</Forms.FormText>}
|
{fullPatchError !== "" && <Forms.FormText style={{ color: "var(--text-danger)" }}>{fullPatchError}</Forms.FormText>}
|
||||||
</>;
|
</>;
|
||||||
|
@ -277,7 +274,6 @@ function FullPatchInput({ setFind, setFinds, setMatch, setReplacement }: FullPat
|
||||||
|
|
||||||
function PatchHelper() {
|
function PatchHelper() {
|
||||||
const [find, setFind] = React.useState<string>("");
|
const [find, setFind] = React.useState<string>("");
|
||||||
const [finds, setFinds] = React.useState<string[]>([]);
|
|
||||||
const [match, setMatch] = React.useState<string>("");
|
const [match, setMatch] = React.useState<string>("");
|
||||||
const [replacement, setReplacement] = React.useState<string | ReplaceFn>("");
|
const [replacement, setReplacement] = React.useState<string | ReplaceFn>("");
|
||||||
|
|
||||||
|
@ -289,39 +285,20 @@ function PatchHelper() {
|
||||||
const code = React.useMemo(() => {
|
const code = React.useMemo(() => {
|
||||||
return `
|
return `
|
||||||
{
|
{
|
||||||
find: ${finds.length > 1 ? `[${finds.map(f => JSON.stringify(f)).join(", ")}]` : finds.length > 0 ? JSON.stringify(finds[0]) : "[]"},
|
find: ${JSON.stringify(find)},
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /${match.replace(/(?<!\\)\//g, "\\/")}/,
|
match: /${match.replace(/(?<!\\)\//g, "\\/")}/,
|
||||||
replace: ${typeof replacement === "function" ? replacement.toString() : JSON.stringify(replacement)}
|
replace: ${typeof replacement === "function" ? replacement.toString() : JSON.stringify(replacement)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`.trim();
|
`.trim();
|
||||||
}, [finds, match, replacement]);
|
}, [find, match, replacement]);
|
||||||
|
|
||||||
function onFindChange(v: string) {
|
function onFindChange(v: string) {
|
||||||
setFindError(void 0);
|
setFindError(void 0);
|
||||||
setFind(v);
|
setFind(v);
|
||||||
}
|
if (v.length) {
|
||||||
|
findCandidates({ find: v, setModule, setError: setFindError });
|
||||||
function onFindBlur() {
|
|
||||||
let finds = [] as string[];
|
|
||||||
const findArrayMatch = find.match(/^\[.*\]$/);
|
|
||||||
|
|
||||||
if (findArrayMatch) {
|
|
||||||
try {
|
|
||||||
const rawFinds = (0, eval)(`(${find})`);
|
|
||||||
finds = rawFinds instanceof Array ? rawFinds : [rawFinds];
|
|
||||||
} catch (e) {
|
|
||||||
setFindError((e as Error).message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (find.length) {
|
|
||||||
finds = [find];
|
|
||||||
}
|
|
||||||
|
|
||||||
setFinds(finds);
|
|
||||||
if (finds.length) {
|
|
||||||
findCandidates({ finds, setModule, setError: setFindError });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,21 +317,19 @@ function PatchHelper() {
|
||||||
<Forms.FormTitle>full patch</Forms.FormTitle>
|
<Forms.FormTitle>full patch</Forms.FormTitle>
|
||||||
<FullPatchInput
|
<FullPatchInput
|
||||||
setFind={onFindChange}
|
setFind={onFindChange}
|
||||||
setFinds={setFinds}
|
|
||||||
setMatch={onMatchChange}
|
setMatch={onMatchChange}
|
||||||
setReplacement={setReplacement}
|
setReplacement={setReplacement}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Forms.FormTitle className={Margins.top8}>find</Forms.FormTitle>
|
<Forms.FormTitle>find</Forms.FormTitle>
|
||||||
<TextInput
|
<TextInput
|
||||||
type="text"
|
type="text"
|
||||||
value={find}
|
value={find}
|
||||||
onChange={onFindChange}
|
onChange={onFindChange}
|
||||||
onBlur={onFindBlur}
|
|
||||||
error={findError}
|
error={findError}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Forms.FormTitle className={Margins.top8}>match</Forms.FormTitle>
|
<Forms.FormTitle>match</Forms.FormTitle>
|
||||||
<CheckedTextInput
|
<CheckedTextInput
|
||||||
value={match}
|
value={match}
|
||||||
onChange={onMatchChange}
|
onChange={onMatchChange}
|
||||||
|
@ -367,7 +342,6 @@ function PatchHelper() {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className={Margins.top8} />
|
|
||||||
<ReplacementInput
|
<ReplacementInput
|
||||||
replacement={replacement}
|
replacement={replacement}
|
||||||
setReplacement={setReplacement}
|
setReplacement={setReplacement}
|
||||||
|
|
|
@ -79,8 +79,6 @@ for (const p of pluginsValues) {
|
||||||
if (p.patches && isPluginEnabled(p.name)) {
|
if (p.patches && isPluginEnabled(p.name)) {
|
||||||
for (const patch of p.patches) {
|
for (const patch of p.patches) {
|
||||||
patch.plugin = p.name;
|
patch.plugin = p.name;
|
||||||
if (!Array.isArray(patch.find))
|
|
||||||
patch.find = [patch.find];
|
|
||||||
if (!Array.isArray(patch.replacement))
|
if (!Array.isArray(patch.replacement))
|
||||||
patch.replacement = [patch.replacement];
|
patch.replacement = [patch.replacement];
|
||||||
patches.push(patch);
|
patches.push(patch);
|
||||||
|
|
|
@ -36,7 +36,7 @@ export interface PatchReplacement {
|
||||||
|
|
||||||
export interface Patch {
|
export interface Patch {
|
||||||
plugin: string;
|
plugin: string;
|
||||||
find: string | string[];
|
find: string;
|
||||||
replacement: PatchReplacement | PatchReplacement[];
|
replacement: PatchReplacement | PatchReplacement[];
|
||||||
/** Whether this patch should apply to multiple modules */
|
/** Whether this patch should apply to multiple modules */
|
||||||
all?: boolean;
|
all?: boolean;
|
||||||
|
|
|
@ -186,8 +186,7 @@ function patchFactories(factories: Record<string | number, (module: { exports: a
|
||||||
const executePatch = traceFunction(`patch by ${patch.plugin}`, (match: string | RegExp, replace: string) => code.replace(match, replace));
|
const executePatch = traceFunction(`patch by ${patch.plugin}`, (match: string | RegExp, replace: string) => code.replace(match, replace));
|
||||||
if (patch.predicate && !patch.predicate()) continue;
|
if (patch.predicate && !patch.predicate()) continue;
|
||||||
|
|
||||||
// we change all patch.find to array in plugins/index
|
if (code.includes(patch.find)) {
|
||||||
if ((patch.find as string[]).every(f => code.includes(f))) {
|
|
||||||
patchedBy.add(patch.plugin);
|
patchedBy.add(patch.plugin);
|
||||||
|
|
||||||
const previousMod = mod;
|
const previousMod = mod;
|
||||||
|
|
Loading…
Reference in a new issue