HexorcistUpdate.MixEdit (hexorcist_update v0.3.0)

Copy Markdown View Source

Minimal, safe mix.exs constraint editing — the bit mix deps.update can't do.

Like Renovate's mix manager, it only touches a literal {:dep, "~> x.y"} tuple, found by a targeted regex; it never evaluates mix.exs. Anything it can't confidently rewrite (non-~> constraints, dynamic deps, multiple matches) is reported as a suggestion instead of edited.

Summary

Functions

Rewrites dep's constraint in contents to new_constraint. Returns

A new ~> constraint that admits version, e.g. new_constraint("2.3.1"){:ok, "~> 2.3"}. Returns :error if the version can't be parsed.

The umbrella apps_path declared in a root mix.exs (e.g. {:ok, "apps"}), or :none for a plain (non-umbrella) project. Used to discover the child mix.exs files that may declare the dep whose constraint we want to raise.

Functions

bump(contents, dep, new_constraint)

@spec bump(String.t(), String.t(), String.t()) ::
  {:ok, String.t(), String.t()} | {:skip, String.t()} | :not_found | :ambiguous

Rewrites dep's constraint in contents to new_constraint. Returns:

  • {:ok, new_contents, old_constraint} — rewrote a single literal ~> tuple
  • {:skip, old_constraint} — found it, but it isn't a ~> requirement
  • :not_found — no literal {:dep, "…"} tuple
  • :ambiguous — more than one match (won't guess)

new_constraint(version)

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

A new ~> constraint that admits version, e.g. new_constraint("2.3.1"){:ok, "~> 2.3"}. Returns :error if the version can't be parsed.

umbrella_apps_path(root_mixexs)

@spec umbrella_apps_path(String.t()) :: {:ok, String.t()} | :none

The umbrella apps_path declared in a root mix.exs (e.g. {:ok, "apps"}), or :none for a plain (non-umbrella) project. Used to discover the child mix.exs files that may declare the dep whose constraint we want to raise.