Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 17497 #17498

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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