-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adds missing dependencies to data-stores #45911
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added react dependencies seem odd to me. In theory, this package shouldn't depend on react as far as I'm aware. In practice, it'll probably always be used with react and this will be fine.
I'm surprised to see @testing-library/react
. We aren't rendering or doing any lifecycle things in this package (I hope). A quick look suggests this is just re-exported from @testing-library/dom
, so we could make that transitive dependency explicit and use it directly. I think that would be better (cc: @p-jackson @andrewserong via #40114)
React is required to be present when this package is imported, because i18n-calypso says so. But we don't want bring in our own copy, so we declare it as a peerDependency.
Darn! I wish we didn't have that dependency here 😞
574118a
to
fe311ab
Compare
Looks like we were depending on |
Thank you! 🙇 |
@sirreal it seems React comes from i18n-calypso. Unmet transitive peer dependency on react@^16.8, via i18n-calypso@^5.0.0 |
Moreover, |
I think we either declare So if we must declare it, I think the best approach is to declare it as a Edit: based on a quick test, Extra note: doing |
The Peer dependency means that the package imports stuff from that package (e.g., webpack plugins import from the Why can't that work transitively? If I'd expect Yarn to check the installed tree and fail in case when I see one case where declaring the dependency on
Now, the But |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I write in #45911 (comment), I think that adding react
as a peer dependency of data-stores
doesn't affect any scenario that can actually happen in practice. But the Yarn Doctor's advice follows the Hippocratic oath (do no harm), as it should, so let's follow it.
If my tests are correct, that's just the way
It is also a package that we publish to NPM registry. That's the use case that breaks if the dependencies are not right. |
What were you testing for? That if your app depends on
That's fine, because the published package will be a dependency of something else, something that is supposed to install |
After a few more tests, this is the behaviour I see (using
With NPM
With Yarn
Looks like both package managers will warn about missing peer dependencies in some cases, but looks like I can't find any authoritative doc saying if a package should re-declare transitive
(from yarnpkg/berry#3) |
Thanks @scinos for the extra details 👍 Peer dependencies indeed look like a complex topic and all my attempts to understand it end up quickly in deep rabbit holes 🙁 There is, for example, this long conversation between NPM and Yarn maintainers about whether to automatically install them: npm/rfcs#43
In your example, it's right for both package managers to warn, because the NPM will not issue the warning only when I can imagine at least one scenario where the NPM validation might fail us -- not warning although it should. Suppose that I suspect that this case might be somehow mitigated by re-declaring the peer deps, although I don't know why and don't want to research it at this moment. |
Background
There are a few undeclared dependencies, found by running
npx @yarnpkg/doctor
:Changes
@testing-library/react
,jest-fetch-mock
andnock
. Version ranges have been copied from./package.json
.react
andreact-dom
as devDependencies (they are peerDependencies of@testing-library/react
). Version ranges have been copied from./package.json
as well.peerDependency
toreact
, required byi18n-calypso
.The reasoning for declaring react twice is:
devDependency
.i18n-calypso
says so. But we don't want bring in our own copy, so we declare it as apeerDependency
.But to be honest, I'm not 100% sure of my reasoning. Please let me know if you think we should do something different.
Testing instructions
Run
cd packages/data-stores && npx @yarnpkg/doctor
and check the warnings about missing dependencies are gone