Yarn: From Design to Implementation

Rate this content
Bookmark

In this talk, we'll go over the various iterations the Yarn team went through designing one of the most critical software in the JavaScript ecosystem. We'll discuss some of the main choices, trade-offs, errors, and successes we faced, and think about evolutions to come and future challenges that await us. By the end of this talk you'll have a better understanding of the work large-scale open-source teams do behind the team, and hopefully a better understanding of what makes open-source so special.

This talk has been presented at DevOps.js Conf 2024, check out the latest edition of this JavaScript Conference.

FAQ

YARN is a package manager for JavaScript that focuses on determinism, stability, clean UX, and being fully open source. It was created to address issues with consistency, security, and performance in the JavaScript ecosystem.

YARN was created because the developers felt that contributing to NPM wouldn't address all the issues they wanted to solve. Each project has its own priorities, and YARN aimed to make different trade-offs and follow a different exploration path.

The core focus areas of YARN are determinism, stability, clean UX, and being fully open source. In YARN 2 and beyond, additional focus areas include monorepos, dogfooding, partitioning, and evolutiveness.

YARN Classic refers to the versions of YARN before 2.0. It was designed to improve consistency, security, and performance in large codebases, particularly at Facebook, where it originated.

Key features in YARN Modern include monorepos as a core concept, dogfooding, better partitioning of code, and a modular pipeline for resolution, fetching, and linking of packages. It also supports various linkers for different installation strategies.

YARN supports offline installations through its offline mirror feature, which allows you to store tarballs of your project's dependencies in a controlled location, such as a Git repository or specific filesystem. This ensures that projects can be installed even if the NPM registry is down.

The constraint engine in YARN allows users to create custom rules for their projects. For example, it can enforce that no two workspaces in the same project depend on different versions of the same package. It uses a JS-based engine for easier rule creation.

YARN uses a file system library called yarn-pkg-slash-fslim to handle path compatibility issues across different operating systems, such as Windows and POSIX systems. This library centralizes the logic for path handling, ensuring consistent behavior.

YARN contributes to the Node.js ecosystem through initiatives like Core Pack, which aims to make it easier to use different package managers. YARN also participates in working groups to tackle large issues affecting multiple projects, such as defining loaders in Node.js.

YARN's modular pipeline allows for different resolvers, fetchers, and linkers to handle various aspects of package management. This modular approach provides flexibility and makes it easier to add new features or make improvements without affecting other parts of the system.

Maël Nison
Maël Nison
28 min
15 Feb, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Today we'll discuss the evolution and implementation of YARN, which focuses on determinism and stability. YARN Modern was re-architected to support projects with multiple packages and embraced Monorepos. YARN 2 improved workspace implementation, codebase partitioning, and stability. Dependency resolution and linking in YARN are handled by different resolvers and fetchers. YARN has a plugin system, a constraint engine, and a redesigned website. It prioritizes compatibility, performance, testing, and contributions to other projects.
Available in Español: Yarn: De Diseño a Implementación

1. Introduction to YARN

Short description:

Today we're going to talk about how YARN came to be, what it evolved into, and interesting tidbits about its implementation. I'm Maren Lison, a staff developer experience engineer at Datadog, leading the development of YARN since 2017. YARN is split into three parts: classics, modern, and implementation details. Classic YARN was created to address problems with consistency, security, and performance at Facebook. We chose to create YARN instead of contributing to NPM because we wanted to address different priorities. YARN focuses on determinism and stability.

Hi, everyone, and welcome to my talk about YARN. Today we're going to talk a bit about how it came to be, what it evolved into, and interesting tidbits about its implementation.

So first, my name is Maren Lison, I'm a staff developer experience engineer at Datadog. And I've been leading the development of YARN since 2017, from the zero point something up to the 4.0 that it currently is.

I split the content of this presentation into three parts. First we're going to talk a bit about YARN classics. Then we're going to go to YARN modern, so everything from 2.0 until today. And finally, we're going to jump into interesting details about either the implementation of YARN or some meta knowledge about YARN.

First thing, YARN classic. So classic is everything that is pre 2.0. Why did we create YARN classic? The answer is if you look at the blog post that got released around the time to introduce YARN, you will see this interesting sentence. As the size of our code base and the number of engineers grew at Facebook, we ran into problems with consistency, security and performance. At the time, the JavaScript ecosystem was very different from what it currently is, and it was very difficult to be sure that when you were running a project it would be working for everyone across the organization. That's something that didn't really work at the scale that Facebook was operating, so they decided to put some resources into trying to figure out a solution.

