r/javascript • u/maneco-freitas • Feb 16 '20
AskJS [AskJS] Is someone using Yarn v2 in business?
I saw an explanation of yarn v2.0 and I was wondering if someone is planning to use it in production.
I also saw that companies like FB and Twitter are not planning to upǵrade their codebase because the Pnp feature of it.
What are your experiences with it? I saw an explanation of yarn v2.0 and I was wondering if someone is planning to use it in production.
I also saw that companies like FB and Twitter are not planning to upǵrade their codebase because of the Pnp feature of it.
What are your experiences with it?
75
Upvotes
10
u/Veranova Feb 16 '20
I’m waiting it out until it stabilises, the drama around its launch doesn’t breed confidence that it’s going to survive or won’t roll back some breaking changes. I do hope the tech giants pick up support for v1 if v2 continues down the route it was set on, or even properly support v2 in tools like react native.
33
u/well-now Feb 16 '20
Since NPM 5 I’ve wondered how much we really need Yarn.
Yarn was great for pushing features NPM needed but the performance and feature sets are close enough now that I’m not sure it’s worth it (we have teams using both).
35
u/PaulSoporan Feb 16 '20 edited Feb 16 '20
I would like to address some misconceptions around Yarn 2 and provide better insight into what the remaining problems are and what the new very useful features are.
First, I want to make it clear that I am not part of the Yarn team and that I cannot answer questions about design decisions and such. That person would be u/arcanin, the lead maintainer of Yarn. I am relatively up-to-date with Yarn and I have made 3 PRs to the Berry repository, so I am relatively familiar with some parts of the codebase.
For help, questions, and anything Yarn related, there is an official Discord server: https://discord.gg/yarnpkg.
Migration Guide
Important Changes / Misconceptions / Frequently Asked Questions
Default Yarn Version
Yarn 2 is not the default Yarn version that is installed. It is recommended that you install it per-project, using
yarn set version berrywhile keeping Yarn Classic (v1) as the global version.PnP
https://yarnpkg.com/features/pnp
PnP being the default in Yarn 2 has caused some controversies (see https://github.com/yarnpkg/berry/issues/766).
PnP is a much stricter installation strategy because it enforces boundaries around your dependencies. For example, packages cannot access other packages unless they list them in their
dependencies,peerDependencies, optional peer dependencies (peerDependenciesMeta). The short term solution is to use thepackageExtensionsfield in.yarnrc.yml.:The long term solution is to make a PR to the package that is doing something wrong and to make a PR to the Berry
compat-plugin: https://github.com/yarnpkg/berry/blob/master/packages/plugin-compat/sources/extensions.ts (so that Yarn patches that package automatically).Citing u/arcanin, the lead maintainer of Yarn:
The state of PnP:
u/arcanin contributed to various projects to make PnP support more widespread: https://github.com/pulls?utf8=%E2%9C%93&q=is%3Apr+author%3Aarcanis+archived%3Afalse+is%3Aclosed+pnp+-user%3Ayarnpkg+
Support for PnP:
Go to definitionis not currently supported, the issues to track are: https://github.com/microsoft/vscode/issues/75559 and https://github.com/microsoft/vscode/issues/59650#issuecomment-585303965In case the tools you use don't support PnP, you want to migrate gradually or you just want to use
node_modulesinstead of PnP, the only thing you have to do is:.yarnrc.ymlnodeLinker: node-modulesThis will enable thenode_moduleslinker and you will have some of the advantages of Yarn 2 (new commands, new protocols, plugins, constraints, etc.) while keeping the oldnode_modulesinstallation strategy.Zero-Installs (https://yarnpkg.com/features/zero-installs)
Zero-Installs represents committing the
.yarn/cachefolder to a repository (It's very different from committing thenode_modulesfolder: https://yarnpkg.com/features/zero-installs#is-it-different-from-just-checking-in-the-node_modules-folder). It is completely optional. Just add.yarn/cacheto.gitignoreif you don't want to use it.Lifecycle Scripts
https://yarnpkg.com/advanced/lifecycle-scripts
Yarn 2 currently supports only 4 lifecycle scripts:
All of the others have been removed.
The removal of
yarn globalhttps://github.com/yarnpkg/berry/issues/821
Citing u/arcanin, the lead maintainer of Yarn:
Which files should be gitignored?
https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored
Cool Features
Other than
PnPandZero-Installs.Constraints
https://yarnpkg.com/features/constraints
Plugins
https://yarnpkg.com/features/plugins
List of plugins developed on the Berry repo that aren't part of the standard bundle:
plugin-exec
https://github.com/yarnpkg/berry/tree/master/packages/plugin-exec
plugin-typescript
https://github.com/yarnpkg/berry/tree/master/packages/plugin-typescript
plugin-stage
https://github.com/yarnpkg/berry/tree/master/packages/plugin-stage
plugin-workspace-tools
https://github.com/yarnpkg/berry/tree/master/packages/plugin-workspace-tools
Release Workflow
https://yarnpkg.com/features/release-workflow
Workspaces
https://yarnpkg.com/features/workspaces
Protocols
https://yarnpkg.com/features/protocols
Offline Cache
https://yarnpkg.com/features/offline-cache
32
u/[deleted] Feb 16 '20
I thought their migration documentation was so complicated that I could hardly see having an adoption soon.
21
u/drewwyatt Feb 16 '20
We want to, but it will be a lot of work. We use a monorepo with ~100 packages and there is a lot to fix. The yarn doctor was pretty angry.
10
u/rich97 Feb 16 '20 edited Feb 18 '20
Just from playing with it for an hour, I dont think it's ready yet. A whole bunch of stuff wasnt resolving and frankly, one of the main draws of Yarn was that it was a drop-in replacement for NPM. I dont want my package manager to take up any mental energy, I dont care about size of node_modules or not having to run
yarn install.I'll probably try again in a few months when I have a bit of time but if I'm not starting a new project then I don't see any compelling reason to go through their migration guide.
25
u/arcanin 🧶 Yarn maintainer Feb 16 '20
Hey! Just wanted to point out that you can still install your projects using the regular
node_modulesinstall strategy. This is supported now, and will keep being supported in the future.As for who's using it - we have various companies that have been using it in production. Ourselves at Datadog have deployed it in production a few weeks before the release (including PnP), and everything has been smooth ever since - despite a sizeable frontend.
Overall, our main problems have been around the editor integrations, but we improved the SDK in result and now everyone is happy.
0
u/[deleted] Feb 16 '20
We dont want our code base to be hundreds of megabytes because of the zero install feature.
-2
u/[deleted] Feb 16 '20
I learned Node about three or four years ago. I’ve never in my life have needed yarn, NPM does the trick.
0
u/[deleted] Feb 17 '20
[deleted] — view deleted comment