Best-effort "is a newer mob.new available?" check, in the spirit of
phx.new's installer-version notice.
mix mob.new calls print_notice/0 once at the end of a run. It fetches the
latest published version from the Hex API and, if the installed archive is
behind, prints a one-line hint to update via mix archive.install hex mob_new.
Constraints this module respects:
- Archive-safe. mob_new ships as a Mix
.ezthat bundles only its own beams, so this code touches OTP/Elixir stdlib only (:httpc,:ssl,Version,Regex) — never a hex dep like Jason. The JSON body is parsed with a narrow regex rather than a JSON library for the same reason. - Never fatal, never slow. Every failure mode (offline, DNS, timeout,
malformed body, unparseable version) collapses to "say nothing." The
network call is capped by a short timeout so a fresh
mix mob.newnever hangs on it.
Summary
Functions
The version of this installed mob_new archive.
Fetches the latest published version string from the Hex API.
The user-facing notice given the current version and a fetch_latest/1
result. Returns the message string when the installed archive is strictly
behind the latest, otherwise nil (up to date, ahead, fetch failed, or
either version is unparseable). Pure — public for testing.
Extracts the latest stable version from a Hex package API JSON body without a
JSON dependency. Prefers latest_stable_version, falls back to
latest_version. Returns {:ok, version} or :error. Pure — public for
testing.
Fetches the latest version and prints an update hint if one is warranted.
Always returns :ok; never raises and never blocks beyond the fetch timeout.
Functions
@spec current_version() :: String.t()
The version of this installed mob_new archive.
@spec fetch_latest(non_neg_integer()) :: {:ok, String.t()} | :error
Fetches the latest published version string from the Hex API.
Returns {:ok, version} or :error (any failure). Best-effort, capped by
timeout ms. Public for testing the orchestration boundary.
The user-facing notice given the current version and a fetch_latest/1
result. Returns the message string when the installed archive is strictly
behind the latest, otherwise nil (up to date, ahead, fetch failed, or
either version is unparseable). Pure — public for testing.
Extracts the latest stable version from a Hex package API JSON body without a
JSON dependency. Prefers latest_stable_version, falls back to
latest_version. Returns {:ok, version} or :error. Pure — public for
testing.
@spec print_notice(non_neg_integer()) :: :ok
Fetches the latest version and prints an update hint if one is warranted.
Always returns :ok; never raises and never blocks beyond the fetch timeout.