Yarn v2 gitignore
Asked Answered
L

1

74

I upgraded yarn from v1.22.0 to v2.0.0-rc.29. It generated .yarn folder with:

  • folders: cache, releases, unplugged
  • files: build-state.yml

Should I add whole .yarn folder to .gitignore? Or maybe some nested folders in there like .yarn/cache?

Also, what to do with .pnp.js. Do I commit it, or add to .gitignore

Lamond answered 12/2, 2020 at 8:35 Comment(0)
T
97

See the Questions & Answers section of the documentation. It has changed several times, so for the most up to date answer just click that link!

But in the StackOverflow spirit of "no link-only answers" here's a snapshot:

Which files should be gitignored?

If you're using Zero-Installs:

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

If you're not using Zero-Installs:

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

Note that, of the paths you mention, only .yarn/releases should not be in .gitignore.

Telepathy answered 12/2, 2020 at 8:46 Comment(11)
UPD: answer is outdated. Check Q&A section, mentioned above.Lamond
@AlexanderPanteleev Thank you, updated. That's what you get for adhering to StackOverflow policy of "no link-only answers"... :(Telepathy
"Which files should be gitignored?" Simple: Anything that's generated as part of the build process. Ideally, you only check in what you modify yourself.Hamil
@cmaster-reinstatemonica No, that's too simple. For example, yarn.lock is never modified directly by the user but should be checked in nonetheless. Same, apparently, for the cache (?!), releases and plugins subdirectories of .yarn, which are explicitly un-ignored above, despite probably never being hand-edited. In general, if a tool creates or changes files that the user doesn't directly care about, documentation like this is necessary to decide which of those files should be checked in and which should be gitignored.Telepathy
Pro tip: if you activated @yarnpkg/plugin-node-modules, and can see a "node_modules" folder in your project, you're not using the zero-installs approach, even if you can still see the ".yarn/cache" folder.Exactly
How do I know if my project is Zero-Install? Installed using from yarn installation page but it doesn't tell me if it's a Zero-Install or not.Phyllous
How can i know if using zero installs?Trichinosis
If you have to ask, you're not using Zero-Installs.Telepathy
This is overly complicatedBalfour
@transang Please direct your complaints to the Yarn developers. This answer is just quoting their official documentation.Telepathy
The link is dead now, good thing the answer included a copy of the essential information!Peggiepeggir

© 2022 - 2024 — McMap. All rights reserved.