mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
fix(deno install): Strip "@..." suffixes from inferred names (#7223)
This commit is contained in:
parent
beec3ae096
commit
3d23208019
3 changed files with 25 additions and 6 deletions
|
@ -757,6 +757,7 @@ The executable name is inferred by default:
|
||||||
- If the file stem is something generic like 'main', 'mod', 'index' or 'cli',
|
- 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
|
and the path has no parent, take the file name of the parent path. Otherwise
|
||||||
settle with the generic name.
|
settle with the generic name.
|
||||||
|
- If the resulting name has an '@...' suffix, strip it.
|
||||||
|
|
||||||
To change the installation root, use --root:
|
To change the installation root, use --root:
|
||||||
deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts
|
deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts
|
||||||
|
|
|
@ -114,17 +114,16 @@ fn get_installer_root() -> Result<PathBuf, Error> {
|
||||||
|
|
||||||
fn infer_name_from_url(url: &Url) -> Option<String> {
|
fn infer_name_from_url(url: &Url) -> Option<String> {
|
||||||
let path = PathBuf::from(url.path());
|
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(),
|
Some(stem) => stem.to_string_lossy().to_string(),
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
if let Some(parent_path) = path.parent() {
|
|
||||||
if stem == "main" || stem == "mod" || stem == "index" || stem == "cli" {
|
if stem == "main" || stem == "mod" || stem == "index" || stem == "cli" {
|
||||||
if let Some(parent_name) = parent_path.file_name() {
|
if let Some(parent_name) = path.parent().and_then(|p| p.file_name()) {
|
||||||
return Some(parent_name.to_string_lossy().to_string());
|
stem = parent_name.to_string_lossy().to_string();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let stem = stem.splitn(2, '@').next().unwrap().to_string();
|
||||||
Some(stem)
|
Some(stem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +348,24 @@ mod tests {
|
||||||
Some("main".to_string())
|
Some("main".to_string())
|
||||||
);
|
);
|
||||||
assert_eq!(infer_name_from_url(&Url::parse("file:///").unwrap()), None);
|
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]
|
#[test]
|
||||||
|
|
|
@ -32,6 +32,7 @@ The executable name is inferred by default:
|
||||||
- If the file stem is something generic like 'main', 'mod', 'index' or 'cli',
|
- 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
|
and the path has no parent, take the file name of the parent path. Otherwise
|
||||||
settle with the generic name.
|
settle with the generic name.
|
||||||
|
- If the resulting name has an '@...' suffix, strip it.
|
||||||
|
|
||||||
To change the installation root, use `--root`:
|
To change the installation root, use `--root`:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue