-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix: prune optional peer dependencies that are no longer explicitly depended on #8431
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
Conversation
7127150
to
efd74f7
Compare
so the Windows tests are failing because my new test results in a request for the I've kept the adding of the tgz file in case that will be useful - I'm also not sure why this fails only on Windows 😕 |
Yeah this is a GOOD thing cause answering this question will help us know if this PR is right. |
@wraithgar so I've spent a few hours trying to dig into this without much luck, though I'm still pretty sure the failure is about the test setup rather than the fix being wrong - if I revert the fix, then all the tests fail with the same kind of error though there's more of them because it's resolving about 20 more packages. I think the issue is something on the lines of dependencies (not) being cached - the error gets raised when calling this: cli/workspaces/arborist/lib/arborist/reify.js Lines 799 to 803 in c457c75
I also feel like when I revert the fix, the Windows test fail about different packages e.g. it complains about I don't think I'll be able to dig into this much further by myself I'm afraid as I've not found any solid difference between Windows and Linux 😞 |
@wraithgar I've got the tests passing in a manner that you might not be too impressed by, but that I think at least shows the issue isn't with my change |
The workaround is very intentional and well commented. It's always these one-line tweaks that get so far off the rails when it comes to testing. Thank you for seeing this through. |
It's possible the mock npm fixture has a quirk in windows with this caching but fixing that is way outside the scope of this PR. |
Is there a chance of this getting backported? |
@lkraav we typically don't actively do backports but this would probably be something we would consider if a PR was made against the v10 branch |
I have opened #8449 backporting this, unfortunately CI for Linux and macOS is failing - since (ironically) Windows is passing, I'm guessing it's cache related and I wasn't able to figure out the root cause for this PR. My very hacky work for exploring this is in https://github.com/G-Rath/cli/tree/prune-optional-peer2 if someone wants to have a crack at digging further - I'm not sure if I'll have the time this week |
Hey @G-Rath , I'm pretty sure this change broke our CI. I don't think this is a desirable way to fix the linked issue because with this change, it is no longer possible to install a peer optional dependency that isn't tracked as a dependency. This seems like a regression. Can we revert this change? Context: I maintain the mongodb pacakge, which has a number of peer optional dependencies. Some of these are native packages with native addons. One of these dependencies (kerberos) doesn't support the full platform matrix that the mongodb package supports. So we don't track it as a dependency because if we did |
Suppose my package A depends on package B which peer-depends on package C which optionally depends on package D. This change causes D to be removed from package-lock.json and node_modules. That doesn't seem correct. D should still be installed. I think this PR has conflated the concept of optional peer dependencies with the concepts of peer dependencies + optional dependencies. |
This change broke my CI as well where I verify that npm generates no diff in the lockfile. With v11.4.2 such optional peer dependencies were present in the lockfile, but since v11.5.0, they are now absent. The change is fine in itself I guess, but I wonder if npm could better communicate such lockfile-breaking changes better. |
Currently optional peer dependencies are retained so long as at least one package in the tree has them as an optional peer dependency, meaning once added they become non-optional even though
npm
does actually seem to mark such dependencies.To resolve this, I've modified the pruning logic to check for nodes that are both
optional
andpeer
, in addition toextraneous
nodes.References
Resolves #4737