Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support :warn_if_outdated in deps #1058

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/hex/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ defmodule Hex.Mix do
requirement: dep.requirement,
app: Atom.to_string(dep.app),
from: Path.relative_to_cwd(dep.from),
dependencies: []
dependencies: [],
warn_if_outdated: dep.opts[:warn_if_outdated]
}
]
else
Expand Down
33 changes: 33 additions & 0 deletions lib/hex/remote_converger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,39 @@ defmodule Hex.RemoteConverger do
verify_resolved(resolved, old_lock)
new_lock = Hex.Mix.to_lock(resolved)
Hex.SCM.prefetch(new_lock)

deps_to_warn =
for %{repo: repo, name: name, requirement: requirement, warn_if_outdated: true} <- requests do
{:ok, requirement} = Version.parse_requirement(requirement)
{:ok, versions} = Registry.versions(repo, name)

latest_version =
versions
|> Enum.filter(&Version.match?(&1, requirement))
|> Enum.sort(&(Version.compare(&1, &2) == :gt))
|> List.first()

{:hex, _name, version, _chhecksum, _managers, _, ^repo, _checksum} =
Map.fetch!(new_lock, String.to_atom(name))

if Version.compare(latest_version, version) == :gt do
{name, latest_version}
end
end
|> Enum.filter(& &1)

if deps_to_warn != [] do
IO.warn(
[
"the following deps set `warn_if_outdated: true` and are outdated:\n\n",
Copy link
Member

Choose a reason for hiding this comment

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

We don't use backticks on Elixir but maybe we do on Hex. Please double check. :)

Enum.map_join(deps_to_warn, "\n", fn {name, version} ->
" * #{name} #{version} is available"
end)
],
[]
)
end

lock_merge(lock, new_lock)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hex/scm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ defmodule Hex.SCM do
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
hex_keys = ~w[hex repo organization warn_if_outdated]a

internal_keys = ~w[dest lock build]a

Expand Down
50 changes: 50 additions & 0 deletions test/hex/remote_converger_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
defmodule Hex.RemoteConvergetTest do
use HexTest.IntegrationCase

defmodule OutdatedDepsBefore.MixProject do
def project do
[
app: :outdated_deps,
version: "0.1.0",
deps: [
{:postgrex, "0.2.1", warn_if_outdated: true},
{:ecto, "3.3.1", warn_if_outdated: true},
{:ecto_sql, "3.3.2", warn_if_outdated: true}
]
]
end
end

defmodule OutdatedDepsAfter.MixProject do
def project do
[
app: :outdated_deps,
version: "0.1.0",
deps: [
{:postgrex, ">= 0.0.0", warn_if_outdated: true},
{:ecto, ">= 0.0.0", warn_if_outdated: true},
{:ecto_sql, ">= 0.0.0", warn_if_outdated: true}
]
]
end
end

test "deps with warn_if_outdated: true" do
in_tmp(fn ->
Mix.Project.push(OutdatedDepsBefore.MixProject)
:ok = Mix.Tasks.Deps.Get.run([])

Mix.Project.pop()
Mix.Project.push(OutdatedDepsAfter.MixProject)

output =
ExUnit.CaptureIO.capture_io(:stderr, fn ->
:ok = Mix.Tasks.Deps.Get.run([])
end)

assert output =~ "ecto 3.3.2 is available"
assert output =~ "ecto_sql 3.3.3 is available"
refute output =~ "postgrex"
end)
end
end
Loading