@snyk/dep-graph
Advanced tools
Comparing version 2.7.4 to 2.8.0
@@ -41,3 +41,5 @@ import * as graphlib from '../graphlib'; | ||
}): types.PkgInfo[][]; | ||
countPathsToRoot(pkg: types.Pkg): number; | ||
countPathsToRoot(pkg: types.Pkg, opts?: { | ||
limit?: number; | ||
}): number; | ||
isTransitive(pkg: types.Pkg): boolean; | ||
@@ -44,0 +46,0 @@ equals(other: types.DepGraph, { compareRoot }?: { |
@@ -106,4 +106,5 @@ "use strict"; | ||
} | ||
countPathsToRoot(pkg) { | ||
countPathsToRoot(pkg, opts) { | ||
let count = 0; | ||
const limit = opts === null || opts === void 0 ? void 0 : opts.limit; | ||
for (const nodeId of this.getPkgNodeIds(pkg)) { | ||
@@ -114,6 +115,12 @@ if (this._countNodePathsToRootCache.has(nodeId)) { | ||
else { | ||
const c = this.countNodePathsToRoot(nodeId); | ||
this._countNodePathsToRootCache.set(nodeId, c); | ||
const c = this.countNodePathsToRoot(nodeId, limit); | ||
// don't cache if a limit was supplied | ||
if (!limit) { | ||
this._countNodePathsToRootCache.set(nodeId, c); | ||
} | ||
count += c; | ||
} | ||
if (limit && count >= limit) { | ||
return limit; | ||
} | ||
} | ||
@@ -266,11 +273,13 @@ return count; | ||
} | ||
countNodePathsToRoot(nodeId, visited = []) { | ||
countNodePathsToRoot(nodeId, limit = 0, count = 0, visited = []) { | ||
if (nodeId === this._rootNodeId) { | ||
return 1; | ||
return count + 1; | ||
} | ||
visited = visited.concat(nodeId); | ||
let count = 0; | ||
for (const parentNodeId of this.getNodeParentsNodeIds(nodeId)) { | ||
if (!visited.includes(parentNodeId)) { | ||
count += this.countNodePathsToRoot(parentNodeId, visited); | ||
count = this.countNodePathsToRoot(parentNodeId, limit, count, visited); | ||
if (limit && count >= limit) { | ||
return limit; | ||
} | ||
} | ||
@@ -277,0 +286,0 @@ } |
@@ -68,3 +68,5 @@ export interface Pkg { | ||
directDepsLeadingTo(pkg: Pkg): PkgInfo[]; | ||
countPathsToRoot(pkg: Pkg): number; | ||
countPathsToRoot(pkg: Pkg, opts?: { | ||
limit?: number; | ||
}): number; | ||
equals(other: DepGraph, options?: { | ||
@@ -71,0 +73,0 @@ compareRoot?: boolean; |
@@ -19,3 +19,3 @@ { | ||
"lint": "npm run lint:eslint && npm run lint:prettier", | ||
"test": "jest --verbose --runInBand", | ||
"test": "jest --runInBand", | ||
"test:coverage": "npm run test -- --coverage", | ||
@@ -72,3 +72,3 @@ "prepare": "npm run build" | ||
}, | ||
"version": "2.7.4" | ||
"version": "2.8.0" | ||
} |
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
133647
1983