yarn

2016-11-03

Today I learnt about Yarn.

Yarn is a node package manager, built by facebook, inspired by cargo and bundler!
It is meant to address the shortcomings of npm, such as module download failures and inconsistant state.

Like bundler, it creates a lockfile in the root of the project called yarn.lock

This lockfile ensures that each build of your project is reproducable, on CI servers and colleagues’ machines.

Great. So now what?

Yarn is super simple to use.
It’s effectively a drop in replacement for npm.

Installation

1
2
$ brew update
$ brew install yarn

Add export PATH="$PATH:$HOME/.yarn/bin" to your bash profile.

Usage

To add a dependency to your package, you simply run:

1
$ yarn add package-name

To make your dependency available globally

1
$ yarn global package-name

Where it shines

“Why do I have this dependency in my node_modules folder?”, I hear you ask!
Yarn can actually tell you!!!

1
2
3
4
5
6
7
8
9
10
11
12
$ yarn why uid-number
yarn why v0.16.1
[1/4] 🤔 Why do we have the module "uid-number"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
info This module exists because "hexo#hexo-fs#chokidar#fsevents#node-pre-gyp#tar-pack" depends on it.
info Disk size without dependencies: "20kB"
info Disk size with unique dependencies: "20kB"
info Disk size with transitive dependencies: "20kB"
info Amount of shared dependencies: 0
✨ Done in 0.34s.

Wanna inspect the licenses of your dependencies? Sure!

1
yarn licenses ls

Interesting read

For more usage info
npm vs yarn
Why I’m Working on Yarn, by Yehuda Katz