Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/hex/scm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defmodule Hex.SCM do
end
end

# https://hexdocs.pm/mix/Mix.Tasks.Deps.html#module-dependency-definition-options
# https://mix.hexdocs.pm/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
Expand Down
14 changes: 10 additions & 4 deletions lib/hex/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,38 @@ defmodule Hex.Utils do

def hexdocs_url(organization, package)
when organization in ["hexpm", nil],
do: "https://hexdocs.pm/#{package}"
do: "https://#{package_subdomain(package)}.hexdocs.pm"

def hexdocs_url(organization, package),
do: "https://#{organization}.hexorgs.pm/#{package}"

def hexdocs_url(organization, package, version)
when organization in ["hexpm", nil],
do: "https://hexdocs.pm/#{package}/#{version}"
do: "https://#{package_subdomain(package)}.hexdocs.pm/#{version}"

def hexdocs_url(organization, package, version),
do: "https://#{organization}.hexorgs.pm/#{package}/#{version}"

def hexdocs_module_url(organization, package, module)
when organization in ["hexpm", nil],
do: "https://hexdocs.pm/#{package}/#{module}.html"
do: "https://#{package_subdomain(package)}.hexdocs.pm/#{module}.html"

def hexdocs_module_url(organization, package, module),
do: "https://#{organization}.hexorgs.pm/#{package}/#{module}.html"

def hexdocs_module_url(organization, package, version, module)
when organization in ["hexpm", nil],
do: "https://hexdocs.pm/#{package}/#{version}/#{module}.html"
do: "https://#{package_subdomain(package)}.hexdocs.pm/#{version}/#{module}.html"

def hexdocs_module_url(organization, package, version, module),
do: "https://#{organization}.hexorgs.pm/#{package}/#{version}/#{module}.html"

# Hex package names allow underscores. RFC 1123 hostname labels and
# RFC 6125 wildcard SAN matching don't, so Fastly returns 421 for
# underscore subdomains under *.hexdocs.pm. Map `_` -> `-` here; the
# Fastly Compute subdomain handler reverses it for the bucket lookup.
defp package_subdomain(package), do: String.replace(package, "_", "-")

def package_retirement_reason(:RETIRED_OTHER), do: "other"
def package_retirement_reason(:RETIRED_INVALID), do: "invalid"
def package_retirement_reason(:RETIRED_SECURITY), do: "security"
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/tasks/hex.publish.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ defmodule Mix.Tasks.Hex.Publish do
is the generated documentation located in the `doc/` directory with an
`index.html` file.

The documentation will be accessible at `https://hexdocs.pm/my_package/1.0.0`,
`https://hexdocs.pm/my_package` will always redirect to the latest published
The documentation will be accessible at `https://my_package.hexdocs.pm/1.0.0`,
`https://my_package.hexdocs.pm` will always redirect to the latest published
version.

Documentation will be built and published automatically. To publish a package
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/hex.search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
defp decode_json!(body) do
if Code.ensure_loaded?(:json) do
try do
:json.decode(body)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.15.7)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.15.7)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.13.4)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (24.3, 1.12.3)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.14.5)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (24.3, 1.12.3)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.13.4)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.14.5)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (24.3, 1.12.3)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.15.7)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.14.5)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)

Check warning on line 212 in lib/mix/tasks/hex.search.ex

View workflow job for this annotation

GitHub Actions / Test (25.3, 1.13.4)

:json.decode/1 is undefined (module :json is not available or is yet to be defined)
rescue
error in ErlangError ->
Mix.raise("Docs search returned invalid JSON: #{inspect(error.original)}")
Expand Down Expand Up @@ -251,7 +251,7 @@
defp document_url(package, ref) do
case :binary.split(package, "-") do
[name, version] ->
"https://hexdocs.pm/#{Enum.join([name, version, ref], "/")}"
"https://#{name}.hexdocs.pm/#{version}/#{ref}"

_ ->
Mix.raise("Unexpected package search result format: #{inspect(package)}")
Expand Down
10 changes: 5 additions & 5 deletions test/mix/tasks/hex.docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ defmodule Mix.Tasks.Hex.DocsTest do
test "open docs online" do
Mix.Tasks.Hex.Docs.run(["online", "ecto"])
assert_received {:hex_system_cmd, _cmd, browser_open_cmd}
assert Enum.fetch!(browser_open_cmd, -1) == "https://hexdocs.pm/ecto"
assert Enum.fetch!(browser_open_cmd, -1) == "https://ecto.hexdocs.pm"
end

