diff options
Diffstat (limited to 'cli/tools/installer.rs')
-rw-r--r-- | cli/tools/installer.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index d1754562a..68810272e 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -135,7 +135,17 @@ pub fn infer_name_from_url(url: &Url) -> Option<String> { stem = parent_name.to_string_lossy().to_string(); } } - let stem = stem.split_once('@').map_or(&*stem, |x| x.0).to_string(); + + // if atmark symbol appears in the index other than 0 (e.g. `foo@bar`) we use + // the former part as the inferred name because the latter part is most likely + // a version number. + match stem.find('@') { + Some(at_index) if at_index > 0 => { + stem = stem.split_at(at_index).0.to_string(); + } + _ => {} + } + Some(stem) } @@ -479,6 +489,24 @@ mod tests { ), Some("abc".to_string()) ); + assert_eq!( + infer_name_from_url(&Url::parse("https://example.com/@abc.ts").unwrap()), + Some("@abc".to_string()) + ); + assert_eq!( + infer_name_from_url( + &Url::parse("https://example.com/@abc/mod.ts").unwrap() + ), + Some("@abc".to_string()) + ); + assert_eq!( + infer_name_from_url(&Url::parse("file:///@abc.ts").unwrap()), + Some("@abc".to_string()) + ); + assert_eq!( + infer_name_from_url(&Url::parse("file:///@abc/cli.ts").unwrap()), + Some("@abc".to_string()) + ); } #[test] |