Fix Dev Companion

This commit is contained in:
thororen1234 2025-02-08 13:37:56 -05:00
parent 63821c1468
commit cb6a8502fd
8 changed files with 55 additions and 37 deletions

View file

@ -9,27 +9,20 @@ import { Settings } from "@api/Settings";
import { canonicalizeMatch } from "@utils/patches";
import { CodeFilter, stringMatches, wreq } from "@webpack";
import { Toasts } from "@webpack/common";
import { AnyWebpackRequire } from "webpack";
import { getFactoryPatchedSource, getOriginalFactory } from "@webpack/utils";
import { settings as companionSettings } from ".";
import { Recieve } from "./types";
const SYM_PATCHED_SOURCE = Symbol("WebpackPatcher.patchedSource");
function getFactoryPatchedSource(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) {
return webpackRequire.m[id]?.[SYM_PATCHED_SOURCE];
}
/**
* extracts the patched module, if there is no patched module, throws an error
* @param id module id
*/
export function extractOrThrow(id: number): string {
const module = wreq.m[id];
const patchedSource = getFactoryPatchedSource(id);
if (!patchedSource)
const module = getFactoryPatchedSource(id);
if (!module)
throw new Error("No patched module found for module id " + id);
return patchedSource;
return module;
}
/**
@ -41,12 +34,11 @@ export function extractOrThrow(id: number): string {
* @param patched return the patched module
*/
export function extractModule(id: number, patched = companionSettings.store.usePatchedModule): string {
const module = wreq.m[id];
if (!module)
throw new Error("No module found for module id:" + id);
const original = module.toString();
const patchedSource = getFactoryPatchedSource(id);
return patched ? patchedSource ?? original : original;
const original = getOriginalFactory(id);
if (patched && !patchedSource || !original)
throw new Error("No module found for module id: " + id);
return patched ? patchedSource ?? original.toString() : original.toString();
}
export function parseNode(node: Recieve.FindNode): any {