Merge branch 'immediate-finds' into immediate-finds-modules-proxy

This commit is contained in:
Nuckyz 2024-06-22 02:39:26 -03:00
commit 9c21c23364
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
10 changed files with 58 additions and 58 deletions

View file

@ -794,6 +794,55 @@ export function extractAndLoadChunksLazy(code: string | string[], matcher: RegEx
return extractAndLoadChunks; 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<string | RegExp>) {
const results: WebpackRequire["m"] = {};
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];
if (!factory) return null;
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: ModuleFactory = (0, eval)(code);
return extracted;
}
function deprecatedRedirect<T extends (...args: any[]) => any>(oldMethod: string, newMethod: string, redirect: T): T { function deprecatedRedirect<T extends (...args: any[]) => any>(oldMethod: string, newMethod: string, redirect: T): T {
return ((...args: Parameters<T>) => { return ((...args: Parameters<T>) => {
logger.warn(`Method ${oldMethod} is deprecated. Use ${newMethod} instead. For more information read https://github.com/Vendicated/Vencord/pull/2409#issue-2277161516`); logger.warn(`Method ${oldMethod} is deprecated. Use ${newMethod} instead. For more information read https://github.com/Vendicated/Vencord/pull/2409#issue-2277161516`);
@ -920,52 +969,3 @@ export const findBulk = deprecatedRedirect("findBulk", "cacheFindBulk", cacheFin
* @returns string or null * @returns string or null
*/ */
export const findModuleId = deprecatedRedirect("findModuleId", "cacheFindModuleId", cacheFindModuleId); 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<string | RegExp>) {
const results: WebpackRequire["m"] = {};
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];
if (!factory) return null;
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: ModuleFactory = (0, eval)(code);
return extracted;
}

View file

@ -17,7 +17,7 @@
*/ */
// eslint-disable-next-line path-alias/no-relative // eslint-disable-next-line path-alias/no-relative
import { find, findByProps } from "../webpack"; import { find, findByProps } from "../api";
import * as t from "./types/classes"; import * as t from "./types/classes";
export const ModalImageClasses = find<t.ImageModalClasses>(m => m.image && m.modal && !m.applicationIcon); export const ModalImageClasses = find<t.ImageModalClasses>(m => m.image && m.modal && !m.applicationIcon);

View file

@ -19,7 +19,7 @@
import { NoopComponent } from "@utils/react"; import { NoopComponent } from "@utils/react";
// eslint-disable-next-line path-alias/no-relative // 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"; import * as t from "./types/components";
export let Card: t.Card = NoopComponent as any; export let Card: t.Card = NoopComponent as any;

View file

@ -17,7 +17,7 @@
*/ */
// eslint-disable-next-line path-alias/no-relative // 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"; import type * as t from "./types/menu";
export const Menu = findByProps<t.Menu>("MenuItem", "MenuSliderControl"); export const Menu = findByProps<t.Menu>("MenuItem", "MenuSliderControl");

View file

@ -17,7 +17,7 @@
*/ */
// eslint-disable-next-line path-alias/no-relative // 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 useState: typeof React.useState;
export let useEffect: typeof React.useEffect; export let useEffect: typeof React.useEffect;

View file

@ -17,7 +17,7 @@
*/ */
// eslint-disable-next-line path-alias/no-relative // 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"; import * as t from "./types/stores";
export const Flux = findByProps<t.Flux>("connectStores"); export const Flux = findByProps<t.Flux>("connectStores");

View file

@ -5,7 +5,7 @@
*/ */
// eslint-disable-next-line path-alias/no-relative // eslint-disable-next-line path-alias/no-relative
import { find } from "../webpack"; import { find } from "../api";
export const UserSettingsActionCreators = { export const UserSettingsActionCreators = {
FrecencyUserSettingsActionCreators: find(m => m.ProtoClass?.typeName?.endsWith(".FrecencyUserSettings")), FrecencyUserSettingsActionCreators: find(m => m.ProtoClass?.typeName?.endsWith(".FrecencyUserSettings")),

View file

@ -20,7 +20,7 @@ import { canonicalizeMatch } from "@utils/patches";
import { Channel } from "discord-types/general"; import { Channel } from "discord-types/general";
// eslint-disable-next-line path-alias/no-relative // 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"; import type * as t from "./types/utils";
export const FluxDispatcher = find<t.FluxDispatcher>(filters.byProps("dispatch", "subscribe"), (m: t.FluxDispatcher) => { export const FluxDispatcher = find<t.FluxDispatcher>(filters.byProps("dispatch", "subscribe"), (m: t.FluxDispatcher) => {

View file

@ -16,6 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
export * from "./api";
export * as Common from "./common"; export * as Common from "./common";
export * from "./webpack";
export * from "./wreq.d"; export * from "./wreq.d";

View file

@ -28,7 +28,7 @@
"@shared/*": ["./shared/*"], "@shared/*": ["./shared/*"],
"@webpack/types": ["./webpack/common/types"], "@webpack/types": ["./webpack/common/types"],
"@webpack/common": ["./webpack/common"], "@webpack/common": ["./webpack/common"],
"@webpack": ["./webpack/webpack"] "@webpack": ["./webpack/api"]
}, },
"plugins": [ "plugins": [