Yarn: “Fast, Reliable, and Secure Dependency Management.”

1_GcmFTIgtubehXuTbrDexCw

Yarn is a package manager that allows you to use and share code with other developers. Yarn does this rapidly, securely, and more reliable. Today we will process the features of yarn in depth. Let’s start.

Fast: Yarn caches every package it has downloaded, so it never needs to download the same package again. It also does almost everything concurrently to maximize resource utilization. This means even faster installs.

Reliable: Using a detailed but concise lockfile format and a deterministic algorithm for install operations, Yarn is able to guarantee that any installation that works on one system will work exactly the same on another system.

Secure: Yarn uses checksums to verify the integrity of every installed package before its code is executed.

Features
    • Offline Mode. If you’ve installed a package before, then you can install it again without an internet connection.
    • Deterministic. The same dependencies will be installed in the same exact way on any machine, regardless of installation order.
    • Network Performance. Yarn efficiently queues requests and avoids request waterfalls in order to maximize network utilization.
    • Network Resilience. A single request that fails will not cause the entire installation to fail. Requests are automatically retried upon failure.
    • Flat Mode. Yarn resolves mismatched versions of dependencies to a single version to avoid creating duplicates.

Installation

macOS
Homebrew

You can install Yarn through the Homebrew package manager. This will also install Node.js if it is not already installed.

brew install yarn

If you use nvm or similar, you should ensure that your PATH lists nvm’s shims before the version of Node.js installed by Homebrew.

MacPorts

You can install Yarn through MacPorts. This will also install Node.js if it is not already installed.

sudo port install yarn

Upgrade Yarn

Yarn will warn you if a new version is available. To upgrade Yarn, you can do so with Homebrew.

brew upgrade yarn

Test that Yarn is installed by running:

yarn --version

Usage

Starting a new project

yarn init

Adding a dependency

yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

Adding a dependency to different categories of dependencies

Add to devDependencies, peerDependencies, and optionalDependencies respectively:

yarn add [package] — dev
yarn add [package] — peer
yarn add [package] — optional

Upgrading a dependency

yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

Removing a dependency

yarn remove [package]

Installing all the dependencies of project

yarn

or

yarn install

I will continue to explain front-end web developer roadmap in my upcoming posts. For any question or feedback, please do not hesitate to leave comments below.

Take care~

Emre Aktaş

Comments

There are no comments yet.

Leave a comment