2020 // Create a wrapped factory
2121 const wrappedFactory = function ( ...args ) {
2222 // 1. Your Custom Require
23- const myRequire = ( id ) => {
23+ const myRequire = function ( id ) {
2424 // Logic to capture/redirect the require
2525 // globalObject.__r is the global require function from Metro
2626 // @ts -ignore
2727 return globalObject . __r ( id ) ;
2828 } ;
2929
3030 // 2. Custom importDefault (MUST use myRequire)
31- const myImportDefault = ( id ) => {
31+ const myImportDefault = function ( id ) {
3232 const mod = myRequire ( id ) ;
3333 return mod && mod . __esModule ? mod . default : mod ;
3434 } ;
3535
3636 // 3. Custom importAll (MUST use myRequire)
37- const myImportAll = ( id ) => {
37+ const myImportAll = function ( id ) {
3838 const mod = myRequire ( id ) ;
3939 if ( mod && mod . __esModule ) {
4040 return mod ;
5252 return result ;
5353 } ;
5454
55- if ( args . length >= 7 ) {
56- // Standard Metro with import support (7 arguments)
57- // args: global, require, importDefault, importAll, module, exports, dependencyMap
58- const [
59- global ,
60- _require ,
61- _importDefault ,
62- _importAll ,
63- moduleObject ,
64- exports ,
65- dependencyMap ,
66- ] = args ;
55+ // Standard Metro with import support (7 arguments)
56+ // args: global, require, importDefault, importAll, module, exports, dependencyMap
57+ const global = args [ 0 ] ;
58+ const moduleObject = args [ 4 ] ;
59+ const exports = args [ 5 ] ;
60+ const depMap = args [ 6 ] ;
6761
68- return factory (
69- global ,
70- myRequire ,
71- myImportDefault ,
72- myImportAll ,
73- moduleObject ,
74- exports ,
75- dependencyMap
76- ) ;
77- } else if ( args . length === 4 ) {
78- // Legacy Metro or CommonJS only (4 arguments)
79- // args: global, require, module, exports
80- const [ global , _require , moduleObject , exports ] = args ;
81-
82- return factory ( global , myRequire , moduleObject , exports ) ;
83- } else {
84- // Unknown signature, try to patch the second argument (require) and hope for the best
85- // This is a fallback
86- args [ 1 ] = myRequire ;
87- return factory . apply ( this , args ) ;
88- }
62+ return factory (
63+ global ,
64+ myRequire ,
65+ myImportDefault ,
66+ myImportAll ,
67+ moduleObject ,
68+ exports ,
69+ depMap
70+ ) ;
8971 } ;
9072
9173 // Call the original define with the wrapped factory
10991 if ( globalObject . __r && globalObject . __r . getModules ) {
11092 const modules = globalObject . __r . getModules ( ) ;
11193 if ( modules ) {
112- for ( const [ moduleId , mod ] of modules ) {
94+ modules . forEach ( function ( mod , moduleId ) {
11395 if ( mod ) {
11496 // We need to create a new object to ensure that the module is re-evaluated
11597 // Mutating existing module directly might not work as expected in some cases
122104 newMod . isInitialized = false ;
123105 modules . set ( moduleId , newMod ) ;
124106 }
125- }
107+ } ) ;
126108 }
127109 }
128110 } ;
134116 : typeof window !== 'undefined'
135117 ? window
136118 : this
137- ) ;
119+ ) ;
0 commit comments