1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(deno install): Strip "@..." suffixes from inferred names (#7223)

This commit is contained in:
Nayeem Rahman 2020-08-27 21:55:58 +01:00 committed by GitHub
parent beec3ae096
commit 3d23208019
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View file

@ -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

View file

@ -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]

View file

@ -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`: