Skip to content

Refactor Mix.Gleam#1

Merged
Papipo merged 1 commit intoPapipo:add-gleam-compilerfrom
eksperimental-forks:Papipo/add-gleam-compiler+
Mar 13, 2026
Merged

Refactor Mix.Gleam#1
Papipo merged 1 commit intoPapipo:add-gleam-compilerfrom
eksperimental-forks:Papipo/add-gleam-compiler+

Conversation

@eksperimental
Copy link

@eksperimental eksperimental commented Feb 27, 2026

  • Renamed Mix.Gleam.require!/0 to Mix.Gleam.requirements!/0 as it has a different meaning in Elixir.

  • Added/ @spec annotations to public functions.

  • Avoided making functions raise and return results ({:ok, value} | {:error, message})

  • Now every function that raises ends with a ! (with the exception of Mix.Gleam.load_config/1 due to consistency with the Rebar compiler)

  • Avoided raising from Elixir functions, and raise with Mix.raise/1 almost exclusively, raising with a descriptive message as opposed to raising with a generic message and a stacktrace. The exceptions are the use of JSON.decode!/1 since there's no way to translate the error atoms to string messages, as well as File.cd!/2.

  • Simplify the calls to Mix.raise/1 with the introduction of a helper. Now only 3 times the helper is called to return the value in the {:ok, value} tuple, or to Mix.raise with a message.

  • Mix.Gleam.parse_dep!/2 now users pattern matching to build its specs.

  • Renamed @required_gleam_version to @gleam_version_requirement for clarity.

  • Mix.Gleam.requirements!/0 raises with a descriptive message saying the minimum gleam version isn't met, as opposed to before where if this requirement is not met it wouldn't even raise

- Renamed `Mix.Gleam.require!/0` to `Mix.Gleam.requirements!/0` as it has a
  different meaning in Elixir.

- Added/ `@spec` annotations to public functions.

- Avoided making functions raise and return results (`{:ok, value}` |
  `{:error, message}`)

- Now every function that raises ends with a ! (with the exception of
 `Mix.Gleam.load_config/1` due to consistency with the Rebar compiler)

- Avoided raising from Elixir functions, and raise with `Mix.raise/1` almost
  exclusively, raising with a descriptive message as opposed to raising with a
  generic message and a stacktrace. The exceptions are the use of
  `JSON.decode!/1` since there's no way to translate the error atoms to string
  messages, as well as `File.cd!/2`.

- Simplify the calls to `Mix.raise/1` with the introduction oof a helper.
  Now only 3 times the helper is called to return the value in the
  `{:ok, value}` tuple, or to `Mix.raise` with a message.

- `Mix.Gleam.parse_dep!/2` now users pattern matching to build its specs.

- Renamed `@required_gleam_version` to `@gleam_version_requirement` for clarity.

- `Mix.Gleam.requirements!/0` raises with a descriptive message saying the
  minimum gleam version isn't met, as opposed to before where if this
  requirement is not met it wouldn't even raise
with {:ok, output} <-
gleam(~W(export package-information --out /dev/stdout)),
json <- JSON.decode!(output),
{:ok, gleam_toml} <- Map.fetch(json, "gleam.toml") do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe?

{{:ok, gleam_toml}, :fetch_toml} <- {Map.fetch(json, "gleam.toml"), :fetch_toml} do
        {:error, :fetch_toml} ->
          {:error, "\"gleam.toml\" key not found in \"gleam export package-information\" output"}

|> Enum.map(&parse_dep!/1)

dev_deps =
Map.get(json, "dev-dependencies", %{})
Copy link

@inoas inoas Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker imho:

The gleam.toml format is now consistent. The two sausage-case fields (dev-dependencies and tag-prefix) have been replaced by snake_case versions. Files using the old names will continue to work.

Source: https://github.com/gleam-lang/gleam/blob/v1.15.0-rc1/CHANGELOG.md#build-tool

... AFAIU we must support dev_dependencies and dev-dependencies (and merge both)

{:error,
"The \"gleam\" executable is not available in your PATH. " <>
"Please install it, as one of your dependencies requires it"}
else
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never seen def/catch/else syntax so far, unless I am blind it is also not mentioned here https://hexdocs.pm/elixir/try-catch-and-rescue.html But if it works, nvm.

@spec requirements!() :: :ok
def requirements!() do
case fetch_gleam_version() do
{:ok, gleam_version} ->
Copy link

@inoas inoas Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elixir-lang#14262 (comment)

Do you still think a test is required, after the changes you made?
@eksperimental

@inoas
Copy link

inoas commented Mar 9, 2026

LGTM except #1 (comment) which is not strictly related to this PR but to the original PR and changes in gleam tooling

@Papipo Papipo merged commit 6762814 into Papipo:add-gleam-compiler Mar 13, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants