mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
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.
This commit is contained in:
parent
1431ffa9f8
commit
5f5ac40631
2 changed files with 12 additions and 5 deletions
|
@ -1452,6 +1452,12 @@ impl CliOptions {
|
||||||
watch: Some(WatchFlagsWithPaths { hmr, .. }),
|
watch: Some(WatchFlagsWithPaths { hmr, .. }),
|
||||||
..
|
..
|
||||||
}) = &self.flags.subcommand
|
}) = &self.flags.subcommand
|
||||||
|
{
|
||||||
|
*hmr
|
||||||
|
} else if let DenoSubcommand::Serve(ServeFlags {
|
||||||
|
watch: Some(WatchFlagsWithPaths { hmr, .. }),
|
||||||
|
..
|
||||||
|
}) = &self.flags.subcommand
|
||||||
{
|
{
|
||||||
*hmr
|
*hmr
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -44,12 +44,15 @@ pub async fn serve(
|
||||||
maybe_npm_install(&factory).await?;
|
maybe_npm_install(&factory).await?;
|
||||||
|
|
||||||
let worker_factory = factory.create_cli_main_worker_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(
|
do_serve(
|
||||||
worker_factory,
|
worker_factory,
|
||||||
main_module.clone(),
|
main_module.clone(),
|
||||||
serve_flags.worker_count,
|
serve_flags.worker_count,
|
||||||
false,
|
hmr,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -109,8 +112,6 @@ async fn do_serve(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(exit_code)
|
Ok(exit_code)
|
||||||
|
|
||||||
// main.await?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_worker(
|
async fn run_worker(
|
||||||
|
@ -119,7 +120,7 @@ async fn run_worker(
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
hmr: bool,
|
hmr: bool,
|
||||||
) -> Result<i32, AnyError> {
|
) -> Result<i32, AnyError> {
|
||||||
let mut worker = worker_factory
|
let mut worker: crate::worker::CliMainWorker = worker_factory
|
||||||
.create_main_worker(
|
.create_main_worker(
|
||||||
deno_runtime::WorkerExecutionMode::Serve {
|
deno_runtime::WorkerExecutionMode::Serve {
|
||||||
is_main: false,
|
is_main: false,
|
||||||
|
|
Loading…
Reference in a new issue