@snyk/dep-graph
Advanced tools
Comparing version 1.27.0 to 1.27.1
@@ -18,3 +18,2 @@ import * as graphlib from '../graphlib'; | ||
private _countNodePathsToRootCache; | ||
private _pathsToRootCache; | ||
private _hasCycles; | ||
@@ -21,0 +20,0 @@ constructor(_graph: graphlib.Graph, _rootNodeId: NodeId, _pkgs: Record<PkgId, types.PkgInfo>, _pkgNodes: Record<PkgId, Set<NodeId>>, _pkgManager: types.PkgManager); |
@@ -14,3 +14,2 @@ "use strict"; | ||
this._countNodePathsToRootCache = new Map(); | ||
this._pathsToRootCache = new Map(); | ||
this._rootPkgId = _graph.node(_rootNodeId).pkgId; | ||
@@ -223,20 +222,12 @@ this._pkgList = Object.values(_pkgs); | ||
pathsFromNodeToRoot(nodeId, ancestors = []) { | ||
if (this._pathsToRootCache.has(nodeId)) { | ||
return this._pathsToRootCache.get(nodeId); | ||
} | ||
const parentNodesIds = this.getNodeParentsNodeIds(nodeId); | ||
const pkgInfo = this.getNodePkg(nodeId); | ||
if (parentNodesIds.length === 0) { | ||
const result = [[pkgInfo]]; | ||
this._pathsToRootCache.set(nodeId, result); | ||
return result; | ||
return [[pkgInfo]]; | ||
} | ||
const allPaths = []; | ||
ancestors = ancestors.concat(nodeId); | ||
let shouldMemoize = true; | ||
for (const id of parentNodesIds) { | ||
if (ancestors.includes(id)) { | ||
shouldMemoize = false; | ||
if (ancestors.includes(id)) | ||
continue; | ||
} | ||
const pathToRoot = this.pathsFromNodeToRoot(id, ancestors).map((path) => [pkgInfo].concat(path)); | ||
@@ -247,5 +238,2 @@ for (const path of pathToRoot) { | ||
} | ||
if (shouldMemoize) { | ||
this._pathsToRootCache.set(nodeId, allPaths); | ||
} | ||
return allPaths; | ||
@@ -252,0 +240,0 @@ } |
@@ -71,3 +71,3 @@ { | ||
}, | ||
"version": "1.27.0" | ||
"version": "1.27.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
109719
1654