metro-runtime 0.80.5 → 0.80.7
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 +1 -1
- package/src/modules/HMRClient.js +0 -23
- package/src/modules/asyncRequire.js +0 -12
- package/src/modules/empty-module.js +0 -9
- package/src/modules/null-module.js +0 -10
- package/src/modules/types.flow.js +0 -11
- package/src/modules/vendor/eventemitter3.js +0 -169
- package/src/polyfills/require.js +2 -161
package/package.json
CHANGED
package/src/modules/HMRClient.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const EventEmitter = require("./vendor/eventemitter3");
|
|
15
4
|
const inject = ({ module: [id, code], sourceURL }) => {
|
|
16
|
-
// Some engines do not support `sourceURL` as a comment. We expose a
|
|
17
|
-
// `globalEvalWithSourceUrl` function to handle updates in that case.
|
|
18
5
|
if (global.globalEvalWithSourceUrl) {
|
|
19
6
|
global.globalEvalWithSourceUrl(code, sourceURL);
|
|
20
7
|
} else {
|
|
21
|
-
// eslint-disable-next-line no-eval
|
|
22
8
|
eval(code);
|
|
23
9
|
}
|
|
24
10
|
};
|
|
@@ -33,9 +19,6 @@ class HMRClient extends EventEmitter {
|
|
|
33
19
|
_state = "opening";
|
|
34
20
|
constructor(url) {
|
|
35
21
|
super();
|
|
36
|
-
|
|
37
|
-
// Access the global WebSocket object only after enabling the client,
|
|
38
|
-
// since some polyfills do the initialization lazily.
|
|
39
22
|
this._ws = new global.WebSocket(url);
|
|
40
23
|
this._ws.onopen = () => {
|
|
41
24
|
this._state = "open";
|
|
@@ -96,7 +79,6 @@ class HMRClient extends EventEmitter {
|
|
|
96
79
|
this._ws.send(message);
|
|
97
80
|
break;
|
|
98
81
|
case "closed":
|
|
99
|
-
// Ignore.
|
|
100
82
|
break;
|
|
101
83
|
default:
|
|
102
84
|
throw new Error("[WebSocketHMRClient] Unknown state: " + this._state);
|
|
@@ -128,8 +110,6 @@ function mergeUpdates(base, next) {
|
|
|
128
110
|
const addedIDs = new Set();
|
|
129
111
|
const deletedIDs = new Set();
|
|
130
112
|
const moduleMap = new Map();
|
|
131
|
-
|
|
132
|
-
// Fill in the temporary maps and sets from both updates in their order.
|
|
133
113
|
applyUpdateLocally(base);
|
|
134
114
|
applyUpdateLocally(next);
|
|
135
115
|
function applyUpdateLocally(update) {
|
|
@@ -155,9 +135,6 @@ function mergeUpdates(base, next) {
|
|
|
155
135
|
moduleMap.set(id, item);
|
|
156
136
|
});
|
|
157
137
|
}
|
|
158
|
-
|
|
159
|
-
// Now reconstruct a unified update from our in-memory maps and sets.
|
|
160
|
-
// Applying it should be equivalent to applying both of them individually.
|
|
161
138
|
const result = {
|
|
162
139
|
isInitialUpdate: next.isInitialUpdate,
|
|
163
140
|
revisionId: next.revisionId,
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @format
|
|
11
|
-
* @oncall react_native
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
3
|
const DEFAULT_OPTIONS = {
|
|
15
4
|
isPrefetchOnly: false,
|
|
16
5
|
};
|
|
@@ -21,7 +10,6 @@ async function asyncRequireImpl(moduleID, paths, options) {
|
|
|
21
10
|
if (paths != null) {
|
|
22
11
|
const bundlePath = paths[stringModuleID];
|
|
23
12
|
if (bundlePath != null) {
|
|
24
|
-
// NOTE: Errors will be swallowed by asyncRequire.prefetch
|
|
25
13
|
await loadBundle(bundlePath);
|
|
26
14
|
}
|
|
27
15
|
}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @format
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
3
|
module.exports = null;
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
@@ -1,79 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @noformat
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
* The MIT License (MIT)
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) 2014 Arnout Kazemier
|
|
14
|
-
*
|
|
15
|
-
* This is a vendored file based on EventEmitter3: https://github.com/primus/eventemitter3
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/* eslint-disable */
|
|
19
|
-
|
|
20
1
|
"use strict";
|
|
21
2
|
|
|
22
3
|
var has = Object.prototype.hasOwnProperty,
|
|
23
4
|
prefix = "~";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Constructor to create a storage for our `EE` objects.
|
|
27
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
28
|
-
*
|
|
29
|
-
* @constructor
|
|
30
|
-
* @private
|
|
31
|
-
*/
|
|
32
5
|
function Events() {}
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
36
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
37
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
38
|
-
// character to make sure that the built-in object properties are not
|
|
39
|
-
// overridden or used as an attack vector.
|
|
40
|
-
//
|
|
41
6
|
if (Object.create) {
|
|
42
7
|
Events.prototype = Object.create(null);
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
46
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
47
|
-
//
|
|
48
8
|
if (!new Events().__proto__) prefix = false;
|
|
49
9
|
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Representation of a single event listener.
|
|
53
|
-
*
|
|
54
|
-
* @param {Function} fn The listener function.
|
|
55
|
-
* @param {*} context The context to invoke the listener with.
|
|
56
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
57
|
-
* @constructor
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
10
|
function EE(fn, context, once) {
|
|
61
11
|
this.fn = fn;
|
|
62
12
|
this.context = context;
|
|
63
13
|
this.once = once || false;
|
|
64
14
|
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Add a listener for a given event.
|
|
68
|
-
*
|
|
69
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
70
|
-
* @param {(String|Symbol)} event The event name.
|
|
71
|
-
* @param {Function} fn The listener function.
|
|
72
|
-
* @param {*} context The context to invoke the listener with.
|
|
73
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
74
|
-
* @returns {EventEmitter}
|
|
75
|
-
* @private
|
|
76
|
-
*/
|
|
77
15
|
function addListener(emitter, event, fn, context, once) {
|
|
78
16
|
if (typeof fn !== "function") {
|
|
79
17
|
throw new TypeError("The listener must be a function");
|
|
@@ -86,38 +24,14 @@ function addListener(emitter, event, fn, context, once) {
|
|
|
86
24
|
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
87
25
|
return emitter;
|
|
88
26
|
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Clear event by name.
|
|
92
|
-
*
|
|
93
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
94
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
95
|
-
* @private
|
|
96
|
-
*/
|
|
97
27
|
function clearEvent(emitter, evt) {
|
|
98
28
|
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
99
29
|
else delete emitter._events[evt];
|
|
100
30
|
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
104
|
-
* `EventEmitter` interface.
|
|
105
|
-
*
|
|
106
|
-
* @constructor
|
|
107
|
-
* @public
|
|
108
|
-
*/
|
|
109
31
|
function EventEmitter() {
|
|
110
32
|
this._events = new Events();
|
|
111
33
|
this._eventsCount = 0;
|
|
112
34
|
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Return an array listing the events for which the emitter has registered
|
|
116
|
-
* listeners.
|
|
117
|
-
*
|
|
118
|
-
* @returns {Array}
|
|
119
|
-
* @public
|
|
120
|
-
*/
|
|
121
35
|
EventEmitter.prototype.eventNames = function eventNames() {
|
|
122
36
|
var names = [],
|
|
123
37
|
events,
|
|
@@ -131,14 +45,6 @@ EventEmitter.prototype.eventNames = function eventNames() {
|
|
|
131
45
|
}
|
|
132
46
|
return names;
|
|
133
47
|
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Return the listeners registered for a given event.
|
|
137
|
-
*
|
|
138
|
-
* @param {(String|Symbol)} event The event name.
|
|
139
|
-
* @returns {Array} The registered listeners.
|
|
140
|
-
* @public
|
|
141
|
-
*/
|
|
142
48
|
EventEmitter.prototype.listeners = function listeners(event) {
|
|
143
49
|
var evt = prefix ? prefix + event : event,
|
|
144
50
|
handlers = this._events[evt];
|
|
@@ -149,14 +55,6 @@ EventEmitter.prototype.listeners = function listeners(event) {
|
|
|
149
55
|
}
|
|
150
56
|
return ee;
|
|
151
57
|
};
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Return the number of listeners listening to a given event.
|
|
155
|
-
*
|
|
156
|
-
* @param {(String|Symbol)} event The event name.
|
|
157
|
-
* @returns {Number} The number of listeners.
|
|
158
|
-
* @public
|
|
159
|
-
*/
|
|
160
58
|
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
161
59
|
var evt = prefix ? prefix + event : event,
|
|
162
60
|
listeners = this._events[evt];
|
|
@@ -164,14 +62,6 @@ EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
|
164
62
|
if (listeners.fn) return 1;
|
|
165
63
|
return listeners.length;
|
|
166
64
|
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Calls each of the listeners registered for a given event.
|
|
170
|
-
*
|
|
171
|
-
* @param {(String|Symbol)} event The event name.
|
|
172
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
173
|
-
* @public
|
|
174
|
-
*/
|
|
175
65
|
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
176
66
|
var evt = prefix ? prefix + event : event;
|
|
177
67
|
if (!this._events[evt]) return false;
|
|
@@ -230,43 +120,12 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
|
230
120
|
}
|
|
231
121
|
return true;
|
|
232
122
|
};
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Add a listener for a given event.
|
|
236
|
-
*
|
|
237
|
-
* @param {(String|Symbol)} event The event name.
|
|
238
|
-
* @param {Function} fn The listener function.
|
|
239
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
240
|
-
* @returns {EventEmitter} `this`.
|
|
241
|
-
* @public
|
|
242
|
-
*/
|
|
243
123
|
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
244
124
|
return addListener(this, event, fn, context, false);
|
|
245
125
|
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Add a one-time listener for a given event.
|
|
249
|
-
*
|
|
250
|
-
* @param {(String|Symbol)} event The event name.
|
|
251
|
-
* @param {Function} fn The listener function.
|
|
252
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
253
|
-
* @returns {EventEmitter} `this`.
|
|
254
|
-
* @public
|
|
255
|
-
*/
|
|
256
126
|
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
257
127
|
return addListener(this, event, fn, context, true);
|
|
258
128
|
};
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Remove the listeners of a given event.
|
|
262
|
-
*
|
|
263
|
-
* @param {(String|Symbol)} event The event name.
|
|
264
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
265
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
266
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
267
|
-
* @returns {EventEmitter} `this`.
|
|
268
|
-
* @public
|
|
269
|
-
*/
|
|
270
129
|
EventEmitter.prototype.removeListener = function removeListener(
|
|
271
130
|
event,
|
|
272
131
|
fn,
|
|
@@ -298,24 +157,12 @@ EventEmitter.prototype.removeListener = function removeListener(
|
|
|
298
157
|
events.push(listeners[i]);
|
|
299
158
|
}
|
|
300
159
|
}
|
|
301
|
-
|
|
302
|
-
//
|
|
303
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
304
|
-
//
|
|
305
160
|
if (events.length)
|
|
306
161
|
this._events[evt] = events.length === 1 ? events[0] : events;
|
|
307
162
|
else clearEvent(this, evt);
|
|
308
163
|
}
|
|
309
164
|
return this;
|
|
310
165
|
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Remove all listeners, or those of the specified event.
|
|
314
|
-
*
|
|
315
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
316
|
-
* @returns {EventEmitter} `this`.
|
|
317
|
-
* @public
|
|
318
|
-
*/
|
|
319
166
|
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
320
167
|
var evt;
|
|
321
168
|
if (event) {
|
|
@@ -327,26 +174,10 @@ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
|
327
174
|
}
|
|
328
175
|
return this;
|
|
329
176
|
};
|
|
330
|
-
|
|
331
|
-
//
|
|
332
|
-
// Alias methods names because people roll like that.
|
|
333
|
-
//
|
|
334
177
|
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
335
178
|
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
336
|
-
|
|
337
|
-
//
|
|
338
|
-
// Expose the prefix.
|
|
339
|
-
//
|
|
340
179
|
EventEmitter.prefixed = prefix;
|
|
341
|
-
|
|
342
|
-
//
|
|
343
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
344
|
-
//
|
|
345
180
|
EventEmitter.EventEmitter = EventEmitter;
|
|
346
|
-
|
|
347
|
-
//
|
|
348
|
-
// Expose the module.
|
|
349
|
-
//
|
|
350
181
|
if ("undefined" !== typeof module) {
|
|
351
182
|
module.exports = EventEmitter;
|
|
352
183
|
}
|
package/src/polyfills/require.js
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
* @polyfill
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
1
|
"use strict";
|
|
14
2
|
|
|
15
|
-
/* eslint-disable no-bitwise */
|
|
16
|
-
// A simpler $ArrayLike<T>. Not iterable and doesn't have a `length`.
|
|
17
|
-
// This is compatible with actual arrays as well as with objects that look like
|
|
18
|
-
// {0: 'value', 1: '...'}
|
|
19
3
|
global.__r = metroRequire;
|
|
20
4
|
global[`${__METRO_GLOBAL_PREFIX__}__d`] = define;
|
|
21
5
|
global.__c = clear;
|
|
22
6
|
global.__registerSegment = registerSegment;
|
|
23
7
|
var modules = clear();
|
|
24
|
-
|
|
25
|
-
// Don't use a Symbol here, it would pull in an extra polyfill with all sorts of
|
|
26
|
-
// additional stuff (e.g. Array.from).
|
|
27
8
|
const EMPTY = {};
|
|
28
9
|
const CYCLE_DETECTED = {};
|
|
29
10
|
const { hasOwnProperty } = {};
|
|
@@ -33,10 +14,6 @@ if (__DEV__) {
|
|
|
33
14
|
}
|
|
34
15
|
function clear() {
|
|
35
16
|
modules = Object.create(null);
|
|
36
|
-
|
|
37
|
-
// We return modules here so that we can assign an initial value to modules
|
|
38
|
-
// when defining it. Otherwise, we would have to do "let modules = null",
|
|
39
|
-
// which will force us to add "nullthrows" everywhere.
|
|
40
17
|
return modules;
|
|
41
18
|
}
|
|
42
19
|
if (__DEV__) {
|
|
@@ -46,19 +23,11 @@ if (__DEV__) {
|
|
|
46
23
|
function define(factory, moduleId, dependencyMap) {
|
|
47
24
|
if (modules[moduleId] != null) {
|
|
48
25
|
if (__DEV__) {
|
|
49
|
-
// (We take `inverseDependencies` from `arguments` to avoid an unused
|
|
50
|
-
// named parameter in `define` in production.
|
|
51
26
|
const inverseDependencies = arguments[4];
|
|
52
|
-
|
|
53
|
-
// If the module has already been defined and the define method has been
|
|
54
|
-
// called with inverseDependencies, we can hot reload it.
|
|
55
27
|
if (inverseDependencies) {
|
|
56
28
|
global.__accept(moduleId, factory, dependencyMap, inverseDependencies);
|
|
57
29
|
}
|
|
58
30
|
}
|
|
59
|
-
|
|
60
|
-
// prevent repeated calls to `global.nativeRequire` to overwrite modules
|
|
61
|
-
// that are already loaded
|
|
62
31
|
return;
|
|
63
32
|
}
|
|
64
33
|
const mod = {
|
|
@@ -74,12 +43,7 @@ function define(factory, moduleId, dependencyMap) {
|
|
|
74
43
|
};
|
|
75
44
|
modules[moduleId] = mod;
|
|
76
45
|
if (__DEV__) {
|
|
77
|
-
// HMR
|
|
78
46
|
mod.hot = createHotReloadingObject();
|
|
79
|
-
|
|
80
|
-
// DEBUGGABLE MODULES NAMES
|
|
81
|
-
// we take `verboseName` from `arguments` to avoid an unused named parameter
|
|
82
|
-
// in `define` in production.
|
|
83
47
|
const verboseName = arguments[3];
|
|
84
48
|
if (verboseName) {
|
|
85
49
|
mod.verboseName = verboseName;
|
|
@@ -100,8 +64,6 @@ function metroRequire(moduleId) {
|
|
|
100
64
|
);
|
|
101
65
|
}
|
|
102
66
|
}
|
|
103
|
-
|
|
104
|
-
//$FlowFixMe: at this point we know that moduleId is a number
|
|
105
67
|
const moduleIdReallyIsNumber = moduleId;
|
|
106
68
|
if (__DEV__) {
|
|
107
69
|
const initializingIndex = initializingModuleIds.indexOf(
|
|
@@ -112,7 +74,7 @@ function metroRequire(moduleId) {
|
|
|
112
74
|
.slice(initializingIndex)
|
|
113
75
|
.map((id) => (modules[id] ? modules[id].verboseName : "[unknown]"));
|
|
114
76
|
if (shouldPrintRequireCycle(cycle)) {
|
|
115
|
-
cycle.push(cycle[0]);
|
|
77
|
+
cycle.push(cycle[0]);
|
|
116
78
|
console.warn(
|
|
117
79
|
`Require cycle: ${cycle.join(" -> ")}\n\n` +
|
|
118
80
|
"Require cycles are allowed, but can result in uninitialized values. " +
|
|
@@ -126,9 +88,6 @@ function metroRequire(moduleId) {
|
|
|
126
88
|
? module.publicModule.exports
|
|
127
89
|
: guardedLoadModule(moduleIdReallyIsNumber, module);
|
|
128
90
|
}
|
|
129
|
-
|
|
130
|
-
// We print require cycles unless they match a pattern in the
|
|
131
|
-
// `requireCycleIgnorePatterns` configuration.
|
|
132
91
|
function shouldPrintRequireCycle(modules) {
|
|
133
92
|
const regExps =
|
|
134
93
|
global[__METRO_GLOBAL_PREFIX__ + "__requireCycleIgnorePatterns"];
|
|
@@ -137,8 +96,6 @@ function shouldPrintRequireCycle(modules) {
|
|
|
137
96
|
}
|
|
138
97
|
const isIgnored = (module) =>
|
|
139
98
|
module != null && regExps.some((regExp) => regExp.test(module));
|
|
140
|
-
|
|
141
|
-
// Print the cycle unless any part of it is ignored
|
|
142
99
|
return modules.every((module) => !isIgnored(module));
|
|
143
100
|
}
|
|
144
101
|
function metroImportDefault(moduleId) {
|
|
@@ -146,8 +103,6 @@ function metroImportDefault(moduleId) {
|
|
|
146
103
|
const verboseName = moduleId;
|
|
147
104
|
moduleId = verboseNamesToModuleIds[verboseName];
|
|
148
105
|
}
|
|
149
|
-
|
|
150
|
-
//$FlowFixMe: at this point we know that moduleId is a number
|
|
151
106
|
const moduleIdReallyIsNumber = moduleId;
|
|
152
107
|
if (
|
|
153
108
|
modules[moduleIdReallyIsNumber] &&
|
|
@@ -158,8 +113,6 @@ function metroImportDefault(moduleId) {
|
|
|
158
113
|
const exports = metroRequire(moduleIdReallyIsNumber);
|
|
159
114
|
const importedDefault =
|
|
160
115
|
exports && exports.__esModule ? exports.default : exports;
|
|
161
|
-
|
|
162
|
-
// $FlowFixMe The metroRequire call above will throw if modules[id] is null
|
|
163
116
|
return (modules[moduleIdReallyIsNumber].importedDefault = importedDefault);
|
|
164
117
|
}
|
|
165
118
|
metroRequire.importDefault = metroImportDefault;
|
|
@@ -168,8 +121,6 @@ function metroImportAll(moduleId) {
|
|
|
168
121
|
const verboseName = moduleId;
|
|
169
122
|
moduleId = verboseNamesToModuleIds[verboseName];
|
|
170
123
|
}
|
|
171
|
-
|
|
172
|
-
//$FlowFixMe: at this point we know that moduleId is a number
|
|
173
124
|
const moduleIdReallyIsNumber = moduleId;
|
|
174
125
|
if (
|
|
175
126
|
modules[moduleIdReallyIsNumber] &&
|
|
@@ -183,8 +134,6 @@ function metroImportAll(moduleId) {
|
|
|
183
134
|
importedAll = exports;
|
|
184
135
|
} else {
|
|
185
136
|
importedAll = {};
|
|
186
|
-
|
|
187
|
-
// Refrain from using Object.assign, it has to work in ES3 environments.
|
|
188
137
|
if (exports) {
|
|
189
138
|
for (const key in exports) {
|
|
190
139
|
if (hasOwnProperty.call(exports, key)) {
|
|
@@ -194,15 +143,9 @@ function metroImportAll(moduleId) {
|
|
|
194
143
|
}
|
|
195
144
|
importedAll.default = exports;
|
|
196
145
|
}
|
|
197
|
-
|
|
198
|
-
// $FlowFixMe The metroRequire call above will throw if modules[id] is null
|
|
199
146
|
return (modules[moduleIdReallyIsNumber].importedAll = importedAll);
|
|
200
147
|
}
|
|
201
148
|
metroRequire.importAll = metroImportAll;
|
|
202
|
-
|
|
203
|
-
// The `require.context()` syntax is never executed in the runtime because it is converted
|
|
204
|
-
// to `require()` in `metro/src/ModuleGraph/worker/collectDependencies.js` after collecting
|
|
205
|
-
// dependencies. If the feature flag is not enabled then the conversion never takes place and this error is thrown (development only).
|
|
206
149
|
metroRequire.context = function fallbackRequireContext() {
|
|
207
150
|
if (__DEV__) {
|
|
208
151
|
throw new Error(
|
|
@@ -213,8 +156,6 @@ metroRequire.context = function fallbackRequireContext() {
|
|
|
213
156
|
"The experimental Metro feature `require.context` is not enabled in your project."
|
|
214
157
|
);
|
|
215
158
|
};
|
|
216
|
-
|
|
217
|
-
// `require.resolveWeak()` is a compile-time primitive (see collectDependencies.js)
|
|
218
159
|
metroRequire.resolveWeak = function fallbackRequireResolveWeak() {
|
|
219
160
|
if (__DEV__) {
|
|
220
161
|
throw new Error(
|
|
@@ -231,7 +172,6 @@ function guardedLoadModule(moduleId, module) {
|
|
|
231
172
|
try {
|
|
232
173
|
returnValue = loadModuleImplementation(moduleId, module);
|
|
233
174
|
} catch (e) {
|
|
234
|
-
// TODO: (moti) T48204692 Type this use of ErrorUtils.
|
|
235
175
|
global.ErrorUtils.reportFatalError(e);
|
|
236
176
|
}
|
|
237
177
|
inGuard = false;
|
|
@@ -306,10 +246,6 @@ function loadModuleImplementation(moduleId, module) {
|
|
|
306
246
|
var Systrace = requireSystrace();
|
|
307
247
|
var Refresh = requireRefresh();
|
|
308
248
|
}
|
|
309
|
-
|
|
310
|
-
// We must optimistically mark module as initialized before running the
|
|
311
|
-
// factory to keep any require cycles inside the factory from causing an
|
|
312
|
-
// infinite require loop.
|
|
313
249
|
module.isInitialized = true;
|
|
314
250
|
const { factory, dependencyMap } = module;
|
|
315
251
|
if (__DEV__) {
|
|
@@ -317,7 +253,6 @@ function loadModuleImplementation(moduleId, module) {
|
|
|
317
253
|
}
|
|
318
254
|
try {
|
|
319
255
|
if (__DEV__) {
|
|
320
|
-
// $FlowIgnore: we know that __DEV__ is const and `Systrace` exists
|
|
321
256
|
Systrace.beginEvent("JS_require_" + (module.verboseName || moduleId));
|
|
322
257
|
}
|
|
323
258
|
const moduleObject = module.publicModule;
|
|
@@ -335,10 +270,6 @@ function loadModuleImplementation(moduleId, module) {
|
|
|
335
270
|
}
|
|
336
271
|
}
|
|
337
272
|
moduleObject.id = moduleId;
|
|
338
|
-
|
|
339
|
-
// keep args in sync with with defineModuleCode in
|
|
340
|
-
// metro/src/Resolver/index.js
|
|
341
|
-
// and metro/src/ModuleGraph/worker.js
|
|
342
273
|
factory(
|
|
343
274
|
global,
|
|
344
275
|
metroRequire,
|
|
@@ -348,15 +279,11 @@ function loadModuleImplementation(moduleId, module) {
|
|
|
348
279
|
moduleObject.exports,
|
|
349
280
|
dependencyMap
|
|
350
281
|
);
|
|
351
|
-
|
|
352
|
-
// avoid removing factory in DEV mode as it breaks HMR
|
|
353
282
|
if (!__DEV__) {
|
|
354
|
-
// $FlowFixMe: This is only sound because we never access `factory` again
|
|
355
283
|
module.factory = undefined;
|
|
356
284
|
module.dependencyMap = undefined;
|
|
357
285
|
}
|
|
358
286
|
if (__DEV__) {
|
|
359
|
-
// $FlowIgnore: we know that __DEV__ is const and `Systrace` exists
|
|
360
287
|
Systrace.endEvent();
|
|
361
288
|
if (Refresh != null) {
|
|
362
289
|
registerExportsForReactRefresh(Refresh, moduleObject.exports, moduleId);
|
|
@@ -391,17 +318,13 @@ function unknownModuleError(id) {
|
|
|
391
318
|
return Error(message);
|
|
392
319
|
}
|
|
393
320
|
if (__DEV__) {
|
|
394
|
-
// $FlowFixMe[prop-missing]
|
|
395
321
|
metroRequire.Systrace = {
|
|
396
322
|
beginEvent: () => {},
|
|
397
323
|
endEvent: () => {},
|
|
398
324
|
};
|
|
399
|
-
// $FlowFixMe[prop-missing]
|
|
400
325
|
metroRequire.getModules = () => {
|
|
401
326
|
return modules;
|
|
402
327
|
};
|
|
403
|
-
|
|
404
|
-
// HOT MODULE RELOADING
|
|
405
328
|
var createHotReloadingObject = function () {
|
|
406
329
|
const hot = {
|
|
407
330
|
_acceptCallback: null,
|
|
@@ -427,48 +350,25 @@ if (__DEV__) {
|
|
|
427
350
|
const mod = modules[id];
|
|
428
351
|
if (!mod) {
|
|
429
352
|
if (factory) {
|
|
430
|
-
// New modules are going to be handled by the define() method.
|
|
431
353
|
return;
|
|
432
354
|
}
|
|
433
355
|
throw unknownModuleError(id);
|
|
434
356
|
}
|
|
435
357
|
if (!mod.hasError && !mod.isInitialized) {
|
|
436
|
-
// The module hasn't actually been executed yet,
|
|
437
|
-
// so we can always safely replace it.
|
|
438
358
|
mod.factory = factory;
|
|
439
359
|
mod.dependencyMap = dependencyMap;
|
|
440
360
|
return;
|
|
441
361
|
}
|
|
442
362
|
const Refresh = requireRefresh();
|
|
443
363
|
const refreshBoundaryIDs = new Set();
|
|
444
|
-
|
|
445
|
-
// In this loop, we will traverse the dependency tree upwards from the
|
|
446
|
-
// changed module. Updates "bubble" up to the closest accepted parent.
|
|
447
|
-
//
|
|
448
|
-
// If we reach the module root and nothing along the way accepted the update,
|
|
449
|
-
// we know hot reload is going to fail. In that case we return false.
|
|
450
|
-
//
|
|
451
|
-
// The main purpose of this loop is to figure out whether it's safe to apply
|
|
452
|
-
// a hot update. It is only safe when the update was accepted somewhere
|
|
453
|
-
// along the way upwards for each of its parent dependency module chains.
|
|
454
|
-
//
|
|
455
|
-
// We perform a topological sort because we may discover the same
|
|
456
|
-
// module more than once in the list of things to re-execute, and
|
|
457
|
-
// we want to execute modules before modules that depend on them.
|
|
458
|
-
//
|
|
459
|
-
// If we didn't have this check, we'd risk re-evaluating modules that
|
|
460
|
-
// have side effects and lead to confusing and meaningless crashes.
|
|
461
|
-
|
|
462
364
|
let didBailOut = false;
|
|
463
365
|
let updatedModuleIDs;
|
|
464
366
|
try {
|
|
465
367
|
updatedModuleIDs = topologicalSort(
|
|
466
368
|
[id],
|
|
467
|
-
// Start with the changed module and go upwards
|
|
468
369
|
(pendingID) => {
|
|
469
370
|
const pendingModule = modules[pendingID];
|
|
470
371
|
if (pendingModule == null) {
|
|
471
|
-
// Nothing to do.
|
|
472
372
|
return [];
|
|
473
373
|
}
|
|
474
374
|
const pendingHot = pendingModule.hot;
|
|
@@ -477,10 +377,8 @@ if (__DEV__) {
|
|
|
477
377
|
"[Refresh] Expected module.hot to always exist in DEV."
|
|
478
378
|
);
|
|
479
379
|
}
|
|
480
|
-
// A module can be accepted manually from within itself.
|
|
481
380
|
let canAccept = pendingHot._didAccept;
|
|
482
381
|
if (!canAccept && Refresh != null) {
|
|
483
|
-
// Or React Refresh may mark it accepted based on exports.
|
|
484
382
|
const isBoundary = isReactRefreshBoundary(
|
|
485
383
|
Refresh,
|
|
486
384
|
pendingModule.publicModule.exports
|
|
@@ -491,15 +389,10 @@ if (__DEV__) {
|
|
|
491
389
|
}
|
|
492
390
|
}
|
|
493
391
|
if (canAccept) {
|
|
494
|
-
// Don't look at parents.
|
|
495
392
|
return [];
|
|
496
393
|
}
|
|
497
|
-
// If we bubble through the roof, there is no way to do a hot update.
|
|
498
|
-
// Bail out altogether. This is the failure case.
|
|
499
394
|
const parentIDs = inverseDependencies[pendingID];
|
|
500
395
|
if (parentIDs.length === 0) {
|
|
501
|
-
// Reload the app because the hot reload can't succeed.
|
|
502
|
-
// This should work both on web and React Native.
|
|
503
396
|
performFullRefresh("No root boundary", {
|
|
504
397
|
source: mod,
|
|
505
398
|
failed: pendingModule,
|
|
@@ -507,11 +400,9 @@ if (__DEV__) {
|
|
|
507
400
|
didBailOut = true;
|
|
508
401
|
return [];
|
|
509
402
|
}
|
|
510
|
-
// This module can't handle the update but maybe all its parents can?
|
|
511
|
-
// Put them all in the queue to run the same set of checks.
|
|
512
403
|
return parentIDs;
|
|
513
404
|
},
|
|
514
|
-
() => didBailOut
|
|
405
|
+
() => didBailOut
|
|
515
406
|
).reverse();
|
|
516
407
|
} catch (e) {
|
|
517
408
|
if (e === CYCLE_DETECTED) {
|
|
@@ -525,9 +416,6 @@ if (__DEV__) {
|
|
|
525
416
|
if (didBailOut) {
|
|
526
417
|
return;
|
|
527
418
|
}
|
|
528
|
-
|
|
529
|
-
// If we reached here, it is likely that hot reload will be successful.
|
|
530
|
-
// Run the actual factories.
|
|
531
419
|
const seenModuleIDs = new Set();
|
|
532
420
|
for (let i = 0; i < updatedModuleIDs.length; i++) {
|
|
533
421
|
const updatedID = updatedModuleIDs[i];
|
|
@@ -547,35 +435,21 @@ if (__DEV__) {
|
|
|
547
435
|
);
|
|
548
436
|
const nextExports = updatedMod.publicModule.exports;
|
|
549
437
|
if (didError) {
|
|
550
|
-
// The user was shown a redbox about module initialization.
|
|
551
|
-
// There's nothing for us to do here until it's fixed.
|
|
552
438
|
return;
|
|
553
439
|
}
|
|
554
440
|
if (refreshBoundaryIDs.has(updatedID)) {
|
|
555
|
-
// Since we just executed the code for it, it's possible
|
|
556
|
-
// that the new exports make it ineligible for being a boundary.
|
|
557
441
|
const isNoLongerABoundary = !isReactRefreshBoundary(
|
|
558
442
|
Refresh,
|
|
559
443
|
nextExports
|
|
560
444
|
);
|
|
561
|
-
// It can also become ineligible if its exports are incompatible
|
|
562
|
-
// with the previous exports.
|
|
563
|
-
// For example, if you add/remove/change exports, we'll want
|
|
564
|
-
// to re-execute the importing modules, and force those components
|
|
565
|
-
// to re-render. Similarly, if you convert a class component
|
|
566
|
-
// to a function, we want to invalidate the boundary.
|
|
567
445
|
const didInvalidate = shouldInvalidateReactRefreshBoundary(
|
|
568
446
|
Refresh,
|
|
569
447
|
prevExports,
|
|
570
448
|
nextExports
|
|
571
449
|
);
|
|
572
450
|
if (isNoLongerABoundary || didInvalidate) {
|
|
573
|
-
// We'll be conservative. The only case in which we won't do a full
|
|
574
|
-
// reload is if all parent modules are also refresh boundaries.
|
|
575
|
-
// In that case we'll add them to the current queue.
|
|
576
451
|
const parentIDs = inverseDependencies[updatedID];
|
|
577
452
|
if (parentIDs.length === 0) {
|
|
578
|
-
// Looks like we bubbled to the root. Can't recover from that.
|
|
579
453
|
performFullRefresh(
|
|
580
454
|
isNoLongerABoundary
|
|
581
455
|
? "No longer a boundary"
|
|
@@ -587,7 +461,6 @@ if (__DEV__) {
|
|
|
587
461
|
);
|
|
588
462
|
return;
|
|
589
463
|
}
|
|
590
|
-
// Schedule all parent refresh boundaries to re-run in this loop.
|
|
591
464
|
for (let j = 0; j < parentIDs.length; j++) {
|
|
592
465
|
const parentID = parentIDs[j];
|
|
593
466
|
const parentMod = modules[parentID];
|
|
@@ -599,7 +472,6 @@ if (__DEV__) {
|
|
|
599
472
|
parentMod.publicModule.exports
|
|
600
473
|
);
|
|
601
474
|
if (canAcceptParent) {
|
|
602
|
-
// All parents will have to re-run too.
|
|
603
475
|
refreshBoundaryIDs.add(parentID);
|
|
604
476
|
updatedModuleIDs.push(parentID);
|
|
605
477
|
} else {
|
|
@@ -614,12 +486,9 @@ if (__DEV__) {
|
|
|
614
486
|
}
|
|
615
487
|
}
|
|
616
488
|
if (Refresh != null) {
|
|
617
|
-
// Debounce a little in case there are multiple updates queued up.
|
|
618
|
-
// This is also useful because __accept may be called multiple times.
|
|
619
489
|
if (reactRefreshTimeout == null) {
|
|
620
490
|
reactRefreshTimeout = setTimeout(() => {
|
|
621
491
|
reactRefreshTimeout = null;
|
|
622
|
-
// Update React components.
|
|
623
492
|
Refresh.performReactRefresh();
|
|
624
493
|
}, 30);
|
|
625
494
|
}
|
|
@@ -691,17 +560,10 @@ if (__DEV__) {
|
|
|
691
560
|
hot._disposeCallback = null;
|
|
692
561
|
metroRequire(id);
|
|
693
562
|
if (mod.hasError) {
|
|
694
|
-
// This error has already been reported via a redbox.
|
|
695
|
-
// We know it's likely a typo or some mistake that was just introduced.
|
|
696
|
-
// Our goal now is to keep the rest of the application working so that by
|
|
697
|
-
// the time user fixes the error, the app isn't completely destroyed
|
|
698
|
-
// underneath the redbox. So we'll revert the module object to the last
|
|
699
|
-
// successful export and stop propagating this update.
|
|
700
563
|
mod.hasError = false;
|
|
701
564
|
mod.isInitialized = true;
|
|
702
565
|
mod.error = null;
|
|
703
566
|
mod.publicModule.exports = prevExports;
|
|
704
|
-
// We errored. Stop the update.
|
|
705
567
|
return true;
|
|
706
568
|
}
|
|
707
569
|
if (hot._acceptCallback) {
|
|
@@ -714,11 +576,9 @@ if (__DEV__) {
|
|
|
714
576
|
);
|
|
715
577
|
}
|
|
716
578
|
}
|
|
717
|
-
// No error.
|
|
718
579
|
return false;
|
|
719
580
|
};
|
|
720
581
|
const performFullRefresh = (reason, modules) => {
|
|
721
|
-
/* global window */
|
|
722
582
|
if (
|
|
723
583
|
typeof window !== "undefined" &&
|
|
724
584
|
window.location != null &&
|
|
@@ -738,14 +598,11 @@ if (__DEV__) {
|
|
|
738
598
|
}
|
|
739
599
|
}
|
|
740
600
|
};
|
|
741
|
-
|
|
742
|
-
// Modules that only export components become React Refresh boundaries.
|
|
743
601
|
var isReactRefreshBoundary = function (Refresh, moduleExports) {
|
|
744
602
|
if (Refresh.isLikelyComponentType(moduleExports)) {
|
|
745
603
|
return true;
|
|
746
604
|
}
|
|
747
605
|
if (moduleExports == null || typeof moduleExports !== "object") {
|
|
748
|
-
// Exit if we can't iterate over exports.
|
|
749
606
|
return false;
|
|
750
607
|
}
|
|
751
608
|
let hasExports = false;
|
|
@@ -757,7 +614,6 @@ if (__DEV__) {
|
|
|
757
614
|
}
|
|
758
615
|
const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
|
|
759
616
|
if (desc && desc.get) {
|
|
760
|
-
// Don't invoke getters as they may have side effects.
|
|
761
617
|
return false;
|
|
762
618
|
}
|
|
763
619
|
const exportValue = moduleExports[key];
|
|
@@ -784,14 +640,10 @@ if (__DEV__) {
|
|
|
784
640
|
}
|
|
785
641
|
return false;
|
|
786
642
|
};
|
|
787
|
-
|
|
788
|
-
// When this signature changes, it's unsafe to stop at this refresh boundary.
|
|
789
643
|
var getRefreshBoundarySignature = (Refresh, moduleExports) => {
|
|
790
644
|
const signature = [];
|
|
791
645
|
signature.push(Refresh.getFamilyByType(moduleExports));
|
|
792
646
|
if (moduleExports == null || typeof moduleExports !== "object") {
|
|
793
|
-
// Exit if we can't iterate over exports.
|
|
794
|
-
// (This is important for legacy environments.)
|
|
795
647
|
return signature;
|
|
796
648
|
}
|
|
797
649
|
for (const key in moduleExports) {
|
|
@@ -811,14 +663,11 @@ if (__DEV__) {
|
|
|
811
663
|
var registerExportsForReactRefresh = (Refresh, moduleExports, moduleID) => {
|
|
812
664
|
Refresh.register(moduleExports, moduleID + " %exports%");
|
|
813
665
|
if (moduleExports == null || typeof moduleExports !== "object") {
|
|
814
|
-
// Exit if we can't iterate over exports.
|
|
815
|
-
// (This is important for legacy environments.)
|
|
816
666
|
return;
|
|
817
667
|
}
|
|
818
668
|
for (const key in moduleExports) {
|
|
819
669
|
const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
|
|
820
670
|
if (desc && desc.get) {
|
|
821
|
-
// Don't invoke getters as they may have side effects.
|
|
822
671
|
continue;
|
|
823
672
|
}
|
|
824
673
|
const exportValue = moduleExports[key];
|
|
@@ -829,21 +678,13 @@ if (__DEV__) {
|
|
|
829
678
|
global.__accept = metroHotUpdateModule;
|
|
830
679
|
}
|
|
831
680
|
if (__DEV__) {
|
|
832
|
-
// The metro require polyfill can not have module dependencies.
|
|
833
|
-
// The Systrace and ReactRefresh dependencies are, therefore, made publicly
|
|
834
|
-
// available. Ideally, the dependency would be inversed in a way that
|
|
835
|
-
// Systrace / ReactRefresh could integrate into Metro rather than
|
|
836
|
-
// having to make them publicly available.
|
|
837
|
-
|
|
838
681
|
var requireSystrace = function requireSystrace() {
|
|
839
682
|
return (
|
|
840
|
-
// $FlowFixMe[prop-missing]
|
|
841
683
|
global[__METRO_GLOBAL_PREFIX__ + "__SYSTRACE"] || metroRequire.Systrace
|
|
842
684
|
);
|
|
843
685
|
};
|
|
844
686
|
var requireRefresh = function requireRefresh() {
|
|
845
687
|
return (
|
|
846
|
-
// $FlowFixMe[prop-missing]
|
|
847
688
|
global[__METRO_GLOBAL_PREFIX__ + "__ReactRefresh"] || metroRequire.Refresh
|
|
848
689
|
);
|
|
849
690
|
};
|