Yarn (package manager)

From Wikipedia, the free encyclopedia
Yarn
Yarn logo.png
Developer(s)Facebook
Initial release18 June 2016; 5 years ago (2016-06-18)[1]
Stable release
3.2.0 / 21 February 2022; 30 days ago (2022-02-21)[2]
Repositoryhttps://github.com/yarnpkg
Written inJavaScript
PlatformCross-platform
TypePackage manager
Websitehttps://yarnpkg.com

Yarn is a software packaging system developed in 2016 by Facebook for Node.js JavaScript runtime environment that provides speed, consistency, stability, and security as an alternative to npm (package manager). Yarn was created as a collaboration of Facebook, Exponent, Google, and Tilde to solve consistency, security, and performance problems with large codebases after Facebook was facing them. [3] Yarn stands for “Yet Another Resource Negotiator”.[4]

Functionality[]

Yarn provided plug-in feature to extend the core-feature or abilities to make better and more structured work-flows.

Yarn not only included some plugins available to use by default but users can also write their own plugins.

Constraints[]

Yarn constraints allow you to automatically enforce rules for your dependencies or manifest fields in your project across entire scoped workspaces.

This feature is only available on Yarn Berry installation, run yarn plugin import constraints to access this feature.

Offline cache[]

The offline cache allows Yarn to automatically store downloaded dependencies and speed up the same dependencies package resolving with local cache next time.

This feature is a critical part of Zero-Installs and doesn't store more than a single file for each package, which makes it suitable for being stored within a repository.

Plug'n'Play[]

Plug'n'Play allows us to run Node projects without node_modules folder, defining the way or location to resolve dependencies package files with the Plug-n-Play-control file. This feature is aimed to fix an unwell structured node_modules architecture and resulting in a faster NodeJs application start-up time.

Plugins[]

Plugins let users extend the yarn features or abilities by writing plugins and inject them and Yarn will do so much more than it can do resulting in your work-flow process faster.

Plugins can add new resolvers, fetchers, linkers, commands, and can also register to some events or be integrated with each other, most features of Yarn are implemented through plugins, including yarn add and yarn install, which are also preinstalled plugins.

Protocols[]

Protocols let users define which protocol will be used to resolve certain packages, for example, git protocol is used for downloading a public package from a Git repository, patch protocol is used for creating a patched copy of the original package, semver protocol (semantic versioning) is used when installing a new package, it will be added to your package.json with a semver version range.

Release Workflow[]

Release Workflow automatically upgrades relative packages among monorepos workspaces when root packages are upgraded.

This feature is only available on Yarn Berry installation, run yarn plugin import version to access this feature.

Workspaces[]

Workspaces allow multiple projects to work together in the same repository and automatically apply changes to other relatives when source code is modified, allowing installation of multiple packages by only running yarn installonce to install all of them in a single pass.

Zero-Installs[]

Zero-Installs solve the needs of installation of packages when packages is required to install when the codes is just fresh fetched to local.

Advantages[]

  • Yarn can install packages from local cache.
  • Yarn binds versions of the package strongly.
  • Yarn allows multiple packages installation simultaneously (parallel install).
  • Yarn’s user community is active and popular.[5]
  • Yarn uses checksum for ensuring data integrity, while npm uses SHA-512 to check data integrity of the packages downloaded.
  • Yarn installs packages in parallel, while npm installs one package at a time, so npm is basically slower than Yarn.[4]

Publishing packages[]

You can share your packages with other developers around the world by publishing them into npm registry, which is used to distribute packages globally.[6]

You must create an npm account and login to publish components as an npm package.

You can login from the npm website or command line using

yarn login

Once you have written all the code in your package, tested it out and you are ready to publish you can kick things off. You can share your packages with other developers around the world by publishing them into npm registry, which is used to distribute packages globally.

yarn publish

Creating a repository for your components is optional.[7]

See also[]

References[]

  1. ^ "Earliest releases of yarn". GitHub. Retrieved Jun 18, 2016.
  2. ^ "Yarn Berry".
  3. ^ "Yarn: A new package manager for JavaScript". Engineering at Meta. 2016-10-11. Retrieved 2021-11-22.
  4. ^ a b "Choosing Between NPM and Yarn". Engineering Education (EngEd) Program | Section. Retrieved 2021-11-22.
  5. ^ "Yarn VS NPM: Why and How to Migrate to Yarn | Software Development". Waverley. 2017-03-15. Retrieved 2021-11-22.
  6. ^ "Yarn". Yarn. Retrieved 2021-11-23.
  7. ^ JB (2021-06-29). "Publish React components as an npm package". Medium. Retrieved 2021-11-22.
Retrieved from ""