Support custom metro ports (#2050)

Summary:
Based on issue https://github.com/facebook/flipper/issues/1509 I needed a custom port for the metro server to pass to flipper.

## Changelog

introduce `METRO_SERVER_PORT` env variable to be able to customize default 8081 port on startup.

Pull Request resolved: https://github.com/facebook/flipper/pull/2050

Test Plan:
Tested with a locally built linux desktop app, this seems to work OK pour hermes debugging & RN logging.

React DevTools don't seem to find the running app, maybe there's a mapping to handle there too ?

Reviewed By: jknoxville

Differential Revision: D27339006

Pulled By: passy

fbshipit-source-id: b1700c4fe73f14bf4617e23583b2954012e0a5aa
This commit is contained in:
Mathis Gardon
2021-03-31 03:29:18 -07:00
committed by Facebook GitHub Bot
parent c183ba33c5
commit f25d189aa5
5 changed files with 43 additions and 9 deletions

View File

@@ -7,13 +7,13 @@
* @format
*/
import {parseEnvironmentVariableAsNumber} from './environmentVariables';
export default () => {
const serverPortString = process.env.ANDROID_ADB_SERVER_PORT;
let port = 5037;
if (serverPortString) {
const parsedInt = parseInt(serverPortString, 10);
port = isNaN(parsedInt) ? port : parsedInt;
}
let port = parseEnvironmentVariableAsNumber(
'ANDROID_ADB_SERVER_PORT',
5037,
) as number;
let host = 'localhost';

View File

@@ -25,3 +25,15 @@ export function parseFlipperPorts(
};
}
}
export function parseEnvironmentVariableAsNumber(
envVarName: string,
defaultValue?: number,
): number | undefined {
const envVarAsString = process.env[envVarName];
if (envVarAsString) {
const parsedInt = parseInt(envVarAsString, 10);
return isNaN(parsedInt) ? defaultValue : parsedInt;
}
return defaultValue;
}