Skip to content

Add download stats and release dates to mix hex.info#1130

Merged
ericmj merged 6 commits into
hexpm:mainfrom
s3cur3:add-downloads-and-dates-to-hex-info
Apr 13, 2026
Merged

Add download stats and release dates to mix hex.info#1130
ericmj merged 6 commits into
hexpm:mainfrom
s3cur3:add-downloads-and-dates-to-hex-info

Conversation

@s3cur3
Copy link
Copy Markdown
Contributor

@s3cur3 s3cur3 commented Mar 30, 2026

This adds download counts and release dates (provided by hex.pm/api/packages/[package_name]) to the mix hex.info [package_name] and mix hex.info [package_name] [version] commands.

Download counts for the overall package info include yesterday, last 7 days, and all-time.

Two decisions I'm not entirely sure of, but happy to revisit:

  • Showing the download numbers for the current version (like the Hex.pm website does) would require a second HTTP request, which seemed iffy.
  • I wasn't clear on what the "recent" key in the downloads meant (it looks like it might be the last 8 releases?), so I left that out of the download output since I was unable to give a more concrete label for it.

(The formatting on the before/after table below is a little weird... GitHub seems to be adding additional spaces between "paragraphs.")

Resolves #1128

BeforeAfter

$ mix hex.info jason
A blazing fast JSON parser and generator in pure Elixir.

Config: {:jason, "~> 1.4"}
Locked version: 1.4.4
Releases: 1.5.0-alpha.2, 1.5.0-alpha.1, 1.4.4, 1.4.3, 1.4.2, 1.4.1, 1.4.0, 1.3.0, ...

Licenses: Apache-2.0
Links:
  GitHub: https://github.com/michalmuskala/jason


$ mix hex.info jason
A blazing fast JSON parser and generator in pure Elixir.

Config: {:jason, "~> 1.4"}
Recent releases:
  1.5.0-alpha.2 (2023-07-07)
  1.5.0-alpha.1 (2022-10-16)
  1.4.4 (2024-07-26)
  1.4.3 (2024-06-29)
  1.4.2 (2024-06-29)
  1.4.1 (2023-07-07)
  1.4.0 (2022-09-12)
  1.3.0 (2021-12-21)
  ...

Downloads:
  Yesterday: 66 791
  Last 7 days: 332 386
  All time: 197 507 648

Licenses: Apache-2.0
Links:
  GitHub: https://github.com/michalmuskala/jason


$ mix hex.info jason 1.5.0-alpha.2
Config: {:jason, "~> 1.5.0-alpha.2"}
Documentation at: https://hexdocs.pm/jason/1.5.0-alpha.2
Dependencies:
  decimal ~> 1.0 or ~> 2.0 (optional)
  jason_native >= 0.0.0 (optional)
Published by: michalmuskala (michal@muskala.eu)

$ mix hex.info jason 1.5.0-alpha.2
Config: {:jason, "~> 1.5.0-alpha.2"}
Released: 2023-07-07
Documentation at: https://hexdocs.pm/jason/1.5.0-alpha.2
Downloads: 26 130
Dependencies:
  decimal ~> 1.0 or ~> 2.0 (optional)
  jason_native >= 0.0.0 (optional)
Published by: michalmuskala (michal@muskala.eu)

This adds download counts and release dates (provided by `hex.pm/api/packages/[package_name]`) to the `mix hex.info [package_name]` and `mix hex.info [package_name] [version]` commands.

Download counts for the overall package info include yesterday, last 7 days, and all-time. Showing the download numbers for the current version (like the Hex.pm website does) would require a second HTTP request, which seemed iffy. I also wasn't clear on what the "recent" key in the downloads meant (it looks like it might be the last 8 releases), so I left that out of the download output.

Resolves hexpm#1128
@ericmj
Copy link
Copy Markdown
Member

ericmj commented Apr 8, 2026

This is a great improvement!

What do you think about something like this to format it nicer:

$ mix hex.info jason
A blazing fast JSON parser and generator in pure Elixir.
Config: {:jason, "~> 1.4"}
Recent releases:
  1.5.0-alpha.2 (2023-07-07)
  1.5.0-alpha.1 (2022-10-16), 1.4.4 (2024-07-26)
  1.4.3 (2024-06-29)
  1.4.2 (2024-06-29)
  1.4.1 (2023-07-07)
  ...


Downloads:
  Yesterday: 20 120
  Last 7 days: 362 042
  All time: 196 976 983


Licenses: Apache-2.0
Links:
  GitHub: https://github.com/michalmuskala/jason

@s3cur3 s3cur3 force-pushed the add-downloads-and-dates-to-hex-info branch from 43b1ee7 to 4479112 Compare April 9, 2026 12:48
@s3cur3
Copy link
Copy Markdown
Contributor Author

s3cur3 commented Apr 9, 2026

@ericmj, done! In 4479112, I've:

  • added a thousands separator for both the list and specific releases, and
  • moved the "recent releases" to each print on their own line.

One thing I'm having trouble with is stubbing out the downloads in test. Ideally I'd do so in test/mix/tasks/hex.info_test.exs:16 (test "package"), but I can't figure out how I'd call into Hexpm to simulate thousands of downloads. It does seem to work as-is when I test manually against the real API, though.

@ericmj
Copy link
Copy Markdown
Member

ericmj commented Apr 9, 2026

You can use bypass to mock a hexpm response, there are existing examples of that in the tests.

@s3cur3
Copy link
Copy Markdown
Contributor Author

s3cur3 commented Apr 11, 2026

Ah, wonderful! Added a couple tests in 67f6180 👍

ericmj added 2 commits April 12, 2026 20:11
Restore iodata pipeline in format_releases so :yellow/:reset atoms
reach Hex.Shell rather than being stringified by Enum.join. Fix
"configs": atom-key in the release downloads test fixture that made
release["configs"]["mix.exs"] return nil.
Drop the extra trailing "\n" in the Recent releases info call — each
entry already ends with a newline and IO.puts adds another, which
produced two blank lines. Add a leading newline so there's a blank
line between the Config/Locked version block and the release list.
@ericmj ericmj merged commit 34997a2 into hexpm:main Apr 13, 2026
19 of 20 checks passed
@ericmj
Copy link
Copy Markdown
Member

ericmj commented Apr 13, 2026

This is great, thank you! 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Additional information in mix hex.info [package_name]

2 participants