Socket
Socket
Sign inDemoInstall

metro-runtime

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-runtime - npm Package Compare versions

Comparing version 0.80.5 to 0.80.6

2

package.json
{
"name": "metro-runtime",
"version": "0.80.5",
"version": "0.80.6",
"description": "🚇 Module required for evaluating Metro bundles.",

@@ -5,0 +5,0 @@ "main": "src",

"use strict";
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
const DEFAULT_OPTIONS = {

@@ -24,3 +13,2 @@ isPrefetchOnly: false,

if (bundlePath != null) {
// NOTE: Errors will be swallowed by asyncRequire.prefetch
await loadBundle(bundlePath);

@@ -27,0 +15,0 @@ }

@@ -1,10 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
"use strict";

@@ -1,12 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -16,8 +5,5 @@

const inject = ({ module: [id, code], sourceURL }) => {
// Some engines do not support `sourceURL` as a comment. We expose a
// `globalEvalWithSourceUrl` function to handle updates in that case.
if (global.globalEvalWithSourceUrl) {
global.globalEvalWithSourceUrl(code, sourceURL);
} else {
// eslint-disable-next-line no-eval
eval(code);

@@ -37,5 +23,2 @@ }

super();
// Access the global WebSocket object only after enabling the client,
// since some polyfills do the initialization lazily.
this._ws = new global.WebSocket(url);

@@ -101,3 +84,2 @@ this._ws.onopen = () => {

case "closed":
// Ignore.
break;

@@ -134,4 +116,2 @@ default:

const moduleMap = new Map();
// Fill in the temporary maps and sets from both updates in their order.
applyUpdateLocally(base);

@@ -162,5 +142,2 @@ applyUpdateLocally(next);

}
// 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 = {

@@ -167,0 +144,0 @@ isInitialUpdate: next.isInitialUpdate,

"use strict";
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
module.exports = null;

@@ -1,12 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -1,20 +0,1 @@

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
*/
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Arnout Kazemier
*
* This is a vendored file based on EventEmitter3: https://github.com/primus/eventemitter3
*/
/* eslint-disable */
"use strict";

@@ -24,38 +5,7 @@

prefix = "~";
/**
* Constructor to create a storage for our `EE` objects.
* An `Events` instance is a plain object whose properties are event names.
*
* @constructor
* @private
*/
function Events() {}
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
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;
}
/**
* Representation of a single event listener.
*
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
* @constructor
* @private
*/
function EE(fn, context, once) {

@@ -66,14 +16,2 @@ this.fn = fn;

}
/**
* Add a listener for a given event.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} once Specify if the listener is a one-time listener.
* @returns {EventEmitter}
* @private
*/
function addListener(emitter, event, fn, context, once) {

@@ -91,10 +29,2 @@ if (typeof fn !== "function") {

}
/**
* Clear event by name.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} evt The Event name.
* @private
*/
function clearEvent(emitter, evt) {

@@ -104,10 +34,2 @@ if (--emitter._eventsCount === 0) emitter._events = new Events();

}
/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*
* @constructor
* @public
*/
function EventEmitter() {

@@ -117,10 +39,2 @@ this._events = new Events();

}
/**
* Return an array listing the events for which the emitter has registered
* listeners.
*
* @returns {Array}
* @public
*/
EventEmitter.prototype.eventNames = function eventNames() {

@@ -139,10 +53,2 @@ var names = [],

};
/**
* Return the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Array} The registered listeners.
* @public
*/
EventEmitter.prototype.listeners = function listeners(event) {

@@ -158,10 +64,2 @@ var evt = prefix ? prefix + event : event,

};
/**
* Return the number of listeners listening to a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Number} The number of listeners.
* @public
*/
EventEmitter.prototype.listenerCount = function listenerCount(event) {

@@ -174,10 +72,2 @@ var evt = prefix ? prefix + event : event,

};
/**
* Calls each of the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Boolean} `true` if the event had listeners, else `false`.
* @public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {

@@ -241,39 +131,8 @@ var evt = prefix ? prefix + event : event;

};
/**
* Add a listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
/**
* Add a one-time listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
/**
* Remove the listeners of a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn Only remove the listeners that match this function.
* @param {*} context Only remove the listeners that have this context.
* @param {Boolean} once Only remove one-time listeners.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeListener = function removeListener(

@@ -310,6 +169,2 @@ event,

}
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length)

@@ -321,10 +176,2 @@ this._events[evt] = events.length === 1 ? events[0] : events;

};
/**
* Remove all listeners, or those of the specified event.
*
* @param {(String|Symbol)} [event] The event name.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {

@@ -341,24 +188,8 @@ var evt;

};
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
//
// Expose the prefix.
//
EventEmitter.prefixed = prefix;
//
// Allow `EventEmitter` to be imported as module namespace.
//
EventEmitter.EventEmitter = EventEmitter;
//
// Expose the module.
//
if ("undefined" !== typeof module) {
module.exports = EventEmitter;
}

@@ -1,19 +0,3 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
* @polyfill
*/
"use strict";
/* eslint-disable no-bitwise */
// A simpler $ArrayLike<T>. Not iterable and doesn't have a `length`.
// This is compatible with actual arrays as well as with objects that look like
// {0: 'value', 1: '...'}
global.__r = metroRequire;

@@ -24,5 +8,2 @@ global[`${__METRO_GLOBAL_PREFIX__}__d`] = define;

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 = {};

@@ -37,6 +18,2 @@ const CYCLE_DETECTED = {};

modules = Object.create(null);
// 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;

@@ -51,8 +28,3 @@ }

if (__DEV__) {
// (We take `inverseDependencies` from `arguments` to avoid an unused
// named parameter in `define` in production.
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) {

@@ -62,5 +34,2 @@ global.__accept(moduleId, factory, dependencyMap, inverseDependencies);

}
// prevent repeated calls to `global.nativeRequire` to overwrite modules
// that are already loaded
return;

@@ -81,8 +50,3 @@ }

if (__DEV__) {
// HMR
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];

@@ -108,4 +72,2 @@ if (verboseName) {

}
//$FlowFixMe: at this point we know that moduleId is a number
const moduleIdReallyIsNumber = moduleId;

@@ -121,3 +83,3 @@ if (__DEV__) {

if (shouldPrintRequireCycle(cycle)) {
cycle.push(cycle[0]); // We want to print A -> B -> A:
cycle.push(cycle[0]);
console.warn(

@@ -136,5 +98,2 @@ `Require cycle: ${cycle.join(" -> ")}\n\n` +

}
// We print require cycles unless they match a pattern in the
// `requireCycleIgnorePatterns` configuration.
function shouldPrintRequireCycle(modules) {

@@ -148,4 +107,2 @@ const regExps =

module != null && regExps.some((regExp) => regExp.test(module));
// Print the cycle unless any part of it is ignored
return modules.every((module) => !isIgnored(module));

@@ -158,4 +115,2 @@ }

}
//$FlowFixMe: at this point we know that moduleId is a number
const moduleIdReallyIsNumber = moduleId;

@@ -171,4 +126,2 @@ if (

exports && exports.__esModule ? exports.default : exports;
// $FlowFixMe The metroRequire call above will throw if modules[id] is null
return (modules[moduleIdReallyIsNumber].importedDefault = importedDefault);

@@ -182,4 +135,2 @@ }

}
//$FlowFixMe: at this point we know that moduleId is a number
const moduleIdReallyIsNumber = moduleId;

@@ -198,4 +149,2 @@ if (

importedAll = {};
// Refrain from using Object.assign, it has to work in ES3 environments.
if (exports) {

@@ -210,11 +159,5 @@ for (const key in exports) {

}
// $FlowFixMe The metroRequire call above will throw if modules[id] is null
return (modules[moduleIdReallyIsNumber].importedAll = importedAll);
}
metroRequire.importAll = metroImportAll;
// 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() {

@@ -230,4 +173,2 @@ if (__DEV__) {

};
// `require.resolveWeak()` is a compile-time primitive (see collectDependencies.js)
metroRequire.resolveWeak = function fallbackRequireResolveWeak() {

@@ -249,3 +190,2 @@ if (__DEV__) {

} catch (e) {
// TODO: (moti) T48204692 Type this use of ErrorUtils.
global.ErrorUtils.reportFatalError(e);

@@ -325,6 +265,2 @@ }

}
// 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;

@@ -337,3 +273,2 @@ const { factory, dependencyMap } = module;

if (__DEV__) {
// $FlowIgnore: we know that __DEV__ is const and `Systrace` exists
Systrace.beginEvent("JS_require_" + (module.verboseName || moduleId));

@@ -356,6 +291,2 @@ }

moduleObject.id = moduleId;
// keep args in sync with with defineModuleCode in
// metro/src/Resolver/index.js
// and metro/src/ModuleGraph/worker.js
factory(

@@ -370,6 +301,3 @@ global,

);
// avoid removing factory in DEV mode as it breaks HMR
if (!__DEV__) {
// $FlowFixMe: This is only sound because we never access `factory` again
module.factory = undefined;

@@ -379,3 +307,2 @@ module.dependencyMap = undefined;

if (__DEV__) {
// $FlowIgnore: we know that __DEV__ is const and `Systrace` exists
Systrace.endEvent();

@@ -415,3 +342,2 @@ if (Refresh != null) {

if (__DEV__) {
// $FlowFixMe[prop-missing]
metroRequire.Systrace = {

@@ -421,8 +347,5 @@ beginEvent: () => {},

};
// $FlowFixMe[prop-missing]
metroRequire.getModules = () => {
return modules;
};
// HOT MODULE RELOADING
var createHotReloadingObject = function () {

@@ -453,3 +376,2 @@ const hot = {

if (factory) {
// New modules are going to be handled by the define() method.
return;

@@ -460,4 +382,2 @@ }

if (!mod.hasError && !mod.isInitialized) {
// The module hasn't actually been executed yet,
// so we can always safely replace it.
mod.factory = factory;

@@ -469,20 +389,2 @@ mod.dependencyMap = dependencyMap;

const refreshBoundaryIDs = new Set();
// In this loop, we will traverse the dependency tree upwards from the
// changed module. Updates "bubble" up to the closest accepted parent.
//
// If we reach the module root and nothing along the way accepted the update,
// we know hot reload is going to fail. In that case we return false.
//
// The main purpose of this loop is to figure out whether it's safe to apply
// a hot update. It is only safe when the update was accepted somewhere
// along the way upwards for each of its parent dependency module chains.
//
// We perform a topological sort because we may discover the same
// module more than once in the list of things to re-execute, and
// we want to execute modules before modules that depend on them.
//
// If we didn't have this check, we'd risk re-evaluating modules that
// have side effects and lead to confusing and meaningless crashes.
let didBailOut = false;

@@ -493,7 +395,5 @@ let updatedModuleIDs;

[id],
// Start with the changed module and go upwards
(pendingID) => {
const pendingModule = modules[pendingID];
if (pendingModule == null) {
// Nothing to do.
return [];

@@ -507,6 +407,4 @@ }

}
// A module can be accepted manually from within itself.
let canAccept = pendingHot._didAccept;
if (!canAccept && Refresh != null) {
// Or React Refresh may mark it accepted based on exports.
const isBoundary = isReactRefreshBoundary(

@@ -522,11 +420,6 @@ Refresh,

if (canAccept) {
// Don't look at parents.
return [];
}
// 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) {
// Reload the app because the hot reload can't succeed.
// This should work both on web and React Native.
performFullRefresh("No root boundary", {

@@ -539,7 +432,5 @@ source: mod,

}
// 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;
},
() => didBailOut // Should we stop?
() => didBailOut
).reverse();

@@ -558,5 +449,2 @@ } catch (e) {

}
// If we reached here, it is likely that hot reload will be successful.
// Run the actual factories.
const seenModuleIDs = new Set();

@@ -581,9 +469,5 @@ for (let i = 0; i < updatedModuleIDs.length; i++) {

if (didError) {
// The user was shown a redbox about module initialization.
// There's nothing for us to do here until it's fixed.
return;
}
if (refreshBoundaryIDs.has(updatedID)) {
// Since we just executed the code for it, it's possible
// that the new exports make it ineligible for being a boundary.
const isNoLongerABoundary = !isReactRefreshBoundary(

@@ -593,8 +477,2 @@ Refresh,

);
// It can also become ineligible if its exports are incompatible
// with the previous exports.
// For example, if you add/remove/change exports, we'll want
// to re-execute the importing modules, and force those components
// to re-render. Similarly, if you convert a class component
// to a function, we want to invalidate the boundary.
const didInvalidate = shouldInvalidateReactRefreshBoundary(

@@ -606,8 +484,4 @@ Refresh,

if (isNoLongerABoundary || didInvalidate) {
// We'll be conservative. The only case in which we won't do a full
// reload is if all parent modules are also refresh boundaries.
// In that case we'll add them to the current queue.
const parentIDs = inverseDependencies[updatedID];
if (parentIDs.length === 0) {
// Looks like we bubbled to the root. Can't recover from that.
performFullRefresh(

@@ -624,3 +498,2 @@ isNoLongerABoundary

}
// Schedule all parent refresh boundaries to re-run in this loop.
for (let j = 0; j < parentIDs.length; j++) {

@@ -637,3 +510,2 @@ const parentID = parentIDs[j];

if (canAcceptParent) {
// All parents will have to re-run too.
refreshBoundaryIDs.add(parentID);

@@ -653,8 +525,5 @@ updatedModuleIDs.push(parentID);

if (Refresh != null) {
// Debounce a little in case there are multiple updates queued up.
// This is also useful because __accept may be called multiple times.
if (reactRefreshTimeout == null) {
reactRefreshTimeout = setTimeout(() => {
reactRefreshTimeout = null;
// Update React components.
Refresh.performReactRefresh();

@@ -731,8 +600,2 @@ }, 30);

if (mod.hasError) {
// This error has already been reported via a redbox.
// We know it's likely a typo or some mistake that was just introduced.
// Our goal now is to keep the rest of the application working so that by
// the time user fixes the error, the app isn't completely destroyed
// underneath the redbox. So we'll revert the module object to the last
// successful export and stop propagating this update.
mod.hasError = false;

@@ -742,3 +605,2 @@ mod.isInitialized = true;

mod.publicModule.exports = prevExports;
// We errored. Stop the update.
return true;

@@ -756,7 +618,5 @@ }

}
// No error.
return false;
};
const performFullRefresh = (reason, modules) => {
/* global window */
if (

@@ -781,4 +641,2 @@ typeof window !== "undefined" &&

};
// Modules that only export components become React Refresh boundaries.
var isReactRefreshBoundary = function (Refresh, moduleExports) {

@@ -789,3 +647,2 @@ if (Refresh.isLikelyComponentType(moduleExports)) {

if (moduleExports == null || typeof moduleExports !== "object") {
// Exit if we can't iterate over exports.
return false;

@@ -802,3 +659,2 @@ }

if (desc && desc.get) {
// Don't invoke getters as they may have side effects.
return false;

@@ -830,4 +686,2 @@ }

};
// When this signature changes, it's unsafe to stop at this refresh boundary.
var getRefreshBoundarySignature = (Refresh, moduleExports) => {

@@ -837,4 +691,2 @@ const signature = [];

if (moduleExports == null || typeof moduleExports !== "object") {
// Exit if we can't iterate over exports.
// (This is important for legacy environments.)
return signature;

@@ -859,4 +711,2 @@ }

if (moduleExports == null || typeof moduleExports !== "object") {
// Exit if we can't iterate over exports.
// (This is important for legacy environments.)
return;

@@ -867,3 +717,2 @@ }

if (desc && desc.get) {
// Don't invoke getters as they may have side effects.
continue;

@@ -879,11 +728,4 @@ }

if (__DEV__) {
// The metro require polyfill can not have module dependencies.
// The Systrace and ReactRefresh dependencies are, therefore, made publicly
// available. Ideally, the dependency would be inversed in a way that
// Systrace / ReactRefresh could integrate into Metro rather than
// having to make them publicly available.
var requireSystrace = function requireSystrace() {
return (
// $FlowFixMe[prop-missing]
global[__METRO_GLOBAL_PREFIX__ + "__SYSTRACE"] || metroRequire.Systrace

@@ -894,3 +736,2 @@ );

return (
// $FlowFixMe[prop-missing]
global[__METRO_GLOBAL_PREFIX__ + "__ReactRefresh"] || metroRequire.Refresh

@@ -897,0 +738,0 @@ );

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc