From 73f489369f40f5d492b1cae24ce2ec82729fb4a5 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 9 Jul 2024 17:41:24 -0400 Subject: [PATCH] fix: simplify how we get tasks to run fix: don't try to format after editing `mix.exs` --- installer/lib/mix/tasks/igniter.new.ex | 13 +++---- lib/igniter/util/install.ex | 48 ++------------------------ 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/installer/lib/mix/tasks/igniter.new.ex b/installer/lib/mix/tasks/igniter.new.ex index fcabfd2..16867c9 100644 --- a/installer/lib/mix/tasks/igniter.new.ex +++ b/installer/lib/mix/tasks/igniter.new.ex @@ -25,10 +25,8 @@ defmodule Mix.Tasks.Igniter.New do install_with = options[:with] || "new" - unless install_with in ["phx.new", "new"] do - if String.match?(install_with, ~r/\s/) do - raise ArgumentError, "The --with option must not contain any spaces, got: #{install_with}" - end + if String.match?(install_with, ~r/\s/) do + raise ArgumentError, "The --with option must not contain any spaces, got: #{install_with}" end install = @@ -77,9 +75,6 @@ defmodule Mix.Tasks.Igniter.New do |> Code.format_string!() File.write!("mix.exs", new_contents) - - Mix.Task.run("format") - Mix.Task.reenable("format") end unless Enum.empty?(install) do @@ -130,8 +125,8 @@ defmodule Mix.Tasks.Igniter.New do defp dont_consolidate_protocols_in_dev(contents) do String.replace( contents, - "elixir: \"~> 1.17\",\n", - "elixir: \"~> 1.17\",\n consolidate_protocols: Mix.env() != :dev,\n" + "start_permanent: Mix.env() == :prod,\n", + "start_permanent: Mix.env() == :prod,\n consolidate_protocols: Mix.env() != :dev,\n" ) end diff --git a/lib/igniter/util/install.ex b/lib/igniter/util/install.ex index 2d8a0cb..77eea59 100644 --- a/lib/igniter/util/install.ex +++ b/lib/igniter/util/install.ex @@ -51,17 +51,9 @@ defmodule Igniter.Util.Install do igniter = Igniter.apply_and_fetch_dependencies(igniter, options) igniter_tasks = - Mix.Task.load_all() - |> Stream.map(fn item -> - Code.ensure_compiled!(item) - item - end) - |> Stream.filter(&implements_behaviour?(&1, Igniter.Mix.Task)) - |> Enum.filter(&(Mix.Task.task_name(&1) in desired_tasks)) - |> Enum.sort_by( - &Enum.find_index(desired_tasks, fn e -> e == Mix.Task.task_name(&1) end), - &<=/2 - ) + desired_tasks + |> Enum.map(&Mix.Task.get/1) + |> Enum.filter(& &1) title = case desired_tasks do @@ -81,40 +73,6 @@ defmodule Igniter.Util.Install do :ok end - def implements_behaviour?(module, behaviour) do - :attributes - |> module.module_info() - |> Enum.any?(fn - {:behaviour, ^behaviour} -> - true - - # optimizations, probably extremely minor but this is in a tight loop in some places - {:behaviour, [^behaviour | _]} -> - true - - {:behaviour, [_, ^behaviour | _]} -> - true - - {:behaviour, [_, _, ^behaviour | _]} -> - true - - # never seen a module with three behaviours in real life, let alone four. - {:behaviour, behaviours} when is_list(behaviours) -> - module in behaviours - - _ -> - false - end) - rescue - _ -> - false - end - - # defp local_dep?(install) do - # config = Mix.Project.config()[:deps][install] - # Keyword.keyword?(config) && config[:path] - # end - defp determine_dep_type_and_version(requirement) do case String.split(requirement, "@", trim: true, parts: 2) do [package] ->