Problem/Motivation

Drupal 10.0.x is currently still using Yarn 1 ("Yarn Classic"). Per https://github.com/yarnpkg/yarn#contributing-to-yarn:

The 1.x codebase is fairly old and will only accept security fixes. For new features or bugfixes, please see our new repository and its contribution guide.

That's been the case since Feb. 2020. I can't find any information about when security fixes for Yarn 1 will cease or how much notice the project will give prior to then.

Proposed resolution

Update to Yarn 4 by following the migration steps from https://yarnpkg.com/getting-started/migration.

We have 2 options of using yarn 4 in core now:

1. Keep executable file in code as suggested in 3109556-yarn-4-to-11x MR https://yarnpkg.com/features/caching#zero-installs
2. Continue with experimental https://nodejs.org/api/corepack.html#corepack as suggested in 3109556-4-1-1-corepack

Remaining tasks

Testing instructions

  • In node js. 16+
  • cd core + corepack enable + yarn install
  • run different yarn build/watch etc. tasks from /core/package.json scripts{} section
  • sure that all scripts work as before

User interface changes

API changes

Data model changes

Release notes snippet

Yarn 4 and Corepack are now required for Drupal core development. Review the change record on Yarn 4 for more information and troubleshooting recommendations for corepack.

Issue fork drupal-3109556

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lauriii created an issue. See original summary.

lauriii’s picture

gábor hojtsy’s picture

Is it a must have to update to Yarn 2?

kingdutch’s picture

Given some community backlash and the fact that Yarn 1 isn't going to be abandoned anytime soon, I'd encourage to stick to Yarn 1 for now.

As a build tool it should be relatively easy to update at a later stage : )

(If really needed yarn set version can be used to specify a Yarn version on project level)

gábor hojtsy’s picture

BTW reason I am asking is we have plenty to do for Drupal 9 (beta), and a dependency coming out with a new version does not and should not automatically mean we need to update. For example, Symfony 5 is very well out and we are not going to update to it due to support timelines. CKEditor 5 is out but we cannot update to it due to incompatibilities and ecosystem concerns, etc. So we need to look at a must have/need to scale as well as consider this in context of the timeline we are aiming for with Drupal 9 (both how soon we want the beta and how long we want to support Drupal 9).

damienmckenna’s picture

Tagging as a requirement for Drupal 9.0.0-beta1.

justafish’s picture

Priority: Major » Minor
Issue tags: -Drupal 9.0.0-beta1 requirement

I don't think we need to worry about this right now, the discussion in the yarn community is still very much ongoing on how this would be released (maybe even as a different binary). yarn 1 isn't going to disappear and will still receive security updates.

damienmckenna’s picture

Should we consider splitting this into two: a) make a decision on what happens for Drupal 9, just so there can be a decision on what happens with Yarn for D9 and be able to close that issue, and b) make a plan for Yarn 2? We could rename this one to "Determine Yarn plan for Drupal 9" and create a separate one for Yarn 2?

lauriii’s picture

I agree with the statement that we're probably not in a hurry to upgrade Drupal to use Yarn 2. I do still think that at minimum we have to ensure that Drupal either works with Yarn 2 when it's released, or that we have a proper warning in place for users who try to use Yarn 2 with Drupal. We have to also make sure that both of these are true with DrupalCI, but that will likely have to be a follow-up issue specific to DrupalCI.

bnjmnm’s picture

#9:

I do still think that at minimum we have to ensure that Drupal either works with Yarn 2 when it's released, or that we have a proper warning in place for users who try to use Yarn 2 with Drupal.

Another option comes to mind, which is enforcing the use of Yarn 1 and providing that version via Core. I believe this should be possible with something like yarn policies set-version '^1', but haven't yet validated this as I'm having trouble getting Yarn 2 working in my dev environment. I'm going to try this out on a VM and report back, provided someone doesn't comment here explaining why enforcing Yarn 1 is not a good option.

xjm’s picture

Priority: Minor » Normal
Issue tags: +beta target

 

finnsky’s picture

Assigned: Unassigned » finnsky

gonna review it.

finnsky’s picture

StatusFileSize
new3.43 MB

