metro-inspector-proxy
Advanced tools
Comparing version 0.72.3 to 0.73.0
{ | ||
"name": "metro-inspector-proxy", | ||
"version": "0.72.3", | ||
"version": "0.73.0", | ||
"description": "🚇 Inspector proxy for React Native and dev tools integration.", | ||
@@ -23,4 +23,4 @@ "main": "src/index.js", | ||
"ws": "^7.5.1", | ||
"yargs": "^15.3.1" | ||
"yargs": "^17.5.1" | ||
} | ||
} |
@@ -9,2 +9,3 @@ /** | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
@@ -29,3 +30,4 @@ "use strict"; | ||
default: "", | ||
}).argv; | ||
}) | ||
.parseSync(); | ||
runInspectorProxy(argv.port, argv.root); |
@@ -5,2 +5,4 @@ "use strict"; | ||
var http = _interopRequireWildcard(require("http")); | ||
var path = _interopRequireWildcard(require("path")); | ||
@@ -64,2 +66,3 @@ | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
@@ -186,10 +189,9 @@ const debug = require("debug")("Metro:InspectorProxy"); | ||
const interceptedResponse = this._interceptMessageFromDebugger( | ||
const handled = this._interceptMessageFromDebugger( | ||
debuggerRequest, | ||
debuggerInfo | ||
debuggerInfo, | ||
socket | ||
); | ||
if (interceptedResponse) { | ||
socket.send(JSON.stringify(interceptedResponse)); | ||
} else { | ||
if (!handled) { | ||
this._sendMessageToDevice({ | ||
@@ -477,17 +479,16 @@ event: "wrappedEvent", | ||
} | ||
} // Allows to make changes in incoming messages from debugger. | ||
} // Allows to make changes in incoming messages from debugger. Returns a boolean | ||
// indicating whether the message has been handled locally (i.e. does not need | ||
// to be forwarded to the target). | ||
_interceptMessageFromDebugger(req, debuggerInfo) { | ||
let response = null; | ||
_interceptMessageFromDebugger(req, debuggerInfo, socket) { | ||
if (req.method === "Debugger.setBreakpointByUrl") { | ||
this._processDebuggerSetBreakpointByUrl(req, debuggerInfo); | ||
} else if (req.method === "Debugger.getScriptSource") { | ||
response = { | ||
id: req.id, | ||
result: this._processDebuggerGetScriptSource(req), | ||
}; | ||
this._processDebuggerGetScriptSource(req, socket); | ||
return true; | ||
} | ||
return response; | ||
return false; | ||
} | ||
@@ -524,5 +525,17 @@ | ||
_processDebuggerGetScriptSource(req) { | ||
_processDebuggerGetScriptSource(req, socket) { | ||
let scriptSource = `Source for script with id '${req.params.scriptId}' was not found.`; | ||
const sendResponse = () => { | ||
const result = { | ||
scriptSource, | ||
}; | ||
socket.send( | ||
JSON.stringify({ | ||
id: req.id, | ||
result, | ||
}) | ||
); | ||
}; | ||
const pathToSource = this._scriptIdToSourcePathMapping.get( | ||
@@ -533,15 +546,45 @@ req.params.scriptId | ||
if (pathToSource) { | ||
let pathIsURL = false; | ||
try { | ||
scriptSource = fs.readFileSync( | ||
path.resolve(this._projectRoot, pathToSource), | ||
"utf8" | ||
); | ||
} catch (err) { | ||
scriptSource = err.message; | ||
pathIsURL = new URL(pathToSource).hostname == "localhost"; | ||
} catch {} | ||
if (pathIsURL) { | ||
http | ||
.get(pathToSource, (httpResponse) => { | ||
const { statusCode } = httpResponse; | ||
if (statusCode == 200) { | ||
httpResponse.setEncoding("utf8"); | ||
scriptSource = ""; | ||
httpResponse.on("data", (body) => { | ||
scriptSource += body; | ||
}); | ||
httpResponse.on("end", () => { | ||
sendResponse(); | ||
}); | ||
} else { | ||
scriptSource = `Fetching ${pathToSource} returned status ${statusCode}`; | ||
sendResponse(); | ||
httpResponse.resume(); | ||
} | ||
}) | ||
.on("error", (e) => { | ||
scriptSource = `Fetching ${pathToSource} failed with error ${e.message}`; | ||
sendResponse(); | ||
}); | ||
} else { | ||
try { | ||
scriptSource = fs.readFileSync( | ||
path.resolve(this._projectRoot, pathToSource), | ||
"utf8" | ||
); | ||
} catch (err) { | ||
scriptSource = err.message; | ||
} | ||
sendResponse(); | ||
} | ||
} | ||
return { | ||
scriptSource, | ||
}; | ||
} | ||
@@ -548,0 +591,0 @@ |
@@ -9,2 +9,3 @@ /** | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
@@ -11,0 +12,0 @@ "use strict"; |
@@ -9,2 +9,3 @@ /** | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
@@ -11,0 +12,0 @@ "use strict"; |
@@ -9,2 +9,3 @@ /** | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
@@ -11,0 +12,0 @@ "use strict"; // Page information received from the device. New page is created for |
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
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
59346
781
2
+ Addedcliui@8.0.1(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcliui@6.0.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@6.2.0(transitive)
- Removedy18n@4.0.3(transitive)
- Removedyargs@15.4.1(transitive)
- Removedyargs-parser@18.1.3(transitive)
Updatedyargs@^17.5.1