feat(runner): add transitive hot-reload for ESM via custom loader#1354
Open
adelisle wants to merge 1 commit into
Open
feat(runner): add transitive hot-reload for ESM via custom loader#1354adelisle wants to merge 1 commit into
adelisle wants to merge 1 commit into
Conversation
Adds hot-reload support to the ESM runner with auto-detection of
transitive dependency changes (parity with the CJS runner).
The ESM runner now registers a dedicated loader
(`src/runner-esm-loader.mjs`) via `module.register()`. The loader
tracks every resolved user file and the parent → child import
relationships seen in its `resolve` hook, building a reverse
dependency graph. When a file changes, the loader bumps a per-file
version counter for that file and every transitive importer; the next
`import()` produces a fresh `?v=<n>` URL so Node re-evaluates the
whole chain.
The HotReload middleware was extended to support pluggable strategies
(CJS keeps the existing `require.cache` / `module.children` walker;
ESM uses the loader). When the runner exposes a non-Node module graph,
the middleware enumerates user files via `getAllUserFiles()` and, on
change, resolves which services to reload via `getImporters()` — only
the affected services are reloaded.
Other changes:
- `--hot` no longer clobbers a `hotReload: { ... }` config object
(CJS and ESM runners).
- HotReload watcher callback debounced (leading edge, 100ms) to dedupe
the multiple `change` events `fs.watch` fires per save on Linux.
- `runner.d.ts`: new `ReloadStrategy` interface.
- `test/e2e/scenarios/hot-reload-{cjs,esm}/`: new e2e scenarios
validating service-file reload, 1-hop transitive dep reload, and
3-hop chain (`A → B → C → service`) reload for both module systems.
Co-authored-by: Copilot <copilot@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Adds hot-reload support to the ESM runner with auto-detection of transitive dependency changes (parity with the CJS runner).
The ESM runner now registers a dedicated loader
(
src/runner-esm-loader.mjs) viamodule.register(). The loader tracks every resolved user file and the parent → child import relationships seen in itsresolvehook, building a reverse dependency graph. When a file changes, the loader bumps a per-file version counter for that file and every transitive importer; the nextimport()produces a fresh?v=<n>URL so Node re-evaluates the whole chain.The HotReload middleware was extended to support pluggable strategies (CJS keeps the existing
require.cache/module.childrenwalker; ESM uses the loader). When the runner exposes a non-Node module graph, the middleware enumerates user files viagetAllUserFiles()and, on change, resolves which services to reload viagetImporters()— only the affected services are reloaded.Other changes:
--hotno longer clobbers ahotReload: { ... }config object (CJS and ESM runners).changeeventsfs.watchfires per save on Linux.runner.d.ts: newReloadStrategyinterface.test/e2e/scenarios/hot-reload-{cjs,esm}/: new e2e scenarios validating service-file reload, 1-hop transitive dep reload, and 3-hop chain (A → B → C → service) reload for both module systems.🎯 Relevant issues
💎 Type of change
🚦 How Has This Been Tested?
npm testandnpm run test:e2ehave been run without errors.🏁 Checklist:
This was made with the help of AI through GitHub Copilot.