mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:

Closes https://github.com/facebook/react-native/pull/10752
Differential Revision: D4131812
Pulled By: bestander
fbshipit-source-id: efaaf97a27005e2c2d10cae5d07afe108d5c0dee
This commit is contained in:
@@ -42,6 +42,17 @@ function getYarnVersionIfAvailable() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param projectDir e.g. /Users/martin/AwesomeApp
|
||||
*/
|
||||
function isGlobalCliUsingYarn(projectDir) {
|
||||
return fs.existsSync(path.join(projectDir, 'yarn.lock'));
|
||||
}
|
||||
|
||||
module.exports = yeoman.generators.NamedBase.extend({
|
||||
constructor: function() {
|
||||
yeoman.generators.NamedBase.apply(this, arguments);
|
||||
@@ -147,7 +158,7 @@ module.exports = yeoman.generators.NamedBase.extend({
|
||||
return;
|
||||
}
|
||||
|
||||
const yarnVersion = (!this.options['npm']) && getYarnVersionIfAvailable();
|
||||
const yarnVersion = (!this.options['npm']) && getYarnVersionIfAvailable() && isGlobalCliUsingYarn(this.destinationRoot());
|
||||
|
||||
console.log('Installing React...');
|
||||
if (yarnVersion) {
|
||||
|
||||
Reference in New Issue
Block a user