Dev-only GenServer that triggers recompilation on router source changes.
It watches the router's own source file and every handler module's source
file, via RpcElixir.Router.source_files/1. Middleware and custom-type
modules are not watched, even though editing them changes the output.
Requires the optional :file_system dep. Without it, init/1 warns and
returns :ignore. The process never starts.
It is Phoenix-specific. Without :endpoint or :on_change there is nothing
to do on a change. Non-Phoenix apps do not need it.
Mix.Tasks.Compile.ElixirTsRpc already regenerates the client on each Elixir
recompile.
Usage
# lib/my_app/application.ex (Phoenix projects only)
children = [
{RpcElixir.Watcher, router: MyApp.Router, endpoint: MyAppWeb.Endpoint}
]Options
:router(required) — the RPC router module. A missing:routerraisesKeyError, even when:file_systemis absent.:endpoint— a Phoenix endpoint. The watcher callsPhoenix.CodeReloader.reload/1on each relevant change. That reloads only the endpoint's:reloadable_compilers, which by default excludes:elixir_ts_rpc. So add it there, or the client is not regenerated:reloadable_compilers: [:gettext, :elixir, :app, :elixir_ts_rpc]Use
:on_changeinstead to call codegen directly.:on_change—{mod, fun, args}invoked on change. Takes precedence over:endpointwhen both are given.:debounce_ms— coalesces rapid file events. Defaults to200.
Restart expectations
The linked FileSystem process starts inside init/1. The watcher traps
exits, so a FileSystem crash arrives as a message rather than killing the
watcher silently. The watcher then stops with {:filesystem_exited, reason}.
The supervisor is expected to restart the pair.
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts the watcher and links it to the caller.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Starts the watcher and links it to the caller.
opts takes the module options listed above, plus :name. The default name
is RpcElixir.Watcher. Returns :ignore when :file_system is not loaded.