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(npm): support Yarn 2 offline cache and zero-installs #7220

Merged
merged 11 commits into from
Oct 19, 2020

Conversation

ylemkimon
Copy link
Contributor

This PR adds support for Yarn 2 offline cache and zero-installs.

Examples: https://github.com/ylemkimon/renovate-berry/pull/2, https://github.com/ylemkimon/renovate-berry/pull/3

/cc @arcanis Could you check whether this is correct/enough to support zero-installs?

@ylemkimon ylemkimon mentioned this pull request Sep 8, 2020
@ylemkimon ylemkimon force-pushed the yarn-2-zero-installs branch 2 times, most recently from 163faf8 to 52659ef Compare September 9, 2020 01:04
@ylemkimon ylemkimon force-pushed the yarn-2-zero-installs branch from 52659ef to de99046 Compare September 9, 2020 01:15
@rarkins
Copy link
Collaborator

rarkins commented Sep 9, 2020

The refactoring makes this a little hard to review changes. Ideally do it before or after the PR which makes the changes, so that it's clear which bits are refactor-only and which is the part that needs reviewing.

@ylemkimon
Copy link
Contributor Author

ylemkimon commented Sep 9, 2020

@rarkins Only the second commit 06ac7aa?diff=split&w=1 is the relevant change.

const yarnrc = await getFile(upath.join(lockFileDir, '.yarnrc'));
const yarnrcYml = await getFile(upath.join(lockFileDir, '.yarnrc.yml'));

if (yarnrc) {
Copy link

Choose a reason for hiding this comment

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

I'd recommend to switch those two blocks (first check for .yarnrc.yml, then for .yarnrc). In my work repo for instance, we have both a .yarnrc and a .yarnrc.yml, with the first one pointing to a binary explaining that the global Yarn isn't recent enough because it doesn't read .yarnrc.yml, and needs to be upgraded.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a minimum version of Yarn v1 that supports "bootstrapping" Yarn v2?

Copy link

Choose a reason for hiding this comment

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

Yarn 1 reading paths from .yarnrc.yml started with 1.18.0. Before that it was still possible, but you had to put the right path in both files.

Copy link
Contributor Author

@ylemkimon ylemkimon Sep 9, 2020

Choose a reason for hiding this comment

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

Updated the PR 😄

}
} else if (yarnrcYml) {
// Yarn 2 (offline cache and zero-installs)
const config = parseSyml(yarnrcYml);
Copy link

Choose a reason for hiding this comment

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

Fwiw, the name is a bit misleading but it's regular YAML, so you can use any parser you want, not necessarily the Yarn one. Or you can use the Configuration class from @yarnpkg/core (which would take care of the default values, etc), but it's perhaps a bit more complicated than necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arcanis Thank you for your valuable comments!

parseSyml is already used to parse the lockfile:

const parsed = parseSyml(yarnLockRaw);
and @yarnpkg/parsers seems to use js-yaml so I think it's OK and would give more consistent behavior with Yarn, e.g., empty file handling.

@ylemkimon ylemkimon marked this pull request as draft September 9, 2020 07:48
@ylemkimon ylemkimon marked this pull request as ready for review September 9, 2020 08:09
@ylemkimon ylemkimon force-pushed the yarn-2-zero-installs branch from 1837f31 to 06342b6 Compare September 9, 2020 08:22
@JamieMagee JamieMagee merged commit c15d301 into renovatebot:master Oct 19, 2020
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 23.53.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@brummelte
Copy link

Thank you. I've tested it and it works now.

It does commit the changes in the cache folder.

@Robula
Copy link

Robula commented Nov 25, 2020

Is 23.53.0 live on Github? I'm not seeing this change in effect.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants