Skip to content

Commit

Permalink
improvement: support dep_opts in schema info
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Feb 20, 2025
1 parent 93d8da2 commit c0a7fec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/igniter/util/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Igniter.Util.Info do
|> Igniter.apply_and_fetch_dependencies(
Keyword.put(opts, :operation, "compiling #{names_message}")
)
|> maybe_set_only(install_names, argv, task_name)
|> maybe_set_dep_options(install_names, argv, task_name)
|> compose_install_and_validate!(
argv,
%{
Expand Down Expand Up @@ -146,16 +146,28 @@ defmodule Igniter.Util.Info do
end
end

defp maybe_set_only(igniter, install_names, argv, parent) do
defp maybe_set_dep_options(igniter, install_names, argv, parent) do
Enum.reduce(install_names, igniter, fn install, igniter ->
composing_task = "#{install}.install"

with composing_task when not is_nil(composing_task) <- Mix.Task.get(composing_task),
true <- function_exported?(composing_task, :info, 2),
composing_schema when not is_nil(composing_schema) <-
composing_task.info(argv, parent),
only when not is_nil(only) <- composing_schema.only do
Igniter.Project.Deps.set_dep_option(igniter, install, :only, only)
composing_task.info(argv, parent) do
options =
if composing_schema.only do
Keyword.put(composing_schema.dep_opts, :only, composing_schema.only)
else
composing_schema.dep_opts
end

if options == [] do
igniter
else
Enum.reduce(options, igniter, fn {key, val}, igniter ->
Igniter.Project.Deps.set_dep_option(igniter, install, key, val)
end)
end
else
_ ->
igniter
Expand Down
4 changes: 4 additions & 0 deletions lib/mix/task/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule Igniter.Mix.Task.Info do
* `positional` - A list of positional arguments that this task accepts. A list of atoms, or a keyword list with the option and config.
See the positional arguments section for more.
* `aliases` - A map of aliases to the schema keys.
* `only` - For installers, a list of environments that the dependency should be installed to.
* `dep_opts` - For installers, dependency options that should be set, like `runtime: false`. Use the `only` key for `only` option.
* `composes` - A list of tasks that this task might compose.
* `installs` - A list of dependencies that should be installed before continuing.
* `adds_deps` - A list of dependencies that should be added to the `mix.exs`, but do not need to be installed before continuing.
Expand Down Expand Up @@ -88,6 +90,7 @@ defmodule Igniter.Mix.Task.Info do
group: nil,
composes: [],
only: nil,
dep_opts: [],
installs: [],
adds_deps: [],
positional: [],
Expand All @@ -105,6 +108,7 @@ defmodule Igniter.Mix.Task.Info do
group: atom | nil,
composes: [String.t()],
only: [atom()] | nil,
dep_opts: Keyword.t(),
positional: list(atom | {atom, [{:optional, boolean()}, {:rest, boolean()}]}),
installs: [{atom(), String.t()}],
adds_deps: [{atom(), String.t()}],
Expand Down

0 comments on commit c0a7fec

Please sign in to comment.