diff options
author | Niclas Overby <niclas@overby.me> | 2021-05-13 23:56:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 23:56:30 +0200 |
commit | 608c7d68e26abbc685f97901e6bfa3be910eec10 (patch) | |
tree | 6af4d268c7e7fd94d47a0a1fb7498527de41e6c3 /cli/config_file.rs | |
parent | 62c752211c982ee6eb297cf49a076464471407f7 (diff) |
fix(lsp): remove duplicate cwd in config path (#10620)
Diffstat (limited to 'cli/config_file.rs')
-rw-r--r-- | cli/config_file.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/cli/config_file.rs b/cli/config_file.rs index fcc702ad5..41d9bbbec 100644 --- a/cli/config_file.rs +++ b/cli/config_file.rs @@ -270,9 +270,14 @@ pub struct ConfigFile { } impl ConfigFile { - pub fn read(path: &str) -> Result<Self, AnyError> { - let cwd = std::env::current_dir()?; - let config_file = cwd.join(path); + pub fn read(path_str: &str) -> Result<Self, AnyError> { + let path = Path::new(path_str); + let config_file = if path.is_absolute() { + path.to_path_buf() + } else { + std::env::current_dir()?.join(path_str) + }; + let config_path = canonicalize_path(&config_file).map_err(|_| { std::io::Error::new( std::io::ErrorKind::InvalidInput, @@ -318,13 +323,23 @@ mod tests { use deno_core::serde_json::json; #[test] - fn read_config_file() { + fn read_config_file_relative() { let config_file = ConfigFile::read("tests/module_graph/tsconfig.json") .expect("Failed to load config file"); assert!(config_file.json.compiler_options.is_some()); } #[test] + fn read_config_file_absolute() { + let path = std::env::current_dir() + .unwrap() + .join("tests/module_graph/tsconfig.json"); + let config_file = ConfigFile::read(path.to_str().unwrap()) + .expect("Failed to load config file"); + assert!(config_file.json.compiler_options.is_some()); + } + + #[test] fn test_json_merge() { let mut value_a = json!({ "a": true, |