···7474 }
7575 }
76767777+ // Populate the module cache
7878+ for (const [id, func] of Object.entries(entry)) {
7979+ if (!Object.hasOwn(moduleCache, id) && func.__moonlight !== true) {
8080+ moduleCache[id] = func.toString().replace(/\n/g, "");
8181+ }
8282+ }
8383+7784 for (const [id, func] of Object.entries(entry)) {
7885 if (func.__moonlight === true) continue;
7979- let moduleString = Object.hasOwn(moduleCache, id)
8080- ? moduleCache[id]
8181- : func.toString().replace(/\n/g, "");
8686+ let moduleString = moduleCache[id];
82878388 for (let i = 0; i < patches.length; i++) {
8489 const patch = patches[i];
···151156 }
152157 }
153158159159+ moduleCache[id] = moduleString;
160160+154161 try {
155155- let parsed = moonlight.lunast.parseScript(id, `(\n${moduleString}\n)`);
162162+ const parsed = moonlight.lunast.parseScript(id, moduleString);
156163 if (parsed != null) {
157157- // parseScript adds an extra ; for some reason
158158- parsed = parsed.trimEnd().substring(0, parsed.lastIndexOf(";"));
159159- if (patchModule(id, "lunast", parsed)) {
160160- moduleString = parsed;
164164+ for (const [parsedId, parsedScript] of Object.entries(parsed)) {
165165+ // parseScript adds an extra ; for some reason
166166+ const fixedScript = parsedScript
167167+ .trimEnd()
168168+ .substring(0, parsedScript.lastIndexOf(";"));
169169+170170+ if (patchModule(parsedId, "lunast", fixedScript)) {
171171+ moduleCache[parsedId] = fixedScript;
172172+ }
161173 }
162174 }
163175 } catch (e) {
···170182 !entry[id].__moonlight
171183 ) {
172184 const wrapped =
173173- `(${moduleString}).apply(this, arguments)\n` +
185185+ `(${moduleCache[id]}).apply(this, arguments)\n` +
174186 `//# sourceURL=Webpack-Module-${id}`;
175187 entry[id] = new Function(
176188 "module",
···181193 entry[id].__moonlight = true;
182194 }
183195 }
184184-185185- moduleCache[id] = moduleString;
186196 }
187197}
188198···302312*/
303313export async function installWebpackPatcher() {
304314 await handleModuleDependencies();
315315+316316+ moonlight.lunast.setModuleSourceGetter((id) => {
317317+ return moduleCache[id] ?? null;
318318+ });
305319306320 let realWebpackJsonp: WebpackJsonp | null = null;
307321 Object.defineProperty(window, "webpackChunkdiscord_app", {
+1-1
packages/lunast/README.md
···114114115115Not really. LunAST runs in roughly ~10ms on [my](https://github.com/NotNite) machine, with filtering for what modules to parse. Parsing every module takes only a second. There are future plans to cache and parallelize the process, so that load times are only slow once.
116116117117-You can measure how long LunAST took to process with the `moonlight.lunast.elapsed` variable
117117+You can measure how long LunAST took to process with the `moonlight.lunast.elapsed` variable.
118118119119### Does this mean patches are dead?
120120