1) Added per project installed yarn 2. Almost all works with some build changes.
It is possible to use both Yarn 1 and 2 in same time. In this patch Yarn2 force enabled. To use Yarn1 rename .yarnrc.yml into anything
Details: https://yarnpkg.com/getting-started/install#per-project-install

2) I grouped build\watch\log script files into `/core/scripts/common/`
Because they are equal for both postcss/js and needed for same filesystem operations.
and `yarn build:css & yarn build:js & yarn build:jqueryui` didn't worked after update to yarn 2.
compile css and compile js tasks are still individual and extendable.

3) Only Nightwatch task still broken, not sure how to check binary file yet.
Because in yarn cache it looks like `/core/.yarn/$$virtual/nightwatch-virtual-5ae4fbd7b4/0/cache/nightwatch-npm-1.3.4-277dc0a684-2.zip/node_modules/nightwatch/bin/nightwatch`
Maybe we need to use https://nightwatchjs.org/guide/running-tests/#programmatic-api which was added `Since v1.0, Nightwatch`
Current nightwatch script was added before 1.0 was released

4) Keeped jquery UI build still same because there is no need to group it. I think it will be removed one day.

5) Added `eslint-import-resolver-node` because of fail in eslint tasks

6) removed "stylelint-checkstyle-formatter" because of fail in stylelint.
Changed this task output to `verbose` own stylelint.
This plugin seems very outdated.
https://plugins.jenkins.io/checkstyle/ is deprecated anyway.

7) Removed "stylelint-no-browser-hacks" for same reasons.

finnsky’s picture

Assigned: finnsky » Unassigned
Status: Active » Needs review
xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev
Issue tags: -beta target

Today during the committer meeting we discussed this and agreed that, given that yarn 1 is no longer being marked legacy, we will stick with yarn 1 (rather than yarn 2 or npm) in 8.9/9.0.

finnsky’s picture

But we can still take some part of this patch related to optimisation of build scripts.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

nod_’s picture

andypost’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

This wasn't in the correct issue tree so it got overlooked. Do we need to start looking into this?

effulgentsia’s picture

Title: Prepare for Yarn 2 » Prepare for Yarn 3 or 4

Yarn 3.2 is out and in that post they're saying that they're now working towards Yarn 4.

nod_’s picture

farbtastic and joyride prevent us from using a newer version as far as i can see.

effulgentsia’s picture

We can remove farbtastic if we do either #1651344: Use color input type in the color.module or #2808151: [policy] Move the Color module to a contributed project when Bartik is deprecated.

For joyride, #3238507: Drupal 10 JavaScript dependency plan says "Remove from Drupal 10... Needs issue". Is that true? Does Tour module not use joyride anymore? If so, let's get that removal issue opened and started.

effulgentsia’s picture

Title: Prepare for Yarn 3 or 4 » Update to Yarn 3 and prepare for Yarn 4
Version: 9.4.x-dev » 10.0.x-dev

Moving to 10.0.x on the assumption that #24 prevent us from doing it in 9.4.

Also, retitling for what I think is more accurate. The "and" in the issue title might be a signal that we should split this into two issues :)

nod_’s picture

followed the steps in https://yarnpkg.com/getting-started/migration#step-by-step for now. This is still using the node_modules folder. So it's not using the Zero-Install feature.

Yarn 1 is in maintenance mode only since 2020, and while there is no date for the end of support, the next step for yarn 1 is end of support so let's get ready before that.

xjm’s picture

 

xjm’s picture

Note that the test failure was a known random, but I can't requeue tests because there's a merge conflict.

nod_’s picture

using the new yarn version means we're committing the yarn cli tool (in core/.yarn/releases/yarn-3.2.0.cjs) which is about 2.5MB of JS. might need to exclude that from the release tarball or something maybe?

nod_’s picture

Issue summary: View changes
nod_’s picture

drupal ci uses yarn 1.x in the setup steps before the commit check, will need to be updated at some point.

nod_’s picture

Tried to exclude the binary from the repo, but that makes yarn crash. We do have to keep that in the source.

longwave’s picture

The title talks about Yarn 3 but the IS only mentions upgrading to Yarn 2.

effulgentsia’s picture

Title: Update to Yarn 3 and prepare for Yarn 4 » Update from Yarn 1 to Yarn 3

