metro-runtime 0.71.1 → 0.72.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-runtime",
3
- "version": "0.71.1",
3
+ "version": "0.72.0",
4
4
  "description": "🚇 Module required for evaluating Metro bundles.",
5
5
  "main": "src",
6
6
  "repository": {
@@ -23,7 +23,7 @@ const CYCLE_DETECTED = {};
23
23
  const { hasOwnProperty } = {};
24
24
 
25
25
  if (__DEV__) {
26
- global.$RefreshReg$ = () => {};
26
+ global.$RefreshReg$ = () => {}; // $FlowFixMe[missing-local-annot]
27
27
 
28
28
  global.$RefreshSig$ = () => (type) => type;
29
29
  }
@@ -111,14 +111,17 @@ function metroRequire(moduleId) {
111
111
  if (initializingIndex !== -1) {
112
112
  const cycle = initializingModuleIds
113
113
  .slice(initializingIndex)
114
- .map((id) => (modules[id] ? modules[id].verboseName : "[unknown]")); // We want to show A -> B -> A:
114
+ .map((id) => (modules[id] ? modules[id].verboseName : "[unknown]"));
115
115
 
116
- cycle.push(cycle[0]);
117
- console.warn(
118
- `Require cycle: ${cycle.join(" -> ")}\n\n` +
119
- "Require cycles are allowed, but can result in uninitialized values. " +
120
- "Consider refactoring to remove the need for a cycle."
121
- );
116
+ if (shouldPrintRequireCycle(cycle)) {
117
+ cycle.push(cycle[0]); // We want to print A -> B -> A:
118
+
119
+ console.warn(
120
+ `Require cycle: ${cycle.join(" -> ")}\n\n` +
121
+ "Require cycles are allowed, but can result in uninitialized values. " +
122
+ "Consider refactoring to remove the need for a cycle."
123
+ );
124
+ }
122
125
  }
123
126
  }
124
127
 
@@ -126,6 +129,21 @@ function metroRequire(moduleId) {
126
129
  return module && module.isInitialized
127
130
  ? module.publicModule.exports
128
131
  : guardedLoadModule(moduleIdReallyIsNumber, module);
132
+ } // We print require cycles unless they match a pattern in the
133
+ // `requireCycleIgnorePatterns` configuration.
134
+
135
+ function shouldPrintRequireCycle(modules) {
136
+ const regExps =
137
+ global[__METRO_GLOBAL_PREFIX__ + "__requireCycleIgnorePatterns"];
138
+
139
+ if (!Array.isArray(regExps)) {
140
+ return true;
141
+ }
142
+
143
+ const isIgnored = (module) =>
144
+ module != null && regExps.some((regExp) => regExp.test(module)); // Print the cycle unless any part of it is ignored
145
+
146
+ return modules.every((module) => !isIgnored(module));
129
147
  }
130
148
 
131
149
  function metroImportDefault(moduleId) {
@@ -79,6 +79,7 @@ const {hasOwnProperty} = {};
79
79
 
80
80
  if (__DEV__) {
81
81
  global.$RefreshReg$ = () => {};
82
+ // $FlowFixMe[missing-local-annot]
82
83
  global.$RefreshSig$ = () => type => type;
83
84
  }
84
85
 
@@ -177,13 +178,15 @@ function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
177
178
  .map((id: number) =>
178
179
  modules[id] ? modules[id].verboseName : '[unknown]',
179
180
  );
180
- // We want to show A -> B -> A:
181
- cycle.push(cycle[0]);
182
- console.warn(
183
- `Require cycle: ${cycle.join(' -> ')}\n\n` +
184
- 'Require cycles are allowed, but can result in uninitialized values. ' +
185
- 'Consider refactoring to remove the need for a cycle.',
186
- );
181
+
182
+ if (shouldPrintRequireCycle(cycle)) {
183
+ cycle.push(cycle[0]); // We want to print A -> B -> A:
184
+ console.warn(
185
+ `Require cycle: ${cycle.join(' -> ')}\n\n` +
186
+ 'Require cycles are allowed, but can result in uninitialized values. ' +
187
+ 'Consider refactoring to remove the need for a cycle.',
188
+ );
189
+ }
187
190
  }
188
191
  }
189
192
 
@@ -194,6 +197,22 @@ function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
194
197
  : guardedLoadModule(moduleIdReallyIsNumber, module);
195
198
  }
196
199
 
200
+ // We print require cycles unless they match a pattern in the
201
+ // `requireCycleIgnorePatterns` configuration.
202
+ function shouldPrintRequireCycle(modules: $ReadOnlyArray<?string>): boolean {
203
+ const regExps =
204
+ global[__METRO_GLOBAL_PREFIX__ + '__requireCycleIgnorePatterns'];
205
+ if (!Array.isArray(regExps)) {
206
+ return true;
207
+ }
208
+
209
+ const isIgnored = (module: ?string) =>
210
+ module != null && regExps.some(regExp => regExp.test(module));
211
+
212
+ // Print the cycle unless any part of it is ignored
213
+ return modules.every(module => !isIgnored(module));
214
+ }
215
+
197
216
  function metroImportDefault(moduleId: ModuleID | VerboseModuleNameForDev) {
198
217
  if (__DEV__ && typeof moduleId === 'string') {
199
218
  const verboseName = moduleId;
@@ -849,7 +868,10 @@ if (__DEV__) {
849
868
  };
850
869
 
851
870
  // Modules that only export components become React Refresh boundaries.
852
- var isReactRefreshBoundary = function (Refresh, moduleExports): boolean {
871
+ var isReactRefreshBoundary = function (
872
+ Refresh: any,
873
+ moduleExports: Exports,
874
+ ): boolean {
853
875
  if (Refresh.isLikelyComponentType(moduleExports)) {
854
876
  return true;
855
877
  }
@@ -878,9 +900,9 @@ if (__DEV__) {
878
900
  };
879
901
 
880
902
  var shouldInvalidateReactRefreshBoundary = (
881
- Refresh,
882
- prevExports,
883
- nextExports,
903
+ Refresh: any,
904
+ prevExports: Exports,
905
+ nextExports: Exports,
884
906
  ) => {
885
907
  const prevSignature = getRefreshBoundarySignature(Refresh, prevExports);
886
908
  const nextSignature = getRefreshBoundarySignature(Refresh, nextExports);
@@ -896,7 +918,10 @@ if (__DEV__) {
896
918
  };
897
919
 
898
920
  // When this signature changes, it's unsafe to stop at this refresh boundary.
899
- var getRefreshBoundarySignature = (Refresh, moduleExports): Array<mixed> => {
921
+ var getRefreshBoundarySignature = (
922
+ Refresh: any,
923
+ moduleExports: Exports,
924
+ ): Array<mixed> => {
900
925
  const signature = [];
901
926
  signature.push(Refresh.getFamilyByType(moduleExports));
902
927
  if (moduleExports == null || typeof moduleExports !== 'object') {
@@ -919,7 +944,11 @@ if (__DEV__) {
919
944
  return signature;
920
945
  };
921
946
 
922
- var registerExportsForReactRefresh = (Refresh, moduleExports, moduleID) => {
947
+ var registerExportsForReactRefresh = (
948
+ Refresh: any,
949
+ moduleExports: Exports,
950
+ moduleID: ModuleID,
951
+ ) => {
923
952
  Refresh.register(moduleExports, moduleID + ' %exports%');
924
953
  if (moduleExports == null || typeof moduleExports !== 'object') {
925
954
  // Exit if we can't iterate over exports.