# `Volt.Priv`
[🔗](https://github.com/elixir-volt/volt/blob/v0.21.0/lib/volt/priv.ex#L1)

Accesses browser support JavaScript and other runtime files from an OTP application's `priv` directory.

`priv` is the OTP convention for application-specific runtime files. Volt uses this
module for its own bundled browser support code, and plugin authors can use it to
keep JavaScript and TypeScript in their application instead of embedding source in
Elixir strings.

The source may be either an OTP application atom or an `{app, root}` tuple. The
tuple form keeps repeated calls concise when several files live under the same
`priv` subdirectory:

    assets = {:my_app, "islands"}

    Volt.Priv.path(assets, "runtime.ts")
    Volt.Priv.read!(assets, "runtime.ts")
    Volt.Priv.render!(assets, "entry.ts", [], splices: [body: "start();"])
    Volt.Priv.js!(assets, "runtime.ts")
    Volt.Priv.js!(assets, "entry.ts", id: "counter", props: %{count: 1})

`render!/4` binds and splices templates while preserving TypeScript for a later
Volt build. `js!/3` and `js!/4` additionally compile the rendered source to browser
JavaScript. This keeps templates valid TypeScript or JavaScript files instead of
requiring EEx or textual source replacement.

`bundle!/3` bundles an entry with everything it imports into one module. npm
packages it imports are vendored beside the sources with `mix volt.priv.vendor`
(see `Volt.Priv.Vendor`), so they ship in the package and no install happens at
runtime:

    Volt.Priv.bundle!(assets, "widget.ts", format: :esm)

# `bindings`

```elixir
@type bindings() :: keyword() | map()
```

# `source`

```elixir
@type source() :: atom() | {atom(), String.t()}
```

# `bundle`

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

Bundles an entry under `priv` with the modules it imports, including npm packages
vendored beside it with `mix volt.priv.vendor`.

Options are passed to `OXC.bundle/2`, such as `:format` and `:define`.

# `bundle!`

```elixir
@spec bundle!(source(), String.t(), keyword()) :: String.t()
```

Like `bundle/3`, but raises when the entry cannot be bundled.

# `js!`

```elixir
@spec js!(source(), String.t(), bindings(), keyword()) :: String.t()
```

Emits browser JavaScript for a support file stored under `priv`.

TypeScript and JavaScript files are both accepted. When bindings are provided, the
source is parsed and `$placeholder` literals are replaced with JSON-compatible
JavaScript literals using `OXC.bind/2` before the result is emitted.

Options:

  * `:splices` - a keyword list of `$placeholder` names to statement,
    property, or array-element replacements accepted by `OXC.splice/3`.
  * `:rewrite_specifiers` - a map or keyword list of import specifiers to rewrite
    after code generation.

# `path`

```elixir
@spec path(source(), String.t()) :: String.t()
```

Returns the absolute path to a file under an OTP application's `priv` directory.

# `read!`

```elixir
@spec read!(source(), String.t()) :: String.t()
```

Reads a file from an OTP application's `priv` directory.

# `render!`

```elixir
@spec render!(source(), String.t(), bindings(), keyword()) :: String.t()
```

Renders a JavaScript or TypeScript template stored under `priv`.

Literal bindings use `OXC.bind/2`, while the `:splices` option accepts statement,
property, and array-element replacements handled by `OXC.splice/3`. The rendered
source is not compiled, making this API suitable for virtual modules and generated
entries that will subsequently pass through `Volt.Builder`.

---

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