Adding our starting point (Yarn 1) to the issue title for clarity. Also, removing the "prepare for Yarn 4" part, since that seems like it should be a separate issue if/when we want to do that, and Yarn 4 doesn't look particularly close (https://github.com/yarnpkg/berry/issues/3591 still has a bunch of empty checkboxes).

effulgentsia’s picture

Am I reading the MR correctly that it removes the Farbtastic library (per #24), but not the Color module, and yet Color module tests still pass even with the Farbtastic library removed?

If so, is that an indication that we're missing some important test coverage in Color module?

effulgentsia’s picture

Issue summary: View changes
Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: -Needs issue summary update +Drupal 10 beta should-have
Related issues: +#3270899: Remove Color module from core

Updated the issue summary. Setting status to "Needs work" because the merge request needs a rebase.

Also raising the priority to Major and tagging as a should-have for beta. In #3118149-74: [meta] Requirements for tagging Drupal 10.0.0-beta1, I added it to the must-have list, but I don't know if that's accurate, so tagging here as a should-have to surface the uncertainty, and then we can make the two match once we decide which it is.

quietone’s picture

nod_’s picture

Title: Update from Yarn 1 to Yarn 3 » Update from Yarn 1 to Yarn 4

we don't need to checkin the binary anymore thanks to corepack

The preferred way to manage Yarn is through Corepack, a new binary shipped with all Node.js releases starting from 16.10. It acts as an intermediary between you and Yarn, and lets you use different package manager versions across multiple projects without having to check-in the Yarn binary anymore.

nod_’s picture

Title: Update from Yarn 1 to Yarn 4 » Update from Yarn 1 to Yarn 3

bit too optimistic there, binary still around :/

nod_’s picture

Title: Update from Yarn 1 to Yarn 3 » Update from Yarn 1 to Yarn 4
Issue summary: View changes
Status: Needs work » Postponed

Ok, we need to wait for yarn 4 to not have the binary checked in, so postponing on that.

https://github.com/yarnpkg/berry/issues/3591

xjm’s picture

Version: 10.0.x-dev » 11.0.x-dev

 

catch’s picture

Title: Update from Yarn 1 to Yarn 4 » [11.x] Update from Yarn 1 to Yarn 4
Version: 11.0.x-dev » 11.x-dev
Issue tags: +Major version only

finnsky’s picture

Status: Postponed » Needs review

Yarn 4 in rc. So we may test it in 11.x

smustgrave’s picture

Status: Needs review » Needs work

Seems updating caused some test errors.

finnsky’s picture

Looks like yarn fixed in Drupal ci

finnsky’s picture

heddn’s picture

The IS needs a (hopefully minor) update to reflect the current status of affairs. Yarn 4 is now fully released.

finnsky’s picture

Status: Needs work » Needs review

It can be reviewed and tested manually because pipeline failure related to old version of yarn used in gitlab CI
#49

longwave’s picture

Do we really have to ship the code for yarn inside the core directory? Can we instead rely on the user installing yarn themselves? Many sites won't need to run it at all.

We also need to make the GitLab CI scripts (which also live in the repo) use the new version.

finnsky’s picture

Scripts are in repo but Docker templates outside.
https://git.drupalcode.org/project/drupalci_environments/-/blob/dev/dock...

I don't think we need to run extra scripts in CI container in this ticket.

ambient.impact’s picture

Regarding the pipeline failure: I ran into this same issue in trying to use Yarn 3.x and 4.x for the current 2.x revamp of the RefreshLess module (see #3393105: Hotwire Turbo minimum viable implementation if you're interested by the way); here's our current .gitlab-ci.yml that took me a lot of swearing and late hours last night to finally get working; it's well documented so should explain everything.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new19.39 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mstrelan’s picture

Issue summary: View changes

Removed mentions of color module from IS since it was removed in 10.0.x. Also removed comment about waiting for Yarn 4 to be released since that is also old news.

finnsky’s picture

RE #52

About yarn files which are stored in repo.

1. It allows us not to define which version of yarn should be installed. Should be only node image. Even with pre installed different version of yarn.

In current MR:

docker run -it --rm --name yarn -v "$PWD":/usr/src/app -w /usr/src/app node:20-alpine yarn && yarn build

Will work fine.

And we will don't care about this https://github.com/nodejs/docker-node/blob/62c2e3cfb17ba8d9167b0daebbff9...

2. About `Many sites won't need to run it at all.`
We can say same about https://git.drupalcode.org/project/drupal/-/tree/11.x/core/scripts/css?r...
or a lot of directories that are in core.

longwave’s picture

yarn.cjs is 2.6Mb. Those other scripts that you have spotted are about 1kb each.

#54 looks like it might have a solution where we can install Yarn purely inside GitLab CI?

finnsky’s picture

I guess it will help ;)

finnsky’s picture

CI mostly fine now

we need to remove --cwd from yarn commands and call them only form core dir
https://github.com/yarnpkg/berry/issues/4908

1. Spell-checking command should be configured.
2. .gitlab-ci/pipeline.yml Nightwatch command needs some love.

I really don't think that 2.6MB is critical.

Especially if we compare this with the opportunities it gives us

ambient.impact’s picture

Regarding committing the yarn-x.x.x.cjs: It's what modern Yarn recommends to do so that you always have a working copy of Yarn. Yes, it's a couple of megabytes, but if it's only in the Git repository to be used for compiling assets and other dev tasks, it can be left out of releases.

longwave’s picture

The problem is that the release process will have to be modified to take that into account, at present this would be shipped with all future releases.

Asking a bigger question: what does yarn do for us that npm (or perhaps pnpm) does not? They do not depend on living in the repository, as far as I know.

finnsky’s picture

Related issues:
finnsky’s picture

Related issues:

I think this question has own discussion.

finnsky’s picture

Status: Needs work » Needs review

Finally brute forced :)

