1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-28 18:26:23 +00:00
Vencord/src/debug/runReporter.ts

85 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-06-01 02:28:58 +00:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Logger } from "@utils/Logger";
import * as Webpack from "@webpack";
import { patches } from "plugins";
2024-06-01 21:39:01 +00:00
import { loadLazyChunks } from "./loadLazyChunks";
2024-06-01 02:28:58 +00:00
const ReporterLogger = new Logger("Reporter");
async function runReporter() {
try {
2024-06-01 21:39:01 +00:00
ReporterLogger.log("Starting test...");
2024-06-01 02:28:58 +00:00
2024-06-01 21:39:01 +00:00
let loadLazyChunksResolve: (value: void | PromiseLike<void>) => void;
const loadLazyChunksDone = new Promise<void>(r => loadLazyChunksResolve = r);
2024-06-01 02:28:58 +00:00
2024-06-01 21:39:01 +00:00
Webpack.beforeInitListeners.add(() => loadLazyChunks().then((loadLazyChunksResolve)));
await loadLazyChunksDone;
2024-06-01 02:28:58 +00:00
for (const patch of patches) {
if (!patch.all) {
new Logger("WebpackInterceptor").warn(`Patch by ${patch.plugin} found no module (Module id is -): ${patch.find}`);
}
}
for (const [searchType, args] of Webpack.lazyWebpackSearchHistory) {
let method = searchType;
if (searchType === "findComponent") method = "find";
if (searchType === "findExportedComponent") method = "findByProps";
if (searchType === "waitFor" || searchType === "waitForComponent") {
if (typeof args[0] === "string") method = "findByProps";
else method = "find";
}
if (searchType === "waitForStore") method = "findStore";
2024-06-20 04:00:07 +00:00
let result: any;
2024-06-01 02:28:58 +00:00
try {
if (method === "proxyLazyWebpack" || method === "LazyComponentWebpack") {
const [factory] = args;
result = factory();
} else if (method === "extractAndLoadChunks") {
const [code, matcher] = args;
result = await Webpack.extractAndLoadChunks(code, matcher);
if (result === false) result = null;
2024-06-20 04:00:07 +00:00
} else if (method === "mapMangledModule") {
const [code, mapper] = args;
result = Webpack.mapMangledModule(code, mapper);
if (Object.keys(result).length !== Object.keys(mapper).length) throw new Error("Webpack Find Fail");
2024-06-01 02:28:58 +00:00
} else {
// @ts-ignore
result = Webpack[method](...args);
}
2024-06-20 04:00:07 +00:00
if (result == null || (result.$$vencordInternal != null && result.$$vencordInternal() == null)) throw new Error("Webpack Find Fail");
2024-06-01 02:28:58 +00:00
} catch (e) {
let logMessage = searchType;
if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${args[0].toString().slice(0, 147)}...)`;
else if (method === "extractAndLoadChunks") logMessage += `([${args[0].map(arg => `"${arg}"`).join(", ")}], ${args[1].toString()})`;
2024-06-20 04:00:07 +00:00
else if (method === "mapMangledModule") {
const failedMappings = Object.keys(args[1]).filter(key => result?.[key] == null);
logMessage += `("${args[0]}", {\n${failedMappings.map(mapping => `\t${mapping}: ${args[1][mapping].toString().slice(0, 147)}...`).join(",\n")}\n})`;
}
2024-06-01 02:28:58 +00:00
else logMessage += `(${args.map(arg => `"${arg}"`).join(", ")})`;
ReporterLogger.log("Webpack Find Fail:", logMessage);
}
}
ReporterLogger.log("Finished test");
} catch (e) {
ReporterLogger.log("A fatal error occurred:", e);
}
}
runReporter();