Skip to content

Commit 3cd0737

Browse files
ihenshawfacebook-github-bot
authored andcommitted
Fix for 17497 (#17498)
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
1 parent 5f8b44f commit 3cd0737

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

local-cli/runAndroid/runAndroid.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -349,25 +349,35 @@ function runOnAllDevices(
349349
}
350350

351351
function startServerInNewWindow(port) {
352-
const scriptFile = /^win/.test(process.platform)
352+
// set up OS-specific filenames and commands
353+
const isWindows = /^win/.test(process.platform);
354+
const scriptFile = isWindows
353355
? 'launchPackager.bat'
354356
: 'launchPackager.command';
357+
const packagerEnvFilename = isWindows
358+
? '.packager.bat'
359+
: '.packager.env';
360+
const portExportContent = isWindows
361+
? `set RCT_METRO_PORT=${port}`
362+
: `export RCT_METRO_PORT=${port}`;
363+
364+
// set up the launchpackager.(command|bat) file
355365
const scriptsDir = path.resolve(__dirname, '..', '..', 'scripts');
356366
const launchPackagerScript = path.resolve(scriptsDir, scriptFile);
357367
const procConfig = {cwd: scriptsDir};
358368
const terminal = process.env.REACT_TERMINAL;
359369

360-
// setup the .packager.env file to ensure the packager starts on the right port
370+
// set up the .packager.(env|bat) file to ensure the packager starts on the right port
361371
const packagerEnvFile = path.join(
362372
__dirname,
363373
'..',
364374
'..',
365375
'scripts',
366-
'.packager.env',
376+
packagerEnvFilename
367377
);
368-
const content = `export RCT_METRO_PORT=${port}`;
378+
369379
// ensure we overwrite file by passing the 'w' flag
370-
fs.writeFileSync(packagerEnvFile, content, {encoding: 'utf8', flag: 'w'});
380+
fs.writeFileSync(packagerEnvFile, portExportContent, {encoding: 'utf8', flag: 'w'});
371381

372382
if (process.platform === 'darwin') {
373383
if (terminal) {

scripts/launchPackager.bat

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@echo off
77
title Metro Bundler
8+
call .packager.bat
89
node "%~dp0..\local-cli\cli.js" start
910
pause
1011
exit

0 commit comments

Comments
 (0)