# `NPM.Dependency.Tree`
[🔗](https://github.com/elixir-volt/npm_ex/blob/v0.7.3/lib/npm/dependency/tree.ex#L1)

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.

# `tree_node`

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

# `build`

```elixir
@spec build(%{required(String.t()) =&gt; NPM.Lockfile.entry()}, %{
  required(String.t()) =&gt; 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`

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

Count total unique packages in the tree.

# `depth`

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

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

# `flatten`

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

Flatten the tree into a list of all package names.

# `paths_to`

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

Find all paths from root to a target package.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
