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.
In Yarn 3 (Berry) exec and workspaces foreach commands can be utilised to achieve this. For example: yarn workspaces foreach exec echo 'foobar'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With