Skip to content

Commit 56fbf2a

Browse files
author
José Valim
committed
Add Mix.Project.deps_paths
Signed-off-by: José Valim <[email protected]>
1 parent c3582f9 commit 56fbf2a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/mix/lib/mix/project.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ defmodule Mix.Project do
236236
Path.expand config[:deps_path]
237237
end
238238

239+
@doc """
240+
Returns the full path of all dependencies as a map.
241+
242+
## Examples
243+
244+
Mix.Project.deps_paths
245+
#=> %{foo: "deps/foo", bar: "custom/path/dep"}
246+
247+
"""
248+
@spec deps_paths() :: %{atom => Path.t}
249+
def deps_paths do
250+
Enum.reduce Mix.Dep.loaded(env: Mix.env), %{}, fn
251+
%{app: app, opts: opts}, acc -> Map.put acc, app, opts[:dest]
252+
end
253+
end
254+
239255
@doc """
240256
Returns the build path for this project.
241257

lib/mix/test/mix/dep_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ defmodule Mix.DepTest do
5353
end
5454
end
5555

56+
test "extracts all dependencies paths from the given project" do
57+
Mix.Project.push DepsApp
58+
59+
in_fixture "deps_status", fn ->
60+
paths = Mix.Project.deps_paths
61+
assert map_size(paths) == 6
62+
assert paths[:ok] =~ "deps/ok"
63+
assert paths[:uncloned] =~ "deps/uncloned"
64+
end
65+
end
66+
5667
test "fails on invalid dependencies" do
5768
assert_wrong_dependency [{:ok}]
5869
assert_wrong_dependency [{:ok, nil}]

0 commit comments

Comments
 (0)