sandorbedo
Finding out hex package version numbers
Given a hex package name (for instance gen_stage) and a version requirement string (for instance "~> 1.1"), how can I programmatically find out the latest version of the package available on hex that satisfies the requirement string? (In this case it would be 1.1.2 at the moment.) Is there a Hex function available in mix tasks that does this?
Most Liked
sandorbedo
Just for the record, I came up with this elixir script:
[package_name, version_requirement] = System.argv()
{:ok, requirement} = Version.parse_requirement(version_requirement)
defmodule Version.Comparison do
def unquote(:>=)(a, b) do
Version.compare(a, b) in [:gt, :eq]
end
end
case Hex.API.Package.get(:hexpm, package_name) do
{:ok, {200, response, _headers}} ->
response
|> Map.get("releases")
|> Enum.map(& &1["version"])
|> Enum.filter(&Version.match?(&1, requirement))
|> Enum.sort(&Version.Comparison.>=/2)
|> IO.inspect(label: "Version(s) found")
{:ok, {404, _, _}} ->
IO.puts("Package not found.")
{:error, reason} ->
IO.inspect(reason, label: "Something went wrong")
end
$ mix run hex_versions.exs gen_stage "~> 1.1"
Version(s) found: ["1.1.2", "1.1.1", "1.1.0"]
3
zachallaun
Check out mix hex.outdated – I think it’s what you’re looking for.
1
LostKobrakai
That’s a private module, which may change at any point in time. You can probably use :hex_core’s :hex_api_package.get instead.
1
Popular in Questions
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
I would like to know what is the best IDE for elixir development?
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New







