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

fix: List optional peer dependencies #1390

Closed
wants to merge 1 commit into from
Closed

Conversation

eps1lon
Copy link
Contributor

@eps1lon eps1lon commented Sep 5, 2019

react-dom is required from the main bundle (not really optional I suppose) while react-native is required when using it with react-native and their batched updates.

Additional context:

I'm currently not using this feature myself until node bundles [email protected]. Just creating this PR now so that we can discuss any concerns you have.

@@ -37,8 +37,18 @@
},
"peerDependencies": {
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-native": "^0.18.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never used react-native. Just use the note from the readme:

As of React Native 0.18, React Redux 5.x should work with React Native.

@netlify
Copy link

netlify bot commented Sep 5, 2019

Deploy preview for react-redux-docs ready!

Built with commit 4fde80f

https://deploy-preview-1390--react-redux-docs.netlify.com

@markerikson
Copy link
Contributor

markerikson commented Sep 6, 2019

This has been brought up several times before. The current behavior is quirky but correct, and there's no need to change.

@markerikson markerikson closed this Sep 6, 2019
@timdorr timdorr reopened this Sep 6, 2019
@timdorr
Copy link
Member

timdorr commented Sep 6, 2019

Actually, this is correct, but only once npm >= 6.11 is in greater circulation. It won't show the error (the reason for this extension to the package.json format), but only for those versions.

Let's leave this one open until npm >= 6.11 has been bundled with Node for a while.

@timdorr
Copy link
Member

timdorr commented Sep 6, 2019

BTW, npm releases are delayed 2 weeks before being bundled into node. nodejs/node#29273 is just about ready to go and nodejs/node#29430 still has 12 days to go. But likely the next 12.x release will have it. I'm not sure what the LTS schedule is.

@eps1lon
Copy link
Contributor Author

eps1lon commented Sep 6, 2019

The current behavior is quirky but correct, and there's no need to change.

I'm not sure how you define "correct" in this context but the dependency trees created from it are incorrect. All I could find about "react dom peer" in the issues is an old statement from dan (#130 (comment)) which

  1. no longer applies with peerDependenciesMeta
  2. is in todays ecosystem a bit of an overstatement since a missing peer dependency warning is only a warning for a reason. Nobody is forcing you to install them and from my experience most packages seem to be ok with having them anyway.

@markerikson
Copy link
Contributor

markerikson commented Sep 6, 2019

@eps1lon : previous PRs:

#1261
#1282
#1371
#1366

And I don't care about "most packages". I care that this package would end up forcing everyone to see at least one warning - RN for RD users, and RD for RN users.

@timdorr
Copy link
Member

timdorr commented Sep 6, 2019

If they are marked optional with peerDependenciesMeta, they won't warn at all.

@arcanis
Copy link

arcanis commented Oct 14, 2019

And I don't care about "most packages". I care that this package would end up forcing everyone to see at least one warning - RN for RD users, and RD for RN users.

This is incorrect. With the optional peer dependencies, peer dep warnings will only be printed if:

  • you use an outdated npm version or,
  • you use a recentish npm version AND npm hasn't fixed their server AND only on initial installs (subsequent ones don't print the warning even now).

Anyway, I've just suggested what I think is an reasonable compromise: if you don't list peer dependencies, please at least put the peerDependenciesMeta field. Yarn will understand that it implies a peer dependencies, even if unlisted, and everyone will be happy.

@markerikson
Copy link
Contributor

@arcanis : my statement about wanting to avoid unnecessary warnings still stands, but no, this is the first time I've heard of "optional peer dependencies", so I'm not familiar with the distinction here in how they behave.

@timdorr
Copy link
Member

timdorr commented Oct 14, 2019

I'll add the optional stuff to the package.json now. It doesn't hurt anything to add it. And if the package managers adopt it as working without the peerDeps entry, that's great.

@arcanis
Copy link

arcanis commented Oct 14, 2019

@markerikson Fwiw documentation is here:
https://next.yarnpkg.com/configuration/manifest#peerDependenciesMeta

Note that it's already implemented in both Yarn 1 (initial rfc) and pnpm. Npm has merged my PR too, but they have to do a fix on their server to return the field on the initial installs (they use a special endpoint which removes most fields from the manifest, including the peerDependenciesMeta one).

The distinction is that a package manager will simply discard the warning if the peer dependency is marked optional, but will be able to leverage the information to properly hoist packages (unlisted peer dependencies aren't having a visual effect - they have an actual technical impact regarding how the package managers will setup the tree, hence why not listing them is dangerous for your users).

The change I've just landed makes it possible to list peerDependenciesMeta without listing peerDependencies. That will at least fix Yarn, and npm will benefit from it as well once they'll have fixed their servers (since it'll help them layout the packages correctly).

@timdorr Awesome, thanks! 🙏

@markerikson
Copy link
Contributor

Looks like this was resolved by 388d9e4 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants