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
···
export function registerPatch(patch: IdentifiedPatch) {
patches.push(patch);
+
moonlight.unpatched.add(patch);
}
export function registerWebpackModule(wp: IdentifiedWebpackModule) {
webpackModules.add(wp);
+
if (wp.dependencies?.length) {
+
moonlight.pendingModules.add(wp);
+
}
}
/*
···
for (const [_modId, mod] of Object.entries(entry)) {
const modStr = mod.toString();
-
const wpModules = Array.from(webpackModules.values());
-
for (const wpModule of wpModules) {
+
for (const wpModule of webpackModules) {
const id = wpModule.ext + "_" + wpModule.id;
if (wpModule.dependencies) {
const deps = new Set(wpModule.dependencies);
···
// FIXME: This dependency resolution might fail if the things we want
// got injected earlier. If weird dependencies fail, this is likely why.
if (deps.size) {
-
for (const dep of deps.values()) {
+
for (const dep of deps) {
if (typeof dep === "string") {
if (modStr.includes(dep)) deps.delete(dep);
} else if (dep instanceof RegExp) {
···
}
if (deps.size !== 0) {
-
// Update the deps that have passed
-
webpackModules.delete(wpModule);
wpModule.dependencies = Array.from(deps);
-
webpackModules.add(wpModule);
continue;
}
···
}
webpackModules.delete(wpModule);
+
moonlight.pendingModules.delete(wpModule);
injectedWpModules.push(wpModule);
inject = true;
-
if (wpModule.run) modules[id] = wpModule.run;
+
if (wpModule.run) {
+
modules[id] = wpModule.run;
+
wpModule.run.__moonlight = true;
+
}
if (wpModule.entrypoint) entrypoints.push(id);
}
if (!webpackModules.size) break;
+2
packages/types/src/globals.ts
···
import {
DetectedExtension,
IdentifiedPatch,
+
IdentifiedWebpackModule,
ProcessedExtensions
} from "./extension";
import EventEmitter from "events";
···
export type MoonlightWeb = {
unpatched: Set<IdentifiedPatch>;
+
pendingModules: Set<IdentifiedWebpackModule>;
enabledExtensions: Set<string>;
getConfig: (ext: string) => ConfigExtension["config"];
+1
packages/web-preload/src/index.ts
···
window.moonlight = {
unpatched: new Set(),
+
pendingModules: new Set(),
enabledExtensions: new Set(),
getConfig: moonlightNode.getConfig.bind(moonlightNode),