Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/pm/src/cmd/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub async fn link_current_to_global(prefix: Option<&str>) -> Result<()> {
})?;

// Install dependencies
install(false, &project_path).await.map_err(|e| {
anyhow::anyhow!("Failed to prepare dependencies for package to link: {}", e)
})?;
install(false, &project_path)
.await
.map_err(|e| anyhow::anyhow!("Failed to prepare dependencies for package to link: {e}"))?;

let global_package_path = get_global_package_dir(prefix)?.join(&package_info.name);
// link local project to global package
Expand Down
4 changes: 2 additions & 2 deletions crates/pm/src/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ pub async fn list_dependencies(cwd: &Path, package_name: &str) -> Result<()> {
// Load package-lock.json
log_verbose("Loading package-lock.json...");
let package_lock = PackageLock::from_lock_file(&lock_file_path)
.map_err(|e| anyhow::anyhow!("Failed to parse package-lock.json: {}", e))?;
.map_err(|e| anyhow::anyhow!("Failed to parse package-lock.json: {e}"))?;

// Build dependency graph
log_verbose("Building dependency graph...");
let graph = package_lock
.build_dependency_graph()
.map_err(|e| anyhow::anyhow!("Failed to build_dependency_graph {}", e))?;
.map_err(|e| anyhow::anyhow!("Failed to build_dependency_graph {e}"))?;

show_package_dependencies(&graph, package_name)?;

Expand Down
36 changes: 7 additions & 29 deletions crates/pm/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn run_script(
workspace_name,
)
.await
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {}", e))?;
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {e}"))?;
log_info(&format!(
"Using workspace: {} at path: {}",
workspace_name,
Expand All @@ -67,7 +67,7 @@ pub async fn run_script(
workspace_name,
)
.await
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {}", e))?
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {e}"))?
} else {
std::env::current_dir().context("Failed to get current directory")?
},
Expand Down Expand Up @@ -96,16 +96,14 @@ pub async fn run_script(
log_command(pre_script, "");
ScriptService::execute_custom_script(&package, &pre_script_name, pre_script)
.await
.map_err(|e| {
anyhow::anyhow!("Failed to execute pre script {}: {}", pre_script_name, e)
})?;
.map_err(|e| anyhow::anyhow!("Failed to execute pre script {pre_script_name}: {e}"))?;
}

// Execute main script
let script_content = if let Some(Value::String(content)) = scripts.get(script_name) {
content
} else {
anyhow::bail!("Script '{}' not found in package.json", script_name);
anyhow::bail!("Script '{script_name}' not found in package.json");
};

let script_args = script_args.unwrap_or_default();
Expand All @@ -117,7 +115,7 @@ pub async fn run_script(
script_args,
)
.await
.map_err(|e| anyhow::anyhow!("Failed to execute script {}: {}", script_name, e))?;
.map_err(|e| anyhow::anyhow!("Failed to execute script {script_name}: {e}"))?;

// Execute post script if exists
let post_script_name = format!("post{script_name}");
Expand All @@ -126,7 +124,7 @@ pub async fn run_script(
ScriptService::execute_custom_script(&package, &post_script_name, post_script)
.await
.map_err(|e| {
anyhow::anyhow!("Failed to execute post script {}: {}", post_script_name, e)
anyhow::anyhow!("Failed to execute post script {post_script_name}: {e}")
})?;
}

Expand Down Expand Up @@ -263,7 +261,7 @@ pub async fn run_script_in_all_workspaces(
match result {
Ok(task_result) => results.push(task_result),
Err(join_error) => {
return Err(anyhow::anyhow!("Task join error: {}", join_error));
return Err(anyhow::anyhow!("Task join error: {join_error}"));
}
}
}
Expand Down Expand Up @@ -372,26 +370,6 @@ mod tests {
assert!(topology.is_empty());
}

#[tokio::test]
async fn test_run_script_in_all_workspaces_no_workspaces() {
let _dir = tempdir().unwrap();
let package_json = r#"
{
"name": "test-project",
"version": "1.0.0",
"scripts": {
"test": "echo test"
}
}"#;

fs::write(_dir.path().join("package.json"), package_json).unwrap();
std::env::set_current_dir(_dir.path()).unwrap();

let result = run_script_in_all_workspaces("test", None).await;
// Should succeed but do nothing when no workspaces exist
assert!(result.is_ok());
}

#[tokio::test]
#[allow(unused_variables)]
async fn test_need_run_with_script() {
Expand Down
8 changes: 1 addition & 7 deletions crates/pm/src/cmd/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ pub async fn view(package_spec: &str) -> Result<()> {
// Get complete package information (like npm view) - use full JSON format for complete data
let (full_manifest, _etag) = fetch_full_manifest_for_view(name, None)
.await
.map_err(|e| {
anyhow!(
"Failed to fetch package info for {}, reason: {}",
package_spec,
e
)
})?;
.map_err(|e| anyhow!("Failed to fetch package info for {package_spec}, reason: {e}"))?;

log_verbose(&format!("Fetched package info: {full_manifest:?}"));

Expand Down
6 changes: 3 additions & 3 deletions crates/pm/src/helper/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async fn execute_update(version: &str) -> Result<()> {
Ok(())
} else {
log_error("Auto update failed, please update manually");
anyhow::bail!("Auto update failed, please execute manually {}", status)
anyhow::bail!("Auto update failed, please execute manually {status}")
}
}

Expand All @@ -152,7 +152,7 @@ async fn check_remote_version_fast() -> Result<VersionCache> {
let package_info = response
.json::<serde_json::Value>()
.await
.map_err(|e| anyhow::anyhow!("Failed to parse package info: {}", e))?;
.map_err(|e| anyhow::anyhow!("Failed to parse package info: {e}"))?;

let version = package_info["version"]
.as_str()
Expand Down Expand Up @@ -184,7 +184,7 @@ fn read_version_cache() -> Result<VersionCache> {
let content =
fs::read_to_string(get_cache_path()).context("Failed to read version cache file")?;
serde_json::from_str(&content)
.map_err(|e| anyhow::anyhow!("Failed to parse version cache: {}", e))
.map_err(|e| anyhow::anyhow!("Failed to parse version cache: {e}"))
}

fn save_version_cache(cache: &VersionCache) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/helper/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn compute_topological_layers(node_list: &[Node], edges: &[Edge]) -> Result<
Ok(sorted) => sorted,
Err(e) => {
log_warning("Failed to perform topological sort");
return Err(anyhow!("Topological sort failed: {:?}", e));
return Err(anyhow!("Topological sort failed: {e:?}"));
}
};

Expand Down
6 changes: 3 additions & 3 deletions crates/pm/src/helper/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub async fn update_package_json(
let target_dir = if let Some(ws) = workspace {
find_workspace_path(cwd, ws)
.await
.map_err(|e| anyhow!("Failed to find workspace path: {}", e))?
.map_err(|e| anyhow!("Failed to find workspace path: {e}"))?
} else {
cwd.to_path_buf()
};
Expand Down Expand Up @@ -227,7 +227,7 @@ pub async fn prepare_global_package_json(npm_spec: &str, prefix: Option<&str>) -
));
download(tarball_url, &cache_path)
.await
.map_err(|e| anyhow!("Failed to download package: {}", e))?;
.map_err(|e| anyhow!("Failed to download package: {e}"))?;

// If the package has install scripts, create a flag file
// in linux, we can use hardlink when FICLONE is not supported
Expand All @@ -246,7 +246,7 @@ pub async fn prepare_global_package_json(npm_spec: &str, prefix: Option<&str>) -
));
clone(&cache_path, &package_path, true)
.await
.map_err(|e| anyhow!("Failed to clone package: {}", e))?;
.map_err(|e| anyhow!("Failed to clone package: {e}"))?;

