@snyk/dep-graph
Advanced tools
Comparing version 2.6.0 to 2.6.1
@@ -109,3 +109,10 @@ "use strict"; | ||
for (const nodeId of this.getPkgNodeIds(pkg)) { | ||
count += this.countNodePathsToRoot(nodeId); | ||
if (this._countNodePathsToRootCache.has(nodeId)) { | ||
count += this._countNodePathsToRootCache.get(nodeId); | ||
} | ||
else { | ||
const c = this.countNodePathsToRoot(nodeId); | ||
this._countNodePathsToRootCache.set(nodeId, c); | ||
count += c; | ||
} | ||
} | ||
@@ -258,19 +265,13 @@ return count; | ||
} | ||
countNodePathsToRoot(nodeId, ancestors = []) { | ||
if (ancestors.includes(nodeId)) { | ||
return 0; | ||
countNodePathsToRoot(nodeId, visited = []) { | ||
if (nodeId === this._rootNodeId) { | ||
return 1; | ||
} | ||
if (this._countNodePathsToRootCache.has(nodeId)) { | ||
return this._countNodePathsToRootCache.get(nodeId) || 0; | ||
visited = visited.concat(nodeId); | ||
let count = 0; | ||
for (const parentNodeId of this.getNodeParentsNodeIds(nodeId)) { | ||
if (!visited.includes(parentNodeId)) { | ||
count += this.countNodePathsToRoot(parentNodeId, visited); | ||
} | ||
} | ||
const parentNodesIds = this.getNodeParentsNodeIds(nodeId); | ||
if (parentNodesIds.length === 0) { | ||
this._countNodePathsToRootCache.set(nodeId, 1); | ||
return 1; | ||
} | ||
ancestors = ancestors.concat(nodeId); | ||
const count = parentNodesIds.reduce((acc, parentNodeId) => { | ||
return acc + this.countNodePathsToRoot(parentNodeId, ancestors); | ||
}, 0); | ||
this._countNodePathsToRootCache.set(nodeId, count); | ||
return count; | ||
@@ -277,0 +278,0 @@ } |
@@ -71,3 +71,3 @@ { | ||
}, | ||
"version": "2.6.0" | ||
"version": "2.6.1" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1908
127571