# `Denox.Deps`
[🔗](https://github.com/gsmlg-dev/denox/blob/v0.9.0/lib/denox/deps.ex#L1)

Dependency management for Denox using the `deno` CLI at build-time.

Manages npm/jsr packages declared in `deno.json` via `deno install`.
In Deno 2.x, vendoring is handled by setting `"vendor": true` in
deno.json and running `deno install`, which creates `node_modules/`
for npm packages in the same directory as deno.json.

The `deno` CLI is only required at build-time, not at runtime.

## Workflow

    # 1. Declare deps in deno.json
    # 2. Install deps
    Denox.Deps.install()

    # 3. Create a runtime with installed deps
    {:ok, rt} = Denox.Deps.runtime()

    # 4. Use bare specifier imports
    Denox.eval_async(rt, ~s[
      import { z } from "zod";
      export default z.string().parse("hello");
    ]) |> Task.await()

# `add`

```elixir
@spec add(String.t(), String.t(), keyword()) :: :ok | {:error, String.t()}
```

Add a dependency to deno.json and reinstall.

## Examples

    Denox.Deps.add("zod", "npm:zod@^3.22")
    Denox.Deps.add("@std/path", "jsr:@std/path@^1.0")

# `check`

```elixir
@spec check(keyword()) :: :ok | {:error, String.t()}
```

Check if dependencies have been installed.

Looks for `node_modules/` in the config directory as evidence
that `deno install` has been run.

Options:
  - `:config` - path to deno.json (default: "deno.json")
  - `:vendor_dir` - legacy option, checks if this directory exists

Returns `:ok` or `{:error, message}`.

# `install`

```elixir
@spec install(keyword()) :: :ok | {:error, String.t()}
```

Install all dependencies declared in `deno.json`.

Sets `"vendor": true` in the config and runs `deno install`,
which creates `node_modules/` for npm packages in the config directory.

Options:
  - `:config` - path to deno.json (default: "deno.json")

Returns `:ok` or `{:error, message}`.

# `list`

```elixir
@spec list(keyword()) ::
  {:ok, %{required(String.t()) =&gt; String.t()}} | {:error, String.t()}
```

List dependencies declared in deno.json.

Returns `{:ok, %{name => specifier}}` or `{:error, message}`.

# `remove`

```elixir
@spec remove(
  String.t(),
  keyword()
) :: :ok | {:error, String.t()}
```

Remove a dependency from deno.json and reinstall.

# `runtime`

```elixir
@spec runtime(keyword()) :: {:ok, Denox.runtime()} | {:error, String.t()}
```

Create a runtime configured to load from the installed deps directory.

Options:
  - `:config` - path to deno.json (default: "deno.json")
  - `:cache_dir` - cache directory for remote fetches (default: "_denox/cache")
  - `:import_map` - map of bare specifiers to resolved URLs/paths
  - Additional options passed to `Denox.runtime/1`

Returns `{:ok, runtime}` or `{:error, message}`.

---

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