Skip to content

Commit fabcf43

Browse files
nlfruyadorno
authored andcommitted
fix(arborist): correctly load overrides on workspace edges, closes #4205
1 parent 90c384c commit fabcf43

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

workspaces/arborist/lib/arborist/load-actual.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ module.exports = cls => class ActualLoader extends cls {
212212
const promises = []
213213
for (const path of tree.workspaces.values()) {
214214
if (!this[_cache].has(path)) {
215-
const p = this[_loadFSNode]({ path, root: this[_actualTree] })
215+
// workspace overrides use the root overrides
216+
const p = this[_loadFSNode]({ path, root: this[_actualTree], useRootOverrides: true })
216217
.then(node => this[_loadFSTree](node))
217218
promises.push(p)
218219
}
@@ -240,7 +241,7 @@ module.exports = cls => class ActualLoader extends cls {
240241
this[_actualTree] = root
241242
}
242243

243-
[_loadFSNode] ({ path, parent, real, root, loadOverrides }) {
244+
[_loadFSNode] ({ path, parent, real, root, loadOverrides, useRootOverrides }) {
244245
if (!real) {
245246
return realpath(path, this[_rpcache], this[_stcache])
246247
.then(
@@ -250,6 +251,7 @@ module.exports = cls => class ActualLoader extends cls {
250251
real,
251252
root,
252253
loadOverrides,
254+
useRootOverrides,
253255
}),
254256
// if realpath fails, just provide a dummy error node
255257
error => new Node({
@@ -289,6 +291,9 @@ module.exports = cls => class ActualLoader extends cls {
289291
parent,
290292
root,
291293
loadOverrides,
294+
...(useRootOverrides && root.overrides
295+
? { overrides: root.overrides.getNodeRule({ name: pkg.name, version: pkg.version }) }
296+
: {}),
292297
})
293298
})
294299
.then(node => {

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

+44
Original file line numberDiff line numberDiff line change
@@ -3744,6 +3744,50 @@ t.test('overrides', t => {
37443744
t.equal(bcEdge.to.version, '2.0.0', 'b->c is 2.0.0')
37453745
})
37463746

3747+
t.test('overrides a workspace dependency', async (t) => {
3748+
generateNocks(t, {
3749+
bar: {
3750+
versions: ['1.0.0', '1.0.1', '2.0.0'],
3751+
},
3752+
})
3753+
3754+
const path = t.testdir({
3755+
'package.json': JSON.stringify({
3756+
name: 'root',
3757+
dependencies: {
3758+
foo: '1.0.1',
3759+
},
3760+
overrides: {
3761+
bar: '2.0.0',
3762+
},
3763+
workspaces: [
3764+
'./workspaces/*',
3765+
],
3766+
}),
3767+
workspaces: {
3768+
foo: {
3769+
'package.json': JSON.stringify({
3770+
name: 'foo',
3771+
version: '1.0.1',
3772+
dependencies: {
3773+
bar: '1.0.0',
3774+
},
3775+
}),
3776+
},
3777+
},
3778+
})
3779+
3780+
const tree = await buildIdeal(path)
3781+
3782+
const fooEdge = tree.edgesOut.get('foo')
3783+
t.equal(fooEdge.valid, true)
3784+
3785+
// fooEdge.to is a link, so we need to look at the target for edgesOut
3786+
const fooBarEdge = fooEdge.to.target.edgesOut.get('bar')
3787+
t.equal(fooBarEdge.valid, true)
3788+
t.equal(fooBarEdge.to.version, '2.0.0')
3789+
})
3790+
37473791
t.end()
37483792
})
37493793

workspaces/arborist/test/arborist/load-actual.js

+30
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,33 @@ t.test('load global space with link deps', async t => {
422422
},
423423
})
424424
})
425+
426+
t.test('loading a workspace maintains overrides', async t => {
427+
const path = t.testdir({
428+
'package.json': JSON.stringify({
429+
name: 'root',
430+
version: '1.0.0',
431+
dependencies: {
432+
foo: '1.0.0',
433+
},
434+
overrides: {
435+
bar: '2.0.0',
436+
},
437+
workspaces: ['./foo'],
438+
}),
439+
foo: {
440+
'package.json': JSON.stringify({
441+
name: 'foo',
442+
version: '1.0.0',
443+
dependencies: {
444+
bar: '1.0.0',
445+
},
446+
}),
447+
},
448+
})
449+
450+
const tree = await loadActual(path)
451+
452+
const fooEdge = tree.edgesOut.get('foo')
453+
t.equal(tree.overrides, fooEdge.overrides, 'foo edge got the correct overrides')
454+
})

0 commit comments

Comments
 (0)