@@ -11,31 +11,39 @@ defmodule Mix.Tasks.Deps.Clean do
1111
1212 Clean does not unlock the dependencies, unless `--unlock` is given.
1313 """
14- import Mix.Deps , only: [ loaded: 0 , loaded_by_name: 1 , format_dep: 1 ]
15-
1614 def run ( args ) do
1715 Mix.Project . get! # Require the project to be available
16+
1817 { opts , args , _ } = OptionParser . parse ( args , switches: [ unlock: :boolean , all: :boolean ] )
18+ loaded = Mix.Deps . loaded
1919
2020 cond do
2121 opts [ :all ] ->
22- do_clean loaded , opts
22+ do_clean Enum . map ( loaded , & ( & 1 . app ) ) , loaded , opts
2323 args != [ ] ->
24- do_clean loaded_by_name ( args ) , opts
24+ do_clean args , loaded , opts
2525 true ->
2626 raise Mix.Error , message: "mix deps.clean expects dependencies as arguments or " <>
2727 "the --all option to clean all dependencies"
2828 end
2929 end
3030
31- defp do_clean ( deps , opts ) do
31+ defp do_clean ( apps , loaded , opts ) do
3232 shell = Mix . shell
33-
34- apps = Enum . map deps , fn ( Mix.Dep [ scm : scm , opts: opts ] = dep ) ->
35- shell . info "* Cleaning #{ format_dep ( dep ) } "
36- File . rm_rf! ( opts [ :build ] )
37- scm . clean opts
38- dep . app
33+ build = Mix.Project . build_path |> Path . join ( "lib" )
34+ deps = Mix.Project . deps_path
35+
36+ Enum . each apps , fn ( app ) ->
37+ shell . info "* Cleaning #{ app } "
38+ load_paths =
39+ if dep = Enum . find ( loaded , & ( & 1 . app == app ) ) do
40+ Mix.Deps . load_paths ( dep )
41+ else
42+ [ Path . join ( [ build , app , "ebin" ] ) ]
43+ end
44+
45+ Enum . each ( load_paths , & ( & 1 |> Path . dirname |> File . rm_rf! ) )
46+ File . rm_rf! ( Path . join ( deps , app ) )
3947 end
4048
4149 if opts [ :unlock ] do
0 commit comments