Yarn a better package manager

yarn is fast, reliable and secure dependency manager

Why yarn

  • Installing first time pkg will cache it so that next time it will be faster
  • It install multiple packages in parallel which makes it super fast.
  • Integertiy verfication using checksums so no corrupt packages.
  • File locking like composer and deterministic algorithms for install to maintain dependency order
  • We can install packages offline which is not possible in npm
  • Unlike npm retry request on failure
  • Unlike nesting in npm, yarn uses flat mode and Avoid duplicates by resolving mismatching
  • Supported by google and facebook team

Installation

Installation on ubuntu require few simple steps
First tweak repository by adding key and repo.

1
2
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Update and install

1
sudo apt-get update && sudo apt-get install yarn

Check if successfully installed

1
yarn --version

Working with yarn

Working with yarn is same as working with npm.

Just like npm init we have yarn init and same question and interstingly it uses same package.json

1
yarn init
1
2
3
4
5
6
7
8
{
"name": "testing-yarn123",
"version": "1.0.0",
"description": "testing yarn package manager",
"main": "index.js",
"repository": {},
"license": "MIT"
}

Adding a dependency same as npm like npm install –save [email protected]

1
2
3
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

We also have nice progress bar and its really fast unlike npm where by enable progress bar installation gets even more slow.

Adding package via yarn

Yarn nice progress bar

Upgrading package

1
2
3
yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

Removing a package

1
yarn remove [package]

Installing all dependency

Like npm install here we have

1
yarn

or

1
yarn install

yarn help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
yarn -h
Usage: yarn [command] [flags]
Options:
-h, --help output usage information
-V, --version output the version number
--verbose output verbose messages on internal operations
--offline trigger an error if any required dependencies are not available in local cache
--prefer-offline use network only if dependencies are not available in local cache
--strict-semver
--json
--ignore-scripts dont run lifecycle scripts
--har save HAR output of network traffic
--ignore-platform ignore platform checks
--ignore-engines ignore engines check
--ignore-optional ignore optional dependencies
--force ignore all caches
--no-bin-links dont generate bin links when setting up packages
--flat only allow one version of a package
--prod, --production [prod]
--no-lockfile dont read or generate a lockfile
--pure-lockfile dont generate a lockfile
--frozen-lockfile dont generate a lockfile and fail if an update is needed
--global-folder <path>
--modules-folder <path> rather than installing modules into the node_modules folder relative to the cwd, output them here
--cache-folder <path> specify a custom folder to store the yarn cache
--mutex <type>[:specifier] use a mutex to ensure only one yarn instance is executing
--no-emoji disable emoji in output
--proxy <host>
--https-proxy <host>
--no-progress disable progress bar
--network-concurrency <number> maximum number of concurrent network requests
Commands:
- access
- add
- bin
- cache
- check
- clean
- config
- generate-lock-entry
- global
- info
- init
- install
- licenses
- link
- list
- login
- logout
- outdated
- owner
- pack
- publish
- remove
- run
- tag
- team
- unlink
- upgrade
- upgrade-interactive
- version
- versions
- why
Run `yarn help COMMAND` for more information on specific commands.
Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn.
Comments