Skip to content
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

fix(arborist): prioritize valid workspace nodes #4230

Merged
merged 1 commit into from
Jan 20, 2022
Merged
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
5 changes: 5 additions & 0 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,11 @@ This is a one-time fix-up, please be patient...
return true
}

// If the edge is a workspace, and it's valid, leave it alone
if (edge.to.isWorkspace) {
return false
}

// user explicitly asked to update this package by name, problem
if (this[_updateNames].includes(edge.name)) {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159178,6 +159178,106 @@ ArboristNode {
}
`

exports[`test/arborist/build-ideal-tree.js TAP workspaces should allow adding a workspace as a dep to a workspace > must match snapshot 1`] = `
ArboristNode {
"children": Map {
"workspace-a" => ArboristLink {
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "workspace-a",
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
"type": "workspace",
},
},
"isWorkspace": true,
"location": "node_modules/workspace-a",
"name": "workspace-a",
"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",
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
"resolved": "file:../workspace-a",
"target": ArboristNode {
"location": "workspace-a",
},
"version": "1.0.0",
},
"workspace-b" => ArboristLink {
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "workspace-b",
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
"type": "workspace",
},
EdgeIn {
"from": "workspace-a",
"name": "workspace-b",
"spec": "*",
"type": "prod",
},
},
"isWorkspace": true,
"location": "node_modules/workspace-b",
"name": "workspace-b",
"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",
"realpath": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
"resolved": "file:../workspace-b",
"target": ArboristNode {
"location": "workspace-b",
},
"version": "1.0.0",
},
},
"edgesOut": Map {
"workspace-a" => EdgeOut {
"name": "workspace-a",
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
"to": "node_modules/workspace-a",
"type": "workspace",
},
"workspace-b" => EdgeOut {
"name": "workspace-b",
"spec": "file:{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
"to": "node_modules/workspace-b",
"type": "workspace",
},
},
"fsChildren": Set {
ArboristNode {
"edgesOut": Map {
"workspace-b" => EdgeOut {
"name": "workspace-b",
"spec": "*",
"to": "node_modules/workspace-b",
"type": "prod",
},
},
"isWorkspace": true,
"location": "workspace-a",
"name": "workspace-a",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-a",
"version": "1.0.0",
},
ArboristNode {
"isWorkspace": true,
"location": "workspace-b",
"name": "workspace-b",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace/workspace-b",
"version": "1.0.0",
},
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace",
"packageName": "root",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-workspaces-should-allow-adding-a-workspace-as-a-dep-to-a-workspace",
"workspaces": Map {
"workspace-a" => "workspace-a",
"workspace-b" => "workspace-b",
},
}
`

exports[`test/arborist/build-ideal-tree.js TAP workspaces should ignore nested node_modules folders > expect resolving Promise 1`] = `
ArboristNode {
"children": Map {
Expand Down
44 changes: 44 additions & 0 deletions workspaces/arborist/test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,50 @@ t.test('workspaces', t => {
)
})

t.test('should allow adding a workspace as a dep to a workspace', async t => {
// turn off networking, this should never make a registry request
nock.disableNetConnect()
t.teardown(() => nock.enableNetConnect())

const path = t.testdir({
'package.json': JSON.stringify({
name: 'root',
workspaces: ['workspace-a', 'workspace-b'],
}),
'workspace-a': {
'package.json': JSON.stringify({
name: 'workspace-a',
version: '1.0.0',
}),
},
'workspace-b': {
'package.json': JSON.stringify({
name: 'workspace-b',
version: '1.0.0',
}),
},
})

const arb = new Arborist({
...OPT,
path,
workspaces: ['workspace-a'],
})

const tree = arb.buildIdealTree({
path,
add: [
'workspace-b',
],
})

// just assert that the buildIdealTree call resolves, if there's a
// problem here it will reject because of nock disabling requests
await t.resolves(tree)

t.matchSnapshot(printTree(await tree))
})

t.end()
})

Expand Down