• Version 2.8.1
  • Published
  • 134 kB
  • 19 dependencies
  • Apache-2.0 license


npm i @snyk/dep-graph
yarn add @snyk/dep-graph
pnpm add @snyk/dep-graph


Snyk dependency graph library



function createChangedPackagesGraph

createChangedPackagesGraph: (
graphA: DepGraph,
graphB: DepGraph
) => Promise<DepGraph>;
  • Creates an induced subgraph of with only packages that are not present in or have a different version.

    Parameter graphA

    Parameter graphB

function createFromJSON

createFromJSON: (depGraphData: DepGraphData) => DepGraph;
  • Create a DepGraph instance from a JSON representation of a dep graph. This is typically used after passing the graph over the wire as DepGraphData.


class DepGraphBuilder

class DepGraphBuilder {}


    constructor(pkgManager: types.PkgManager, rootPkg?: types.PkgInfo);

      property rootNodeId

      readonly rootNodeId: string;

        method addPkgNode

        addPkgNode: (
        pkgInfo: types.PkgInfo,
        nodeId: string,
        nodeInfo?: types.NodeInfo
        ) => this;

          method build

          build: () => types.DepGraph;

            method connectDep

            connectDep: (parentNodeId: string, depNodeId: string) => this;

              method getPkgs

              getPkgs: () => types.PkgInfo[];


                interface DepGraph

                interface DepGraph {}

                  property pkgManager

                  readonly pkgManager: PkgManager;

                    property rootPkg

                    readonly rootPkg: PkgInfo;

                      method countPathsToRoot

                      countPathsToRoot: (pkg: Pkg, opts?: { limit?: number }) => number;

                        method directDepsLeadingTo

                        directDepsLeadingTo: (pkg: Pkg) => PkgInfo[];

                          method equals

                          equals: (other: DepGraph, options?: { compareRoot?: boolean }) => boolean;

                            method getDepPkgs

                            getDepPkgs: () => PkgInfo[];

                              method getPkgNodes

                              getPkgNodes: (pkg: Pkg) => Node[];

                                method getPkgs

                                getPkgs: () => PkgInfo[];

                                  method isTransitive

                                  isTransitive: (pkg: Pkg) => boolean;

                                    method pkgPathsToRoot

                                    pkgPathsToRoot: (pkg: Pkg, opts?: { limit?: number }) => PkgInfo[][];

                                      method toJSON

                                      toJSON: () => DepGraphData;

                                        interface DepGraphData

                                        interface DepGraphData {}

                                          property graph

                                          graph: {
                                          rootNodeId: string;
                                          nodes: GraphNode[];

                                            property pkgManager

                                            pkgManager: PkgManager;

                                              property pkgs

                                              pkgs: Array<{
                                              id: string;
                                              info: PkgInfo;

                                                property schemaVersion

                                                schemaVersion: string;

                                                  interface Pkg

                                                  interface Pkg {}

                                                    property name

                                                    name: string;

                                                      property version

                                                      version?: string;

                                                        interface PkgInfo

                                                        interface PkgInfo {}

                                                          property name

                                                          name: string;

                                                            property purl

                                                            purl?: PurlString;

                                                              property version

                                                              version?: string;

                                                                interface PkgManager

                                                                interface PkgManager {}

                                                                  property name

                                                                  name: string;

                                                                    property repositories

                                                                    repositories?: Array<{
                                                                    alias: string;

                                                                      property version

                                                                      version?: string;

                                                                        interface VersionProvenance

                                                                        interface VersionProvenance {}

                                                                          property location

                                                                          location: string;

                                                                            property property

                                                                            property?: {
                                                                            name: string;

                                                                              property type

                                                                              type: string;


                                                                                namespace Errors

                                                                                module 'dist/core/errors/index.d.ts' {}

                                                                                  class ValidationError

                                                                                  class ValidationError extends CustomError {}


                                                                                    constructor(message: string);

                                                                                      namespace legacy

                                                                                      module 'dist/legacy/index.d.ts' {}

                                                                                      function depTreeToGraph

                                                                                      depTreeToGraph: (
                                                                                      depTree: DepTree,
                                                                                      pkgManagerName: string
                                                                                      ) => Promise<types.DepGraph>;
                                                                                      • Deprecated

                                                                                        Don't use dep trees as an intermediate step, because they are large structures, resulting in high memory usage and high CPU costs from serializing / deserializing. Instead, create a graph directly with DepGraphBuilder

                                                                                      function graphToDepTree

                                                                                      graphToDepTree: (
                                                                                      depGraphInterface: types.DepGraph,
                                                                                      pkgType: string,
                                                                                      opts?: GraphToTreeOptions
                                                                                      ) => Promise<DepTree>;
                                                                                      • Deprecated

                                                                                        Don't use dep trees. You should adapt your code to use graphs, and enhance the dep-graph library if there is missing functionality from the graph structure

                                                                                      interface DepTree

                                                                                      interface DepTree extends DepTreeDep {}

                                                                                      property packageFormatVersion

                                                                                      packageFormatVersion?: string;

                                                                                        property targetOS

                                                                                        targetOS?: {
                                                                                        name: string;
                                                                                        version: string;

                                                                                          property type

                                                                                          type?: string;

                                                                                            interface GraphToTreeOptions

                                                                                            interface GraphToTreeOptions {}

                                                                                              property deduplicateWithinTopLevelDeps

                                                                                              deduplicateWithinTopLevelDeps: boolean;

                                                                                                Package Files (8)

                                                                                                Dependencies (19)

                                                                                                Dev Dependencies (15)

                                                                                                Peer Dependencies (0)

                                                                                                No peer dependencies.


                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@snyk/dep-graph.

                                                                                                • Markdown
                                                                                                • HTML
                                                                                                  <a href="https://www.jsdocs.io/package/@snyk/dep-graph"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>