Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move react to peerDependencies #5813

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions local-cli/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,13 @@ module.exports = yeoman.generators.NamedBase.extend({
{name: this.name}
);
}
},

install: function() {
if (this.options.upgrade) {
return;
}

this.npmInstall('react', { '--save': true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this respect the declared version of React via peerDependencies (0.14.5)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good question, might be worth installing the version we know matches react-native's one, we can get it from RN's package.json's peerDependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to reading the version from RN package.json

}
});
13 changes: 13 additions & 0 deletions local-cli/upgrade/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ module.exports = function upgrade(args, config) {
'https://github.com/facebook/react-native/releases/tag/v' + semver.major(v) + '.' + semver.minor(v) + '.0'
)
);

// >= v0.21.0, we require react to be a peer depdendency
if (semver.gte(v, '0.21.0') && !pak.dependencies['react']) {
console.log(
chalk.yellow(
'\nYour \'package.json\' file doesn\'t seem to have \'react\' as a dependency.\n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style suggestion: I often use template strings for messages so quotes don't have to be escaped

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ide I was just matching other places in the file. I guess I could update the whole file...are template strings supported everywhere now? (the local-cli isn't run through babel-register)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC they shipped with Node 4

'\'react\' was changed from a dependency to a peer dependency in react-native v0.21.0.\n' +
'Therefore, it\'s necessary to include \'react\' in your project\'s dependencies.\n' +
'Just run \'npm install --save react\', then re-run \'react-native upgrade\'.\n'
)
);
return Promise.resolve();
}
} else {
console.log(
chalk.yellow(
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
"bin": {
"react-native": "local-cli/wrong-react-native.js"
},
"peerDependencies": {
"react": "^0.14.5"
},
"dependencies": {
"absolute-path": "^0.0.0",
"art": "^0.10.0",
Expand Down Expand Up @@ -133,7 +136,6 @@
"optimist": "^0.6.1",
"progress": "^1.1.8",
"promise": "^7.1.1",
"react": "^0.14.5",
"react-timer-mixin": "^0.13.2",
"react-transform-hmr": "^1.0.2",
"rebound": "^0.0.13",
Expand Down