Skip to content

Commit 962a12e

Browse files
authored
fix(arborist): dependencies from registries with a peerDependency on a workspace (#6193)
* fix(arborist): support dependencies from registries with a peer dependency on a workspace
1 parent 84fbaf2 commit 962a12e

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

workspaces/arborist/lib/arborist/build-ideal-tree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ This is a one-time fix-up, please be patient...
12431243
if (isWorkspace) {
12441244
const existingNode = this.idealTree.edgesOut.get(spec.name).to
12451245
if (existingNode && existingNode.isWorkspace && existingNode.satisfies(edge)) {
1246-
return edge.to
1246+
return existingNode
12471247
}
12481248
}
12491249

workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs

+88
Original file line numberDiff line numberDiff line change
@@ -159849,6 +159849,94 @@ ArboristNode {
159849159849
}
159850159850
`
159851159851

159852+
exports[`test/arborist/build-ideal-tree.js TAP workspaces should allow cyclic peer dependencies between workspaces and packages from a repository > must match snapshot 1`] = `
159853+
ArboristNode {
159854+
"children": Map {
159855+
"foo" => ArboristNode {
159856+
"edgesIn": Set {
159857+
EdgeIn {
159858+
"from": "workspace-a",
159859+
"name": "foo",
159860+
"spec": ">=1.0.0",
159861+
"type": "prod",
159862+
},
159863+
},
159864+
"edgesOut": Map {
159865+
"workspace-a" => EdgeOut {
159866+
"name": "workspace-a",
159867+
"spec": "1.0.0",
159868+
"to": "node_modules/workspace-a",
159869+
"type": "peer",
159870+
},
159871+
},
159872+
"location": "node_modules/foo",
159873+
"name": "foo",
159874+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository/node_modules/foo",
159875+
"version": "1.0.0",
159876+
},
159877+
"workspace-a" => ArboristLink {
159878+
"edgesIn": Set {
159879+
EdgeIn {
159880+
"from": "",
159881+
"name": "workspace-a",
159882+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository/workspace-a",
159883+
"type": "workspace",
159884+
},
159885+
EdgeIn {
159886+
"from": "node_modules/foo",
159887+
"name": "workspace-a",
159888+
"spec": "1.0.0",
159889+
"type": "peer",
159890+
},
159891+
},
159892+
"isWorkspace": true,
159893+
"location": "node_modules/workspace-a",
159894+
"name": "workspace-a",
159895+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository/node_modules/workspace-a",
159896+
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository/workspace-a",
159897+
"resolved": "file:../workspace-a",
159898+
"target": ArboristNode {
159899+
"location": "workspace-a",
159900+
},
159901+
"version": "1.0.0",
159902+
},
159903+
},
159904+
"edgesOut": Map {
159905+
"workspace-a" => EdgeOut {
159906+
"name": "workspace-a",
159907+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository/workspace-a",
159908+
"to": "node_modules/workspace-a",
159909+
"type": "workspace",
159910+
},
159911+
},
159912+
"fsChildren": Set {
159913+
ArboristNode {
159914+
"edgesOut": Map {
159915+
"foo" => EdgeOut {
159916+
"name": "foo",
159917+
"spec": ">=1.0.0",
159918+
"to": "node_modules/foo",
159919+
"type": "prod",
159920+
},
159921+
},
159922+
"isWorkspace": true,
159923+
"location": "workspace-a",
159924+
"name": "workspace-a",
159925+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository/workspace-a",
159926+
"version": "1.0.0",
159927+
},
159928+
},
159929+
"isProjectRoot": true,
159930+
"location": "",
159931+
"name": "tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository",
159932+
"packageName": "root",
159933+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-cyclic-peer-dependencies-between-workspaces-and-packages-from-a-repository",
159934+
"workspaces": Map {
159935+
"workspace-a" => "workspace-a",
159936+
},
159937+
}
159938+
`
159939+
159852159940
exports[`test/arborist/build-ideal-tree.js TAP workspaces should ignore nested node_modules folders > expect resolving Promise 1`] = `
159853159941
ArboristNode {
159854159942
"children": Map {

workspaces/arborist/test/arborist/build-ideal-tree.js

+46
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,52 @@ t.test('workspaces', t => {
877877
t.matchSnapshot(printTree(await tree))
878878
})
879879

880+
t.test('should allow cyclic peer dependencies between workspaces and packages from a repository', async t => {
881+
generateNocks(t, {
882+
foo: {
883+
versions: ['1.0.0'],
884+
peerDependencies: ['workspace-a'],
885+
},
886+
})
887+
const path = t.testdir({
888+
'package.json': JSON.stringify({
889+
name: 'root',
890+
dependencies: {
891+
'workspace-a': '*',
892+
},
893+
workspaces: ['workspace-a'],
894+
}),
895+
'workspace-a': {
896+
'package.json': JSON.stringify({
897+
name: 'workspace-a',
898+
version: '1.0.0',
899+
dependencies: {
900+
foo: '>=1.0.0',
901+
},
902+
}),
903+
},
904+
})
905+
906+
const arb = new Arborist({
907+
...OPT,
908+
path,
909+
workspaces: ['workspace-a'],
910+
})
911+
912+
const tree = arb.buildIdealTree({
913+
path,
914+
add: [
915+
'foo',
916+
],
917+
})
918+
919+
// just assert that the buildIdealTree call resolves, if there's a
920+
// problem here it will reject because of nock disabling requests
921+
await t.resolves(tree)
922+
923+
t.matchSnapshot(printTree(await tree))
924+
})
925+
880926
t.test('workspace nodes are used instead of fetching manifests when they are valid', async t => {
881927
// turn off networking, this should never make a registry request
882928
nock.disableNetConnect()

0 commit comments

Comments
 (0)