Basic Usage
Learn the core snpm commands
snpm works just like npm. If you know npm, you already know snpm.
Installing Dependencies
snpm installReads package.json, resolves dependencies, downloads packages to the global store, and links them to node_modules.
Options:
--production- Skip dev dependencies--frozen-lockfile- Fail if lockfile needs updates (useful for CI)--force- Force re-download all packages
# Production install
snpm install --production
# CI install (fail if lockfile is out of sync)
snpm install --frozen-lockfileAdding Packages
snpm add <package>Adds a package to dependencies and installs it.
# Add a package
snpm add react
# Add specific version
snpm add react@18.2.0
# Add as dev dependency
snpm add -D typescript
# Add multiple packages
snpm add react react-domRemoving Packages
snpm remove <package>Removes a package from package.json and node_modules.
snpm remove react
snpm remove react react-domRunning Scripts
snpm run <script>Runs a script defined in package.json.
# Run build script
snpm run build
# Pass arguments (use -- to separate)
snpm run test -- --watchLifecycle Scripts
snpm supports standard lifecycle scripts that run during installation.
{
"scripts": {
"preinstall": "echo 'Running before install'",
"install": "node-gyp rebuild",
"postinstall": "echo 'Running after install'",
"prepare": "npm run build"
}
}- preinstall: Runs before dependencies are installed.
- install / postinstall: Runs after dependencies are installed.
- prepare: Runs after install and before publish (also runs on local
snpm installwithout arguments).
By default, snpm blocks install scripts for security. You must explicitly allow packages to run scripts via SNPM_ALLOW_SCRIPTS="pkg1,pkg2" or by configuring onlyBuiltDependencies in snpm-workspace.yaml.
Performance
snpm is designed for speed.
Warm Path Optimization
If your node_modules is up to date with package.json and snpm-lock.yaml, snpm install finishes in milliseconds (50-100ms typ.). It performs an "early exit" check to avoid unnecessary work.
Lockfile-less Install
Even without a lockfile, snpm uses aggressive caching and parallelization to resolve and install dependencies rapidly.
Upgrading Packages
snpm upgradeUpdates all packages to their latest versions within semver constraints.
# Upgrade all packages
snpm upgrade
# Upgrade specific packages
snpm upgrade react react-dom
# Upgrade production dependencies only
snpm upgrade --productionChecking for Updates
snpm outdatedShows which packages have newer versions available.
# Check all dependencies
snpm outdated
# Check production dependencies only
snpm outdated --productionGlobal Store
Packages are downloaded once to a global store and reused across all projects. The store location is platform-specific:
- macOS:
~/Library/Application Support/io.snpm.snpm/packages - Linux:
~/.local/share/snpm/packages - Windows:
%LOCALAPPDATA%\snpm\snpm\data\packages
Override with the SNPM_HOME environment variable (packages stored in $SNPM_HOME/data/packages).
This saves disk space and makes subsequent installs much faster.
Lockfile
snpm-lock.yaml ensures deterministic installs. Always commit it to version control.