Background

Facebook Launches Yarn, A JavaScript Package Manager And Npm-Alternative Built For Speed

Yarn

Many of the web is powered by JavaScript, and many of them use the npm package manager. To them, reusing existing codes may not matter much. But for Facebook that has scaled larger that it was, some of its components don't quite work.

At Facebook, npm has slowed down the company’s continuous integration workflow. Previously, the company's engineers had to run the ubiquitous "npm install" command manually, but that didn't work in the sandboxed and isolated continuous integration environments the company uses for security and reliability reasons. Another option the engineers had done was checking all of the modules into a repository, but that also was inefficient because even a minor change could easily create massive commits.

For that reason it has started developing an alternative for its internal use. On October 11th, 2016, the company has launched Yarn, a package manager for JavaScript with the help from developers at Google, Exponent and Tilde.

Yarn is compatible with the npm registry, but the approach to installing the package is different: Yarn uses lockfiles and a deterministic installation algorithm.

According to Facebook when announcing Yarn:

"In the JavaScript community, engineers share hundreds of thousands of pieces of code so we can avoid rewriting basic components, libraries, or frameworks of our own. Each piece of code may in turn depend on other pieces of code, and these dependencies are managed by package managers. The most popular JavaScript package manager is the npm client, which provides access to more than 300,000 packages in the npm registry. More than 5 million engineers use the npm registry, which sees up to 5 billion downloads every month."

"We've used the npm client successfully at Facebook for years, but as the size of our codebase and the number of engineers grew, we ran into problems with consistency, security, and performance. After trying to solve for each issue as it came up, we set out to build a new solution to help us manage our dependencies more reliably. The product of that work is called Yarn - a fast, reliable, and secure alternative npm client."

Primary Focus Is Speed

Npm and Yarn - comparison

For Facebook, Yarn means speed. And that it has done well by caching files locally which ensures it doesn’t have to connect to the network quiet as often as before, and by making the operation parallel.

Using Yarn, Facebook's engineers and developers can still have access to the existing npm and Bower workflows. However the main difference here is that the install package is more quickly and have consistent dependencies across different machines or in secure offline environment.

Furthermore, Yarn also allows Facebook to maintain the same structure of node_modules directories - which house dependencies - for all users involved in a project. The advantage is that it can help reduce bugs that previously are difficult to trace and replicate.

And because it's faster, its engineers and developers can manage projects faster when using shared code, and they can focus more on what matters.

Yarn

By delivering the project open-source, Facebook works for a large base of developer as soon as possible. The team at npm said that it's happy to welcome Yarn to the open-source npm clients. The team noted that Yarn "seems to work great on public packages," but doesn't yet work with private packages. The team behind Yarn is working to fix this issue.

Yarn is just another open-source project from Facebook. But because of the number of other companies that has contributed to the project, the team at Facebook decided to host it outside of Facebook's own repository.

"Our hope is that all of the folks who have been contributing to it so far can help us figure that out," said engineering manager Tom Occhino.

As a social media company, it has been active in the open-source community by delivering numerous project to the masses. Facebook's frequent contribution has made it #2 on GitHub's list of organization with the most open-source contributors, placing the social giant right after Microsoft which sits at #1 on the list.