yarnpkg / yarnpkg/berry

[Feature]: `yarn workspaces focus` should make all subsequent operations "focused"

Open
#2,129 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

  • I'd be willing to implement this feature
  • This feature can already be implemented through a plugin

Describe the user story

Essentially https://twitter.com/VLecrubier/status/1301620546589913088.

Our current workflow when building a module/artifact on CI (with yarn v1, fwiw) is:

  • a custom script that does yarn workspaces info and finds a package and its dependencies - it then runs rm -rf on all other packages and runs yarn in root (so essentially yarn workspaces focus, but will modify lockfile)
  • we then use oao to run yarn build in all packages which has that command following the inverse dependency tree etc.

That last step is still needed if we were to migrate to Yarn v2 as we cannot do yarn workspaces foreach -pt run build as yarn will run that in all workspaces rather than the ones focus has... focused.

Describe the solution you'd like

After running yarn workspace focus all further yarn workspaces * commands should respect the fact we're currently "focused" and not do work on all workspaces. I'm specifically after yarn workspaces foreach run, but I think other commands like yarn why or yarn up should also only operate on the "focused" workspace and its dependencies.

As an aside, for this I think it'd make more sense if focus just "focused" without installing anything. So yarn workspaces focus foobar would just set some somewhere in .yarn/ I guess, and when we then run yarn install afterwards, only foobar (and its dependencies) would be "installed".

Describe the drawbacks of your solution

Not sure... It would probably mean more forking of logic ("all workspaces" vs "some workspaces") in multiple places, but I don't think there's any drawbacks beyond the implementation aspect of it?

Describe alternatives you've considered

Not use yarn workspaces focus at all as it doesn't work for our use cases and keep using a manual approach.

Additional context

Happy to chat on Discord about what other stuff we do on CI to build if applicable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the command entry points for yarn workspaces focus and yarn workspaces foreach run, then inspect how workspace selection is represented. Done means subsequent workspace operations consistently honor the focused workspace and its dependencies, including the requested foreach behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.