Fast, reliable, and secure dependency management tool for JavaScript/Node.js projects
npx @tessl/cli install tessl/npm-yarn@1.22.00
# Yarn
1
2
Yarn is a fast, reliable, and secure dependency management tool for JavaScript/Node.js projects. It serves as an alternative to npm with enhanced features including offline mode, deterministic installs, network performance optimizations, and flat dependency resolution. Yarn provides comprehensive dependency management capabilities with caching mechanisms, detailed lockfile format for reproducible builds, and integrity verification through checksums.
3
4
## Package Information
5
6
- **Package Name**: yarn
7
- **Package Type**: npm
8
- **Language**: JavaScript (Node.js)
9
- **Installation**: `npm install -g yarn` or download from https://yarnpkg.com/
10
- **Binary**: `yarn`, `yarnpkg`
11
- **Version**: 1.22.22
12
13
## Core Imports
14
15
Yarn is a command-line tool, so it doesn't use traditional imports. Instead, it's invoked via shell commands:
16
17
```bash
18
# Global installation
19
npm install -g yarn
20
21
# Usage via npx (no installation required)
22
npx yarn <command>
23
24
# Direct binary usage (after global install)
25
yarn <command>
26
yarnpkg <command> # Alternative binary name
27
```
28
29
## Basic Usage
30
31
Yarn is primarily used as a command-line tool for managing dependencies:
32
33
```bash
34
# Install dependencies
35
yarn install
36
37
# Add a dependency
38
yarn add react
39
40
# Add a dev dependency
41
yarn add --dev jest
42
43
# Remove a dependency
44
yarn remove lodash
45
46
# Run scripts
47
yarn run build
48
yarn test
49
50
# Upgrade dependencies
51
yarn upgrade
52
```
53
54
## Architecture
55
56
Yarn is built around several key components:
57
58
- **CLI Interface**: 30+ commands for complete package management workflow
59
- **Configuration System**: RC files, registry management, and workspace support
60
- **Lockfile Management**: Deterministic dependency resolution with yarn.lock
61
- **Package Resolution**: Multi-registry support with exotic resolvers (Git, GitHub, etc.)
62
- **Cache System**: Offline-first architecture with intelligent caching
63
- **Workspace Support**: Monorepo management with workspace-aware operations
64
- **Integrity Checking**: Checksum verification for security
65
66
## Capabilities
67
68
### Package Management Commands
69
70
Core commands for installing, adding, removing, and upgrading dependencies.
71
72
```bash { .api }
73
# Install all dependencies from package.json
74
yarn install [--production] [--frozen-lockfile] [--offline]
75
76
# Add dependencies to package.json
77
yarn add <package> [--dev] [--peer] [--optional] [--exact] [--tilde]
78
79
# Remove dependencies from package.json
80
yarn remove <package>
81
82
# Upgrade dependencies
83
yarn upgrade [package] [--latest] [--exact] [--pattern]
84
```
85
86
[Package Management](./package-management.md)
87
88
### Project Commands
89
90
Commands for project initialization, script execution, and development workflow.
91
92
```bash { .api }
93
# Initialize new project
94
yarn init [-y] [--private]
95
96
# Create project from template
97
yarn create <starter-kit-package> [args]
98
99
# Run package scripts
100
yarn run <script-name> [args]
101
yarn <script-name>
102
103
# Execute binaries
104
yarn exec <command> [args]
105
106
# Run Node.js
107
yarn node [args]
108
```
109
110
[Project Management](./project-management.md)
111
112
### Information Commands
113
114
Commands for inspecting packages, dependencies, and project status.
115
116
```bash { .api }
117
# Show package information
118
yarn info <package> [field]
119
120
# List installed packages
121
yarn list [--depth] [--pattern]
122
123
# Show why package is installed
124
yarn why <package>
125
126
# Show outdated packages
127
yarn outdated [package]
128
129
# Show license information
130
yarn licenses list|generate-disclaimer
131
132
# Show binary locations
133
yarn bin [package]
134
```
135
136
[Information Commands](./information-commands.md)
137
138
### Registry Commands
139
140
Commands for interacting with npm registries and package publishing.
141
142
```bash { .api }
143
# Login to registry
144
yarn login
145
146
# Logout from registry
147
yarn logout
148
149
# Publish package
150
yarn publish [--tag] [--access] [--registry]
151
152
# Manage package access
153
yarn access public|restricted <package>
154
yarn access grant|revoke <read-write|read-only> <scope:team> <package>
155
156
# Manage package ownership
157
yarn owner add|remove|list <user> <package>
158
159
# Manage package tags
160
yarn tag add|remove|list <package> <tag>
161
162
# Manage organization teams
163
yarn team create|destroy <scope:team>
164
yarn team add|remove <scope:team> <user>
165
yarn team list <scope> [team]
166
```
167
168
[Registry Operations](./registry-operations.md)
169
170
### Workspace Commands
171
172
Commands for managing monorepos and workspaces.
173
174
```bash { .api }
175
# Run command in all workspaces
176
yarn workspaces run <command>
177
178
# Get workspace information
179
yarn workspaces info [--json]
180
181
# Run command in specific workspace
182
yarn workspace <workspace-name> <command>
183
```
184
185
[Workspace Management](./workspace-management.md)
186
187
### Configuration Commands
188
189
Commands for managing yarn configuration and global packages.
190
191
```bash { .api }
192
# Manage configuration
193
yarn config set <key> <value> [--global]
194
yarn config get <key>
195
yarn config delete <key>
196
yarn config list
197
198
# Manage global packages
199
yarn global add <package>
200
yarn global remove <package>
201
yarn global list
202
203
# Manage symlinks for development
204
yarn link [package]
205
yarn unlink [package]
206
```
207
208
[Configuration](./configuration.md)
209
210
### Cache Commands
211
212
Commands for managing yarn's package cache.
213
214
```bash { .api }
215
# Show cache directory
216
yarn cache dir
217
218
# List cached packages
219
yarn cache list [--pattern]
220
221
# Clean cache
222
yarn cache clean [package]
223
```
224
225
[Cache Management](./cache-management.md)
226
227
### Utility Commands
228
229
Additional utility commands for package integrity, security, and maintenance.
230
231
```bash { .api }
232
# Verify package integrity
233
yarn check [--integrity] [--verify-tree]
234
235
# Run security audit
236
yarn audit [--level] [--json]
237
238
# Create package tarball
239
yarn pack [--filename]
240
241
# Import dependencies from package-lock.json
242
yarn import
243
244
# Generate lockfile entry
245
yarn generate-lock-entry
246
247
# Clean unnecessary files
248
yarn autoclean [--init] [--force]
249
250
# Temporarily unplug Plug'n'Play packages for debugging
251
yarn unplug <package> [--clear] [--clear-all]
252
253
# Manage release policies and yarn version
254
yarn policies set-version <version>
255
256
# Show help
257
yarn help [command]
258
259
# Show version
260
yarn version [--new-version] [--major] [--minor] [--patch]
261
262
# Show versions of dependencies
263
yarn versions
264
```
265
266
[Utility Commands](./utility-commands.md)
267
268
## Types
269
270
```javascript { .api }
271
// Command-line options for yarn install
272
interface InstallOptions {
273
production?: boolean; // Install only production dependencies
274
"frozen-lockfile"?: boolean; // Don't generate lockfile and fail if update needed
275
"pure-lockfile"?: boolean; // Don't generate lockfile
276
offline?: boolean; // Use only cached packages
277
"ignore-scripts"?: boolean; // Don't run lifecycle scripts
278
"ignore-platform"?: boolean; // Don't check platform compatibility
279
"ignore-engines"?: boolean; // Don't check engines compatibility
280
"ignore-optional"?: boolean; // Don't install optional dependencies
281
"force"?: boolean; // Force re-download of packages
282
"har"?: boolean; // Save HAR file for network requests
283
"non-interactive"?: boolean; // Disable interactive prompts
284
"no-bin-links"?: boolean; // Don't create symlinks for binaries
285
"flat"?: boolean; // Install all dependencies in root node_modules
286
"focus"?: boolean; // Focus on workspace dependencies
287
"verbose"?: boolean; // Show additional logging
288
}
289
290
// Command-line options for yarn add
291
interface AddOptions {
292
dev?: boolean; // Add to devDependencies
293
peer?: boolean; // Add to peerDependencies
294
optional?: boolean; // Add to optionalDependencies
295
exact?: boolean; // Install exact version
296
tilde?: boolean; // Install with tilde range
297
"ignore-workspace-root-check"?: boolean; // Allow install on workspace root
298
"audit"?: boolean; // Run audit after install
299
}
300
301
// Configuration values
302
interface YarnConfig {
303
registry?: string; // Package registry URL
304
"cache-folder"?: string; // Cache directory path
305
"global-folder"?: string; // Global packages directory
306
"modules-folder"?: string; // Local node_modules directory name
307
"offline-mirror"?: string; // Offline mirror directory
308
"disable-self-update-check"?: boolean; // Disable update checks
309
"ignore-engines"?: boolean; // Ignore engines field
310
"ignore-scripts"?: boolean; // Don't run lifecycle scripts
311
workspaces?: boolean; // Enable workspaces
312
"workspace-experimental"?: boolean; // Enable experimental features
313
}
314
```
315
316
## Exit Codes
317
318
Yarn uses standard exit codes to indicate success or failure:
319
320
- **0**: Success
321
- **1**: General error (network issues, package not found, etc.)
322
- **2**: Missing or invalid arguments
323
- **3**: Permission errors
324
- **4**: Network connectivity issues
325
- **5**: Package resolution errors
326
327
## Environment Variables
328
329
```bash { .api }
330
# Cache directory override
331
YARN_CACHE_FOLDER=/path/to/cache
332
333
# Registry override
334
YARN_REGISTRY=https://registry.npmjs.org
335
336
# Disable update checks
337
YARN_DISABLE_SELF_UPDATE_CHECK=true
338
339
# Enable offline mode
340
YARN_ENABLE_OFFLINE_MODE=true
341
342
# HTTP proxy settings
343
HTTP_PROXY=http://proxy.example.com:8080
344
HTTPS_PROXY=https://proxy.example.com:8080
345
```