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

fix(install): recommend using deno install -g when using a single http url (#25388)

Closes https://github.com/denoland/deno/issues/25361
This commit is contained in:
Bartek Iwańczuk 2024-09-03 16:55:29 +01:00 committed by GitHub
parent 203428ea14
commit 81e941bc92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 1 deletions

View file

@ -237,7 +237,6 @@ pub struct InstallFlagsGlobal {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InstallKind {
#[allow(unused)]
Local(Option<AddFlags>),
Global(InstallFlagsGlobal),
}

View file

@ -15,6 +15,7 @@ use crate::factory::CliFactory;
use crate::http_util::HttpClientProvider;
use crate::util::fs::canonicalize_path_maybe_not_exists;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
@ -284,6 +285,24 @@ async fn install_local(
Ok(())
}
fn check_if_installs_a_single_package_globally(
maybe_add_flags: Option<&AddFlags>,
) -> Result<(), AnyError> {
let Some(add_flags) = maybe_add_flags else {
return Ok(());
};
if add_flags.packages.len() != 1 {
return Ok(());
}
let Ok(url) = Url::parse(&add_flags.packages[0]) else {
return Ok(());
};
if matches!(url.scheme(), "http" | "https") {
bail!("Failed to install \"{}\" specifier. If you are trying to install {} globally, run again with `-g` flag:\n deno install -g {}", url.scheme(), url.as_str(), url.as_str());
}
Ok(())
}
pub async fn install_command(
flags: Arc<Flags>,
install_flags: InstallFlags,
@ -297,6 +316,7 @@ pub async fn install_command(
install_global(flags, global_flags).await
}
InstallKind::Local(maybe_add_flags) => {
check_if_installs_a_single_package_globally(maybe_add_flags.as_ref())?;
install_local(flags, maybe_add_flags).await
}
}

View file

@ -0,0 +1,14 @@
{
"steps": [
{
"args": "install http://example.com",
"output": "install_http.out",
"exitCode": 1
},
{
"args": "install https://example.com",
"output": "install_https.out",
"exitCode": 1
}
]
}

View file

@ -0,0 +1,2 @@
error: Failed to install "http" specifier. If you are trying to install http://example.com/ globally, run again with `-g` flag:
deno install -g http://example.com/

View file

@ -0,0 +1,2 @@
error: Failed to install "https" specifier. If you are trying to install https://example.com/ globally, run again with `-g` flag:
deno install -g https://example.com/