Yarn in Depth: Why & How

Rate this content
Bookmark

Since 2017 Yarn proved itself a pillar of JavaScript development incubating numerous features our ecosystem now heavily relies on. As years passed, as competitors improved, so did Yarn, and it's now time today to dive into the features and tradeoffs that make Yarn a truly unique gem of the JavaScript ecosystem.

FAQ

Yarn is a package manager for JavaScript that extends its capabilities to act as a project manager, allowing you to manage scripts, split applications into standalone modules, manage release cycles, monitor script usage, and enforce standards across projects.

Yarn's development is guided by core values such as community contribution, soundness (ensuring the application alerts you to mistakes), and promoting good practices in JavaScript development.

Yarn enhances developer experience by providing default behaviors that simplify command usage, promoting learning and better engineering practices, and integrating features that streamline project management and deployment processes.

Yes, Yarn is versatile enough to be used in both open source and internal projects, offering tools and features like Release Workflow and Zero Installs that support efficient project management and development in various environments.

Yarn transitioned to a modular architecture where the core functionality is separated into distinct modules. This allows for independent development and integration of features, making Yarn extendable and adaptable to specific needs.

As an open source project, Yarn faces challenges like ensuring sustainability and managing a large community of contributors. They address these by relying on community contributions and exploring sponsorship programs to fund their development efforts.

Yarn uses a novel approach like Plug'n'Play (PnP) and Zero Installs to handle dependencies efficiently. PnP avoids node_modules directories, while Zero Installs caches the project's dependencies within the repository for quick access and switching.

Maël Nison
Maël Nison
33 min
01 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Yarn is not just a package manager, it intends to be a project manager with a focus on simplicity and a good developer experience. Yarn's impact on workflows and project management has been positive, improving scalability and release management. It offers features like local fixes, compressed packages, and sharing packages between projects. Yarn's infrastructure and extensive testing ensure compatibility and catch regressions. Yarn is modular, with plans for version 3 and a more powerful plugin ecosystem. The choice between npm and Yarn depends on the project's configuration.

1. Introduction to Yarn and Core Values

Short description:

Today, we're going to talk about what Yarn is and what it can bring you. Yarn is not just a package manager, it intends to be a project manager. It lets you manage scripts, split your application into standalone models, and more. We rely on our contributors to make Yarn sustainable and see it as a project. Soundness is a key value when merging PRs, ensuring that Yarn detects errors and doesn't make uncontrolled assumptions.

Hi everyone, for those who don't know me, my name is Mael. I currently work at Datadog and I've been leading Yarn's development for a few years now. Today, we're going to extensively talk about what it is and what it can bring you. While we won't be able to go into each and every single little quality of life improvements it offers, I hope that by the end of this talk, you will have a better idea of what makes this project unique in our ecosystem.

First, we should discuss what's actually Yarn. If you ask anyone, they will likely tell you that Yarn is a package manager for JavaScript, and they would be mostly right. But it's only part of the story. Yarn is not just a package manager, it intends to be a project manager. One run system. Indeed, if you think about it, Yarn lets you manage scripts. It lets you split your application into standalone models. But as we will see later, it can also be used to manage your releases cycles, to monitor how your team uses your scripts, or even to enforce standards across your monolith. All these tasks go far beyond the typical package manager, and every release pushes the boundaries further by introducing new features.

So, project managers, that sounds nice. How do we get there? What are the things that we look for when managing PRs? We're going to discuss core values. The first thing to realize is that we're a community of contributors. Open source is a very taxing environment, and most projects are struggling finding ways to make their work sustainable, and Yarn isn't exempt. To help with that, we rely a lot on our contributors to be the change that they want to see to contribute back to the project they like. In this way, we don't really see Yarn as a product. We really see it as a project. In practice, it means that our core team spends as much time working on our infrastructure as on the product itself. Recently, we moved from Webpack to ESbuild in order to make building Yarn easier. Multiple comments let you build part of the Yarn binaries from source, so you can easily try out independent features. Yarn is really all about making it possible for you to experiment well past what we as a team could offer by ourselves.

A second important value we are always keeping in mind when merging PRs is soundness. Yarn must tell you if something is wrong in your application. It shouldn't let you make mistakes. It shouldn't let them go unnoticed. It must not make uncontrolled assumptions. This might sound rigid because you have more errors than you used to, but it's really critical whether you author applications or libraries, you need to have confidence that something that works now will also work on your production or when installed by your consumers.

2. Yarn's Impact and Workflows

Short description:

Yarn helps users understand the tool and guides them along the JavaScript DevOps path. Default behaviors and user experience are crucial. Yarn's impact on the work we've made so far has been positive. Workflows like Ready Cycles and Release Workflow have improved scalability and release management. Zero installs keep the project cache within the repository.

Another one is good practices. The JavaScript landscape is large, changes fast and has many very opinionated people. As a package manager we are in a unique position to help our users understand the tool that they are using and to guide them along the hard path. Not only using Yarn should solve a practical need, it should also contribute making you learn and becoming a better engineer along the way in terms of JavaScript DevOps.

