sublime_node_tools 0.0.4

Node.js bindings for Sublime Workspace CLI Tools via napi-rs
Documentation
//! 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(&params.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(&params.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.