yarnpkg / berry

šŸ“¦šŸˆ Active development trunk for Yarn āš’
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.45k stars 1.11k forks source link

[Feature] Add an option `--topological-peer` for `worspace foreach` #3594

Open EmrysMyrddin opened 3 years ago

EmrysMyrddin commented 3 years ago

Describe the user story

I have a modular project using yarn workspaces with a lot of packages.

To be modular, each packages are small modules that can depend on other packages in the worspace. The final user of the library will have to use multiple packages from our library.

For example, a user will have to use both @cuillere/core and @cuiller/postgres. since @cuillere/postrgres depends on @cuillere/core but the user also have to use this dependency, @cuillere/core is defined as a peer dependency.

Starting from yarn v2, it is no longer required to add peer-dependency as dev-dependency to be able to develop it. So most of our dependencies between our worspaces are defined using only peer-dependency.

Now, I would like to use workspace foreach run build to build each packages following the dependency tree defined by peer-dependencies.

Describe the solution you'd like

The solution is to add a --topological-peer which would behave the same as --topological-dev but with peer-dependencies instead of dev-dependencies.

Describe the drawbacks of your solution

I'm not sure there is clear drawbacks. The only one I see is that it could potentially be dificult to resolve peer-dependencies depending on how it is implemented in Yarn's code.

Describe alternatives you've considered

My alternative for now is to include all my worspaces both in peer-dependecies and dev-dependencies. Whoch is not that anoying, but a little odd since I do it only for yarn worspaces foreach to work properly, not to make my package work.

EmrysMyrddin commented 3 years ago

@arcanis If I want to POC around this, do you have any clue of where to begin with ?

I'm lost since it would be my very first contribution to yarn.

martinstark commented 1 year ago

Just ran into this issue when trying to migrate from yarn classic to berry, I would very much like to see this feature as well.

bamblack commented 1 year ago

Also just ran into this and would love to see this as a feature. Adding peerDependencies to devDependencies feels weird just to get yarn workspaces foreach to behave. It looks like it would be easy enough to add the suggested --topological-peer to foreach.ts like --topological-dev is here and here

martinvillysson commented 1 year ago

Same here, just ran into this and would love to see it as a flag! thx for a nice tool :)

simlmx commented 10 months ago

My workaround was also to use --topological-dev and make sure the dependencies are also devDependencies.

Wouldn't a better solution be to consider all of dependencies, devDependencies and peerDependencies when using the --topological flag?