···
const moduleCache: Record<string, string> = {};
const patched: Record<string, Array<string>> = {};
69
-
function patchModules(entry: WebpackJsonpEntry[1]) {
70
-
function patchModule(id: string, patchId: string, replaced: string) {
71
-
// Store what extensions patched what modules for easier debugging
72
-
patched[id] = patched[id] || [];
73
-
patched[id].push(patchId);
69
+
function createSourceURL(id: string) {
70
+
const remapped = Object.entries(moonlight.moonmap.modules).find((m) => m[1] === id)?.[0];
73
+
return `// Webpack Module: ${id}\n//# sourceURL=${remapped}`;
76
+
return `//# sourceURL=Webpack-Module/${id.slice(0, 3)}/${id}`;
79
+
function patchModule(id: string, patchId: string, replaced: string, entry: WebpackJsonpEntry[1]) {
80
+
// Store what extensions patched what modules for easier debugging
81
+
patched[id] = patched[id] ?? [];
82
+
patched[id].push(patchId);
75
-
// Webpack module arguments are minified, so we replace them with consistent names
76
-
// We have to wrap it so things don't break, though
77
-
const patchedStr = patched[id].sort().join(", ");
84
+
// Webpack module arguments are minified, so we replace them with consistent names
85
+
// We have to wrap it so things don't break, though
86
+
const patchedStr = patched[id].sort().join(", ");
80
-
`(${replaced}).apply(this, arguments)\n` +
81
-
`// Patched by moonlight: ${patchedStr}\n` +
82
-
`//# sourceURL=Webpack-Module/${id.slice(0, 3)}/${id}`;
89
+
`(${replaced}).apply(this, arguments)\n` + `// Patched by moonlight: ${patchedStr}\n` + createSourceURL(id);
85
-
const func = new Function("module", "exports", "require", wrapped) as WebpackModuleFunc;
87
-
entry[id].__moonlight = true;
90
-
logger.warn("Error constructing function for patch", patchId, e);
92
+
const func = new Function("module", "exports", "require", wrapped) as WebpackModuleFunc;
94
+
entry[id].__moonlight = true;
97
+
logger.warn("Error constructing function for patch", patchId, e);
103
+
function patchModules(entry: WebpackJsonpEntry[1]) {
// Populate the module cache
for (const [id, func] of Object.entries(entry)) {
if (!Object.hasOwn(moduleCache, id) && func.__moonlight !== true) {
···
188
-
if (!swappedModule) patchModule(id, patchedStr.join(", "), moduleString);
196
+
if (!swappedModule) patchModule(id, patchedStr.join(", "), moduleString, entry);
moduleCache[id] = moduleString;
moonlight.patched.set(id, exts);
···
const parsed = moonlight.lunast.parseScript(id, moduleString);
for (const [parsedId, parsedScript] of Object.entries(parsed)) {
197
-
if (patchModule(parsedId, "lunast", parsedScript)) {
205
+
if (patchModule(parsedId, "lunast", parsedScript, entry)) {
moduleCache[parsedId] = parsedScript;
···
if (moonlightNode.config.patchAll === true) {
if ((typeof id !== "string" || !id.includes("_")) && !entry[id].__moonlight) {
209
-
`(${moduleCache[id]}).apply(this, arguments)\n` + `//# sourceURL=Webpack-Module/${id.slice(0, 3)}/${id}`;
216
+
const wrapped = `(${moduleCache[id]}).apply(this, arguments)\n` + createSourceURL(id);
entry[id] = new Function("module", "exports", "require", wrapped) as WebpackModuleFunc;
entry[id].__moonlight = true;
···
for (const [name, func] of Object.entries(moonlight.moonmap.getWebpackModules("window.moonlight.moonmap"))) {
339
+
// @ts-expect-error probably should fix the type on this idk
340
+
func.__moonlight = true;
injectedWpModules.push({ id: name, run: func });