Skip to content

Commit

Permalink
Backout "Remove runInspectorProxy option"
Browse files Browse the repository at this point in the history
Summary: Backs out D48066221. This change caused direct debugging of Hermes in Flipper and Chrome inspector to stop working.

Reviewed By: motiz88

Differential Revision: D48158187

fbshipit-source-id: c47b6d874918d8daabef6407386a9e0b5494294b
  • Loading branch information
rozele authored and facebook-github-bot committed Aug 8, 2023
1 parent 13d0001 commit 6fc9f9d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Object {
"enhanceMiddleware": [Function],
"port": 8081,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
"unstable_serverRoot": null,
"useGlobalHotkey": true,
"verifyConnections": false,
Expand Down Expand Up @@ -278,6 +279,7 @@ Object {
"enhanceMiddleware": [Function],
"port": 8081,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
"unstable_serverRoot": null,
"useGlobalHotkey": true,
"verifyConnections": false,
Expand Down Expand Up @@ -455,6 +457,7 @@ Object {
"enhanceMiddleware": [Function],
"port": 8081,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
"unstable_serverRoot": null,
"useGlobalHotkey": true,
"verifyConnections": false,
Expand Down Expand Up @@ -632,6 +635,7 @@ Object {
"enhanceMiddleware": [Function],
"port": 8081,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
"unstable_serverRoot": null,
"useGlobalHotkey": true,
"verifyConnections": false,
Expand Down
2 changes: 2 additions & 0 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type ServerConfigT = {
enhanceMiddleware: (Middleware, MetroServer) => Middleware | Server,
port: number,
rewriteRequestUrl: string => string,
runInspectorProxy: boolean,
unstable_serverRoot: ?string,
useGlobalHotkey: boolean,
verifyConnections: boolean,
Expand Down Expand Up @@ -261,6 +262,7 @@ export type YargArguments = $ReadOnly<{
transformer?: string,
'reset-cache'?: boolean,
resetCache?: boolean,
runInspectorProxy?: boolean,
verbose?: boolean,
...
}>;
1 change: 1 addition & 0 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
enhanceMiddleware: (middleware, _) => middleware,
port: 8081,
rewriteRequestUrl: url => url,
runInspectorProxy: true,
unstable_serverRoot: null,
useGlobalHotkey: true,
verifyConnections: false,
Expand Down
6 changes: 6 additions & 0 deletions packages/metro-config/src/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ function overrideConfigWithArguments(
output.server.port = Number(argv.port);
}

if (argv.runInspectorProxy != null) {
// $FlowFixMe[incompatible-use]
// $FlowFixMe[cannot-write]
output.server.runInspectorProxy = Boolean(argv.runInspectorProxy);
}

if (argv.projectRoot != null) {
output.projectRoot = argv.projectRoot;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/metro-config/types/configTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface ServerConfigT {
) => Middleware | Server;
port: number;
rewriteRequestUrl: (url: string) => string;
runInspectorProxy: boolean;
unstable_serverRoot: string | null;
useGlobalHotkey: boolean;
verifyConnections: boolean;
Expand Down Expand Up @@ -250,5 +251,6 @@ export interface YargArguments {
transformer?: string;
'reset-cache'?: boolean;
resetCache?: boolean;
runInspectorProxy?: boolean;
verbose?: boolean;
}
1 change: 1 addition & 0 deletions packages/metro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"metro-config": "0.78.0",
"metro-core": "0.78.0",
"metro-file-map": "0.78.0",
"metro-inspector-proxy": "0.78.0",
"metro-minify-terser": "0.78.0",
"metro-resolver": "0.78.0",
"metro-runtime": "0.78.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/metro/src/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const {
resolveConfig,
} = require('metro-config');
const {Terminal} = require('metro-core');
const {InspectorProxy} = require('metro-inspector-proxy');
const net = require('net');
const {parse} = require('url');

Expand All @@ -67,6 +68,7 @@ export type RunServerOptions = $ReadOnly<{
host?: string,
onError?: (Error & {code?: string}) => void,
onReady?: (server: HttpServer | HttpsServer) => void,
runInspectorProxy?: boolean,
secureServerOptions?: Object,
secure?: boolean, // deprecated
secureCert?: string, // deprecated
Expand Down Expand Up @@ -279,6 +281,11 @@ exports.runServer = async (
serverApp.use(handler);
}

let inspectorProxy: ?InspectorProxy = null;
if (config.server.runInspectorProxy) {
inspectorProxy = new InspectorProxy(config.projectRoot);
}

let httpServer;

if (secure || secureServerOptions != null) {
Expand Down Expand Up @@ -315,6 +322,9 @@ exports.runServer = async (

websocketEndpoints = {
...websocketEndpoints,
...(inspectorProxy
? {...inspectorProxy.createWebSocketListeners(httpServer)}
: {}),
'/hot': createWebsocketServer({
websocketServer: new MetroHmrServer(
metroServer.getBundler(),
Expand All @@ -340,6 +350,14 @@ exports.runServer = async (
}
});

if (inspectorProxy) {
// TODO(hypuk): Refactor inspectorProxy.processRequest into separate request handlers
// so that we could provide routes (/json/list and /json/version) here.
// Currently this causes Metro to give warning about T31407894.
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
serverApp.use(inspectorProxy.processRequest.bind(inspectorProxy));
}

resolve(httpServer);
});

Expand Down
1 change: 1 addition & 0 deletions packages/metro/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface RunServerOptions {
host?: string;
onError?: (error: Error & {code?: string}) => void;
onReady?: (server: HttpServer | HttpsServer) => void;
runInspectorProxy?: boolean;
secureServerOptions?: Record<string, unknown>;

/** @deprecated since version 0.61 */
Expand Down

0 comments on commit 6fc9f9d

Please sign in to comment.