diff --git a/src/debug/runReporter.ts b/src/debug/runReporter.ts index 2c6563b6d..70a244f43 100644 --- a/src/debug/runReporter.ts +++ b/src/debug/runReporter.ts @@ -7,6 +7,7 @@ import { Logger } from "@utils/Logger"; import * as Webpack from "@webpack"; import { patches } from "plugins"; +import { initWs } from "plugins/devCompanion.dev/initWs"; import { loadLazyChunks } from "./loadLazyChunks"; import { reporterData } from "./reporterData"; @@ -78,11 +79,13 @@ async function runReporter() { } } + // if we are running the reporter with companion integration, send the list to vscode as soon as we can + if(IS_COMPANION_TEST) + initWs(); ReporterLogger.log("Finished test"); } catch (e) { ReporterLogger.log("A fatal error occurred:", e); } - console.log(reporterData); } // imported in webpack for reporterData, wrap to avoid running reporter diff --git a/src/plugins/devCompanion.dev/index.tsx b/src/plugins/devCompanion.dev/index.tsx index 6e9a287d1..22a10dba0 100644 --- a/src/plugins/devCompanion.dev/index.tsx +++ b/src/plugins/devCompanion.dev/index.tsx @@ -20,7 +20,6 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; -import { reporterData } from "debug/reporterData"; import { initWs, socket, stopWs } from "./initWs"; console.log("imported"); @@ -58,9 +57,9 @@ export default definePlugin({ }, start() { - console.log(123); - console.log(reporterData); - initWs(); + // if were running the reporter, we need to initws in the reporter file to avoid a race condition + if (!IS_COMPANION_TEST) + initWs(); }, stop: stopWs, diff --git a/src/plugins/devCompanion.dev/initWs.tsx b/src/plugins/devCompanion.dev/initWs.tsx index 000c79b1f..a99c168c3 100644 --- a/src/plugins/devCompanion.dev/initWs.tsx +++ b/src/plugins/devCompanion.dev/initWs.tsx @@ -6,7 +6,6 @@ import { showNotification } from "@api/Notifications"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; -import { Patch } from "@utils/types"; import { filters, findAll, search, wreq } from "@webpack"; import { reporterData } from "debug/reporterData"; @@ -40,29 +39,19 @@ export function initWs(isManual = false) { data: Object.keys(wreq.m), ok: true, }); - // if we are running the reporter with companion integration, send the list to vscode as soon as we can + if (IS_COMPANION_TEST) { - const toSend = reporterData; - for (const i in toSend.failedPatches) { - for (const j in toSend.failedPatches[i]) { - const patch: Patch = toSend.failedPatches[i][j]; - if (patch.find instanceof RegExp) - patch.find = String(patch.find); - if (!Array.isArray(patch.replacement)) - patch.replacement = [patch.replacement]; - patch.replacement = patch.replacement.map(v => { - return { - match: String(v.match), - replace: String(v.replace) - }; - }); - } - } - replyData({ - type: "report", - data: toSend, - ok: true + const toSend = JSON.stringify(reporterData, (_k, v) => { + if (v instanceof RegExp) + return String(v); + return v; }); + + socket?.send(JSON.stringify({ + type: "report", + data: JSON.parse(toSend), + ok: true + })); }