Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Respect link deps when calculating peerDep sets #249

Merged
merged 1 commit into from
Mar 11, 2021

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Mar 9, 2021

Previously, we were not including link targets in the virtual trees
where peer dependency sets are calculated. Additionally, we were still
using the path /virtual-root for the virtual node, even though this is
no longer load-bearing. (And, as of the other change in this PR to the Node
printable output, no longer necessary or particularly helpful for
debugging.)

As a result, a link dependency from the root node like file:../../foo
would get resolved against /virtual-root, resulting in /foo, which
of course does not match any Node in the virtual tree. The outcome was
an ERESOLVE error where the current Node is shown as having no name
or version (because it is an unsatisfied Link).

The solution is two-part.

First, the path of the virtual tree root now matches the path of the
Node that it is sourced from.

Second, any Link children of the source node have their targets mirrored
in the virtual tree, resulting in them being matched appropriately.

The result is that a Link dependency can now properly satisfy a
peerDependency. Test shows an example of using a Link to a local Node
as a workaround for a peerSet that otherwise would not be resolveable.

This can of course be abused to get around valid peerDep contracts, but
if they user takes it on themselves to use a local fork of a dependency,
we should respect that in buildIdealTree as we do elsewhere.

Fix: npm/cli#2199

@isaacs isaacs requested a review from wraithgar March 9, 2021 19:43
@isaacs isaacs force-pushed the isaacs/fix-peer-set-with-link-deps branch from 962214b to 62d6fd2 Compare March 9, 2021 19:44
Copy link
Contributor

@ruyadorno ruyadorno left a comment

Choose a reason for hiding this comment

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

👍 LGTM

* Show useful debug printing for virtual root nodes
* Respect hidden lockfiles when symlink deps present. As long as the
target of the link is in the shrinkwrap, and not newer.
* Respect link deps when calculating peerDep sets

Previously, we were not including link targets in the virtual trees
where peer dependency sets are calculated.  Additionally, we were still
using the path `/virtual-root` for the virtual node, even though this is
no longer load-bearing.  (And, as of the recent change to the Node
printable output, no longer necessary or particularly helpful for
debugging.)

As a result, a link dependency from the root node like `file:../../foo`
would get resolved against `/virtual-root`, resulting in `/foo`, which
of course does not match any Node in the virtual tree.  The outcome was
an ERESOLVE error where the `current` Node is shown as having no name
or version (because it is an unsatisfied Link).

The solution is two-part.

First, the path of the virtual tree root now matches the path of the
Node that it is sourced from.

Second, any Link children of the source node have their targets mirrored
in the virtual tree, resulting in them being matched appropriately.

The result is that a Link dependency can now properly satisfy a
peerDependency.  Test shows an example of using a Link to a local Node
as a workaround for a peerSet that otherwise would not be resolveable.

This can of course be abused to get around valid peerDep contracts, but
if they user takes it on themselves to use a local fork of a dependency,
we should respect that in buildIdealTree as we do elsewhere.

Fix: npm/cli#2199

PR-URL: #249
Credit: @isaacs
Close: #249
Reviewed-by: @ruyadorno
@ruyadorno ruyadorno force-pushed the isaacs/fix-peer-set-with-link-deps branch from 62d6fd2 to fa16e09 Compare March 11, 2021 20:06
@ruyadorno ruyadorno merged commit fa16e09 into main Mar 11, 2021
@wraithgar wraithgar deleted the isaacs/fix-peer-set-with-link-deps branch April 22, 2021 17:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Locally-installed package should satisfy peer dependency
2 participants