This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
NodeSwap is a Windows-only Node.js version manager written in C# (.NET 8.0). It's similar to NVM but specifically designed for Windows. The application uses symlinks to manage different Node.js versions and requires administrator privileges for symlink creation.
- NodeSwap - Main console application (.NET 8.0-windows)
- NodeSwap.Tests - MSTest unit tests using Shouldly assertions
- NodeSwap.Installer - WiX installer project for Windows
- Program.cs - Entry point with dependency injection setup using Microsoft.Extensions.DependencyInjection
- GlobalContext.cs - Shared configuration and paths (storage, symlink, version tracking)
- Commands/ - CLI command implementations using DotMake.CommandLine with full dependency injection
- Interfaces/ - Abstraction interfaces for external dependencies (file system, process elevation, etc.)
- Services/ - Service implementations wrapping external dependencies
- NodeJs.cs & NodeJsWebApi.cs - Node.js version management and API integration
- Utils/ - Helper utilities for console output, process elevation, and list operations
The application uses comprehensive dependency injection for improved testability:
- IProcessElevation - Windows process elevation and administrator checks
- IConsoleWriter - Console output abstraction
- IFileSystem - File system operations (read/write/delete/symlinks)
- INodeJsWebApi - Node.js API integration for version lookup and downloads
- INodeJs - Local Node.js version management
- ProcessElevationService - Windows-specific elevation implementation
- ConsoleWriterService - Console.WriteLine wrapper
- FileSystemService - System.IO wrapper with symlink support
- NodeJsWebApiService - HTTP-based Node.js API client
- NodeJsService - Local version management implementation
- DotMake.CommandLine - Primary CLI framework
- System.CommandLine - Additional command line support
- NuGet.Versioning - Version parsing and comparison
- ShellProgressBar - Progress indication for downloads
- Microsoft.Extensions.DependencyInjection - Dependency injection container
dotnet build NodeSwap.sln
dotnet build -c Release NodeSwap.slndotnet test NodeSwap.Tests/
dotnet test --verbosity normaldotnet publish NodeSwap/NodeSwap.csproj -c Releasedotnet run --project NodeSwap/- .NET 8.0 runtime or SDK
- Windows operating system (uses Windows-specific symlinks)
NODESWAP_STORAGEenvironment variable must be set to a valid directory path
The use command requires administrator privileges to create/update symlinks. The application will prompt for elevation when needed.
- Node.js versions are downloaded and stored in
%NODESWAP_STORAGE% - Active version tracked via symlink at
%NODESWAP_STORAGE%/current - Version history maintained in
last-usedandprevious-usedfiles - Supports fuzzy version matching (e.g., "22" → "22.x.x")
All commands use dependency injection and inherit from DotMake.CommandLine patterns:
list- Show installed versionsavail [min_version]- Show available downloadsinstall <version>- Download and install Node.js versionuninstall <version>- Remove installed versionuse <version>- Switch active version (requires admin)prev- Switch to previously used versionfile- Use or create a .nodeswap file to manage Node.js version for the current directory
All commands now accept required dependencies through constructor injection:
- UseCommand - Takes GlobalContext, INodeJs, IProcessElevation, IConsoleWriter, IFileSystem
- InstallCommand - Takes GlobalContext, INodeJsWebApi, INodeJs, IConsoleWriter, IFileSystem
- PrevCommand - Takes GlobalContext, INodeJs, IProcessElevation, IConsoleWriter, IFileSystem
- FileCommand - Takes GlobalContext, INodeJs, IProcessElevation, IConsoleWriter, IFileSystem
- MSTest framework with Shouldly assertions
- Comprehensive mock-based testing for isolation
- 60+ unit tests covering all commands and utilities
Custom mock implementations for complete test isolation:
- MockProcessElevation - Configurable administrator status and elevation behavior
- MockConsoleWriter - Captures output and error messages for verification
- MockFileSystem - In-memory file system with symlink simulation
- MockNodeJs - Configurable installed versions and active version tracking
- MockNodeJsWebApi - Configurable API responses and exception testing
- Command Tests - All commands have comprehensive test coverage using mocks
- Utility Tests - Version parsing, list operations, and helper functions
- Integration-style Tests - Some tests use MockServices with dependency injection
- Error Scenario Testing - Exception handling, validation, and edge cases
- FileCommandTests.cs - Tests for .nodeswap file management (6 tests)
- UseCommandTests.cs - Tests for version switching with mocks (7 tests)
- UseCommandTestsWithMocks.cs - Additional comprehensive use command tests (10 tests)
- InstallCommandTestsWithMocks.cs - Installation command tests (8 tests)
- PrevCommandTests.cs - Previous version switching tests (6 tests)
- ListCommandTests.cs, UninstallCommandTests.cs, AvailCommandTests.cs - Additional command coverage
# Run all tests
dotnet test NodeSwap.Tests/ --verbosity normal
# Run specific test class
dotnet test NodeSwap.Tests/ --filter "FileCommandTests" --verbosity normal
# Run tests before making changes to core logic
dotnet test NodeSwap.Tests/