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.
Why Override the Agent?
Section titled “Why Override the Agent?”Testing Different Package Managers
Section titled “Testing Different Package Managers”# Test how your project works with different toolsjpd install --agent npmjpd install --agent yarnjpd install --agent pnpmjpd install --agent bunTeam Standardization
Section titled “Team Standardization”Even if a project has multiple lock files, you might want to enforce a specific package manager:
# Team policy: always use pnpmjpd install --agent pnpmjpd run --agent pnpm buildCompatibility Issues
Section titled “Compatibility Issues”Some packages or scripts might work better with specific package managers:
# Use npm for a specific installation that has compatibility issuesjpd install --agent npm problematic-package
# Use yarn for the rest of the workflowjpd run build # Uses detected yarnPerformance Testing
Section titled “Performance Testing”Compare installation and execution performance across package managers:
# Time npm installationtime jpd install --agent npm
# Time pnpm installationtime jpd install --agent pnpmMethod 1: Per-Command Override (—agent flag)
Section titled “Method 1: Per-Command Override (—agent flag)”Basic Usage
Section titled “Basic Usage”Override the agent for a single command:
jpd install --agent yarn lodashjpd run --agent pnpm devjpd exec --agent bun create-react-app my-appjpd update --agent npmSupported Agents
Section titled “Supported Agents”jpd supports these package manager values for the --agent flag:
| Agent | Description |
|---|---|
npm | Node Package Manager |
yarn | Yarn (auto-detects v1 vs v2+) |
pnpm | Fast, disk space efficient PM |
bun | All-in-one JavaScript runtime |
deno | Secure TypeScript/JavaScript runtime |
Command Examples
Section titled “Command Examples”# Install with specific package managerjpd install --agent yarnjpd install --agent pnpm reactjpd install --agent npm --dev vitestjpd install --agent bun --global typescript# Run scripts with specific package managerjpd run --agent npm devjpd run --agent yarn buildjpd run --agent pnpm testjpd run --agent bun start# Execute packages with specific tooljpd exec --agent npm create-react-app my-appjpd exec --agent yarn create vite my-appjpd exec --agent pnpm create-next-app my-appjpd exec --agent bun create hono my-appFlag Position
Section titled “Flag Position”The --agent flag can appear in different positions:
# All of these are equivalentjpd install --agent yarn lodashjpd install lodash --agent yarnjpd --agent yarn install lodashMethod 2: Session-Wide Override (Environment Variable)
Section titled “Method 2: Session-Wide Override (Environment Variable)”Setting JPD_AGENT
Section titled “Setting JPD_AGENT”Set the JPD_AGENT environment variable to override the default for all commands in your session:
# Set for current sessionexport JPD_AGENT=yarn
# All jpd commands now use yarn by defaultjpd install # Uses yarnjpd run dev # Uses yarnjpd update # Uses yarn
# Clear the overrideunset JPD_AGENT# Set for current sessionset -x JPD_AGENT yarn
# All jpd commands now use yarn by defaultjpd install # Uses yarnjpd run dev # Uses yarn
# Clear the overrideset -e JPD_AGENT# Set for current session$env:JPD_AGENT = "yarn"
# All jpd commands now use yarn by defaultjpd install # Uses yarnjpd run dev # Uses yarn
# Clear the overrideRemove-Item Env:JPD_AGENT# Set for current session$env.JPD_AGENT = "yarn"
# All jpd commands now use yarn by defaultjpd install # Uses yarnjpd run dev # Uses yarnPersistent Environment Setup
Section titled “Persistent Environment Setup”Add to your shell configuration file for permanent override:
# Always use pnpm as defaultexport JPD_AGENT=pnpm# Always use pnpm as defaultexport JPD_AGENT=pnpm# Always use pnpm as defaultset -x JPD_AGENT pnpmOverride Precedence
Section titled “Override Precedence”jpd checks for package manager overrides in this order (highest to lowest priority):
- Command-line flag:
--agent yarn - Environment variable:
JPD_AGENT=yarn - Lock file detection:
yarn.lock→ yarn - PATH detection: First available package manager
- Interactive prompt: Ask user to install one
Example of Precedence
Section titled “Example of Precedence”# Set environment defaultexport 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_AGENTjpd installValidation and Error Handling
Section titled “Validation and Error Handling”Invalid Agent Names
Section titled “Invalid Agent Names”jpd validates agent names and provides helpful error messages:
$ 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]Supported Agents List
Section titled “Supported Agents List”jpd only accepts these exact values (case-sensitive):
npmyarnpnpmbundeno
Agent Availability
Section titled “Agent Availability”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.
Practical Workflows
Section titled “Practical Workflows”Project-Specific Overrides
Section titled “Project-Specific Overrides”Use .env files for project-specific package manager preferences:
# In your project's .env fileJPD_AGENT=pnpm
# jpd automatically loads .env filesjpd install # Uses pnpm for this projectCI/CD Pipeline Standardization
Section titled “CI/CD Pipeline Standardization”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 testDevelopment vs Production
Section titled “Development vs Production”Use different package managers for different environments:
# Development - use fast local installsexport JPD_AGENT=bunjpd installjpd run dev
# Production builds - use npm for compatibilityjpd install --agent npm --productionjpd run --agent npm buildMonorepo Mixed Usage
Section titled “Monorepo Mixed Usage”Different packages in a monorepo might prefer different package managers:
# Frontend uses yarnjpd install --agent yarn --cwd ./apps/frontend/
# Backend uses npmjpd install --agent npm --cwd ./apps/backend/
# Shared packages use pnpmjpd install --agent pnpm --cwd ./packages/shared/Debugging Agent Selection
Section titled “Debugging Agent Selection”Check Current Agent
Section titled “Check Current Agent”See which package manager jpd would use:
jpd agentDebug Detection Process
Section titled “Debug Detection Process”Use debug mode to see how jpd selects the package manager:
jpd install --debug
# Shows detection process:# DEBUG Agent flag is set: yarn# DEBUG Package manager detected: yarn# DEBUG Executing command: yarn installTest Different Agents
Section titled “Test Different Agents”Quickly test which package managers are available:
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"Advanced Usage Patterns
Section titled “Advanced Usage Patterns”Conditional Agent Selection
Section titled “Conditional Agent Selection”Use shell logic to select agents based on conditions:
# Use yarn if available, fallback to npmif command -v yarn >/dev/null 2>&1; then jpd install --agent yarnelse jpd install --agent npmfi
# Use pnpm for large projects, npm for small onesif [ $(find . -name "node_modules" -prune -o -name "*.js" -print | wc -l) -gt 100 ]; then jpd install --agent pnpm # Better for large projectselse jpd install --agent npm # Simpler for small projectsfiFunction Wrappers
Section titled “Function Wrappers”Create shell functions with preset agents:
# Add to your shell configfunction jpnpm() { jpd "$@" --agent npm; }function jpyarn() { jpd "$@" --agent yarn; }function jppnpm() { jpd "$@" --agent pnpm; }function jpbun() { jpd "$@" --agent bun; }
# Usagejpnpm install lodash # Always uses npmjpyarn run dev # Always uses yarnjppnpm update # Always uses pnpmSee Also
Section titled “See Also”- Complete Commands Reference - Full
--agentflag documentation - Getting Started - Basic jpd usage patterns