However, now let's take the same question but with a different emphasis. Why did we create YARN? Why didn't we just contribute to NPM? The reason for that is that it felt at the time there were so many different things that we wanted to attempt to address, that contributing to NPM wouldn't have made sense. Each project has their own priorities, and some of the things that YARN intended to address were not things that NPM intended to challenge, because they felt that it was the developer experience they wanted to have. That's completely fair. We decided that it would be easier to just create one other project that would make different trade-offs and would follow a different exploration path. Contributing wasn't really an option because we didn't want to push against NPM on a project that was entirely theirs. Remember that NPM was also a company at the time, so they had their own priorities.

When we built YARN, we decided to focus on four different core areas. The first one was determinism. It's easy to remember log files as being used everywhere, basically. However, at the time, they were very rare. We were a project. We were not enforcing the version of their dependencies across different installs, meaning that everyone would get different things. We felt that it was important that projects that work now should work in the future, and for that, YARN had to do some focus work on that. Additionally, we wanted YARN to be safe, meaning that we wanted to catch as many bugs as possible before they would even ship in production. So stability was very important to us.

2. YARN Features and Stability

Short description:

We focused on the user experience of working with the CLI, made YARN fully open source, and released it as a separate project. The initial product offering included log files, an offline mirror, and emojis for better CLI output. YARN was fully typed using Flow for improved stability.

A clean UX was also very important. We wanted YARN to be a tool that could be approached by anyone without having deep knowledge of how package managers work, how projects are set up. To that end, we decided to focus a little on the user experience of working with the CLI and not just the implementation of the software itself.

Finally, we wanted it to be fully open source. I mentioned that NPM was a company, and actually it still is a company, but now owned by GitHub. NPM was a startup, meaning that it was receiving investment from VCs, and it felt like the incentives weren't completely aligned with what the JavaScript ecosystem needed. So we really wanted YARN to be fully open source, and it got released as a project that wasn't even part of Facebook. Nowadays, Facebook doesn't actually have any part in it. It's only maintained by people from different companies.

The initial product offering when we released YARN, there were four main different things. The first one, of course, was log files. Log files all the day. At the time, NPM added shrinkwraps, which allowed you to log the version of your dependencies, but were not enabled by default. It also had an effect on transitive installs. They were a little weird and we wanted to have something simpler to understand, and that would be enabled by default. We also shipped with the offline mirror, which also followed the same strategy of how can we make sure that the project will keep being installed in the future. What if the NPM registry goes down, whether temporarily or permanently? Can we make sure that it doesn't affect us, because it doesn't affect our installs? The offline mirror lets you store the tarballs of the cache of your project, somewhere you control, for instance, inside your Git repository, but not necessarily. You can also store it inside a specific file system. So that even if the registry is down, YARN can still install your project just fine. It also shipped with emojis. I know that when you read emoji as a product feature, that doesn't seem very important, but actually, it kind of was for our users. I think it also showed that the output of the CLI is very important, and making it easier to parse for humans makes a lot of sense. Nowadays we do that with different things than emojis. We do that using semantic colors on the different components that we display. But that's the kind of attention that we decided to put into the developer experience.

