metro-runtime 0.83.1 → 0.83.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-runtime",
3
- "version": "0.83.1",
3
+ "version": "0.83.2",
4
4
  "description": "🚇 Module required for evaluating Metro bundles.",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.25.2",
31
- "react": "19.1.0",
31
+ "react": "19.1.1",
32
32
  "react-refresh": "^0.14.0",
33
- "react-test-renderer": "19.1.0"
33
+ "react-test-renderer": "19.1.1"
34
34
  },
35
35
  "engines": {
36
36
  "node": ">=20.19.4"
@@ -10,8 +10,8 @@
10
10
  */
11
11
 
12
12
  'use strict';
13
- import type {HmrModule} from './types.flow';
14
- import type {HmrMessage, HmrUpdate} from './types.flow';
13
+ import type {HmrModule} from './types';
14
+ import type {HmrMessage, HmrUpdate} from './types';
15
15
 
16
16
  const EventEmitter = require('./vendor/eventemitter3');
17
17
 
@@ -26,14 +26,14 @@ async function asyncRequire(moduleID, paths, moduleName) {
26
26
  }
27
27
  asyncRequire.unstable_importMaybeSync = function unstable_importMaybeSync(
28
28
  moduleID,
29
- paths
29
+ paths,
30
30
  ) {
31
31
  return asyncRequireImpl(moduleID, paths);
32
32
  };
33
33
  asyncRequire.prefetch = function (moduleID, paths, moduleName) {
34
34
  maybeLoadBundle(moduleID, paths)?.then(
35
35
  () => {},
36
- () => {}
36
+ () => {},
37
37
  );
38
38
  };
39
39
  module.exports = asyncRequire;
@@ -9,8 +9,6 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  export type ModuleMap = $ReadOnlyArray<[number, string]>;
15
13
 
16
14
  export type Bundle = {
@@ -82,7 +80,6 @@ export type HmrClientMessage =
82
80
  | 'groupEnd'
83
81
  | 'debug',
84
82
  +data: Array<mixed>,
85
- +mode: 'BRIDGE' | 'NOBRIDGE',
86
83
  }
87
84
  | {
88
85
  +type: 'log-opt-in',
@@ -19,7 +19,7 @@ function addListener(emitter, event, fn, context, once) {
19
19
  var listener = new EE(fn, context || emitter, once),
20
20
  evt = prefix ? prefix + event : event;
21
21
  if (!emitter._events[evt])
22
- (emitter._events[evt] = listener), emitter._eventsCount++;
22
+ ((emitter._events[evt] = listener), emitter._eventsCount++);
23
23
  else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
24
24
  else emitter._events[evt] = [emitter._events[evt], listener];
25
25
  return emitter;
@@ -74,17 +74,17 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
74
74
  this.removeListener(event, listeners.fn, undefined, true);
75
75
  switch (len) {
76
76
  case 1:
77
- return listeners.fn.call(listeners.context), true;
77
+ return (listeners.fn.call(listeners.context), true);
78
78
  case 2:
79
- return listeners.fn.call(listeners.context, a1), true;
79
+ return (listeners.fn.call(listeners.context, a1), true);
80
80
  case 3:
81
- return listeners.fn.call(listeners.context, a1, a2), true;
81
+ return (listeners.fn.call(listeners.context, a1, a2), true);
82
82
  case 4:
83
- return listeners.fn.call(listeners.context, a1, a2, a3), true;
83
+ return (listeners.fn.call(listeners.context, a1, a2, a3), true);
84
84
  case 5:
85
- return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
85
+ return (listeners.fn.call(listeners.context, a1, a2, a3, a4), true);
86
86
  case 6:
87
- return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
87
+ return (listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true);
88
88
  }
89
89
  for (i = 1, args = new Array(len - 1); i < len; i++) {
90
90
  args[i - 1] = arguments[i];
@@ -130,7 +130,7 @@ EventEmitter.prototype.removeListener = function removeListener(
130
130
  event,
131
131
  fn,
132
132
  context,
133
- once
133
+ once,
134
134
  ) {
135
135
  var evt = prefix ? prefix + event : event;
136
136
  if (!this._events[evt]) return this;
@@ -70,13 +70,13 @@ function metroRequire(moduleId, maybeNameForDev) {
70
70
  moduleId = getModuleIdForVerboseName(verboseName);
71
71
  console.warn(
72
72
  `Requiring module "${verboseName}" by name is only supported for ` +
73
- "debugging purposes and will BREAK IN PRODUCTION!"
73
+ "debugging purposes and will BREAK IN PRODUCTION!",
74
74
  );
75
75
  }
76
76
  const moduleIdReallyIsNumber = moduleId;
77
77
  if (__DEV__) {
78
78
  const initializingIndex = initializingModuleIds.indexOf(
79
- moduleIdReallyIsNumber
79
+ moduleIdReallyIsNumber,
80
80
  );
81
81
  if (initializingIndex !== -1) {
82
82
  const cycle = initializingModuleIds
@@ -87,7 +87,7 @@ function metroRequire(moduleId, maybeNameForDev) {
87
87
  console.warn(
88
88
  `Require cycle: ${cycle.join(" -> ")}\n\n` +
89
89
  "Require cycles are allowed, but can result in uninitialized values. " +
90
- "Consider refactoring to remove the need for a cycle."
90
+ "Consider refactoring to remove the need for a cycle.",
91
91
  );
92
92
  }
93
93
  }
@@ -159,17 +159,17 @@ metroRequire.importAll = metroImportAll;
159
159
  metroRequire.context = function fallbackRequireContext() {
160
160
  if (__DEV__) {
161
161
  throw new Error(
162
- "The experimental Metro feature `require.context` is not enabled in your project.\nThis can be enabled by setting the `transformer.unstable_allowRequireContext` property to `true` in your Metro configuration."
162
+ "The experimental Metro feature `require.context` is not enabled in your project.\nThis can be enabled by setting the `transformer.unstable_allowRequireContext` property to `true` in your Metro configuration.",
163
163
  );
164
164
  }
165
165
  throw new Error(
166
- "The experimental Metro feature `require.context` is not enabled in your project."
166
+ "The experimental Metro feature `require.context` is not enabled in your project.",
167
167
  );
168
168
  };
169
169
  metroRequire.resolveWeak = function fallbackRequireResolveWeak() {
170
170
  if (__DEV__) {
171
171
  throw new Error(
172
- "require.resolveWeak cannot be called dynamically. Ensure you are using the same version of `metro` and `metro-runtime`."
172
+ "require.resolveWeak cannot be called dynamically. Ensure you are using the same version of `metro` and `metro-runtime`.",
173
173
  );
174
174
  }
175
175
  throw new Error("require.resolveWeak cannot be called dynamically.");
@@ -212,13 +212,13 @@ function registerSegment(segmentId, moduleDefiner, moduleIds) {
212
212
  if (__DEV__) {
213
213
  if (segmentId === 0 && moduleIds) {
214
214
  throw new Error(
215
- "registerSegment: Expected moduleIds to be null for main segment"
215
+ "registerSegment: Expected moduleIds to be null for main segment",
216
216
  );
217
217
  }
218
218
  if (segmentId !== 0 && !moduleIds) {
219
219
  throw new Error(
220
220
  "registerSegment: Expected moduleIds to be passed for segment #" +
221
- segmentId
221
+ segmentId,
222
222
  );
223
223
  }
224
224
  }
@@ -289,7 +289,7 @@ function loadModuleImplementation(moduleId, module) {
289
289
  metroImportAll,
290
290
  moduleObject,
291
291
  moduleObject.exports,
292
- dependencyMap
292
+ dependencyMap,
293
293
  );
294
294
  if (!__DEV__) {
295
295
  module.factory = undefined;
@@ -302,7 +302,7 @@ function loadModuleImplementation(moduleId, module) {
302
302
  registerExportsForReactRefresh(
303
303
  Refresh,
304
304
  moduleObject.exports,
305
- prefixedModuleId
305
+ prefixedModuleId,
306
306
  );
307
307
  }
308
308
  }
@@ -317,7 +317,7 @@ function loadModuleImplementation(moduleId, module) {
317
317
  if (__DEV__) {
318
318
  if (initializingModuleIds.pop() !== moduleId) {
319
319
  throw new Error(
320
- "initializingModuleIds is corrupt; something is terribly wrong"
320
+ "initializingModuleIds is corrupt; something is terribly wrong",
321
321
  );
322
322
  }
323
323
  global.$RefreshReg$ = prevRefreshReg;
@@ -362,7 +362,7 @@ if (__DEV__) {
362
362
  id,
363
363
  factory,
364
364
  dependencyMap,
365
- inverseDependencies
365
+ inverseDependencies,
366
366
  ) {
367
367
  const mod = modules.get(id);
368
368
  if (!mod) {
@@ -391,14 +391,14 @@ if (__DEV__) {
391
391
  const pendingHot = pendingModule.hot;
392
392
  if (pendingHot == null) {
393
393
  throw new Error(
394
- "[Refresh] Expected module.hot to always exist in DEV."
394
+ "[Refresh] Expected module.hot to always exist in DEV.",
395
395
  );
396
396
  }
397
397
  let canAccept = pendingHot._didAccept;
398
398
  if (!canAccept && Refresh != null) {
399
399
  const isBoundary = isReactRefreshBoundary(
400
400
  Refresh,
401
- pendingModule.publicModule.exports
401
+ pendingModule.publicModule.exports,
402
402
  );
403
403
  if (isBoundary) {
404
404
  canAccept = true;
@@ -419,7 +419,7 @@ if (__DEV__) {
419
419
  }
420
420
  return parentIDs;
421
421
  },
422
- () => didBailOut
422
+ () => didBailOut,
423
423
  ).reverse();
424
424
  } catch (e) {
425
425
  if (e === CYCLE_DETECTED) {
@@ -448,7 +448,7 @@ if (__DEV__) {
448
448
  const didError = runUpdatedModule(
449
449
  updatedID,
450
450
  updatedID === id ? factory : undefined,
451
- updatedID === id ? dependencyMap : undefined
451
+ updatedID === id ? dependencyMap : undefined,
452
452
  );
453
453
  const nextExports = updatedMod.publicModule.exports;
454
454
  if (didError) {
@@ -457,12 +457,12 @@ if (__DEV__) {
457
457
  if (refreshBoundaryIDs.has(updatedID)) {
458
458
  const isNoLongerABoundary = !isReactRefreshBoundary(
459
459
  Refresh,
460
- nextExports
460
+ nextExports,
461
461
  );
462
462
  const didInvalidate = shouldInvalidateReactRefreshBoundary(
463
463
  Refresh,
464
464
  prevExports,
465
- nextExports
465
+ nextExports,
466
466
  );
467
467
  if (isNoLongerABoundary || didInvalidate) {
468
468
  const parentIDs = inverseDependencies[updatedID];
@@ -474,7 +474,7 @@ if (__DEV__) {
474
474
  {
475
475
  source: mod,
476
476
  failed: updatedMod,
477
- }
477
+ },
478
478
  );
479
479
  return;
480
480
  }
@@ -486,7 +486,7 @@ if (__DEV__) {
486
486
  }
487
487
  const canAcceptParent = isReactRefreshBoundary(
488
488
  Refresh,
489
- parentMod.publicModule.exports
489
+ parentMod.publicModule.exports,
490
490
  );
491
491
  if (canAcceptParent) {
492
492
  refreshBoundaryIDs.add(parentID);
@@ -555,7 +555,7 @@ if (__DEV__) {
555
555
  } catch (error) {
556
556
  console.error(
557
557
  `Error while calling dispose handler for module ${id}: `,
558
- error
558
+ error,
559
559
  );
560
560
  }
561
561
  }
@@ -589,7 +589,7 @@ if (__DEV__) {
589
589
  } catch (error) {
590
590
  console.error(
591
591
  `Error while calling accept handler for module ${id}: `,
592
- error
592
+ error,
593
593
  );
594
594
  }
595
595
  }
@@ -608,13 +608,19 @@ if (__DEV__) {
608
608
  const sourceName = modules.source?.verboseName ?? "unknown";
609
609
  const failedName = modules.failed?.verboseName ?? "unknown";
610
610
  Refresh.performFullRefresh(
611
- `Fast Refresh - ${reason} <${sourceName}> <${failedName}>`
611
+ `Fast Refresh - ${reason} <${sourceName}> <${failedName}>`,
612
612
  );
613
613
  } else {
614
614
  console.warn("Could not reload the application after an edit.");
615
615
  }
616
616
  }
617
617
  };
618
+ const isExportSafeToAccess = (moduleExports, key) => {
619
+ return (
620
+ moduleExports?.__esModule ||
621
+ Object.getOwnPropertyDescriptor(moduleExports, key)?.get == null
622
+ );
623
+ };
618
624
  var isReactRefreshBoundary = function (Refresh, moduleExports) {
619
625
  if (Refresh.isLikelyComponentType(moduleExports)) {
620
626
  return true;
@@ -628,9 +634,7 @@ if (__DEV__) {
628
634
  hasExports = true;
629
635
  if (key === "__esModule") {
630
636
  continue;
631
- }
632
- const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
633
- if (desc && desc.get) {
637
+ } else if (!isExportSafeToAccess(moduleExports, key)) {
634
638
  return false;
635
639
  }
636
640
  const exportValue = moduleExports[key];
@@ -643,7 +647,7 @@ if (__DEV__) {
643
647
  var shouldInvalidateReactRefreshBoundary = (
644
648
  Refresh,
645
649
  prevExports,
646
- nextExports
650
+ nextExports,
647
651
  ) => {
648
652
  const prevSignature = getRefreshBoundarySignature(Refresh, prevExports);
649
653
  const nextSignature = getRefreshBoundarySignature(Refresh, nextExports);
@@ -666,9 +670,7 @@ if (__DEV__) {
666
670
  for (const key in moduleExports) {
667
671
  if (key === "__esModule") {
668
672
  continue;
669
- }
670
- const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
671
- if (desc && desc.get) {
673
+ } else if (!isExportSafeToAccess(moduleExports, key)) {
672
674
  continue;
673
675
  }
674
676
  const exportValue = moduleExports[key];
@@ -683,8 +685,7 @@ if (__DEV__) {
683
685
  return;
684
686
  }
685
687
  for (const key in moduleExports) {
686
- const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
687
- if (desc && desc.get) {
688
+ if (!isExportSafeToAccess(moduleExports, key)) {
688
689
  continue;
689
690
  }
690
691
  const exportValue = moduleExports[key];
@@ -191,7 +191,7 @@ function metroRequire(
191
191
  );
192
192
  }
193
193
 
194
- //$FlowFixMe: at this point we know that moduleId is a number
194
+ //$FlowFixMe[incompatible-type]: at this point we know that moduleId is a number
195
195
  const moduleIdReallyIsNumber: number = moduleId;
196
196
 
197
197
  if (__DEV__) {
@@ -244,7 +244,7 @@ function metroImportDefault(
244
244
  moduleId = getModuleIdForVerboseName(verboseName);
245
245
  }
246
246
 
247
- //$FlowFixMe: at this point we know that moduleId is a number
247
+ //$FlowFixMe[incompatible-type]: at this point we know that moduleId is a number
248
248
  const moduleIdReallyIsNumber: number = moduleId;
249
249
 
250
250
  const maybeInitializedModule = modules.get(moduleIdReallyIsNumber);
@@ -276,7 +276,7 @@ function metroImportAll(
276
276
  moduleId = getModuleIdForVerboseName(verboseName);
277
277
  }
278
278
 
279
- //$FlowFixMe: at this point we know that moduleId is a number
279
+ //$FlowFixMe[incompatible-type]: at this point we know that moduleId is a number
280
280
  const moduleIdReallyIsNumber: number = moduleId;
281
281
 
282
282
  const maybeInitializedModule = modules.get(moduleIdReallyIsNumber);
@@ -457,7 +457,7 @@ function loadModuleImplementation(
457
457
  }
458
458
  try {
459
459
  if (__DEV__) {
460
- // $FlowIgnore: we know that __DEV__ is const and `Systrace` exists
460
+ // $FlowFixMe[incompatible-use]: we know that __DEV__ is const and `Systrace` exists
461
461
  Systrace.beginEvent('JS_require_' + (module.verboseName || moduleId));
462
462
  }
463
463
 
@@ -497,13 +497,13 @@ function loadModuleImplementation(
497
497
 
498
498
  // avoid removing factory in DEV mode as it breaks HMR
499
499
  if (!__DEV__) {
500
- // $FlowFixMe: This is only sound because we never access `factory` again
500
+ // $FlowFixMe[incompatible-type]: This is only sound because we never access `factory` again
501
501
  module.factory = undefined;
502
502
  module.dependencyMap = undefined;
503
503
  }
504
504
 
505
505
  if (__DEV__) {
506
- // $FlowIgnore: we know that __DEV__ is const and `Systrace` exists
506
+ // $FlowFixMe[incompatible-use]: we know that __DEV__ is const and `Systrace` exists
507
507
  Systrace.endEvent();
508
508
 
509
509
  if (Refresh != null) {
@@ -585,6 +585,8 @@ if (__DEV__) {
585
585
  ) {
586
586
  const mod = modules.get(id);
587
587
  if (!mod) {
588
+ /* $FlowFixMe[constant-condition] Error discovered during Constant
589
+ * Condition roll out. See https://fburl.com/workplace/1v97vimq. */
588
590
  if (factory) {
589
591
  // New modules are going to be handled by the define() method.
590
592
  return;
@@ -927,6 +929,21 @@ if (__DEV__) {
927
929
  }
928
930
  };
929
931
 
932
+ // Check whether accessing an export may be side-effectful
933
+ const isExportSafeToAccess = (
934
+ moduleExports: Exports,
935
+ key: string,
936
+ ): boolean => {
937
+ return (
938
+ // Transformed ESM syntax uses getters to support live bindings - we
939
+ // consider those safe. ESM itself does not allow user-defined getters
940
+ // on exports.
941
+ moduleExports?.__esModule ||
942
+ // CommonJS modules exporting getters may have side-effects.
943
+ Object.getOwnPropertyDescriptor(moduleExports, key)?.get == null
944
+ );
945
+ };
946
+
930
947
  // Modules that only export components become React Refresh boundaries.
931
948
  var isReactRefreshBoundary = function (
932
949
  Refresh: any,
@@ -945,9 +962,7 @@ if (__DEV__) {
945
962
  hasExports = true;
946
963
  if (key === '__esModule') {
947
964
  continue;
948
- }
949
- const desc = Object.getOwnPropertyDescriptor<any>(moduleExports, key);
950
- if (desc && desc.get) {
965
+ } else if (!isExportSafeToAccess(moduleExports, key)) {
951
966
  // Don't invoke getters as they may have side effects.
952
967
  return false;
953
968
  }
@@ -992,9 +1007,7 @@ if (__DEV__) {
992
1007
  for (const key in moduleExports) {
993
1008
  if (key === '__esModule') {
994
1009
  continue;
995
- }
996
- const desc = Object.getOwnPropertyDescriptor<any>(moduleExports, key);
997
- if (desc && desc.get) {
1010
+ } else if (!isExportSafeToAccess(moduleExports, key)) {
998
1011
  continue;
999
1012
  }
1000
1013
  const exportValue = moduleExports[key];
@@ -1016,8 +1029,7 @@ if (__DEV__) {
1016
1029
  return;
1017
1030
  }
1018
1031
  for (const key in moduleExports) {
1019
- const desc = Object.getOwnPropertyDescriptor<any>(moduleExports, key);
1020
- if (desc && desc.get) {
1032
+ if (!isExportSafeToAccess(moduleExports, key)) {
1021
1033
  // Don't invoke getters as they may have side effects.
1022
1034
  continue;
1023
1035
  }
File without changes