88defmodule Mix.Dep.Loader do
99 @ moduledoc false
1010
11- import Mix.Dep , only: [ ok?: 1 , mix?: 1 , rebar?: 1 , make?: 1 ]
11+ import Mix.Dep , only: [ ok?: 1 , mix?: 1 , rebar?: 1 , make?: 1 , gleam?: 1 ]
1212
1313 @ doc """
1414 Gets all direct children of the current `Mix.Project`
@@ -84,9 +84,9 @@ defmodule Mix.Dep.Loader do
8484 def load ( % Mix.Dep { manager: manager , scm: scm , opts: opts } = dep , children , locked? ) do
8585 # The manager for a child dependency is set based on the following rules:
8686 # 1. Set in dependency definition
87- # 2. From SCM, so that Hex dependencies of a rebar project can be compiled with mix
87+ # 2. From SCM, so that Hex dependencies of a rebar/gleam project can be compiled with mix
8888 # 3. From the parent dependency, used for rebar dependencies from git
89- # 4. Inferred from files in dependency (mix.exs, rebar.config, Makefile)
89+ # 4. Inferred from files in dependency (mix.exs, rebar.config, Makefile, gleam.toml )
9090 manager = opts [ :manager ] || scm_manager ( scm , opts ) || manager || infer_manager ( opts [ :dest ] )
9191 dep = % { dep | manager: manager , status: scm_status ( scm , opts ) }
9292
@@ -106,6 +106,9 @@ defmodule Mix.Dep.Loader do
106106 make? ( dep ) ->
107107 make_dep ( dep )
108108
109+ gleam? ( dep ) ->
110+ gleam_dep ( dep , children , locked? )
111+
109112 true ->
110113 { dep , [ ] }
111114 end
@@ -220,7 +223,7 @@ defmodule Mix.Dep.Loader do
220223
221224 # Note that we ignore Make dependencies because the
222225 # file based heuristic will always figure it out.
223- @ scm_managers ~w( mix rebar3) a
226+ @ scm_managers ~w( mix rebar3 gleam ) a
224227
225228 defp scm_manager ( scm , opts ) do
226229 managers = scm . managers ( opts )
@@ -246,6 +249,9 @@ defmodule Mix.Dep.Loader do
246249 any_of? ( dest , [ "Makefile" , "Makefile.win" ] ) ->
247250 :make
248251
252+ any_of? ( dest , [ "gleam.toml" ] ) ->
253+ :gleam
254+
249255 true ->
250256 nil
251257 end
@@ -361,6 +367,21 @@ defmodule Mix.Dep.Loader do
361367 { dep , [ ] }
362368 end
363369
370+ defp gleam_dep ( % Mix.Dep { opts: opts } = dep , children , locked? ) do
371+ Mix.Gleam . require! ( )
372+
373+ deps =
374+ if children do
375+ Enum . map ( children , & to_dep ( & 1 , opts [ :dest ] , _manager = nil , locked? ) )
376+ else
377+ config = File . cd! ( opts [ :dest ] , fn -> Mix.Gleam . load_config ( "." ) end )
378+ from = Path . join ( opts [ :dest ] , "gleam.toml" )
379+ Enum . map ( config [ :deps ] , & to_dep ( & 1 , from , _manager = nil , locked? ) )
380+ end
381+
382+ { % { dep | opts: Keyword . merge ( opts , app: false , override: true ) } , deps }
383+ end
384+
364385 defp mix_children ( config , locked? , opts ) do
365386 from = Mix.Project . project_file ( )
366387
0 commit comments