CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pnpm

Fast, disk space efficient package manager for Node.js with hard links, symlinks, and monorepo support

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

script-running.mddocs/

Script Running and Execution

Execute package scripts, run packages without installing, and manage development workflows with pnpm's comprehensive script running capabilities.

Capabilities

Run Package Scripts

Execute scripts defined in package.json with full lifecycle support and environment setup.

/**
 * Run scripts defined in package.json
 * Executes with proper PATH setup and lifecycle hooks
 */
pnpm run <script> [options]
pnpm run-script <script> [options]

Options:

  • --recursive, -r - Run script in all workspace packages
  • --filter <pattern> - Run script in filtered packages
  • --parallel - Run scripts in parallel across workspaces
  • --stream - Stream output from parallel runs
  • --if-present - Don't fail if script doesn't exist
  • -- - Pass remaining arguments to the script

Usage Examples:

# Run development server
pnpm run dev

# Run tests
pnpm run test

# Run script with arguments
pnpm run build -- --watch

# Run in all workspaces
pnpm run -r test

# Run in filtered packages
pnpm run --filter "@myorg/*" build

# Run tests in parallel
pnpm run -r --parallel test

Execute Without Installing (dlx)

Download and execute packages without installing them globally, similar to npx but faster.

/**
 * Download and execute packages without installing
 * Equivalent to npx but uses pnpm's fast store
 */
pnpm dlx <pkg> [args]

Usage Examples:

# Create React app
pnpm dlx create-react-app my-app

# Run TypeScript compiler
pnpm dlx tsc --version

# Execute with specific version
pnpm dlx create-next-app@latest my-next-app

# Execute with arguments
pnpm dlx eslint src/ --fix

Execute in Package Context

Execute arbitrary commands with access to locally installed packages.

/**
 * Execute commands in package context
 * Runs commands with node_modules/.bin in PATH
 */
pnpm exec <command> [options]

Options:

  • --recursive, -r - Execute in all workspace packages
  • --filter <pattern> - Execute in filtered packages
  • --parallel - Execute in parallel across workspaces

Usage Examples:

# Run TypeScript compiler
pnpm exec tsc

# Check installed package version
pnpm exec -- webpack --version

# Run in all workspaces
pnpm exec -r -- eslint .

# Run in filtered packages
pnpm exec --filter "frontend-*" -- jest

Create Projects from Templates

Create new projects using create-* templates with initialization and setup.

/**
 * Create projects from templates
 * Uses create-* packages to scaffold new projects
 */
pnpm create <template> [options]

Usage Examples:

# Create React app
pnpm create react-app my-app

# Create Next.js app
pnpm create next-app my-next-app

# Create Vite project
pnpm create vite my-vite-app

# Create with TypeScript
pnpm create next-app --typescript my-ts-app

Restart Services

Restart application by running stop and start scripts in sequence.

/**
 * Restart application services
 * Runs npm stop followed by npm start
 */
pnpm restart [options]

Options:

  • --recursive, -r - Restart in all workspace packages
  • --filter <pattern> - Restart in filtered packages

Usage Examples:

# Restart current package
pnpm restart

# Restart all services in workspace
pnpm restart -r

# Restart specific services
pnpm restart --filter "api-*"

Install and Test

Install dependencies and immediately run tests - useful for CI environments.

/**
 * Install dependencies and run tests
 * Combines install and test steps for CI workflows
 */
pnpm install-test [options]
pnpm it [options]

Usage Examples:

# Install and test
pnpm install-test

# Install and test with options
pnpm it --frozen-lockfile

Script Context and Environment

Environment Variables

pnpm sets up the following environment variables when running scripts:

# Available in all scripts
npm_command          # Current command name (e.g., 'run', 'test')
npm_lifecycle_event  # Current script name (e.g., 'dev', 'build')
npm_package_name     # Package name from package.json
npm_package_version  # Package version from package.json
PNPM_SCRIPT_SRC_DIR  # Directory containing package.json

PATH Setup

pnpm automatically adds the following to PATH during script execution:

# Directories added to PATH
./node_modules/.bin              # Local package binaries
<store>/node_modules/.bin        # Global store binaries
<workspace-root>/node_modules/.bin  # Workspace root binaries (if applicable)

Lifecycle Scripts

pnpm respects npm lifecycle scripts and runs them automatically:

# Pre/post scripts run automatically
prestart    # Before 'start' script
start       # Main start script  
poststart   # After 'start' script

prebuild    # Before 'build' script
build       # Main build script
postbuild   # After 'build' script

pretest     # Before 'test' script
test        # Main test script
posttest    # After 'test' script

Workspace Script Execution

Parallel Execution

Run scripts across multiple workspace packages simultaneously:

# Run scripts in parallel
pnpm run -r --parallel build
pnpm run -r --parallel test

# Control concurrency
pnpm run -r --parallel --max-workers=4 build

Sequential Execution

Run scripts in dependency order across workspace packages:

# Run in topological order
pnpm run -r build

# Run with dependency awareness
pnpm run -r --workspace-concurrency=1 build

Filtering

Execute scripts only in specific workspace packages:

# Filter by package name pattern
pnpm run --filter "*api*" build
pnpm run --filter "@myorg/*" test

# Filter by changed files
pnpm run --filter "...[HEAD~1]" test

# Filter by dependencies
pnpm run --filter "...@myorg/core" build

Error Handling

Exit Codes

pnpm preserves exit codes from executed scripts:

# Script exits with code 1 on failure
pnpm run test  # exits with 1 if tests fail

# Continue on error in workspaces
pnpm run -r --no-bail test  # continues even if some tests fail

Failure Handling

Control behavior when scripts fail in workspace scenarios:

# Stop on first failure (default)
pnpm run -r test

# Continue despite failures
pnpm run -r --no-bail test

# Report all results
pnpm run -r --reporter=append-only test

Install with Tessl CLI

npx tessl i tessl/npm-pnpm

docs

configuration.md

index.md

package-inspection.md

package-management.md

script-running.md

store-management.md

workspace-management.md

tile.json