@@ -83,7 +83,9 @@ defmodule Mix.Deps.Converger do
8383
8484 # Look for an overriding dep in the upper breadths, if
8585 # 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.
8789 defp overriden_deps ( acc , upper_breadths , dep ) do
8890 overriden = Enum . any? ( upper_breadths , fn ( other ) ->
8991 other . app == dep . app
@@ -92,18 +94,21 @@ defmodule Mix.Deps.Converger do
9294 if overriden do
9395 Mix.Dep [ app : app ] = dep
9496
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
97100
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 ) ]
107112 end
108113 end
109114
0 commit comments