question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alamothecommented, Dec 2, 2021

--from works, but it’s very confusing that I have to specify it given that:

  • I’m already in that workspace.
  • It’s surprising that --from reverses from dependents to dependencies. The docs do not suggest anything like that.
0reactions
alamothecommented, Jan 28, 2022

Right now we use this to build:

yarn workspaces foreach -R -ptv --from xyz run build

Thoughts:

  • Why should I specify -R? That should be the default
  • Why should I specify -t? That should be the default
  • Why should I specify -p? That should be the default
  • Why should I specify -v? That should be the default
  • Instead of --from which requires the name of the workspace, it could only accept --up or --down which should be the direction from the current workspace that I am in.
Read more comments on GitHub >

github_iconTop Results From Across the Web

`yarn workspaces foreach` | Yarn - Package Manager
yarn workspaces foreach run build. Run build script on current and all descendant packages in parallel, building package dependencies first :.
Read more >
yarn berry foreach workspaces not building packages in order ...
Start by including the workspace-tools yarn plugin: yarn plugin import workspace-tools. After doing that you should be able to do:
Read more >
Rethinking the “One Ring To Rule Them all” Monorepo manager
I'm replacing the NX call with the yarn workspace run command and ... the plugin which allows us to use the “foreach” command...
Read more >
The Case for Monorepos: A sane Workspace Setup (Part 2)
This tells TypeScript to pre-build the package and cache information about it. ... yarn workspaces foreach run my-task --parallel# pnpm
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
We will be using TypeScript, Yarn workspaces, Lerna, and Jest. The release of the ... That is why we can't use --parallel flag...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found