hmr 2.0.0
hmr: ^2.0.0 copied to clipboard
Hot Module Replacement system specially designed for command-line Dart applications.
Changelog #
2.0.0 #
Flutter-grade HMR for CLI Dart applications. Major rewrite around the Dart VM service: true hot reload (no recompilation pipeline, no isolate restart), preserved app state, and a child-side runtime API for reacting to events.
Highlights #
Three supported usage modes:
- Built-in CLI (
hmr) — zero-config supervisor for the 80% case. - Runtime API (
package:hmr/runtime.dart) — opt into typed hooks (onReload,onRestart,onFile*) from inside your app. - Custom runner (
package:hmr/hmr.dart) — composeVmServiceProcessStrategy,FileWatcher, filters, presenters andHotKeyControllerto build your own supervisor. Seeexample/bin/custom_hmr.dart.
New #
VmServiceProcessStrategy— launches the entrypoint as a child process with--enable-vm-service=0, then issuesreloadSourceson file changes.- Automatic fallback from hot reload to a full restart on shape changes.
- Full restart automatically triggered when the entrypoint file itself is
modified (a hot reload would skip
main()re-execution). package:hmr/runtime.dart— opt-inHmr.instanceAPI for the child process to subscribe to typed events (onReload,onRestart,onFileCreated,onFileModified,onFileDeleted,onFileMoved, or a genericon<E>). Handler exceptions are caught and logged — a buggy hook can never crash the supervised app. No-op outside the supervisor, so the samemain()works for bothhmrand plaindart run.RuntimeBridgeforwards events from the parent to the child via theext.hmr.dispatchVM service extension, with bounded polling to absorb child startup latency without dropping early events.- Hot keys:
r(reload),R(restart),c(clear),h(help),q(quit). - Structured event model with JSON serialization (
--format=json) coveringstarted,compileStarted,compileSucceeded,compileFailed,reloadSucceeded,reloadFailed,fileChanged,processCrashed,stopped. Same shape consumed by the runtime API. ProcessCrashedpreserves the full child stderr verbatim — no truncation.EntrypointResolverwith a documented priority chain: CLI arg → pubspechmr.entrypoint→bin/<package>.dart→bin/main.dart.example/bin/custom_hmr.dart— runnable template for building your own supervisor from the library's building blocks.
Breaking #
- Removed
IsolateRestartStrategyand the--strategyflag — every run uses the VM-service strategy. - Removed the
--rescan-extensionflag (use the runtime API instead). - Renamed
impl/toexample/(pub.dev convention). - Renamed
VmServiceReloadStrategy→VmServiceProcessStrategy. - Removed the legacy
Runner/Watcher/IgnoreMiddleware/DebounceMiddleware/IncludeMiddlewareAPI; build a custom supervisor withReloadOrchestrator+FileWatcher+ignoreSegment/includeGlobs/excludeGlobsfilters instead.
Fixes #
- Surface a clear, red error message when the configured entrypoint does not
exist, instead of the cryptic
Bad state: VM service URI not found in child process output. - Stop dropping early runtime-API events:
RuntimeBridge.initnow polls the isolate (default 500 ms) forext.hmr.dispatchinstead of checking once, closing the race between parent VM-service handshake and childmain(). - Suppress VM-service URI lines from child stdout/stderr so terminal output stays focused on app logs.
- Detect post-restart crashes and emit
CompileFailedso reload errors are rendered without a stale "reloading…" header.
Docs #
- Rewritten
README.mdwith a table of contents, the three usage modes, a fullpubspec.yamlschema reference, CLI flags, runtime API table, and a table of every library symbol exported for custom runners. - New
example/README.mdcovering both the watched-app demo and thecustom_hmr.darttemplate.
1.4.1 #
- remove
SIGTERMon windows
1.4.0 #
- Expose
sendandlistenmethods - Request
SendPortfrom Isolate to send messages in the Isolate
1.3.2 #
- Change
debouncemiddleware order
1.3.1 #
- Remove
debouncedelay by default
1.3.0 #
- Migrate filters to responsibility chain pattern
1.2.0 #
- Implement
debouncedelay - Ignore
.dart_tooland IDE directories by default
1.1.2 #
- Remove
ProcessSignal.SIGTERM
1.1.1 #
- Fix entrypoint implicite extension
1.1.0 #
- Transfert
hmr [...args]toIsolate
1.0.3 #
- Add newline on exit to prevent terminal prompt bad display
1.0.2 #
- Enforce clear screen on start
- Enforce clear screen on reload
1.0.1 #
- Prevent the
hmrcommand from being run in a non-Dart project - Add clean-up of temporary files on exit
1.0.0 #
Initial Release - Première publication officielle du package HMR pour Dart
-
Hot reload without restarting the application
-
State retention between reloads
-
Automated kernel compilation via
dart compile. -
Glob patterns for inclusion/exclusion (
**/*.dart) -
Detection of modifications/creations/deletions/moves
-
Configurable debounce mechanism
-
Visual feedback with ANSI codes (colours, positioning)
-
Own compile error handling
-
Successive changes counter