berry icon indicating copy to clipboard operation
berry copied to clipboard

enable fallback to root for scripts/bins

Open zachbryant opened this issue 2 years ago • 0 comments

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.
  • [x] I will check that all automated PR checks pass before the PR gets reviewed.

zachbryant avatar Dec 29 '23 18:12 zachbryant