Skip to content

pnpm tips and tricks

Tyler Butler edited this page Feb 7, 2023 · 2 revisions

pnpm has a rich filtering syntax to run on a subset of packages. You can run commands only on packages that match a particular scope, depend on specific other packages, those that are in a particular directory, and even those that have been edited since a previous commit.

Filtering can be done with most pnpm commands, including exec, run, add, and remove.

Add dependencies only to packages with another dependency

This example adds mocha-multi-reporters and mocha-json-output-reporter as devDependencies to all packages in the release group that already depend on c8.

pnpm add -D --filter "...^c8" mocha-multi-reporters mocha-json-output-reporter

Run format only on packages changed since main

pnpm run -r --filter "...[origin/main]" format
Clone this wiki locally