Skip to content

Refactor Mix.Gleam#1

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

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

Conversation

@eksperimental

@eksperimental eksperimental commented Feb 27, 2026

Copy link
Copy Markdown
  • 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
Comment thread lib/mix/lib/mix/gleam.ex
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
Copy Markdown

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"}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Initially i did that, but the only function that returns :error is Map.fetch/2 so I decided to simplify it.

Comment thread lib/mix/lib/mix/gleam.ex
Comment thread lib/mix/lib/mix/gleam.ex
|> Enum.map(&parse_dep!/1)

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

@inoas inoas Mar 9, 2026

Copy link
Copy Markdown

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)

Comment thread lib/mix/lib/mix/gleam.ex
{:error,
"The \"gleam\" executable is not available in your PATH. " <>
"Please install it, as one of your dependencies requires it"}
else

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Neither have I but seems to work. Maybe it its worth documenting this

Comment thread lib/mix/lib/mix/gleam.ex
@spec requirements!() :: :ok
def requirements!() do
case fetch_gleam_version() do
{:ok, gleam_version} ->

@inoas inoas Mar 9, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well, in theory it should work, but so i theory it should have worked before the fix. Personally, since it's crucial I would test it.

@inoas

inoas commented Mar 9, 2026

Copy link
Copy Markdown

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
@inoas

inoas commented Jun 14, 2026

Copy link
Copy Markdown

@eksperimental do you still have concerns/feedback on elixir-lang#14262? Specifically the PR is still marked as non-mergable/red to me because of:

eksperimental Requested changes with read-only permissions

Is the PR now fine for you (and could you remove the change request) or do you still see that there is something to do?

@eksperimental

Copy link
Copy Markdown
Author

Is the PR now fine for you (and could you remove the change request) or do you still see that there is something to do?

Hi. There's no further requests on my side. I also don't see how to remove that. Maybe one of the change requests is still pending, something which I doubt

@inoas

inoas commented Jun 15, 2026

Copy link
Copy Markdown

Maybe https://github.com/elixir-lang/elixir/pull/14262/changes .. then Submit review then Approve ... there are probably other ways to not approve but also remove the request change, which is still there (I checked right now)

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