Skip to content

Commit 891b87e

Browse files
janicduplessisFacebook Github Bot 0
authored andcommitted
Launch the packager with react-native run-android on Windows
Summary: Adds support for launching the packager in a new window on Windows. **Test plan (required)** Tested that the packager is launched in a completely independent process. This means that exiting the `react-native run-android` command should not close the packager window and it should exit properly when completed even if the packager window is still opened. Pretty much made sure it behaves exactly like on mac. Also tested that an error in the packager will not close the window immediately to show the error stack trace. Closes facebook#7129 Differential Revision: D3240628 Pulled By: mkonicek fb-gh-sync-id: 007582250536481d2b2376f9a201f8f415fc1080 fbshipit-source-id: 007582250536481d2b2376f9a201f8f415fc1080
1 parent 3a5457c commit 891b87e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

local-cli/runAndroid/runAndroid.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ function buildAndRun(args, reject) {
159159
function startServerInNewWindow() {
160160
var yargV = require('yargs').argv;
161161

162+
const scriptFile = /^win/.test(process.platform) ?
163+
'launchPackager.bat' :
164+
'launchPackager.command';
165+
162166
const launchPackagerScript = path.resolve(
163-
__dirname, '..', '..', 'packager', 'launchPackager.command'
167+
__dirname, '..', '..', 'packager', scriptFile
164168
);
165169

166170
if (process.platform === 'darwin') {
@@ -176,13 +180,9 @@ function startServerInNewWindow() {
176180
return child_process.spawn('sh', [launchPackagerScript],{detached: true});
177181

178182
} else if (/^win/.test(process.platform)) {
179-
console.log(chalk.yellow('Starting the packager in a new window ' +
180-
'is not supported on Windows yet.\nPlease start it manually using ' +
181-
'\'react-native start\'.'));
182-
console.log('We believe the best Windows ' +
183-
'support will come from a community of people\nusing React Native on ' +
184-
'Windows on a daily basis.\n' +
185-
'Would you be up for sending a pull request?');
183+
return child_process.spawn(
184+
'cmd.exe', ['/C', 'start', launchPackagerScript], {detached: true, stdio: 'ignore'}
185+
);
186186
} else {
187187
console.log(chalk.red(`Cannot start the packager. Unknown platform ${process.platform}`));
188188
}

packager/launchPackager.bat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:: Copyright (c) 2015-present, Facebook, Inc.
2+
:: All rights reserved.
3+
::
4+
:: This source code is licensed under the BSD-style license found in the
5+
:: LICENSE file in the root directory of this source tree. An additional grant
6+
:: of patent rights can be found in the PATENTS file in the same directory.
7+
8+
@echo off
9+
title React Packager
10+
node "%~dp0..\local-cli\cli.js" start
11+
pause
12+
exit

0 commit comments

Comments
 (0)