fix: use npx to invoke correct Yarn version instead of relying on Corepack PATH shims - #78
Conversation
…epack PATH shims Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| if [[ "$PKG_MANAGER" =~ ^yarn@1\. ]]; then | ||
| echo "Detected Yarn 1 (Classic)" | ||
| npx --yes "${PKG_MANAGER%%+*}" install --frozen-lockfile | ||
| elif [[ -n "$PKG_MANAGER" && "$PKG_MANAGER" =~ ^yarn@ ]]; then | ||
| echo "Detected Yarn (Berry)" | ||
| yarn install --no-immutable | ||
| else | ||
| # Yarn 1 (Classic) | ||
| echo "Detected Yarn $YARN_VERSION (Classic)" | ||
| yarn install --frozen-lockfile | ||
| YARN_VERSION=$(yarn --version) | ||
| if [[ "$YARN_VERSION" =~ ^[234] ]]; then | ||
| echo "Detected Yarn $YARN_VERSION (Berry)" | ||
| yarn install --no-immutable | ||
| else | ||
| echo "Detected Yarn $YARN_VERSION (Classic)" | ||
| yarn install --frozen-lockfile | ||
| fi | ||
| fi |
There was a problem hiding this comment.
The Yarn 1 path was fixed to invoke the exact pinned version via npx, but the Berry path (line 48-50) and the fallback (line 51-60) still call the ambient global yarn. Since this PR removes corepack enable / corepack prepare --activate, a downstream repo with packageManager: yarn@3.x that calls this shared action would now run whatever yarn is on PATH (Yarn 1 on ubuntu-latest runners) instead of its pinned Berry version, unless their own workflow enables corepack.
This repo is unaffected (it's yarn@1.22.22, and danger.yml still runs corepack enable at the workflow level), so this isn't blocking. But for consistency with the npx approach, was leaving the Berry branch on ambient yarn intentional? It's an asymmetry worth a comment, or applying the same npx "${PKG_MANAGER%%+*}" treatment.
There was a problem hiding this comment.
Yes, downstream repos that use Barry (Yarn 2+) are expected to have the correct yarn version on PATH.
Code ReviewSummaryThis PR fixes Yarn version resolution in the shared Issues Found🟡 Important / Question — Berry path no longer pins its version ( This repo is not affected (it pins Areas Reviewed
Note: the untracked Nice, well-scoped fix with a clear commit history. The only thing worth a second look is the Berry-branch asymmetry above. |
The approach in #77 of using
corepack prepare --activateto routeyarnto the correct version did not work. Each step in a composite action runs in a fresh shell, so PATH changes made bycorepack enabledo not carry over to subsequent steps. As a result,yarn --versionstill returned 4.10.3 despite the activation.This PR replaces that approach with
npx --yes yarn@<version>for Yarn 1 projects.npxfetches and runs the exact version specified in thepackageManagerfield directly, without depending on PATH or Corepack shim setup.For Berry projects, the system
yarnis still used since Berry repos typically manage their own Yarn binary locally. For projects with nopackageManagerfield, the existing version detection fallback is preserved.🤖 Generated with Claude Code