diff options
-rw-r--r-- | cli/flags.rs | 1 | ||||
-rw-r--r-- | cli/installer.rs | 29 | ||||
-rw-r--r-- | docs/tools/script_installer.md | 1 |
3 files changed, 25 insertions, 6 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 8c2400057..cba41db57 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -757,6 +757,7 @@ The executable name is inferred by default: - If the file stem is something generic like 'main', 'mod', 'index' or 'cli', and the path has no parent, take the file name of the parent path. Otherwise settle with the generic name. + - If the resulting name has an '@...' suffix, strip it. To change the installation root, use --root: deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts diff --git a/cli/installer.rs b/cli/installer.rs index 6d498a16c..2f8b2c18d 100644 --- a/cli/installer.rs +++ b/cli/installer.rs @@ -114,17 +114,16 @@ fn get_installer_root() -> Result<PathBuf, Error> { fn infer_name_from_url(url: &Url) -> Option<String> { let path = PathBuf::from(url.path()); - let stem = match path.file_stem() { + let mut stem = match path.file_stem() { Some(stem) => stem.to_string_lossy().to_string(), None => return None, }; - if let Some(parent_path) = path.parent() { - if stem == "main" || stem == "mod" || stem == "index" || stem == "cli" { - if let Some(parent_name) = parent_path.file_name() { - return Some(parent_name.to_string_lossy().to_string()); - } + if stem == "main" || stem == "mod" || stem == "index" || stem == "cli" { + if let Some(parent_name) = path.parent().and_then(|p| p.file_name()) { + stem = parent_name.to_string_lossy().to_string(); } } + let stem = stem.splitn(2, '@').next().unwrap().to_string(); Some(stem) } @@ -349,6 +348,24 @@ mod tests { Some("main".to_string()) ); assert_eq!(infer_name_from_url(&Url::parse("file:///").unwrap()), None); + assert_eq!( + infer_name_from_url( + &Url::parse("https://example.com/abc@0.1.0").unwrap() + ), + Some("abc".to_string()) + ); + assert_eq!( + infer_name_from_url( + &Url::parse("https://example.com/abc@0.1.0/main.ts").unwrap() + ), + Some("abc".to_string()) + ); + assert_eq!( + infer_name_from_url( + &Url::parse("https://example.com/abc@def@ghi").unwrap() + ), + Some("abc".to_string()) + ); } #[test] diff --git a/docs/tools/script_installer.md b/docs/tools/script_installer.md index e588a39d6..a5f37659c 100644 --- a/docs/tools/script_installer.md +++ b/docs/tools/script_installer.md @@ -32,6 +32,7 @@ The executable name is inferred by default: - If the file stem is something generic like 'main', 'mod', 'index' or 'cli', and the path has no parent, take the file name of the parent path. Otherwise settle with the generic name. +- If the resulting name has an '@...' suffix, strip it. To change the installation root, use `--root`: |