From 6cc27ec5b236056ce41354d17b154cc5609d874f Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Sun, 10 Aug 2025 00:35:13 +0400 Subject: [PATCH] chore: linting --- src/bundler.rs | 9 ++-- src/executable.rs | 8 ++- src/node_downloader.rs | 8 ++- tests/local_link_integration_test.rs | 77 +++++++++++++++++++++------- 4 files changed, 69 insertions(+), 33 deletions(-) diff --git a/src/bundler.rs b/src/bundler.rs index 9266f89..866d4a2 100644 --- a/src/bundler.rs +++ b/src/bundler.rs @@ -76,11 +76,10 @@ pub async fn bundle_project( ProgressStyle::with_template("{prefix:.bold.dim} {spinner:.green} {wide_msg}") .unwrap() .tick_chars("/|\\- "); - let bar_style = ProgressStyle::with_template( - "{prefix:.bold.dim} {msg}[ {wide_bar} ] {pos}/{len}", - ) - .unwrap() - .progress_chars("#>-"); + let bar_style = + ProgressStyle::with_template("{prefix:.bold.dim} {msg}[ {wide_bar} ] {pos}/{len}") + .unwrap() + .progress_chars("#>-"); let emoji_prepare = Emoji("🔧", ""); let emoji_bundle = Emoji("📦", ""); diff --git a/src/executable.rs b/src/executable.rs index 8fc70bb..a325f8c 100644 --- a/src/executable.rs +++ b/src/executable.rs @@ -135,11 +135,9 @@ fn build_executable_with_progress( if let Some(pb) = progress { if known_total > 0 { pb.set_style( - ProgressStyle::with_template( - "[ {wide_bar} ] {pos}/{len}", - ) - .unwrap() - .progress_chars("#>-"), + ProgressStyle::with_template("[ {wide_bar} ] {pos}/{len}") + .unwrap() + .progress_chars("#>-"), ); pb.set_length(known_total); pb.set_position(0); diff --git a/src/node_downloader.rs b/src/node_downloader.rs index 036d113..2d2ea8e 100644 --- a/src/node_downloader.rs +++ b/src/node_downloader.rs @@ -205,11 +205,9 @@ impl NodeDownloader { // Extract the archive with determinate progress if let Some(pb) = progress { pb.set_style( - ProgressStyle::with_template( - "[ {wide_bar} ] {pos}/{len}", - ) - .unwrap() - .progress_chars("#>-"), + ProgressStyle::with_template("[ {wide_bar} ] {pos}/{len}") + .unwrap() + .progress_chars("#>-"), ); pb.set_length(0); pb.set_position(0); diff --git a/tests/local_link_integration_test.rs b/tests/local_link_integration_test.rs index 75a1c97..bdc83fd 100644 --- a/tests/local_link_integration_test.rs +++ b/tests/local_link_integration_test.rs @@ -26,10 +26,9 @@ fn write_app_with_dep(app_dir: &Path, dep_spec: &str) { "version": "1.0.0", "main": "index.js", "dependencies": {{ - "test_local_dep": "{}" + "test_local_dep": "{dep_spec}" }} -}}"#, - dep_spec +}}"# ); let index_js = r#"const test_local_dep = require('test_local_dep'); console.log('Hello from app'); @@ -40,7 +39,9 @@ process.exit(0);"#; } fn copy_dir_recursive(src: &Path, dst: &Path) -> std::io::Result<()> { - if dst.exists() { let _ = fs::remove_dir_all(dst); } + if dst.exists() { + let _ = fs::remove_dir_all(dst); + } fs::create_dir_all(dst)?; for entry in walkdir::WalkDir::new(src) { let entry = entry.unwrap(); @@ -50,7 +51,9 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> std::io::Result<()> { if entry.file_type().is_dir() { fs::create_dir_all(&target)?; } else if entry.file_type().is_file() { - if let Some(parent) = target.parent() { fs::create_dir_all(parent)?; } + if let Some(parent) = target.parent() { + fs::create_dir_all(parent)?; + } fs::copy(path, &target)?; } } @@ -60,16 +63,26 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> std::io::Result<()> { #[cfg(unix)] fn make_symlink(target: &Path, link: &Path) -> std::io::Result<()> { use std::os::unix::fs as unix_fs; - if link.exists() { let _ = fs::remove_file(link); let _ = fs::remove_dir_all(link); } - if let Some(parent) = link.parent() { fs::create_dir_all(parent)?; } + if link.exists() { + let _ = fs::remove_file(link); + let _ = fs::remove_dir_all(link); + } + if let Some(parent) = link.parent() { + fs::create_dir_all(parent)?; + } unix_fs::symlink(target, link) } #[cfg(windows)] fn make_symlink(target: &Path, link: &Path) -> std::io::Result<()> { // Best-effort: try directory junction; fall back to copy if it fails - if link.exists() { let _ = fs::remove_file(link); let _ = fs::remove_dir_all(link); } - if let Some(parent) = link.parent() { fs::create_dir_all(parent)?; } + if link.exists() { + let _ = fs::remove_file(link); + let _ = fs::remove_dir_all(link); + } + if let Some(parent) = link.parent() { + fs::create_dir_all(parent)?; + } std::os::windows::fs::symlink_dir(target, link).or_else(|_| copy_dir_recursive(target, link)) } @@ -100,28 +113,52 @@ fn bundle_app(app_dir: &Path, out_dir: &Path, name: &str) -> PathBuf { }; if !path.exists() { let out = Command::new("cargo").args(["build"]).output().unwrap(); - assert!(out.status.success(), "Failed to build banderole: {}", String::from_utf8_lossy(&out.stderr)); + assert!( + out.status.success(), + "Failed to build banderole: {}", + String::from_utf8_lossy(&out.stderr) + ); } path }; let output = Command::new(&bundler) - .args(["bundle", app_dir.to_str().unwrap(), "--no-compression", "--name", name]) + .args([ + "bundle", + app_dir.to_str().unwrap(), + "--no-compression", + "--name", + name, + ]) .current_dir(out_dir) .output() .unwrap(); - assert!(output.status.success(), "Bundle failed: {}", String::from_utf8_lossy(&output.stderr)); + assert!( + output.status.success(), + "Bundle failed: {}", + String::from_utf8_lossy(&output.stderr) + ); - let exe = out_dir.join(if cfg!(windows) { format!("{}.exe", name) } else { name.to_string() }); - if exe.exists() && exe.is_file() { exe } else { out_dir.join(if cfg!(windows) { format!("{}-bundle.exe", name) } else { format!("{}-bundle", name) }) } + let exe = out_dir.join(if cfg!(windows) { + format!("{name}.exe") + } else { + name.to_string() + }); + if exe.exists() && exe.is_file() { + exe + } else { + out_dir.join(if cfg!(windows) { + format!("{name}-bundle.exe") + } else { + format!("{name}-bundle") + }) + } } fn copy_exe_to_fresh_dir(exe: &Path) -> PathBuf { let run_dir = TempDir::new().unwrap(); - let dst = run_dir - .path() - .join(exe.file_name().unwrap_or_default()); + let dst = run_dir.path().join(exe.file_name().unwrap_or_default()); fs::copy(exe, &dst).unwrap(); // Keep dir alive by leaking TempDir, test process will clean temp space later Box::leak(Box::new(run_dir)); @@ -138,7 +175,11 @@ fn run_and_assert(exe: &Path) { } let out = Command::new(exe).output().unwrap(); let stdout = String::from_utf8_lossy(&out.stdout); - assert!(out.status.success(), "Executable failed: {}", String::from_utf8_lossy(&out.stderr)); + assert!( + out.status.success(), + "Executable failed: {}", + String::from_utf8_lossy(&out.stderr) + ); assert!(stdout.contains("Hello from app")); assert!(stdout.contains("test_local_dep: test_local_dep says hi")); }