mirror of
https://github.com/zhom/banderole.git
synced 2026-06-08 07:23:53 +02:00
chore: linting
This commit is contained in:
+30
-32
@@ -49,9 +49,10 @@ pub async fn bundle_project(
|
||||
|
||||
let source_dir = determine_source_directory(&project_path, &package_value)?;
|
||||
|
||||
let node_version = detect_node_version_with_workspace_support(&project_path, ignore_cached_versions)
|
||||
.await
|
||||
.unwrap_or_else(|_| "22.17.1".into());
|
||||
let node_version =
|
||||
detect_node_version_with_workspace_support(&project_path, ignore_cached_versions)
|
||||
.await
|
||||
.unwrap_or_else(|_| "22.17.1".into());
|
||||
|
||||
println!(
|
||||
"Bundling {app_name} v{app_version} using Node.js v{node_version} for {plat}",
|
||||
@@ -120,7 +121,7 @@ where
|
||||
|
||||
if let Some(main) = package_value["main"].as_str() {
|
||||
let main_path = project_path.join(main);
|
||||
if let Ok(relative_to_source) = main_path.strip_prefix(&source_dir) {
|
||||
if let Ok(relative_to_source) = main_path.strip_prefix(source_dir) {
|
||||
package_value["main"] =
|
||||
Value::String(relative_to_source.to_string_lossy().to_string());
|
||||
}
|
||||
@@ -141,7 +142,7 @@ where
|
||||
}
|
||||
|
||||
for warning in &deps_result.warnings {
|
||||
println!("Warning: {}", warning);
|
||||
println!("Warning: {warning}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -172,7 +173,7 @@ where
|
||||
let is_pnpm_workspace = if package_manager == PackageManager::Pnpm {
|
||||
if let Ok(entries) = fs::read_dir(&project_node_modules) {
|
||||
entries.flatten().any(|entry| {
|
||||
if entry.file_type().ok().map_or(false, |ft| ft.is_symlink()) {
|
||||
if entry.file_type().ok().is_some_and(|ft| ft.is_symlink()) {
|
||||
if let Ok(target) = fs::read_link(entry.path()) {
|
||||
let target_str = target.to_string_lossy();
|
||||
target_str.contains("/.pnpm/") && target_str.starts_with("../")
|
||||
@@ -324,7 +325,7 @@ fn detect_package_manager(node_modules_path: &Path, project_path: &Path) -> Pack
|
||||
if node_modules_path.exists() {
|
||||
if let Ok(entries) = fs::read_dir(node_modules_path) {
|
||||
for entry in entries.flatten() {
|
||||
if entry.file_type().ok().map_or(false, |ft| ft.is_symlink()) {
|
||||
if entry.file_type().ok().is_some_and(|ft| ft.is_symlink()) {
|
||||
if let Ok(target) = fs::read_link(entry.path()) {
|
||||
let target_str = target.to_string_lossy();
|
||||
if target_str.contains("/.pnpm/") {
|
||||
@@ -407,7 +408,7 @@ where
|
||||
if let Err(e) =
|
||||
copy_pnpm_package_comprehensive(zip, &node_modules_path, &pnpm_dir, package_name, opts)
|
||||
{
|
||||
println!("Warning: Failed to copy package {}: {}", package_name, e);
|
||||
println!("Warning: Failed to copy package {package_name}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,7 +705,7 @@ where
|
||||
package_name,
|
||||
opts,
|
||||
) {
|
||||
println!("Warning: Failed to copy package {}: {}", package_name, e);
|
||||
println!("Warning: Failed to copy package {package_name}: {e}");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -727,7 +728,7 @@ where
|
||||
|
||||
for package_name in &resolved_packages {
|
||||
if let Err(e) = copy_workspace_package(zip, node_modules_path, package_name, opts) {
|
||||
println!("Warning: Failed to copy package {}: {}", package_name, e);
|
||||
println!("Warning: Failed to copy package {package_name}: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -804,7 +805,7 @@ where
|
||||
|
||||
for package_name in &resolved_packages {
|
||||
if let Err(e) = copy_workspace_package(zip, node_modules_path, package_name, opts) {
|
||||
println!("Warning: Failed to copy package {}: {}", package_name, e);
|
||||
println!("Warning: Failed to copy package {package_name}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -887,7 +888,7 @@ where
|
||||
package_name,
|
||||
opts,
|
||||
) {
|
||||
println!("Warning: Failed to copy package {}: {}", package_name, e);
|
||||
println!("Warning: Failed to copy package {package_name}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -917,15 +918,17 @@ async fn detect_node_version_with_workspace_support(
|
||||
) -> Result<String> {
|
||||
let version_manager = NodeVersionManager::new();
|
||||
let version_spec = find_node_version_spec(project_path)?;
|
||||
|
||||
version_manager.resolve_version(&version_spec, ignore_cached_versions).await
|
||||
|
||||
version_manager
|
||||
.resolve_version(&version_spec, ignore_cached_versions)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Find Node version specification from .nvmrc or .node-version files,
|
||||
/// supporting workspace packages (parent/package, parent/packages/package patterns)
|
||||
fn find_node_version_spec(project_path: &Path) -> Result<String> {
|
||||
let mut current_path = project_path;
|
||||
|
||||
|
||||
loop {
|
||||
for file in [".nvmrc", ".node-version"] {
|
||||
let version_file = current_path.join(file);
|
||||
@@ -938,32 +941,27 @@ fn find_node_version_spec(project_path: &Path) -> Result<String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if is_workspace_root(current_path) || current_path.parent().is_none() {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
current_path = current_path.parent().unwrap();
|
||||
}
|
||||
|
||||
|
||||
anyhow::bail!("Node version specification not found in project or workspace hierarchy")
|
||||
}
|
||||
|
||||
/// Check if a directory is a workspace root (contains workspace configuration)
|
||||
fn is_workspace_root(path: &Path) -> bool {
|
||||
let workspace_files = [
|
||||
"pnpm-workspace.yaml",
|
||||
"lerna.json",
|
||||
"rush.json",
|
||||
"nx.json",
|
||||
];
|
||||
|
||||
let workspace_files = ["pnpm-workspace.yaml", "lerna.json", "rush.json", "nx.json"];
|
||||
|
||||
for file in workspace_files {
|
||||
if path.join(file).exists() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let Ok(package_json_content) = fs::read_to_string(path.join("package.json")) {
|
||||
if let Ok(package_json) = serde_json::from_str::<serde_json::Value>(&package_json_content) {
|
||||
if package_json.get("workspaces").is_some() {
|
||||
@@ -971,7 +969,7 @@ fn is_workspace_root(path: &Path) -> bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
@@ -1011,10 +1009,11 @@ fn determine_source_directory(project_path: &Path, package_json: &Value) -> Resu
|
||||
|
||||
for dir_name in ["dist", "build", "lib", "out"] {
|
||||
let dir_path = project_path.join(dir_name);
|
||||
if dir_path.exists() && dir_path.is_dir() {
|
||||
if contains_js_files(&dir_path) || dir_path.join("package.json").exists() {
|
||||
return Ok(dir_path);
|
||||
}
|
||||
if dir_path.exists()
|
||||
&& dir_path.is_dir()
|
||||
&& (contains_js_files(&dir_path) || dir_path.join("package.json").exists())
|
||||
{
|
||||
return Ok(dir_path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1119,7 +1118,6 @@ fn resolve_output_path(
|
||||
// Self-extracting executable generation using a more reliable approach
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
// Utility helpers
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
+9
-7
@@ -7,7 +7,11 @@ use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Create a self-extracting executable for the current platform
|
||||
pub fn create_self_extracting_executable(out: &Path, zip_data: Vec<u8>, _app_name: &str) -> Result<()> {
|
||||
pub fn create_self_extracting_executable(
|
||||
out: &Path,
|
||||
zip_data: Vec<u8>,
|
||||
_app_name: &str,
|
||||
) -> Result<()> {
|
||||
let build_id = Uuid::new_v4();
|
||||
|
||||
if Platform::current().is_windows() {
|
||||
@@ -36,7 +40,7 @@ else
|
||||
CACHE_DIR="/tmp/banderole-cache"
|
||||
fi
|
||||
|
||||
APP_DIR="$CACHE_DIR/{}"
|
||||
APP_DIR="$CACHE_DIR/{build_id}"
|
||||
READY_FILE="$APP_DIR/.ready"
|
||||
|
||||
run_app() {{
|
||||
@@ -112,8 +116,7 @@ echo "Error: Failed to extract or run application after $MAX_ATTEMPTS attempts"
|
||||
exit 1
|
||||
|
||||
__DATA__
|
||||
"#,
|
||||
build_id
|
||||
"#
|
||||
);
|
||||
|
||||
file.write_all(script.as_bytes())?;
|
||||
@@ -141,7 +144,7 @@ fn create_windows_executable(out: &Path, zip_data: Vec<u8>, build_id: &str) -> R
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "CACHE_DIR=%LOCALAPPDATA%\banderole"
|
||||
set "APP_DIR=!CACHE_DIR!\{}"
|
||||
set "APP_DIR=!CACHE_DIR!\{build_id}"
|
||||
set "LOCK_FILE=!APP_DIR!\.lock"
|
||||
set "READY_FILE=!APP_DIR!\.ready"
|
||||
set "QUEUE_DIR=!APP_DIR!\.queue"
|
||||
@@ -267,8 +270,7 @@ rmdir "!LOCK_FILE!" 2>nul
|
||||
goto run_app
|
||||
|
||||
__DATA__
|
||||
"#,
|
||||
build_id
|
||||
"#
|
||||
);
|
||||
|
||||
file.write_all(script.as_bytes())?;
|
||||
|
||||
+2
-1
@@ -52,7 +52,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
no_compression,
|
||||
ignore_cached_versions,
|
||||
} => {
|
||||
bundler::bundle_project(path, output, name, no_compression, ignore_cached_versions).await?;
|
||||
bundler::bundle_project(path, output, name, no_compression, ignore_cached_versions)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,14 +29,10 @@ impl NodeDownloader {
|
||||
.resolve_version(version_spec, false)
|
||||
.await
|
||||
.context(format!(
|
||||
"Failed to resolve Node.js version '{}'",
|
||||
version_spec
|
||||
"Failed to resolve Node.js version '{version_spec}'"
|
||||
))?;
|
||||
|
||||
println!(
|
||||
"Resolved '{}' to Node.js version {}",
|
||||
version_spec, resolved_version
|
||||
);
|
||||
println!("Resolved '{version_spec}' to Node.js version {resolved_version}");
|
||||
|
||||
Ok(Self {
|
||||
platform: Platform::current(),
|
||||
@@ -236,7 +232,7 @@ impl NodeDownloader {
|
||||
|
||||
async fn extract_tar_gz(&self, archive_path: &Path, target_dir: &Path) -> Result<()> {
|
||||
let output = tokio::process::Command::new("tar")
|
||||
.args(&[
|
||||
.args([
|
||||
"-xzf",
|
||||
archive_path.to_str().unwrap(),
|
||||
"-C",
|
||||
|
||||
@@ -135,7 +135,11 @@ impl NodeVersionManager {
|
||||
}
|
||||
|
||||
/// Resolve a version specification like "23", "23.5", "v22.1.0" to a complete version
|
||||
pub async fn resolve_version(&self, version_spec: &str, ignore_cached_versions: bool) -> Result<String> {
|
||||
pub async fn resolve_version(
|
||||
&self,
|
||||
version_spec: &str,
|
||||
ignore_cached_versions: bool,
|
||||
) -> Result<String> {
|
||||
let versions = self.fetch_versions(ignore_cached_versions).await?;
|
||||
let parsed_spec = self.parse_version_spec(version_spec)?;
|
||||
|
||||
@@ -332,7 +336,7 @@ mod tests {
|
||||
// This test requires internet connection
|
||||
if let Ok(version) = resolver.resolve_version("18", false).await {
|
||||
assert!(version.starts_with("18."));
|
||||
println!("Resolved '18' to: {}", version);
|
||||
println!("Resolved '18' to: {version}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -23,18 +23,18 @@ impl Platform {
|
||||
("macos", "aarch64") => Platform::MacosArm64,
|
||||
("windows", "x86_64") => Platform::WindowsX64,
|
||||
("windows", "aarch64") => Platform::WindowsArm64,
|
||||
_ => panic!("Unsupported platform: {}-{}", os, arch),
|
||||
_ => panic!("Unsupported platform: {os}-{arch}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn node_archive_name(&self, version: &str) -> String {
|
||||
match self {
|
||||
Platform::LinuxX64 => format!("node-v{}-linux-x64.tar.gz", version),
|
||||
Platform::LinuxArm64 => format!("node-v{}-linux-arm64.tar.gz", version),
|
||||
Platform::MacosX64 => format!("node-v{}-darwin-x64.tar.gz", version),
|
||||
Platform::MacosArm64 => format!("node-v{}-darwin-arm64.tar.gz", version),
|
||||
Platform::WindowsX64 => format!("node-v{}-win-x64.zip", version),
|
||||
Platform::WindowsArm64 => format!("node-v{}-win-arm64.zip", version),
|
||||
Platform::LinuxX64 => format!("node-v{version}-linux-x64.tar.gz"),
|
||||
Platform::LinuxArm64 => format!("node-v{version}-linux-arm64.tar.gz"),
|
||||
Platform::MacosX64 => format!("node-v{version}-darwin-x64.tar.gz"),
|
||||
Platform::MacosArm64 => format!("node-v{version}-darwin-arm64.tar.gz"),
|
||||
Platform::WindowsX64 => format!("node-v{version}-win-x64.zip"),
|
||||
Platform::WindowsArm64 => format!("node-v{version}-win-arm64.zip"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user