mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-18 13:51:38 -04:00
fix(dependencies-hierarchy): initialize resultHeight to null
In a debugger, I noticed a test package with no dependencies return a
height of `0` from getTree. By the comment in `DependencyInfo`, this
should instead be `null` since the dependencies array is empty.
It turns out this is the case when `deps == null`. The `getTree`
function early returns with a `null` height:
```ts
if (deps == null) {
return { dependencies: [], isPartiallyVisited: false, height: null }
}
```
However, when `deps` is `{}`, `resultHeight` gets initialized to `0`.
The subsequent `.forEach` loop then iterates over the non-empty object.
This commit is contained in:
committed by
Zoltan Kochan
parent
ec97a31057
commit
35fea5ea74
@@ -80,7 +80,7 @@ function getTreeHelper (
|
||||
const peers = new Set(Object.keys(opts.currentPackages[parentId].peerDependencies ?? {}))
|
||||
|
||||
const resultDependencies: PackageNode[] = []
|
||||
let resultHeight = 0
|
||||
let resultHeight: number | null = null
|
||||
let resultCircular: boolean = false
|
||||
let resultIsPartiallyVisited = false
|
||||
|
||||
@@ -119,7 +119,7 @@ function getTreeHelper (
|
||||
const children = getChildrenTree(keypath.concat([relativeId]), relativeId)
|
||||
dependencies = children.dependencies
|
||||
const heightOfCurrentDepNode = children.height == null ? 0 : children.height + 1
|
||||
resultHeight = Math.max(resultHeight, heightOfCurrentDepNode + 1)
|
||||
resultHeight = Math.max(resultHeight ?? 0, heightOfCurrentDepNode + 1)
|
||||
resultIsPartiallyVisited = resultIsPartiallyVisited || children.isPartiallyVisited
|
||||
|
||||
if (children.circular) {
|
||||
|
||||
Reference in New Issue
Block a user