Adding this to review not in terms of code.
(Some DevOps gurus can make it better I'm sure)

But in terms of approach, seems we are ready to go.

Some js files changes included to MR because yarn linters not silent now ;)

Please review.

longwave’s picture

Why have the JS files been reformatted? IIRC we use prettier to format, so it should be the same if the locked version of prettier is unchanged? You say "yarn linters not silent now", was there a bug somewhere before?

finnsky’s picture

@longwave
Yes for some reason linter failed.
https://git.drupalcode.org/issue/drupal-3109556/-/jobs/334117

I only wanted to pass all tests here. Js linting can be moved to own ticket.

nod_’s picture

all right, wanted to make sure we could use yarn with corepack only, it's simpler than #54 because we have a package.json with a packageManager entry.

Using yarn like this present some issues:

Not sure if we should go with this or with the executable committed to the repo, in any case it works as expected.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new5 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

longwave’s picture

Is it feasible to do corepack enable in the initial Yarn step and then pass whatever it does as an artifact to the child jobs?

Or we could just move it to a global before_script so it runs automatically on all jobs?

Or even, do it in the base images so it's always available?

nod_’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot

I don't think we can pass whatever corepack enable does as an artifact. Probably a before script makes more sense, I don't have strong preference, whatever works is good with me. I'm more concern of existing devs not having this working. I think we need the yarnPath if an existing yarn exec already exists. Can someone test it?

ambient.impact’s picture

@longwave:

Asking a bigger question: what does yarn do for us that npm (or perhaps pnpm) does not? They do not depend on living in the repository, as far as I know.

You're right that npm and pnpm don't rely on placing themselves in the repository like Yarn does. It took me a bit of time to adjust when moving from npm. The Yarn documentation does a pretty good job of detailing what it offers. One big difference is that, by default, it doesn't create a node_modules directory at all, but abstracts calls to packages, which are actually stored in archive files; again, the Yarn Plug'n'Play documentation has a lot of info about their architecture and the benefits of it, and of particular interest are performance and predictability, and of particular interest to CI:

Shared installs across disks

Related to the previous point, Yarn PnP allows to reuse the same package artifacts across all projects on the disk. Unlike pnpm, which uses a content-addressable store where each file from each package needs to be hardlinked into its final destination, the PnP loader directly references packages via their cache path, removing a lot of complexity.

smustgrave’s picture

what's a recommended way for testing this one?

Believe issue summary has been updated so removing that tag.

finnsky’s picture

@smustgrave

