Skip to content

Commit c99c215

Browse files
authored
fix(arborist): prioritize valid workspace nodes (#4230)
closes #3637
1 parent cfd59b8 commit c99c215

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
@@ -159209,6 +159209,106 @@ ArboristNode {
159209159209
}
159210159210
`
159211159211

159212+
exports[`test/arborist/build-ideal-tree.js TAP workspaces should allow adding a workspace as a dep to a workspace > must match snapshot 1`] = `
159213+
ArboristNode {
159214+
"children": Map {
159215+
"workspace-a" => ArboristLink {
159216+
"edgesIn": Set {
159217+
EdgeIn {
159218+
"from": "",
159219+
"name": "workspace-a",
159220+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159221+
"type": "workspace",
159222+
},
159223+
},
159224+
"isWorkspace": true,
159225+
"location": "node_modules/workspace-a",
159226+
"name": "workspace-a",
159227+
"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",
159228+
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159229+
"resolved": "file:../workspace-a",
159230+
"target": ArboristNode {
159231+
"location": "workspace-a",
159232+
},
159233+
"version": "1.0.0",
159234+
},
159235+
"workspace-b" => ArboristLink {
159236+
"edgesIn": Set {
159237+
EdgeIn {
159238+
"from": "",
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+
"type": "workspace",
159242+
},
159243+
EdgeIn {
159244+
"from": "workspace-a",
159245+
"name": "workspace-b",
159246+
"spec": "*",
159247+
"type": "prod",
159248+
},
159249+
},
159250+
"isWorkspace": true,
159251+
"location": "node_modules/workspace-b",
159252+
"name": "workspace-b",
159253+
"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",
159254+
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159255+
"resolved": "file:../workspace-b",
159256+
"target": ArboristNode {
159257+
"location": "workspace-b",
159258+
},
159259+
"version": "1.0.0",
159260+
},
159261+
},
159262+
"edgesOut": Map {
159263+
"workspace-a" => EdgeOut {
159264+
"name": "workspace-a",
159265+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159266+
"to": "node_modules/workspace-a",
159267+
"type": "workspace",
159268+
},
159269+
"workspace-b" => EdgeOut {
159270+
"name": "workspace-b",
159271+
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159272+
"to": "node_modules/workspace-b",
159273+
"type": "workspace",
159274+
},
159275+
},
159276+
"fsChildren": Set {
159277+
ArboristNode {
159278+
"edgesOut": Map {
159279+
"workspace-b" => EdgeOut {
159280+
"name": "workspace-b",
159281+
"spec": "*",
159282+
"to": "node_modules/workspace-b",
159283+
"type": "prod",
159284+
},
159285+
},
159286+
"isWorkspace": true,
159287+
"location": "workspace-a",
159288+
"name": "workspace-a",
159289+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
159290+
"version": "1.0.0",
159291+
},
159292+
ArboristNode {
159293+
"isWorkspace": true,
159294+
"location": "workspace-b",
159295+
"name": "workspace-b",
159296+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
159297+
"version": "1.0.0",
159298+
},
159299+
},
159300+
"isProjectRoot": true,
159301+
"location": "",
159302+
"name": "tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace",
159303+
"packageName": "root",
159304+
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace",
159305+
"workspaces": Map {
159306+
"workspace-a" => "workspace-a",
159307+
"workspace-b" => "workspace-b",
159308+
},
159309+
}
159310+
`
159311+
159212159312
exports[`test/arborist/build-ideal-tree.js TAP workspaces should ignore nested node_modules folders > expect resolving Promise 1`] = `
159213159313
ArboristNode {
159214159314
"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)