PhoenixAssets.Context (PhoenixAssets v0.1.0)

View Source

The read-only snapshot threaded through every plugin callback.

A context is built once per operation (generation, dev startup, doctor run, graph build) from a PhoenixAssets.Config plus the resolved plugin list and the runtime environment. Plugins receive it and must not mutate it -- they contribute declarations (generated_files/2, dev_processes/2, graph_entries/2, ...) computed from it.

The most-used config fields are hoisted onto the context for ergonomics; the full PhoenixAssets.Config remains available as :config for less-common knobs.

Summary

Functions

Joins rel onto the asset root, returning a path relative to the project root.

The absolute path of a frontend tool's executable under the asset root.

Joins rel onto the generated-contracts directory (under the asset root).

The Vite manifest path: the :vite_manifest build override, or the default under static_root.

Types

env()

@type env() :: :dev | :test | :prod

resolved_plugin()

@type resolved_plugin() :: {module(), keyword()} | {module(), keyword(), term()}

t()

@type t() :: %PhoenixAssets.Context{
  asset_root: String.t(),
  config: PhoenixAssets.Config.t(),
  endpoint: module() | nil,
  env: env(),
  generated_dir: String.t(),
  js_runtime: :node | :bun,
  otp_app: atom(),
  package_manager: :pnpm | :npm | :bun,
  plugins: [resolved_plugin()],
  router: module() | nil,
  ssr_runtime: :node | :bun,
  static_assets_path: String.t(),
  static_root: String.t()
}

Functions

asset_path(context, rel)

@spec asset_path(t(), Path.t()) :: Path.t()

Joins rel onto the asset root, returning a path relative to the project root.

bin_path(context, tool)

@spec bin_path(t(), String.t()) :: Path.t()

The absolute path of a frontend tool's executable under the asset root.

Dev processes exec node_modules/.bin/<tool> directly rather than through a package-manager wrapper: under MuonTrap the wrapper process exits and orphans the node child, which keeps holding the dev-server port and breaks teardown. The doctor's binary checks use the same resolution, so what it validates is exactly what the supervisor execs.

generated_path(context, rel \\ "")

@spec generated_path(t(), Path.t()) :: Path.t()

Joins rel onto the generated-contracts directory (under the asset root).

manifest_path(context)

@spec manifest_path(t()) :: Path.t()

The Vite manifest path: the :vite_manifest build override, or the default under static_root.

new(config, opts \\ [])

@spec new(
  PhoenixAssets.Config.t(),
  keyword()
) :: t()

Builds a context from a PhoenixAssets.Config.

Options:

  • :env -- the runtime environment (:dev | :test | :prod), default :prod.

  • :plugins -- the resolved, ordered plugin list, default [].