diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-10-31 01:25:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 01:25:58 +0100 |
commit | 1713df13524ad20c6bd0413bcf4aa57adc3f9735 (patch) | |
tree | a558239a7f483cab10b83305b333d5ef9657bd3e /cli/factory.rs | |
parent | 48c5c3a3fb2f43716528db8915b36e55c411d94f (diff) |
feat: deno run --unstable-hmr (#20876)
This commit adds `--unstable-hmr` flag, that enabled Hot Module Replacement.
This flag works like `--watch` and accepts the same arguments. If
HMR is not possible the process will be restarted instead.
Currently HMR is only supported in `deno run` subcommand.
Upon HMR a `CustomEvent("hmr")` will be dispatched that contains
information which file was changed in its `details` property.
---------
Co-authored-by: Valentin Anger <syrupthinker@gryphno.de>
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/factory.rs')
-rw-r--r-- | cli/factory.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/cli/factory.rs b/cli/factory.rs index 9cdd32702..389c4dbe0 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -66,7 +66,7 @@ use std::future::Future; use std::sync::Arc; pub struct CliFactoryBuilder { - watcher_communicator: Option<WatcherCommunicator>, + watcher_communicator: Option<Arc<WatcherCommunicator>>, } impl CliFactoryBuilder { @@ -86,7 +86,7 @@ impl CliFactoryBuilder { pub async fn build_from_flags_for_watcher( mut self, flags: Flags, - watcher_communicator: WatcherCommunicator, + watcher_communicator: Arc<WatcherCommunicator>, ) -> Result<CliFactory, AnyError> { self.watcher_communicator = Some(watcher_communicator); self.build_from_flags(flags).await @@ -171,7 +171,7 @@ struct CliFactoryServices { } pub struct CliFactory { - watcher_communicator: Option<WatcherCommunicator>, + watcher_communicator: Option<Arc<WatcherCommunicator>>, options: Arc<CliOptions>, services: CliFactoryServices, } @@ -620,6 +620,11 @@ impl CliFactory { let npm_resolver = self.npm_resolver().await?; let fs = self.fs(); let cli_node_resolver = self.cli_node_resolver().await?; + let maybe_file_watcher_communicator = if self.options.has_hmr() { + Some(self.watcher_communicator.clone().unwrap()) + } else { + None + }; Ok(CliMainWorkerFactory::new( StorageKeyResolver::from_options(&self.options), @@ -643,6 +648,8 @@ impl CliFactory { )), self.root_cert_store_provider().clone(), self.fs().clone(), + Some(self.emitter()?.clone()), + maybe_file_watcher_communicator, self.maybe_inspector_server().clone(), self.maybe_lockfile().clone(), self.feature_checker().clone(), @@ -659,6 +666,7 @@ impl CliFactory { coverage_dir: self.options.coverage_dir(), enable_testing_features: self.options.enable_testing_features(), has_node_modules_dir: self.options.has_node_modules_dir(), + hmr: self.options.has_hmr(), inspect_brk: self.options.inspect_brk().is_some(), inspect_wait: self.options.inspect_wait().is_some(), is_inspecting: self.options.is_inspecting(), |