In the next version of yarn ("berry") the manual states that one should just commit the directory created called .yarn
, but if you use the multi-version setup for yarn, this directory contains the file releases/yarn-berry.js
which seems to be the entire berry version of yarn, taking up more than 2MB of disk.
This just seems really wrong - why should I commit a package manager to git, just to get it to work?
From My experience I would say yes we should commit yarn. lock file. It will ensure that, when other people use your project they will get the same dependencies as your project expected. When you run either yarn or yarn add , Yarn will generate a yarn.
yarn/unplugged should likely always be ignored since they typically hold machine-specific build artifacts. Ignoring it might however prevent Zero-Installs from working (to prevent this, set enableScripts to false ). .
yarn/releases should not be in . gitignore . UPD: answer is outdated. Check Q&A section, mentioned above.
json file that provides information to Yarn about your package. Most packages use some kind of version control system. The most common one is git but Yarn doesn't mind whatever one you choose to use.
The Yarn developers explain the rationale for this in the Installation docs, in the section called "About global installs":
Using a single package manager across your system has always been a problem. To be stable, installs need to be run with the same package manager version across environments, otherwise there's a risk we introduce accidental breaking changes between versions - after all, that's why the concept of lockfile was introduced in the first place! And with Yarn being in a sense your very first project dependency, it should make sense to "lock it" as well.
Once Yarn is tracked and "locked" as a per-project dependency, it ends up getting committed to Git if you follow Yarn 2's zero-install strategy, the rationale for which is explained here.
I'm a newcomer to Yarn, but I spent years working devops, helping developers figure out why their code would sometimes build correctly on half of the team's laptops but not on the other half, or would suddenly start failing to build in CI while continuing to work elsewhere. Trying to keep the version of npm
consistent across every computer and codebase in the company was essentially impossible, given that Node is constantly being upgraded, but locking each project to its own specific version of Yarn -- which, by being committed to Git, is guaranteed to be available in every checkout of that project -- solves this problem.
The official documentation mentions what's should be ignored and what should be committed. It can solve this problem I think. https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
I have written a small tool for those people who don't want to commit Yarn 2+ binary into their git repos, while still benefiting from sticking Yarn version per project. If you already have Yarn 2+ configured in your project just don't want to commit it, you can run:
yarn dlx pinyarn
This command will generate .pinyarn.js
(4KB) which you should commit, instead. .pinyarn.js
will contain URLs inside to download Yarn 2+ and its plugins from the official Yarn Berry GitHub repo. .pinyarn.js
will download binary and plugins from these URLs if they are not downloaded yet.
You can also specify which version of Yarn 2+ you want via:
yarn dlx pinyarn 3
- the latest released Yarn 3 version, or
yarn dlx pinyarn 2.2.2
- version 2.2.2, or
yarn dlx master
- version from latest sources, or
yarn dlx 1638
- version from Pull Request 1638
The pinyarn
tool repo on GitHub:
https://github.com/sysgears/pinyarn
The new docs states using node's newest corepack feature (to date).
This means that when using appropriate node you only need to place a valid packageManager
field value in package.json
and run corepack enable
, e.g.
{
"name": "foo",
"packageManager": "[email protected]",
"scripts": {
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With