Gathering detailed insights and metrics for @snyk/dep-graph
Gathering detailed insights and metrics for @snyk/dep-graph
Gathering detailed insights and metrics for @snyk/dep-graph
Gathering detailed insights and metrics for @snyk/dep-graph
snyk-poetry-lockfile-parser
Generate a dep graph given poetry.lock and pyproject.toml files
akanchha-snyk-pnpm-deptree-api-tool
use snyk-nodejs-lockfile-parser to build a deptree and scan/monitor it via the api
cargo-to-dep-graph
A small library that converts Cargo files (a `cargo.toml` and its respective `cargo.lock`) into a [dependency graph](https://www.npmjs.com/package/@snyk/dep-graph)
unity-to-dep-graph
A small library that converts Unity package manager files (a `manifest.json` and its respective `packages-lock.json`) into a [dependency graph](https://www.npmjs.com/package/@snyk/dep-graph)
npm install @snyk/dep-graph
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (98.79%)
JavaScript (1.21%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
45 Stars
230 Commits
12 Forks
102 Watchers
27 Branches
39 Contributors
Updated on Apr 27, 2025
Latest Version
2.9.0
Package Id
@snyk/dep-graph@2.9.0
Unpacked Size
130.51 kB
Size
32.11 kB
File Count
63
NPM Version
6.14.17
Node Version
14.19.3
Published on
Jun 05, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
19
Snyk helps you find, fix and monitor for known vulnerabilities in your dependencies, both on an ad hoc basis and as part of your CI (Build) system.
This library provides a time and space efficient representation of a resolved package dependency graph, which can be used to construct, query and de/serialize dep-graphs.
A directed graph, where a node represents a package instance and an edge from node foo
to node bar
means bar
is a dependency of foo
.
A package (name@version
) can have several different nodes (i.e. instances) in the graph. This flexibility is useful for some ecosystems, for example:
npm
due to conflict-resolutions by duplication. e.g. try to npm i tap@5.7
and then run npm ls
and look for strip-ansi@3.0.1
. You'll see that in some instances it depends on ansi-regex@2.0.0
while in others on ansi-regex@2.1.1
.maven
due to "exclusion" rules. A dependency foo
can be declared in the pom.xml
such that some of it's sub-dependencies are excluded via the <exclusions>
tag. If the same dependency is required elsewhere without (or with different) exclusions then foo
can appear in the tree with different sub-trees.This can also be used to break cycles in the graph, e.g.:
instead of:
A -> B -> C -> A
can have:
A -> B -> C -> A'
DepGraph
A dep-graph instance can be queried using the following interface:
1export interface DepGraph { 2 readonly pkgManager: { 3 name: string; 4 version?: string; 5 repositories?: Array<{ 6 alias: string; 7 }>; 8 }; 9 readonly rootPkg: { 10 name: string; 11 version?: string; 12 purl?: string; 13 }; 14 // all unique packages in the graph (including root package) 15 getPkgs(): Array<{ 16 name: string; 17 version?: string; 18 purl?: string; 19 }>; 20 // all unique packages in the graph, except the root package 21 getDepPkgs(): Array<{ 22 name: string; 23 version?: string; 24 purl?: string; 25 }>; 26 pkgPathsToRoot(pkg: Pkg): Array<Array<{ 27 name: string; 28 version?: string; 29 purl?: string; 30 }>>; 31 directDepsLeadingTo(pkg: Pkg): Array<{ 32 name: string; 33 version?: string; 34 purl?: string; 35 }>; 36 countPathsToRoot(pkg: Pkg): number; 37 toJSON(): DepGraphData; 38 equals(other: DepGraph, options?: { compareRoot?: boolean }): boolean; 39}
DepGraphData
A dep-graph can be serialised into the following format:
1export interface DepGraphData { 2 schemaVersion: string; 3 pkgManager: { 4 name: string; 5 version?: string; 6 repositories?: Array<{ 7 alias: string; 8 }>; 9 }; 10 pkgs: Array<{ 11 id: string; 12 info: { 13 name: string; 14 version?: string; 15 purl?: string; 16 }; 17 }>; 18 graph: { 19 rootNodeId: string; 20 nodes: Array<{ 21 nodeId: string; 22 pkgId: string; 23 info?: { 24 versionProvenance?: { 25 type: string; 26 location: string; 27 property?: { 28 name: string; 29 }; 30 }, 31 labels?: { 32 [key: string]: string | undefined; 33 }; 34 }; 35 deps: Array<{ 36 nodeId: string; 37 }>; 38 }>; 39 }; 40}
createFromJSON
DepGraphData
can be used to construct a DepGraph
instance using createFromJSON
DepGraphBuilder
DepGraphBuilder
is used to create new DepGraph
instances by adding packages and their connections.
1 /** 2 * Instantiates build for given package manager 3 * 4 * @param pkgManager - package manager for which dependcy graph is created 5 * @param rootPkg - root package information 6 * 7 */ 8 public constructor(pkgManager: types.PkgManager, rootPkg?: types.PkgInfo) 9 10 /** 11 * Adds node to the graph. Every node represents logical instance of the package in the dependency graph. 12 * 13 * @param pkgInfo - name and version of the package 14 * @param nodeId - identifier for node in the graph, e.g. `package@version`. 15 * Must uniquely identify this "instance" of the package in the graph, 16 * so may need to be more than `package@version` for many ecosystems. 17 * If in doubt - ask a contributor! 18 * @param nodeInfo - additional node info, e.g. for version provenance 19 * 20 */ 21 public addPkgNode(pkgInfo: types.PkgInfo, nodeId: string, nodeInfo?: types.NodeInfo) 22 23 /** 24 * Makes a connection between parent and its dependency. 25 * 26 * @param parentNodeId - id of the parent node 27 * @param depNodeId - id of the dependency node 28 * 29 */ 30 public connectDep(parentNodeId: string, depNodeId: string) 31 32 /** 33 * Creates an instance of DepGraph 34 * 35 * @return DepGraph instance built from provided packages and their connections 36 * 37 */ 38 public build(): types.DepGraph 39
legacy
moduleA DepTree
is a legacy structure used by the Snyk CLI to represent dependency trees. Conversion functions in the legacy
module ease the gradual migration of code that relies on the legacy format.
DepTree
A DepTree
is a recursive structure that is quite similar to the output of npm list --json
, and (omitting some details) looks like:
1interface DepTree { 2 name: string; 3 version: string; 4 dependencies?: { 5 [depName: string]: DepTree 6 }; 7}
The legacy
conversion functions aim to maintain extra data that might be attached to the dep-tree and is dependant upon in code that wasn't yet updated to use solely dep-graphs:
targetOS
which exists on tree roots for Docker scansversionProvenance
which might exist on the nodes of maven trees, storing information about the source manifest that caused the specfic version to be resolvedNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 13/15 approved changesets -- score normalized to 8
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More