diff options
Diffstat (limited to 'cli/config_file.rs')
-rw-r--r-- | cli/config_file.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/cli/config_file.rs b/cli/config_file.rs index ba1d427a1..3644bb7c1 100644 --- a/cli/config_file.rs +++ b/cli/config_file.rs @@ -1,5 +1,7 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use crate::flags::ConfigFlag; +use crate::flags::Flags; use crate::fs_util::canonicalize_path; use crate::fs_util::specifier_parent; use crate::fs_util::specifier_to_file_path; @@ -161,21 +163,25 @@ pub const IGNORED_RUNTIME_COMPILER_OPTIONS: &[&str] = &[ /// Filenames that Deno will recognize when discovering config. const CONFIG_FILE_NAMES: [&str; 2] = ["deno.json", "deno.jsonc"]; -pub fn discover(flags: &crate::Flags) -> Result<Option<ConfigFile>, AnyError> { - if let Some(config_path) = flags.config_path.as_ref() { - Ok(Some(ConfigFile::read(config_path)?)) - } else if let Some(config_path_args) = flags.config_path_args() { - let mut checked = HashSet::new(); - for f in config_path_args { - if let Some(cf) = discover_from(&f, &mut checked)? { - return Ok(Some(cf)); +pub fn discover(flags: &Flags) -> Result<Option<ConfigFile>, AnyError> { + match &flags.config_flag { + ConfigFlag::Disabled => Ok(None), + ConfigFlag::Path(config_path) => Ok(Some(ConfigFile::read(config_path)?)), + ConfigFlag::Discover => { + if let Some(config_path_args) = flags.config_path_args() { + let mut checked = HashSet::new(); + for f in config_path_args { + if let Some(cf) = discover_from(&f, &mut checked)? { + return Ok(Some(cf)); + } + } + // From CWD walk up to root looking for deno.json or deno.jsonc + let cwd = std::env::current_dir()?; + discover_from(&cwd, &mut checked) + } else { + Ok(None) } } - // From CWD walk up to root looking for deno.json or deno.jsonc - let cwd = std::env::current_dir()?; - discover_from(&cwd, &mut checked) - } else { - Ok(None) } } |