Minga.Extension.Hex (Minga v0.1.0)

Copy Markdown View Source

Resolves hex-sourced extensions via Mix.install/2.

All hex extensions are installed in a single Mix.install/2 call at startup. This handles dependency resolution, downloading, and compilation. Results are cached by Mix (keyed on the dep list hash), so subsequent boots with the same extensions skip all network and compilation work.

Limitations

Mix.install/2 can only be called once per VM (or again with force: true). On config reload, if the hex dep list changed, we call Mix.install/2 with force: true to reinstall everything.

Summary

Types

A Mix dep tuple ready for Mix.install/2.

Functions

Collects hex deps from the registry as Mix.install-compatible tuples.

Installs all hex-sourced extensions from the registry via Mix.install/2.

Reinstalls all hex extensions with force: true.

Types

mix_dep()

@type mix_dep() :: {atom(), String.t()} | {atom(), String.t(), keyword()}

A Mix dep tuple ready for Mix.install/2.

Functions

collect_hex_deps(registry)

@spec collect_hex_deps(GenServer.server()) :: [mix_dep()]

Collects hex deps from the registry as Mix.install-compatible tuples.

Returns a list like [{:minga_snippets, "~> 0.3"}, {:other_ext, ">= 0.0.0"}]. Extensions without a version constraint default to ">= 0.0.0" (latest).

install_all()

@spec install_all() :: :ok | {:error, String.t()}

Installs all hex-sourced extensions from the registry via Mix.install/2.

Collects every extension with source_type: :hex, builds a dep list, and calls Mix.install/2 once. Returns :ok if successful or if there are no hex extensions. Returns {:error, reason} if Mix.install fails (network error, resolution failure, compile error).

After a successful install, extension modules are on the code path and can be loaded with Code.ensure_loaded?/1.

install_all(registry)

@spec install_all(GenServer.server()) :: :ok | {:error, String.t()}

reinstall_all()

@spec reinstall_all() :: :ok | {:error, String.t()}

Reinstalls all hex extensions with force: true.

Used during config reload when the hex dep list has changed. Forces Mix.install/2 to re-resolve, re-download, and re-compile everything.

reinstall_all(registry)

@spec reinstall_all(GenServer.server()) :: :ok | {:error, String.t()}