Skip to content

Override or choose the agent

Sometimes you need to override jpd’s automatic package manager detection. This might be for testing, compatibility, personal preference, or when working with projects that support multiple package managers.

Terminal window
# Test how your project works with different tools
jpd install --agent npm
jpd install --agent yarn
jpd install --agent pnpm
jpd install --agent bun

Even if a project has multiple lock files, you might want to enforce a specific package manager:

Terminal window
# Team policy: always use pnpm
jpd install --agent pnpm
jpd run --agent pnpm build

Some packages or scripts might work better with specific package managers:

Terminal window
# Use npm for a specific installation that has compatibility issues
jpd install --agent npm problematic-package
# Use yarn for the rest of the workflow
jpd run build # Uses detected yarn

Compare installation and execution performance across package managers:

Terminal window
# Time npm installation
time jpd install --agent npm
# Time pnpm installation
time jpd install --agent pnpm

Method 1: Per-Command Override (—agent flag)

Section titled “Method 1: Per-Command Override (—agent flag)”

Override the agent for a single command:

Terminal window
jpd install --agent yarn lodash
jpd run --agent pnpm dev
jpd exec --agent bun create-react-app my-app
jpd update --agent npm

jpd supports these package manager values for the --agent flag:

AgentDescription
npmNode Package Manager
yarnYarn (auto-detects v1 vs v2+)
pnpmFast, disk space efficient PM
bunAll-in-one JavaScript runtime
denoSecure TypeScript/JavaScript runtime
Terminal window
# Install with specific package manager
jpd install --agent yarn
jpd install --agent pnpm react
jpd install --agent npm --dev vitest
jpd install --agent bun --global typescript

The --agent flag can appear in different positions:

Terminal window
# All of these are equivalent
jpd install --agent yarn lodash
jpd install lodash --agent yarn
jpd --agent yarn install lodash

Method 2: Session-Wide Override (Environment Variable)

Section titled “Method 2: Session-Wide Override (Environment Variable)”

Set the JPD_AGENT environment variable to override the default for all commands in your session:

Terminal window
# Set for current session
export JPD_AGENT=yarn
# All jpd commands now use yarn by default
jpd install # Uses yarn
jpd run dev # Uses yarn
jpd update # Uses yarn
# Clear the override
unset JPD_AGENT

Add to your shell configuration file for permanent override:

Terminal window
# Always use pnpm as default
export JPD_AGENT=pnpm

jpd checks for package manager overrides in this order (highest to lowest priority):

  1. Command-line flag: --agent yarn
  2. Environment variable: JPD_AGENT=yarn
  3. Lock file detection: yarn.lock → yarn
  4. PATH detection: First available package manager
  5. Interactive prompt: Ask user to install one
Terminal window
# Set environment default
export JPD_AGENT=npm
# This uses yarn (flag overrides environment)
jpd install --agent yarn
# This uses npm (environment variable)
jpd install
# This uses whatever is detected from lock files (if JPD_AGENT is unset)
unset JPD_AGENT
jpd install

jpd validates agent names and provides helpful error messages:

Terminal window
$ jpd install --agent invalid-pm
Error: the agent flag is set the wrong way use one of these values instead [npm yarn pnpm bun deno]

jpd only accepts these exact values (case-sensitive):

  • npm
  • yarn
  • pnpm
  • bun
  • deno

jpd doesn’t check if the specified agent is installed. If you override to an unavailable package manager, you’ll get the standard “command not found” error from your shell.

Use .env files for project-specific package manager preferences:

Terminal window
# In your project's .env file
JPD_AGENT=pnpm
# jpd automatically loads .env files
jpd install # Uses pnpm for this project

Ensure consistent package manager usage in CI:

# GitHub Actions
- name: Install dependencies
run: jpd install --agent pnpm
env:
JPD_AGENT: pnpm # Backup via environment
- name: Run tests
run: jpd run --agent pnpm test

Use different package managers for different environments:

Terminal window
# Development - use fast local installs
export JPD_AGENT=bun
jpd install
jpd run dev
# Production builds - use npm for compatibility
jpd install --agent npm --production
jpd run --agent npm build

Different packages in a monorepo might prefer different package managers:

Terminal window
# Frontend uses yarn
jpd install --agent yarn --cwd ./apps/frontend/
# Backend uses npm
jpd install --agent npm --cwd ./apps/backend/
# Shared packages use pnpm
jpd install --agent pnpm --cwd ./packages/shared/

See which package manager jpd would use:

Terminal window
jpd agent

Use debug mode to see how jpd selects the package manager:

Terminal window
jpd install --debug
# Shows detection process:
# DEBUG Agent flag is set: yarn
# DEBUG Package manager detected: yarn
# DEBUG Executing command: yarn install

Quickly test which package managers are available:

Terminal window
jpd install --agent npm --dry-run 2>/dev/null && echo "npm available"
jpd install --agent yarn --dry-run 2>/dev/null && echo "yarn available"
jpd install --agent pnpm --dry-run 2>/dev/null && echo "pnpm available"
jpd install --agent bun --dry-run 2>/dev/null && echo "bun available"

Use shell logic to select agents based on conditions:

Terminal window
# Use yarn if available, fallback to npm
if command -v yarn >/dev/null 2>&1; then
jpd install --agent yarn
else
jpd install --agent npm
fi
# Use pnpm for large projects, npm for small ones
if [ $(find . -name "node_modules" -prune -o -name "*.js" -print | wc -l) -gt 100 ]; then
jpd install --agent pnpm # Better for large projects
else
jpd install --agent npm # Simpler for small projects
fi

Create shell functions with preset agents:

Terminal window
# Add to your shell config
function jpnpm() { jpd "$@" --agent npm; }
function jpyarn() { jpd "$@" --agent yarn; }
function jppnpm() { jpd "$@" --agent pnpm; }
function jpbun() { jpd "$@" --agent bun; }
# Usage
jpnpm install lodash # Always uses npm
jpyarn run dev # Always uses yarn
jppnpm update # Always uses pnpm