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

Conversation

skevy
Copy link
Contributor

@skevy skevy commented Feb 8, 2016

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 [email protected]@3 would automatically de-dupe.

However, when #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.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @frantic and @winterbe to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 8, 2016
@skevy
Copy link
Contributor Author

skevy commented Feb 8, 2016

cc @ide

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

@facebook-github-bot
Copy link
Contributor

@skevy updated the pull request.

@facebook-github-bot
Copy link
Contributor

@skevy updated the pull request.

@@ -1,6 +1,6 @@
{
"name": "react-native",
"version": "0.0.0-master",
"version": "0.22.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to keep the version here to make it clear we're on master?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a remnant of testing in the middle of the night and me being tired. Will fix. :)

@mkonicek
Copy link
Contributor

mkonicek commented Feb 8, 2016

Updates react-native-cli to install react ... this will require a release of a new version of rn CLI

Is this still relevant? The CLI is here: https://github.com/facebook/react-native/blob/master/react-native-cli/index.js

What happens when people don't run react-native upgrade and simply bump the version of react-native in the package.json of their apps?

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

@mkonicek
Copy link
Contributor

mkonicek commented Feb 8, 2016

I'm not the best person to review this. cc @martinbigio

@skevy
Copy link
Contributor Author

skevy commented Feb 8, 2016

@mkonicek that note is not still relevant...I took @frantic's advice and moved the code that does anything re: installing react-native to local-cli. PR description has been updated accordingly.

@facebook-github-bot
Copy link
Contributor

@skevy updated the pull request.

@mkonicek
Copy link
Contributor

mkonicek commented Feb 9, 2016

Cool, thanks @skevy! I'll let @martinbigio or @ide merge this as I'm not that familiar with npm.

@ide
Copy link
Contributor

ide commented Feb 9, 2016

I restarted the E2E tests since the failure looked related to the npm repo. Let's get the E2E tests passing and then merge this. We have a bunch of time including a 2-week RC period to shake out issues.

@ide
Copy link
Contributor

ide commented Feb 9, 2016

E2E tests look good. I took a closer look at the Obj-C tests and found that they run the UIExplorer. So @skevy I think we either need to add "npm install react" to travis.yml (hacky solution but has some nice properties, like we install all of RN's dependencies just once) or set up a package.json in each example project and be sure to run something like cd Examples/UIExplorer && npm install in the Obj-C test

@skevy
Copy link
Contributor Author

skevy commented Feb 9, 2016

@ide I don't think the obj-c test failed because of this change.

It's still installing react:

asdf

That's because npm only doesn't install peer deps automatically when it's installing dependencies. When you run npm install in the root of a project, like React Native, it will install dev/prod/peer deps.

@ide
Copy link
Contributor

ide commented Feb 9, 2016

Snazzy. move fast break things, let's do it

@ide
Copy link
Contributor

ide commented Feb 9, 2016

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1964504793775223/int_phab to review.

1 similar comment
@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1964504793775223/int_phab to review.

@skevy
Copy link
Contributor Author

skevy commented Feb 9, 2016

Excuse me @ide I think it's "move fast with STABLE INFRA".

Get it right.

@skevy
Copy link
Contributor Author

skevy commented Feb 9, 2016

In all seriousness though, somebody (@mkonicek?) stop this import. I didn't fix the npm install command in the generator, and would like to do that before this goes to core.

@skevy
Copy link
Contributor Author

skevy commented Feb 9, 2016

Eh. nvm. I'll just fix in a follow up diff. This works for now.

@ide
Copy link
Contributor

ide commented Feb 9, 2016

This will get Relay working. We can fix things like getting the react version right shortly after.

@skevy
Copy link
Contributor Author

skevy commented Feb 9, 2016

*almost will get Relay working...still waiting on #5084 :(

@ghost ghost closed this in 9f01f96 Feb 9, 2016
@mkonicek
Copy link
Contributor

Note: This will require a shrinkwrap update.

Can you elaborate please? @davidaurelio do we need to do anything internally?

Snazzy. move fast break things, let's do it

@skevy Are you happy with the PR now? Is there a followup we should merge?

@mkonicek
Copy link
Contributor

@skevy I'm trying to understand the note about the shrinkwrap file - why not update it as part of this PR? https://github.com/facebook/react-native/blob/master/npm-shrinkwrap.json

@skevy
Copy link
Contributor Author

skevy commented Feb 10, 2016

@mkonicek honestly I didn't update the shrinkwrap because I thought that you guys had a process internally that would update the shrinkwrap automatically when deps were changed. I'm not sure where I heard that :)

If you don't mind updating it for this change (given that this is already merged in)...and then in the future any PR's I send that change dependencies, I'll make sure I update shrinkwrap.

@ide
Copy link
Contributor

ide commented Feb 10, 2016

The issue with updating shrinkwrap.json (as I understand it) is that FB might not have the correct versions of the modules in trunk, so the shrinkwrap had to be generated by FB.

This might be addressed recently by the FB npm package tools. Ideally what would happen is PRs would include npm-shrinkwrap.json, then something inside of FB would run npm install and get all of the packages, and then feed the packages into FB's npm tooling. That way npm-shrinkwrap.json acts as a source of truth.

@davidaurelio
Copy link
Contributor

This breaks our internal shrinkwrap process @mkonicek @bestander @martinbigio

(when using npm3. npm2 is fine)

@mkonicek
Copy link
Contributor

mkonicek commented Mar 3, 2016

@skevy I just created a new app with npm2. package.json has deps as follows:

"dependencies": {
  "react": "^0.14.7",
  "react-native": "^0.22.0"
}

I'm using npm2. When starting the packager using npm start I get:

Failed to build DependencyGraph: @providesModule naming collision:
  Duplicate module name: ViewportMetrics
 Paths: /private/tmp/Zero22/node_modules/react/lib/ViewportMetrics.js collides with /private/tmp/Zero22/node_modules/react-native/node_modules/react/lib/ViewportMetrics.js

So it looks like this PR fixed collisions for some use cases but broke them for others (specifically, no one is able to work on their React Native apps if they're using npm 2).

@mkonicek
Copy link
Contributor

mkonicek commented Mar 3, 2016

@skevy tells me this is resolved by facebookarchive/node-haste#33

pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
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 [email protected]@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
grabbou pushed a commit to react-native-community/cli that referenced this pull request Sep 26, 2018
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 [email protected]@3 would automatically de-dupe.

However, when #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/react-native#5813

Reviewed By: svcscm

Differential Revision: D2918380

Pulled By: androidtrunkagent

fb-gh-sync-id: 6e4234a45284be2fdf6fedf29e70b2d2d0262486
shipit-source-id: 6e4234a45284be2fdf6fedf29e70b2d2d0262486
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants