1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05: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:
David Sherret 2023-06-15 13:09:37 -04:00 committed by Bartek Iwańczuk
parent f5b9af7cd7
commit 7c3a641dae
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
10 changed files with 248 additions and 120 deletions

View file

@ -38,12 +38,14 @@ pub struct BenchFlags {
pub filter: Option<String>, pub filter: Option<String>,
pub json: bool, pub json: bool,
pub no_run: bool, pub no_run: bool,
pub watch: Option<WatchFlags>,
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct BundleFlags { pub struct BundleFlags {
pub source_file: String, pub source_file: String,
pub out_file: Option<PathBuf>, pub out_file: Option<PathBuf>,
pub watch: Option<WatchFlags>,
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -115,6 +117,7 @@ pub struct FmtFlags {
pub single_quote: Option<bool>, pub single_quote: Option<bool>,
pub prose_wrap: Option<String>, pub prose_wrap: Option<String>,
pub no_semicolons: Option<bool>, pub no_semicolons: Option<bool>,
pub watch: Option<WatchFlags>,
} }
impl FmtFlags { impl FmtFlags {
@ -159,6 +162,7 @@ pub struct LintFlags {
pub maybe_rules_exclude: Option<Vec<String>>, pub maybe_rules_exclude: Option<Vec<String>>,
pub json: bool, pub json: bool,
pub compact: bool, pub compact: bool,
pub watch: Option<WatchFlags>,
} }
impl LintFlags { impl LintFlags {
@ -178,6 +182,7 @@ pub struct ReplFlags {
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct RunFlags { pub struct RunFlags {
pub script: String, pub script: String,
pub watch: Option<WatchFlagsWithPaths>,
} }
impl RunFlags { impl RunFlags {
@ -186,6 +191,17 @@ impl RunFlags {
} }
} }
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct WatchFlags {
pub no_clear_screen: bool,
}
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct WatchFlagsWithPaths {
pub paths: Vec<PathBuf>,
pub no_clear_screen: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct TaskFlags { pub struct TaskFlags {
pub cwd: Option<String>, pub cwd: Option<String>,
@ -196,6 +212,7 @@ pub struct TaskFlags {
pub struct TestFlags { pub struct TestFlags {
pub doc: bool, pub doc: bool,
pub no_run: bool, pub no_run: bool,
pub coverage_dir: Option<String>,
pub fail_fast: Option<NonZeroUsize>, pub fail_fast: Option<NonZeroUsize>,
pub files: FileFlags, pub files: FileFlags,
pub allow_none: bool, pub allow_none: bool,
@ -203,6 +220,7 @@ pub struct TestFlags {
pub shuffle: Option<u64>, pub shuffle: Option<u64>,
pub concurrent_jobs: Option<NonZeroUsize>, pub concurrent_jobs: Option<NonZeroUsize>,
pub trace_ops: bool, pub trace_ops: bool,
pub watch: Option<WatchFlags>,
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -343,7 +361,6 @@ pub struct Flags {
pub type_check_mode: TypeCheckMode, pub type_check_mode: TypeCheckMode,
pub config_flag: ConfigFlag, pub config_flag: ConfigFlag,
pub node_modules_dir: Option<bool>, pub node_modules_dir: Option<bool>,
pub coverage_dir: Option<String>,
pub enable_testing_features: bool, pub enable_testing_features: bool,
pub ext: Option<String>, pub ext: Option<String>,
pub ignore: Vec<PathBuf>, pub ignore: Vec<PathBuf>,
@ -364,9 +381,6 @@ pub struct Flags {
pub unstable: bool, pub unstable: bool,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub v8_flags: Vec<String>, pub v8_flags: Vec<String>,
pub version: bool,
pub watch: Option<Vec<PathBuf>>,
pub no_clear_screen: bool,
} }
fn join_paths(allowlist: &[PathBuf], d: &str) -> String { fn join_paths(allowlist: &[PathBuf], d: &str) -> String {
@ -497,7 +511,7 @@ impl Flags {
match &self.subcommand { match &self.subcommand {
Fmt(FmtFlags { files, .. }) => Some(files.include.clone()), Fmt(FmtFlags { files, .. }) => Some(files.include.clone()),
Lint(LintFlags { files, .. }) => Some(files.include.clone()), Lint(LintFlags { files, .. }) => Some(files.include.clone()),
Run(RunFlags { script }) => { Run(RunFlags { script, .. }) => {
if let Ok(module_specifier) = resolve_url_or_path(script, current_dir) { if let Ok(module_specifier) = resolve_url_or_path(script, current_dir) {
if module_specifier.scheme() == "file" if module_specifier.scheme() == "file"
|| module_specifier.scheme() == "npm" || module_specifier.scheme() == "npm"
@ -539,7 +553,7 @@ impl Flags {
use DenoSubcommand::*; use DenoSubcommand::*;
match &self.subcommand { match &self.subcommand {
Run(RunFlags { script }) => { Run(RunFlags { script, .. }) => {
let module_specifier = resolve_url_or_path(script, current_dir).ok()?; let module_specifier = resolve_url_or_path(script, current_dir).ok()?;
if module_specifier.scheme() == "file" { if module_specifier.scheme() == "file" {
let p = module_specifier let p = module_specifier
@ -2544,12 +2558,12 @@ fn bench_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let no_run = matches.get_flag("no-run"); let no_run = matches.get_flag("no-run");
watch_arg_parse(flags, matches, false);
flags.subcommand = DenoSubcommand::Bench(BenchFlags { flags.subcommand = DenoSubcommand::Bench(BenchFlags {
files: FileFlags { include, ignore }, files: FileFlags { include, ignore },
filter, filter,
json, json,
no_run, no_run,
watch: watch_arg_parse(matches),
}); });
} }
@ -2568,12 +2582,12 @@ fn bundle_parse(flags: &mut Flags, matches: &mut ArgMatches) {
None None
}; };
watch_arg_parse(flags, matches, false);
ext_arg_parse(flags, matches); ext_arg_parse(flags, matches);
flags.subcommand = DenoSubcommand::Bundle(BundleFlags { flags.subcommand = DenoSubcommand::Bundle(BundleFlags {
source_file, source_file,
out_file, out_file,
watch: watch_arg_parse(matches),
}); });
} }
@ -2743,7 +2757,6 @@ fn eval_parse(flags: &mut Flags, matches: &mut ArgMatches) {
fn fmt_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn fmt_parse(flags: &mut Flags, matches: &mut ArgMatches) {
config_args_parse(flags, matches); config_args_parse(flags, matches);
watch_arg_parse(flags, matches, false);
ext_arg_parse(flags, matches); ext_arg_parse(flags, matches);
let include = match matches.remove_many::<PathBuf>("files") { let include = match matches.remove_many::<PathBuf>("files") {
@ -2771,6 +2784,7 @@ fn fmt_parse(flags: &mut Flags, matches: &mut ArgMatches) {
single_quote, single_quote,
prose_wrap, prose_wrap,
no_semicolons, no_semicolons,
watch: watch_arg_parse(matches),
}); });
} }
@ -2832,7 +2846,6 @@ fn lsp_parse(flags: &mut Flags, _matches: &mut ArgMatches) {
fn lint_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn lint_parse(flags: &mut Flags, matches: &mut ArgMatches) {
config_args_parse(flags, matches); config_args_parse(flags, matches);
watch_arg_parse(flags, matches, false);
let files = match matches.remove_many::<PathBuf>("files") { let files = match matches.remove_many::<PathBuf>("files") {
Some(f) => f.collect(), Some(f) => f.collect(),
None => vec![], None => vec![],
@ -2865,9 +2878,9 @@ fn lint_parse(flags: &mut Flags, matches: &mut ArgMatches) {
maybe_rules_tags, maybe_rules_tags,
maybe_rules_include, maybe_rules_include,
maybe_rules_exclude, maybe_rules_exclude,
json, json,
compact, compact,
watch: watch_arg_parse(matches),
}); });
} }
@ -2899,8 +2912,10 @@ fn run_parse(flags: &mut Flags, matches: &mut ArgMatches) {
ext_arg_parse(flags, matches); ext_arg_parse(flags, matches);
watch_arg_parse(flags, matches, true); flags.subcommand = DenoSubcommand::Run(RunFlags {
flags.subcommand = DenoSubcommand::Run(RunFlags { script }); script,
watch: watch_arg_parse_with_paths(matches),
});
} }
fn task_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn task_parse(flags: &mut Flags, matches: &mut ArgMatches) {
@ -3001,11 +3016,10 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) {
Vec::new() Vec::new()
}; };
flags.coverage_dir = matches.remove_one::<String>("coverage");
watch_arg_parse(flags, matches, false);
flags.subcommand = DenoSubcommand::Test(TestFlags { flags.subcommand = DenoSubcommand::Test(TestFlags {
no_run, no_run,
doc, doc,
coverage_dir: matches.remove_one::<String>("coverage"),
fail_fast, fail_fast,
files: FileFlags { include, ignore }, files: FileFlags { include, ignore },
filter, filter,
@ -3013,6 +3027,7 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) {
allow_none, allow_none,
concurrent_jobs, concurrent_jobs,
trace_ops, trace_ops,
watch: watch_arg_parse(matches),
}); });
} }
@ -3336,22 +3351,25 @@ fn reload_arg_validate(urlstr: &str) -> Result<String, String> {
} }
} }
fn watch_arg_parse( fn watch_arg_parse(matches: &mut ArgMatches) -> Option<WatchFlags> {
flags: &mut Flags, if matches.get_flag("watch") {
matches: &mut ArgMatches, Some(WatchFlags {
allow_extra: bool, no_clear_screen: matches.get_flag("no-clear-screen"),
) { })
if allow_extra { } else {
if let Some(f) = matches.remove_many::<PathBuf>("watch") { None
flags.watch = Some(f.collect());
}
} else if matches.get_flag("watch") {
flags.watch = Some(vec![]);
} }
}
if matches.get_flag("no-clear-screen") { fn watch_arg_parse_with_paths(
flags.no_clear_screen = true; matches: &mut ArgMatches,
} ) -> Option<WatchFlagsWithPaths> {
matches
.remove_many::<PathBuf>("watch")
.map(|f| WatchFlagsWithPaths {
paths: f.collect(),
no_clear_screen: matches.get_flag("no-clear-screen"),
})
} }
// TODO(ry) move this to utility module and add test. // TODO(ry) move this to utility module and add test.
@ -3394,6 +3412,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
unstable: true, unstable: true,
log_level: Some(Level::Error), log_level: Some(Level::Error),
@ -3448,6 +3467,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
reload: true, reload: true,
..Flags::default() ..Flags::default()
@ -3464,8 +3484,11 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Some(WatchFlagsWithPaths {
paths: vec![],
no_clear_screen: false,
}),
}), }),
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -3481,8 +3504,11 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Some(WatchFlagsWithPaths {
paths: vec![PathBuf::from("file1"), PathBuf::from("file2")],
no_clear_screen: false,
}),
}), }),
watch: Some(vec![PathBuf::from("file1"), PathBuf::from("file2")]),
..Flags::default() ..Flags::default()
} }
); );
@ -3504,9 +3530,11 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Some(WatchFlagsWithPaths {
paths: vec![],
no_clear_screen: true,
})
}), }),
watch: Some(vec![]),
no_clear_screen: true,
..Flags::default() ..Flags::default()
} }
); );
@ -3522,6 +3550,7 @@ mod tests {
reload: true, reload: true,
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_write: Some(vec![]), allow_write: Some(vec![]),
..Flags::default() ..Flags::default()
@ -3537,6 +3566,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "_".to_string(), script: "_".to_string(),
watch: Default::default(),
}), }),
v8_flags: svec!["--help"], v8_flags: svec!["--help"],
..Flags::default() ..Flags::default()
@ -3554,6 +3584,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
v8_flags: svec!["--expose-gc", "--gc-stats=1"], v8_flags: svec!["--expose-gc", "--gc-stats=1"],
..Flags::default() ..Flags::default()
@ -3594,6 +3625,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "gist.ts".to_string(), script: "gist.ts".to_string(),
watch: Default::default(),
}), }),
argv: svec!["--title", "X"], argv: svec!["--title", "X"],
allow_net: Some(vec![]), allow_net: Some(vec![]),
@ -3610,6 +3642,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "gist.ts".to_string(), script: "gist.ts".to_string(),
watch: Default::default(),
}), }),
allow_all: true, allow_all: true,
allow_net: Some(vec![]), allow_net: Some(vec![]),
@ -3633,6 +3666,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "gist.ts".to_string(), script: "gist.ts".to_string(),
watch: Default::default(),
}), }),
allow_read: Some(vec![]), allow_read: Some(vec![]),
..Flags::default() ..Flags::default()
@ -3648,6 +3682,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "gist.ts".to_string(), script: "gist.ts".to_string(),
watch: Default::default(),
}), }),
allow_hrtime: true, allow_hrtime: true,
..Flags::default() ..Flags::default()
@ -3674,6 +3709,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
argv: svec!["--", "-D", "--allow-net"], argv: svec!["--", "-D", "--allow-net"],
allow_write: Some(vec![]), allow_write: Some(vec![]),
@ -3703,6 +3739,7 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Default::default(),
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
..Flags::default() ..Flags::default()
@ -3725,6 +3762,7 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Default::default(),
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
..Flags::default() ..Flags::default()
@ -3747,6 +3785,7 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Default::default(),
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
..Flags::default() ..Flags::default()
@ -3769,9 +3808,11 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Some(WatchFlags {
no_clear_screen: false,
})
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -3793,10 +3834,11 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Some(WatchFlags {
no_clear_screen: true,
})
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
watch: Some(vec![]),
no_clear_screen: true,
..Flags::default() ..Flags::default()
} }
); );
@ -3824,9 +3866,11 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Some(WatchFlags {
no_clear_screen: false,
})
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -3847,6 +3891,7 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Default::default(),
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()), config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
@ -3877,10 +3922,12 @@ mod tests {
single_quote: None, single_quote: None,
prose_wrap: None, prose_wrap: None,
no_semicolons: None, no_semicolons: None,
watch: Some(WatchFlags {
no_clear_screen: false,
})
}), }),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()), config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -3913,6 +3960,7 @@ mod tests {
single_quote: Some(true), single_quote: Some(true),
prose_wrap: Some("never".to_string()), prose_wrap: Some("never".to_string()),
no_semicolons: Some(true), no_semicolons: Some(true),
watch: Default::default(),
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
..Flags::default() ..Flags::default()
@ -3942,6 +3990,7 @@ mod tests {
single_quote: Some(false), single_quote: Some(false),
prose_wrap: None, prose_wrap: None,
no_semicolons: Some(false), no_semicolons: Some(false),
watch: Default::default(),
}), }),
ext: Some("ts".to_string()), ext: Some("ts".to_string()),
..Flags::default() ..Flags::default()
@ -3969,6 +4018,7 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: false, json: false,
compact: false, compact: false,
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -3998,8 +4048,10 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: false, json: false,
compact: false, compact: false,
watch: Some(WatchFlags {
no_clear_screen: false,
})
}), }),
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -4029,9 +4081,10 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: false, json: false,
compact: false, compact: false,
watch: Some(WatchFlags {
no_clear_screen: true,
})
}), }),
watch: Some(vec![]),
no_clear_screen: true,
..Flags::default() ..Flags::default()
} }
); );
@ -4055,6 +4108,7 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: false, json: false,
compact: false, compact: false,
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -4075,6 +4129,7 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: false, json: false,
compact: false, compact: false,
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -4101,6 +4156,7 @@ mod tests {
maybe_rules_exclude: Some(svec!["no-const-assign"]), maybe_rules_exclude: Some(svec!["no-const-assign"]),
json: false, json: false,
compact: false, compact: false,
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -4121,6 +4177,7 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: true, json: true,
compact: false, compact: false,
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -4148,6 +4205,7 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: true, json: true,
compact: false, compact: false,
watch: Default::default(),
}), }),
config_flag: ConfigFlag::Path("Deno.jsonc".to_string()), config_flag: ConfigFlag::Path("Deno.jsonc".to_string()),
..Flags::default() ..Flags::default()
@ -4176,6 +4234,7 @@ mod tests {
maybe_rules_exclude: None, maybe_rules_exclude: None,
json: false, json: false,
compact: true, compact: true,
watch: Default::default(),
}), }),
config_flag: ConfigFlag::Path("Deno.jsonc".to_string()), config_flag: ConfigFlag::Path("Deno.jsonc".to_string()),
..Flags::default() ..Flags::default()
@ -4345,6 +4404,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
config_flag: ConfigFlag::Path("tsconfig.json".to_owned()), config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
..Flags::default() ..Flags::default()
@ -4614,6 +4674,7 @@ mod tests {
allow_read: Some(vec![PathBuf::from("."), temp_dir]), allow_read: Some(vec![PathBuf::from("."), temp_dir]),
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -4638,6 +4699,7 @@ mod tests {
allow_write: Some(vec![PathBuf::from("."), temp_dir]), allow_write: Some(vec![PathBuf::from("."), temp_dir]),
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
..Flags::default() ..Flags::default()
} }
@ -4657,6 +4719,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_net: Some(svec!["127.0.0.1"]), allow_net: Some(svec!["127.0.0.1"]),
..Flags::default() ..Flags::default()
@ -4673,6 +4736,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_env: Some(svec!["HOME"]), allow_env: Some(svec!["HOME"]),
..Flags::default() ..Flags::default()
@ -4693,6 +4757,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_env: Some(svec!["HOME", "PATH"]), allow_env: Some(svec!["HOME", "PATH"]),
..Flags::default() ..Flags::default()
@ -4721,6 +4786,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_sys: Some(vec![]), allow_sys: Some(vec![]),
..Flags::default() ..Flags::default()
@ -4737,6 +4803,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_sys: Some(svec!["hostname"]), allow_sys: Some(svec!["hostname"]),
..Flags::default() ..Flags::default()
@ -4757,6 +4824,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_sys: Some(svec!["hostname", "osRelease"]), allow_sys: Some(svec!["hostname", "osRelease"]),
..Flags::default() ..Flags::default()
@ -4869,6 +4937,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: None, out_file: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
..Flags::default() ..Flags::default()
@ -4893,6 +4962,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: Some(PathBuf::from("bundle.js")), out_file: Some(PathBuf::from("bundle.js")),
watch: Default::default(),
}), }),
allow_write: Some(vec![]), allow_write: Some(vec![]),
no_remote: true, no_remote: true,
@ -4912,6 +4982,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: Some(PathBuf::from("bundle.js")), out_file: Some(PathBuf::from("bundle.js")),
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
allow_write: Some(vec![]), allow_write: Some(vec![]),
@ -4935,6 +5006,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: None, out_file: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
lock_write: true, lock_write: true,
@ -4954,6 +5026,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: None, out_file: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
..Flags::default() ..Flags::default()
@ -4971,6 +5044,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "script.ts".to_string(), source_file: "script.ts".to_string(),
out_file: None, out_file: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::None, type_check_mode: TypeCheckMode::None,
..Flags::default() ..Flags::default()
@ -4987,9 +5061,11 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: None, out_file: None,
watch: Some(WatchFlags {
no_clear_screen: false,
}),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
) )
@ -5010,10 +5086,11 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: None, out_file: None,
watch: Some(WatchFlags {
no_clear_screen: true,
}),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
watch: Some(vec![]),
no_clear_screen: true,
..Flags::default() ..Flags::default()
} }
) )
@ -5032,6 +5109,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
import_map_path: Some("import_map.json".to_owned()), import_map_path: Some("import_map.json".to_owned()),
..Flags::default() ..Flags::default()
@ -5126,6 +5204,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
seed: Some(250_u64), seed: Some(250_u64),
v8_flags: svec!["--random-seed=250"], v8_flags: svec!["--random-seed=250"],
@ -5149,6 +5228,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
seed: Some(250_u64), seed: Some(250_u64),
v8_flags: svec!["--expose-gc", "--random-seed=250"], v8_flags: svec!["--expose-gc", "--random-seed=250"],
@ -5243,6 +5323,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
log_level: Some(Level::Debug), log_level: Some(Level::Debug),
..Flags::default() ..Flags::default()
@ -5258,6 +5339,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
log_level: Some(Level::Error), log_level: Some(Level::Error),
..Flags::default() ..Flags::default()
@ -5291,6 +5373,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
argv: svec!["--allow-read", "--allow-net"], argv: svec!["--allow-read", "--allow-net"],
..Flags::default() ..Flags::default()
@ -5314,6 +5397,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
location: Some(Url::parse("https://foo/").unwrap()), location: Some(Url::parse("https://foo/").unwrap()),
allow_read: Some(vec![]), allow_read: Some(vec![]),
@ -5328,6 +5412,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
argv: svec!["foo", "bar"], argv: svec!["foo", "bar"],
..Flags::default() ..Flags::default()
@ -5339,6 +5424,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
argv: svec!["-"], argv: svec!["-"],
..Flags::default() ..Flags::default()
@ -5352,6 +5438,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
argv: svec!["-", "foo", "bar"], argv: svec!["-", "foo", "bar"],
..Flags::default() ..Flags::default()
@ -5367,6 +5454,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::None, type_check_mode: TypeCheckMode::None,
..Flags::default() ..Flags::default()
@ -5383,6 +5471,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
..Flags::default() ..Flags::default()
@ -5427,6 +5516,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
unsafely_ignore_certificate_errors: Some(vec![]), unsafely_ignore_certificate_errors: Some(vec![]),
..Flags::default() ..Flags::default()
@ -5447,6 +5537,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
unsafely_ignore_certificate_errors: Some(svec![ unsafely_ignore_certificate_errors: Some(svec![
"deno.land", "deno.land",
@ -5497,6 +5588,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
no_remote: true, no_remote: true,
..Flags::default() ..Flags::default()
@ -5512,6 +5604,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
no_npm: true, no_npm: true,
..Flags::default() ..Flags::default()
@ -5528,6 +5621,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
node_modules_dir: Some(true), node_modules_dir: Some(true),
..Flags::default() ..Flags::default()
@ -5545,6 +5639,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
node_modules_dir: Some(false), node_modules_dir: Some(false),
..Flags::default() ..Flags::default()
@ -5560,6 +5655,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
cached_only: true, cached_only: true,
..Flags::default() ..Flags::default()
@ -5580,6 +5676,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_net: Some(svec![ allow_net: Some(svec![
"deno.land", "deno.land",
@ -5608,6 +5705,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
allow_net: Some(svec![ allow_net: Some(svec![
"deno.land", "deno.land",
@ -5640,6 +5738,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
lock_write: true, lock_write: true,
lock: Some(PathBuf::from("lock.json")), lock: Some(PathBuf::from("lock.json")),
@ -5653,6 +5752,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
no_lock: true, no_lock: true,
..Flags::default() ..Flags::default()
@ -5671,6 +5771,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
lock_write: true, lock_write: true,
lock: Some(PathBuf::from("./deno.lock")), lock: Some(PathBuf::from("./deno.lock")),
@ -5691,6 +5792,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
lock_write: true, lock_write: true,
lock: Some(PathBuf::from("lock.json")), lock: Some(PathBuf::from("lock.json")),
@ -5704,6 +5806,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
lock_write: true, lock_write: true,
..Flags::default() ..Flags::default()
@ -5761,12 +5864,13 @@ mod tests {
shuffle: None, shuffle: None,
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: true, trace_ops: true,
coverage_dir: Some("cov".to_string()),
watch: Default::default(),
}), }),
unstable: true, unstable: true,
no_prompt: true, no_prompt: true,
no_npm: true, no_npm: true,
no_remote: true, no_remote: true,
coverage_dir: Some("cov".to_string()),
location: Some(Url::parse("https://foo/").unwrap()), location: Some(Url::parse("https://foo/").unwrap()),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
allow_net: Some(vec![]), allow_net: Some(vec![]),
@ -5790,6 +5894,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
ca_data: Some(CaData::File("example.crt".to_owned())), ca_data: Some(CaData::File("example.crt".to_owned())),
..Flags::default() ..Flags::default()
@ -5810,6 +5915,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
enable_testing_features: true, enable_testing_features: true,
..Flags::default() ..Flags::default()
@ -5836,6 +5942,8 @@ mod tests {
}, },
concurrent_jobs: Some(NonZeroUsize::new(4).unwrap()), concurrent_jobs: Some(NonZeroUsize::new(4).unwrap()),
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
no_prompt: true, no_prompt: true,
@ -5866,6 +5974,8 @@ mod tests {
}, },
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
no_prompt: true, no_prompt: true,
@ -5900,6 +6010,8 @@ mod tests {
}, },
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Default::default(),
}), }),
no_prompt: true, no_prompt: true,
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
@ -5928,9 +6040,10 @@ mod tests {
}, },
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Default::default(),
}), }),
no_prompt: true, no_prompt: true,
watch: None,
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
..Flags::default() ..Flags::default()
} }
@ -5956,10 +6069,13 @@ mod tests {
}, },
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Some(WatchFlags {
no_clear_screen: false,
}),
}), }),
no_prompt: true, no_prompt: true,
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -5983,10 +6099,13 @@ mod tests {
}, },
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Some(WatchFlags {
no_clear_screen: false,
}),
}), }),
no_prompt: true, no_prompt: true,
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -6012,10 +6131,12 @@ mod tests {
}, },
concurrent_jobs: None, concurrent_jobs: None,
trace_ops: false, trace_ops: false,
coverage_dir: None,
watch: Some(WatchFlags {
no_clear_screen: true,
}),
}), }),
watch: Some(vec![]),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
no_clear_screen: true,
no_prompt: true, no_prompt: true,
..Flags::default() ..Flags::default()
} }
@ -6037,6 +6158,7 @@ mod tests {
subcommand: DenoSubcommand::Bundle(BundleFlags { subcommand: DenoSubcommand::Bundle(BundleFlags {
source_file: "source.ts".to_string(), source_file: "source.ts".to_string(),
out_file: None, out_file: None,
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
ca_data: Some(CaData::File("example.crt".to_owned())), ca_data: Some(CaData::File("example.crt".to_owned())),
@ -6203,6 +6325,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "foo.js".to_string(), script: "foo.js".to_string(),
watch: Default::default(),
}), }),
inspect: Some("127.0.0.1:9229".parse().unwrap()), inspect: Some("127.0.0.1:9229".parse().unwrap()),
..Flags::default() ..Flags::default()
@ -6218,6 +6341,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "foo.js".to_string(), script: "foo.js".to_string(),
watch: Default::default(),
}), }),
inspect_wait: Some("127.0.0.1:9229".parse().unwrap()), inspect_wait: Some("127.0.0.1:9229".parse().unwrap()),
..Flags::default() ..Flags::default()
@ -6235,6 +6359,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "foo.js".to_string(), script: "foo.js".to_string(),
watch: Default::default(),
}), }),
inspect_wait: Some("127.0.0.1:3567".parse().unwrap()), inspect_wait: Some("127.0.0.1:3567".parse().unwrap()),
..Flags::default() ..Flags::default()
@ -6684,6 +6809,7 @@ mod tests {
include: vec![PathBuf::from("dir1/"), PathBuf::from("dir2/")], include: vec![PathBuf::from("dir1/"), PathBuf::from("dir2/")],
ignore: vec![], ignore: vec![],
}, },
watch: Default::default(),
}), }),
unstable: true, unstable: true,
no_npm: true, no_npm: true,
@ -6712,10 +6838,12 @@ mod tests {
include: vec![], include: vec![],
ignore: vec![], ignore: vec![],
}, },
watch: Some(WatchFlags {
no_clear_screen: false,
}),
}), }),
no_prompt: true, no_prompt: true,
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
watch: Some(vec![]),
..Flags::default() ..Flags::default()
} }
); );
@ -6729,6 +6857,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
..Flags::default() ..Flags::default()
@ -6741,6 +6870,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::All, type_check_mode: TypeCheckMode::All,
..Flags::default() ..Flags::default()
@ -6753,6 +6883,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
type_check_mode: TypeCheckMode::None, type_check_mode: TypeCheckMode::None,
..Flags::default() ..Flags::default()
@ -6777,6 +6908,7 @@ mod tests {
Flags { Flags {
subcommand: DenoSubcommand::Run(RunFlags { subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(), script: "script.ts".to_string(),
watch: Default::default(),
}), }),
config_flag: ConfigFlag::Disabled, config_flag: ConfigFlag::Disabled,
..Flags::default() ..Flags::default()

View file

@ -757,7 +757,7 @@ impl CliOptions {
resolve_url_or_path("./$deno$stdin.ts", &cwd) resolve_url_or_path("./$deno$stdin.ts", &cwd)
.map_err(AnyError::from) .map_err(AnyError::from)
}) })
} else if self.flags.watch.is_some() { } else if run_flags.watch.is_some() {
resolve_url_or_path(&run_flags.script, self.initial_cwd()) resolve_url_or_path(&run_flags.script, self.initial_cwd())
.map_err(AnyError::from) .map_err(AnyError::from)
} else if NpmPackageReqReference::from_str(&run_flags.script).is_ok() { } else if NpmPackageReqReference::from_str(&run_flags.script).is_ok() {
@ -1023,23 +1023,13 @@ impl CliOptions {
} }
pub fn coverage_dir(&self) -> Option<String> { pub fn coverage_dir(&self) -> Option<String> {
fn allow_coverage(sub_command: &DenoSubcommand) -> bool { match &self.flags.subcommand {
match sub_command { DenoSubcommand::Test(test) => test
DenoSubcommand::Test(_) => true,
DenoSubcommand::Run(flags) => !flags.is_stdin(),
_ => false,
}
}
if allow_coverage(self.sub_command()) {
self
.flags
.coverage_dir .coverage_dir
.as_ref() .as_ref()
.map(ToOwned::to_owned) .map(ToOwned::to_owned)
.or_else(|| env::var("DENO_UNSTABLE_COVERAGE_DIR").ok()) .or_else(|| env::var("DENO_UNSTABLE_COVERAGE_DIR").ok()),
} else { _ => None,
None
} }
} }
@ -1139,25 +1129,30 @@ impl CliOptions {
&self.flags.v8_flags &self.flags.v8_flags
} }
pub fn watch_paths(&self) -> Option<Vec<PathBuf>> { pub fn watch_paths(&self) -> Vec<PathBuf> {
if let Some(mut paths) = self.flags.watch.clone() { let mut paths = if let DenoSubcommand::Run(RunFlags {
if let Ok(Some(import_map_path)) = self watch: Some(WatchFlagsWithPaths { paths, .. }),
.resolve_import_map_specifier() ..
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok())) }) = &self.flags.subcommand
{ {
paths.push(import_map_path); paths.clone()
} } else {
if let Some(specifier) = self.maybe_config_file_specifier() { Vec::with_capacity(2)
if specifier.scheme() == "file" { };
if let Ok(path) = specifier.to_file_path() { if let Ok(Some(import_map_path)) = self
paths.push(path); .resolve_import_map_specifier()
} .map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
{
paths.push(import_map_path);
}
if let Some(specifier) = self.maybe_config_file_specifier() {
if specifier.scheme() == "file" {
if let Ok(path) = specifier.to_file_path() {
paths.push(path);
} }
} }
Some(paths)
} else {
None
} }
paths
} }
} }

