How aaronhaddad/nvm works
Project type and purpose
• This is an open-source command-line tool (nvm: Node Version Manager) written in shell script.
• It provides a shell-function interface to install, switch between, and manage multiple Node.js (and io.js) versions per user/shell.
• It is invoked by the user’s POSIX shell, sources core scripts, interacts with the file system (in $NVM_DIR), and fetches binaries (or source) from remote servers.
Key components
a. User & Shell Environment
• User’s terminal (bash, zsh, ksh, dash) → sources nvm.sh → exposes nvm commands.
b. CLI Entrypoint & Core Scripts
• install.sh (bootstrapper)
• nvm.sh (core library of functions: install, use, alias, ls, rm, etc.)
• bash_completion (auto-completion support)
c. Local Storage (File System under $NVM_DIR)
• versions/…
• alias/…
• default-packages
• ‘current’ symlink (if enabled)
d. External Tools & Shell Utilities
• curl / wget / git (for download/clone)
• tar / make / gcc (for building from source)
• tarball extractor, checksum utilities (sha256sum)
e. Remote Services
• Node.js / io.js distribution servers (e.g. https://nodejs.org/dist)
• GitHub (for git-based installs & updates)
f. Test Suite & CI
• Urchin-based test harness: fast tests (mocked filesystem calls) and slow tests (actual installs)
• GitHub Actions, Travis CI, Docker (nvm-dev container) orchestrating test runs
Relationships & Data Flows
• User → Shell → nvm function → core script (nvm.sh)
• Core script ↔ Local Storage ($NVM_DIR):
• read/write version directories, alias files, default-packages file
• create/remove symlinks
• Core script → External Tools (curl/git/tar) → Remote Service (download binary or source)
• Core script → External Tools (make, gcc) when building from source
• Test Suite → mocks or real core scripts → Local Storage → External Tools/Remote Services (in slow tests)
• CI Platform → triggers tests, lint, releases, coverage
Architectural patterns & design principles
• Monolithic CLI layered design:
• Bootstrap layer (install.sh) → library layer (nvm.sh) → completion layer
• Filesystem-driven state: all installed versions, aliases, and defaults stored in well-known directories under $NVM_DIR.
• Plugin-style shell integration: deeper integration via avn/nvshim hooks or shell functions.
• Idempotent and declarative commands: user invokes commands; state changes on disk.
• Extensibility points: alias mechanism, custom default-packages file, mirror URLs via env vars.