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