Crate sublime_standard_tools

Crate sublime_standard_tools 

Source
Expand description

§sublime_standard_tools

A comprehensive toolkit for working with Node.js projects from Rust applications.

§What

This crate provides a foundational set of utilities for interacting with Node.js projects, package managers, and development workflows from Rust. It handles project structure detection, command execution, environment management, and various other tasks required when working with Node.js ecosystems.

§How

The crate follows a clean architectural approach with clear separation of concerns:

§Core Modules

  • node: Generic Node.js concepts (repositories, package managers)
  • project: Unified project detection and management
  • monorepo: Monorepo-specific functionality and workspace management
  • command: Robust command execution framework
  • filesystem: Safe filesystem operations and path utilities
  • error: Comprehensive error handling

§Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                    sublime_standard_tools                    │
├─────────────────────────────────────────────────────────────┤
│  project/     │  Unified project detection and management   │
│  ├─detector   │  ├─ ProjectDetector (any project type)     │
│  ├─manager    │  ├─ ProjectManager (lifecycle management)  │
│  └─types      │  └─ ProjectInfo trait (common interface)   │
├─────────────────────────────────────────────────────────────┤
│  node/        │  Generic Node.js concepts                  │
│  ├─types      │  ├─ RepoKind (Simple vs Monorepo)         │
│  ├─package_*  │  ├─ PackageManager & PackageManagerKind   │
│  └─repository │  └─ RepositoryInfo trait                  │
├─────────────────────────────────────────────────────────────┤
│  monorepo/    │  Monorepo-specific functionality           │
│  ├─detector   │  ├─ MonorepoDetector (workspace detection) │
│  ├─descriptor │  ├─ MonorepoDescriptor (full structure)    │
│  └─kinds      │  └─ MonorepoKind (npm, yarn, pnpm, etc.)  │
├─────────────────────────────────────────────────────────────┤
│  command/     │  Robust command execution                  │
│  filesystem/  │  Safe filesystem operations               │
│  error/       │  Comprehensive error handling             │
└─────────────────────────────────────────────────────────────┘

§Why

Interacting with Node.js projects from Rust typically involves a significant amount of boilerplate code for path handling, command execution, and project structure detection. This crate abstracts these common tasks into a reusable library with consistent error handling and cross-platform support.

The new architecture provides:

  • Clean separation of concerns: Each module has a clear responsibility
  • Unified project handling: Works with both simple and monorepo projects
  • Type-safe abstractions: Strong typing prevents common errors
  • Extensible design: Easy to add new project types and package managers

§Quick Start

§Detect any Node.js project

use sublime_standard_tools::project::{ProjectDetector, ProjectDetectorTrait};
use std::path::Path;

let detector = ProjectDetector::new();

match detector.detect(Path::new("."), None).await {
    Ok(project) => {
        let info = project.as_project_info();
        println!("Found {} project", info.kind().name());

        if let Some(pm) = info.package_manager() {
            println!("Using {} package manager", pm.command());
        }
    }
    Err(e) => eprintln!("Detection failed: {}", e),
}

§Auto-load configuration from project files

All major components support automatic configuration loading:

use sublime_standard_tools::{
    project::ProjectDetector,
    monorepo::MonorepoDetector,
    filesystem::FileSystemManager,
    command::DefaultCommandExecutor,
    config::StandardConfig,
};
use std::path::Path;

// Each component uses default config or accepts explicit configuration
let project_detector = ProjectDetector::new();
let monorepo_detector = MonorepoDetector::new(); // Uses default config
let filesystem = FileSystemManager::new(); // Uses default config
let executor = DefaultCommandExecutor::new(); // Uses default config

// Or with explicit configuration
let config = StandardConfig::default();
let monorepo_detector_with_config = MonorepoDetector::new_with_config(config.monorepo);

§Work with package managers

use sublime_standard_tools::node::{PackageManager, PackageManagerKind};
use std::path::Path;

// Detect package manager
let manager = PackageManager::detect(Path::new(".")).await?;
println!("Using {}", manager.command());

// Check capabilities
if manager.supports_workspaces() {
    println!("Workspaces supported");
}

§Analyze monorepos

use sublime_standard_tools::monorepo::{MonorepoDetector, MonorepoDetectorTrait};
use std::path::Path;

let detector = MonorepoDetector::new();
if let Some(kind) = detector.is_monorepo_root(".").await? {
    let monorepo = detector.detect_monorepo(".").await?;

    println!("Found {} with {} packages",
             monorepo.kind().name(),
             monorepo.packages().len());

    // Analyze dependencies
    let graph = monorepo.get_dependency_graph();
    for (pkg, deps) in graph {
        println!("{} has {} dependents", pkg, deps.len());
    }
}

Modules§

command
Command Execution Module
config
Configuration module for flexible and extensible configuration management.
error
Error handling for sublime_standard_tools
filesystem
Filesystem Operations Module - Async Only
monorepo
Monorepo Management Module - Async Only
node
Node.js Project Module
project
Project Management Module

Constants§

VERSION
Version of the crate

Functions§

version
Returns the version of the crate