Skip to content

Commit 403f356

Browse files
anpfacebook-github-bot
authored andcommitted
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, expo/create-react-native-app#101, expo/create-react-native-app#113 (comment) 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 #13355 Differential Revision: D4848084 Pulled By: hramos fbshipit-source-id: f32176354e0bd7ff6d7009ea30dca64ff23ae3d5
1 parent d03f9b7 commit 403f356

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

local-cli/util/PackageManager.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ const spawnOpts = {
1515
stdin: 'inherit',
1616
};
1717

18-
const projectDir = process.cwd();
19-
const isYarnAvailable =
20-
yarn.getYarnVersionIfAvailable() &&
21-
yarn.isGlobalCliUsingYarn(projectDir);
22-
2318
/**
2419
* Execute npm or yarn command
2520
*
@@ -30,6 +25,11 @@ const isYarnAvailable =
3025
function callYarnOrNpm(yarnCommand, npmCommand) {
3126
let command;
3227

28+
const projectDir = process.cwd();
29+
const isYarnAvailable =
30+
yarn.getYarnVersionIfAvailable() &&
31+
yarn.isGlobalCliUsingYarn(projectDir);
32+
3333
if (isYarnAvailable) {
3434
command = yarnCommand;
3535
} else {

local-cli/util/yarn.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ function getYarnVersionIfAvailable() {
2121
let yarnVersion;
2222
try {
2323
// execSync returns a Buffer -> convert to string
24-
if (process.platform.startsWith('win')) {
25-
yarnVersion = (execSync('yarn --version').toString() || '').trim();
26-
} else {
27-
yarnVersion = (execSync('yarn --version 2>/dev/null').toString() || '').trim();
28-
}
24+
yarnVersion = (execSync('yarn --version', {
25+
stdio: [ 0, 'pipe', 'ignore', ]
26+
}).toString() || '').trim();
2927
} catch (error) {
3028
return null;
3129
}

0 commit comments

Comments
 (0)