Reputation: 2160
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?
Upvotes: 11
Views: 5611
Reputation: 63
I just want to add, that with yarn berry, you can use the -T
option on the run command.
yarn run -T my-top-level-script
Upvotes: 2
Reputation: 245
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.
Upvotes: 3
Reputation: 9692
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
Upvotes: 10