pm x
Execute packages without installing
Overview
The pm x command executes packages directly from the registry without permanently installing them. It’s the Better PM equivalent of npx, pnpx, or bunx, automatically using the right tool for your package manager.
Syntax
pm x <package> [...args]
Arguments
package string required
The package or command to execute
args string[]
Arguments to pass to the executed command
Examples
Run Package Binary
pm x typescript --version
Running: pnpx typescript --version
Version 5.0.0
Execute One-off Command
pm x create-vite my-app
Running: pnpx create-vite my-app
Run CLI Tool
pm x prettier --write .
Running: pnpx prettier --write .
Execute with Arguments
pm x eslint --init
Running: pnpx eslint --init
Run Versioned Package
pm x typescript@4.9.0 --version
Running: pnpx typescript@4.9.0 --version
Package Manager Mapping
Better PM automatically uses the appropriate execution tool:
| Package Manager | Tool Used | Example |
|---|---|---|
| pnpm | pnpx |
pnpx create-vite |
| bun | bunx |
bunx create-vite |
| npm | npx |
npx create-vite |
From src/commands/x.ts:13-14:
const execBin =
pm.name === 'pnpm' ? 'pnpx' : pm.name === 'bun' ? 'bunx' : 'npx';
Use Cases
Project Scaffolding
Create new projects without global installs:
pm x create-next-app my-app
pm x create-vite my-app --template react
pm x degit user/repo my-project
One-time Tools
Run tools you don’t need permanently:
pm x prettier --check .
pm x eslint --fix src/
pm x markdownlint **/*.md
Version Testing
Test different package versions:
pm x typescript@5.0.0 --version
pm x typescript@4.9.0 --version
pm x typescript@latest --version
CI/CD Scripts
Run commands without adding to dependencies:
pm x semantic-release
pm x commitizen
pm x lint-staged
Common Commands
Create Projects
pm x create-next-app@latestpm x create-vitepm x create-remix@latestpm x create-astro@latestDevelopment Tools
pm x prettier --write .pm x eslint --initpm x tsc --initpm x playwright installGenerators
pm x license mit > LICENSEpm x gitignore nodepm x readme-md-generatorHow It Works
From src/commands/x.ts:10-19:
export const xCmd = cli.Command.make('x', { args: argsArg }, (args) =>
Effect.gen(function* () {
const pm = yield* PackageManagerService;
const execBin =
pm.name === 'pnpm' ? 'pnpx' : pm.name === 'bun' ? 'bunx' : 'npx';
const passthrough = Array.from(args.args);
const cmd = ShellCommand.make(execBin, ...passthrough);
yield* Console.log(`Running: ${execBin} ${passthrough.join(' ')}`);
yield* runShellCommand(cmd);
}).pipe(Effect.provide(PackageManagerLayer)),
);
The command:
- Detects your package manager
- Maps to the appropriate execution binary (npx/pnpx/bunx)
- Passes all arguments through
- Executes the command
Benefits
No Global Installs
Keep your global environment clean:
# Instead of:
npm install -g create-vite
create-vite my-app
# Use:
pm x create-vite my-app
Always Latest Version
Run the latest version without updating:
pm x create-next-app@latest
# Always gets the newest version
Try Before Installing
Test tools before adding to package.json:
pm x vitest
# Try it out first
# If you like it:
pm add -D vitest
Package Manager Agnostic
Same command works everywhere:
pm x prettier --write .
# Works with pnpm, bun, or npm
Performance
Execution tools cache packages for faster subsequent runs:
# First run (downloads package)
pm x prettier --version
# ~2-3 seconds
# Second run (uses cache)
pm x prettier --version
# ~200ms
Best Practices
Use for Generators
# Perfect for project creation
pm x create-vite my-app
Use for One-off Tasks
# Great for occasional commands
pm x prettier --check .
Install for Repeated Use
# If used frequently, install it
pm add -D prettier
pm run format
Pin Versions for Consistency
# In CI/CD, use specific versions
pm x prettier@2.8.0 --check .
Common Workflows
Quick Project Setup
pm x create-vite my-app --template react-ts
cd my-app
pm install
pm run dev
Format and Lint
pm x prettier --write .
pm x eslint --fix src/
Generate Files
pm x license mit > LICENSE
pm x gitignore node > .gitignore
Run Scripts
pm x tsx src/script.ts
pm x ts-node src/script.ts
Related Commands
- pm run - Run package.json scripts
- pm add - Install packages permanently
- pm install - Install all dependencies