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
28 changes: 27 additions & 1 deletion src/commands/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct WorkspaceDepsJsonReport {
#[derive(Debug, Serialize, Deserialize)]
pub struct WorkspaceDepsEntry {
pub workspace: String,
pub path: String,
pub dependencies: Vec<String>,
pub reverse: bool,
pub transitive: bool,
Expand Down Expand Up @@ -121,6 +122,14 @@ impl WorkspaceDependencyAnalysis {
.find(|ws| ws.name() == workspace_name)
}

/// Get workspace path by name
pub fn get_workspace_path(&self, workspace_name: &str) -> Option<&PathBuf> {
self.workspaces
.iter()
.find(|(_, ws)| ws.name() == workspace_name)
.map(|(path, _)| path)
}

/// Get direct dependencies of a workspace
pub fn get_direct_dependencies(&mut self, workspace: &str) -> &HashSet<String> {
if !self.direct_deps_cache.contains_key(workspace) {
Expand Down Expand Up @@ -226,6 +235,11 @@ impl WorkspaceDepsReportGenerator {
for workspace in workspaces {
writeln!(output, "\n📦 Workspace: {workspace}")?;

// Add workspace path if available
if let Some(workspace_path) = analysis.get_workspace_path(&workspace) {
writeln!(output, " 📍 Path: {}", workspace_path.display())?;
}

if self.reverse {
writeln!(output, " ⬆️ Reverse dependencies (who depends on this):")?;
let reverse_deps = analysis.get_reverse_dependencies(&workspace);
Expand Down Expand Up @@ -300,8 +314,14 @@ impl WorkspaceDepsReportGenerator {
.map(|info| info.is_standalone())
.unwrap_or(false);

let workspace_path = analysis
.get_workspace_path(&workspace)
.map(|p| p.display().to_string())
.unwrap_or_else(|| "(unknown)".to_string());

workspace_data.push(WorkspaceDepsEntry {
workspace,
workspace: workspace.clone(),
path: workspace_path,
dependencies: deps,
reverse: self.reverse,
transitive: self.transitive,
Expand Down Expand Up @@ -583,6 +603,7 @@ mod tests {
let report = generator.generate_human_report(&mut analysis).unwrap();

assert!(report.contains("workspace-a"));
assert!(report.contains("Path: /test/workspace-a"));
assert!(report.contains("Direct dependencies"));
assert!(report.contains("workspace-b"));
}
Expand All @@ -598,5 +619,10 @@ mod tests {

let json: serde_json::Value = serde_json::from_str(&report).unwrap();
assert!(json["workspace_dependencies"].is_array());

// Verify path field exists in the JSON output
let workspace_deps = json["workspace_dependencies"].as_array().unwrap();
assert!(!workspace_deps.is_empty());
assert!(workspace_deps[0]["path"].is_string());
}
}
2 changes: 1 addition & 1 deletion src/executors/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl CommandExecutor for AnalyzeExecutor {
};

match report_result {
Ok(report) => print!("{report}"),
Ok(report) => println!("{report}"),
Err(e) => {
return Err(e).wrap_err("Failed to generate report for crate analysis");
}
Expand Down
2 changes: 1 addition & 1 deletion src/executors/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl CommandExecutor for DepsExecutor {
};

match report_result {
Ok(report) => print!("{report}"),
Ok(report) => println!("{report}"),
Err(e) => {
return Err(e)
.into_diagnostic()
Expand Down
9 changes: 9 additions & 0 deletions src/toml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ impl CargoToml {
.unwrap_or_default()
}

/// Returns the list of workspace exclude patterns from the Cargo.toml
pub fn get_workspace_excludes(&self) -> Vec<String> {
self.workspace
.as_ref()
.and_then(|ws| ws.exclude.as_ref())
.cloned()
.unwrap_or_default()
}

pub fn get_workspace_dependencies(&self) -> HashMap<String, PathBuf> {
let mut deps = HashMap::new();

Expand Down
Loading
Loading