Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable fallback to root for scripts/bins #6047

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zachbryant
Copy link

@zachbryant zachbryant commented Dec 29, 2023

What's the problem this PR addresses?

This PR addresses an issue I noticed while upgrading from yarn v1 to v4: the inability for yarn to fallback to the root workspace for scripts and binaries if not found in the current workspace, while not looking exclusively in either the top level or current workspace.

#6045
...

How did you fix it?

When we're looking for dependencies/scripts available to the package in getPackageAccessibleBinaries, a new flag tells us whether to limit our search to the current workspace workspace (CW) or, if omitted, expand our search to the root workspace (RW). The edited utility is shared between yarn bin and yarn run and keeps the two consistent.

Flags Added

  • For yarn bin
    1. -T,--top-level: same behavior as in yarn run
    2. -C,--current-workspace-only: Limits dep/script search to the CW only
  • For yarn run
    1. -C,--current-workspace-only: As above

I edited yarn bin's flags because we get functionality for free from the utils changes, and for consistency with yarn run if the user needs to debug where their running binaries are.

Scripts Behavior
Based on the flags, we may check the RW for the script and run the same steps as if a script existed in the CW.

Dependencies Behavior
In getPackageAccessibleBinaries: we start by feeding the RW deps into our set, followed by the CW deps. The "fallback" behavior comes from the insertion order, letting binaries.set(name, ...) prioritize the CW's deps.

New Default Behavior
If RW has jest 29 and CW has jest 28, running jest --version in CW will output 28 and yarn bin jest will output the path to v28.

If flag -T is given, we check the top level only (existing functionality). If -C is specified, no deps outside of CW will be considered. If both are specified, -C takes priority.
...

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant