From c30d125050d0a82f5133cc14fc82d0fd9e95e371 Mon Sep 17 00:00:00 2001 From: James Ide Date: Thu, 7 Apr 2016 00:06:19 -0700 Subject: [PATCH] Honor the version of "react" under peerDeps when setting up a new project Summary:We need this since React 15.0.0 is coming and will break `react-native init`, which currently installs the latest version of React. We'll need some changes to React Native to support 15 that Sebastian is actively working on, but till that lands we want `react-native init` to continue working. Closes https://github.com/facebook/react-native/pull/6846 Differential Revision: D3148182 Pulled By: sebmarkbage fb-gh-sync-id: 3df5bc184c0b82d2c9c320c620256c7c8568d90b fbshipit-source-id: 3df5bc184c0b82d2c9c320c620256c7c8568d90b --- local-cli/generator/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/local-cli/generator/index.js b/local-cli/generator/index.js index 04b410f12..43c327c5c 100644 --- a/local-cli/generator/index.js +++ b/local-cli/generator/index.js @@ -96,6 +96,17 @@ module.exports = yeoman.generators.NamedBase.extend({ return; } - this.npmInstall('react', { '--save': true }); + var reactNativePackageJson = require('../../package.json'); + var { peerDependencies } = reactNativePackageJson; + if (!peerDependencies) { + return; + } + + var reactVersion = peerDependencies.react; + if (!reactVersion) { + return; + } + + this.npmInstall(`react@${reactVersion}`, { '--save': true }); } });