NPM.Why (NPM v0.6.0)

Copy Markdown View Source

Explains why a package is installed by tracing through the dependency tree.

Implements the npm why / npm explain functionality.

Summary

Functions

Finds all packages that directly depend on the target.

Checks if a package is a direct dependency.

Explains why a package is in the lockfile.

Returns a human-readable explanation string.

Types

reason()

@type reason() :: %{path: [String.t()], range: String.t() | nil, direct: boolean()}

Functions

dependents(target, lockfile)

@spec dependents(String.t(), map()) :: [String.t()]

Finds all packages that directly depend on the target.

direct?(name, root_deps)

@spec direct?(String.t(), map()) :: boolean()

Checks if a package is a direct dependency.

explain(target, lockfile, root_deps)

@spec explain(String.t(), map(), map()) :: [reason()]

Explains why a package is in the lockfile.

Returns a list of dependency paths that lead to the given package. Each path is a list of package names from root to the target.

format_reasons(reasons)

@spec format_reasons([reason()]) :: String.t()

Returns a human-readable explanation string.