Skip to content

Detect Yarn Berry before installing Yarn - #1003

Merged
ramonskie merged 2 commits into
masterfrom
fix/yarn-berry-detection
Dec 4, 2026
Merged

ramonskie merged 2 commits into
masterfrom
fix/yarn-berry-detection

Conversation

@ramonskie

@ramonskie ramonskie commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Do not merge yet. This PR depends on the yarn-berry dependency being republished with the correct .js suffix. Review item 1 from the code review: merge cloudfoundry/binary-builder#130 and let the dependency rebuild land before merging this, otherwise the new Yarn Berry integration spec will fail in CI.

Why

Fixes #996.

Run() chose between InstallYarn (Classic) and InstallYarnBerry before ReadPackageJSON() set UsesYarnBerry, so Yarn Berry projects were always given Yarn Classic. Classic then handed off to the project's Yarn 4 release via yarnPath and rejected the Classic-only flag in yarn --version --loglevel notice, failing supply.

Detection only depends on files in the app (yarn.lock, .yarnrc.yml), so it can run much earlier.

What changed

  • Add DetectYarn(), which sets UseYarn from yarn.lock and UsesYarnBerry from .yarnrc.yml, and explicitly clears both when the project is not a Yarn project.
  • Call DetectYarn() in Run() right after LoadNvmrc(), before the Yarn install branch.
  • Reuse DetectYarn() from ReadPackageJSON() instead of duplicating the two FileExists calls.
  • Add unit specs for Classic, Berry, .yarnrc.yml without yarn.lock, and stale-flag reset.
  • Add a Yarn Berry integration fixture (fixtures/yarn/berry) and spec asserting Installed yarn (berry) and Installing node modules (yarn.lock) [yarn berry], and that Classic was not installed.

manifest.yml is intentionally untouched; the releng bot updates the yarn-berry URI after the dependency is rebuilt.

Merge dependency (review item 1)

The new Berry integration spec cannot pass on the current manifest:

  1. manifest.yml still points at yarn-berry_4.18.1_linux_noarch_any-stack_a28ad591.tgz, which is raw yarn.js, not a tarball.
  2. libbuildpack selects the extractor from the URI suffix (vendor/github.com/cloudfoundry/libbuildpack/installer.go, .tar.gz/.tgz branch), so it calls ExtractTarGz and fails with gzip: invalid header before InstallYarnBerry() runs.
  3. This affects both cached and uncached integration matrix legs.

Required order:

Validation

  • go build ./src/...
  • go test ./src/nodejs/supply/ — 140/140 specs pass
  • All non-integration, non-brats packages pass
  • Berry fixture verified with Yarn 4.18.1: yarn install --immutable succeeds and leaves the lockfile unchanged
  • Integration suite requires a CF or Docker platform, so it runs in CI

Run() picked InstallYarn vs InstallYarnBerry before ReadPackageJSON set
UsesYarnBerry, so Berry projects were always given Yarn Classic and then
failed on `yarn --version --loglevel notice` (#996). Extract the
yarn.lock/.yarnrc.yml detection into DetectYarn() and call it before the
install branch.

Add DetectYarn specs and a Yarn Berry integration fixture. The fixture
depends on the yarn-berry dependency being republished as .js, so its
integration spec cannot pass until cloudfoundry/binary-builder#130 lands
and manifest.yml is bumped.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Yarn integration test uses ContainLines for messages separated by intervening logs, so the assertion will fail even when Berry installs successfully.

1 open issue
What changed in this PR

Fixes #996 by detecting Yarn Berry before the buildpack chooses which Yarn version to install.

Changes:

  • Extracts reusable Yarn detection and runs it before package-manager installation.
  • Adds unit coverage for Classic, Berry, marker-only projects, and stale-flag reset.
  • Adds a minimal Berry fixture and deployment integration test.

The PR remains dependent on the corrected Yarn Berry artifact and manifest update described in the merge prerequisites.

File Description
src/​nodejs/​supply/​supply.go Detects Yarn flavor before installation and reuses detection during package parsing.
src/​nodejs/​supply/​supply_test.go Tests Yarn detection and flag reset behavior.
src/​nodejs/​integration/​yarn_test.go Adds Berry installation and deployment coverage.
fixtures/​yarn/​berry/​yarn.lock Supplies a Berry-format lockfile.
fixtures/​yarn/​berry/​server.js Provides a minimal HTTP application for deployment verification.
fixtures/​yarn/​berry/​package.json Defines the fixture application and start command.
fixtures/​yarn/​berry/​.yarnrc.yml Configures Berry to use node modules and global caching.

Review effort: Balanced

Comment thread src/nodejs/integration/yarn_test.go Resolved
@benjaminguttmann-avtq

Copy link
Copy Markdown
Contributor

@ramonskie I think you can rebase this one now

Refactor log expectations for yarn installation.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@benjaminguttmann-avtq benjaminguttmann-avtq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Approval depends on confirming the separate releng manifest update from .tgz to .js and successful cached and uncached integration runs, which remain pending.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@ramonskie
ramonskie merged commit 0669845 into master Dec 4, 2026
8 checks passed
@ramonskie
ramonskie deleted the fix/yarn-berry-detection branch December 4, 2026 12:06
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.

Yarn Berry is detected after Yarn Classic is installed, so Berry projects fail at yarn --version --loglevel notice

3 participants