I'm wondering: if your terminal's current working directory is inside a yarn workspace, is there a way to run a yarn script that's defined at the project root without changing the current directory to be outside of a workspace?
For instance, you can run a command for a particular workspace by running yarn workspace workspace-name script-name
but is it possible to use that yarn workspace
command to target not a subpackage, but the root package itself?
I couldn't find a way to do it with yarn workspace
, but you can do it by specifying the current working directory (cwd
) when running the root command. Assuming you're running your command from ~/packages/subpackage
, you'll need to go back two times with ../..
:
yarn --cwd="../.." my-root-script
Scripts that contain a :
in their name can be run from anywhere!
For example, your root script called "root:something"
can be called from within any workspace by running yarn root:something
.
Note that this even works if the :
script is not a root script, but a workspace script. See yarn docs.
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