Skip to content

Commit bdf123f

Browse files
committed
fix: use basic es6
1 parent 4fb0489 commit bdf123f

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

packages/runtime/assets/harness-module-system.js

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
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;
@@ -52,40 +52,22 @@
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
@@ -109,7 +91,7 @@
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
@@ -122,7 +104,7 @@
122104
newMod.isInitialized = false;
123105
modules.set(moduleId, newMod);
124106
}
125-
}
107+
});
126108
}
127109
}
128110
};
@@ -134,4 +116,4 @@
134116
: typeof window !== 'undefined'
135117
? window
136118
: this
137-
);
119+
);

0 commit comments

Comments
 (0)