From 3cd0737fe2dce9df29822854bfbfaf2f22346c69 Mon Sep 17 00:00:00 2001 From: Ian Henshaw Date: Thu, 28 Jun 2018 14:02:34 -0700 Subject: [PATCH] Fix for 17497 (#17498) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Changed runAndroid.js to generate .packager.bat and launchPackager.ba…t to call it to setup the environment variable 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.) [INTERNAL] [BUGFIX] [./scripts] - Fixed runAndroid to enable the use of a package on port <> 8081 for Windows. Closes https://github.com/facebook/react-native/pull/17498 Differential Revision: D8682067 Pulled By: hramos fbshipit-source-id: 6604b827077b3a6a2da9914c1fd36dad6ef30e43 --- local-cli/runAndroid/runAndroid.js | 20 +++++++++++++++----- scripts/launchPackager.bat | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index 234530c104156e..cd21b6ac29cfd7 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -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) { diff --git a/scripts/launchPackager.bat b/scripts/launchPackager.bat index 09f1de98737002..b85ecc6822ce4a 100644 --- a/scripts/launchPackager.bat +++ b/scripts/launchPackager.bat @@ -5,6 +5,7 @@ @echo off title Metro Bundler +call .packager.bat node "%~dp0..\local-cli\cli.js" start pause exit