npm
Install tools published as npm packages. Supports both npm and bun as package managers.
npm-installed tools are externally managed: the package manager owns the files, and .bin() names the executables the package provides so dotfiles can shim them (see .bin() runtime behavior).
Basic Usage
Section titled “Basic Usage”import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("npm", { package: "prettier" }).bin("prettier"));Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
package | string | No | npm package name (defaults to tool name) |
version | string | No | Version or version range (e.g., 3.0.0, defaults to latest) |
packageManager | 'npm' | 'bun' | No | Package manager to use for installation (defaults to 'npm') |
force | boolean | No | Pass --force to npm install -g / bun install -g (defaults to false) |
Examples
Section titled “Examples”Specific Version
Section titled “Specific Version”export default defineTool((install) => install("npm", { package: "prettier", version: "3.0.0", }).bin("prettier"),);The version parameter takes precedence over .version(), and dotfiles update refuses a tool it pins (tool update).
Using Bun
Section titled “Using Bun”export default defineTool((install) => install("npm", { package: "prettier", packageManager: "bun", }).bin("prettier"),);Scoped Package
Section titled “Scoped Package”export default defineTool((install) => install("npm", { package: "@angular/cli", }).bin("ng"),);Install Specific Version
Section titled “Install Specific Version”export default defineTool((install) => install("npm", { package: "typescript", version: "5.8.3", }).bin("tsc"),);How It Works
Section titled “How It Works”- Install: Runs
npm install -g <package>[@version](orbun install -g <package>[@version]whenpackageManager: 'bun'), adding--forcewhenforce: true - Binaries: Each declared
.bin()name is resolved from the package manager’s global bin directory (npm config get prefix+/bin, orbun pm bin -g) - Update check: Compares against
npm view <package> version(npm) orbun pm view <package> version(bun). If that command fails or prints no version, the check fails (tool check)