PhoenixAssets.Engine (PhoenixAssets v0.1.0)

View Source

Initialises plugins and collects their declarations.

The engine is the single place that turns a PhoenixAssets.Context (which carries the resolved-but-uninitialised plugin list) into initialised plugins, and gathers a given callback across all of them in order. The generators, the graph builder, the dev supervisor, and the doctor all build on these two primitives so plugin initialisation happens exactly once per operation and in the resolved order.

Summary

Types

A plugin after initialisation: {module, opts, state}.

Functions

Calls callback/2 on every initialised plugin and concatenates the results.

Calls callback/2 on every initialised plugin and deep-merges the returned maps.

Initialises every plugin in the context, in resolved order.

Types

initialized()

@type initialized() :: {module(), keyword(), term()}

A plugin after initialisation: {module, opts, state}.

Functions

collect(ctx, initialized, callback)

@spec collect(PhoenixAssets.Context.t(), [initialized()], atom()) :: [term()]

Calls callback/2 on every initialised plugin and concatenates the results.

callback is one of the list-returning PhoenixAssets.Plugin callbacks (:generated_files, :dev_processes, :graph_entries, :doctor_checks). Each plugin receives (ctx, state).

collect_map(ctx, initialized, callback)

@spec collect_map(PhoenixAssets.Context.t(), [initialized()], atom()) :: map()

Calls callback/2 on every initialised plugin and deep-merges the returned maps.

Plugins are visited in resolved order and a later plugin wins on key conflicts, so overrides follow the same deterministic ordering as every other collection. Used for the map-returning :vite_config callback.

init_plugins(ctx)

@spec init_plugins(PhoenixAssets.Context.t()) ::
  {:ok, [initialized()]} | {:error, {module(), term()}}

Initialises every plugin in the context, in resolved order.

Returns {:ok, initialized} or {:error, {plugin_module, reason}} on the first plugin whose PhoenixAssets.Plugin.init/2 fails.