Skip to content

fix: peer edge crash due to no parent or detached node #8448

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

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,12 @@ This is a one-time fix-up, please be patient...
.sort(({ name: a }, { name: b }) => localeCompare(a, b))

for (const edge of peerEdges) {
// node.parent gets mutated during loop execution due to recursive #nodeFromEdge calls.
// When a compatible peer is found (e.g. [email protected] replaces [email protected]), the original node loses its parent.
// if node is detached/removed from the tree, or has no parent, so no need to check remaining edgesOut for that node.
if (!node.parent) {
break
}
// already placed this one, and we're happy with it.
if (edge.valid && edge.to) {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74672,6 +74672,315 @@ exports[`test/arborist/build-ideal-tree.js TAP more peer dep conflicts metadeps
Array []
`

exports[`test/arborist/build-ideal-tree.js TAP more peer dep conflicts peerDep replacement of top level dep with different version resulting detached top level dep > default result 1`] = `
ArboristNode {
"children": Map {
"@test/a" => ArboristNode {
"dev": true,
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "@test/a",
"spec": "^1.1.0",
"type": "dev",
},
EdgeIn {
"from": "node_modules/@test/b",
"name": "@test/a",
"spec": "1.1.0",
"type": "peer",
},
},
"edgesOut": Map {
"@test/b" => EdgeOut {
"name": "@test/b",
"spec": "1.1.0",
"to": "node_modules/@test/b",
"type": "peerOptional",
},
"@test/c" => EdgeOut {
"name": "@test/c",
"spec": "1.1.0",
"to": null,
"type": "peerOptional",
},
"lodash" => EdgeOut {
"name": "lodash",
"spec": "^4.17.0",
"to": null,
"type": "peerOptional",
},
"uniq" => EdgeOut {
"name": "uniq",
"spec": "^1.0.0",
"to": null,
"type": "peerOptional",
},
},
"location": "node_modules/@test/a",
"name": "@test/a",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep/node_modules/@test/a",
"resolved": "http://localhost:4873/@test/a/-/a-1.1.0.tgz",
"version": "1.1.0",
},
"@test/b" => ArboristNode {
"dev": true,
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "@test/b",
"spec": "1.1.0",
"type": "dev",
},
EdgeIn {
"from": "node_modules/@test/a",
"name": "@test/b",
"spec": "1.1.0",
"type": "peerOptional",
},
},
"edgesOut": Map {
"@test/a" => EdgeOut {
"name": "@test/a",
"spec": "1.1.0",
"to": "node_modules/@test/a",
"type": "peer",
},
},
"location": "node_modules/@test/b",
"name": "@test/b",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep/node_modules/@test/b",
"resolved": "http://localhost:4873/@test/b/-/b-1.1.0.tgz",
"version": "1.1.0",
},
},
"edgesOut": Map {
"@test/a" => EdgeOut {
"name": "@test/a",
"spec": "^1.1.0",
"to": "node_modules/@test/a",
"type": "dev",
},
"@test/b" => EdgeOut {
"name": "@test/b",
"spec": "1.1.0",
"to": "node_modules/@test/b",
"type": "dev",
},
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep",
}
`

exports[`test/arborist/build-ideal-tree.js TAP more peer dep conflicts peerDep replacement of top level dep with different version resulting detached top level dep > force result 1`] = `
ArboristNode {
"children": Map {
"@test/a" => ArboristNode {
"dev": true,
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "@test/a",
"spec": "^1.1.0",
"type": "dev",
},
EdgeIn {
"from": "node_modules/@test/b",
"name": "@test/a",
"spec": "1.1.0",
"type": "peer",
},
},
"edgesOut": Map {
"@test/b" => EdgeOut {
"name": "@test/b",
"spec": "1.1.0",
"to": "node_modules/@test/b",
"type": "peerOptional",
},
"@test/c" => EdgeOut {
"name": "@test/c",
"spec": "1.1.0",
"to": null,
"type": "peerOptional",
},
"lodash" => EdgeOut {
"name": "lodash",
"spec": "^4.17.0",
"to": null,
"type": "peerOptional",
},
"uniq" => EdgeOut {
"name": "uniq",
"spec": "^1.0.0",
"to": null,
"type": "peerOptional",
},
},
"location": "node_modules/@test/a",
"name": "@test/a",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep/node_modules/@test/a",
"resolved": "http://localhost:4873/@test/a/-/a-1.1.0.tgz",
"version": "1.1.0",
},
"@test/b" => ArboristNode {
"dev": true,
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "@test/b",
"spec": "1.1.0",
"type": "dev",
},
EdgeIn {
"from": "node_modules/@test/a",
"name": "@test/b",
"spec": "1.1.0",
"type": "peerOptional",
},
},
"edgesOut": Map {
"@test/a" => EdgeOut {
"name": "@test/a",
"spec": "1.1.0",
"to": "node_modules/@test/a",
"type": "peer",
},
},
"location": "node_modules/@test/b",
"name": "@test/b",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep/node_modules/@test/b",
"resolved": "http://localhost:4873/@test/b/-/b-1.1.0.tgz",
"version": "1.1.0",
},
},
"edgesOut": Map {
"@test/a" => EdgeOut {
"name": "@test/a",
"spec": "^1.1.0",
"to": "node_modules/@test/a",
"type": "dev",
},
"@test/b" => EdgeOut {
"name": "@test/b",
"spec": "1.1.0",
"to": "node_modules/@test/b",
"type": "dev",
},
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep",
}
`

exports[`test/arborist/build-ideal-tree.js TAP more peer dep conflicts peerDep replacement of top level dep with different version resulting detached top level dep > strict result 1`] = `
ArboristNode {
"children": Map {
"@test/a" => ArboristNode {
"dev": true,
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "@test/a",
"spec": "^1.1.0",
"type": "dev",
},
EdgeIn {
"from": "node_modules/@test/b",
"name": "@test/a",
"spec": "1.1.0",
"type": "peer",
},
},
"edgesOut": Map {
"@test/b" => EdgeOut {
"name": "@test/b",
"spec": "1.1.0",
"to": "node_modules/@test/b",
"type": "peerOptional",
},
"@test/c" => EdgeOut {
"name": "@test/c",
"spec": "1.1.0",
"to": null,
"type": "peerOptional",
},
"lodash" => EdgeOut {
"name": "lodash",
"spec": "^4.17.0",
"to": null,
"type": "peerOptional",
},
"uniq" => EdgeOut {
"name": "uniq",
"spec": "^1.0.0",
"to": null,
"type": "peerOptional",
},
},
"location": "node_modules/@test/a",
"name": "@test/a",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep/node_modules/@test/a",
"resolved": "http://localhost:4873/@test/a/-/a-1.1.0.tgz",
"version": "1.1.0",
},
"@test/b" => ArboristNode {
"dev": true,
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "@test/b",
"spec": "1.1.0",
"type": "dev",
},
EdgeIn {
"from": "node_modules/@test/a",
"name": "@test/b",
"spec": "1.1.0",
"type": "peerOptional",
},
},
"edgesOut": Map {
"@test/a" => EdgeOut {
"name": "@test/a",
"spec": "1.1.0",
"to": "node_modules/@test/a",
"type": "peer",
},
},
"location": "node_modules/@test/b",
"name": "@test/b",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep/node_modules/@test/b",
"resolved": "http://localhost:4873/@test/b/-/b-1.1.0.tgz",
"version": "1.1.0",
},
},
"edgesOut": Map {
"@test/a" => EdgeOut {
"name": "@test/a",
"spec": "^1.1.0",
"to": "node_modules/@test/a",
"type": "dev",
},
"@test/b" => EdgeOut {
"name": "@test/b",
"spec": "1.1.0",
"to": "node_modules/@test/b",
"type": "dev",
},
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-more-peer-dep-conflicts-peerDep-replacement-of-top-level-dep-with-different-version-resulting-detached-top-level-dep",
}
`

exports[`test/arborist/build-ideal-tree.js TAP more peer dep conflicts prod dep directly on conflicted peer, full peer set, newer > force result 1`] = `
ArboristNode {
"children": Map {
Expand Down
10 changes: 10 additions & 0 deletions workspaces/arborist/test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,16 @@ t.test('more peer dep conflicts', async t => {
error: false,
resolvable: true,
},
'peerDep replacement of top level dep with different version resulting detached top level dep': {
pkg: {
description: 'a@ -> (PeerOptional(b, c, dep, dep)) b -> ( Peer(a) ) c -> ( Peer(a) )',
devDependencies: {
'@test/a': '^1.1.0',
'@test/b': '1.1.0',
},
},
error: false,
resolvable: true },
})

createRegistry(t, true)
Expand Down
Loading
Loading