Skip to content

Commit 4d0ce90

Browse files
author
Martin Konicek
committed
CLI: Only use yarn if global CLI uses it
Summary: Check that 'react-native init' itself used yarn to install React Native. When using an old global react-native-cli@1.0.0 (or older), we don't want to install React Native with npm, and React + Jest with yarn. Let's be safe and not mix yarn and npm in a single project. **Test plan** Publish the code in this PR to Sinopia, use that when creating a new project. Using old CLI: npm install -g react-native-cli@1.0.0 react-native init AwesomeApp The generated project doesn't contain `yarn.lock` (everything was installed with the npm client). --- Using new CLI: npm install -g react-native-cli@1.2.0 react-native init AwesomeApp The generated project contains `yarn.lock`, output shows that yarn is used to install React Native, React, Jest. --- In both cases the project runs and Reload JS works: ![screenshot 2016-11-04 17 20 50](https://cloud.githubusercontent.com/assets/346214/20015719/719effb0-a2b4-11e6-84a0-43474314009b.png) Closes #10752 Differential Revision: D4131812 Pulled By: bestander fbshipit-source-id: efaaf97a27005e2c2d10cae5d07afe108d5c0dee
1 parent 0b27d21 commit 4d0ce90

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

local-cli/generator/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ function getYarnVersionIfAvailable() {
4242
}
4343
}
4444

45+
/**
46+
* Check that 'react-native init' itself used yarn to install React Native.
47+
* When using an old global react-native-cli@1.0.0 (or older), we don't want
48+
* to install React Native with npm, and React + Jest with yarn.
49+
* Let's be safe and not mix yarn and npm in a single project.
50+
* @param projectDir e.g. /Users/martin/AwesomeApp
51+
*/
52+
function isGlobalCliUsingYarn(projectDir) {
53+
return fs.existsSync(path.join(projectDir, 'yarn.lock'));
54+
}
55+
4556
module.exports = yeoman.generators.NamedBase.extend({
4657
constructor: function() {
4758
yeoman.generators.NamedBase.apply(this, arguments);
@@ -147,7 +158,7 @@ module.exports = yeoman.generators.NamedBase.extend({
147158
return;
148159
}
149160

150-
const yarnVersion = (!this.options['npm']) && getYarnVersionIfAvailable();
161+
const yarnVersion = (!this.options['npm']) && getYarnVersionIfAvailable() && isGlobalCliUsingYarn(this.destinationRoot());
151162

152163
console.log('Installing React...');
153164
if (yarnVersion) {

0 commit comments

Comments
 (0)