deno
89e196db - feat(cli): native HMR runner for --watch-hmr (Phase 3, part 2)

Commit
170 days ago
feat(cli): native HMR runner for --watch-hmr (Phase 3, part 2) Replaces the CDP `Debugger.setScriptSource` HMR runner with the native import.meta.hot engine, so `deno run --watch-hmr` performs true module replacement: on a file change the worker reads and transpiles the new source, registers it as a loader override, and drives `applyHmrUpdate` in JS. Accept boundaries re-run with the fresh module, `dispose` hands state to the new instance via `hot.data`, and the program is not restarted. When no accepting boundary handles the change (or a path can't be hot-replaced), it falls back to the watcher's full restart. - module_loader: add `HmrSourceOverrides` (Arc<Mutex<HashMap<specifier,String>>>) checked first in `load_code_source`, so the post-evict `import()` recompiles from the freshly transpiled source instead of the stale module-graph source. Exposed from CliModuleLoaderFactory and shared with the worker. - worker: `NativeHmrState` carries the emitter, watcher communicator, and the override map. `run()` runs `run_event_loop_with_native_hmr`, which selects the event loop against `watch_for_changed_paths`; on change `apply_native_hmr` emits + overrides + `run_apply_hmr_update` (drives Deno.core.applyHmrUpdate and reads the handled bool), falling back to `force_restart` otherwise. - factory: build `NativeHmrState` instead of the CDP `create_hmr_runner`. - Remove the CDP HMR runner (cli/tools/run/hmr.rs) and its now-unused cdp.rs types (SetScriptSourceResponse, Status, ScriptParsed). Verified end-to-end: editing a self-accepting module under --watch-hmr re-runs it with new source, preserves state across the reload via hot.data, fires the accept callback, and does not restart the process. Known limitation: under symlinked paths (e.g. macOS /tmp -> /private/tmp) the watcher's canonical path can differ from the module specifier; the lookup misses and it falls back to a full restart (safe degradation).
Author
Parents
Loading