diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-13 13:50:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 18:50:23 +0100 |
commit | e8f22c076525c2fa55115349157f67085df287bf (patch) | |
tree | df4105ee11bd69a4de1a138a26d6b44bca131ea1 /core/module_specifier.rs | |
parent | 4c2aeb250241fff5084cf31747ab53f4a0ecad79 (diff) |
refactor(core): pass cwd explicitly to resolve_path (#18092)
Towards landing #15454
Diffstat (limited to 'core/module_specifier.rs')
-rw-r--r-- | core/module_specifier.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/module_specifier.rs b/core/module_specifier.rs index c65f34110..72d693723 100644 --- a/core/module_specifier.rs +++ b/core/module_specifier.rs @@ -4,6 +4,7 @@ use crate::normalize_path; use std::env::current_dir; use std::error::Error; use std::fmt; +use std::path::Path; use std::path::PathBuf; use url::ParseError; use url::Url; @@ -128,7 +129,9 @@ pub fn resolve_url_or_path( if specifier_has_uri_scheme(specifier) { resolve_url(specifier) } else { - resolve_path(specifier) + let cwd = current_dir() + .map_err(|_| ModuleResolutionError::InvalidPath(specifier.into()))?; + resolve_path(specifier, &cwd) } } @@ -137,10 +140,9 @@ pub fn resolve_url_or_path( /// working directory. pub fn resolve_path( path_str: &str, + current_dir: &Path, ) -> Result<ModuleSpecifier, ModuleResolutionError> { - let path = current_dir() - .map_err(|_| ModuleResolutionError::InvalidPath(path_str.into()))? - .join(path_str); + let path = current_dir.join(path_str); let path = normalize_path(path); Url::from_file_path(&path) .map_err(|()| ModuleResolutionError::InvalidPath(path)) |