Skip to content

Commit 9f01f96

Browse files
skevyfacebook-github-bot-1
authored andcommitted
Move react to peerDependencies
Summary: This PR moves `react` from dependencies to peerDependencies. In general, this would have only been important for those people using packages that depend on `react` and were using npm@2...npm@3 would automatically de-dupe. However, when facebook#5812 gets merged, dependencies will be scoped to react-native (on both npm@2 & npm@3), thus breaking projects that are using a package like `react-redux` for example, which depends on `react`. There would be two copies of React installed, and due to the use of haste modules in `react`, this would break the packager and cause naming collisions. This PR does three things - 1. Moves the dependency from dependencies to peerDependencies 2. Updates the local-cli to run `npm install react --save` when a new project is initialized. 3. Updates `react-native upgrade` to warn if `react` is not listed in the package.json's dependencies. **Note: This will require a shrinkwrap update.** Closes facebook#5813 Reviewed By: svcscm Differential Revision: D2918380 Pulled By: androidtrunkagent fb-gh-sync-id: 6e4234a45284be2fdf6fedf29e70b2d2d0262486 shipit-source-id: 6e4234a45284be2fdf6fedf29e70b2d2d0262486
1 parent d97223b commit 9f01f96

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

local-cli/generator/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,13 @@ module.exports = yeoman.generators.NamedBase.extend({
8282
{name: this.name}
8383
);
8484
}
85+
},
86+
87+
install: function() {
88+
if (this.options.upgrade) {
89+
return;
90+
}
91+
92+
this.npmInstall('react', { '--save': true });
8593
}
8694
});

local-cli/upgrade/upgrade.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ module.exports = function upgrade(args, config) {
4444
'https://github.com/facebook/react-native/releases/tag/v' + semver.major(v) + '.' + semver.minor(v) + '.0'
4545
)
4646
);
47+
48+
// >= v0.21.0, we require react to be a peer depdendency
49+
if (semver.gte(v, '0.21.0') && !pak.dependencies['react']) {
50+
console.log(
51+
chalk.yellow(
52+
'\nYour \'package.json\' file doesn\'t seem to have \'react\' as a dependency.\n' +
53+
'\'react\' was changed from a dependency to a peer dependency in react-native v0.21.0.\n' +
54+
'Therefore, it\'s necessary to include \'react\' in your project\'s dependencies.\n' +
55+
'Just run \'npm install --save react\', then re-run \'react-native upgrade\'.\n'
56+
)
57+
);
58+
return Promise.resolve();
59+
}
4760
} else {
4861
console.log(
4962
chalk.yellow(

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
"bin": {
103103
"react-native": "local-cli/wrong-react-native.js"
104104
},
105+
"peerDependencies": {
106+
"react": "^0.14.5"
107+
},
105108
"dependencies": {
106109
"absolute-path": "^0.0.0",
107110
"art": "^0.10.0",
@@ -133,7 +136,6 @@
133136
"optimist": "^0.6.1",
134137
"progress": "^1.1.8",
135138
"promise": "^7.1.1",
136-
"react": "^0.14.5",
137139
"react-timer-mixin": "^0.13.2",
138140
"react-transform-hmr": "^1.0.2",
139141
"rebound": "^0.0.13",

0 commit comments

Comments
 (0)