Recursively Run Scripts in All pnpm Workspace Projects

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

While its convenient to be able to use filter commands to run scripts without having to cd into package/app folders, it's still a tedious task if you need to run commands in several projects at once.

It's actually very easy to recursively run a script in all projects with pnpm using the -r flag. For example, pnpm run -r build will go through each project in the workspace and attempt to run the build command.

Instructor: [0:00] We have this Remix app in our apps folder and that shared UI React library node packages folder within our pnpm workspace. We can obviously target the single packages directly using the pnpm filter, let's say shared UI. Let's say we want to run the build here, so we run shared UI build, and it is with them build our shared UI package. [0:24] Sometimes you might want to run commands across all the applications and target, let's say, all the build commands and build all the apps and libraries there. To do that, we can use the -R commands, which recursively runs a given command.

[0:39] We can run pnpm, run -R, build. What this will do is it figures out which packages need to be run. In this case, it's packages shared UI and then apps, my Remix app, we'll run build for both of them. This obviously also works for every other command that you want to run from some package.json script.

egghead
egghead
~ 16 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today