diff options
Diffstat (limited to 'cli/tools/vendor/mappings.rs')
-rw-r--r-- | cli/tools/vendor/mappings.rs | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/cli/tools/vendor/mappings.rs b/cli/tools/vendor/mappings.rs index 2e85445dc..543536128 100644 --- a/cli/tools/vendor/mappings.rs +++ b/cli/tools/vendor/mappings.rs @@ -14,6 +14,7 @@ use deno_graph::Position; use deno_graph::Resolved; use crate::fs_util::path_with_stem_suffix; +use crate::fs_util::relative_specifier; use super::specifiers::dir_name_for_root; use super::specifiers::get_unique_path; @@ -28,7 +29,6 @@ pub struct ProxiedModule { /// Constructs and holds the remote specifier to local path mappings. pub struct Mappings { - output_dir: ModuleSpecifier, mappings: HashMap<ModuleSpecifier, PathBuf>, base_specifiers: Vec<ModuleSpecifier>, proxies: HashMap<ModuleSpecifier, ProxiedModule>, @@ -104,17 +104,12 @@ impl Mappings { } Ok(Self { - output_dir: ModuleSpecifier::from_directory_path(output_dir).unwrap(), mappings, base_specifiers, proxies, }) } - pub fn output_dir(&self) -> &ModuleSpecifier { - &self.output_dir - } - pub fn local_uri(&self, specifier: &ModuleSpecifier) -> ModuleSpecifier { if specifier.scheme() == "file" { specifier.clone() @@ -146,43 +141,14 @@ impl Mappings { } } - pub fn relative_path( - &self, - from: &ModuleSpecifier, - to: &ModuleSpecifier, - ) -> String { - let mut from = self.local_uri(from); - let to = self.local_uri(to); - - // workaround using parent directory until https://github.com/servo/rust-url/pull/754 is merged - if !from.path().ends_with('/') { - let local_path = self.local_path(&from); - from = ModuleSpecifier::from_directory_path(local_path.parent().unwrap()) - .unwrap(); - } - - // workaround for url crate not adding a trailing slash for a directory - // it seems to be fixed once a version greater than 2.2.2 is released - let is_dir = to.path().ends_with('/'); - let mut text = from.make_relative(&to).unwrap(); - if is_dir && !text.ends_with('/') && to.query().is_none() { - text.push('/'); - } - text - } - pub fn relative_specifier_text( &self, from: &ModuleSpecifier, to: &ModuleSpecifier, ) -> String { - let relative_path = self.relative_path(from, to); - - if relative_path.starts_with("../") || relative_path.starts_with("./") { - relative_path - } else { - format!("./{}", relative_path) - } + let from = self.local_uri(from); + let to = self.local_uri(to); + relative_specifier(&from, &to).unwrap() } pub fn base_specifiers(&self) -> &Vec<ModuleSpecifier> { |