fix: Adapt to change of window.modules being a Map

closes #120
This commit is contained in:
pylixonly 2025-01-11 19:40:22 +08:00
parent 87cfc742f6
commit 78c303b5f5
2 changed files with 8 additions and 1 deletions

View file

@ -66,6 +66,11 @@ if (typeof globalThis.__r !== "undefined") {
_requireFunc = function patchedRequire(a: number) {
// Initializing index.ts(x)
if (a === 0) {
// https://github.com/facebook/metro/commit/1361405ffe6f1bdef54295addfef0f30523aaab2
if (window.modules instanceof Map) {
window.modules = Object.fromEntries([...window.modules]);
}
onceIndexRequired(v);
_requireFunc = v;
} else return v(a);

View file

@ -6,7 +6,9 @@ import { ModuleFlags, ModulesMapInternal } from "./enums";
const { before, instead } = require("spitroast");
export const metroModules: Metro.ModuleList = window.modules;
const metroRequire: Metro.Require = window.__r;
// Since modules registry is now a Map, the id is now strictly a number
// Making the codebase to adapt to this change would be more ideal, though
const metroRequire = (id: number | string) => window.__r(+id);
// eslint-disable-next-line func-call-spacing
const moduleSubscriptions = new Map<number, Set<() => void>>();