From 5f5ac4063142c6c411486581f2f26cf51a32d7e3 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:32:18 +0200 Subject: [PATCH] fix(serve): support serve hmr (#26078) This PR addresses issue #25600 Changes: Updated `fn has_hmr` to check `serve` subcommand and return its hmr value if found, in order to run the worker in serve mode with hmr_runner. Thus the hmr event can be dispatched upon changes on the file served. --- cli/args/mod.rs | 6 ++++++ cli/tools/serve.rs | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index f5ecc04496..754cd38fa9 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1452,6 +1452,12 @@ impl CliOptions { watch: Some(WatchFlagsWithPaths { hmr, .. }), .. }) = &self.flags.subcommand + { + *hmr + } else if let DenoSubcommand::Serve(ServeFlags { + watch: Some(WatchFlagsWithPaths { hmr, .. }), + .. + }) = &self.flags.subcommand { *hmr } else { diff --git a/cli/tools/serve.rs b/cli/tools/serve.rs index 4ce1cad6f2..e3f9e94f8e 100644 --- a/cli/tools/serve.rs +++ b/cli/tools/serve.rs @@ -44,12 +44,15 @@ pub async fn serve( maybe_npm_install(&factory).await?; let worker_factory = factory.create_cli_main_worker_factory().await?; - + let hmr = serve_flags + .watch + .map(|watch_flags| watch_flags.hmr) + .unwrap_or(false); do_serve( worker_factory, main_module.clone(), serve_flags.worker_count, - false, + hmr, ) .await } @@ -109,8 +112,6 @@ async fn do_serve( } } Ok(exit_code) - - // main.await? } async fn run_worker( @@ -119,7 +120,7 @@ async fn run_worker( main_module: ModuleSpecifier, hmr: bool, ) -> Result { - let mut worker = worker_factory + let mut worker: crate::worker::CliMainWorker = worker_factory .create_main_worker( deno_runtime::WorkerExecutionMode::Serve { is_main: false,