Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set yarn classic for corepack enabled #1408

Merged

Conversation

MikeMcC399
Copy link
Contributor

Issue

If a user has Node.js' experimental Corepack enabled, then invoking yarn may cause Yarn Modern (version 2 and later) instead of Yarn Classic (version 1) to be used. The Cypress Real-world app is however not compatible with Yarn Modern and calling yarn dev, after installing dependencies with yarn, may then cause the app to crash.

Note that Yarn Modern > Starting with Yarn > Installation describes the preferred way to manage Yarn as being through Corepack. Users may have other projects on their client system, besides RWA, which use Yarn Modern, and so the scenario where Corepack is enabled should be catered for by RWA.

Changes

"packageManager": "[email protected]" is added to package.json so that if corepack is enabled it will use Yarn Classic and not Yarn Modern.

The instructions for users who have not executed corepack enable remain unchanged.

The advice that the project is not compatible with Yarn Modern also remains unchanged.

Detailed changes

  1. README.md is updated with instructions that work for both traditional Yarn Classic users and those who have executed corepack enable.

  2. Yarn is set to Classic

    The following is invoked

    yarn set version classic

    to tie the project to Yarn Classic methods for installation, even if Yarn Modern has been set as the global default version through corepack.

  3. The following is merged into .gitignore to make sure only the required Yarn files are considered for git commit to the repo:

    .pnp.*
    .yarn/*
    !.yarn/patches
    !.yarn/plugins
    !.yarn/releases
    !.yarn/sdks
    !.yarn/versions
    

    See Yarn Modern > Which files should be gitignored?.

Verification

Using Node.js 18.16.1 according to .node-version.

Yarn Classic

Install Yarn Classic globally and run yarn install:

corepack disable
npm install yarn@latest -g
git clean -x -d -f
yarn install
git status

Confirm that Yarn v1.22.19 is used to install, that there are no errors and no files identified by git for committing.

Yarn Modern

Install Yarn Modern globally using corepack and run yarn install:

npm uninstall yarn -g
corepack enable
corepack prepare yarn@stable --activate
git clean -x -d -f
yarn install
git status

Confirm that Yarn v1.22.19 is used to install, that there are no errors and no files identified by git for committing.

@cypress-app-bot
Copy link

@MikeMcC399 MikeMcC399 force-pushed the set/corepack-yarn-classic branch from 02f75a3 to 175aaed Compare September 11, 2023 13:34
@MikeMcC399 MikeMcC399 marked this pull request as ready for review September 11, 2023 14:01
Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

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

gave everything a go and looks good on my end

@AtofStryker AtofStryker merged commit 757e178 into cypress-io:develop Sep 11, 2023
@MikeMcC399
Copy link
Contributor Author

gave everything a go and looks good on my end

Many thanks @AtofStryker! 👍🏻

@MikeMcC399 MikeMcC399 deleted the set/corepack-yarn-classic branch September 11, 2023 16:24
@emilyrohrbough
Copy link
Member

@MikeMcC399 I see you checked in .yarn/releases/yarn-1.22.19.cjs this repo and it has 14k+ bits of data that is now installed each time this repo is clones and checked out. We use this repo to test in Cypress and this is downloaded multiple times in CI to run tests against the latest changes to Cypress. Is there any reason users cannot configure this themselves locally if they want to run this experimental feature?

@MikeMcC399
Copy link
Contributor Author

@emilyrohrbough

You're referring to CI testing in CircleCI I guess? Would you like to open a new issue for this, since it is apparently causing you problems.

I can take a look to see if there is a better way of doing this. The PR was based on following the official Yarn Modern documentation as explained in the related issue #1404, however I recognize that Yarn is still in transition mode between the frozen Yarn Classic version and the Yarn Modern v4 version which was released two weeks ago. It presents problems to try to balance between the two worlds!

#1423 suggests migrating away from Yarn Classic. This is probably more of a medium- / long-term goal though.

@MikeMcC399
Copy link
Contributor Author

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.

Support corepack enabled environments for yarn install
4 participants