Skip to content

Commit

Permalink
Fix for 17497 (#17498)
Browse files Browse the repository at this point in the history
Summary:
Changed runAndroid.js to generate .packager.bat and launchPackager.ba…t to call it to setup the environment variable

<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

Trying to use react-native on a Windows box with a virus killer that runs on port 8081...

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)
1) Start an android emulator
2) on a react-native project (with the changes), run `react-native run-android --port 9988`.
3) When the packager starts, verify that it states the correct port in the terminal window.
4) verify that the application correctly starts in the Emulator.

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.)

<!--
Help reviewers and the release process by writing your own release notes

**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

  CATEGORY
[----------]        TYPE
[ CLI      ]   [-------------]      LOCATION
[ DOCS     ]   [ BREAKING    ]   [-------------]
[ GENERAL  ]   [ BUGFIX      ]   [-{Component}-]
[ INTERNAL ]   [ ENHANCEMENT ]   [ {File}      ]
[ IOS      ]   [ FEATURE     ]   [ {Directory} ]   |-----------|
[ ANDROID  ]   [ MINOR       ]   [ {Framework} ] - | {Message} |
[----------]   [-------------]   [-------------]   |-----------|

[CATEGORY] [TYPE] [LOCATION] - MESSAGE

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
[INTERNAL] [BUGFIX] [./scripts] - Fixed runAndroid to enable the use of a package on port <> 8081 for Windows.
Closes #17498

Differential Revision: D8682067

Pulled By: hramos

fbshipit-source-id: 6604b827077b3a6a2da9914c1fd36dad6ef30e43
  • Loading branch information
ihenshaw authored and facebook-github-bot committed Jun 28, 2018
1 parent 5f8b44f commit 3cd0737
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions local-cli/runAndroid/runAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,35 @@ function runOnAllDevices(
}

function startServerInNewWindow(port) {
const scriptFile = /^win/.test(process.platform)
// set up OS-specific filenames and commands
const isWindows = /^win/.test(process.platform);
const scriptFile = isWindows
? 'launchPackager.bat'
: 'launchPackager.command';
const packagerEnvFilename = isWindows
? '.packager.bat'
: '.packager.env';
const portExportContent = isWindows
? `set RCT_METRO_PORT=${port}`
: `export RCT_METRO_PORT=${port}`;

// set up the launchpackager.(command|bat) file
const scriptsDir = path.resolve(__dirname, '..', '..', 'scripts');
const launchPackagerScript = path.resolve(scriptsDir, scriptFile);
const procConfig = {cwd: scriptsDir};
const terminal = process.env.REACT_TERMINAL;

// setup the .packager.env file to ensure the packager starts on the right port
// set up the .packager.(env|bat) file to ensure the packager starts on the right port
const packagerEnvFile = path.join(
__dirname,
'..',
'..',
'scripts',
'.packager.env',
packagerEnvFilename
);
const content = `export RCT_METRO_PORT=${port}`;

// ensure we overwrite file by passing the 'w' flag
fs.writeFileSync(packagerEnvFile, content, {encoding: 'utf8', flag: 'w'});
fs.writeFileSync(packagerEnvFile, portExportContent, {encoding: 'utf8', flag: 'w'});

if (process.platform === 'darwin') {
if (terminal) {
Expand Down
1 change: 1 addition & 0 deletions scripts/launchPackager.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@echo off
title Metro Bundler
call .packager.bat
node "%~dp0..\local-cli\cli.js" start
pause
exit

0 comments on commit 3cd0737

Please sign in to comment.