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

Do not ERESOLVE on peerOptionals not added to tree #227

Merged
merged 1 commit into from
Feb 12, 2021

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Feb 11, 2021

Based on #225, land that first.

For these dependency graphs:

# case a
root -> (x, y@1)
x -> PEEROPTIONAL(z)
z -> PEER(y@2)

# case b
root -> (x) PEEROPTIONAL(y@1)
x -> PEEROPTIONAL(y@2)

# case c
root -> (x) PEEROPTIONAL(y@1)
x -> PEER(z)
z -> PEEROPTIONAL(y@2)

The peerOptional dependency is included in the peerSet, which would
raise an ERESOLVE conflict at the peerSet generation stage, even though
the peerOptional dependencies will not actually be added to the tree.

To address this, this commit tracks the nodes which are actually
required in the peerSet generation phase, by virtue of being
non-optionally depended upon by a required node in the peerSet.

If a conflict occurs on a node which is not in the required set during
the peerSet generation phase, we ignore it in much the same way that we
would ignore peerSet errors in metadependencies or when --force is used.

Of course, if the peerOptional dependency is actually required, to
avoid a conflict with an invalid resolution present in the tree already,
and there is no suitable placement for it, then ERESOLVE will still be
raised.

Fix: #223
Fix: npm/cli#2667

"optional": false,
"path": "{CWD}/test/fixtures/peer-optional-eresolve/a/node_modules/@isaacs/testing-peer-optional-conflict-a-x",
"peer": false,
"realpath": "{CWD}/test/fixtures/peer-optional-eresolve/a/node_modules/@isaacs/testing-peer-optional-conflict-a-x",
Copy link
Contributor

@ruyadorno ruyadorno Feb 11, 2021

Choose a reason for hiding this comment

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

heads up, looks like cleanSnapshot is failing to clean {CWD} in all windows ci targets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I missed something there. Gotta get that fixed before landing, might be a real issue.

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

for (const c of cases) {
t.test(`case ${c}`, async t => {
const path = resolve(base, c)
t.matchSnapshot(await buildIdeal(path))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.matchSnapshot(await buildIdeal(path))
t.matchSnapshot(await printIdeal(path))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahhhh, right, because the print does the cleanup. Thanks!

For these dependency graphs:

    # case a
    root -> (x, y@1)
    x -> PEEROPTIONAL(z)
    z -> PEER(y@2)

    # case b
    root -> (x) PEEROPTIONAL(y@1)
    x -> PEEROPTIONAL(y@2)

    # case c
    root -> (x) PEEROPTIONAL(y@1)
    x -> PEER(z)
    z -> PEEROPTIONAL(y@2)

The peerOptional dependency is included in the peerSet, which would
raise an ERESOLVE conflict at the peerSet generation stage, even though
the peerOptional dependencies will not actually be added to the tree.

To address this, this commit tracks the nodes which are actually
required in the peerSet generation phase, by virtue of being
non-optionally depended upon by a required node in the peerSet.

If a conflict occurs on a node which is not in the required set during
the peerSet generation phase, we ignore it in much the same way that we
would ignore peerSet errors in metadependencies or when --force is used.

Of course, if the peerOptional dependency is _actually_ required, to
avoid a conflict with an invalid resolution present in the tree already,
and there is no suitable placement for it, then ERESOLVE will still be
raised.

Fix: #223
Fix: npm/cli#2667

PR-URL: #227
Credit: @isaacs
Close: #227
Reviewed-by: @ruyadorno
@isaacs isaacs force-pushed the isaacs/fix-peer-optional-eresolve branch from 2f8dc90 to f375873 Compare February 12, 2021 16:38
@isaacs isaacs merged commit f375873 into main Feb 12, 2021
@wraithgar wraithgar deleted the isaacs/fix-peer-optional-eresolve 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
3 participants