1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-26 12:45:20 +03:00
aports/community/deno/upgrade-feature.patch
2023-11-17 01:28:04 +00:00

125 lines
4.4 KiB
Diff

Patch-Source: https://github.com/denoland/deno/pull/19910 (backported)
--
From 12dba658d8205e7d9dcb85817f8462a6bcff5c04 Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 22 Jul 2023 19:39:01 +0200
Subject: [PATCH] feat(cli): allow to build without upgrade feature
The self-upgrade feature is undesirable when deno is installed from
(Linux) distribution repository - using a system package manager.
This change will allow package maintainers to build deno with the
"upgrade" subcommand and background check disabled.
When the user runs `deno upgrade <args>` and the upgrade feature is
disabled, it will exit with error message explaining that this deno
binary was built without the upgrade feature.
Resolves #19909
---
cli/Cargo.toml | 6 +++++-
cli/args/flags.rs | 1 +
cli/main.rs | 22 ++++++++++++++++------
cli/tests/integration/flags_tests.rs | 1 +
cli/tools/run/mod.rs | 1 +
5 files changed, 24 insertions(+), 7 deletions(-)
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -27,6 +27,11 @@
path = "./bench/lsp_bench_standalone.rs"
[features]
+default = ["upgrade"]
+# A feature that enables the upgrade subcommand and the background check for
+# available updates (of deno binary). This is typically disabled for (Linux)
+# distribution packages.
+upgrade = []
# A dev feature to disable creations and loading of snapshots in favor of
# loading JS sources at runtime.
__runtime_js_sources = ["deno_runtime/__runtime_js_sources"]
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 235743bda2509..d537cf9979861 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -2204,6 +2204,7 @@ update to a different location, use the --output flag
deno upgrade --output $HOME/my_deno",
)
+ .hide(cfg!(not(feature = "upgrade")))
.defer(|cmd| {
cmd
.arg(
diff --git a/cli/main.rs b/cli/main.rs
index 6c5a78e617391..35e331cd0fb4d 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -198,9 +198,15 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
let types = tsc::get_types_declaration_file_text(flags.unstable);
display::write_to_stdout_ignore_sigpipe(types.as_bytes())
}),
+ #[cfg(feature = "upgrade")]
DenoSubcommand::Upgrade(upgrade_flags) => spawn_subcommand(async {
tools::upgrade::upgrade(flags, upgrade_flags).await
}),
+ #[cfg(not(feature = "upgrade"))]
+ DenoSubcommand::Upgrade(_) => exit_with_message(
+ "This deno was built without the \"upgrade\" feature",
+ 1,
+ ),
DenoSubcommand::Vendor(vendor_flags) => spawn_subcommand(async {
tools::vendor::vendor(flags, vendor_flags).await
}),
@@ -233,6 +239,15 @@ fn setup_panic_hook() {
}));
}
+fn exit_with_message(message: &str, code: i32) -> ! {
+ eprintln!(
+ "{}: {}",
+ colors::red_bold("error"),
+ message.trim_start_matches("error: ")
+ );
+ std::process::exit(code);
+}
+
fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
match result {
Ok(value) => value,
@@ -247,12 +262,7 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
error_code = 10;
}
- eprintln!(
- "{}: {}",
- colors::red_bold("error"),
- error_string.trim_start_matches("error: ")
- );
- std::process::exit(error_code);
+ exit_with_message(&error_string, error_code);
}
}
}
diff --git a/cli/tests/integration/flags_tests.rs b/cli/tests/integration/flags_tests.rs
index 695283aca2ba3..ab6b517e4d8d8 100644
--- a/cli/tests/integration/flags_tests.rs
+++ b/cli/tests/integration/flags_tests.rs
@@ -50,6 +50,7 @@ fn help_output() {
"Run a task defined in the configuration file",
"Run tests",
"Print runtime TypeScript declarations",
+ #[cfg(feature = "upgrade")]
"Upgrade deno executable to given version",
"Vendor remote modules into a local directory",
"Print this message or the help of the given subcommand(s)",
diff --git a/cli/tools/run/mod.rs b/cli/tools/run/mod.rs
index 119129b1bab55..743fe64cad6a8 100644
--- a/cli/tools/run/mod.rs
+++ b/cli/tools/run/mod.rs
@@ -47,6 +47,7 @@ To grant permissions, set them before the script argument. For example:
// Run a background task that checks for available upgrades. If an earlier
// run of this background task found a new version of Deno.
+ #[cfg(feature = "upgrade")]
super::upgrade::check_for_upgrades(
http_client.clone(),
deno_dir.upgrade_check_file_path(),