Yarn, un nuevo gestor de paquetes JavaScript lanzado por Facebook y Google

Yarn, a new JavaScript package manager released by Facebook and Google

Yarn is the new JavaScript package installer and dependency manager released by Facebook in collaboration with other big tech players such as Google. It introduces changes in dependency management and task execution as well as some performance improvements. 

BBVAOpen4U
|
28 Nov. 2016

When working with JavaScript technology, the most logical approach for developers is to frequently install new packages in this programming language to then be able to launch certain projects. For this type of action, some managers enable seamless installation of these libraries with a single command line. For example, npm (Node Package Manager) is the most popular JavaScript package manager among developers that use Node.js, the cross-platform, open-source execution environment by server layer. Node.js is one of the technologies that has been able to bring JavaScript language from front-end to back-end.

The idea behind these JavaScript package managers is that developers can share millions of small pieces of code that can be reused in different projects, sparing them from wasting time writing code for basic elements. By downloading and installing a package or library, this can be avoided.

Between the added elements and those that are a part of the developer's own programming there are some dependencies (to some extent, they all fit together like engine parts). JavaScript package managers release developers from the hard work of managing these code dependencies, allowing them to focus on what really matters: creating reliable products and services.

Yarn, the new market player

As an alternative to npm (possibly the most popular JavaScript package manager among the developer community), we now have a solution that may attain success if we consider its promoters: Facebook, Google, Exponent and Tilde. This alternative is called Yarn and it has drawn a lot of attention not only for its creators, but also due to the change in the approach to package download and installation, as well as dependency management.

For years, Facebook used the npm client to install and manage JavaScript packages in its own code but it has acknowledged that "consistency, security and performance issues" rose exponentially with the increase of the code volume and the number of engineers and programmers involved. For this reason, they decided to develop their own JavaScript package manager that would allow them to "manage our dependencies more reliably."

Key differences between npm and Yarn

npm and Yarn show some major differences that result from the work of Facebook and its partners on the new JavaScript package manager

  • Dependency management: Within the node ecosystem that a JavaScript package manager normally works in, dependencies can be found in node_modules of the project's directory. In npm, the package installation order and dependency generation define the structure of the directory's node. Consequently, when developers work with npm, it's likely that the structure of their dependency node will be different from the dependency node of other programmers.

Yarn doesn't work this way. This new manager uses certain blocking files that work on the dependencies installed in certain code versions to ensure that node_modules has the same file structure irrespective of the project and the developers that have accessed the programming base. Yarn generates a certain level of unity in the entire process albeit there are some changes. In any case, npm also includes the command npm shrinkwrap to block certain versions of different packages and their descendants within the hierarchical directory node_modules. The problem arises when there are changes to packages that are no longer inside what npm calls "semantic versioning" (semver).

Yarn's new installation and control process consists of various steps:

Resolution: Yarn resolves the dependencies among JavaScript packages and libraries by submitting record requests and reviewing each dependency that has already been processed within the directory.

Fletching: Then, Yearn reviews the overall directory in the cache memory and checks that the JavaScript package or library that you wish to download was not installed before. If it finds out that the package was not installed before, it downloads the package and installs it in the cache so that the same dependency is not installed and processed again in the future.

Linking: Lastly, Yarn copies all files from the cache memory to node_modules of the local directory so that developers may start working with the JavaScript package.

  • On installing packages: When developers wish to install a new JavaScript package, a series of prior tasks are carried out. In npm, these tasks are executed by packages in a gradual and sequential manner. In other words, the tasks for installing the first package are carried out first, then the tasks for the second package and so on. In Yarn, package tasks are executed in parallel, which has a clear impact on performance times. This comparison put together by Sitepoint shows some performance differences when you install express and gulp JavaScript packages (for the latter, a total of 195 dependencies were handled).
     
  • Command line: Yarn and npm use different commands, from the commands used by the manager's own installation to package search or the management of blocking files for dependencies.

Are you interested in financial APIs? Discover all the APIs we can offer you at BBVA

 

 

 

 

Sign up!

Sign up to the BBVAOPEN4U newsletter and receive tips, tools and the most innovative events directly in your inbox.