mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
build(cli): allow to build without upgrade feature (#19910)
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. Note: This patch is already used in the Alpine Linux’s [deno](https://pkgs.alpinelinux.org/packages?name=deno) package.
This commit is contained in:
parent
9ac405d587
commit
ae327d0a83
5 changed files with 24 additions and 7 deletions
|
@ -27,7 +27,11 @@ harness = false
|
||||||
path = "./bench/lsp_bench_standalone.rs"
|
path = "./bench/lsp_bench_standalone.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["__vendored_zlib_ng"]
|
default = ["upgrade", "__vendored_zlib_ng"]
|
||||||
|
# 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
|
# A dev feature to disable creations and loading of snapshots in favor of
|
||||||
# loading JS sources at runtime.
|
# loading JS sources at runtime.
|
||||||
__runtime_js_sources = ["deno_runtime/__runtime_js_sources"]
|
__runtime_js_sources = ["deno_runtime/__runtime_js_sources"]
|
||||||
|
|
|
@ -2202,6 +2202,7 @@ update to a different location, use the --output flag
|
||||||
|
|
||||||
deno upgrade --output $HOME/my_deno",
|
deno upgrade --output $HOME/my_deno",
|
||||||
)
|
)
|
||||||
|
.hide(cfg!(not(feature = "upgrade")))
|
||||||
.defer(|cmd| {
|
.defer(|cmd| {
|
||||||
cmd
|
cmd
|
||||||
.arg(
|
.arg(
|
||||||
|
|
22
cli/main.rs
22
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);
|
let types = tsc::get_types_declaration_file_text(flags.unstable);
|
||||||
display::write_to_stdout_ignore_sigpipe(types.as_bytes())
|
display::write_to_stdout_ignore_sigpipe(types.as_bytes())
|
||||||
}),
|
}),
|
||||||
|
#[cfg(feature = "upgrade")]
|
||||||
DenoSubcommand::Upgrade(upgrade_flags) => spawn_subcommand(async {
|
DenoSubcommand::Upgrade(upgrade_flags) => spawn_subcommand(async {
|
||||||
tools::upgrade::upgrade(flags, upgrade_flags).await
|
tools::upgrade::upgrade(flags, upgrade_flags).await
|
||||||
}),
|
}),
|
||||||
|
#[cfg(not(feature = "upgrade"))]
|
||||||
|
DenoSubcommand::Upgrade(_) => exit_with_message(
|
||||||
|
"This deno was built without the \"upgrade\" feature. Please upgrade using the installation method originally used to install Deno.",
|
||||||
|
1,
|
||||||
|
),
|
||||||
DenoSubcommand::Vendor(vendor_flags) => spawn_subcommand(async {
|
DenoSubcommand::Vendor(vendor_flags) => spawn_subcommand(async {
|
||||||
tools::vendor::vendor(flags, vendor_flags).await
|
tools::vendor::vendor(flags, vendor_flags).await
|
||||||
}),
|
}),
|
||||||
|
@ -237,6 +243,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 {
|
fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
|
||||||
match result {
|
match result {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
|
@ -251,12 +266,7 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
|
||||||
error_code = 10;
|
error_code = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!(
|
exit_with_message(&error_string, error_code);
|
||||||
"{}: {}",
|
|
||||||
colors::red_bold("error"),
|
|
||||||
error_string.trim_start_matches("error: ")
|
|
||||||
);
|
|
||||||
std::process::exit(error_code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ fn help_output() {
|
||||||
"Run a task defined in the configuration file",
|
"Run a task defined in the configuration file",
|
||||||
"Run tests",
|
"Run tests",
|
||||||
"Print runtime TypeScript declarations",
|
"Print runtime TypeScript declarations",
|
||||||
|
#[cfg(feature = "upgrade")]
|
||||||
"Upgrade deno executable to given version",
|
"Upgrade deno executable to given version",
|
||||||
"Vendor remote modules into a local directory",
|
"Vendor remote modules into a local directory",
|
||||||
"Print this message or the help of the given subcommand(s)",
|
"Print this message or the help of the given subcommand(s)",
|
||||||
|
|
|
@ -47,6 +47,7 @@ To grant permissions, set them before the script argument. For example:
|
||||||
|
|
||||||
// Run a background task that checks for available upgrades or output
|
// Run a background task that checks for available upgrades or output
|
||||||
// if an earlier run of this background task found a new version of Deno.
|
// if an earlier run of this background task found a new version of Deno.
|
||||||
|
#[cfg(feature = "upgrade")]
|
||||||
super::upgrade::check_for_upgrades(
|
super::upgrade::check_for_upgrades(
|
||||||
http_client.clone(),
|
http_client.clone(),
|
||||||
deno_dir.upgrade_check_file_path(),
|
deno_dir.upgrade_check_file_path(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue