Skip to content

Commit

Permalink
feat(arborist): add overridden getter to Node class
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf authored and fritzy committed Aug 17, 2022
1 parent 9dc6983 commit e6d4304
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions workspaces/arborist/lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ class Node {
return `${myname}@${alias}${version}`
}

get overridden () {
return !!(this.overrides && this.overrides.value && this.overrides.name === this.name)
}

get package () {
return this[_package]
}
Expand Down
46 changes: 46 additions & 0 deletions workspaces/arborist/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,52 @@ t.test('overrides', (t) => {
t.end()
})

t.test('node.overridden is true when an override applies to a specific node', async (t) => {
const tree = new Node({
loadOverrides: true,
path: '/some/path',
pkg: {
name: 'foo',
dependencies: {
bar: '^1',
},
overrides: {
baz: '1.0.0',
},
},
children: [{
name: 'bar',
version: '1.0.0',
pkg: {
dependencies: {
baz: '2.0.0',
},
},
children: [{
name: 'baz',
version: '1.0.0',
pkg: {
dependencies: {
buzz: '1.0.0',
},
},
children: [{
name: 'buzz',
version: '1.0.0',
pkg: {},
}],
}],
}],
})

const bar = tree.edgesOut.get('bar').to
t.not(bar.overridden, 'bar was not overridden')
const baz = bar.edgesOut.get('baz').to
t.ok(baz.overridden, 'baz was overridden')
const buzz = baz.edgesOut.get('buzz').to
t.not(buzz.overridden, 'buzz was not overridden')
})

t.test('assertRootOverrides throws when a dependency and override conflict', async (t) => {
const conflictingTree = new Node({
loadOverrides: true,
Expand Down

0 comments on commit e6d4304

Please sign in to comment.