summaryrefslogtreecommitdiff
path: root/cli/tools/upgrade.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-02-13 21:52:30 +0530
committerGitHub <noreply@github.com>2024-02-13 21:52:30 +0530
commita68eb3fcc3997fce8680f87edce46f6450e79635 (patch)
tree6839607033226fdfb2ce1be3187ef93791096507 /cli/tools/upgrade.rs
parent492a9fbb9194a24a1f9223f797b4f4df9efde2bd (diff)
feat: denort binary for `deno compile` (#22205)
This introduces the `denort` binary - a slim version of deno without tooling. The binary is used as the default for `deno compile`. Improves `deno compile` final size by ~2.5x (141 MB -> 61 MB) on Linux x86_64.
Diffstat (limited to 'cli/tools/upgrade.rs')
-rw-r--r--cli/tools/upgrade.rs80
1 files changed, 11 insertions, 69 deletions
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index 70141f571..efe7e707e 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -7,6 +7,7 @@ use crate::args::UpgradeFlags;
use crate::colors;
use crate::factory::CliFactory;
use crate::http_util::HttpClient;
+use crate::standalone::binary::unpack_into_dir;
use crate::util::progress_bar::ProgressBar;
use crate::util::progress_bar::ProgressBarStyle;
use crate::util::time;
@@ -30,11 +31,11 @@ use std::process::Command;
use std::sync::Arc;
use std::time::Duration;
-static ARCHIVE_NAME: Lazy<String> =
- Lazy::new(|| format!("deno-{}.zip", env!("TARGET")));
-
const RELEASE_URL: &str = "https://github.com/denoland/deno/releases";
+pub static ARCHIVE_NAME: Lazy<String> =
+ Lazy::new(|| format!("deno-{}.zip", env!("TARGET")));
+
// How often query server for new version. In hours.
const UPGRADE_CHECK_INTERVAL: i64 = 24;
@@ -501,7 +502,13 @@ pub async fn upgrade(
log::info!("Deno is upgrading to version {}", &install_version);
let temp_dir = tempfile::TempDir::new()?;
- let new_exe_path = unpack_into_dir(archive_data, cfg!(windows), &temp_dir)?;
+ let new_exe_path = unpack_into_dir(
+ "deno",
+ &ARCHIVE_NAME,
+ archive_data,
+ cfg!(windows),
+ &temp_dir,
+ )?;
fs::set_permissions(&new_exe_path, permissions)?;
check_exe(&new_exe_path)?;
@@ -628,71 +635,6 @@ async fn download_package(
}
}
-pub fn unpack_into_dir(
- archive_data: Vec<u8>,
- is_windows: bool,
- temp_dir: &tempfile::TempDir,
-) -> Result<PathBuf, AnyError> {
- const EXE_NAME: &str = "deno";
- let temp_dir_path = temp_dir.path();
- let exe_ext = if is_windows { "exe" } else { "" };
- let archive_path = temp_dir_path.join(EXE_NAME).with_extension("zip");
- let exe_path = temp_dir_path.join(EXE_NAME).with_extension(exe_ext);
- assert!(!exe_path.exists());
-
- let archive_ext = Path::new(&*ARCHIVE_NAME)
- .extension()
- .and_then(|ext| ext.to_str())
- .unwrap();
- let unpack_status = match archive_ext {
- "zip" if cfg!(windows) => {
- fs::write(&archive_path, &archive_data)?;
- Command::new("tar.exe")
- .arg("xf")
- .arg(&archive_path)
- .arg("-C")
- .arg(temp_dir_path)
- .spawn()
- .map_err(|err| {
- if err.kind() == std::io::ErrorKind::NotFound {
- std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "`tar.exe` was not found in your PATH",
- )
- } else {
- err
- }
- })?
- .wait()?
- }
- "zip" => {
- fs::write(&archive_path, &archive_data)?;
- Command::new("unzip")
- .current_dir(temp_dir_path)
- .arg(&archive_path)
- .spawn()
- .map_err(|err| {
- if err.kind() == std::io::ErrorKind::NotFound {
- std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "`unzip` was not found in your PATH, please install `unzip`",
- )
- } else {
- err
- }
- })?
- .wait()?
- }
- ext => bail!("Unsupported archive type: '{ext}'"),
- };
- if !unpack_status.success() {
- bail!("Failed to unpack archive.");
- }
- assert!(exe_path.exists());
- fs::remove_file(&archive_path)?;
- Ok(exe_path)
-}
-
fn replace_exe(from: &Path, to: &Path) -> Result<(), std::io::Error> {
if cfg!(windows) {
// On windows you cannot replace the currently running executable.