fix serialization and race cond

This commit is contained in:
sadan 2024-08-23 13:25:13 -04:00
parent d188a93a6c
commit c365c86a49
No known key found for this signature in database
3 changed files with 18 additions and 27 deletions

View file

@ -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

View file

@ -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,

View file

@ -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
}));
}