Skip to content

Commit

Permalink
fix(serve): support serve hmr (#26078)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HasanAlrimawi authored and bartlomieju committed Nov 5, 2024
1 parent f51f192 commit 2acbe13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions cli/tools/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -109,8 +112,6 @@ async fn do_serve(
}
}
Ok(exit_code)

// main.await?
}

async fn run_worker(
Expand All @@ -119,7 +120,7 @@ async fn run_worker(
main_module: ModuleSpecifier,
hmr: bool,
) -> Result<i32, AnyError> {
let mut worker = worker_factory
let mut worker: crate::worker::CliMainWorker = worker_factory
.create_main_worker(
deno_runtime::WorkerExecutionMode::Serve {
is_main: false,
Expand Down

0 comments on commit 2acbe13

Please sign in to comment.