Skip to content

Commit c76642a

Browse files
committed
fix(arborist): prioritize valid workspace nodes
closes #3637
1 parent a92665c commit c76642a

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,11 @@ This is a one-time fix-up, please be patient...
11801180
return true
11811181
}
11821182

1183+
// If the edge is a workspace, and it's valid, leave it alone
1184+
if (edge.to.isWorkspace) {
1185+
return false
1186+
}
1187+
11831188
// user explicitly asked to update this package by name, problem
11841189
if (this[_updateNames].includes(edge.name)) {
11851190
return true

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159178,6 +159178,106 @@ ArboristNode {
159178159178
}
159179159179
`
159180159180

159181+
exports[`test/arborist/build-ideal-tree.js TAP workspaces should allow adding a workspace as a dep to a workspace > must match snapshot 1`] = `
159182+
ArboristNode {
159183+
"children": Map {
159184+
"workspace-a" => ArboristLink {
159185+
"edgesIn": Set {
159186+
EdgeIn {
159187+
"from": "",
159188+
"name": "workspace-a",
159189+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159190+
"type": "workspace",
159191+
},
159192+
},
159193+
"isWorkspace": true,
159194+
"location": "node_modules/workspace-a",
159195+
"name": "workspace-a",
159196+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/node_modules/workspace-a",
159197+
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159198+
"resolved": "file:../workspace-a",
159199+
"target": ArboristNode {
159200+
"location": "workspace-a",
159201+
},
159202+
"version": "1.0.0",
159203+
},
159204+
"workspace-b" => ArboristLink {
159205+
"edgesIn": Set {
159206+
EdgeIn {
159207+
"from": "",
159208+
"name": "workspace-b",
159209+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159210+
"type": "workspace",
159211+
},
159212+
EdgeIn {
159213+
"from": "workspace-a",
159214+
"name": "workspace-b",
159215+
"spec": "*",
159216+
"type": "prod",
159217+
},
159218+
},
159219+
"isWorkspace": true,
159220+
"location": "node_modules/workspace-b",
159221+
"name": "workspace-b",
159222+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/node_modules/workspace-b",
159223+
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159224+
"resolved": "file:../workspace-b",
159225+
"target": ArboristNode {
159226+
"location": "workspace-b",
159227+
},
159228+
"version": "1.0.0",
159229+
},
159230+
},
159231+
"edgesOut": Map {
159232+
"workspace-a" => EdgeOut {
159233+
"name": "workspace-a",
159234+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159235+
"to": "node_modules/workspace-a",
159236+
"type": "workspace",
159237+
},
159238+
"workspace-b" => EdgeOut {
159239+
"name": "workspace-b",
159240+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159241+
"to": "node_modules/workspace-b",
159242+
"type": "workspace",
159243+
},
159244+
},
159245+
"fsChildren": Set {
159246+
ArboristNode {
159247+
"edgesOut": Map {
159248+
"workspace-b" => EdgeOut {
159249+
"name": "workspace-b",
159250+
"spec": "*",
159251+
"to": "node_modules/workspace-b",
159252+
"type": "prod",
159253+
},
159254+
},
159255+
"isWorkspace": true,
159256+
"location": "workspace-a",
159257+
"name": "workspace-a",
159258+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159259+
"version": "1.0.0",
159260+
},
159261+
ArboristNode {
159262+
"isWorkspace": true,
159263+
"location": "workspace-b",
159264+
"name": "workspace-b",
159265+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159266+
"version": "1.0.0",
159267+
},
159268+
},
159269+
"isProjectRoot": true,
159270+
"location": "",
159271+
"name": "tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace",
159272+
"packageName": "root",
159273+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace",
159274+
"workspaces": Map {
159275+
"workspace-a" => "workspace-a",
159276+
"workspace-b" => "workspace-b",
159277+
},
159278+
}
159279+
`
159280+
159181159281
exports[`test/arborist/build-ideal-tree.js TAP workspaces should ignore nested node_modules folders > expect resolving Promise 1`] = `
159182159282
ArboristNode {
159183159283
"children": Map {

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,50 @@ t.test('workspaces', t => {
833833
)
834834
})
835835

836+
t.test('should allow adding a workspace as a dep to a workspace', async t => {
837+
// turn off networking, this should never make a registry request
838+
nock.disableNetConnect()
839+
t.teardown(() => nock.enableNetConnect())
840+
841+
const path = t.testdir({
842+
'package.json': JSON.stringify({
843+
name: 'root',
844+
workspaces: ['workspace-a', 'workspace-b'],
845+
}),
846+
'workspace-a': {
847+
'package.json': JSON.stringify({
848+
name: 'workspace-a',
849+
version: '1.0.0',
850+
}),
851+
},
852+
'workspace-b': {
853+
'package.json': JSON.stringify({
854+
name: 'workspace-b',
855+
version: '1.0.0',
856+
}),
857+
},
858+
})
859+
860+
const arb = new Arborist({
861+
...OPT,
862+
path,
863+
workspaces: ['workspace-a'],
864+
})
865+
866+
const tree = arb.buildIdealTree({
867+
path,
868+
add: [
869+
'workspace-b',
870+
],
871+
})
872+
873+
// just assert that the buildIdealTree call resolves, if there's a
874+
// problem here it will reject because of nock disabling requests
875+
await t.resolves(tree)
876+
877+
t.matchSnapshot(printTree(await tree))
878+
})
879+
836880
t.end()
837881
})
838882

0 commit comments

Comments
 (0)