From ba6d3c7e60a74663de0ab1975ba2f5c5537ddebf Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 22 Jun 2024 02:37:40 -0300 Subject: [PATCH] organize --- src/plugins/consoleShortcuts/index.ts | 1 + src/webpack/{webpack.tsx => api.tsx} | 98 +++++++++++++-------------- src/webpack/common/classes.ts | 2 +- src/webpack/common/components.ts | 2 +- src/webpack/common/menu.ts | 2 +- src/webpack/common/react.ts | 2 +- src/webpack/common/stores.ts | 2 +- src/webpack/common/userSettings.ts | 2 +- src/webpack/common/utils.ts | 2 +- src/webpack/index.ts | 2 +- tsconfig.json | 2 +- 11 files changed, 59 insertions(+), 58 deletions(-) rename src/webpack/{webpack.tsx => api.tsx} (100%) diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index 2f8a240aa..9896bcdfb 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -85,6 +85,7 @@ function makeShortcuts() { wpex: extract, wpexs: (code: string) => extract(Webpack.cacheFindModuleId(code)!), loadLazyChunks: IS_DEV ? loadLazyChunks : () => { throw new Error("loadLazyChunks is dev only."); }, + filters, find, findAll: cacheFindAll, findByProps, diff --git a/src/webpack/webpack.tsx b/src/webpack/api.tsx similarity index 100% rename from src/webpack/webpack.tsx rename to src/webpack/api.tsx index c7dbaa234..e7d77bf49 100644 --- a/src/webpack/webpack.tsx +++ b/src/webpack/api.tsx @@ -788,6 +788,55 @@ export function extractAndLoadChunksLazy(code: string | string[], matcher: RegEx return extractAndLoadChunks; } +/** + * Search modules by keyword. This searches the factory methods, + * meaning you can search all sorts of things, methodName, strings somewhere in the code, etc. + * + * @param filters One or more strings or regexes + * @returns Mapping of found modules + */ +export function search(...filters: Array) { + const results = {} as Record; + const factories = wreq.m; + outer: + for (const id in factories) { + const factory = factories[id]; + const factoryStr = String(factory); + for (const filter of filters) { + if (typeof filter === "string" && !factoryStr.includes(filter)) continue outer; + if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer; + } + results[id] = factory; + } + + return results; +} + +/** + * Extract a specific module by id into its own Source File. This has no effect on + * the code, it is only useful to be able to look at a specific module without having + * to view a massive file. extract then returns the extracted module so you can jump to it. + * As mentioned above, note that this extracted module is not actually used, + * so putting breakpoints or similar will have no effect. + * + * @param id The id of the module to extract + */ +export function extract(id: PropertyKey) { + const factory = wreq.m[id] as Function; + if (!factory) return; + + const code = ` +// [EXTRACTED] WebpackModule${String(id)} +// WARNING: This module was extracted to be more easily readable. +// This module is NOT ACTUALLY USED! This means putting breakpoints will have NO EFFECT!! + +0,${String(factory)} +//# sourceURL=ExtractedWebpackModule${String(id)} +`; + const extracted = (0, eval)(code); + return extracted as Function; +} + function deprecatedRedirect any>(oldMethod: string, newMethod: string, redirect: T): T { return ((...args: Parameters) => { logger.warn(`Method ${oldMethod} is deprecated. Use ${newMethod} instead. For more information read https://github.com/Vendicated/Vencord/pull/2409#issue-2277161516`); @@ -914,52 +963,3 @@ export const findBulk = deprecatedRedirect("findBulk", "cacheFindBulk", cacheFin * @returns string or null */ export const findModuleId = deprecatedRedirect("findModuleId", "cacheFindModuleId", cacheFindModuleId); - -/** - * Search modules by keyword. This searches the factory methods, - * meaning you can search all sorts of things, methodName, strings somewhere in the code, etc. - * - * @param filters One or more strings or regexes - * @returns Mapping of found modules - */ -export function search(...filters: Array) { - const results = {} as Record; - const factories = wreq.m; - outer: - for (const id in factories) { - const factory = factories[id]; - const factoryStr = String(factory); - for (const filter of filters) { - if (typeof filter === "string" && !factoryStr.includes(filter)) continue outer; - if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer; - } - results[id] = factory; - } - - return results; -} - -/** - * Extract a specific module by id into its own Source File. This has no effect on - * the code, it is only useful to be able to look at a specific module without having - * to view a massive file. extract then returns the extracted module so you can jump to it. - * As mentioned above, note that this extracted module is not actually used, - * so putting breakpoints or similar will have no effect. - * - * @param id The id of the module to extract - */ -export function extract(id: PropertyKey) { - const factory = wreq.m[id] as Function; - if (!factory) return; - - const code = ` -// [EXTRACTED] WebpackModule${String(id)} -// WARNING: This module was extracted to be more easily readable. -// This module is NOT ACTUALLY USED! This means putting breakpoints will have NO EFFECT!! - -0,${String(factory)} -//# sourceURL=ExtractedWebpackModule${String(id)} -`; - const extracted = (0, eval)(code); - return extracted as Function; -} diff --git a/src/webpack/common/classes.ts b/src/webpack/common/classes.ts index ea41bd693..d928c92c1 100644 --- a/src/webpack/common/classes.ts +++ b/src/webpack/common/classes.ts @@ -17,7 +17,7 @@ */ // eslint-disable-next-line path-alias/no-relative -import { find, findByProps } from "../webpack"; +import { find, findByProps } from "../api"; import * as t from "./types/classes"; export const ModalImageClasses = find(m => m.image && m.modal && !m.applicationIcon); diff --git a/src/webpack/common/components.ts b/src/webpack/common/components.ts index 92ff4c3b2..ea32a5912 100644 --- a/src/webpack/common/components.ts +++ b/src/webpack/common/components.ts @@ -19,7 +19,7 @@ import { NoopComponent } from "@utils/react"; // eslint-disable-next-line path-alias/no-relative -import { filters, find, findComponent, findExportedComponent } from "../webpack"; +import { filters, find, findComponent, findExportedComponent } from "../api"; import * as t from "./types/components"; export let Card: t.Card = NoopComponent as any; diff --git a/src/webpack/common/menu.ts b/src/webpack/common/menu.ts index b61b09466..91a40bd50 100644 --- a/src/webpack/common/menu.ts +++ b/src/webpack/common/menu.ts @@ -17,7 +17,7 @@ */ // eslint-disable-next-line path-alias/no-relative -import { filters, findByProps, mapMangledModule } from "../webpack"; +import { filters, findByProps, mapMangledModule } from "../api"; import type * as t from "./types/menu"; export const Menu = findByProps("MenuItem", "MenuSliderControl"); diff --git a/src/webpack/common/react.ts b/src/webpack/common/react.ts index 6109290ec..0707092a0 100644 --- a/src/webpack/common/react.ts +++ b/src/webpack/common/react.ts @@ -17,7 +17,7 @@ */ // eslint-disable-next-line path-alias/no-relative -import { filters, find, findByProps } from "../webpack"; +import { filters, find, findByProps } from "../api"; export let useState: typeof React.useState; export let useEffect: typeof React.useEffect; diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index 28acafd78..b612b08c5 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -17,7 +17,7 @@ */ // eslint-disable-next-line path-alias/no-relative -import { findByCode, findByProps, findStore } from "../webpack"; +import { findByCode, findByProps, findStore } from "../api"; import * as t from "./types/stores"; export const Flux = findByProps("connectStores"); diff --git a/src/webpack/common/userSettings.ts b/src/webpack/common/userSettings.ts index 6137a06f2..4f908dad0 100644 --- a/src/webpack/common/userSettings.ts +++ b/src/webpack/common/userSettings.ts @@ -5,7 +5,7 @@ */ // eslint-disable-next-line path-alias/no-relative -import { find } from "../webpack"; +import { find } from "../api"; export const UserSettingsActionCreators = { FrecencyUserSettingsActionCreators: find(m => m.ProtoClass?.typeName?.endsWith(".FrecencyUserSettings")), diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index 234647eab..c15269fd9 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -20,7 +20,7 @@ import { canonicalizeMatch } from "@utils/patches"; import { Channel } from "discord-types/general"; // eslint-disable-next-line path-alias/no-relative -import { _resolveDiscordLoaded, filters, find, findByCode, findByProps, mapMangledModule, waitFor } from "../webpack"; +import { _resolveDiscordLoaded, filters, find, findByCode, findByProps, mapMangledModule, waitFor } from "../api"; import type * as t from "./types/utils"; export const FluxDispatcher = find(filters.byProps("dispatch", "subscribe"), (m: t.FluxDispatcher) => { diff --git a/src/webpack/index.ts b/src/webpack/index.ts index 036c2a3fc..5ae449e5c 100644 --- a/src/webpack/index.ts +++ b/src/webpack/index.ts @@ -16,5 +16,5 @@ * along with this program. If not, see . */ +export * from "./api"; export * as Common from "./common"; -export * from "./webpack"; diff --git a/tsconfig.json b/tsconfig.json index 8db0ab3c1..b0b4ef5bf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,7 +28,7 @@ "@shared/*": ["./shared/*"], "@webpack/types": ["./webpack/common/types"], "@webpack/common": ["./webpack/common"], - "@webpack": ["./webpack/webpack"] + "@webpack": ["./webpack/api"] }, "plugins": [