And finally, this one is more about the maintenance that YARN features themselves, but they go into the stability bucket that I mentioned earlier. YARN was fully typed using Flow, not TypeScript at the time. And that was very important because it allowed us to cache many issues that we wouldn't have caught otherwise if we had not type-checked the codebase. NPM was following a very different strategy where they intended to have full coverage through tests. However, from our experience, doing something like that would still have let things pass that shouldn't have been shipped.

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

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
Remix Flat Routes – An Evolution in Routing
Remix Conf Europe 2022Remix Conf Europe 2022
16 min
Remix Flat Routes – An Evolution in Routing
Top Content
Remix Flat Routes is a new convention that aims to make it easier to see and organize the routes in your app. It allows for the co-location of support files with routes, decreases refactor and redesign friction, and helps apps migrate to Remix. Flat Folders convention supports co-location and allows importing assets as relative imports. To migrate existing apps to Flat Routes, use the Remix Flat Routes package's migration tool.
The Zen of Yarn
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
Let's talk about React and TypeScript, Yarn's philosophy and long-term relevance, stability and error handling in Yarn, Yarn's behavior and open source sustainability, investing in maintenance and future contributors, contributing to the JavaScript ecosystem, open-source contribution experience, maintaining naming consistency in large projects, version consistency and strictness in Yarn, and Yarn 4 experiments for performance improvement.
How to Make a Web Game All by Yourself
JS GameDev Summit 2023JS GameDev Summit 2023
27 min
How to Make a Web Game All by Yourself
This talk guides you on how to make a web game by yourself, emphasizing the importance of focusing on tasks that interest you and outsourcing the rest. It suggests choosing a game engine that allows distribution on the web and aligns with your understanding and enjoyment. The talk also highlights the significance of finding fun in the creative process, managing scope, cutting features that don't align with the game's direction, and iterating to the finish line. It concludes by discussing the options for publishing the game on the web and leveraging unique web features.
Atomic Deployment for JS Hipsters
DevOps.js Conf 2024DevOps.js Conf 2024
25 min
Atomic Deployment for JS Hipsters
This Talk discusses atomic deployment for JavaScript and TypeScript, focusing on automated deployment processes, Git hooks, and using hard links to copy changes. The speaker demonstrates setting up a bare repository, configuring deployment variables, and using the post-receive hook to push changes to production. They also cover environment setup, branch configuration, and the build process. The Talk concludes with tips on real use cases, webhooks, and wrapping the deployment process.
Your GraphQL Groove
GraphQL Galaxy 2022GraphQL Galaxy 2022
31 min
Your GraphQL Groove
The Talk discusses the value proposition of GraphQL and its ability to solve common pain points in API development. It highlights the importance of making informed decisions when choosing GraphQL clients, servers, and schema builders. The Talk also emphasizes the need to focus on the best developer experience in the present rather than seeking a perfect long-term solution. Additionally, it mentions the future of the Urkel GraphQL client and the reasons for dropping ReScript support. Overall, the Talk provides insights into the current state and future trends of GraphQL development.

Workshops on related topic

Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
Finding, Hacking and fixing your NodeJS Vulnerabilities with Snyk
JSNation 2022JSNation 2022
99 min
Finding, Hacking and fixing your NodeJS Vulnerabilities with Snyk
WorkshopFree
Matthew Salmon
Matthew Salmon
npm and security, how much do you know about your dependencies?Hack-along, live hacking of a vulnerable Node app https://github.com/snyk-labs/nodejs-goof, Vulnerabilities from both Open source and written code. Encouraged to download the application and hack along with us.Fixing the issues and an introduction to Snyk with a demo.Open questions.
Managers Are From Mars, Devs Are From Venus
TechLead Conference 2024TechLead Conference 2024
111 min
Managers Are From Mars, Devs Are From Venus
Workshop
Mo Khazali
Mo Khazali
A Developer’s Guide to Communicating, Convincing, and Collaborating Effectively With Stakeholders
It’s a tale as old as time - collaboration between developers and business stakeholders has long been a challenge, with a lack of clear communication often leaving both sides frustrated. The best developers can deeply understand their business counterparts’ needs, effectively communicate technical strategy without losing the non-technical crowd, and convince the business to make the right decisions. Working at a consultancy, I’ve both failed and succeeded in architecting and “selling” technical visions, learning many lessons along the way.Whether you work at a product company, are a consultant/freelancer, or want to venture beyond just being a developer, the ability to convince and clearly communicate with stakeholders can set you apart in the tech industry. This becomes even more important with the rise of GenAI and the increasingly competitive developer market, as problem-solving and effective communication are key to positioning yourself.In this workshop, I’ll share real-world examples, both good and bad, and guide you through putting the theory into practice through dojos.
Build Web3 apps with React
React Summit 2022React Summit 2022
51 min
Build Web3 apps with React
WorkshopFree
Shain Dholakiya
Shain Dholakiya
The workshop is designed to help Web2 developers start building for Web3 using the Hyperverse. The Hyperverse is an open marketplace of community-built, audited, easy to discover smart modules. Our goal - to make it easy for React developers to build Web3 apps without writing a single line of smart contract code. Think “npm for smart contracts.”
Learn more about the Hyperverse here.
We will go over all the blockchain/crypto basics you need to know to start building on the Hyperverse, so you do not need to have any previous knowledge about the Web3 space. You just need to have React experience.
How to create editor experiences your team will love
React Advanced 2021React Advanced 2021
168 min
How to create editor experiences your team will love
Workshop
Lauren Etheridge
Knut Melvær
2 authors
Content is a crucial part of what you build on the web. Modern web technologies brings a lot to the developer experience in terms of building content-driven sites, but how can we improve things for editors and content creators? In this workshop you’ll learn how use Sanity.io to approach structured content modeling, and how to build, iterate, and configure your own CMS to unify data models with efficient and delightful editor experiences. It’s intended for web developers who want to deliver better content experiences for their content teams and clients.