Skip to content

Commit

Permalink
add ifndef for default ports and change name of env var to RCT_METRO_…
Browse files Browse the repository at this point in the history
…PORT
  • Loading branch information
Michael S. Kazmier committed Nov 6, 2017
1 parent 75b60c9 commit e36a4f6
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)";
Expand Down
4 changes: 4 additions & 0 deletions Libraries/WebSocket/RCTWebSocketExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <RCTJavaScriptExecutor>

- (instancetype)initWithURL:(NSURL *)URL;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/WebSocket/RCTWebSocketExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions React/Base/RCTBundleURLProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#import <Foundation/Foundation.h>

#ifndef RCT_METRO_PORT
#define RCT_METRO_PORT 8081
#endif

extern NSString *const RCTBundleURLProviderUpdatedNotification;

extern const NSUInteger kRCTBundleURLProviderDefaultPort;
Expand Down
2 changes: 1 addition & 1 deletion React/Base/RCTBundleURLProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions React/React.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ = {
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions local-cli/runAndroid/runAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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),
}],
};
4 changes: 2 additions & 2 deletions local-cli/runIOS/runIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};
}

Expand Down Expand Up @@ -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),
}],
};
2 changes: 1 addition & 1 deletion local-cli/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]',
Expand Down
2 changes: 1 addition & 1 deletion local-cli/util/isPackagerRunning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit e36a4f6

Please sign in to comment.