diff --git a/README.md b/README.md index ef218e1..8906563 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Add the following to your `mix.exs` file: ```elixir defp deps do [ - {:contexted, "~> 0.3.1"} + {:contexted, "~> 0.3.2"} ] end ``` @@ -197,7 +197,7 @@ App.Account.find_user(1) Both docs and specs are attached as metadata of module once it's compiled and saved as `.beam`. In reference to the example of `App.Account` context, it's possible that `App.Account.Users` will not be saved in `.beam` file before the `delegate_all` macro is executed. Therefore, first, all of the modules have to be compiled, and saved to `.beam` and only then we can create `@doc` and `@spec` of each delegated function. -As a workaround, in `Contexted.Tracer.after_compiler/1` all of the contexts `.beam` files are first deleted and then recompiled. This is an opt-in functionality, as it extends compilation time, and may produce warnings. If you want to enable it, set the following config value: +As a workaround, in `Contexted.Tracer.after_compiler/1` all of the contexts `.beam` files are first deleted and then recompiled. This is an opt-in functionality, as it extends compilation time. If you want to enable it, set the following config value: ```elixir config :contexted, @@ -206,6 +206,8 @@ config :contexted, You may also want to enable it only for certain environments, like `dev`. +*Please also note that when this functionality is enabled, during the recompilation process, warnings are temporarily silenced to avoid logging conflict warnings. It will still log warnings as intended, during the first compilation, therefore it won't have any affect on normal compilation flow.* + Read more about `Contexted.Delegator` and its options in [docs](https://hexdocs.pm/contexted/Contexted.Delegator.html).
diff --git a/lib/contexted/tracer.ex b/lib/contexted/tracer.ex index b13ed1c..3bf80c0 100644 --- a/lib/contexted/tracer.ex +++ b/lib/contexted/tracer.ex @@ -44,7 +44,9 @@ defmodule Contexted.Tracer do beam_files_folder = extract_beam_files_folder() file_paths = remove_context_beams_and_return_module_paths() - Kernel.ParallelCompiler.compile_to_path(file_paths, beam_files_folder) + silence_recompilation_warnings(fn -> + Kernel.ParallelCompiler.compile_to_path(file_paths, beam_files_folder) + end) {status, diagnostics} end @@ -116,4 +118,20 @@ defmodule Contexted.Tracer do |> Atom.to_string() |> then(&~r/\b#{&1}\b/) end + + @spec silence_recompilation_warnings((() -> any())) :: any() + defp silence_recompilation_warnings(fun) do + original_logger_level = Logger.level() + original_compiler_options = Code.compiler_options() + + Logger.configure(level: :error) + Code.compiler_options(ignore_module_conflict: true) + + try do + fun.() + after + Logger.configure(level: original_logger_level) + Code.compiler_options(original_compiler_options) + end + end end diff --git a/mix.exs b/mix.exs index d701f02..a948285 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule Contexted.MixProject do app: :contexted, description: "Contexted is an Elixir library designed to streamline the management of complex Phoenix contexts in your projects, offering tools for module separation, subcontext creation, and auto-generating CRUD operations for improved code maintainability.", - version: "0.3.1", + version: "0.3.2", elixir: "~> 1.14", start_permanent: Mix.env() == :prod, deps: deps(),