diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-04-27 10:05:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 10:05:20 -0400 |
commit | 742cc3111ccb7c3c12c1b05904be052094657481 (patch) | |
tree | 56910a8843fbc666b719b61e772bfa51dbfd750e /cli/args/mod.rs | |
parent | 03132e19da6c8e34e8100c6a57cd911b43900950 (diff) |
refactor(cli): extract out ProcState from CliMainWorker (#18867)
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 93 |
1 files changed, 55 insertions, 38 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index f83b33936..440403f62 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -817,30 +817,6 @@ impl CliOptions { ) } - /// Resolves the storage key to use based on the current flags, config, or main module. - pub fn resolve_storage_key( - &self, - main_module: &ModuleSpecifier, - ) -> Option<String> { - if let Some(location) = &self.flags.location { - // if a location is set, then the ascii serialization of the location is - // used, unless the origin is opaque, and then no storage origin is set, as - // we can't expect the origin to be reproducible - let storage_origin = location.origin(); - if storage_origin.is_tuple() { - Some(storage_origin.ascii_serialization()) - } else { - None - } - } else if let Some(config_file) = &self.maybe_config_file { - // otherwise we will use the path to the config file - Some(config_file.specifier.to_string()) - } else { - // otherwise we will use the path to the main module - Some(main_module.to_string()) - } - } - pub fn resolve_inspector_server(&self) -> Option<InspectorServer> { let maybe_inspect_host = self .flags @@ -1089,20 +1065,6 @@ impl CliOptions { &self.flags.subcommand } - pub fn trace_ops(&self) -> bool { - match self.sub_command() { - DenoSubcommand::Test(flags) => flags.trace_ops, - _ => false, - } - } - - pub fn shuffle_tests(&self) -> Option<u64> { - match self.sub_command() { - DenoSubcommand::Test(flags) => flags.shuffle, - _ => None, - } - } - pub fn type_check_mode(&self) -> TypeCheckMode { self.flags.type_check_mode } @@ -1216,6 +1178,44 @@ fn resolve_import_map_specifier( Ok(None) } +pub struct StorageKeyResolver(Option<Option<String>>); + +impl StorageKeyResolver { + pub fn from_options(options: &CliOptions) -> Self { + Self(if let Some(location) = &options.flags.location { + // if a location is set, then the ascii serialization of the location is + // used, unless the origin is opaque, and then no storage origin is set, as + // we can't expect the origin to be reproducible + let storage_origin = location.origin(); + if storage_origin.is_tuple() { + Some(Some(storage_origin.ascii_serialization())) + } else { + Some(None) + } + } else { + // otherwise we will use the path to the config file or None to + // fall back to using the main module's path + options + .maybe_config_file + .as_ref() + .map(|config_file| Some(config_file.specifier.to_string())) + }) + } + + /// Resolves the storage key to use based on the current flags, config, or main module. + pub fn resolve_storage_key( + &self, + main_module: &ModuleSpecifier, + ) -> Option<String> { + // use the stored value or fall back to using the path of the main module. + if let Some(maybe_value) = &self.0 { + maybe_value.clone() + } else { + Some(main_module.to_string()) + } + } +} + /// Collect included and ignored files. CLI flags take precedence /// over config file, i.e. if there's `files.ignore` in config file /// and `--ignore` CLI flag, only the flag value is taken into account. @@ -1381,4 +1381,21 @@ mod test { let actual = actual.unwrap(); assert_eq!(actual, None); } + + #[test] + fn storage_key_resolver_test() { + let resolver = StorageKeyResolver(None); + let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap(); + assert_eq!( + resolver.resolve_storage_key(&specifier), + Some(specifier.to_string()) + ); + let resolver = StorageKeyResolver(Some(None)); + assert_eq!(resolver.resolve_storage_key(&specifier), None); + let resolver = StorageKeyResolver(Some(Some("value".to_string()))); + assert_eq!( + resolver.resolve_storage_key(&specifier), + Some("value".to_string()) + ); + } } |