mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
refactor(flags): move watch flags into subcommand structs (#19516)
Moves the watch setting out of the `Flags` struct and into the individual subcommands
This commit is contained in:
parent
b2e546e530
commit
fa63fd4610
10 changed files with 248 additions and 120 deletions
|
@ -684,12 +684,15 @@ pub async fn run_benchmarks_with_watch(
|
|||
flags: Flags,
|
||||
bench_flags: BenchFlags,
|
||||
) -> Result<(), AnyError> {
|
||||
let clear_screen = !flags.no_clear_screen;
|
||||
file_watcher::watch_func(
|
||||
flags,
|
||||
file_watcher::PrintConfig {
|
||||
job_name: "Bench".to_string(),
|
||||
clear_screen,
|
||||
clear_screen: bench_flags
|
||||
.watch
|
||||
.as_ref()
|
||||
.map(|w| !w.no_clear_screen)
|
||||
.unwrap_or(true),
|
||||
},
|
||||
move |flags, sender, changed_paths| {
|
||||
let bench_flags = bench_flags.clone();
|
||||
|
@ -701,9 +704,7 @@ pub async fn run_benchmarks_with_watch(
|
|||
let cli_options = factory.cli_options();
|
||||
let bench_options = cli_options.resolve_bench_options(bench_flags)?;
|
||||
|
||||
if let Some(watch_paths) = cli_options.watch_paths() {
|
||||
let _ = sender.send(watch_paths);
|
||||
}
|
||||
let _ = sender.send(cli_options.watch_paths());
|
||||
let _ = sender.send(bench_options.files.include.clone());
|
||||
|
||||
let graph_kind = cli_options.type_check_mode().as_graph_kind();
|
||||
|
|
|
@ -28,13 +28,12 @@ pub async fn bundle(
|
|||
"Use alternative bundlers like \"deno_emit\", \"esbuild\" or \"rollup\" instead."
|
||||
);
|
||||
|
||||
if flags.watch.is_some() {
|
||||
let clear_screen = !flags.no_clear_screen;
|
||||
if let Some(watch_flags) = &bundle_flags.watch {
|
||||
util::file_watcher::watch_func(
|
||||
flags,
|
||||
util::file_watcher::PrintConfig {
|
||||
job_name: "Bundle".to_string(),
|
||||
clear_screen,
|
||||
clear_screen: !watch_flags.no_clear_screen,
|
||||
},
|
||||
move |flags, sender, _changed_paths| {
|
||||
let bundle_flags = bundle_flags.clone();
|
||||
|
@ -44,11 +43,7 @@ pub async fn bundle(
|
|||
.build_from_flags(flags)
|
||||
.await?;
|
||||
let cli_options = factory.cli_options();
|
||||
|
||||
if let Some(watch_paths) = cli_options.watch_paths() {
|
||||
let _ = sender.send(watch_paths);
|
||||
}
|
||||
|
||||
let _ = sender.send(cli_options.watch_paths());
|
||||
bundle_action(factory, &bundle_flags).await?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -61,13 +61,12 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> {
|
|||
);
|
||||
}
|
||||
|
||||
if flags.watch.is_some() {
|
||||
let clear_screen = !flags.no_clear_screen;
|
||||
if let Some(watch_flags) = &fmt_flags.watch {
|
||||
file_watcher::watch_func(
|
||||
flags,
|
||||
file_watcher::PrintConfig {
|
||||
job_name: "Fmt".to_string(),
|
||||
clear_screen,
|
||||
clear_screen: !watch_flags.no_clear_screen,
|
||||
},
|
||||
move |flags, sender, changed_paths| {
|
||||
let fmt_flags = fmt_flags.clone();
|
||||
|
|
|
@ -51,18 +51,17 @@ fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> {
|
|||
}
|
||||
|
||||
pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
|
||||
if flags.watch.is_some() {
|
||||
if let Some(watch_flags) = &lint_flags.watch {
|
||||
if lint_flags.is_stdin() {
|
||||
return Err(generic_error(
|
||||
"Lint watch on standard input is not supported.",
|
||||
));
|
||||
}
|
||||
let clear_screen = !flags.no_clear_screen;
|
||||
file_watcher::watch_func(
|
||||
flags,
|
||||
file_watcher::PrintConfig {
|
||||
job_name: "Lint".to_string(),
|
||||
clear_screen,
|
||||
clear_screen: !watch_flags.no_clear_screen,
|
||||
},
|
||||
move |flags, sender, changed_paths| {
|
||||
let lint_flags = lint_flags.clone();
|
||||
|
|
|
@ -9,12 +9,17 @@ use deno_runtime::permissions::PermissionsContainer;
|
|||
|
||||
use crate::args::EvalFlags;
|
||||
use crate::args::Flags;
|
||||
use crate::args::RunFlags;
|
||||
use crate::args::WatchFlagsWithPaths;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::factory::CliFactoryBuilder;
|
||||
use crate::file_fetcher::File;
|
||||
use crate::util;
|
||||
|
||||
pub async fn run_script(flags: Flags) -> Result<i32, AnyError> {
|
||||
pub async fn run_script(
|
||||
flags: Flags,
|
||||
run_flags: RunFlags,
|
||||
) -> Result<i32, AnyError> {
|
||||
if !flags.has_permission() && flags.has_permission_in_argv() {
|
||||
log::warn!(
|
||||
"{}",
|
||||
|
@ -26,8 +31,8 @@ To grant permissions, set them before the script argument. For example:
|
|||
);
|
||||
}
|
||||
|
||||
if flags.watch.is_some() {
|
||||
return run_with_watch(flags).await;
|
||||
if let Some(watch_flags) = run_flags.watch {
|
||||
return run_with_watch(flags, watch_flags).await;
|
||||
}
|
||||
|
||||
// TODO(bartlomieju): actually I think it will also fail if there's an import
|
||||
|
@ -96,14 +101,15 @@ pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
|
|||
|
||||
// TODO(bartlomieju): this function is not handling `exit_code` set by the runtime
|
||||
// code properly.
|
||||
async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
|
||||
let clear_screen = !flags.no_clear_screen;
|
||||
|
||||
async fn run_with_watch(
|
||||
flags: Flags,
|
||||
watch_flags: WatchFlagsWithPaths,
|
||||
) -> Result<i32, AnyError> {
|
||||
util::file_watcher::watch_func(
|
||||
flags,
|
||||
util::file_watcher::PrintConfig {
|
||||
job_name: "Process".to_string(),
|
||||
clear_screen,
|
||||
clear_screen: !watch_flags.no_clear_screen,
|
||||
},
|
||||
move |flags, sender, _changed_paths| {
|
||||
Ok(async move {
|
||||
|
@ -116,9 +122,7 @@ async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
|
|||
|
||||
maybe_npm_install(&factory).await?;
|
||||
|
||||
if let Some(watch_paths) = cli_options.watch_paths() {
|
||||
let _ = sender.send(watch_paths);
|
||||
}
|
||||
let _ = sender.send(cli_options.watch_paths());
|
||||
|
||||
let permissions = PermissionsContainer::new(Permissions::from_options(
|
||||
&cli_options.permissions_options(),
|
||||
|
|
|
@ -1726,12 +1726,15 @@ pub async fn run_tests_with_watch(
|
|||
}
|
||||
});
|
||||
|
||||
let clear_screen = !flags.no_clear_screen;
|
||||
file_watcher::watch_func(
|
||||
flags,
|
||||
file_watcher::PrintConfig {
|
||||
job_name: "Test".to_string(),
|
||||
clear_screen,
|
||||
clear_screen: !test_flags
|
||||
.watch
|
||||
.as_ref()
|
||||
.map(|w| !w.no_clear_screen)
|
||||
.unwrap_or(true),
|
||||
},
|
||||
move |flags, sender, changed_paths| {
|
||||
let test_flags = test_flags.clone();
|
||||
|
@ -1743,9 +1746,7 @@ pub async fn run_tests_with_watch(
|
|||
let cli_options = factory.cli_options();
|
||||
let test_options = cli_options.resolve_test_options(test_flags)?;
|
||||
|
||||
if let Some(watch_paths) = cli_options.watch_paths() {
|
||||
let _ = sender.send(watch_paths);
|
||||
}
|
||||
let _ = sender.send(cli_options.watch_paths());
|
||||
let _ = sender.send(test_options.files.include.clone());
|
||||
|
||||
let graph_kind = cli_options.type_check_mode().as_graph_kind();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue