diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-09-03 16:55:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-03 17:55:29 +0200 |
commit | 81e941bc92aac37bbf2f385eeceec9e4c8cfb13d (patch) | |
tree | 7f15f9d3eab20ba95ab9ad69a1aa4dc57fb12ec8 /cli/tools/installer.rs | |
parent | 203428ea14d3630f537f0e05f15bb8d56474fe36 (diff) |
fix(install): recommend using `deno install -g` when using a single http url (#25388)
Closes https://github.com/denoland/deno/issues/25361
Diffstat (limited to 'cli/tools/installer.rs')
-rw-r--r-- | cli/tools/installer.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index c3f415dc7..6965d5c6d 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -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 } } |