@@ -69,17 +69,22 @@ defmodule IEx.Helpers do
6969 import IEx , only: [ dont_display_result: 0 ]
7070
7171 @ doc """
72- Recompiles the current Mix project.
72+ Recompiles the current Mix project or Mix install
73+ dependencies.
7374
74- This helper only works when IEx is started with a Mix
75- project, for example, `iex -S mix`. Note this function
76- simply recompiles Elixir modules, without reloading
77- configuration, recompiling dependencies, or restarting
78- applications.
75+ This helper requires either `Mix.install/2` to have been
76+ called within the current IEx session or for IEx to be
77+ started alongside, for example, `iex -S mix`.
7978
80- Therefore, any long running process may crash on recompilation,
81- as changed modules will be temporarily removed and recompiled,
82- without going through the proper code change callback.
79+ In the `Mix.install/1` case, it will recompile any outdated
80+ path dependency declared during install. Within a project,
81+ it will recompile any outdated module.
82+
83+ Note this function simply recompiles Elixir modules, without
84+ reloading configuration or restarting applications. This means
85+ any long running process may crash on recompilation, as changed
86+ modules will be temporarily removed and recompiled, without
87+ going through the proper code change callback.
8388
8489 If you want to reload a single module, consider using
8590 `r(ModuleName)` instead.
@@ -93,21 +98,36 @@ defmodule IEx.Helpers do
9398
9499 """
95100 def recompile ( options \\ [ ] ) do
96- if mix_started? ( ) do
97- config = Mix.Project . config ( )
98- consolidation = Mix.Project . consolidation_path ( config )
99- reenable_tasks ( config )
101+ cond do
102+ not mix_started? ( ) ->
103+ IO . puts ( IEx . color ( :eval_error , "Mix is not running. Please start IEx with: iex -S mix" ) )
104+ :error
105+
106+ Mix . installed? ( ) ->
107+ Mix . in_install_project ( fn ->
108+ do_recompile ( options )
109+ # Just as with Mix.install/2 we clear all task invocations,
110+ # so that we can recompile the dependencies again next time
111+ Mix.Task . clear ( )
112+ :ok
113+ end )
114+
115+ true ->
116+ do_recompile ( options )
117+ end
118+ end
100119
101- force? = Keyword . get ( options , :force , false )
102- args = [ "--purge-consolidation-path-if-stale" , "--return-errors" , consolidation ]
103- args = if force? , do: [ "--force" | args ] , else: args
120+ defp do_recompile ( options ) do
121+ config = Mix.Project . config ( )
122+ consolidation = Mix.Project . consolidation_path ( config )
123+ reenable_tasks ( config )
104124
105- { result , _ } = Mix.Task . run ( "compile" , args )
106- result
107- else
108- IO . puts ( IEx . color ( :eval_error , "Mix is not running. Please start IEx with: iex -S mix" ) )
109- :error
110- end
125+ force? = Keyword . get ( options , :force , false )
126+ args = [ "--purge-consolidation-path-if-stale" , "--return-errors" , consolidation ]
127+ args = if force? , do: [ "--force" | args ] , else: args
128+
129+ { result , _ } = Mix.Task . run ( "compile" , args )
130+ result
111131 end
112132
113133 defp mix_started? do
0 commit comments