metro-runtime 0.66.2 → 0.67.0
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 +13 -13
- package/src/modules/HMRClient.js.flow +7 -6
- package/src/modules/asyncRequire.js +2 -2
- package/src/modules/asyncRequire.js.flow +2 -2
- package/src/modules/empty-module.js +10 -0
- package/src/modules/empty-module.js.flow +9 -0
- package/src/modules/types.flow.js +1 -1
- package/src/modules/types.flow.js.flow +1 -1
- package/src/polyfills/require.js +22 -22
- package/src/polyfills/require.js.flow +7 -9
package/package.json
CHANGED
package/src/modules/HMRClient.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -22,7 +22,7 @@ const inject = ({ module: [id, code], sourceURL }) => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const injectUpdate = update => {
|
|
25
|
+
const injectUpdate = (update) => {
|
|
26
26
|
update.added.forEach(inject);
|
|
27
27
|
update.modified.forEach(inject);
|
|
28
28
|
};
|
|
@@ -46,7 +46,7 @@ class HMRClient extends EventEmitter {
|
|
|
46
46
|
this._flushQueue();
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
this._ws.onerror = error => {
|
|
49
|
+
this._ws.onerror = (error) => {
|
|
50
50
|
this.emit("connection-error", error);
|
|
51
51
|
};
|
|
52
52
|
|
|
@@ -55,8 +55,8 @@ class HMRClient extends EventEmitter {
|
|
|
55
55
|
this.emit("close");
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
this._ws.onmessage = message => {
|
|
59
|
-
const data = JSON.parse(message.data);
|
|
58
|
+
this._ws.onmessage = (message) => {
|
|
59
|
+
const data = JSON.parse(String(message.data));
|
|
60
60
|
|
|
61
61
|
switch (data.type) {
|
|
62
62
|
case "bundle-registered":
|
|
@@ -82,12 +82,12 @@ class HMRClient extends EventEmitter {
|
|
|
82
82
|
default:
|
|
83
83
|
this.emit("error", {
|
|
84
84
|
type: "unknown-message",
|
|
85
|
-
message: data
|
|
85
|
+
message: data,
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
this.on("update", update => {
|
|
90
|
+
this.on("update", (update) => {
|
|
91
91
|
if (this._isEnabled) {
|
|
92
92
|
injectUpdate(update);
|
|
93
93
|
} else if (this._pendingUpdate == null) {
|
|
@@ -124,7 +124,7 @@ class HMRClient extends EventEmitter {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
_flushQueue() {
|
|
127
|
-
this._queue.forEach(message => this.send(message));
|
|
127
|
+
this._queue.forEach((message) => this.send(message));
|
|
128
128
|
|
|
129
129
|
this._queue.length = 0;
|
|
130
130
|
}
|
|
@@ -161,7 +161,7 @@ function mergeUpdates(base, next) {
|
|
|
161
161
|
applyUpdateLocally(next);
|
|
162
162
|
|
|
163
163
|
function applyUpdateLocally(update) {
|
|
164
|
-
update.deleted.forEach(id => {
|
|
164
|
+
update.deleted.forEach((id) => {
|
|
165
165
|
if (addedIDs.has(id)) {
|
|
166
166
|
addedIDs.delete(id);
|
|
167
167
|
} else {
|
|
@@ -170,7 +170,7 @@ function mergeUpdates(base, next) {
|
|
|
170
170
|
|
|
171
171
|
moduleMap.delete(id);
|
|
172
172
|
});
|
|
173
|
-
update.added.forEach(item => {
|
|
173
|
+
update.added.forEach((item) => {
|
|
174
174
|
const id = item.module[0];
|
|
175
175
|
|
|
176
176
|
if (deletedIDs.has(id)) {
|
|
@@ -181,7 +181,7 @@ function mergeUpdates(base, next) {
|
|
|
181
181
|
|
|
182
182
|
moduleMap.set(id, item);
|
|
183
183
|
});
|
|
184
|
-
update.modified.forEach(item => {
|
|
184
|
+
update.modified.forEach((item) => {
|
|
185
185
|
const id = item.module[0];
|
|
186
186
|
moduleMap.set(id, item);
|
|
187
187
|
});
|
|
@@ -193,9 +193,9 @@ function mergeUpdates(base, next) {
|
|
|
193
193
|
revisionId: next.revisionId,
|
|
194
194
|
added: [],
|
|
195
195
|
modified: [],
|
|
196
|
-
deleted: []
|
|
196
|
+
deleted: [],
|
|
197
197
|
};
|
|
198
|
-
deletedIDs.forEach(id => {
|
|
198
|
+
deletedIDs.forEach((id) => {
|
|
199
199
|
result.deleted.push(id);
|
|
200
200
|
});
|
|
201
201
|
moduleMap.forEach((item, id) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
-
|
|
13
|
-
const EventEmitter = require('./vendor/eventemitter3');
|
|
12
|
+
import type {HmrModule} from './types.flow';
|
|
14
13
|
|
|
15
14
|
import type {HmrMessage, HmrUpdate} from './types.flow';
|
|
16
15
|
|
|
16
|
+
const EventEmitter = require('./vendor/eventemitter3');
|
|
17
|
+
|
|
17
18
|
type SocketState = 'opening' | 'open' | 'closed';
|
|
18
19
|
|
|
19
|
-
const inject = ({module: [id, code], sourceURL}) => {
|
|
20
|
+
const inject = ({module: [id, code], sourceURL}: HmrModule) => {
|
|
20
21
|
// Some engines do not support `sourceURL` as a comment. We expose a
|
|
21
22
|
// `globalEvalWithSourceUrl` function to handle updates in that case.
|
|
22
23
|
if (global.globalEvalWithSourceUrl) {
|
|
@@ -27,7 +28,7 @@ const inject = ({module: [id, code], sourceURL}) => {
|
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
const injectUpdate = update => {
|
|
31
|
+
const injectUpdate = (update: HmrUpdate) => {
|
|
31
32
|
update.added.forEach(inject);
|
|
32
33
|
update.modified.forEach(inject);
|
|
33
34
|
};
|
|
@@ -58,7 +59,7 @@ class HMRClient extends EventEmitter {
|
|
|
58
59
|
this.emit('close');
|
|
59
60
|
};
|
|
60
61
|
this._ws.onmessage = message => {
|
|
61
|
-
const data: HmrMessage = JSON.parse(message.data);
|
|
62
|
+
const data: HmrMessage = JSON.parse(String(message.data));
|
|
62
63
|
|
|
63
64
|
switch (data.type) {
|
|
64
65
|
case 'bundle-registered':
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
const dynamicRequire = require;
|
|
13
13
|
|
|
14
|
-
module.exports = function(moduleID) {
|
|
14
|
+
module.exports = function (moduleID) {
|
|
15
15
|
return Promise.resolve().then(() => dynamicRequire.importAll(moduleID));
|
|
16
16
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
// $FlowExpectedError Flow does not know about Metro's require extensions.
|
|
14
14
|
const dynamicRequire = (require: {importAll: mixed => mixed});
|
|
15
|
-
module.exports = function(moduleID: mixed): Promise<mixed> {
|
|
15
|
+
module.exports = function (moduleID: mixed): Promise<mixed> {
|
|
16
16
|
return Promise.resolve().then(() => dynamicRequire.importAll(moduleID));
|
|
17
17
|
};
|
package/src/polyfills/require.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -24,7 +24,7 @@ const { hasOwnProperty } = {};
|
|
|
24
24
|
if (__DEV__) {
|
|
25
25
|
global.$RefreshReg$ = () => {};
|
|
26
26
|
|
|
27
|
-
global.$RefreshSig$ = () => type => type;
|
|
27
|
+
global.$RefreshSig$ = () => (type) => type;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function clear() {
|
|
@@ -65,8 +65,8 @@ function define(factory, moduleId, dependencyMap) {
|
|
|
65
65
|
importedDefault: EMPTY,
|
|
66
66
|
isInitialized: false,
|
|
67
67
|
publicModule: {
|
|
68
|
-
exports: {}
|
|
69
|
-
}
|
|
68
|
+
exports: {},
|
|
69
|
+
},
|
|
70
70
|
};
|
|
71
71
|
modules[moduleId] = mod;
|
|
72
72
|
|
|
@@ -110,7 +110,7 @@ function metroRequire(moduleId) {
|
|
|
110
110
|
if (initializingIndex !== -1) {
|
|
111
111
|
const cycle = initializingModuleIds
|
|
112
112
|
.slice(initializingIndex)
|
|
113
|
-
.map(id => (modules[id] ? modules[id].verboseName : "[unknown]")); // We want to show A -> B -> A:
|
|
113
|
+
.map((id) => (modules[id] ? modules[id].verboseName : "[unknown]")); // We want to show A -> B -> A:
|
|
114
114
|
|
|
115
115
|
cycle.push(cycle[0]);
|
|
116
116
|
console.warn(
|
|
@@ -218,7 +218,7 @@ function unpackModuleId(moduleId) {
|
|
|
218
218
|
const localId = moduleId & LOCAL_ID_MASK;
|
|
219
219
|
return {
|
|
220
220
|
segmentId,
|
|
221
|
-
localId
|
|
221
|
+
localId,
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -251,7 +251,7 @@ function registerSegment(segmentId, moduleDefiner, moduleIds) {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
if (moduleIds) {
|
|
254
|
-
moduleIds.forEach(moduleId => {
|
|
254
|
+
moduleIds.forEach((moduleId) => {
|
|
255
255
|
if (!modules[moduleId] && !definingSegmentByModuleID.has(moduleId)) {
|
|
256
256
|
definingSegmentByModuleID.set(moduleId, segmentId);
|
|
257
257
|
}
|
|
@@ -404,32 +404,32 @@ function moduleThrewError(id, error) {
|
|
|
404
404
|
if (__DEV__) {
|
|
405
405
|
metroRequire.Systrace = {
|
|
406
406
|
beginEvent: () => {},
|
|
407
|
-
endEvent: () => {}
|
|
407
|
+
endEvent: () => {},
|
|
408
408
|
};
|
|
409
409
|
|
|
410
410
|
metroRequire.getModules = () => {
|
|
411
411
|
return modules;
|
|
412
412
|
}; // HOT MODULE RELOADING
|
|
413
413
|
|
|
414
|
-
var createHotReloadingObject = function() {
|
|
414
|
+
var createHotReloadingObject = function () {
|
|
415
415
|
const hot = {
|
|
416
416
|
_acceptCallback: null,
|
|
417
417
|
_disposeCallback: null,
|
|
418
418
|
_didAccept: false,
|
|
419
|
-
accept: callback => {
|
|
419
|
+
accept: (callback) => {
|
|
420
420
|
hot._didAccept = true;
|
|
421
421
|
hot._acceptCallback = callback;
|
|
422
422
|
},
|
|
423
|
-
dispose: callback => {
|
|
423
|
+
dispose: (callback) => {
|
|
424
424
|
hot._disposeCallback = callback;
|
|
425
|
-
}
|
|
425
|
+
},
|
|
426
426
|
};
|
|
427
427
|
return hot;
|
|
428
428
|
};
|
|
429
429
|
|
|
430
430
|
let reactRefreshTimeout = null;
|
|
431
431
|
|
|
432
|
-
const metroHotUpdateModule = function(
|
|
432
|
+
const metroHotUpdateModule = function (
|
|
433
433
|
id,
|
|
434
434
|
factory,
|
|
435
435
|
dependencyMap,
|
|
@@ -475,7 +475,7 @@ if (__DEV__) {
|
|
|
475
475
|
let didBailOut = false;
|
|
476
476
|
const updatedModuleIDs = topologicalSort(
|
|
477
477
|
[id], // Start with the changed module and go upwards
|
|
478
|
-
pendingID => {
|
|
478
|
+
(pendingID) => {
|
|
479
479
|
const pendingModule = modules[pendingID];
|
|
480
480
|
|
|
481
481
|
if (pendingModule == null) {
|
|
@@ -519,7 +519,7 @@ if (__DEV__) {
|
|
|
519
519
|
// This should work both on web and React Native.
|
|
520
520
|
performFullRefresh("No root boundary", {
|
|
521
521
|
source: mod,
|
|
522
|
-
failed: pendingModule
|
|
522
|
+
failed: pendingModule,
|
|
523
523
|
});
|
|
524
524
|
didBailOut = true;
|
|
525
525
|
return [];
|
|
@@ -600,7 +600,7 @@ if (__DEV__) {
|
|
|
600
600
|
: "Invalidated boundary",
|
|
601
601
|
{
|
|
602
602
|
source: mod,
|
|
603
|
-
failed: updatedMod
|
|
603
|
+
failed: updatedMod,
|
|
604
604
|
}
|
|
605
605
|
);
|
|
606
606
|
return;
|
|
@@ -626,7 +626,7 @@ if (__DEV__) {
|
|
|
626
626
|
} else {
|
|
627
627
|
performFullRefresh("Invalidated boundary", {
|
|
628
628
|
source: mod,
|
|
629
|
-
failed: parentMod
|
|
629
|
+
failed: parentMod,
|
|
630
630
|
});
|
|
631
631
|
return;
|
|
632
632
|
}
|
|
@@ -648,7 +648,7 @@ if (__DEV__) {
|
|
|
648
648
|
}
|
|
649
649
|
};
|
|
650
650
|
|
|
651
|
-
const topologicalSort = function(roots, getEdges, earlyStop) {
|
|
651
|
+
const topologicalSort = function (roots, getEdges, earlyStop) {
|
|
652
652
|
const result = [];
|
|
653
653
|
const visited = new Set();
|
|
654
654
|
|
|
@@ -660,7 +660,7 @@ if (__DEV__) {
|
|
|
660
660
|
return;
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
-
dependentNodes.forEach(dependent => {
|
|
663
|
+
dependentNodes.forEach((dependent) => {
|
|
664
664
|
if (visited.has(dependent)) {
|
|
665
665
|
return;
|
|
666
666
|
}
|
|
@@ -670,7 +670,7 @@ if (__DEV__) {
|
|
|
670
670
|
result.push(node);
|
|
671
671
|
}
|
|
672
672
|
|
|
673
|
-
roots.forEach(root => {
|
|
673
|
+
roots.forEach((root) => {
|
|
674
674
|
if (!visited.has(root)) {
|
|
675
675
|
traverseDependentNodes(root);
|
|
676
676
|
}
|
|
@@ -678,7 +678,7 @@ if (__DEV__) {
|
|
|
678
678
|
return result;
|
|
679
679
|
};
|
|
680
680
|
|
|
681
|
-
const runUpdatedModule = function(id, factory, dependencyMap) {
|
|
681
|
+
const runUpdatedModule = function (id, factory, dependencyMap) {
|
|
682
682
|
const mod = modules[id];
|
|
683
683
|
|
|
684
684
|
if (mod == null) {
|
|
@@ -795,7 +795,7 @@ if (__DEV__) {
|
|
|
795
795
|
}
|
|
796
796
|
}; // Modules that only export components become React Refresh boundaries.
|
|
797
797
|
|
|
798
|
-
var isReactRefreshBoundary = function(Refresh, moduleExports) {
|
|
798
|
+
var isReactRefreshBoundary = function (Refresh, moduleExports) {
|
|
799
799
|
if (Refresh.isLikelyComponentType(moduleExports)) {
|
|
800
800
|
return true;
|
|
801
801
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -283,9 +283,7 @@ function guardedLoadModule(
|
|
|
283
283
|
const ID_MASK_SHIFT = 16;
|
|
284
284
|
const LOCAL_ID_MASK = ~0 >>> ID_MASK_SHIFT;
|
|
285
285
|
|
|
286
|
-
function unpackModuleId(
|
|
287
|
-
moduleId: ModuleID,
|
|
288
|
-
): {
|
|
286
|
+
function unpackModuleId(moduleId: ModuleID): {
|
|
289
287
|
localId: number,
|
|
290
288
|
segmentId: number,
|
|
291
289
|
...
|
|
@@ -482,7 +480,7 @@ if (__DEV__) {
|
|
|
482
480
|
};
|
|
483
481
|
|
|
484
482
|
// HOT MODULE RELOADING
|
|
485
|
-
var createHotReloadingObject = function() {
|
|
483
|
+
var createHotReloadingObject = function () {
|
|
486
484
|
const hot: HotModuleReloadingData = {
|
|
487
485
|
_acceptCallback: null,
|
|
488
486
|
_disposeCallback: null,
|
|
@@ -500,7 +498,7 @@ if (__DEV__) {
|
|
|
500
498
|
|
|
501
499
|
let reactRefreshTimeout = null;
|
|
502
500
|
|
|
503
|
-
const metroHotUpdateModule = function(
|
|
501
|
+
const metroHotUpdateModule = function (
|
|
504
502
|
id: ModuleID,
|
|
505
503
|
factory: FactoryFn,
|
|
506
504
|
dependencyMap: DependencyMap,
|
|
@@ -704,7 +702,7 @@ if (__DEV__) {
|
|
|
704
702
|
}
|
|
705
703
|
};
|
|
706
704
|
|
|
707
|
-
const topologicalSort = function<T>(
|
|
705
|
+
const topologicalSort = function <T>(
|
|
708
706
|
roots: Array<T>,
|
|
709
707
|
getEdges: T => Array<T>,
|
|
710
708
|
earlyStop: T => boolean,
|
|
@@ -733,7 +731,7 @@ if (__DEV__) {
|
|
|
733
731
|
return result;
|
|
734
732
|
};
|
|
735
733
|
|
|
736
|
-
const runUpdatedModule = function(
|
|
734
|
+
const runUpdatedModule = function (
|
|
737
735
|
id: ModuleID,
|
|
738
736
|
factory?: FactoryFn,
|
|
739
737
|
dependencyMap?: DependencyMap,
|
|
@@ -832,7 +830,7 @@ if (__DEV__) {
|
|
|
832
830
|
};
|
|
833
831
|
|
|
834
832
|
// Modules that only export components become React Refresh boundaries.
|
|
835
|
-
var isReactRefreshBoundary = function(Refresh, moduleExports): boolean {
|
|
833
|
+
var isReactRefreshBoundary = function (Refresh, moduleExports): boolean {
|
|
836
834
|
if (Refresh.isLikelyComponentType(moduleExports)) {
|
|
837
835
|
return true;
|
|
838
836
|
}
|