Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From inside a yarn workspace subpackage, run a root-level script

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?

like image 714
osdiab Avatar asked Nov 14 '22 23:11

osdiab


2 Answers

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
like image 192
pmrotule Avatar answered May 23 '23 06:05

pmrotule


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.

like image 35
Andre Brdoch Avatar answered May 23 '23 05:05

Andre Brdoch