diff options
author | Vendicated <vendicated@riseup.net> | 2022-09-16 21:43:38 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-09-16 21:43:38 +0200 |
commit | 204ce6758a4d03eb4cb2b5535833f4d34e2014a4 (patch) | |
tree | b304d0ec87ccb9f78a850d1df8859f8ad5a597f6 /src/webpack/webpack.ts | |
parent | 37e81c017e3b1fc47a58efcec02baafdc8d121ab (diff) | |
download | Vencord-204ce6758a4d03eb4cb2b5535833f4d34e2014a4.tar.gz Vencord-204ce6758a4d03eb4cb2b5535833f4d34e2014a4.tar.bz2 Vencord-204ce6758a4d03eb4cb2b5535833f4d34e2014a4.zip |
Add Webpack.search and Webpack.extract
Diffstat (limited to 'src/webpack/webpack.ts')
-rw-r--r-- | src/webpack/webpack.ts | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 4f86eef..7e1c3e6 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -54,8 +54,6 @@ export function findAll(filter: FilterFn, getDefault = true) { return ret; } - - export function findByProps(...props: string[]) { return find(filters.byProps(props)); } @@ -85,4 +83,51 @@ export function addListener(callback: CallbackFn) { export function removeListener(callback: CallbackFn) { listeners.delete(callback); +} + +/** + * Search modules by keyword. This searches the factory methods, + * meaning you can search all sorts of things, displayName, 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 = {} as Record<number, Function>; + const factories = wreq.m; + outer: + for (const id in factories) { + const factory = factories[id]; + const str: string = factory.toString(); + for (const filter of filters) { + if (typeof filter === "string" && !str.includes(filter)) continue outer; + if (filter instanceof RegExp && !filter.test(str)) continue outer; + } + results[id] = factory; + } + + return results; +} + +/** + * Extract a specific module by id into its own webpack chunk. 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: number) { + const mod = wreq.m[id] as Function; + if (!mod) return null; + + const code = ` +// [EXTRACTED] WebpackModule${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!! + +${mod.toString()} +//# sourceURL=ExtractedWebpackModule${id} +`; + const extracted = (0, eval)(code); + return extracted as Function; }
\ No newline at end of file |