metro-runtime 0.80.8 → 0.80.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/modules/asyncRequire.js +18 -12
- package/src/modules/asyncRequire.js.flow +32 -17
- package/src/polyfills/require.js +40 -36
- package/src/polyfills/require.js.flow +49 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-runtime",
|
|
3
|
-
"version": "0.80.
|
|
3
|
+
"version": "0.80.10",
|
|
4
4
|
"description": "🚇 Module required for evaluating Metro bundles.",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"repository": {
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "^7.0.0"
|
|
16
|
+
"@babel/runtime": "^7.0.0",
|
|
17
|
+
"flow-enums-runtime": "^0.0.6"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@babel/core": "^7.20.0",
|
|
20
|
-
"react": "
|
|
21
|
+
"react": "19.0.0-rc-fb9a90fa48-20240614",
|
|
21
22
|
"react-refresh": "^0.14.0",
|
|
22
|
-
"react-test-renderer": "
|
|
23
|
+
"react-test-renderer": "19.0.0-rc-fb9a90fa48-20240614"
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
26
|
"node": ">=18"
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
isPrefetchOnly: false,
|
|
5
|
-
};
|
|
6
|
-
async function asyncRequireImpl(moduleID, paths, options) {
|
|
3
|
+
function maybeLoadBundle(moduleID, paths) {
|
|
7
4
|
const loadBundle = global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`];
|
|
8
5
|
if (loadBundle != null) {
|
|
9
6
|
const stringModuleID = String(moduleID);
|
|
10
7
|
if (paths != null) {
|
|
11
8
|
const bundlePath = paths[stringModuleID];
|
|
12
9
|
if (bundlePath != null) {
|
|
13
|
-
|
|
10
|
+
return loadBundle(bundlePath);
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
if (!options.isPrefetchOnly) {
|
|
18
|
-
return require.importAll(moduleID);
|
|
19
|
-
}
|
|
20
14
|
return undefined;
|
|
21
15
|
}
|
|
16
|
+
function asyncRequireImpl(moduleID, paths) {
|
|
17
|
+
const maybeLoadBundlePromise = maybeLoadBundle(moduleID, paths);
|
|
18
|
+
const importAll = () => require.importAll(moduleID);
|
|
19
|
+
if (maybeLoadBundlePromise != null) {
|
|
20
|
+
return maybeLoadBundlePromise.then(importAll);
|
|
21
|
+
}
|
|
22
|
+
return importAll();
|
|
23
|
+
}
|
|
22
24
|
async function asyncRequire(moduleID, paths, moduleName) {
|
|
23
|
-
return asyncRequireImpl(moduleID, paths
|
|
25
|
+
return asyncRequireImpl(moduleID, paths);
|
|
24
26
|
}
|
|
27
|
+
asyncRequire.unstable_importMaybeSync = function unstable_importMaybeSync(
|
|
28
|
+
moduleID,
|
|
29
|
+
paths
|
|
30
|
+
) {
|
|
31
|
+
return asyncRequireImpl(moduleID, paths);
|
|
32
|
+
};
|
|
25
33
|
asyncRequire.prefetch = function (moduleID, paths, moduleName) {
|
|
26
|
-
|
|
27
|
-
isPrefetchOnly: true,
|
|
28
|
-
}).then(
|
|
34
|
+
maybeLoadBundle(moduleID, paths)?.then(
|
|
29
35
|
() => {},
|
|
30
36
|
() => {}
|
|
31
37
|
);
|
|
@@ -9,26 +9,22 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
type Options = {isPrefetchOnly: boolean, ...};
|
|
13
12
|
type MetroRequire = {
|
|
14
13
|
(number): mixed,
|
|
15
|
-
importAll: number =>
|
|
14
|
+
importAll: <T>(number) => T,
|
|
16
15
|
...
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
declare var require: MetroRequire;
|
|
20
19
|
|
|
21
|
-
const DEFAULT_OPTIONS = {isPrefetchOnly: false};
|
|
22
|
-
|
|
23
20
|
type DependencyMapPaths = ?$ReadOnly<{[moduleID: number | string]: mixed}>;
|
|
24
21
|
|
|
25
22
|
declare var __METRO_GLOBAL_PREFIX__: string;
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
function maybeLoadBundle(
|
|
28
25
|
moduleID: number,
|
|
29
26
|
paths: DependencyMapPaths,
|
|
30
|
-
|
|
31
|
-
): Promise<mixed> {
|
|
27
|
+
): void | Promise<void> {
|
|
32
28
|
const loadBundle: (bundlePath: mixed) => Promise<void> =
|
|
33
29
|
global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`];
|
|
34
30
|
|
|
@@ -38,32 +34,51 @@ async function asyncRequireImpl(
|
|
|
38
34
|
const bundlePath = paths[stringModuleID];
|
|
39
35
|
if (bundlePath != null) {
|
|
40
36
|
// NOTE: Errors will be swallowed by asyncRequire.prefetch
|
|
41
|
-
|
|
37
|
+
return loadBundle(bundlePath);
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function asyncRequireImpl<T>(
|
|
46
|
+
moduleID: number,
|
|
47
|
+
paths: DependencyMapPaths,
|
|
48
|
+
): Promise<T> | T {
|
|
49
|
+
const maybeLoadBundlePromise = maybeLoadBundle(moduleID, paths);
|
|
50
|
+
const importAll = () => require.importAll<T>(moduleID);
|
|
51
|
+
|
|
52
|
+
if (maybeLoadBundlePromise != null) {
|
|
53
|
+
return maybeLoadBundlePromise.then(importAll);
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
return
|
|
56
|
+
return importAll();
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
async function asyncRequire(
|
|
59
|
+
async function asyncRequire<T>(
|
|
54
60
|
moduleID: number,
|
|
55
61
|
paths: DependencyMapPaths,
|
|
56
|
-
moduleName?: string,
|
|
57
|
-
): Promise<
|
|
58
|
-
return asyncRequireImpl(moduleID, paths
|
|
62
|
+
moduleName?: string, // unused
|
|
63
|
+
): Promise<T> {
|
|
64
|
+
return asyncRequireImpl<T>(moduleID, paths);
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
// Synchronous version of asyncRequire, which can still return a promise
|
|
68
|
+
// if the module is split.
|
|
69
|
+
asyncRequire.unstable_importMaybeSync = function unstable_importMaybeSync<T>(
|
|
70
|
+
moduleID: number,
|
|
71
|
+
paths: DependencyMapPaths,
|
|
72
|
+
): Promise<T> | T {
|
|
73
|
+
return asyncRequireImpl(moduleID, paths);
|
|
74
|
+
};
|
|
75
|
+
|
|
61
76
|
asyncRequire.prefetch = function (
|
|
62
77
|
moduleID: number,
|
|
63
78
|
paths: DependencyMapPaths,
|
|
64
|
-
moduleName?: string,
|
|
79
|
+
moduleName?: string, // unused
|
|
65
80
|
): void {
|
|
66
|
-
|
|
81
|
+
maybeLoadBundle(moduleID, paths)?.then(
|
|
67
82
|
() => {},
|
|
68
83
|
() => {},
|
|
69
84
|
);
|
package/src/polyfills/require.js
CHANGED
|
@@ -13,15 +13,22 @@ if (__DEV__) {
|
|
|
13
13
|
global.$RefreshSig$ = () => (type) => type;
|
|
14
14
|
}
|
|
15
15
|
function clear() {
|
|
16
|
-
modules =
|
|
16
|
+
modules = new Map();
|
|
17
17
|
return modules;
|
|
18
18
|
}
|
|
19
19
|
if (__DEV__) {
|
|
20
|
-
var verboseNamesToModuleIds =
|
|
20
|
+
var verboseNamesToModuleIds = new Map();
|
|
21
|
+
var getModuleIdForVerboseName = (verboseName) => {
|
|
22
|
+
const moduleId = verboseNamesToModuleIds.get(verboseName);
|
|
23
|
+
if (moduleId == null) {
|
|
24
|
+
throw new Error(`Unknown named module: "${verboseName}"`);
|
|
25
|
+
}
|
|
26
|
+
return moduleId;
|
|
27
|
+
};
|
|
21
28
|
var initializingModuleIds = [];
|
|
22
29
|
}
|
|
23
30
|
function define(factory, moduleId, dependencyMap) {
|
|
24
|
-
if (modules
|
|
31
|
+
if (modules.has(moduleId)) {
|
|
25
32
|
if (__DEV__) {
|
|
26
33
|
const inverseDependencies = arguments[4];
|
|
27
34
|
if (inverseDependencies) {
|
|
@@ -41,28 +48,24 @@ function define(factory, moduleId, dependencyMap) {
|
|
|
41
48
|
exports: {},
|
|
42
49
|
},
|
|
43
50
|
};
|
|
44
|
-
modules
|
|
51
|
+
modules.set(moduleId, mod);
|
|
45
52
|
if (__DEV__) {
|
|
46
53
|
mod.hot = createHotReloadingObject();
|
|
47
54
|
const verboseName = arguments[3];
|
|
48
55
|
if (verboseName) {
|
|
49
56
|
mod.verboseName = verboseName;
|
|
50
|
-
verboseNamesToModuleIds
|
|
57
|
+
verboseNamesToModuleIds.set(verboseName, moduleId);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
function metroRequire(moduleId) {
|
|
55
62
|
if (__DEV__ && typeof moduleId === "string") {
|
|
56
63
|
const verboseName = moduleId;
|
|
57
|
-
moduleId =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
`Requiring module "${verboseName}" by name is only supported for ` +
|
|
63
|
-
"debugging purposes and will BREAK IN PRODUCTION!"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
64
|
+
moduleId = getModuleIdForVerboseName(verboseName);
|
|
65
|
+
console.warn(
|
|
66
|
+
`Requiring module "${verboseName}" by name is only supported for ` +
|
|
67
|
+
"debugging purposes and will BREAK IN PRODUCTION!"
|
|
68
|
+
);
|
|
66
69
|
}
|
|
67
70
|
const moduleIdReallyIsNumber = moduleId;
|
|
68
71
|
if (__DEV__) {
|
|
@@ -72,7 +75,7 @@ function metroRequire(moduleId) {
|
|
|
72
75
|
if (initializingIndex !== -1) {
|
|
73
76
|
const cycle = initializingModuleIds
|
|
74
77
|
.slice(initializingIndex)
|
|
75
|
-
.map((id) => (
|
|
78
|
+
.map((id) => modules.get(id)?.verboseName ?? "[unknown]");
|
|
76
79
|
if (shouldPrintRequireCycle(cycle)) {
|
|
77
80
|
cycle.push(cycle[0]);
|
|
78
81
|
console.warn(
|
|
@@ -83,7 +86,7 @@ function metroRequire(moduleId) {
|
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
|
-
const module = modules
|
|
89
|
+
const module = modules.get(moduleIdReallyIsNumber);
|
|
87
90
|
return module && module.isInitialized
|
|
88
91
|
? module.publicModule.exports
|
|
89
92
|
: guardedLoadModule(moduleIdReallyIsNumber, module);
|
|
@@ -101,32 +104,32 @@ function shouldPrintRequireCycle(modules) {
|
|
|
101
104
|
function metroImportDefault(moduleId) {
|
|
102
105
|
if (__DEV__ && typeof moduleId === "string") {
|
|
103
106
|
const verboseName = moduleId;
|
|
104
|
-
moduleId =
|
|
107
|
+
moduleId = getModuleIdForVerboseName(verboseName);
|
|
105
108
|
}
|
|
106
109
|
const moduleIdReallyIsNumber = moduleId;
|
|
110
|
+
const maybeInitializedModule = modules.get(moduleIdReallyIsNumber);
|
|
107
111
|
if (
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
maybeInitializedModule &&
|
|
113
|
+
maybeInitializedModule.importedDefault !== EMPTY
|
|
110
114
|
) {
|
|
111
|
-
return
|
|
115
|
+
return maybeInitializedModule.importedDefault;
|
|
112
116
|
}
|
|
113
117
|
const exports = metroRequire(moduleIdReallyIsNumber);
|
|
114
118
|
const importedDefault =
|
|
115
119
|
exports && exports.__esModule ? exports.default : exports;
|
|
116
|
-
|
|
120
|
+
const initializedModule = modules.get(moduleIdReallyIsNumber);
|
|
121
|
+
return (initializedModule.importedDefault = importedDefault);
|
|
117
122
|
}
|
|
118
123
|
metroRequire.importDefault = metroImportDefault;
|
|
119
124
|
function metroImportAll(moduleId) {
|
|
120
125
|
if (__DEV__ && typeof moduleId === "string") {
|
|
121
126
|
const verboseName = moduleId;
|
|
122
|
-
moduleId =
|
|
127
|
+
moduleId = getModuleIdForVerboseName(verboseName);
|
|
123
128
|
}
|
|
124
129
|
const moduleIdReallyIsNumber = moduleId;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
) {
|
|
129
|
-
return modules[moduleIdReallyIsNumber].importedAll;
|
|
130
|
+
const maybeInitializedModule = modules.get(moduleIdReallyIsNumber);
|
|
131
|
+
if (maybeInitializedModule && maybeInitializedModule.importedAll !== EMPTY) {
|
|
132
|
+
return maybeInitializedModule.importedAll;
|
|
130
133
|
}
|
|
131
134
|
const exports = metroRequire(moduleIdReallyIsNumber);
|
|
132
135
|
let importedAll;
|
|
@@ -143,7 +146,8 @@ function metroImportAll(moduleId) {
|
|
|
143
146
|
}
|
|
144
147
|
importedAll.default = exports;
|
|
145
148
|
}
|
|
146
|
-
|
|
149
|
+
const initializedModule = modules.get(moduleIdReallyIsNumber);
|
|
150
|
+
return (initializedModule.importedAll = importedAll);
|
|
147
151
|
}
|
|
148
152
|
metroRequire.importAll = metroImportAll;
|
|
149
153
|
metroRequire.context = function fallbackRequireContext() {
|
|
@@ -214,7 +218,7 @@ function registerSegment(segmentId, moduleDefiner, moduleIds) {
|
|
|
214
218
|
}
|
|
215
219
|
if (moduleIds) {
|
|
216
220
|
moduleIds.forEach((moduleId) => {
|
|
217
|
-
if (!modules
|
|
221
|
+
if (!modules.has(moduleId) && !definingSegmentByModuleID.has(moduleId)) {
|
|
218
222
|
definingSegmentByModuleID.set(moduleId, segmentId);
|
|
219
223
|
}
|
|
220
224
|
});
|
|
@@ -226,7 +230,7 @@ function loadModuleImplementation(moduleId, module) {
|
|
|
226
230
|
const definer = moduleDefinersBySegmentID[segmentId];
|
|
227
231
|
if (definer != null) {
|
|
228
232
|
definer(moduleId);
|
|
229
|
-
module = modules
|
|
233
|
+
module = modules.get(moduleId);
|
|
230
234
|
definingSegmentByModuleID.delete(moduleId);
|
|
231
235
|
}
|
|
232
236
|
}
|
|
@@ -234,7 +238,7 @@ function loadModuleImplementation(moduleId, module) {
|
|
|
234
238
|
if (!module && nativeRequire) {
|
|
235
239
|
const { segmentId, localId } = unpackModuleId(moduleId);
|
|
236
240
|
nativeRequire(localId, segmentId);
|
|
237
|
-
module = modules
|
|
241
|
+
module = modules.get(moduleId);
|
|
238
242
|
}
|
|
239
243
|
if (!module) {
|
|
240
244
|
throw unknownModuleError(moduleId);
|
|
@@ -347,7 +351,7 @@ if (__DEV__) {
|
|
|
347
351
|
dependencyMap,
|
|
348
352
|
inverseDependencies
|
|
349
353
|
) {
|
|
350
|
-
const mod = modules
|
|
354
|
+
const mod = modules.get(id);
|
|
351
355
|
if (!mod) {
|
|
352
356
|
if (factory) {
|
|
353
357
|
return;
|
|
@@ -367,7 +371,7 @@ if (__DEV__) {
|
|
|
367
371
|
updatedModuleIDs = topologicalSort(
|
|
368
372
|
[id],
|
|
369
373
|
(pendingID) => {
|
|
370
|
-
const pendingModule = modules
|
|
374
|
+
const pendingModule = modules.get(pendingID);
|
|
371
375
|
if (pendingModule == null) {
|
|
372
376
|
return [];
|
|
373
377
|
}
|
|
@@ -423,7 +427,7 @@ if (__DEV__) {
|
|
|
423
427
|
continue;
|
|
424
428
|
}
|
|
425
429
|
seenModuleIDs.add(updatedID);
|
|
426
|
-
const updatedMod = modules
|
|
430
|
+
const updatedMod = modules.get(updatedID);
|
|
427
431
|
if (updatedMod == null) {
|
|
428
432
|
throw new Error("[Refresh] Expected to find the updated module.");
|
|
429
433
|
}
|
|
@@ -463,7 +467,7 @@ if (__DEV__) {
|
|
|
463
467
|
}
|
|
464
468
|
for (let j = 0; j < parentIDs.length; j++) {
|
|
465
469
|
const parentID = parentIDs[j];
|
|
466
|
-
const parentMod = modules
|
|
470
|
+
const parentMod = modules.get(parentID);
|
|
467
471
|
if (parentMod == null) {
|
|
468
472
|
throw new Error("[Refresh] Expected to find parent module.");
|
|
469
473
|
}
|
|
@@ -524,7 +528,7 @@ if (__DEV__) {
|
|
|
524
528
|
return result;
|
|
525
529
|
};
|
|
526
530
|
const runUpdatedModule = function (id, factory, dependencyMap) {
|
|
527
|
-
const mod = modules
|
|
531
|
+
const mod = modules.get(id);
|
|
528
532
|
if (mod == null) {
|
|
529
533
|
throw new Error("[Refresh] Expected to find the module.");
|
|
530
534
|
}
|
|
@@ -67,11 +67,7 @@ type ModuleDefinition = {
|
|
|
67
67
|
publicModule: Module,
|
|
68
68
|
verboseName?: string,
|
|
69
69
|
};
|
|
70
|
-
type ModuleList =
|
|
71
|
-
[number]: ?ModuleDefinition,
|
|
72
|
-
__proto__: null,
|
|
73
|
-
...
|
|
74
|
-
};
|
|
70
|
+
type ModuleList = Map<number, ModuleDefinition>;
|
|
75
71
|
export type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports;
|
|
76
72
|
export type DefineFn = (
|
|
77
73
|
factory: FactoryFn,
|
|
@@ -103,7 +99,7 @@ if (__DEV__) {
|
|
|
103
99
|
}
|
|
104
100
|
|
|
105
101
|
function clear(): ModuleList {
|
|
106
|
-
modules = (
|
|
102
|
+
modules = new Map();
|
|
107
103
|
|
|
108
104
|
// We return modules here so that we can assign an initial value to modules
|
|
109
105
|
// when defining it. Otherwise, we would have to do "let modules = null",
|
|
@@ -112,11 +108,14 @@ function clear(): ModuleList {
|
|
|
112
108
|
}
|
|
113
109
|
|
|
114
110
|
if (__DEV__) {
|
|
115
|
-
var verboseNamesToModuleIds:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
var verboseNamesToModuleIds: Map<string, number> = new Map();
|
|
112
|
+
var getModuleIdForVerboseName = (verboseName: string): number => {
|
|
113
|
+
const moduleId = verboseNamesToModuleIds.get(verboseName);
|
|
114
|
+
if (moduleId == null) {
|
|
115
|
+
throw new Error(`Unknown named module: "${verboseName}"`);
|
|
116
|
+
}
|
|
117
|
+
return moduleId;
|
|
118
|
+
};
|
|
120
119
|
var initializingModuleIds: Array<number> = [];
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -125,7 +124,7 @@ function define(
|
|
|
125
124
|
moduleId: number,
|
|
126
125
|
dependencyMap?: DependencyMap,
|
|
127
126
|
): void {
|
|
128
|
-
if (modules
|
|
127
|
+
if (modules.has(moduleId)) {
|
|
129
128
|
if (__DEV__) {
|
|
130
129
|
// (We take `inverseDependencies` from `arguments` to avoid an unused
|
|
131
130
|
// named parameter in `define` in production.
|
|
@@ -153,7 +152,7 @@ function define(
|
|
|
153
152
|
publicModule: {exports: {}},
|
|
154
153
|
};
|
|
155
154
|
|
|
156
|
-
modules
|
|
155
|
+
modules.set(moduleId, mod);
|
|
157
156
|
|
|
158
157
|
if (__DEV__) {
|
|
159
158
|
// HMR
|
|
@@ -165,7 +164,7 @@ function define(
|
|
|
165
164
|
const verboseName: string | void = arguments[3];
|
|
166
165
|
if (verboseName) {
|
|
167
166
|
mod.verboseName = verboseName;
|
|
168
|
-
verboseNamesToModuleIds
|
|
167
|
+
verboseNamesToModuleIds.set(verboseName, moduleId);
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
170
|
}
|
|
@@ -173,15 +172,11 @@ function define(
|
|
|
173
172
|
function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
|
|
174
173
|
if (__DEV__ && typeof moduleId === 'string') {
|
|
175
174
|
const verboseName = moduleId;
|
|
176
|
-
moduleId =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
`Requiring module "${verboseName}" by name is only supported for ` +
|
|
182
|
-
'debugging purposes and will BREAK IN PRODUCTION!',
|
|
183
|
-
);
|
|
184
|
-
}
|
|
175
|
+
moduleId = getModuleIdForVerboseName(verboseName);
|
|
176
|
+
console.warn(
|
|
177
|
+
`Requiring module "${verboseName}" by name is only supported for ` +
|
|
178
|
+
'debugging purposes and will BREAK IN PRODUCTION!',
|
|
179
|
+
);
|
|
185
180
|
}
|
|
186
181
|
|
|
187
182
|
//$FlowFixMe: at this point we know that moduleId is a number
|
|
@@ -194,10 +189,7 @@ function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
|
|
|
194
189
|
if (initializingIndex !== -1) {
|
|
195
190
|
const cycle = initializingModuleIds
|
|
196
191
|
.slice(initializingIndex)
|
|
197
|
-
.map((id: number) =>
|
|
198
|
-
modules[id] ? modules[id].verboseName : '[unknown]',
|
|
199
|
-
);
|
|
200
|
-
|
|
192
|
+
.map((id: number) => modules.get(id)?.verboseName ?? '[unknown]');
|
|
201
193
|
if (shouldPrintRequireCycle(cycle)) {
|
|
202
194
|
cycle.push(cycle[0]); // We want to print A -> B -> A:
|
|
203
195
|
console.warn(
|
|
@@ -209,7 +201,7 @@ function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
|
|
|
209
201
|
}
|
|
210
202
|
}
|
|
211
203
|
|
|
212
|
-
const module = modules
|
|
204
|
+
const module = modules.get(moduleIdReallyIsNumber);
|
|
213
205
|
|
|
214
206
|
return module && module.isInitialized
|
|
215
207
|
? module.publicModule.exports
|
|
@@ -237,25 +229,30 @@ function metroImportDefault(
|
|
|
237
229
|
): any | Exports {
|
|
238
230
|
if (__DEV__ && typeof moduleId === 'string') {
|
|
239
231
|
const verboseName = moduleId;
|
|
240
|
-
moduleId =
|
|
232
|
+
moduleId = getModuleIdForVerboseName(verboseName);
|
|
241
233
|
}
|
|
242
234
|
|
|
243
235
|
//$FlowFixMe: at this point we know that moduleId is a number
|
|
244
236
|
const moduleIdReallyIsNumber: number = moduleId;
|
|
245
237
|
|
|
238
|
+
const maybeInitializedModule = modules.get(moduleIdReallyIsNumber);
|
|
239
|
+
|
|
246
240
|
if (
|
|
247
|
-
|
|
248
|
-
|
|
241
|
+
maybeInitializedModule &&
|
|
242
|
+
maybeInitializedModule.importedDefault !== EMPTY
|
|
249
243
|
) {
|
|
250
|
-
return
|
|
244
|
+
return maybeInitializedModule.importedDefault;
|
|
251
245
|
}
|
|
252
246
|
|
|
253
247
|
const exports: Exports = metroRequire(moduleIdReallyIsNumber);
|
|
254
248
|
const importedDefault: any | Exports =
|
|
255
249
|
exports && exports.__esModule ? exports.default : exports;
|
|
256
250
|
|
|
257
|
-
// $FlowFixMe The metroRequire call above
|
|
258
|
-
|
|
251
|
+
// $FlowFixMe[incompatible-type] The `metroRequire` call above would have thrown if modules[id] was null
|
|
252
|
+
const initializedModule: ModuleDefinition = modules.get(
|
|
253
|
+
moduleIdReallyIsNumber,
|
|
254
|
+
);
|
|
255
|
+
return (initializedModule.importedDefault = importedDefault);
|
|
259
256
|
}
|
|
260
257
|
metroRequire.importDefault = metroImportDefault;
|
|
261
258
|
|
|
@@ -264,17 +261,16 @@ function metroImportAll(
|
|
|
264
261
|
): any | Exports | {[string]: any} {
|
|
265
262
|
if (__DEV__ && typeof moduleId === 'string') {
|
|
266
263
|
const verboseName = moduleId;
|
|
267
|
-
moduleId =
|
|
264
|
+
moduleId = getModuleIdForVerboseName(verboseName);
|
|
268
265
|
}
|
|
269
266
|
|
|
270
267
|
//$FlowFixMe: at this point we know that moduleId is a number
|
|
271
268
|
const moduleIdReallyIsNumber: number = moduleId;
|
|
272
269
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return modules[moduleIdReallyIsNumber].importedAll;
|
|
270
|
+
const maybeInitializedModule = modules.get(moduleIdReallyIsNumber);
|
|
271
|
+
|
|
272
|
+
if (maybeInitializedModule && maybeInitializedModule.importedAll !== EMPTY) {
|
|
273
|
+
return maybeInitializedModule.importedAll;
|
|
278
274
|
}
|
|
279
275
|
|
|
280
276
|
const exports: Exports = metroRequire(moduleIdReallyIsNumber);
|
|
@@ -297,8 +293,11 @@ function metroImportAll(
|
|
|
297
293
|
importedAll.default = exports;
|
|
298
294
|
}
|
|
299
295
|
|
|
300
|
-
// $FlowFixMe The metroRequire call above
|
|
301
|
-
|
|
296
|
+
// $FlowFixMe[incompatible-type] The `metroRequire` call above would have thrown if modules[id] was null
|
|
297
|
+
const initializedModule: ModuleDefinition = modules.get(
|
|
298
|
+
moduleIdReallyIsNumber,
|
|
299
|
+
);
|
|
300
|
+
return (initializedModule.importedAll = importedAll);
|
|
302
301
|
}
|
|
303
302
|
metroRequire.importAll = metroImportAll;
|
|
304
303
|
|
|
@@ -394,7 +393,7 @@ function registerSegment(
|
|
|
394
393
|
}
|
|
395
394
|
if (moduleIds) {
|
|
396
395
|
moduleIds.forEach(moduleId => {
|
|
397
|
-
if (!modules
|
|
396
|
+
if (!modules.has(moduleId) && !definingSegmentByModuleID.has(moduleId)) {
|
|
398
397
|
definingSegmentByModuleID.set(moduleId, segmentId);
|
|
399
398
|
}
|
|
400
399
|
});
|
|
@@ -410,7 +409,7 @@ function loadModuleImplementation(
|
|
|
410
409
|
const definer = moduleDefinersBySegmentID[segmentId];
|
|
411
410
|
if (definer != null) {
|
|
412
411
|
definer(moduleId);
|
|
413
|
-
module = modules
|
|
412
|
+
module = modules.get(moduleId);
|
|
414
413
|
definingSegmentByModuleID.delete(moduleId);
|
|
415
414
|
}
|
|
416
415
|
}
|
|
@@ -419,7 +418,7 @@ function loadModuleImplementation(
|
|
|
419
418
|
if (!module && nativeRequire) {
|
|
420
419
|
const {segmentId, localId} = unpackModuleId(moduleId);
|
|
421
420
|
nativeRequire(localId, segmentId);
|
|
422
|
-
module = modules
|
|
421
|
+
module = modules.get(moduleId);
|
|
423
422
|
}
|
|
424
423
|
|
|
425
424
|
if (!module) {
|
|
@@ -563,7 +562,7 @@ if (__DEV__) {
|
|
|
563
562
|
dependencyMap: DependencyMap,
|
|
564
563
|
inverseDependencies: InverseDependencyMap,
|
|
565
564
|
) {
|
|
566
|
-
const mod = modules
|
|
565
|
+
const mod = modules.get(id);
|
|
567
566
|
if (!mod) {
|
|
568
567
|
if (factory) {
|
|
569
568
|
// New modules are going to be handled by the define() method.
|
|
@@ -606,7 +605,7 @@ if (__DEV__) {
|
|
|
606
605
|
updatedModuleIDs = topologicalSort(
|
|
607
606
|
[id], // Start with the changed module and go upwards
|
|
608
607
|
pendingID => {
|
|
609
|
-
const pendingModule = modules
|
|
608
|
+
const pendingModule = modules.get(pendingID);
|
|
610
609
|
if (pendingModule == null) {
|
|
611
610
|
// Nothing to do.
|
|
612
611
|
return [];
|
|
@@ -677,7 +676,7 @@ if (__DEV__) {
|
|
|
677
676
|
}
|
|
678
677
|
seenModuleIDs.add(updatedID);
|
|
679
678
|
|
|
680
|
-
const updatedMod = modules
|
|
679
|
+
const updatedMod = modules.get(updatedID);
|
|
681
680
|
if (updatedMod == null) {
|
|
682
681
|
throw new Error('[Refresh] Expected to find the updated module.');
|
|
683
682
|
}
|
|
@@ -734,7 +733,7 @@ if (__DEV__) {
|
|
|
734
733
|
// Schedule all parent refresh boundaries to re-run in this loop.
|
|
735
734
|
for (let j = 0; j < parentIDs.length; j++) {
|
|
736
735
|
const parentID = parentIDs[j];
|
|
737
|
-
const parentMod = modules
|
|
736
|
+
const parentMod = modules.get(parentID);
|
|
738
737
|
if (parentMod == null) {
|
|
739
738
|
throw new Error('[Refresh] Expected to find parent module.');
|
|
740
739
|
}
|
|
@@ -810,7 +809,7 @@ if (__DEV__) {
|
|
|
810
809
|
factory?: FactoryFn,
|
|
811
810
|
dependencyMap?: DependencyMap,
|
|
812
811
|
): boolean {
|
|
813
|
-
const mod = modules
|
|
812
|
+
const mod = modules.get(id);
|
|
814
813
|
if (mod == null) {
|
|
815
814
|
throw new Error('[Refresh] Expected to find the module.');
|
|
816
815
|
}
|