@@ -83,7 +83,9 @@ defmodule Mix.Deps.Converger do
83
83
84
84
# Look for an overriding dep in the upper breadths, if
85
85
# found return a new acc without the overriden dep and
86
- # with the proper status set on the overrider
86
+ # with the proper status set on the overrider. The
87
+ # overrider is moved to the front of the accumulator to
88
+ # preserve the position of the removed dep.
87
89
defp overriden_deps ( acc , upper_breadths , dep ) do
88
90
overriden = Enum . any? ( upper_breadths , fn ( other ) ->
89
91
other . app == dep . app
@@ -92,18 +94,21 @@ defmodule Mix.Deps.Converger do
92
94
if overriden do
93
95
Mix.Dep [ app : app ] = dep
94
96
95
- Enum . map ( acc , fn other ->
96
- Mix.Dep [ app : other_app , opts: other_opts ] = other
97
+ { overrider , acc } =
98
+ Enum . reduce ( acc , { nil , [ ] } , fn other , { overrider , acc } ->
99
+ Mix.Dep [ app : other_app , opts: other_opts ] = other
97
100
98
- cond do
99
- app == other_app && ( other_opts [ :override ] || converge? ( dep , other ) ) ->
100
- other
101
- app == other_app ->
102
- other . status ( { :overriden , dep } )
103
- true ->
104
- other
105
- end
106
- end )
101
+ cond do
102
+ app == other_app && ( other_opts [ :override ] || converge? ( dep , other ) ) ->
103
+ { other , acc }
104
+ app == other_app ->
105
+ { other . status ( { :overriden , dep } ) , acc }
106
+ true ->
107
+ { overrider , [ other | acc ] }
108
+ end
109
+ end )
110
+
111
+ [ overrider | Enum . reverse ( acc ) ]
107
112
end
108
113
end
109
114
0 commit comments