View file

@ -82,7 +82,7 @@ fn spawn_subcommand<F: Future<Output = T> + 'static, T: SubcommandOutput>(
async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> { async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
let handle = match flags.subcommand.clone() { let handle = match flags.subcommand.clone() {
DenoSubcommand::Bench(bench_flags) => spawn_subcommand(async { DenoSubcommand::Bench(bench_flags) => spawn_subcommand(async {
if flags.watch.is_some() { if bench_flags.watch.is_some() {
tools::bench::run_benchmarks_with_watch(flags, bench_flags).await tools::bench::run_benchmarks_with_watch(flags, bench_flags).await
} else { } else {
tools::bench::run_benchmarks(flags, bench_flags).await tools::bench::run_benchmarks(flags, bench_flags).await
@ -153,7 +153,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
if run_flags.is_stdin() { if run_flags.is_stdin() {
tools::run::run_from_stdin(flags).await tools::run::run_from_stdin(flags).await
} else { } else {
tools::run::run_script(flags).await tools::run::run_script(flags, run_flags).await
} }
}), }),
DenoSubcommand::Task(task_flags) => spawn_subcommand(async { DenoSubcommand::Task(task_flags) => spawn_subcommand(async {
@ -161,7 +161,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
}), }),
DenoSubcommand::Test(test_flags) => { DenoSubcommand::Test(test_flags) => {
spawn_subcommand(async { spawn_subcommand(async {
if let Some(ref coverage_dir) = flags.coverage_dir { if let Some(ref coverage_dir) = test_flags.coverage_dir {
std::fs::create_dir_all(coverage_dir) std::fs::create_dir_all(coverage_dir)
.with_context(|| format!("Failed creating: {coverage_dir}"))?; .with_context(|| format!("Failed creating: {coverage_dir}"))?;
// this is set in order to ensure spawned processes use the same // this is set in order to ensure spawned processes use the same
@ -172,7 +172,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
); );
} }
if flags.watch.is_some() { if test_flags.watch.is_some() {
tools::test::run_tests_with_watch(flags, test_flags).await tools::test::run_tests_with_watch(flags, test_flags).await
} else { } else {
tools::test::run_tests(flags, test_flags).await tools::test::run_tests(flags, test_flags).await

View file

@ -385,6 +385,7 @@ async fn fmt_watch_test() {
wait_contains("Checked", &mut stderr_lines).await, wait_contains("Checked", &mut stderr_lines).await,
"Checked 1 file" "Checked 1 file"
); );
wait_contains("Fmt finished", &mut stderr_lines).await;
let expected = std::fs::read_to_string(fixed.clone()).unwrap(); let expected = std::fs::read_to_string(fixed.clone()).unwrap();
let actual = std::fs::read_to_string(badly_formatted.clone()).unwrap(); let actual = std::fs::read_to_string(badly_formatted.clone()).unwrap();
@ -401,6 +402,7 @@ async fn fmt_watch_test() {
wait_contains("Checked", &mut stderr_lines).await, wait_contains("Checked", &mut stderr_lines).await,
"Checked 1 file" "Checked 1 file"
); );
wait_contains("Fmt finished", &mut stderr_lines).await;
// Check if file has been automatically formatted by watcher // Check if file has been automatically formatted by watcher
let expected = std::fs::read_to_string(fixed).unwrap(); let expected = std::fs::read_to_string(fixed).unwrap();

View file

@ -684,12 +684,15 @@ pub async fn run_benchmarks_with_watch(
flags: Flags, flags: Flags,
bench_flags: BenchFlags, bench_flags: BenchFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let clear_screen = !flags.no_clear_screen;
file_watcher::watch_func( file_watcher::watch_func(
flags, flags,
file_watcher::PrintConfig { file_watcher::PrintConfig {
job_name: "Bench".to_string(), 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| { move |flags, sender, changed_paths| {
let bench_flags = bench_flags.clone(); let bench_flags = bench_flags.clone();
@ -701,9 +704,7 @@ pub async fn run_benchmarks_with_watch(
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let bench_options = cli_options.resolve_bench_options(bench_flags)?; let bench_options = cli_options.resolve_bench_options(bench_flags)?;
if let Some(watch_paths) = cli_options.watch_paths() { let _ = sender.send(cli_options.watch_paths());
let _ = sender.send(watch_paths);
}
let _ = sender.send(bench_options.files.include.clone()); let _ = sender.send(bench_options.files.include.clone());
let graph_kind = cli_options.type_check_mode().as_graph_kind(); let graph_kind = cli_options.type_check_mode().as_graph_kind();

View file

@ -28,13 +28,12 @@ pub async fn bundle(
"Use alternative bundlers like \"deno_emit\", \"esbuild\" or \"rollup\" instead." "Use alternative bundlers like \"deno_emit\", \"esbuild\" or \"rollup\" instead."
); );
if flags.watch.is_some() { if let Some(watch_flags) = &bundle_flags.watch {
let clear_screen = !flags.no_clear_screen;
util::file_watcher::watch_func( util::file_watcher::watch_func(
flags, flags,
util::file_watcher::PrintConfig { util::file_watcher::PrintConfig {
job_name: "Bundle".to_string(), job_name: "Bundle".to_string(),
clear_screen, clear_screen: !watch_flags.no_clear_screen,
}, },
move |flags, sender, _changed_paths| { move |flags, sender, _changed_paths| {
let bundle_flags = bundle_flags.clone(); let bundle_flags = bundle_flags.clone();
@ -44,11 +43,7 @@ pub async fn bundle(
.build_from_flags(flags) .build_from_flags(flags)
.await?; .await?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let _ = sender.send(cli_options.watch_paths());
if let Some(watch_paths) = cli_options.watch_paths() {
let _ = sender.send(watch_paths);
}
bundle_action(factory, &bundle_flags).await?; bundle_action(factory, &bundle_flags).await?;
Ok(()) Ok(())

View file

@ -61,13 +61,12 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> {
); );
} }
if flags.watch.is_some() { if let Some(watch_flags) = &fmt_flags.watch {
let clear_screen = !flags.no_clear_screen;
file_watcher::watch_func( file_watcher::watch_func(
flags, flags,
file_watcher::PrintConfig { file_watcher::PrintConfig {
job_name: "Fmt".to_string(), job_name: "Fmt".to_string(),
clear_screen, clear_screen: !watch_flags.no_clear_screen,
}, },
move |flags, sender, changed_paths| { move |flags, sender, changed_paths| {
let fmt_flags = fmt_flags.clone(); let fmt_flags = fmt_flags.clone();

View file

@ -51,18 +51,17 @@ fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> {
} }
pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { 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() { if lint_flags.is_stdin() {
return Err(generic_error( return Err(generic_error(
"Lint watch on standard input is not supported.", "Lint watch on standard input is not supported.",
)); ));
} }
let clear_screen = !flags.no_clear_screen;
file_watcher::watch_func( file_watcher::watch_func(
flags, flags,
file_watcher::PrintConfig { file_watcher::PrintConfig {
job_name: "Lint".to_string(), job_name: "Lint".to_string(),
clear_screen, clear_screen: !watch_flags.no_clear_screen,
}, },
move |flags, sender, changed_paths| { move |flags, sender, changed_paths| {
let lint_flags = lint_flags.clone(); let lint_flags = lint_flags.clone();

View file

@ -9,12 +9,17 @@ use deno_runtime::permissions::PermissionsContainer;
use crate::args::EvalFlags; use crate::args::EvalFlags;
use crate::args::Flags; use crate::args::Flags;
use crate::args::RunFlags;
use crate::args::WatchFlagsWithPaths;
use crate::factory::CliFactory; use crate::factory::CliFactory;
use crate::factory::CliFactoryBuilder; use crate::factory::CliFactoryBuilder;
use crate::file_fetcher::File; use crate::file_fetcher::File;
use crate::util; 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() { if !flags.has_permission() && flags.has_permission_in_argv() {
log::warn!( log::warn!(
"{}", "{}",
@ -26,8 +31,8 @@ To grant permissions, set them before the script argument. For example:
); );
} }
if flags.watch.is_some() { if let Some(watch_flags) = run_flags.watch {
return run_with_watch(flags).await; return run_with_watch(flags, watch_flags).await;
} }
// TODO(bartlomieju): actually I think it will also fail if there's an import // 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 // TODO(bartlomieju): this function is not handling `exit_code` set by the runtime
// code properly. // code properly.
async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> { async fn run_with_watch(
let clear_screen = !flags.no_clear_screen; flags: Flags,
watch_flags: WatchFlagsWithPaths,
) -> Result<i32, AnyError> {
util::file_watcher::watch_func( util::file_watcher::watch_func(
flags, flags,
util::file_watcher::PrintConfig { util::file_watcher::PrintConfig {
job_name: "Process".to_string(), job_name: "Process".to_string(),
clear_screen, clear_screen: !watch_flags.no_clear_screen,
}, },
move |flags, sender, _changed_paths| { move |flags, sender, _changed_paths| {
Ok(async move { Ok(async move {
@ -116,9 +122,7 @@ async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
maybe_npm_install(&factory).await?; maybe_npm_install(&factory).await?;
if let Some(watch_paths) = cli_options.watch_paths() { let _ = sender.send(cli_options.watch_paths());
let _ = sender.send(watch_paths);
}
let permissions = PermissionsContainer::new(Permissions::from_options( let permissions = PermissionsContainer::new(Permissions::from_options(
&cli_options.permissions_options(), &cli_options.permissions_options(),

View file

@ -1726,12 +1726,15 @@ pub async fn run_tests_with_watch(
} }
}); });
let clear_screen = !flags.no_clear_screen;
file_watcher::watch_func( file_watcher::watch_func(
flags, flags,
file_watcher::PrintConfig { file_watcher::PrintConfig {
job_name: "Test".to_string(), 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| { move |flags, sender, changed_paths| {
let test_flags = test_flags.clone(); let test_flags = test_flags.clone();
@ -1743,9 +1746,7 @@ pub async fn run_tests_with_watch(
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let test_options = cli_options.resolve_test_options(test_flags)?; let test_options = cli_options.resolve_test_options(test_flags)?;
if let Some(watch_paths) = cli_options.watch_paths() { let _ = sender.send(cli_options.watch_paths());
let _ = sender.send(watch_paths);
}
let _ = sender.send(test_options.files.include.clone()); let _ = sender.send(test_options.files.include.clone());
let graph_kind = cli_options.type_check_mode().as_graph_kind(); let graph_kind = cli_options.type_check_mode().as_graph_kind();