GtBridge.HotReload (gt_bridge v0.17.3)

Copy Markdown View Source

I drive the hot-reload pipeline: write source to disk, compile, persist beam files, broadcast events, and return a payload that GT-side subscribers can re-render from directly.

See reload/2 for the full sequence and the recompiled payload shape carried back to the GT side.

Summary

Functions

I return the compile dependency graph as {from, to, label} edges.

I drop mod from the BEAM so a stale loaded copy does not survive source-file deletion, then broadcast :source_removed. GT-side caches subscribe to that event and drop their derived state.

I hot-reload a source file and its dependents.

Functions

compile_dep_edges(opts \\ [])

@spec compile_dep_edges(keyword()) :: [map()]

I return the compile dependency graph as {from, to, label} edges.

Edges represent: changing to forces recompilation of from. Label is :compile, :export, or :runtime.

purge_module(mod)

@spec purge_module(module()) :: :ok

I drop mod from the BEAM so a stale loaded copy does not survive source-file deletion, then broadcast :source_removed. GT-side caches subscribe to that event and drop their derived state.

reload(path, content)

@spec reload(String.t(), String.t()) :: :ok

I hot-reload a source file and its dependents.

  1. Writes content to path and formats it
  2. Compiles the dep's full source tree via ParallelCompiler (excludes the currently running eval module)
  3. Persists compiled beams to ebin
  4. Recompiles the main project via IEx.Helpers.recompile
  5. Broadcasts a %GtBridge.Events.ModuleEvent{kind: :recompiled} for each module that was compiled. On parse/compile failure, broadcasts a %ModuleEvent{kind: :compile_failed} and reraises.

Returns %{recompiled: [payload]} where each payload is a map. The directly-saved module's payload carries mod, source_hash, and functions (the new Analysis.all_functions/1 result) inline, so GT-side subscribers re-render from the announcement without a follow-up bridge call. Sibling modules from ParallelCompiler propagation arrive bare (%{mod: name, source_hash: nil, functions: nil}) and let any subscribers fall back to refetching on demand.

Returns :ok regardless of success/failure; subscribers learn the outcome via the broadcast events (:source_written, :recompiled, :compile_failed). No GT-side caller inspects the response.