yarnpkg / berry

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

[Feature][Breaking?] workspaces recursion issues #4692

Open xenoterracide opened 2 years ago

xenoterracide commented 2 years ago

(is workspaces in this repo? I don't know...)

Describe the user story

As a corporate developer, I have to use the npm script name in CI, workspace commands become recursive.

    "test": "yarn build && yarn :concurrently --names constraints,lint,jest,workspaces -- 'yarn constraints' 'yarn lint' 'yarn :jest /unit/' 'yarn :test:all'",
    ":test:all": "yarn workspaces foreach --exclude @cof/e1-lib --parallel --topological-dev --verbose run test",

this seems all good and well, except when I renamed the library after some discussions, I forgot to rename it in this command. what happened then is that it started recursing. Honestly I'm having trouble with the idea that if I run yarn test that it also runs it in every workspace, or that with workspaces it's considering the root package as a valid location. I can see though that as designed it's not aware of the current location. this is actually massively unintuitive and frustrating, that in any given workspace I have to run yarn workspace mywork :foo because otherwise it would run all of them.

Describe the solution you'd like

In my worst case I think that making the root repo excluded by default would be good. Thus my suggestion would be that at the root

    ":test:all": "yarn workspaces foreach --parallel --topological-dev --verbose run test",

would be equivalent to

    ":test:all": "yarn workspaces foreach --exclude @cof/e1-lib --parallel --topological-dev --verbose run test",

Describe the drawbacks of your solution

breaks backwards compatibility

Describe alternatives you've considered

alternatively an --exclude-root so that naming doesn't matter would also be acceptable, but I'm having trouble with why I would want a script like this to also run itself.

Additional

could yarn be generally more package aware? so that in sub workspaces doing yarn foo won't run it like it's the root repo? and or maybe you could have yarn workspace this foo again to avoid the naming issue... There are plenty of workarounds, but it's all kind of frustrating.

I still think it would be awesome if yarn could have its own scripts defintions that aren't partial to the npm spec. maybe something that could go in .yarnrc.yml and be more optimized (not forking), that however could start as a contrib plugin

nettybun commented 1 year ago

This is extremely confusing. Thanks for posting your workaround!

I can't even run yarn build without it descending into recursive hell:

dashboard-enterprise on ξ‚  will-this-let-me-hate-yarn-less [$✘!?] via  v16.14.0 took 6s 
❯ yarn workspaces foreach --interlaced --verbose --topological-dev run build
➀ YN0000: [dashboard-enterprise]: Process started
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: Process started
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: Process started
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: Process started
^C
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: Process exited (exit code 129), completed in 0s 486ms
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: Failed with errors in 0s 490ms
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: Process exited (exit code 1), completed in 3s 366ms
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: ➀ YN0000: Failed with errors in 3s 369ms
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: [dashboard-enterprise]: Process exited (exit code 1), completed in 6s 99ms
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
➀ YN0000: [dashboard-enterprise]: ➀ YN0000: Failed with errors in 6s 102ms
➀ YN0000: [dashboard-enterprise]: Process exited (exit code 1), completed in 8s 565ms
➀ YN0000: The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
➀ YN0000: Failed with errors in 8s 573ms

dashboard-enterprise on ξ‚  will-this-let-me-hate-yarn-less [$✘!?] via  v16.14.0 took 9s 

Adding the --exclude flag worked for me:

❯ yarn workspaces foreach --verbose --interlaced --parallel --jobs unlimited --topological-dev --exclude dashboard-enterprise run build

It's sad how long that is compared to lerna run build --stream but oh well.