Skip to content

feat: add Yarn Modern yarn install --immutable#1823

Closed
MikeMcC399 wants to merge 6 commits into
cypress-io:masterfrom
MikeMcC399:yarn-modern-install
Closed

feat: add Yarn Modern yarn install --immutable#1823
MikeMcC399 wants to merge 6 commits into
cypress-io:masterfrom
MikeMcC399:yarn-modern-install

Conversation

@MikeMcC399

@MikeMcC399 MikeMcC399 commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Situation

If yarn.lock is detected, the action installs using yarn --frozen-lockfile. Although this works for Yarn v1 Classic and Yarn Modern, it is deprecated for Yarn Modern and causes a warning.

Because of this, the action documentation section Yarn Modern currently advises using the install-command parameter to install Yarn Modern as a workaround.

Change

If yarn.lock is detected, examine the contents of the beginning of the lockfile. Yarn Modern lockfiles typically begin like this:

# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
  version: 10
  cacheKey: 10c0

If __metadata: is detected, Yarn Modern is assumed and yarn install --immutable is used. Although --immutable is set by default in CI, applying it explicitly makes the intent clearer.

There is no change to the command used to install Yarn v1 Classic, yarn --frozen-lockfile, which remains the default after yarn.lock detection, in order to avoid a breaking change for Yarn v1 Classic users.

The Yarn Modern workflows are modified to remove the install-command parameter workaround:

The following README sections are updated to describe the changes:

The CHANGELOG.md is updated with the expected new version v7.5.0.

Verification

Yarn Classic

Run the workflow example-yarn-classic.yml

Confirm that installation step "Test with Yarn Classic" shows the following and is successful:

/usr/local/bin/yarn --frozen-lockfile

Yarn Modern

Run the workflow example-yarn-modern.yml

Confirm that installation step "Test with Yarn Modern" shows the following and is successful:

/opt/hostedtoolcache/node/24.18.0/x64/bin/yarn install --immutable

Yarn Modern pnp

Run the workflow example-yarn-modern-pnp.yml

Confirm that installation step "Test with Yarn Modern" shows the following and is successful:

/opt/hostedtoolcache/node/24.18.0/x64/bin/yarn install --immutable

Note that verification continues to use npx to test potentially the wrong version of Cypress in Yarn Modern pnp. This was described in issue #971 and is not targeted for a fix. Cypress documentation prefers the node-modules setting for Yarn Modern, and notes that pnp is not compatible with Cypress component testing.


Note

Low Risk
Install-path change is limited to Yarn Modern lockfiles and preserves Classic behavior; mis-detection is unlikely given the __metadata marker.

Overview
When a yarn.lock is present, the action now detects Yarn Modern by looking for __metadata: in the first bytes of the lockfile. Modern projects get yarn install --immutable by default; Yarn Classic still uses yarn --frozen-lockfile, so existing v1 behavior is unchanged.

Docs and v7.5.0 changelog describe the new default. Yarn Modern example workflows no longer need the install-command: yarn install workaround; the PnP example only keeps its custom command for running Cypress.

Reviewed by Cursor Bugbot for commit 1515e84. Bugbot is set up for automated code reviews on this repo. Configure here.

@cypress-app-bot

Copy link
Copy Markdown
Collaborator

@MikeMcC399 MikeMcC399 self-assigned this Jul 4, 2026
@MikeMcC399 MikeMcC399 added the type: enhancement New feature or request label Jul 4, 2026
@MikeMcC399 MikeMcC399 marked this pull request as ready for review July 4, 2026 13:41
Detect Yarn Modern and install with
yarn install --immutable
@MikeMcC399 MikeMcC399 force-pushed the yarn-modern-install branch from 1de1763 to 75f48d0 Compare July 6, 2026 08:25
@MikeMcC399 MikeMcC399 requested a review from mschile July 6, 2026 17:28
Comment thread index.js Outdated
Comment thread index.js Outdated
const isYarnModern = () => {
if (!useYarn()) return false
const fd = fs.openSync(yarnFilename, 'r')
const buffer = Buffer.alloc(256)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The 256-byte window encodes an assumption about the Yarn header length. It's correct (__metadata: lands ~byte 127), but a one-line comment explaining why 256 is sufficient might help future maintainers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No longer checking only at the start, so I've removed this complication.

@MikeMcC399 MikeMcC399 marked this pull request as draft July 8, 2026 10:42
@MikeMcC399

Copy link
Copy Markdown
Collaborator Author

It appears that all versions of Yarn work with --frozen-lockfile

so it may be simpler and better for maintenance not to merge this PR, but instead to document that the deprecation warning from Yarn Modern can be ignored.

I'm trying to get clarification from yarnpkg/berry#7212.

Leaving in draft for the moment.

@MikeMcC399

Copy link
Copy Markdown
Collaborator Author

I'm withdrawing this PR.

  • The Yarn maintainer wants to keep --immutable deprecated
  • Using the contents of yarn.lock is not a reliable or documented way of determining the version of Yarn. Yarn Modern and Yarn zpm are sharing the same lockfile content
  • The current instructions and examples for using Yarn Classic and Yarn Modern are reliably working at the moment
  • If Yarn does at some point officially deprecate Yarn Classic, then installation support should be revisited (see also Yarn v1 Classic unsupported - deprecation is due #1819). At the moment there are still 8-10 Million downloads of Yarn Classic / week

Thanks @jennifer-shehane in any case for your review and comments!

@MikeMcC399 MikeMcC399 closed this Jul 9, 2026
@MikeMcC399 MikeMcC399 deleted the yarn-modern-install branch July 9, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use yarn --frozen-lockfile only for Yarn v1 Classic

3 participants