Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metro-inspector-proxy

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-inspector-proxy - npm Package Compare versions

Comparing version 0.59.0 to 0.60.0

4

package.json
{
"name": "metro-inspector-proxy",
"version": "0.59.0",
"version": "0.60.0",
"description": "metro-inspector-proxy",

@@ -23,4 +23,4 @@ "main": "src/index.js",

"ws": "^1.1.5",
"yargs": "^14.2.0"
"yargs": "^15.3.1"
}
}

@@ -17,8 +17,15 @@ /**

yargs.option("port", {
alias: "p",
describe: "port to run inspector proxy on",
type: "number",
default: 8081
});
runInspectorProxy(yargs.argv.port);
const argv = yargs
.option("port", {
alias: "p",
describe: "port to run inspector proxy on",
type: "number",
default: 8081
})
.option("root", {
alias: "r",
describe: "root folder of metro project",
type: "string",
default: ""
}).argv;
runInspectorProxy(argv.port, argv.root);

@@ -12,2 +12,6 @@ /**

var fs = _interopRequireWildcard(require("fs"));
var path = _interopRequireWildcard(require("path"));
var _ws = _interopRequireDefault(require("ws"));

@@ -19,2 +23,44 @@

function _getRequireWildcardCache() {
if (typeof WeakMap !== "function") return null;
var cache = new WeakMap();
_getRequireWildcardCache = function() {
return cache;
};
return cache;
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
return { default: obj };
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function _defineProperty(obj, key, value) {

@@ -65,3 +111,4 @@ if (key in obj) {

// The previous "GetPages" message, for deduplication in debug logs.
constructor(id, name, app, socket) {
// Mapping built from scriptParsed events and used to fetch file content in `Debugger.getScriptSource`.
constructor(id, name, app, socket, projectRoot) {
_defineProperty(this, "_debuggerConnection", null);

@@ -75,2 +122,4 @@

_defineProperty(this, "_scriptIdToSourcePathMapping", new Map());
this._id = id;

@@ -81,2 +130,3 @@ this._name = name;

this._deviceSocket = socket;
this._projectRoot = projectRoot;

@@ -154,13 +204,20 @@ this._deviceSocket.on("message", message => {

debug("(Debugger) -> (Proxy) (Device): " + message);
const parsedMessage = JSON.parse(message);
const debuggerRequest = JSON.parse(message);
this._processMessageFromDebugger(parsedMessage, debuggerInfo);
const interceptedResponse = this._interceptMessageFromDebugger(
debuggerRequest,
debuggerInfo
);
this._sendMessageToDevice({
event: "wrappedEvent",
payload: {
pageId: this._getPageId(pageId),
wrappedEvent: JSON.stringify(parsedMessage)
}
});
if (interceptedResponse) {
socket.send(JSON.stringify(interceptedResponse));
} else {
this._sendMessageToDevice({
event: "wrappedEvent",
payload: {
pageId: this._getPageId(pageId),
wrappedEvent: JSON.stringify(debuggerRequest)
}
});
}
});

@@ -337,3 +394,2 @@ socket.on("close", () => {

} // Allows to make changes in incoming message from device.
// eslint-disable-next-line lint/no-unclear-flowtypes

@@ -376,2 +432,6 @@ _processMessageFromDevice(payload, debuggerInfo) {

}
if (params.scriptId != null) {
this._scriptIdToSourcePathMapping.set(params.scriptId, params.url);
}
}

@@ -381,6 +441,11 @@

// Chrome won't use the source map unless it appears to be new.
payload.params.sourceMapURL +=
"&cachePrevention=" + this._getPageId(debuggerInfo.pageId);
payload.params.url +=
"&cachePrevention=" + this._getPageId(debuggerInfo.pageId);
if (payload.params.sourceMapURL) {
payload.params.sourceMapURL +=
"&cachePrevention=" + this._getPageId(debuggerInfo.pageId);
}
if (payload.params.url) {
payload.params.url +=
"&cachePrevention=" + this._getPageId(debuggerInfo.pageId);
}
}

@@ -422,14 +487,23 @@ }

} // Allows to make changes in incoming messages from debugger.
// eslint-disable-next-line lint/no-unclear-flowtypes
_processMessageFromDebugger(payload, debuggerInfo) {
_interceptMessageFromDebugger(req, debuggerInfo) {
let response = null;
if (req.method === "Debugger.setBreakpointByUrl") {
this._processDebuggerSetBreakpointByUrl(req, debuggerInfo);
} else if (req.method === "Debugger.getScriptSource") {
response = {
id: req.id,
result: this._processDebuggerGetScriptSource(req)
};
}
return response;
}
_processDebuggerSetBreakpointByUrl(req, debuggerInfo) {
// If we replaced Android emulator's address to localhost we need to change it back.
if (
payload.method === "Debugger.setBreakpointByUrl" &&
debuggerInfo.originalSourceURLAddress
) {
const params = payload.params || {};
if ("url" in params) {
payload.params.url = params.url.replace(
if (debuggerInfo.originalSourceURLAddress) {
if (req.params.url) {
req.params.url = req.params.url.replace(
"localhost",

@@ -440,12 +514,13 @@ debuggerInfo.originalSourceURLAddress

if (
payload.params.url.startsWith(FILE_PREFIX) &&
req.params.url &&
req.params.url.startsWith(FILE_PREFIX) &&
debuggerInfo.prependedFilePrefix
) {
// Remove fake URL prefix if we modified URL in _processMessageFromDevice.
payload.params.url = payload.params.url.slice(FILE_PREFIX.length);
req.params.url = req.params.url.slice(FILE_PREFIX.length);
}
}
if ("urlRegex" in params) {
payload.params.urlRegex = params.urlRegex.replace(
if (req.params.urlRegex) {
req.params.urlRegex = req.params.urlRegex.replace(
/localhost/g,

@@ -458,2 +533,25 @@ debuggerInfo.originalSourceURLAddress

_processDebuggerGetScriptSource(req) {
let scriptSource = `Source for script with id '${req.params.scriptId}' was not found.`;
const pathToSource = this._scriptIdToSourcePathMapping.get(
req.params.scriptId
);
if (pathToSource) {
try {
scriptSource = fs.readFileSync(
path.resolve(this._projectRoot, pathToSource),
"utf8"
);
} catch (err) {
scriptSource = err.message;
}
}
return {
scriptSource
};
}
_getPageId(pageId) {

@@ -460,0 +558,0 @@ if (

@@ -17,4 +17,4 @@ /**

function runInspectorProxy(port) {
const inspectorProxy = new InspectorProxy();
function runInspectorProxy(port, projectRoot) {
const inspectorProxy = new InspectorProxy(projectRoot);

@@ -21,0 +21,0 @@ const app = require("connect")();

@@ -46,3 +46,6 @@ /**

return (
_arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest()
_arrayWithHoles(arr) ||
_iterableToArrayLimit(arr, i) ||
_unsupportedIterableToArray(arr, i) ||
_nonIterableRest()
);

@@ -52,6 +55,26 @@ }

function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
throw new TypeError(
"Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr)))
return;
var _arr = [];

@@ -120,2 +143,3 @@ var _n = true;

class InspectorProxy {
// Root of the project used for relative to absolute source path conversion.
// Maps device ID to Device instance.

@@ -126,3 +150,3 @@ // Internal counter for device IDs -- just gets incremented for each new device.

// by debugger to know where to connect.
constructor() {
constructor(projectRoot) {
_defineProperty(this, "_deviceCounter", 0);

@@ -132,2 +156,3 @@

this._projectRoot = projectRoot;
this._devices = new Map();

@@ -186,5 +211,3 @@ } // Process HTTP request sent to server. We only respond to 2 HTTP requests:

_buildPageDescription(deviceId, device, page) {
const debuggerUrl = `${
this._serverAddressWithPort
}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;
const debuggerUrl = `${this._serverAddressWithPort}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;
const webSocketDebuggerUrl = "ws://" + debuggerUrl;

@@ -232,4 +255,3 @@ const devtoolsFrontendUrl =

"connection",
/*#__PURE__*/
(function() {
/*#__PURE__*/ (function() {
var _ref3 = _asyncToGenerator(function*(socket) {

@@ -245,3 +267,9 @@ try {

deviceId,
new Device(deviceId, deviceName, appName, socket)
new Device(
deviceId,
deviceName,
appName,
socket,
_this._projectRoot
)
);

@@ -282,4 +310,3 @@

"connection",
/*#__PURE__*/
(function() {
/*#__PURE__*/ (function() {
var _ref4 = _asyncToGenerator(function*(socket) {

@@ -286,0 +313,0 @@ try {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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