NPM.DepGraph (NPM v0.6.0)

Copy Markdown View Source

Dependency graph operations on the lockfile.

Provides adjacency-list based graph algorithms for analyzing the dependency structure: detecting cycles, computing fan-in/out, and finding orphans.

Summary

Functions

Build an adjacency list from the lockfile.

Detect circular dependencies. Returns list of cycle paths.

Compute fan-in (number of dependents) for each package.

Compute fan-out (number of dependencies) for each package.

Find leaf packages (no dependencies).

Find root packages (not depended on by any other package).

Functions

adjacency_list(lockfile)

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

Build an adjacency list from the lockfile.

Returns %{name => [dep_name, ...]}.

cycles(adj)

@spec cycles(%{required(String.t()) => [String.t()]}) :: [[String.t()]]

Detect circular dependencies. Returns list of cycle paths.

Uses Erlang's :digraph_utils for reliable cycle detection.

fan_in(adj)

@spec fan_in(%{required(String.t()) => [String.t()]}) :: %{
  required(String.t()) => non_neg_integer()
}

Compute fan-in (number of dependents) for each package.

fan_out(adj)

@spec fan_out(%{required(String.t()) => [String.t()]}) :: %{
  required(String.t()) => non_neg_integer()
}

Compute fan-out (number of dependencies) for each package.

leaves(adj)

@spec leaves(%{required(String.t()) => [String.t()]}) :: [String.t()]

Find leaf packages (no dependencies).

roots(adj)

@spec roots(%{required(String.t()) => [String.t()]}) :: [String.t()]

Find root packages (not depended on by any other package).