From 6c3360825b3f6d490311659b449e70a5ec63f413 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Fri, 7 Apr 2017 11:12:52 -0700 Subject: [PATCH] Stop yarn error message appearing for Windows users of local-cli Summary: On windows, recent versions of local-cli will display a yarn error to stderr when starting the packager (see https://github.com/expo/xde/issues/91, https://github.com/react-community/create-react-native-app/issues/101, https://github.com/react-community/create-react-native-app/issues/113#issuecomment-289185491 for examples of users hitting this in the wild), even though no package management action is being taken. From what I can tell this is what happens: * [`local-cli/util/yarn.js` does not ignore stderr on Windows](https://github.com/facebook/react-native/blob/6fa87134fc68fd447e33a01a538ae0af6710e5d2/local-cli/util/yarn.js#L25) * [`local-cli/util/PackageManager.js` calls the above function when it's require'd](https://github.com/facebook/react-native/blob/6fa87134fc68fd447e33a01a538ae0af6710e5d2/local-cli/util/PackageManager.js#L20) For Windows users who don't have yarn installed, this means that the 'yarn is not recognized as an internal or external command..." error displays wh Closes https://github.com/facebook/react-native/pull/13355 Differential Revision: D4848084 Pulled By: hramos fbshipit-source-id: f32176354e0bd7ff6d7009ea30dca64ff23ae3d5 --- local-cli/util/PackageManager.js | 10 +++++----- local-cli/util/yarn.js | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/local-cli/util/PackageManager.js b/local-cli/util/PackageManager.js index 989aa135fe7202..6d866a0505aa23 100644 --- a/local-cli/util/PackageManager.js +++ b/local-cli/util/PackageManager.js @@ -15,11 +15,6 @@ const spawnOpts = { stdin: 'inherit', }; -const projectDir = process.cwd(); -const isYarnAvailable = - yarn.getYarnVersionIfAvailable() && - yarn.isGlobalCliUsingYarn(projectDir); - /** * Execute npm or yarn command * @@ -30,6 +25,11 @@ const isYarnAvailable = function callYarnOrNpm(yarnCommand, npmCommand) { let command; + const projectDir = process.cwd(); + const isYarnAvailable = + yarn.getYarnVersionIfAvailable() && + yarn.isGlobalCliUsingYarn(projectDir); + if (isYarnAvailable) { command = yarnCommand; } else { diff --git a/local-cli/util/yarn.js b/local-cli/util/yarn.js index 86b0d3f5b354a6..8bef7804eb9b09 100644 --- a/local-cli/util/yarn.js +++ b/local-cli/util/yarn.js @@ -21,11 +21,9 @@ function getYarnVersionIfAvailable() { let yarnVersion; try { // execSync returns a Buffer -> convert to string - if (process.platform.startsWith('win')) { - yarnVersion = (execSync('yarn --version').toString() || '').trim(); - } else { - yarnVersion = (execSync('yarn --version 2>/dev/null').toString() || '').trim(); - } + yarnVersion = (execSync('yarn --version', { + stdio: [ 0, 'pipe', 'ignore', ] + }).toString() || '').trim(); } catch (error) { return null; }