We reached the last one of this set, default behaviors, which directly tie into developer experience. Most of our users will only ever use the default commands of our tool, which is a good thing because most of them, they don't have to remember a bunch of command line flags just for the sake of running one specific behavior. For instance, the fact that you can run any script by prefixing it in your CLI with just Yarn, may look a very simple thing, but it surely is one of the reasons some people might find it appealing. User experience is really important and crucial to the Yarn user experience.

We've now seen a bit of what Yarn claims to be. Now, we are going to talk a bit about DevOps. What does Yarn actually do for you, practically speaking? We are going to go over two interesting stories of projects who adopted it. One is an open source project and the other is an internal application that we use at my company. Without surprise, the first one is Yarn itself. Before we dive in, let me tell you a funny story. Back in Yarn 1, we didn't actually use Workspaces to develop Yarn. It was a real problem for us because not only were problems hidden away from the maintainers themselves, we weren't also directly confronted with the values that some features might have. As a result, we were not emerging things even though perhaps we should have just because we couldn't see how impactful they would actually be. When you use Workspaces, it's very apparent that, for example, you need to be able to run a script in all your Workspaces at once. But since we didn't use the Workspaces, it didn't really seem like a huge deal for us at the time. Nowadays, we have an informal rule that the Yarn team needs to use all features shipped into the core, and I believe that had a strong positive impact on the work we've made so far by forcing us to use all the features that we ship as part of Yarn itself.

So, now let's talk about Workflows. The first one we are going to discuss are Ready Cycles. Our previous process back in Yarn 1 was very simple. We just had a single file at the root of the repository, and each PR that people were making was expected to add one line to it. It worked fine, but after switching to a monorepo, it wouldn't have scaled very well since we needed the ability to release each workspace, each package, by itself. So, we developed the Release Workflow, which is not unlike the chance set package that you may know. The idea is that each PR we merge also has to include a little file created by Yarn itself that lists all the workspaces that have been changed by the PR and whether they need to be part of the next release. Our CI validates these files content, and at release time, we simply instruct Yarn to aggregate all version files into classic package bums. Another workflow that we are using are zero installs. The idea is that we decided to keep the cache of the project inside the repository itself.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
You will learn about one of the most popular package managers for JavaScript and its advantages over npm and Yarn.A brief history of JavaScript package managersThe isolated node_modules structure created pnpmWhat makes pnpm so fastWhat makes pnpm disk space efficientMonorepo supportManaging Node.js versions with pnpm
The Zen of Yarn
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
In the past years Yarn took a spot as one of the most common tools used to develop JavaScript projects, in no small part thanks to an opinionated set of guiding principles. But what are they? How do they apply to Yarn in practice? And just as important: how do they benefit you and your projects?
In this talk we won't dive into benchmarks or feature sets: instead, you'll learn how we approach Yarn’s development, how we explore new paths, how we keep our codebase healthy, and generally why we think Yarn will remain firmly set in our ecosystem for the years to come.
Yarn 4 - Modern Package Management
JSNation 2022JSNation 2022
28 min
Yarn 4 - Modern Package Management
Top Content
Yarn 4 is the next major release of your favourite JavaScript package manager, with a focus on performance, security, and developer experience. All through this talk we'll go over its new features, major changes, and share our long-term plans for the project.If you only heard about Yarn without trying it yet, if you're not sure why people make such a fuss over package managers, if you wonder how your package manager can make your work simpler and safer, this is the perfect talk for you!
Security Controls in the JavaScript Supply Chain
JSNation 2022JSNation 2022
28 min
Security Controls in the JavaScript Supply Chain
The omnipresence of open-source software and low-barrier of entry on npmjs are serving as a catalyst for supply chain security incidents that are continuously impacting JavaScript developers. What can we do to protect ourselves?
Vite - The Next Generation Frontend Tooling
React Advanced Conference 2021React Advanced Conference 2021
21 min
Vite - The Next Generation Frontend Tooling
How will we build web apps in the future? Let's learn how esbuild and bundlers like Vite built on top of it work to see how it can speed up our dev workflows.
Taming the State Management Dragon
React Summit US 2023React Summit US 2023
23 min
Taming the State Management Dragon
We spend a lot of time discussing which state library we should use, and fair. There are quite a few, from the common one everyone uses and loves to hate on, to that one quirky alternative, to several up and comers. However, discussing which library is best puts the cart before the horse.

When figuring out how to handle state, we should first ask ourselves: what different categories of state do we need? What are the constraints of each category? How do they relate to each other? How do they relate to the outside world? How do we keep them from becoming a giant, brittle ball of yarn? And more.

This might sound overwhelming, but never fear! In this talk, I'll walk you through how to answer these questions, and how craft an approachable, maintainable, and scalable state system. And yes, I will talk about how to pick a state management library too.