diff --git a/local-cli/generator/index.js b/local-cli/generator/index.js index 6973e239d14..8d6d7992e85 100644 --- a/local-cli/generator/index.js +++ b/local-cli/generator/index.js @@ -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) {