$ show nvm-sh/nvm
nvm (Node Version Manager) is a battle-tested, POSIX-compliant shell function that allows users to install, switch between, and manage multiple versions of Node.js and io.js on a per-shell basis. The core architecture is a single monolithic shell script (`nvm.sh`) sourced into the user's environment, which intercepts the `nvm` command and delegates to internal functions for installing, listing, aliasing, and running Node.js versions. Key entry points include `nvm.sh` (the main script), `install.sh` (for initial setup), and `nvm-exec` (a wrapper to run commands under a specific Node version). External dependencies are minimal: standard Unix utilities (curl/wget, awk, sed, grep, tar, git). Data flows involve fetching version index files from nodejs.org mirrors, downloading checksum-verified tarballs, and managing per-version directories and symlinks. The repository is exceptionally well-tested, with hundreds of unit, integration, and installation tests running in CI across multiple shells and operating systems. Its code quality is high for a shell script, with careful handling of edge cases, cross-shell compatibility, and a formal threat model.
The LLM identified 2 files worth highlighting for reuse:
A collection of reusable shell test utilities including `try`, `try_err`, `assert_ok`, `assert_not_ok`, `make_fake_node`, `make_fake_curl`, and `strip_colors`. These helpers encapsulate patterns for creating temporary executable stubs, asserting command outcomes, and sanitizing color output. They are isolated from the nvm-specific logic and could be adopted by any shell project's test suite with minimal modification, demonstrating non-obvious shell scripting techniques (e.g., making fake executables for mocking, handling colored output portably).
A compact (~30-line) wrapper script that sources `nvm.sh`, resolves the desired Node version, and executes a user-provided command under that version by manipulating `PATH`, `MANPATH`, and `NODE_PATH`. It demonstrates a clean pattern for creating an environment-specific command runner that is decoupled from the main interactive shell, making it reusable as a template for any tool that needs to run subcommands within a version-managed context.