[Feature] Have `yarn workspaces foreach -t` automatically include workspace dependents
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 monorepo with several private packages plus several deployable apps that consume them. Typically, when I want to build an individual app, I’d like to ensure that the packages it depends have up-to-date builds. I’m currently able to build all apps at once with
$ yarn workspaces foreach -A --topological-dev run build
This command lets me build everything while making sure dependents resolve things like TypeScript types in the correct order. However, if I want to build one individual app and its dependencies, I have to re-do all the work Yarn does in traversing the dependency graph to figure out what dependencies need built before passing them as --include
arguments.
Describe the solution you’d like
Say my app is @kherock/app, and it depends on @kherock/package-a and @kherock/package-b. What I’m most interested in right now is that when I run
$ yarn workspaces foreach --include @kherock/app --topological-dev run build
Yarn will additionally run the command for the workspaces of package-a and package-b. I want to say that this is intuitive
behavior given that I’m already concerned with the implications of running foreach
with --topological(-dev)
. If I want to explicitly avoid building certain packages, I can still mark them for exclusion with --exclude
.
Describe the drawbacks of your solution
This does introduce more complexity at the risk of being confusing if not documented properly. I’ll note that the old behavior can be preserved in this implementation without much effort (especially since -A
is being considered for removal in v3):
$ yarn workspaces foreach -A --exclude '*' --include @kherock/app --topological-dev run build
Describe alternatives you’ve considered
I’m also considering making a plugin building off of the existing foreach
command that allows for more powerful queries on the dependency graph (e.g. run x
for all workspaces listing package y
as a dependent or vice-versa).
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
It’s supported, it was implemented in https://github.com/yarnpkg/berry/pull/2835. To do what @kherock is asking for in https://github.com/yarnpkg/berry/issues/2389#issuecomment-762834916 you would run
https://yarnpkg.com/cli/workspaces/foreach#examples
Sounds a lot like the
--recursive
flag https://yarnpkg.com/cli/workspaces/foreach#options-R%2C-recursive