Just need to be runned /core yarn scripts in "node": ">= 18.12" for first MR.

For second MR also should be https://nodejs.org/api/corepack.html enabled

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

So I applied MR 4698 and just clicked around. Performed some basic tasks like create a content type, view block, etc. Didn't notice anything that broke. Think this may have missed the 10.2 window but maybe get in early for 10.3?

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

I have only skimmed the Issue Summary. I see that there are two MR on this issue and the remaining tasks states that there is a failing test. However, the tests for the two MR are passing. The issue summary is out of date.

I am tagging this for an issue summary update. In that, include which MR is considered RTBC and then rebase it so it is up to date.

Thanks!

finnsky changed the visibility of the branch 11.x to hidden.

finnsky’s picture

Issue summary: View changes
finnsky’s picture

Status: Needs work » Needs review

Rebased both MRs

finnsky’s picture

finnsky’s picture

Seems were some random pipeline failures. Now `both branches ready for review

finnsky’s picture

smustgrave’s picture

Status: Needs review » Needs work

Seems to have a merge block.

But with 11.x now open wonder if it would be good to try and get in.

finnsky changed the visibility of the branch 3109556-yarn-4-to-11x-corepack to hidden.

finnsky’s picture

Status: Needs work » Needs review

It was easier to create new MR instead of rebase corepack branch.
I think we ready to go with this approach even experimental.

Keeping executable branch for example of approach for review.

finnsky’s picture

I've added yet another MR for tests that js/css/yaml linters will triggered.
Seems all tasks triggered and passed well

quietone’s picture

Title: [11.x] Update from Yarn 1 to Yarn 4 » Update from Yarn 1 to Yarn 4
smustgrave’s picture

Mind updating the issue summary with the option you’re going with. And maybe quick sentence for which MR should be reviewed. Or if any can be hidden.

finnsky changed the visibility of the branch test-css-js-yaml-changes to hidden.

finnsky changed the visibility of the branch 3109556-yarn-4-to-11x to hidden.

finnsky’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Really do think it would be good to get in to 11.x

finnsky’s picture

Status: Reviewed & tested by the community » Needs work

Some scaffold error here. Not sure how to fix

finnsky’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Issue tags: +Needs change record

I think we need a change record that tells core developers what to do. I also wonder about the impact of working on 11.x and 10.x - is this going to make it harder?

finnsky’s picture

@alexpott

git co 3109556-4-1-1-corepack && yarn -v
Already on '3109556-4-1-1-corepack'
Your branch is up to date with 'drupal-3109556/3109556-4-1-1-corepack'.
4.1.1

then

git co 11.x && yarn -v                  
Switched to branch '11.x'
Your branch is up to date with 'origin/11.x'.
1.22.21

Switch happends easy.

longwave’s picture

Was expecting to tag this for docs updates but we actually already tell developers to run corepack enable: https://www.drupal.org/about/core/policies/core-change-policies/frontend...

A change record is still worthwhile for those that already had Yarn 1 and haven't used corepack yet.

alexpott’s picture

I've just swapped over to using corepack locally and now my core/package.json file changes whenever I run a command. That's really annoying. If we're telling people to use corepack great but we need to update package.json in 10.3 and 10.2 to have the "packageManager": "yarn@1.22" key.

alexpott’s picture

nod_’s picture

can't commit this one but RTBC +1

longwave’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs change record

Change record for review: https://www.drupal.org/node/3428571

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

CR reads well, tested on my macbook that it worked

longwave’s picture

Status: Reviewed & tested by the community » Fixed

Alright, time to land this. Tested locally back and forth between Yarn 1 and 4 and haven't run into any issues, and we backported the packageManager setting already to previous branches. The changes to .gitlab-ci.yml might make future CI changes trickier to backport, I think we should consider copying those to 10.3.x as well so we have corepack on both sides, but that can be done in a followup.

Committed ad10de3 and pushed to 11.x. Thanks!

Also published the change record.

  • longwave committed ad10de38 on 11.x
    Issue #3109556 by finnsky, nod_, longwave, effulgentsia, Ambient.Impact...

longwave’s picture

Issue tags: +11.0.0 release notes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Issue summary: View changes

Adding a release note snippet since the CR has important info for core contributors.