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): correctly load overrides on workspace edges, closes #4205 #4327

Merged
merged 1 commit into from
Jan 26, 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
9 changes: 7 additions & 2 deletions workspaces/arborist/lib/arborist/load-actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ module.exports = cls => class ActualLoader extends cls {
const promises = []
for (const path of tree.workspaces.values()) {
if (!this[_cache].has(path)) {
const p = this[_loadFSNode]({ path, root: this[_actualTree] })
// workspace overrides use the root overrides
const p = this[_loadFSNode]({ path, root: this[_actualTree], useRootOverrides: true })
.then(node => this[_loadFSTree](node))
promises.push(p)
}
Expand Down Expand Up @@ -240,7 +241,7 @@ module.exports = cls => class ActualLoader extends cls {
this[_actualTree] = root
}

[_loadFSNode] ({ path, parent, real, root, loadOverrides }) {
[_loadFSNode] ({ path, parent, real, root, loadOverrides, useRootOverrides }) {
if (!real) {
return realpath(path, this[_rpcache], this[_stcache])
.then(
Expand All @@ -250,6 +251,7 @@ module.exports = cls => class ActualLoader extends cls {
real,
root,
loadOverrides,
useRootOverrides,
}),
// if realpath fails, just provide a dummy error node
error => new Node({
Expand Down Expand Up @@ -289,6 +291,9 @@ module.exports = cls => class ActualLoader extends cls {
parent,
root,
loadOverrides,
...(useRootOverrides && root.overrides
? { overrides: root.overrides.getNodeRule({ name: pkg.name, version: pkg.version }) }
: {}),
})
})
.then(node => {
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 @@ -3724,6 +3724,50 @@ t.test('overrides', t => {
t.equal(bcEdge.to.version, '2.0.0', 'b->c is 2.0.0')
})

t.test('overrides a workspace dependency', async (t) => {
generateNocks(t, {
bar: {
versions: ['1.0.0', '1.0.1', '2.0.0'],
},
})

const path = t.testdir({
'package.json': JSON.stringify({
name: 'root',
dependencies: {
foo: '1.0.1',
},
overrides: {
bar: '2.0.0',
},
workspaces: [
'./workspaces/*',
],
}),
workspaces: {
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.0.1',
dependencies: {
bar: '1.0.0',
},
}),
},
},
})

const tree = await buildIdeal(path)

const fooEdge = tree.edgesOut.get('foo')
t.equal(fooEdge.valid, true)

// fooEdge.to is a link, so we need to look at the target for edgesOut
const fooBarEdge = fooEdge.to.target.edgesOut.get('bar')
t.equal(fooBarEdge.valid, true)
t.equal(fooBarEdge.to.version, '2.0.0')
})

t.end()
})

Expand Down
30 changes: 30 additions & 0 deletions workspaces/arborist/test/arborist/load-actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,33 @@ t.test('load global space with link deps', async t => {
},
})
})

t.test('loading a workspace maintains overrides', async t => {
const path = t.testdir({
'package.json': JSON.stringify({
name: 'root',
version: '1.0.0',
dependencies: {
foo: '1.0.0',
},
overrides: {
bar: '2.0.0',
},
workspaces: ['./foo'],
}),
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.0.0',
dependencies: {
bar: '1.0.0',
},
}),
},
})

const tree = await loadActual(path)

const fooEdge = tree.edgesOut.get('foo')
t.equal(tree.overrides, fooEdge.overrides, 'foo edge got the correct overrides')
})