Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn workspaces run shell command for each

I'd like to use Yarn's Workspaces feature to run a shell command in each of my workspaces.

Yarn supports the yarn workspaces run foo command, but foo must be a script defined in package.json, not an arbitrary command (eg. echo "foobar").

Ideally I'd like to have a single script eg. "foo": "yarn workspaces run echo 'foobar'" in my top level package.json. One workaround is to add a script called foobar to each workspace's package.json, and have the top-level package.json delegate to these, but with a non-trivial number of workspaces this becomes cumbersome to maintain.

like image 266
old greg Avatar asked Aug 05 '26 00:08

old greg


1 Answers

In Yarn 3 (Berry) exec and workspaces foreach commands can be utilised to achieve this. For example: yarn workspaces foreach exec echo 'foobar'

like image 183
h-kippo Avatar answered Aug 07 '26 14:08

h-kippo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!