mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 14:43:03 -04:00
Fix Dev Companion
This commit is contained in:
parent
63821c1468
commit
cb6a8502fd
8 changed files with 55 additions and 37 deletions
|
@ -9,27 +9,20 @@ import { Settings } from "@api/Settings";
|
||||||
import { canonicalizeMatch } from "@utils/patches";
|
import { canonicalizeMatch } from "@utils/patches";
|
||||||
import { CodeFilter, stringMatches, wreq } from "@webpack";
|
import { CodeFilter, stringMatches, wreq } from "@webpack";
|
||||||
import { Toasts } from "@webpack/common";
|
import { Toasts } from "@webpack/common";
|
||||||
import { AnyWebpackRequire } from "webpack";
|
import { getFactoryPatchedSource, getOriginalFactory } from "@webpack/utils";
|
||||||
|
|
||||||
import { settings as companionSettings } from ".";
|
import { settings as companionSettings } from ".";
|
||||||
import { Recieve } from "./types";
|
import { Recieve } from "./types";
|
||||||
|
|
||||||
const SYM_PATCHED_SOURCE = Symbol("WebpackPatcher.patchedSource");
|
|
||||||
|
|
||||||
function getFactoryPatchedSource(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
|
||||||
return webpackRequire.m[id]?.[SYM_PATCHED_SOURCE];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extracts the patched module, if there is no patched module, throws an error
|
* extracts the patched module, if there is no patched module, throws an error
|
||||||
* @param id module id
|
* @param id module id
|
||||||
*/
|
*/
|
||||||
export function extractOrThrow(id: number): string {
|
export function extractOrThrow(id: number): string {
|
||||||
const module = wreq.m[id];
|
const module = getFactoryPatchedSource(id);
|
||||||
const patchedSource = getFactoryPatchedSource(id);
|
if (!module)
|
||||||
if (!patchedSource)
|
|
||||||
throw new Error("No patched module found for module id " + id);
|
throw new Error("No patched module found for module id " + id);
|
||||||
return patchedSource;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,12 +34,11 @@ export function extractOrThrow(id: number): string {
|
||||||
* @param patched return the patched module
|
* @param patched return the patched module
|
||||||
*/
|
*/
|
||||||
export function extractModule(id: number, patched = companionSettings.store.usePatchedModule): string {
|
export function extractModule(id: number, patched = companionSettings.store.usePatchedModule): string {
|
||||||
const module = wreq.m[id];
|
|
||||||
if (!module)
|
|
||||||
throw new Error("No module found for module id:" + id);
|
|
||||||
const original = module.toString();
|
|
||||||
const patchedSource = getFactoryPatchedSource(id);
|
const patchedSource = getFactoryPatchedSource(id);
|
||||||
return patched ? patchedSource ?? original : original;
|
const original = getOriginalFactory(id);
|
||||||
|
if (patched && !patchedSource || !original)
|
||||||
|
throw new Error("No module found for module id: " + id);
|
||||||
|
return patched ? patchedSource ?? original.toString() : original.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseNode(node: Recieve.FindNode): any {
|
export function parseNode(node: Recieve.FindNode): any {
|
||||||
|
|
|
@ -17,5 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * as Common from "./common";
|
export * as Common from "./common";
|
||||||
|
export * from "./utils/getFactories";
|
||||||
export * from "./webpack";
|
export * from "./webpack";
|
||||||
export * from "./wreq.d";
|
export * from "./wreq.d";
|
||||||
|
|
|
@ -15,10 +15,8 @@ import { reporterData } from "debug/reporterData";
|
||||||
import { traceFunctionWithResults } from "../debug/Tracer";
|
import { traceFunctionWithResults } from "../debug/Tracer";
|
||||||
import { patches } from "../plugins";
|
import { patches } from "../plugins";
|
||||||
import { _initWebpack, _shouldIgnoreModule, AnyModuleFactory, AnyWebpackRequire, factoryListeners, findModuleId, MaybeWrappedModuleFactory, ModuleExports, moduleListeners, waitForSubscriptions, WebpackRequire, WrappedModuleFactory, wreq } from ".";
|
import { _initWebpack, _shouldIgnoreModule, AnyModuleFactory, AnyWebpackRequire, factoryListeners, findModuleId, MaybeWrappedModuleFactory, ModuleExports, moduleListeners, waitForSubscriptions, WebpackRequire, WrappedModuleFactory, wreq } from ".";
|
||||||
|
import { SYM_ORIGINAL_FACTORY, SYM_PATCHED_BY, SYM_PATCHED_SOURCE } from "./utils/symbols";
|
||||||
|
|
||||||
export const SYM_ORIGINAL_FACTORY = Symbol("WebpackPatcher.originalFactory");
|
|
||||||
export const SYM_PATCHED_SOURCE = Symbol("WebpackPatcher.patchedSource");
|
|
||||||
export const SYM_PATCHED_BY = Symbol("WebpackPatcher.patchedBy");
|
|
||||||
/** A set with all the Webpack instances */
|
/** A set with all the Webpack instances */
|
||||||
export const allWebpackInstances = new Set<AnyWebpackRequire>();
|
export const allWebpackInstances = new Set<AnyWebpackRequire>();
|
||||||
export const patchTimings = [] as Array<[plugin: string, moduleId: PropertyKey, match: string | RegExp, totalTime: number]>;
|
export const patchTimings = [] as Array<[plugin: string, moduleId: PropertyKey, match: string | RegExp, totalTime: number]>;
|
||||||
|
@ -78,19 +76,6 @@ const define: Define = (target, p, attributes) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getOriginalFactory(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
|
||||||
const moduleFactory = webpackRequire.m[id];
|
|
||||||
return (moduleFactory?.[SYM_ORIGINAL_FACTORY] ?? moduleFactory) as AnyModuleFactory | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFactoryPatchedSource(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
|
||||||
return webpackRequire.m[id]?.[SYM_PATCHED_SOURCE];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFactoryPatchedBy(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
|
||||||
return webpackRequire.m[id]?.[SYM_PATCHED_BY];
|
|
||||||
}
|
|
||||||
|
|
||||||
// wreq.m is the Webpack object containing module factories. It is pre-populated with module factories, and is also populated via webpackGlobal.push
|
// wreq.m is the Webpack object containing module factories. It is pre-populated with module factories, and is also populated via webpackGlobal.push
|
||||||
// We use this setter to intercept when wreq.m is defined and apply the patching in its module factories.
|
// We use this setter to intercept when wreq.m is defined and apply the patching in its module factories.
|
||||||
// We wrap wreq.m with our proxy, which is responsible for patching the module factories when they are set, or defining getters for the patched versions.
|
// We wrap wreq.m with our proxy, which is responsible for patching the module factories when they are set, or defining getters for the patched versions.
|
||||||
|
|
23
src/webpack/utils/getFactories.ts
Normal file
23
src/webpack/utils/getFactories.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { wreq } from "@webpack";
|
||||||
|
import { AnyModuleFactory, AnyWebpackRequire } from "webpack/wreq";
|
||||||
|
|
||||||
|
import { SYM_ORIGINAL_FACTORY, SYM_PATCHED_BY, SYM_PATCHED_SOURCE } from "./symbols";
|
||||||
|
|
||||||
|
export function getOriginalFactory(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
||||||
|
const moduleFactory = webpackRequire.m[id];
|
||||||
|
return (moduleFactory?.[SYM_ORIGINAL_FACTORY] ?? moduleFactory) as AnyModuleFactory | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFactoryPatchedSource(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
||||||
|
return webpackRequire.m[id]?.[SYM_PATCHED_SOURCE];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFactoryPatchedBy(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
|
||||||
|
return webpackRequire.m[id]?.[SYM_PATCHED_BY];
|
||||||
|
}
|
8
src/webpack/utils/index.ts
Normal file
8
src/webpack/utils/index.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./getFactories";
|
||||||
|
export * from "./symbols";
|
9
src/webpack/utils/symbols.ts
Normal file
9
src/webpack/utils/symbols.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const SYM_ORIGINAL_FACTORY = Symbol.for("WebpackPatcher.originalFactory");
|
||||||
|
export const SYM_PATCHED_SOURCE = Symbol.for("WebpackPatcher.patchedSource");
|
||||||
|
export const SYM_PATCHED_BY = Symbol.for("WebpackPatcher.patchedBy");
|
2
src/webpack/wreq.d.ts
vendored
2
src/webpack/wreq.d.ts
vendored
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SYM_ORIGINAL_FACTORY, SYM_PATCHED_BY, SYM_PATCHED_SOURCE } from "./patchWebpack";
|
import { SYM_ORIGINAL_FACTORY, SYM_PATCHED_BY, SYM_PATCHED_SOURCE } from "./utils/symbols";
|
||||||
|
|
||||||
export type ModuleExports = any;
|
export type ModuleExports = any;
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,12 @@
|
||||||
"@webpack/common": [
|
"@webpack/common": [
|
||||||
"./webpack/common"
|
"./webpack/common"
|
||||||
],
|
],
|
||||||
|
"@webpack/utils": [
|
||||||
|
"./webpack/utils"
|
||||||
|
],
|
||||||
"@webpack": [
|
"@webpack": [
|
||||||
"./webpack/webpack"
|
"./webpack/webpack"
|
||||||
],
|
],
|
||||||
"@webpack/patch": [
|
|
||||||
"./webpack/patchWebpack"
|
|
||||||
],
|
|
||||||
"@plugins": [
|
"@plugins": [
|
||||||
"./plugins"
|
"./plugins"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue