metro-runtime 0.71.1 → 0.71.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
package/src/polyfills/require.js
CHANGED
|
@@ -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]"));
|
|
114
|
+
.map((id) => (modules[id] ? modules[id].verboseName : "[unknown]"));
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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) {
|
|
@@ -177,13 +177,15 @@ function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
|
|
|
177
177
|
.map((id: number) =>
|
|
178
178
|
modules[id] ? modules[id].verboseName : '[unknown]',
|
|
179
179
|
);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
|
|
181
|
+
if (shouldPrintRequireCycle(cycle)) {
|
|
182
|
+
cycle.push(cycle[0]); // We want to print A -> B -> A:
|
|
183
|
+
console.warn(
|
|
184
|
+
`Require cycle: ${cycle.join(' -> ')}\n\n` +
|
|
185
|
+
'Require cycles are allowed, but can result in uninitialized values. ' +
|
|
186
|
+
'Consider refactoring to remove the need for a cycle.',
|
|
187
|
+
);
|
|
188
|
+
}
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
|
|
@@ -194,6 +196,22 @@ function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev): Exports {
|
|
|
194
196
|
: guardedLoadModule(moduleIdReallyIsNumber, module);
|
|
195
197
|
}
|
|
196
198
|
|
|
199
|
+
// We print require cycles unless they match a pattern in the
|
|
200
|
+
// `requireCycleIgnorePatterns` configuration.
|
|
201
|
+
function shouldPrintRequireCycle(modules: $ReadOnlyArray<?string>): boolean {
|
|
202
|
+
const regExps =
|
|
203
|
+
global[__METRO_GLOBAL_PREFIX__ + '__requireCycleIgnorePatterns'];
|
|
204
|
+
if (!Array.isArray(regExps)) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const isIgnored = module =>
|
|
209
|
+
module != null && regExps.some(regExp => regExp.test(module));
|
|
210
|
+
|
|
211
|
+
// Print the cycle unless any part of it is ignored
|
|
212
|
+
return modules.every(module => !isIgnored(module));
|
|
213
|
+
}
|
|
214
|
+
|
|
197
215
|
function metroImportDefault(moduleId: ModuleID | VerboseModuleNameForDev) {
|
|
198
216
|
if (__DEV__ && typeof moduleId === 'string') {
|
|
199
217
|
const verboseName = moduleId;
|