NPM.DepTree (NPM v0.6.0)

Copy Markdown View Source

Build and query a dependency tree from the lockfile.

Provides a structured view of the dependency graph, useful for mix npm.tree, mix npm.why, and deduplication.

Summary

Functions

Build a dependency tree from the lockfile.

Count total unique packages in the tree.

Get the depth of a package in the tree (0 = root dep).

Flatten the tree into a list of all package names.

Find all paths from root to a target package.

Types

tree_node()

@type tree_node() :: %{name: String.t(), version: String.t(), children: [tree_node()]}

Functions

build(lockfile, root_deps)

@spec build(%{required(String.t()) => NPM.Lockfile.entry()}, %{
  required(String.t()) => String.t()
}) :: [
  tree_node()
]

Build a dependency tree from the lockfile.

Returns a list of root-level nodes, each with their transitive dependencies as children.

count(nodes)

@spec count([tree_node()]) :: non_neg_integer()

Count total unique packages in the tree.

depth(nodes, target)

@spec depth([tree_node()], String.t()) :: non_neg_integer() | nil

Get the depth of a package in the tree (0 = root dep).

flatten(nodes)

@spec flatten([tree_node()]) :: [String.t()]

Flatten the tree into a list of all package names.

paths_to(nodes, target)

@spec paths_to([tree_node()], String.t()) :: [[String.t()]]

Find all paths from root to a target package.