feat: add Yarn Modern yarn install --immutable#1823
Conversation
|
Detect Yarn Modern and install with yarn install --immutable
1de1763 to
75f48d0
Compare
| const isYarnModern = () => { | ||
| if (!useYarn()) return false | ||
| const fd = fs.openSync(yarnFilename, 'r') | ||
| const buffer = Buffer.alloc(256) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
No longer checking only at the start, so I've removed this complication.
|
It appears that all versions of Yarn work with
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. |
|
I'm withdrawing this PR.
Thanks @jennifer-shehane in any case for your review and comments! |
yarn --frozen-lockfileonly for Yarn v1 Classic #1822Situation
If
yarn.lockis detected, the action installs usingyarn --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-commandparameter to install Yarn Modern as a workaround.Change
If
yarn.lockis detected, examine the contents of the beginning of the lockfile. Yarn Modern lockfiles typically begin like this:If
__metadata:is detected, Yarn Modern is assumed andyarn install --immutableis used. Although--immutableis 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 afteryarn.lockdetection, in order to avoid a breaking change for Yarn v1 Classic users.The Yarn Modern workflows are modified to remove the
install-commandparameter 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-lockfileYarn 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 --immutableYarn 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 --immutableNote that verification continues to use
npxto 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 thenode-modulessetting for Yarn Modern, and notes thatpnpis 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
__metadatamarker.Overview
When a
yarn.lockis present, the action now detects Yarn Modern by looking for__metadata:in the first bytes of the lockfile. Modern projects getyarn install --immutableby default; Yarn Classic still usesyarn --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 installworkaround; the PnP example only keeps its customcommandfor running Cypress.Reviewed by Cursor Bugbot for commit 1515e84. Bugbot is set up for automated code reviews on this repo. Configure here.