[Feature] yarn workspaces foreach cannot be used to build
See original GitHub issue- I’d be willing to implement this feature (contributing guide)
- This feature is important to have in this repository; a contrib plugin wouldn’t do
Describe the user story
I have a TypeScript monorepo with multiple workspaces that depend on each other (shared libs etc.). With TypeScript, very important part is the build. Say I have a workspace A which depends on B, and workspace B which depends on C. By “depends” I mean that it is listed as a dependency with workspace:* protocol.
When I change B, I would like to make sure that it doesn’t introduce compile errors in A. By looking at https://github.com/DerekZiemba/yarn-V2-workspaces-simple-monorepo I was lead to believe that yarn workspaces foreach can be used for this purpose (which the author of that repo also seems to believe).
I tried both default options and -R but it doesn’t match the expectations. I execute the command inside the workspace B.
The default
~/myrepo/packages/b $ yarn workspaces foreach -vt run compile
➤ YN0000: [b]: Process started
➤ YN0000: [b]: Process exited (exit code 0), completed in 3s 962ms
➤ YN0000: Done in 3s 968ms
If executed inside a workspace, it compiles only the current workspace.
-R
~/myrepo/packages/b $ yarn workspaces foreach -vtR run compile
➤ YN0000: [b]: Process started
➤ YN0000: [b]: Process exited (exit code 0), completed in 3s 797ms
➤ YN0000: [c]: Process started
➤ YN0000: [c]: Process exited (exit code 0), completed in 4s 212ms
➤ YN0000: Done in 14s 303ms
If executed inside a workspace, it compiles the current workspace and its dependencies — which is exactly the opposite of what it needs to do when building. It should instead build B then A.
Describe the solution you’d like
Some combination of the flags to be able to produce the desired behavior for TypeScript builds.
Describe the drawbacks of your solution
This command already has a lot of flags, however they are all very confusing. This might be because I don’t understand other use cases, but I do believe that build is one of the top use cases needed. Perhaps an overhaul of the flags could make the command clearer.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)

Top Related StackOverflow Question
--fromworks, but it’s very confusing that I have to specify it given that:--fromreverses from dependents to dependencies. The docs do not suggest anything like that.Right now we use this to build:
Thoughts:
-R? That should be the default-t? That should be the default-p? That should be the default-v? That should be the default--fromwhich requires the name of the workspace, it could only accept--upor--downwhich should be the direction from the current workspace that I am in.