this repo has no description

Unbreak webpack module dependency resolving

Changed files
+14 -7
packages
core
src
types
web-preload
src
+11 -7
packages/core/src/patch.ts
··· 20 20 21 21 export function registerPatch(patch: IdentifiedPatch) { 22 22 patches.push(patch); 23 + moonlight.unpatched.add(patch); 23 24 } 24 25 25 26 export function registerWebpackModule(wp: IdentifiedWebpackModule) { 26 27 webpackModules.add(wp); 28 + if (wp.dependencies?.length) { 29 + moonlight.pendingModules.add(wp); 30 + } 27 31 } 28 32 29 33 /* ··· 206 210 207 211 for (const [_modId, mod] of Object.entries(entry)) { 208 212 const modStr = mod.toString(); 209 - const wpModules = Array.from(webpackModules.values()); 210 - for (const wpModule of wpModules) { 213 + for (const wpModule of webpackModules) { 211 214 const id = wpModule.ext + "_" + wpModule.id; 212 215 if (wpModule.dependencies) { 213 216 const deps = new Set(wpModule.dependencies); ··· 215 218 // FIXME: This dependency resolution might fail if the things we want 216 219 // got injected earlier. If weird dependencies fail, this is likely why. 217 220 if (deps.size) { 218 - for (const dep of deps.values()) { 221 + for (const dep of deps) { 219 222 if (typeof dep === "string") { 220 223 if (modStr.includes(dep)) deps.delete(dep); 221 224 } else if (dep instanceof RegExp) { ··· 230 233 } 231 234 232 235 if (deps.size !== 0) { 233 - // Update the deps that have passed 234 - webpackModules.delete(wpModule); 235 236 wpModule.dependencies = Array.from(deps); 236 - webpackModules.add(wpModule); 237 237 continue; 238 238 } 239 239 ··· 242 242 } 243 243 244 244 webpackModules.delete(wpModule); 245 + moonlight.pendingModules.delete(wpModule); 245 246 injectedWpModules.push(wpModule); 246 247 247 248 inject = true; 248 249 249 - if (wpModule.run) modules[id] = wpModule.run; 250 + if (wpModule.run) { 251 + modules[id] = wpModule.run; 252 + wpModule.run.__moonlight = true; 253 + } 250 254 if (wpModule.entrypoint) entrypoints.push(id); 251 255 } 252 256 if (!webpackModules.size) break;
+2
packages/types/src/globals.ts
··· 3 3 import { 4 4 DetectedExtension, 5 5 IdentifiedPatch, 6 + IdentifiedWebpackModule, 6 7 ProcessedExtensions 7 8 } from "./extension"; 8 9 import EventEmitter from "events"; ··· 36 37 37 38 export type MoonlightWeb = { 38 39 unpatched: Set<IdentifiedPatch>; 40 + pendingModules: Set<IdentifiedWebpackModule>; 39 41 enabledExtensions: Set<string>; 40 42 41 43 getConfig: (ext: string) => ConfigExtension["config"];
+1
packages/web-preload/src/index.ts
··· 8 8 9 9 window.moonlight = { 10 10 unpatched: new Set(), 11 + pendingModules: new Set(), 11 12 enabledExtensions: new Set(), 12 13 13 14 getConfig: moonlightNode.getConfig.bind(moonlightNode),