diff --git a/lib/hex/scm.ex b/lib/hex/scm.ex index ed9b1f5a..bd4febd3 100644 --- a/lib/hex/scm.ex +++ b/lib/hex/scm.ex @@ -116,6 +116,16 @@ defmodule Hex.SCM do end end + # https://hexdocs.pm/mix/Mix.Tasks.Deps.html#module-dependency-definition-options + mix_keys = ~w[app env compile optional only targets override manager runtime system_env]a + + # https://hex.pm/docs/usage#options + hex_keys = ~w[hex repo organization]a + + internal_keys = ~w[dest lock build]a + + @allowed_keys mix_keys ++ hex_keys ++ internal_keys + def update(opts) do Registry.open() @@ -125,6 +135,15 @@ defmodule Hex.SCM do repo = opts[:repo] || "hexpm" path = cache_path(repo, name, lock.version) + unknown_options = Keyword.keys(opts) -- @allowed_keys + + if unknown_options != [] do + Hex.Shell.warn( + "#{name} is using unknown options: " <> + Enum.map_join(unknown_options, ", ", &inspect/1) + ) + end + case Hex.Parallel.await(:hex_fetcher, {:tarball, repo, name, lock.version}, @fetch_timeout) do {:ok, :cached} -> Hex.Shell.debug(" Using locally cached package (#{path})") diff --git a/test/hex/mix_task_test.exs b/test/hex/mix_task_test.exs index 3d07fc29..96a20328 100644 --- a/test/hex/mix_task_test.exs +++ b/test/hex/mix_task_test.exs @@ -229,6 +229,19 @@ defmodule Hex.MixTaskTest do end end + defmodule WithUnknownOptions do + def project do + [ + app: :with_unknown_options, + version: "0.1.0", + consolidate_protocols: false, + deps: [ + {:ex_doc, dir: "/bad", typo: true} + ] + ] + end + end + defmodule WithNonMatchingRequirement do def project do [ @@ -882,6 +895,22 @@ defmodule Hex.MixTaskTest do end) end + test "deps.get with unknown options" do + Mix.Project.push(WithUnknownOptions) + + in_tmp(fn -> + Hex.State.put(:cache_home, File.cwd!()) + + Mix.Task.run("deps.get") + + assert_received {:mix_shell, :info, + ["\e[33mex_doc is missing its version requirement, use \">= 0.0.0\"" <> _]} + + assert_received {:mix_shell, :info, + ["\e[33mex_doc is using unknown options: :dir, :typo\e[0m"]} + end) + end + defp old_lock_tuple(lock_tuple) do {elem(lock_tuple, 0), elem(lock_tuple, 1), elem(lock_tuple, 2), elem(lock_tuple, 3)} end