Skip to content

Commit ebc87ab

Browse files
authored
Fix MixFile strategy for sparse git dependencies (#110)
1 parent c4dc99c commit ebc87ab

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

lib/mix_dependency_submission/fetcher/mix_file.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ defmodule MixDependencySubmission.Fetcher.MixFile do
5353

5454
defp normalize_dep({app, requirement, opts})
5555
when is_atom(app) and (is_binary(requirement) or is_nil(requirement)) and is_list(opts) do
56+
bin_app = Atom.to_string(app)
57+
58+
dest = Path.join(Mix.Project.deps_path(), bin_app)
59+
build = Path.join([Mix.Project.build_path(), "lib", bin_app])
60+
61+
opts =
62+
opts
63+
|> Keyword.put(:dest, dest)
64+
|> Keyword.put(:build, build)
65+
5666
{scm, opts} =
5767
Enum.find_value(Mix.SCM.available(), {nil, opts}, fn scm ->
5868
case scm.accepts_options(app, opts) do

test/fixtures/app_locked/mix.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ defmodule AppNameToReplace.MixProject do
88
deps: [
99
{:credo, "~> 1.7"},
1010
{:mime, "~> 2.0"},
11-
{:expo, github: "elixir-gettext/expo"}
11+
{:expo, github: "elixir-gettext/expo"},
12+
{:heroicons,
13+
github: "tailwindlabs/heroicons", tag: "v2.1.5", sparse: "optimized", app: false, compile: false, depth: 1}
1214
]
1315
]
1416
end

test/fixtures/app_locked/mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"credo": {:hex, :credo, "1.7.0", "6119bee47272e85995598ee04f2ebbed3e947678dee048d10b5feca139435f75", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "6839fcf63d1f0d1c0f450abc8564a57c43d644077ab96f2934563e68b8a769d7"},
44
"expo": {:git, "https://github.com/elixir-gettext/expo.git", "2ae85019d62288001bdc4a949d65bf650beee315", []},
55
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
6+
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "ad0ad1f6d51bd64dcd67e363d2b2833a8de25154", [tag: "v2.1.5", sparse: "optimized", depth: 1]},
67
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
78
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
89
}

test/mix_dependency_submission/fetcher/mix_file_test.exs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule MixDependencySubmission.Fetcher.MixFileTest do
22
use MixDependencySubmission.FixtureCase, async: false
33

4+
alias Mix.SCM.Git
45
alias MixDependencySubmission.Fetcher.MixFile
56
alias MixDependencySubmission.Util
67

@@ -14,21 +15,46 @@ defmodule MixDependencySubmission.Fetcher.MixFileTest do
1415
assert %{
1516
credo: %{
1617
scm: Hex.SCM,
17-
mix_dep: {:credo, "~> 1.7", [hex: "credo", repo: "hexpm"]},
18+
mix_dep: {:credo, "~> 1.7", [hex: "credo", build: _credo_build, dest: _credo_dest, repo: "hexpm"]},
1819
scope: :runtime,
1920
relationship: :direct
2021
},
2122
expo: %{
22-
scm: Mix.SCM.Git,
23-
mix_dep: {:expo, nil, [git: "https://github.com/elixir-gettext/expo.git", checkout: nil]},
23+
scm: Git,
24+
mix_dep:
25+
{:expo, nil,
26+
[
27+
git: "https://github.com/elixir-gettext/expo.git",
28+
checkout: _expo_checkout,
29+
build: _expo_build,
30+
dest: _expo_dest
31+
]},
2432
scope: :runtime,
2533
relationship: :direct
2634
},
2735
mime: %{
2836
scm: Hex.SCM,
29-
mix_dep: {:mime, "~> 2.0", [hex: "mime", repo: "hexpm"]},
37+
mix_dep: {:mime, "~> 2.0", [hex: "mime", build: _mime_build, dest: _mime_dest, repo: "hexpm"]},
3038
scope: :runtime,
3139
relationship: :direct
40+
},
41+
heroicons: %{
42+
scope: :runtime,
43+
scm: Git,
44+
mix_dep:
45+
{:heroicons, nil,
46+
[
47+
git: "https://github.com/tailwindlabs/heroicons.git",
48+
dest: _heroicons_dest,
49+
checkout: _heroicons_checkout,
50+
build: _heroicons_build,
51+
tag: "v2.1.5",
52+
sparse: "optimized",
53+
app: false,
54+
compile: false,
55+
depth: 1
56+
]},
57+
relationship: :direct
3258
}
3359
} = MixFile.fetch()
3460
end)
@@ -40,15 +66,15 @@ defmodule MixDependencySubmission.Fetcher.MixFileTest do
4066
Util.in_project(app_path, fn _mix_module ->
4167
assert %{
4268
credo: %{
43-
mix_dep: {:credo, "~> 1.7", [hex: "credo", repo: "hexpm"]},
69+
mix_dep: {:credo, "~> 1.7", [hex: "credo", build: _credo_build, dest: _credo_dest, repo: "hexpm"]},
4470
relationship: :direct,
4571
scm: Hex.SCM,
4672
scope: :runtime
4773
},
4874
path_dep: %{
4975
scope: :runtime,
5076
scm: Mix.SCM.Path,
51-
mix_dep: {:path_dep, nil, [dest: "/tmp", path: "/tmp"]},
77+
mix_dep: {:path_dep, nil, [dest: "/tmp", build: _path_dep_build, path: "/tmp"]},
5278
relationship: :direct
5379
}
5480
} = MixFile.fetch()

0 commit comments

Comments
 (0)