Skip to content

Commit

Permalink
fix: Adapt to change of window.modules being a Map
Browse files Browse the repository at this point in the history
closes #120
  • Loading branch information
pylixonly committed Jan 14, 2025
1 parent 87cfc74 commit 78c303b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/metro/internals/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>>();
Expand Down

1 comment on commit 78c303b

@mero-neh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I DONT GET IT- how i get the code?

Please sign in to comment.