Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonNavon committed Nov 4, 2024
1 parent 35ce2f7 commit 5630954
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions workspaces/arborist/lib/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,17 @@ class Edge {
get spec () {
if (this.overrides?.value && this.overrides.value !== '*' && this.overrides.name === this.#name) {
// If this edge has the same overrides field as the source, then we're not applying an override for this edge.
if (this.overrides === this.#from.overrides) {
if (this.overrides === this.#from?.overrides) {
return this.#spec
}

if (this.overrides.value.startsWith('$')) {
const ref = this.overrides.value.slice(1)
// we may be a virtual root, if we are we want to resolve reference overrides
// from the real root, not the virtual one
const pkg = this.#from.sourceReference
? this.#from.sourceReference.root.package
: this.#from.root.package
const pkg = this.#from?.sourceReference
? this.#from?.sourceReference.root.package
: this.#from?.root?.package
if (pkg.devDependencies?.[ref]) {
return pkg.devDependencies[ref]
}
Expand Down Expand Up @@ -264,6 +264,7 @@ class Edge {
this.#error = 'MISSING'
}
} else if (this.peer && this.#from === this.#to.parent && !this.#from.isTop) {
} else if (this.peer && this.#from === this.#to.parent && !this.#from?.isTop) {
this.#error = 'PEER LOCAL'
} else if (!this.satisfiedBy(this.#to)) {
this.#error = 'INVALID'
Expand All @@ -289,6 +290,7 @@ class Edge {
let newOverrideSet
let oldOverrideSet
if (this.#from.overrides) {
if (this.#from?.overrides) {
newOverrideSet = this.#from.overrides.getEdgeRule(this)
if (newOverrideSet && !newOverrideSet.isEqual(this.overrides)) {
// If there's a new different override set we need to propagate it to the nodes.
Expand All @@ -301,6 +303,7 @@ class Edge {
delete this.overrides
}
const newTo = this.#from.resolve(this.#name)
const newTo = this.#from?.resolve(this.#name)
if (newTo !== this.#to) {
if (this.#to) {
this.#to.deleteEdgeIn(this)
Expand All @@ -326,6 +329,7 @@ class Edge {
this.#to.deleteEdgeIn(this)
}
this.#from.edgesOut.delete(this.#name)
this.#from?.edgesOut.delete(this.#name)
this.#to = null
this.#error = 'DETACHED'
this.#from = null
Expand Down
4 changes: 2 additions & 2 deletions workspaces/arborist/lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1378,15 +1378,15 @@ class Node {

recalculateOutEdgesOverrides () {
// For each edge out propogate the new overrides through.
for (const [, edge] of this.edgesOut) {
for (const edge of this.edgesOut.values()) {
edge.reload(true)
if (edge.to) {
edge.to.updateOverridesEdgeInAdded(edge.overrides)
}
}
}

findSpecificOverrideSet (first, second) {
static findSpecificOverrideSet (first, second) {
for (let overrideSet = second; overrideSet; overrideSet = overrideSet.parent) {
if (overrideSet.isEqual(first)) {
return second
Expand Down

0 comments on commit 5630954

Please sign in to comment.