Skip to content

Commit 39902de

Browse files
authored
fix(pm): full-manifest dist-tags (#2236)
* feat: dist-tag * chore: ci * chore: ci * chore: ci * fix: ci * chore: clone * chore: remove arc clone * chore: fmt * chore: arc
1 parent d5d5bed commit 39902de

23 files changed

+440
-312
lines changed

crates/pm/src/cmd/link.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub async fn link_current_to_global(prefix: Option<&str>) -> Result<()> {
2222
})?;
2323

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

2929
let global_package_path = get_global_package_dir(prefix)?.join(&package_info.name);
3030
// link local project to global package

crates/pm/src/cmd/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ pub async fn list_dependencies(cwd: &Path, package_name: &str) -> Result<()> {
2222
// Load package-lock.json
2323
log_verbose("Loading package-lock.json...");
2424
let package_lock = PackageLock::from_lock_file(&lock_file_path)
25-
.map_err(|e| anyhow::anyhow!("Failed to parse package-lock.json: {}", e))?;
25+
.map_err(|e| anyhow::anyhow!("Failed to parse package-lock.json: {e}"))?;
2626

2727
// Build dependency graph
2828
log_verbose("Building dependency graph...");
2929
let graph = package_lock
3030
.build_dependency_graph()
31-
.map_err(|e| anyhow::anyhow!("Failed to build_dependency_graph {}", e))?;
31+
.map_err(|e| anyhow::anyhow!("Failed to build_dependency_graph {e}"))?;
3232

3333
show_package_dependencies(&graph, package_name)?;
3434

crates/pm/src/cmd/run.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub async fn run_script(
4646
workspace_name,
4747
)
4848
.await
49-
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {}", e))?;
49+
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {e}"))?;
5050
log_info(&format!(
5151
"Using workspace: {} at path: {}",
5252
workspace_name,
@@ -67,7 +67,7 @@ pub async fn run_script(
6767
workspace_name,
6868
)
6969
.await
70-
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {}", e))?
70+
.map_err(|e| anyhow::anyhow!("Failed to find workspace path: {e}"))?
7171
} else {
7272
std::env::current_dir().context("Failed to get current directory")?
7373
},
@@ -96,16 +96,14 @@ pub async fn run_script(
9696
log_command(pre_script, "");
9797
ScriptService::execute_custom_script(&package, &pre_script_name, pre_script)
9898
.await
99-
.map_err(|e| {
100-
anyhow::anyhow!("Failed to execute pre script {}: {}", pre_script_name, e)
101-
})?;
99+
.map_err(|e| anyhow::anyhow!("Failed to execute pre script {pre_script_name}: {e}"))?;
102100
}
103101

104102
// Execute main script
105103
let script_content = if let Some(Value::String(content)) = scripts.get(script_name) {
106104
content
107105
} else {
108-
anyhow::bail!("Script '{}' not found in package.json", script_name);
106+
anyhow::bail!("Script '{script_name}' not found in package.json");
109107
};
110108

111109
let script_args = script_args.unwrap_or_default();
@@ -117,7 +115,7 @@ pub async fn run_script(
117115
script_args,
118116
)
119117
.await
120-
.map_err(|e| anyhow::anyhow!("Failed to execute script {}: {}", script_name, e))?;
118+
.map_err(|e| anyhow::anyhow!("Failed to execute script {script_name}: {e}"))?;
121119

122120
// Execute post script if exists
123121
let post_script_name = format!("post{script_name}");
@@ -126,7 +124,7 @@ pub async fn run_script(
126124
ScriptService::execute_custom_script(&package, &post_script_name, post_script)
127125
.await
128126
.map_err(|e| {
129-
anyhow::anyhow!("Failed to execute post script {}: {}", post_script_name, e)
127+
anyhow::anyhow!("Failed to execute post script {post_script_name}: {e}")
130128
})?;
131129
}
132130

@@ -263,7 +261,7 @@ pub async fn run_script_in_all_workspaces(
263261
match result {
264262
Ok(task_result) => results.push(task_result),
265263
Err(join_error) => {
266-
return Err(anyhow::anyhow!("Task join error: {}", join_error));
264+
return Err(anyhow::anyhow!("Task join error: {join_error}"));
267265
}
268266
}
269267
}
@@ -372,26 +370,6 @@ mod tests {
372370
assert!(topology.is_empty());
373371
}
374372

375-
#[tokio::test]
376-
async fn test_run_script_in_all_workspaces_no_workspaces() {
377-
let _dir = tempdir().unwrap();
378-
let package_json = r#"
379-
{
380-
"name": "test-project",
381-
"version": "1.0.0",
382-
"scripts": {
383-
"test": "echo test"
384-
}
385-
}"#;
386-
387-
fs::write(_dir.path().join("package.json"), package_json).unwrap();
388-
std::env::set_current_dir(_dir.path()).unwrap();
389-
390-
let result = run_script_in_all_workspaces("test", None).await;
391-
// Should succeed but do nothing when no workspaces exist
392-
assert!(result.is_ok());
393-
}
394-
395373
#[tokio::test]
396374
#[allow(unused_variables)]
397375
async fn test_need_run_with_script() {

crates/pm/src/cmd/view.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ pub async fn view(package_spec: &str) -> Result<()> {
2020
// Get complete package information (like npm view) - use full JSON format for complete data
2121
let (full_manifest, _etag) = fetch_full_manifest_for_view(name, None)
2222
.await
23-
.map_err(|e| {
24-
anyhow!(
25-
"Failed to fetch package info for {}, reason: {}",
26-
package_spec,
27-
e
28-
)
29-
})?;
23+
.map_err(|e| anyhow!("Failed to fetch package info for {package_spec}, reason: {e}"))?;
3024

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

crates/pm/src/helper/auto_update.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async fn execute_update(version: &str) -> Result<()> {
131131
Ok(())
132132
} else {
133133
log_error("Auto update failed, please update manually");
134-
anyhow::bail!("Auto update failed, please execute manually {}", status)
134+
anyhow::bail!("Auto update failed, please execute manually {status}")
135135
}
136136
}
137137

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

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

190190
fn save_version_cache(cache: &VersionCache) -> Result<()> {

crates/pm/src/helper/deps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn compute_topological_layers(node_list: &[Node], edges: &[Edge]) -> Result<
110110
Ok(sorted) => sorted,
111111
Err(e) => {
112112
log_warning("Failed to perform topological sort");
113-
return Err(anyhow!("Topological sort failed: {:?}", e));
113+
return Err(anyhow!("Topological sort failed: {e:?}"));
114114
}
115115
};
116116

crates/pm/src/helper/lock.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub async fn update_package_json(
115115
let target_dir = if let Some(ws) = workspace {
116116
find_workspace_path(cwd, ws)
117117
.await
118-
.map_err(|e| anyhow!("Failed to find workspace path: {}", e))?
118+
.map_err(|e| anyhow!("Failed to find workspace path: {e}"))?
119119
} else {
120120
cwd.to_path_buf()
121121
};
@@ -227,7 +227,7 @@ pub async fn prepare_global_package_json(npm_spec: &str, prefix: Option<&str>) -
227227
));
228228
download(tarball_url, &cache_path)
229229
.await
230-
.map_err(|e| anyhow!("Failed to download package: {}", e))?;
230+
.map_err(|e| anyhow!("Failed to download package: {e}"))?;
231231

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

251251
// Remove devDependencies from package.json
252252
let package_json_path = package_path.join("package.json");

crates/pm/src/helper/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub async fn find_workspace_path(cwd: &Path, workspace: &str) -> Result<PathBuf>
9494
return Ok(path);
9595
}
9696
}
97-
anyhow::bail!("Workspace '{}' not found", workspace)
97+
anyhow::bail!("Workspace '{workspace}' not found")
9898
}
9999

100100
/// Check if a directory is a workspace root by examining its package.json

crates/pm/src/model/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl PackageInfo {
153153
// Ensure target file is executable
154154
ScriptService::ensure_executable(&target_path)
155155
.await
156-
.map_err(|e| anyhow::anyhow!("Failed to ensure binary is executable: {}", e))?;
156+
.map_err(|e| anyhow::anyhow!("Failed to ensure binary is executable: {e}"))?;
157157

158158
// Create symbolic link
159159
link(&target_path, &link_path)

crates/pm/src/model/package_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl PackageLock {
147147
fs::read_to_string(path.as_ref()).context("Failed to read package-lock.json file")?;
148148

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

152152
Ok(package_lock)
153153
}

0 commit comments

Comments
 (0)