Skip to content

Commit

Permalink
Remove Hex Jason dependency (#11295)
Browse files Browse the repository at this point in the history
JSON now ships with Elixir 1.18, which means that the Elixir portion of the Hex processing can now remove Jason, and have no dependencies.

This simplifies some uncommon (to most) mix environment setup that adds some friction to onboarding.

Co-authored-by: Hariharan Thavachelvam <[email protected]>
  • Loading branch information
TylerWitt and thavaahariharangit authored Jan 22, 2025
1 parent fb8ba72 commit 83b4d5d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 49 deletions.
2 changes: 0 additions & 2 deletions hex/helpers/build
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ esac

cp $CP_OPTS "$helpers_dir/lib" "$install_dir"
cp $CP_OPTS "$helpers_dir/mix.exs" "$install_dir"
cp $CP_OPTS "$helpers_dir/mix.lock" "$install_dir"

cd "$install_dir"
mix deps.get
22 changes: 7 additions & 15 deletions hex/helpers/lib/do_update.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@ dependency =
{dependency_lock, rest_lock} = Map.split(Mix.Dep.Lock.read(), [dependency])
Mix.Dep.Fetcher.by_name([dependency], dependency_lock, rest_lock, [])

System.cmd(
"mix",
[
"deps.get",
"--no-compile",
"--no-elixir-version-check",
],
[
env: %{
"MIX_EXS" => nil,
"MIX_LOCK" => nil,
"MIX_DEPS" => nil
}
]
)
args = [
"deps.get",
"--no-compile",
"--no-elixir-version-check",
]

System.cmd("mix", args, [env: %{"MIX_EXS" => nil}])

"mix.lock"
|> File.read()
Expand Down
15 changes: 3 additions & 12 deletions hex/helpers/lib/run.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule DependencyHelper do
def main() do
IO.read(:stdio, :eof)
|> Jason.decode!()
|> JSON.decode!()
|> run()
|> case do
{output, 0} ->
Expand Down Expand Up @@ -35,7 +35,7 @@ defmodule DependencyHelper do

defp encode_and_write(content) do
content
|> Jason.encode!()
|> JSON.encode!()
|> IO.write()
end

Expand Down Expand Up @@ -69,16 +69,7 @@ defmodule DependencyHelper do
script
] ++ args

System.cmd(
"mix",
args,
cd: dir,
env: %{
"MIX_EXS" => nil,
"MIX_LOCK" => nil,
"MIX_DEPS" => nil
}
)
System.cmd("mix", args, cd: dir, env: %{"MIX_EXS" => nil})
end

defp set_credentials([]), do: :ok
Expand Down
18 changes: 7 additions & 11 deletions hex/helpers/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ defmodule DependabotCore.Mixfile do
use Mix.Project

def project do
[app: :dependabot_core,
version: "0.1.0",
elixir: "~> 1.5",
start_permanent: Mix.env == :prod,
lockfile: System.get_env("MIX_LOCK") || "mix.lock",
deps_path: System.get_env("MIX_DEPS") || "deps",
deps: deps()]
[
app: :dependabot_core,
version: "0.1.0",
elixir: "~> 1.18",
start_permanent: Mix.env == :prod,
deps: []
]
end

def application do
[extra_applications: [:hex, :logger, :ssh]]
end

defp deps() do
[{:jason, "~> 1.0"}]
end
end
3 changes: 0 additions & 3 deletions hex/helpers/mix.lock

This file was deleted.

2 changes: 0 additions & 2 deletions hex/lib/dependabot/hex/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ def sanitize_mixfile(content)
def mix_env
{
"MIX_EXS" => File.join(NativeHelpers.hex_helpers_dir, "mix.exs"),
"MIX_LOCK" => File.join(NativeHelpers.hex_helpers_dir, "mix.lock"),
"MIX_DEPS" => File.join(NativeHelpers.hex_helpers_dir, "deps"),
"MIX_QUIET" => "1"
}
end
Expand Down
2 changes: 0 additions & 2 deletions hex/lib/dependabot/hex/file_updater/lockfile_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ def sanitize_mixfile(content)
def mix_env
{
"MIX_EXS" => File.join(NativeHelpers.hex_helpers_dir, "mix.exs"),
"MIX_LOCK" => File.join(NativeHelpers.hex_helpers_dir, "mix.lock"),
"MIX_DEPS" => File.join(NativeHelpers.hex_helpers_dir, "deps"),
"MIX_QUIET" => "1"
}
end
Expand Down
2 changes: 0 additions & 2 deletions hex/lib/dependabot/hex/update_checker/version_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ def version_class
def mix_env
{
"MIX_EXS" => File.join(NativeHelpers.hex_helpers_dir, "mix.exs"),
"MIX_LOCK" => File.join(NativeHelpers.hex_helpers_dir, "mix.lock"),
"MIX_DEPS" => File.join(NativeHelpers.hex_helpers_dir, "deps"),
"MIX_QUIET" => "1"
}
end
Expand Down

0 comments on commit 83b4d5d

Please sign in to comment.