test "open the version of a package this app uses online" do
Expand All @@ -350,7 +350,7 @@ defmodule Mix.Tasks.Hex.DocsTest do
Mix.Dep.Lock.write(%{docs_package: {:hex, :docs_package, "1.1.1"}})
Mix.Tasks.Hex.Docs.run(["online", "docs_package"])
assert_received {:hex_system_cmd, _cmd, browser_open_cmd}
assert Enum.fetch!(browser_open_cmd, -1) == "https://hexdocs.pm/docs_package/1.1.1"
assert Enum.fetch!(browser_open_cmd, -1) == "https://docs-package.hexdocs.pm/1.1.1"
end)
end

Expand All @@ -361,14 +361,14 @@ defmodule Mix.Tasks.Hex.DocsTest do
Mix.Dep.Lock.write(%{docs_package: {:hex, :docs_package, "1.1.1"}})
Mix.Tasks.Hex.Docs.run(["online", "docs_package", "--latest"])
assert_received {:hex_system_cmd, _cmd, browser_open_cmd}
assert Enum.fetch!(browser_open_cmd, -1) == "https://hexdocs.pm/docs_package"
assert Enum.fetch!(browser_open_cmd, -1) == "https://docs-package.hexdocs.pm"
end)
end

test "open a specific page online using the page option" do
Mix.Tasks.Hex.Docs.run(["online", "ecto", "--page", "Ecto.Repo"])
assert_received {:hex_system_cmd, _cmd, browser_open_cmd}
assert Enum.fetch!(browser_open_cmd, -1) == "https://hexdocs.pm/ecto/Ecto.Repo.html"
assert Enum.fetch!(browser_open_cmd, -1) == "https://ecto.hexdocs.pm/Ecto.Repo.html"
end
end

Expand All @@ -377,7 +377,7 @@ defmodule Mix.Tasks.Hex.DocsTest do
Mix.Tasks.Hex.Docs.run(["online", "ecto", "--module", "Ecto.Repo"])
assert_received {:mix_shell, :error, ["--module is deprecated, use --page instead"]}
assert_received {:hex_system_cmd, _cmd, browser_open_cmd}
assert Enum.fetch!(browser_open_cmd, -1) == "https://hexdocs.pm/ecto/Ecto.Repo.html"
assert Enum.fetch!(browser_open_cmd, -1) == "https://ecto.hexdocs.pm/Ecto.Repo.html"
end

@tag mirror: true
Expand Down
6 changes: 3 additions & 3 deletions test/mix/tasks/hex.publish_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ defmodule Mix.Tasks.Hex.PublishTest do

refute_received {:mix_shell, :info,
[
"Docs will soon be available at https://hexdocs.pm/invalid_filename/0.1.0"
"Docs will soon be available at https://invalid-filename.hexdocs.pm/0.1.0"
]}
end
end)
Expand All @@ -258,7 +258,7 @@ defmodule Mix.Tasks.Hex.PublishTest do

refute_received {:mix_shell, :info,
[
"Docs will soon be available at https://hexdocs.pm/invalid_dirname/0.1.0"
"Docs will soon be available at https://invalid-dirname.hexdocs.pm/0.1.0"
]}
end
end)
Expand All @@ -278,7 +278,7 @@ defmodule Mix.Tasks.Hex.PublishTest do
Mix.Tasks.Hex.Publish.run(["docs", "--no-progress", "--replace"])

refute_received {:mix_shell, :info,
["Docs will soon be available at https://hexdocs.pm/ex_doc/0.1.0"]}
["Docs will soon be available at https://ex-doc.hexdocs.pm/0.1.0"]}
end
end)
end
Expand Down
4 changes: 2 additions & 2 deletions test/mix/tasks/hex.search_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ defmodule Mix.Tasks.Hex.SearchTest do

assert_received {:mix_shell, :info,
[
"# cast/4 (1/2)\nhttps://hexdocs.pm/ecto/3.13.4/Ecto.Changeset.html#cast/4\n\nCast changesets.\n\n"
"# cast/4 (1/2)\nhttps://ecto.hexdocs.pm/3.13.4/Ecto.Changeset.html#cast/4\n\nCast changesets.\n\n"
]}

assert_received {:mix_shell, :info,
[
"# Examples - mix deps.tree (2/2)\nhttps://hexdocs.pm/mix/1.20.0-rc.5/Mix.Tasks.Deps.Tree.html#module-examples\n\nTree docs.\n\n"
"# Examples - mix deps.tree (2/2)\nhttps://mix.hexdocs.pm/1.20.0-rc.5/Mix.Tasks.Deps.Tree.html#module-examples\n\nTree docs.\n\n"
]}
end)
end
Expand Down
Loading