Skip to content

Commit

Permalink
Updated CLI to handle different versions of react and react-test-rend…
Browse files Browse the repository at this point in the history
…erer
  • Loading branch information
Brian Vaughn committed Mar 23, 2017
1 parent 0382460 commit ac37fa4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions local-cli/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ function init(projectDir, argsOrName) {
*/
function generateProject(destinationRoot, newProjectName, options) {
var reactNativePackageJson = require('../../package.json');
var { peerDependencies } = reactNativePackageJson;
var { devDependencies, peerDependencies } = reactNativePackageJson;
if (!peerDependencies) {
console.error('Missing React peer dependency in React Native\'s package.json. Aborting.');
return;
} else if (!devDependencies) {
console.error('Missing react-test-renderer dev dependency in React Native\'s package.json. Aborting.');
}

var reactVersion = peerDependencies.react;
Expand All @@ -72,6 +74,12 @@ function generateProject(destinationRoot, newProjectName, options) {
return;
}

var reactTestRendererVersion = devDependencies['react-test-renderer'];
if (!reactVersion) {
console.error('Missing react-test-renderer dev dependency in React Native\'s package.json. Aborting.');
return;
}

const yarnVersion =
(!options.npm) &&
yarn.getYarnVersionIfAvailable() &&
Expand All @@ -88,7 +96,7 @@ function generateProject(destinationRoot, newProjectName, options) {
}
if (!options['skip-jest']) {
const jestDeps = (
`jest babel-jest babel-preset-react-native react-test-renderer@${reactVersion}`
`jest babel-jest babel-preset-react-native react-test-renderer@${reactTestRendererVersion}`
);
if (yarnVersion) {
console.log('Adding Jest...');
Expand Down

0 comments on commit ac37fa4

Please sign in to comment.