// Remove devDependencies from package.json
let package_json_path = package_path.join("package.json");
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/helper/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub async fn find_workspace_path(cwd: &Path, workspace: &str) -> Result<PathBuf>
return Ok(path);
}
}
anyhow::bail!("Workspace '{}' not found", workspace)
anyhow::bail!("Workspace '{workspace}' not found")
}

/// Check if a directory is a workspace root by examining its package.json
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/model/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl PackageInfo {
// Ensure target file is executable
ScriptService::ensure_executable(&target_path)
.await
.map_err(|e| anyhow::anyhow!("Failed to ensure binary is executable: {}", e))?;
.map_err(|e| anyhow::anyhow!("Failed to ensure binary is executable: {e}"))?;

// Create symbolic link
link(&target_path, &link_path)
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/model/package_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl PackageLock {
fs::read_to_string(path.as_ref()).context("Failed to read package-lock.json file")?;

let package_lock: PackageLock = serde_json::from_str(&content)
.map_err(|e| anyhow::anyhow!("Failed to parse package-lock.json: {}", e))?;
.map_err(|e| anyhow::anyhow!("Failed to parse package-lock.json: {e}"))?;

Ok(package_lock)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/service/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn load_config() -> Result<&'static Value> {
response
.json()
.await
.map_err(|e| anyhow::anyhow!("Failed to parse binary mirror config: {}", e))
.map_err(|e| anyhow::anyhow!("Failed to parse binary mirror config: {e}"))
})
.await
}
Expand Down
Loading
Loading