diff options
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, |