metro-runtime
Advanced tools
Comparing version 0.73.3 to 0.73.5
{ | ||
"name": "metro-runtime", | ||
"version": "0.73.3", | ||
"version": "0.73.5", | ||
"description": "🚇 Module required for evaluating Metro bundles.", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -10,8 +10,9 @@ /** | ||
*/ | ||
"use strict"; // $FlowExpectedError Flow does not know about Metro's require extensions. | ||
"use strict"; | ||
// $FlowExpectedError Flow does not know about Metro's require extensions. | ||
const dynamicRequire = require; | ||
module.exports = function (moduleID) { | ||
return Promise.resolve().then(() => dynamicRequire.importAll(moduleID)); | ||
}; |
@@ -12,2 +12,3 @@ "use strict"; | ||
*/ | ||
module.exports = require("react-refresh/runtime"); |
@@ -11,6 +11,6 @@ /** | ||
*/ | ||
"use strict"; | ||
const EventEmitter = require("./vendor/eventemitter3"); | ||
const inject = ({ module: [id, code], sourceURL }) => { | ||
@@ -26,3 +26,2 @@ // Some engines do not support `sourceURL` as a comment. We expose a | ||
}; | ||
const injectUpdate = (update) => { | ||
@@ -32,3 +31,2 @@ update.added.forEach(inject); | ||
}; | ||
class HMRClient extends EventEmitter { | ||
@@ -39,28 +37,22 @@ _isEnabled = false; | ||
_state = "opening"; | ||
constructor(url) { | ||
super(); | ||
constructor(url) { | ||
super(); // Access the global WebSocket object only after enabling the client, | ||
// Access the global WebSocket object only after enabling the client, | ||
// since some polyfills do the initialization lazily. | ||
this._ws = new global.WebSocket(url); | ||
this._ws.onopen = () => { | ||
this._state = "open"; | ||
this.emit("open"); | ||
this._flushQueue(); | ||
}; | ||
this._ws.onerror = (error) => { | ||
this.emit("connection-error", error); | ||
}; | ||
this._ws.onclose = () => { | ||
this._ws.onclose = (closeEvent) => { | ||
this._state = "closed"; | ||
this.emit("close"); | ||
this.emit("close", closeEvent); | ||
}; | ||
this._ws.onmessage = (message) => { | ||
const data = JSON.parse(String(message.data)); | ||
switch (data.type) { | ||
@@ -70,19 +62,14 @@ case "bundle-registered": | ||
break; | ||
case "update-start": | ||
this.emit("update-start", data.body); | ||
break; | ||
case "update": | ||
this.emit("update", data.body); | ||
break; | ||
case "update-done": | ||
this.emit("update-done"); | ||
break; | ||
case "error": | ||
this.emit("error", data.body); | ||
break; | ||
default: | ||
@@ -95,3 +82,2 @@ this.emit("error", { | ||
}; | ||
this.on("update", (update) => { | ||
@@ -107,7 +93,5 @@ if (this._isEnabled) { | ||
} | ||
close() { | ||
this._ws.close(); | ||
} | ||
send(message) { | ||
@@ -117,14 +101,9 @@ switch (this._state) { | ||
this._queue.push(message); | ||
break; | ||
case "open": | ||
this._ws.send(message); | ||
break; | ||
case "closed": | ||
// Ignore. | ||
break; | ||
default: | ||
@@ -134,9 +113,6 @@ throw new Error("[WebSocketHMRClient] Unknown state: " + this._state); | ||
} | ||
_flushQueue() { | ||
this._queue.forEach((message) => this.send(message)); | ||
this._queue.length = 0; | ||
} | ||
enable() { | ||
@@ -146,3 +122,2 @@ this._isEnabled = true; | ||
this._pendingUpdate = null; | ||
if (update != null) { | ||
@@ -152,11 +127,8 @@ injectUpdate(update); | ||
} | ||
disable() { | ||
this._isEnabled = false; | ||
} | ||
isEnabled() { | ||
return this._isEnabled; | ||
} | ||
hasPendingUpdates() { | ||
@@ -166,11 +138,10 @@ return this._pendingUpdate != null; | ||
} | ||
function mergeUpdates(base, next) { | ||
const addedIDs = new Set(); | ||
const deletedIDs = new Set(); | ||
const moduleMap = new Map(); // Fill in the temporary maps and sets from both updates in their order. | ||
const moduleMap = new Map(); | ||
// Fill in the temporary maps and sets from both updates in their order. | ||
applyUpdateLocally(base); | ||
applyUpdateLocally(next); | ||
function applyUpdateLocally(update) { | ||
@@ -183,3 +154,2 @@ update.deleted.forEach((id) => { | ||
} | ||
moduleMap.delete(id); | ||
@@ -189,3 +159,2 @@ }); | ||
const id = item.module[0]; | ||
if (deletedIDs.has(id)) { | ||
@@ -196,3 +165,2 @@ deletedIDs.delete(id); | ||
} | ||
moduleMap.set(id, item); | ||
@@ -204,5 +172,6 @@ }); | ||
}); | ||
} // Now reconstruct a unified update from our in-memory maps and sets. | ||
} | ||
// Now reconstruct a unified update from our in-memory maps and sets. | ||
// Applying it should be equivalent to applying both of them individually. | ||
const result = { | ||
@@ -222,3 +191,2 @@ isInitialUpdate: next.isInitialUpdate, | ||
} | ||
if (addedIDs.has(id)) { | ||
@@ -232,3 +200,2 @@ result.added.push(item); | ||
} | ||
module.exports = HMRClient; |
@@ -12,2 +12,3 @@ "use strict"; | ||
*/ | ||
module.exports = null; |
@@ -11,2 +11,3 @@ /** | ||
*/ | ||
"use strict"; |
@@ -19,2 +19,3 @@ /** | ||
/* eslint-disable */ | ||
"use strict"; | ||
@@ -24,2 +25,3 @@ | ||
prefix = "~"; | ||
/** | ||
@@ -32,4 +34,5 @@ * Constructor to create a storage for our `EE` objects. | ||
*/ | ||
function Events() {} | ||
function Events() {} // | ||
// | ||
// We try to not inherit from `Object.prototype`. In some engines creating an | ||
@@ -41,11 +44,12 @@ // instance in this way is faster than calling `Object.create(null)` directly. | ||
// | ||
if (Object.create) { | ||
Events.prototype = Object.create(null); | ||
if (Object.create) { | ||
Events.prototype = Object.create(null); // | ||
// | ||
// This hack is needed because the `__proto__` property is still inherited in | ||
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. | ||
// | ||
if (!new Events().__proto__) prefix = false; | ||
} | ||
/** | ||
@@ -60,3 +64,2 @@ * Representation of a single event listener. | ||
*/ | ||
function EE(fn, context, once) { | ||
@@ -67,2 +70,3 @@ this.fn = fn; | ||
} | ||
/** | ||
@@ -79,3 +83,2 @@ * Add a listener for a given event. | ||
*/ | ||
function addListener(emitter, event, fn, context, once) { | ||
@@ -85,3 +88,2 @@ if (typeof fn !== "function") { | ||
} | ||
var listener = new EE(fn, context || emitter, once), | ||
@@ -95,2 +97,3 @@ evt = prefix ? prefix + event : event; | ||
} | ||
/** | ||
@@ -103,3 +106,2 @@ * Clear event by name. | ||
*/ | ||
function clearEvent(emitter, evt) { | ||
@@ -109,2 +111,3 @@ if (--emitter._eventsCount === 0) emitter._events = new Events(); | ||
} | ||
/** | ||
@@ -117,3 +120,2 @@ * Minimal `EventEmitter` interface that is molded against the Node.js | ||
*/ | ||
function EventEmitter() { | ||
@@ -123,2 +125,3 @@ this._events = new Events(); | ||
} | ||
/** | ||
@@ -131,3 +134,2 @@ * Return an array listing the events for which the emitter has registered | ||
*/ | ||
EventEmitter.prototype.eventNames = function eventNames() { | ||
@@ -138,13 +140,11 @@ var names = [], | ||
if (this._eventsCount === 0) return names; | ||
for (name in (events = this._events)) { | ||
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); | ||
} | ||
if (Object.getOwnPropertySymbols) { | ||
return names.concat(Object.getOwnPropertySymbols(events)); | ||
} | ||
return names; | ||
}; | ||
/** | ||
@@ -157,3 +157,2 @@ * Return the listeners registered for a given event. | ||
*/ | ||
EventEmitter.prototype.listeners = function listeners(event) { | ||
@@ -164,9 +163,8 @@ var evt = prefix ? prefix + event : event, | ||
if (handlers.fn) return [handlers.fn]; | ||
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { | ||
ee[i] = handlers[i].fn; | ||
} | ||
return ee; | ||
}; | ||
/** | ||
@@ -179,3 +177,2 @@ * Return the number of listeners listening to a given event. | ||
*/ | ||
EventEmitter.prototype.listenerCount = function listenerCount(event) { | ||
@@ -188,2 +185,3 @@ var evt = prefix ? prefix + event : event, | ||
}; | ||
/** | ||
@@ -196,3 +194,2 @@ * Calls each of the listeners registered for a given event. | ||
*/ | ||
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { | ||
@@ -205,31 +202,22 @@ var evt = prefix ? prefix + event : event; | ||
i; | ||
if (listeners.fn) { | ||
if (listeners.once) | ||
this.removeListener(event, listeners.fn, undefined, true); | ||
switch (len) { | ||
case 1: | ||
return listeners.fn.call(listeners.context), true; | ||
case 2: | ||
return listeners.fn.call(listeners.context, a1), true; | ||
case 3: | ||
return listeners.fn.call(listeners.context, a1, a2), true; | ||
case 4: | ||
return listeners.fn.call(listeners.context, a1, a2, a3), true; | ||
case 5: | ||
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; | ||
case 6: | ||
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; | ||
} | ||
for (i = 1, args = new Array(len - 1); i < len; i++) { | ||
args[i - 1] = arguments[i]; | ||
} | ||
listeners.fn.apply(listeners.context, args); | ||
@@ -239,7 +227,5 @@ } else { | ||
j; | ||
for (i = 0; i < length; i++) { | ||
if (listeners[i].once) | ||
this.removeListener(event, listeners[i].fn, undefined, true); | ||
switch (len) { | ||
@@ -249,15 +235,11 @@ case 1: | ||
break; | ||
case 2: | ||
listeners[i].fn.call(listeners[i].context, a1); | ||
break; | ||
case 3: | ||
listeners[i].fn.call(listeners[i].context, a1, a2); | ||
break; | ||
case 4: | ||
listeners[i].fn.call(listeners[i].context, a1, a2, a3); | ||
break; | ||
default: | ||
@@ -272,5 +254,5 @@ if (!args) | ||
} | ||
return true; | ||
}; | ||
/** | ||
@@ -285,6 +267,6 @@ * Add a listener for a given event. | ||
*/ | ||
EventEmitter.prototype.on = function on(event, fn, context) { | ||
return addListener(this, event, fn, context, false); | ||
}; | ||
/** | ||
@@ -299,6 +281,6 @@ * Add a one-time listener for a given event. | ||
*/ | ||
EventEmitter.prototype.once = function once(event, fn, context) { | ||
return addListener(this, event, fn, context, true); | ||
}; | ||
/** | ||
@@ -314,3 +296,2 @@ * Remove the listeners of a given event. | ||
*/ | ||
EventEmitter.prototype.removeListener = function removeListener( | ||
@@ -324,3 +305,2 @@ event, | ||
if (!this._events[evt]) return this; | ||
if (!fn) { | ||
@@ -330,5 +310,3 @@ clearEvent(this, evt); | ||
} | ||
var listeners = this._events[evt]; | ||
if (listeners.fn) { | ||
@@ -351,6 +329,7 @@ if ( | ||
} | ||
} // | ||
} | ||
// | ||
// Reset the array, or remove it completely if we have no more listeners. | ||
// | ||
if (events.length) | ||
@@ -360,5 +339,5 @@ this._events[evt] = events.length === 1 ? events[0] : events; | ||
} | ||
return this; | ||
}; | ||
/** | ||
@@ -371,6 +350,4 @@ * Remove all listeners, or those of the specified event. | ||
*/ | ||
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { | ||
var evt; | ||
if (event) { | ||
@@ -383,23 +360,26 @@ evt = prefix ? prefix + event : event; | ||
} | ||
return this; | ||
}; | ||
return this; | ||
}; // | ||
// | ||
// Alias methods names because people roll like that. | ||
// | ||
EventEmitter.prototype.off = EventEmitter.prototype.removeListener; | ||
EventEmitter.prototype.addListener = EventEmitter.prototype.on; | ||
EventEmitter.prototype.off = EventEmitter.prototype.removeListener; | ||
EventEmitter.prototype.addListener = EventEmitter.prototype.on; // | ||
// | ||
// Expose the prefix. | ||
// | ||
EventEmitter.prefixed = prefix; | ||
EventEmitter.prefixed = prefix; // | ||
// | ||
// Allow `EventEmitter` to be imported as module namespace. | ||
// | ||
EventEmitter.EventEmitter = EventEmitter; | ||
EventEmitter.EventEmitter = EventEmitter; // | ||
// | ||
// Expose the module. | ||
// | ||
if ("undefined" !== typeof module) { | ||
module.exports = EventEmitter; | ||
} |
@@ -12,5 +12,6 @@ /** | ||
*/ | ||
"use strict"; | ||
/* eslint-disable no-bitwise */ | ||
global.__r = metroRequire; | ||
@@ -20,23 +21,21 @@ global[`${__METRO_GLOBAL_PREFIX__}__d`] = define; | ||
global.__registerSegment = registerSegment; | ||
var modules = clear(); // Don't use a Symbol here, it would pull in an extra polyfill with all sorts of | ||
var modules = clear(); | ||
// Don't use a Symbol here, it would pull in an extra polyfill with all sorts of | ||
// additional stuff (e.g. Array.from). | ||
const EMPTY = {}; | ||
const CYCLE_DETECTED = {}; | ||
const { hasOwnProperty } = {}; | ||
if (__DEV__) { | ||
global.$RefreshReg$ = () => {}; | ||
global.$RefreshSig$ = () => (type) => type; | ||
} | ||
function clear() { | ||
modules = Object.create(null); | ||
function clear() { | ||
modules = Object.create(null); // We return modules here so that we can assign an initial value to modules | ||
// We return modules here so that we can assign an initial value to modules | ||
// when defining it. Otherwise, we would have to do "let modules = null", | ||
// which will force us to add "nullthrows" everywhere. | ||
return modules; | ||
} | ||
if (__DEV__) { | ||
@@ -46,3 +45,2 @@ var verboseNamesToModuleIds = Object.create(null); | ||
} | ||
function define(factory, moduleId, dependencyMap) { | ||
@@ -53,14 +51,15 @@ if (modules[moduleId] != null) { | ||
// named parameter in `define` in production. | ||
const inverseDependencies = arguments[4]; // If the module has already been defined and the define method has been | ||
const inverseDependencies = arguments[4]; | ||
// If the module has already been defined and the define method has been | ||
// called with inverseDependencies, we can hot reload it. | ||
if (inverseDependencies) { | ||
global.__accept(moduleId, factory, dependencyMap, inverseDependencies); | ||
} | ||
} // prevent repeated calls to `global.nativeRequire` to overwrite modules | ||
} | ||
// prevent repeated calls to `global.nativeRequire` to overwrite modules | ||
// that are already loaded | ||
return; | ||
} | ||
const mod = { | ||
@@ -78,11 +77,10 @@ dependencyMap, | ||
modules[moduleId] = mod; | ||
if (__DEV__) { | ||
// HMR | ||
mod.hot = createHotReloadingObject(); // DEBUGGABLE MODULES NAMES | ||
mod.hot = createHotReloadingObject(); | ||
// DEBUGGABLE MODULES NAMES | ||
// we take `verboseName` from `arguments` to avoid an unused named parameter | ||
// in `define` in production. | ||
const verboseName = arguments[3]; | ||
if (verboseName) { | ||
@@ -94,3 +92,2 @@ mod.verboseName = verboseName; | ||
} | ||
function metroRequire(moduleId) { | ||
@@ -100,3 +97,2 @@ if (__DEV__ && typeof moduleId === "string") { | ||
moduleId = verboseNamesToModuleIds[verboseName]; | ||
if (moduleId == null) { | ||
@@ -110,6 +106,6 @@ throw new Error(`Unknown named module: "${verboseName}"`); | ||
} | ||
} //$FlowFixMe: at this point we know that moduleId is a number | ||
} | ||
//$FlowFixMe: at this point we know that moduleId is a number | ||
const moduleIdReallyIsNumber = moduleId; | ||
if (__DEV__) { | ||
@@ -119,3 +115,2 @@ const initializingIndex = initializingModuleIds.indexOf( | ||
); | ||
if (initializingIndex !== -1) { | ||
@@ -125,6 +120,4 @@ const cycle = initializingModuleIds | ||
.map((id) => (modules[id] ? modules[id].verboseName : "[unknown]")); | ||
if (shouldPrintRequireCycle(cycle)) { | ||
cycle.push(cycle[0]); // We want to print A -> B -> A: | ||
console.warn( | ||
@@ -138,3 +131,2 @@ `Require cycle: ${cycle.join(" -> ")}\n\n` + | ||
} | ||
const module = modules[moduleIdReallyIsNumber]; | ||
@@ -144,19 +136,18 @@ return module && module.isInitialized | ||
: guardedLoadModule(moduleIdReallyIsNumber, module); | ||
} // We print require cycles unless they match a pattern in the | ||
} | ||
// We print require cycles unless they match a pattern in the | ||
// `requireCycleIgnorePatterns` configuration. | ||
function shouldPrintRequireCycle(modules) { | ||
const regExps = | ||
global[__METRO_GLOBAL_PREFIX__ + "__requireCycleIgnorePatterns"]; | ||
if (!Array.isArray(regExps)) { | ||
return true; | ||
} | ||
const isIgnored = (module) => | ||
module != null && regExps.some((regExp) => regExp.test(module)); // Print the cycle unless any part of it is ignored | ||
module != null && regExps.some((regExp) => regExp.test(module)); | ||
// Print the cycle unless any part of it is ignored | ||
return modules.every((module) => !isIgnored(module)); | ||
} | ||
function metroImportDefault(moduleId) { | ||
@@ -166,6 +157,6 @@ if (__DEV__ && typeof moduleId === "string") { | ||
moduleId = verboseNamesToModuleIds[verboseName]; | ||
} //$FlowFixMe: at this point we know that moduleId is a number | ||
} | ||
//$FlowFixMe: at this point we know that moduleId is a number | ||
const moduleIdReallyIsNumber = moduleId; | ||
if ( | ||
@@ -177,12 +168,10 @@ modules[moduleIdReallyIsNumber] && | ||
} | ||
const exports = metroRequire(moduleIdReallyIsNumber); | ||
const importedDefault = | ||
exports && exports.__esModule ? exports.default : exports; // $FlowFixMe The metroRequire call above will throw if modules[id] is null | ||
exports && exports.__esModule ? exports.default : exports; | ||
// $FlowFixMe The metroRequire call above will throw if modules[id] is null | ||
return (modules[moduleIdReallyIsNumber].importedDefault = importedDefault); | ||
} | ||
metroRequire.importDefault = metroImportDefault; | ||
function metroImportAll(moduleId) { | ||
@@ -192,6 +181,6 @@ if (__DEV__ && typeof moduleId === "string") { | ||
moduleId = verboseNamesToModuleIds[verboseName]; | ||
} //$FlowFixMe: at this point we know that moduleId is a number | ||
} | ||
//$FlowFixMe: at this point we know that moduleId is a number | ||
const moduleIdReallyIsNumber = moduleId; | ||
if ( | ||
@@ -203,11 +192,10 @@ modules[moduleIdReallyIsNumber] && | ||
} | ||
const exports = metroRequire(moduleIdReallyIsNumber); | ||
let importedAll; | ||
if (exports && exports.__esModule) { | ||
importedAll = exports; | ||
} else { | ||
importedAll = {}; // Refrain from using Object.assign, it has to work in ES3 environments. | ||
importedAll = {}; | ||
// Refrain from using Object.assign, it has to work in ES3 environments. | ||
if (exports) { | ||
@@ -220,13 +208,13 @@ for (const key in exports) { | ||
} | ||
importedAll.default = exports; | ||
} // $FlowFixMe The metroRequire call above will throw if modules[id] is null | ||
} | ||
// $FlowFixMe The metroRequire call above will throw if modules[id] is null | ||
return (modules[moduleIdReallyIsNumber].importedAll = importedAll); | ||
} | ||
metroRequire.importAll = metroImportAll; | ||
metroRequire.importAll = metroImportAll; // The `require.context()` syntax is never executed in the runtime because it is converted | ||
// The `require.context()` syntax is never executed in the runtime because it is converted | ||
// to `require()` in `metro/src/ModuleGraph/worker/collectDependencies.js` after collecting | ||
// dependencies. If the feature flag is not enabled then the conversion never takes place and this error is thrown (development only). | ||
metroRequire.context = function fallbackRequireContext() { | ||
@@ -238,3 +226,2 @@ if (__DEV__) { | ||
} | ||
throw new Error( | ||
@@ -244,5 +231,3 @@ "The experimental Metro feature `require.context` is not enabled in your project." | ||
}; | ||
let inGuard = false; | ||
function guardedLoadModule(moduleId, module) { | ||
@@ -252,3 +237,2 @@ if (!inGuard && global.ErrorUtils) { | ||
let returnValue; | ||
try { | ||
@@ -260,3 +244,2 @@ returnValue = loadModuleImplementation(moduleId, module); | ||
} | ||
inGuard = false; | ||
@@ -268,6 +251,4 @@ return returnValue; | ||
} | ||
const ID_MASK_SHIFT = 16; | ||
const LOCAL_ID_MASK = ~0 >>> ID_MASK_SHIFT; | ||
function unpackModuleId(moduleId) { | ||
@@ -281,16 +262,11 @@ const segmentId = moduleId >>> ID_MASK_SHIFT; | ||
} | ||
metroRequire.unpackModuleId = unpackModuleId; | ||
function packModuleId(value) { | ||
return (value.segmentId << ID_MASK_SHIFT) + value.localId; | ||
} | ||
metroRequire.packModuleId = packModuleId; | ||
const moduleDefinersBySegmentID = []; | ||
const definingSegmentByModuleID = new Map(); | ||
function registerSegment(segmentId, moduleDefiner, moduleIds) { | ||
moduleDefinersBySegmentID[segmentId] = moduleDefiner; | ||
if (__DEV__) { | ||
@@ -302,3 +278,2 @@ if (segmentId === 0 && moduleIds) { | ||
} | ||
if (segmentId !== 0 && !moduleIds) { | ||
@@ -311,3 +286,2 @@ throw new Error( | ||
} | ||
if (moduleIds) { | ||
@@ -321,7 +295,5 @@ moduleIds.forEach((moduleId) => { | ||
} | ||
function loadModuleImplementation(moduleId, module) { | ||
if (!module && moduleDefinersBySegmentID.length > 0) { | ||
var _definingSegmentByMod; | ||
const segmentId = | ||
@@ -333,3 +305,2 @@ (_definingSegmentByMod = definingSegmentByModuleID.get(moduleId)) !== | ||
const definer = moduleDefinersBySegmentID[segmentId]; | ||
if (definer != null) { | ||
@@ -341,5 +312,3 @@ definer(moduleId); | ||
} | ||
const nativeRequire = global.nativeRequire; | ||
if (!module && nativeRequire) { | ||
@@ -350,25 +319,21 @@ const { segmentId, localId } = unpackModuleId(moduleId); | ||
} | ||
if (!module) { | ||
throw unknownModuleError(moduleId); | ||
} | ||
if (module.hasError) { | ||
throw moduleThrewError(moduleId, module.error); | ||
throw module.error; | ||
} | ||
if (__DEV__) { | ||
var Systrace = requireSystrace(); | ||
var Refresh = requireRefresh(); | ||
} // We must optimistically mark module as initialized before running the | ||
} | ||
// We must optimistically mark module as initialized before running the | ||
// factory to keep any require cycles inside the factory from causing an | ||
// infinite require loop. | ||
module.isInitialized = true; | ||
const { factory, dependencyMap } = module; | ||
if (__DEV__) { | ||
initializingModuleIds.push(moduleId); | ||
} | ||
try { | ||
@@ -379,5 +344,3 @@ if (__DEV__) { | ||
} | ||
const moduleObject = module.publicModule; | ||
if (__DEV__) { | ||
@@ -387,10 +350,7 @@ moduleObject.hot = module.hot; | ||
var prevRefreshSig = global.$RefreshSig$; | ||
if (Refresh != null) { | ||
const RefreshRuntime = Refresh; | ||
global.$RefreshReg$ = (type, id) => { | ||
RefreshRuntime.register(type, moduleId + " " + id); | ||
}; | ||
global.$RefreshSig$ = | ||
@@ -400,7 +360,7 @@ RefreshRuntime.createSignatureFunctionForTransform; | ||
} | ||
moduleObject.id = moduleId; | ||
moduleObject.id = moduleId; // keep args in sync with with defineModuleCode in | ||
// keep args in sync with with defineModuleCode in | ||
// metro/src/Resolver/index.js | ||
// and metro/src/ModuleGraph/worker.js | ||
factory( | ||
@@ -414,4 +374,5 @@ global, | ||
dependencyMap | ||
); // avoid removing factory in DEV mode as it breaks HMR | ||
); | ||
// avoid removing factory in DEV mode as it breaks HMR | ||
if (!__DEV__) { | ||
@@ -422,7 +383,5 @@ // $FlowFixMe: This is only sound because we never access `factory` again | ||
} | ||
if (__DEV__) { | ||
// $FlowIgnore: we know that __DEV__ is const and `Systrace` exists | ||
Systrace.endEvent(); | ||
if (Refresh != null) { | ||
@@ -432,3 +391,2 @@ registerExportsForReactRefresh(Refresh, moduleObject.exports, moduleId); | ||
} | ||
return moduleObject.exports; | ||
@@ -448,3 +406,2 @@ } catch (e) { | ||
} | ||
global.$RefreshReg$ = prevRefreshReg; | ||
@@ -455,6 +412,4 @@ global.$RefreshSig$ = prevRefreshSig; | ||
} | ||
function unknownModuleError(id) { | ||
let message = 'Requiring unknown module "' + id + '".'; | ||
if (__DEV__) { | ||
@@ -465,13 +420,4 @@ message += | ||
} | ||
return Error(message); | ||
} | ||
function moduleThrewError(id, error) { | ||
const displayName = (__DEV__ && modules[id] && modules[id].verboseName) || id; | ||
return Error( | ||
'Requiring module "' + displayName + '", which threw an exception: ' + error | ||
); | ||
} | ||
if (__DEV__) { | ||
@@ -482,8 +428,9 @@ // $FlowFixMe[prop-missing] | ||
endEvent: () => {}, | ||
}; // $FlowFixMe[prop-missing] | ||
}; | ||
// $FlowFixMe[prop-missing] | ||
metroRequire.getModules = () => { | ||
return modules; | ||
}; // HOT MODULE RELOADING | ||
}; | ||
// HOT MODULE RELOADING | ||
var createHotReloadingObject = function () { | ||
@@ -504,5 +451,3 @@ const hot = { | ||
}; | ||
let reactRefreshTimeout = null; | ||
const metroHotUpdateModule = function ( | ||
@@ -515,3 +460,2 @@ id, | ||
const mod = modules[id]; | ||
if (!mod) { | ||
@@ -522,6 +466,4 @@ if (factory) { | ||
} | ||
throw unknownModuleError(id); | ||
} | ||
if (!mod.hasError && !mod.isInitialized) { | ||
@@ -534,5 +476,6 @@ // The module hasn't actually been executed yet, | ||
} | ||
const Refresh = requireRefresh(); | ||
const refreshBoundaryIDs = new Set(); | ||
const Refresh = requireRefresh(); | ||
const refreshBoundaryIDs = new Set(); // In this loop, we will traverse the dependency tree upwards from the | ||
// In this loop, we will traverse the dependency tree upwards from the | ||
// changed module. Updates "bubble" up to the closest accepted parent. | ||
@@ -556,9 +499,8 @@ // | ||
let updatedModuleIDs; | ||
try { | ||
updatedModuleIDs = topologicalSort( | ||
[id], // Start with the changed module and go upwards | ||
[id], | ||
// Start with the changed module and go upwards | ||
(pendingID) => { | ||
const pendingModule = modules[pendingID]; | ||
if (pendingModule == null) { | ||
@@ -568,5 +510,3 @@ // Nothing to do. | ||
} | ||
const pendingHot = pendingModule.hot; | ||
if (pendingHot == null) { | ||
@@ -576,6 +516,5 @@ throw new Error( | ||
); | ||
} // A module can be accepted manually from within itself. | ||
} | ||
// A module can be accepted manually from within itself. | ||
let canAccept = pendingHot._didAccept; | ||
if (!canAccept && Refresh != null) { | ||
@@ -587,3 +526,2 @@ // Or React Refresh may mark it accepted based on exports. | ||
); | ||
if (isBoundary) { | ||
@@ -594,11 +532,9 @@ canAccept = true; | ||
} | ||
if (canAccept) { | ||
// Don't look at parents. | ||
return []; | ||
} // If we bubble through the roof, there is no way to do a hot update. | ||
} | ||
// If we bubble through the roof, there is no way to do a hot update. | ||
// Bail out altogether. This is the failure case. | ||
const parentIDs = inverseDependencies[pendingID]; | ||
if (parentIDs.length === 0) { | ||
@@ -613,5 +549,5 @@ // Reload the app because the hot reload can't succeed. | ||
return []; | ||
} // This module can't handle the update but maybe all its parents can? | ||
} | ||
// This module can't handle the update but maybe all its parents can? | ||
// Put them all in the queue to run the same set of checks. | ||
return parentIDs; | ||
@@ -628,27 +564,21 @@ }, | ||
} | ||
throw e; | ||
} | ||
if (didBailOut) { | ||
return; | ||
} // If we reached here, it is likely that hot reload will be successful. | ||
} | ||
// If we reached here, it is likely that hot reload will be successful. | ||
// Run the actual factories. | ||
const seenModuleIDs = new Set(); | ||
for (let i = 0; i < updatedModuleIDs.length; i++) { | ||
const updatedID = updatedModuleIDs[i]; | ||
if (seenModuleIDs.has(updatedID)) { | ||
continue; | ||
} | ||
seenModuleIDs.add(updatedID); | ||
const updatedMod = modules[updatedID]; | ||
if (updatedMod == null) { | ||
throw new Error("[Refresh] Expected to find the updated module."); | ||
} | ||
const prevExports = updatedMod.publicModule.exports; | ||
@@ -661,3 +591,2 @@ const didError = runUpdatedModule( | ||
const nextExports = updatedMod.publicModule.exports; | ||
if (didError) { | ||
@@ -668,3 +597,2 @@ // The user was shown a redbox about module initialization. | ||
} | ||
if (refreshBoundaryIDs.has(updatedID)) { | ||
@@ -676,3 +604,4 @@ // Since we just executed the code for it, it's possible | ||
nextExports | ||
); // It can also become ineligible if its exports are incompatible | ||
); | ||
// It can also become ineligible if its exports are incompatible | ||
// with the previous exports. | ||
@@ -683,3 +612,2 @@ // For example, if you add/remove/change exports, we'll want | ||
// to a function, we want to invalidate the boundary. | ||
const didInvalidate = shouldInvalidateReactRefreshBoundary( | ||
@@ -690,3 +618,2 @@ Refresh, | ||
); | ||
if (isNoLongerABoundary || didInvalidate) { | ||
@@ -697,3 +624,2 @@ // We'll be conservative. The only case in which we won't do a full | ||
const parentIDs = inverseDependencies[updatedID]; | ||
if (parentIDs.length === 0) { | ||
@@ -711,12 +637,10 @@ // Looks like we bubbled to the root. Can't recover from that. | ||
return; | ||
} // Schedule all parent refresh boundaries to re-run in this loop. | ||
} | ||
// Schedule all parent refresh boundaries to re-run in this loop. | ||
for (let j = 0; j < parentIDs.length; j++) { | ||
const parentID = parentIDs[j]; | ||
const parentMod = modules[parentID]; | ||
if (parentMod == null) { | ||
throw new Error("[Refresh] Expected to find parent module."); | ||
} | ||
const canAcceptParent = isReactRefreshBoundary( | ||
@@ -726,3 +650,2 @@ Refresh, | ||
); | ||
if (canAcceptParent) { | ||
@@ -743,3 +666,2 @@ // All parents will have to re-run too. | ||
} | ||
if (Refresh != null) { | ||
@@ -750,4 +672,4 @@ // Debounce a little in case there are multiple updates queued up. | ||
reactRefreshTimeout = setTimeout(() => { | ||
reactRefreshTimeout = null; // Update React components. | ||
reactRefreshTimeout = null; | ||
// Update React components. | ||
Refresh.performReactRefresh(); | ||
@@ -758,3 +680,2 @@ }, 30); | ||
}; | ||
const topologicalSort = function (roots, getEdges, earlyStop) { | ||
@@ -764,3 +685,2 @@ const result = []; | ||
const stack = new Set(); | ||
function traverseDependentNodes(node) { | ||
@@ -770,11 +690,8 @@ if (stack.has(node)) { | ||
} | ||
if (visited.has(node)) { | ||
return; | ||
} | ||
visited.add(node); | ||
stack.add(node); | ||
const dependentNodes = getEdges(node); | ||
if (earlyStop(node)) { | ||
@@ -784,3 +701,2 @@ stack.delete(node); | ||
} | ||
dependentNodes.forEach((dependent) => { | ||
@@ -792,3 +708,2 @@ traverseDependentNodes(dependent); | ||
} | ||
roots.forEach((root) => { | ||
@@ -799,16 +714,11 @@ traverseDependentNodes(root); | ||
}; | ||
const runUpdatedModule = function (id, factory, dependencyMap) { | ||
const mod = modules[id]; | ||
if (mod == null) { | ||
throw new Error("[Refresh] Expected to find the module."); | ||
} | ||
const { hot } = mod; | ||
if (!hot) { | ||
throw new Error("[Refresh] Expected module.hot to always exist in DEV."); | ||
} | ||
if (hot._disposeCallback) { | ||
@@ -824,11 +734,8 @@ try { | ||
} | ||
if (factory) { | ||
mod.factory = factory; | ||
} | ||
if (dependencyMap) { | ||
mod.dependencyMap = dependencyMap; | ||
} | ||
mod.hasError = false; | ||
@@ -845,3 +752,2 @@ mod.error = undefined; | ||
metroRequire(id); | ||
if (mod.hasError) { | ||
@@ -857,7 +763,6 @@ // This error has already been reported via a redbox. | ||
mod.error = null; | ||
mod.publicModule.exports = prevExports; // We errored. Stop the update. | ||
mod.publicModule.exports = prevExports; | ||
// We errored. Stop the update. | ||
return true; | ||
} | ||
if (hot._acceptCallback) { | ||
@@ -872,7 +777,6 @@ try { | ||
} | ||
} // No error. | ||
} | ||
// No error. | ||
return false; | ||
}; | ||
const performFullRefresh = (reason, modules) => { | ||
@@ -888,3 +792,2 @@ /* global window */ | ||
const Refresh = requireRefresh(); | ||
if (Refresh != null) { | ||
@@ -895,3 +798,2 @@ var _modules$source$verbo, | ||
_modules$failed; | ||
const sourceName = | ||
@@ -922,4 +824,5 @@ (_modules$source$verbo = | ||
} | ||
}; // Modules that only export components become React Refresh boundaries. | ||
}; | ||
// Modules that only export components become React Refresh boundaries. | ||
var isReactRefreshBoundary = function (Refresh, moduleExports) { | ||
@@ -929,3 +832,2 @@ if (Refresh.isLikelyComponentType(moduleExports)) { | ||
} | ||
if (moduleExports == null || typeof moduleExports !== "object") { | ||
@@ -935,15 +837,10 @@ // Exit if we can't iterate over exports. | ||
} | ||
let hasExports = false; | ||
let areAllExportsComponents = true; | ||
for (const key in moduleExports) { | ||
hasExports = true; | ||
if (key === "__esModule") { | ||
continue; | ||
} | ||
const desc = Object.getOwnPropertyDescriptor(moduleExports, key); | ||
if (desc && desc.get) { | ||
@@ -953,5 +850,3 @@ // Don't invoke getters as they may have side effects. | ||
} | ||
const exportValue = moduleExports[key]; | ||
if (!Refresh.isLikelyComponentType(exportValue)) { | ||
@@ -961,6 +856,4 @@ areAllExportsComponents = false; | ||
} | ||
return hasExports && areAllExportsComponents; | ||
}; | ||
var shouldInvalidateReactRefreshBoundary = ( | ||
@@ -973,7 +866,5 @@ Refresh, | ||
const nextSignature = getRefreshBoundarySignature(Refresh, nextExports); | ||
if (prevSignature.length !== nextSignature.length) { | ||
return true; | ||
} | ||
for (let i = 0; i < nextSignature.length; i++) { | ||
@@ -984,10 +875,9 @@ if (prevSignature[i] !== nextSignature[i]) { | ||
} | ||
return false; | ||
}; // When this signature changes, it's unsafe to stop at this refresh boundary. | ||
}; | ||
// When this signature changes, it's unsafe to stop at this refresh boundary. | ||
var getRefreshBoundarySignature = (Refresh, moduleExports) => { | ||
const signature = []; | ||
signature.push(Refresh.getFamilyByType(moduleExports)); | ||
if (moduleExports == null || typeof moduleExports !== "object") { | ||
@@ -998,3 +888,2 @@ // Exit if we can't iterate over exports. | ||
} | ||
for (const key in moduleExports) { | ||
@@ -1004,9 +893,6 @@ if (key === "__esModule") { | ||
} | ||
const desc = Object.getOwnPropertyDescriptor(moduleExports, key); | ||
if (desc && desc.get) { | ||
continue; | ||
} | ||
const exportValue = moduleExports[key]; | ||
@@ -1016,9 +902,6 @@ signature.push(key); | ||
} | ||
return signature; | ||
}; | ||
var registerExportsForReactRefresh = (Refresh, moduleExports, moduleID) => { | ||
Refresh.register(moduleExports, moduleID + " %exports%"); | ||
if (moduleExports == null || typeof moduleExports !== "object") { | ||
@@ -1029,6 +912,4 @@ // Exit if we can't iterate over exports. | ||
} | ||
for (const key in moduleExports) { | ||
const desc = Object.getOwnPropertyDescriptor(moduleExports, key); | ||
if (desc && desc.get) { | ||
@@ -1038,3 +919,2 @@ // Don't invoke getters as they may have side effects. | ||
} | ||
const exportValue = moduleExports[key]; | ||
@@ -1045,6 +925,4 @@ const typeID = moduleID + " %exports% " + key; | ||
}; | ||
global.__accept = metroHotUpdateModule; | ||
} | ||
if (__DEV__) { | ||
@@ -1056,2 +934,3 @@ // The metro require polyfill can not have module dependencies. | ||
// having to make them publicly available. | ||
var requireSystrace = function requireSystrace() { | ||
@@ -1063,3 +942,2 @@ return ( | ||
}; | ||
var requireRefresh = function requireRefresh() { | ||
@@ -1066,0 +944,0 @@ return ( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1400
84934