1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Audit command implementation for Node.js bindings.
//!
//! # What
//!
//! This module implements the `audit` NAPI function that provides comprehensive
//! health checks and analysis of the workspace. It examines dependencies,
//! version consistency, available upgrades, and potential breaking changes.
//!
//! # How
//!
//! The function:
//! 1. Validates the input parameters (root path, sections, severity, verbosity)
//! 2. Calls `execute_audit` from `sublime_cli_tools`
//! 3. Captures the JSON output containing the audit report
//! 4. Returns a `JsonResponse<AuditData>` with health score and issues
//!
//! # Why
//!
//! Regular auditing helps maintain workspace health by identifying:
//! - Outdated dependencies that should be upgraded
//! - Version inconsistencies across packages
//! - Circular dependencies that could cause issues
//! - Deprecated packages that need replacement
//! - Potential breaking changes in dependencies
//!
//! # Examples
//!
//! ```typescript
//! import { audit } from '@websublime/workspace-tools';
//!
//! // Run full audit with all sections
//! const result = await audit({
//! root: '.',
//! sections: ['upgrades', 'dependencies', 'versions', 'breaking'],
//! minSeverity: 'medium',
//! verbosity: 'normal'
//! });
//!
//! if (result.success) {
//! console.log(`Health Score: ${result.data.summary.healthScore}%`);
//! console.log(`Total Issues: ${result.data.summary.totalIssues}`);
//! console.log(` Critical: ${result.data.summary.criticalIssues}`);
//! console.log(` High: ${result.data.summary.highIssues}`);
//! console.log(` Medium: ${result.data.summary.mediumIssues}`);
//! console.log(` Low: ${result.data.summary.lowIssues}`);
//!
//! // Check upgrade section
//! if (result.data.sections.upgrades) {
//! const { totalUpgrades, majorUpgrades, minorUpgrades, patchUpgrades } =
//! result.data.sections.upgrades;
//! console.log(`\nUpgrades available: ${totalUpgrades}`);
//! console.log(` Major: ${majorUpgrades}`);
//! console.log(` Minor: ${minorUpgrades}`);
//! console.log(` Patch: ${patchUpgrades}`);
//! }
//!
//! // Check dependency issues
//! if (result.data.sections.dependencies) {
//! const { circularDependencies, deprecatedPackages } =
//! result.data.sections.dependencies;
//! if (circularDependencies.length > 0) {
//! console.log(`\nCircular dependencies found: ${circularDependencies.length}`);
//! }
//! if (deprecatedPackages.length > 0) {
//! console.log(`\nDeprecated packages: ${deprecatedPackages.length}`);
//! for (const pkg of deprecatedPackages) {
//! console.log(` ${pkg.name}: ${pkg.message}`);
//! }
//! }
//! }
//! }
//! ```
// TODO: will be implemented on story 9.1 - Audit Command
//
// Implementation outline:
//
// #[napi]
// pub async fn audit(params: AuditParams) -> JsonResponse<AuditData> {
// // 1. Validate parameters
// if let Err(e) = validate_root(¶ms.root) {
// return JsonResponse::from_error_info(e);
// }
//
// // 2. Parse and validate sections if provided
// // Valid sections: "upgrades", "dependencies", "versions", "breaking"
// // Default: all sections
//
// // 3. Parse and validate min_severity if provided
// // Valid values: "critical", "high", "medium", "low", "info"
// // Default: "info" (show all)
//
// // 4. Parse and validate verbosity if provided
// // Valid values: "minimal", "normal", "detailed"
// // Default: "normal"
//
// // 5. Create AuditArgs from params
// let args = AuditArgs {
// sections: params.sections.unwrap_or_default(),
// min_severity: params.min_severity.unwrap_or_else(|| "info".to_string()),
// verbosity: params.verbosity.unwrap_or_else(|| "normal".to_string()),
// output: params.output_file,
// ..Default::default()
// };
//
// // 6. Create Output with JSON format for capturing
// let mut buffer = Vec::new();
// let output = Output::new(OutputFormat::Json, &mut buffer, false);
//
// // 7. Determine workspace root path
// let root_path = Path::new(¶ms.root);
// let config_path = None; // Will use default config discovery
//
// // 8. Call execute_audit from CLI (commands/audit/comprehensive.rs)
// match execute_audit(&args, &output, root_path, config_path).await {
// Ok(()) => {
// // 9. Parse JSON response from buffer
// let json_str = String::from_utf8_lossy(&buffer);
// match serde_json::from_str::<JsonResponse<AuditData>>(&json_str) {
// Ok(response) => response,
// Err(e) => JsonResponse::error(format!("Failed to parse audit response: {}", e)),
// }
// }
// Err(e) => JsonResponse::error(format!("Audit failed: {}", e)),
// }
// }
//
// Note: The audit command is comprehensive and may take some time to complete,
// especially for large workspaces with many dependencies. Consider adding
// progress reporting in future enhancements.