From d4cc5b53c7770f8206e8dbe99593131a3ad0c2d0 Mon Sep 17 00:00:00 2001 From: jsdevel Date: Wed, 4 May 2016 02:44:42 -0700 Subject: [PATCH] Setting current working directory for dev server. Summary: * This allows `react-native` to work for users on fedora. * `react-native run-android` was failing because the launch packager script was unable to find packager.sh (see `source` in `man bash`). * This change sets cwd for the dev server when run with `run-android`. Closes https://github.com/facebook/react-native/pull/7316 Differential Revision: D3255866 fb-gh-sync-id: 88f6b18f7c61636ce8fecef77f7f4e60b1d9a637 fbshipit-source-id: 88f6b18f7c61636ce8fecef77f7f4e60b1d9a637 --- local-cli/runAndroid/runAndroid.js | 25 ++++++++++++------------- packager/launchPackager.command | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index 864f5bbbaf230c..56b534d92a4d64 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -168,32 +168,31 @@ function buildAndRun(args, reject) { } function startServerInNewWindow() { - var yargV = require('yargs').argv; - + const yargV = require('yargs').argv; const scriptFile = /^win/.test(process.platform) ? 'launchPackager.bat' : 'launchPackager.command'; - - const launchPackagerScript = path.resolve( - __dirname, '..', '..', 'packager', scriptFile - ); + const packagerDir = path.resolve(__dirname, '..', '..', 'packager'); + const launchPackagerScript = path.resolve(packagerDir, scriptFile); + const procConfig = {cwd: packagerDir}; if (process.platform === 'darwin') { if (yargV.open) { - return child_process.spawnSync('open', ['-a', yargV.open, launchPackagerScript]); + return child_process.spawnSync('open', ['-a', yargV.open, launchPackagerScript], procConfig); } - return child_process.spawnSync('open', [launchPackagerScript]); + return child_process.spawnSync('open', [launchPackagerScript], procConfig); } else if (process.platform === 'linux') { + procConfig.detached = true; if (yargV.open){ - return child_process.spawn(yargV.open,['-e', 'sh', launchPackagerScript], {detached: true}); + return child_process.spawn(yargV.open,['-e', 'sh', launchPackagerScript], procConfig); } - return child_process.spawn('sh', [launchPackagerScript],{detached: true}); + return child_process.spawn('sh', [launchPackagerScript], procConfig); } else if (/^win/.test(process.platform)) { - return child_process.spawn( - 'cmd.exe', ['/C', 'start', launchPackagerScript], {detached: true, stdio: 'ignore'} - ); + procConfig.detached = true; + procConfig.stdio = 'ignore'; + return child_process.spawn('cmd.exe', ['/C', 'start', launchPackagerScript], procConfig); } else { console.log(chalk.red(`Cannot start the packager. Unknown platform ${process.platform}`)); } diff --git a/packager/launchPackager.command b/packager/launchPackager.command index 56683667df9235..6f894cfda24304 100755 --- a/packager/launchPackager.command +++ b/packager/launchPackager.command @@ -13,7 +13,7 @@ clear THIS_DIR=$(dirname "$0") pushd "$THIS_DIR" -source packager.sh +source ./packager.sh popd echo "Process terminated. Press to close the window"