From e36a4f692c52983fb3f477db222a0fa3672f60a1 Mon Sep 17 00:00:00 2001 From: "Michael S. Kazmier" Date: Wed, 25 Oct 2017 11:26:56 -0600 Subject: [PATCH] add ifndef for default ports and change name of env var to RCT_METRO_PORT --- Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj | 4 ++-- Libraries/WebSocket/RCTWebSocketExecutor.h | 4 ++++ Libraries/WebSocket/RCTWebSocketExecutor.m | 2 +- React/Base/RCTBundleURLProvider.h | 4 ++++ React/Base/RCTBundleURLProvider.m | 2 +- React/React.xcodeproj/project.pbxproj | 6 +++--- local-cli/runAndroid/runAndroid.js | 4 ++-- local-cli/runIOS/runIOS.js | 4 ++-- local-cli/server/server.js | 2 +- local-cli/util/isPackagerRunning.js | 2 +- 10 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj b/Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj index 742b905842a01f..8121ed0c108179 100644 --- a/Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj +++ b/Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj @@ -436,7 +436,7 @@ GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", - "RCT_PACKAGER_PORT=${RCT_PACKAGER_PORT}", + "RCT_METRO_PORT=${RCT_METRO_PORT}", ); GCC_TREAT_WARNINGS_AS_ERRORS = NO; OTHER_LDFLAGS = "-ObjC"; @@ -448,7 +448,7 @@ isa = XCBuildConfiguration; buildSettings = { EXECUTABLE_PREFIX = lib; - GCC_PREPROCESSOR_DEFINITIONS = "RCT_PACKAGER_PORT=${RCT_PACKAGER_PORT}"; + GCC_PREPROCESSOR_DEFINITIONS = "RCT_METRO_PORT=${RCT_METRO_PORT}"; GCC_TREAT_WARNINGS_AS_ERRORS = NO; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Libraries/WebSocket/RCTWebSocketExecutor.h b/Libraries/WebSocket/RCTWebSocketExecutor.h index 733da2adb7cc40..8e5664538bcbbb 100644 --- a/Libraries/WebSocket/RCTWebSocketExecutor.h +++ b/Libraries/WebSocket/RCTWebSocketExecutor.h @@ -12,6 +12,10 @@ #if RCT_DEV // Debug executors are only supported in dev mode +#ifndef RCT_METRO_PORT +#define RCT_METRO_PORT 8081 +#endif + @interface RCTWebSocketExecutor : NSObject - (instancetype)initWithURL:(NSURL *)URL; diff --git a/Libraries/WebSocket/RCTWebSocketExecutor.m b/Libraries/WebSocket/RCTWebSocketExecutor.m index 1f7dc1d9ef3a6d..b292c4f9b8ca15 100644 --- a/Libraries/WebSocket/RCTWebSocketExecutor.m +++ b/Libraries/WebSocket/RCTWebSocketExecutor.m @@ -54,7 +54,7 @@ - (instancetype)initWithURL:(NSURL *)URL - (void)setUp { if (!_url) { - NSInteger port = [[[_bridge bundleURL] port] integerValue] ?: RCT_PACKAGER_PORT; + NSInteger port = [[[_bridge bundleURL] port] integerValue] ?: RCT_METRO_PORT; NSString *host = [[_bridge bundleURL] host] ?: @"localhost"; NSString *URLString = [NSString stringWithFormat:@"http://%@:%lld/debugger-proxy?role=client", host, (long long)port]; _url = [RCTConvert NSURL:URLString]; diff --git a/React/Base/RCTBundleURLProvider.h b/React/Base/RCTBundleURLProvider.h index efc9be73bac36f..e6ade241eeb926 100644 --- a/React/Base/RCTBundleURLProvider.h +++ b/React/Base/RCTBundleURLProvider.h @@ -9,6 +9,10 @@ #import +#ifndef RCT_METRO_PORT +#define RCT_METRO_PORT 8081 +#endif + extern NSString *const RCTBundleURLProviderUpdatedNotification; extern const NSUInteger kRCTBundleURLProviderDefaultPort; diff --git a/React/Base/RCTBundleURLProvider.m b/React/Base/RCTBundleURLProvider.m index 29407508516d62..61c286ec4518d6 100644 --- a/React/Base/RCTBundleURLProvider.m +++ b/React/Base/RCTBundleURLProvider.m @@ -14,7 +14,7 @@ NSString *const RCTBundleURLProviderUpdatedNotification = @"RCTBundleURLProviderUpdatedNotification"; -const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_PACKAGER_PORT; +const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_METRO_PORT; static NSString *const kRCTJsLocationKey = @"RCT_jsLocation"; static NSString *const kRCTEnableLiveReloadKey = @"RCT_enableLiveReload"; diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 77343823442b15..a4a87f509da74b 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -3724,7 +3724,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export RCT_PACKAGER_PORT=\"${RCT_PACKAGER_PORT:-8081}\"\necho \"export RCT_PACKAGER_PORT=${RCT_PACKAGER_PORT}\" > \"${SRCROOT}/../scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_PACKAGER_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_PACKAGER_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_PACKAGER_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi"; + shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:-8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi"; showEnvVarsInLog = 0; }; 142C4F7F1B582EA6001F0B58 /* Include RCTJSCProfiler */ = { @@ -4831,7 +4831,7 @@ "RCT_DEBUG=1", "RCT_DEV=1", "RCT_NSASSERT=1", - "RCT_PACKAGER_PORT=${RCT_PACKAGER_PORT}", + "RCT_METRO_PORT=${RCT_METRO_PORT}", ); GCC_WARN_ABOUT_MISSING_NEWLINE = YES; OTHER_LDFLAGS = "-ObjC"; @@ -4849,7 +4849,7 @@ CLANG_STATIC_ANALYZER_MODE = deep; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", - "RCT_PACKAGER_PORT=${RCT_PACKAGER_PORT}", + "RCT_METRO_PORT=${RCT_METRO_PORT}", ); GCC_WARN_ABOUT_MISSING_NEWLINE = YES; OTHER_LDFLAGS = "-ObjC"; diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index a1ae11d57afead..47070821371934 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -273,7 +273,7 @@ function startServerInNewWindow(port) { // setup the .packager.env file to ensure the packager starts on the right port const packagerEnvFile = path.join(__dirname, '..', '..', 'scripts', '.packager.env'); - const content = `export RCT_PACKAGER_PORT=${port}`; + const content = `export RCT_METRO_PORT=${port}`; fs.writeFileSync(packagerEnvFile,content,{encoding: 'utf8', flag:'w'}); // passing the 'w' flag will overwrite the file if (process.platform === 'darwin') { @@ -338,7 +338,7 @@ module.exports = { description: 'Do not launch packager while building', }, { command: '--port [number]', - default: process.env.RCT_PACKAGER_PORT || 8081, + default: process.env.RCT_METRO_PORT || 8081, parse: (val: string) => Number(val), }], }; diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 617bc7fca21084..1dce9c2939420b 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -235,7 +235,7 @@ function printFoundDevices(devices) { function getProcessOptions(launchPackager, port) { if (launchPackager) { return { - env: { ...process.env, RCT_PACKAGER_PORT: port } + env: { ...process.env, RCT_METRO_PORT: port } }; } @@ -291,7 +291,7 @@ module.exports = { description: 'Do not use xcpretty even if installed', },{ command: '--port [number]', - default: process.env.RCT_PACKAGER_PORT || 8081, + default: process.env.RCT_METRO_PORT || 8081, parse: (val: string) => Number(val), }], }; diff --git a/local-cli/server/server.js b/local-cli/server/server.js index 6ad03eaa9fae3b..fe151798ef24d5 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -60,7 +60,7 @@ module.exports = { description: 'starts the webserver', options: [{ command: '--port [number]', - default: process.env.RCT_PACKAGER_PORT || 8081, + default: process.env.RCT_METRO_PORT || 8081, parse: (val: string) => Number(val), }, { command: '--host [string]', diff --git a/local-cli/util/isPackagerRunning.js b/local-cli/util/isPackagerRunning.js index be0090b089e429..fbdebd08d255f9 100644 --- a/local-cli/util/isPackagerRunning.js +++ b/local-cli/util/isPackagerRunning.js @@ -19,7 +19,7 @@ const fetch = require('node-fetch'); * - `unrecognized`: one other process is running on the port we expect the * packager to be running. */ -function isPackagerRunning(packagerPort = (process.env.RCT_PACKAGER_PORT || 8081)) { +function isPackagerRunning(packagerPort = (process.env.RCT_METRO_PORT || 8081)) { return fetch(`http://localhost:${packagerPort}/status`).then( res => res.text().then(body => body === 'packager-status:running' ? 'running' : 'unrecognized'