0
# Information Commands
1
2
Commands for inspecting packages, dependencies, and project status to understand your project's dependency tree and package details.
3
4
## Capabilities
5
6
### Package Information
7
8
Show detailed information about packages from the registry.
9
10
```bash { .api }
11
yarn info <package> [field] [options]
12
13
# Options:
14
--json # Output in JSON format
15
--registry <url> # Use specific registry
16
```
17
18
**Usage Examples:**
19
20
```bash
21
# Show all package information
22
yarn info react
23
24
# Show specific field
25
yarn info react version
26
yarn info react description
27
yarn info react dependencies
28
yarn info react peerDependencies
29
30
# Show information in JSON format
31
yarn info react --json
32
33
# Show information from specific registry
34
yarn info react --registry https://registry.npmjs.org
35
36
# Show information for scoped package
37
yarn info @types/react
38
39
# Show information for specific version
40
yarn info react@17.0.2
41
```
42
43
**Available Fields:**
44
- `name` - Package name
45
- `version` - Latest version
46
- `description` - Package description
47
- `keywords` - Package keywords
48
- `homepage` - Homepage URL
49
- `repository` - Repository information
50
- `author` - Author information
51
- `license` - License information
52
- `dependencies` - Production dependencies
53
- `devDependencies` - Development dependencies
54
- `peerDependencies` - Peer dependencies
55
- `engines` - Node.js/npm version requirements
56
- `scripts` - Available scripts
57
- `dist` - Distribution information
58
- `maintainers` - Package maintainers
59
60
### List Installed Packages
61
62
Display the dependency tree of installed packages.
63
64
```bash { .api }
65
yarn list [pattern] [options]
66
67
# Options:
68
--depth <number> # Limit dependency depth (default: all levels)
69
--pattern <pattern> # Filter packages by pattern
70
--json # Output in JSON format
71
```
72
73
**Usage Examples:**
74
75
```bash
76
# List all dependencies
77
yarn list
78
79
# List with limited depth
80
yarn list --depth=0 # Only direct dependencies
81
yarn list --depth=1 # Direct + one level deep
82
83
# Filter by pattern
84
yarn list --pattern "react*"
85
yarn list --pattern "@types/*"
86
87
# List in JSON format
88
yarn list --json
89
90
# List specific package and its dependencies
91
yarn list react
92
```
93
94
**Output Format:**
95
```
96
├─ package-a@1.0.0
97
│ ├─ dependency-1@2.0.0
98
│ └─ dependency-2@3.0.0
99
├─ package-b@2.0.0
100
└─ package-c@1.5.0
101
└─ shared-dep@1.0.0
102
```
103
104
### Why Package is Installed
105
106
Explain why a package is installed and show the dependency chain.
107
108
```bash { .api }
109
yarn why <package>
110
```
111
112
**Usage Examples:**
113
114
```bash
115
# Show why package is installed
116
yarn why lodash
117
118
# Show why specific version is installed
119
yarn why lodash@4.17.21
120
121
# Show why scoped package is installed
122
yarn why @babel/core
123
```
124
125
**Output Example:**
126
```
127
info Reasons this module exists
128
- "eslint-config-airbnb" depends on it
129
- Hoisted from "eslint-config-airbnb#lodash"
130
- "webpack#uglifyjs-webpack-plugin" depends on it
131
- Hoisted from "webpack#uglifyjs-webpack-plugin#lodash"
132
```
133
134
### Show Outdated Packages
135
136
Display packages that have newer versions available.
137
138
```bash { .api }
139
yarn outdated [package] [options]
140
141
# Options:
142
--json # Output in JSON format
143
```
144
145
**Usage Examples:**
146
147
```bash
148
# Show all outdated packages
149
yarn outdated
150
151
# Check specific package
152
yarn outdated react
153
154
# Output in JSON format
155
yarn outdated --json
156
```
157
158
**Output Format:**
159
```
160
Package Current Wanted Latest Package Type
161
react 16.8.0 16.14.0 18.2.0 dependencies
162
@types/node 14.18.0 14.18.63 20.5.0 devDependencies
163
```
164
165
- **Current**: Currently installed version
166
- **Wanted**: Latest version matching semver range in package.json
167
- **Latest**: Latest version available (may be outside semver range)
168
169
### License Information
170
171
Show license information for installed packages.
172
173
```bash { .api }
174
yarn licenses list # List all licenses
175
yarn licenses generate-disclaimer # Generate license disclaimer text
176
```
177
178
**Usage Examples:**
179
180
```bash
181
# List all package licenses
182
yarn licenses list
183
184
# Generate disclaimer text for legal compliance
185
yarn licenses generate-disclaimer > LICENSES.txt
186
```
187
188
**List Output:**
189
```
190
├─ MIT
191
│ ├─ react@18.2.0
192
│ ├─ lodash@4.17.21
193
│ └─ express@4.18.2
194
├─ Apache-2.0
195
│ └─ @babel/core@7.22.0
196
└─ BSD-3-Clause
197
└─ qs@6.11.0
198
```
199
200
### Binary Locations
201
202
Show the location of package binaries.
203
204
```bash { .api }
205
yarn bin [package]
206
```
207
208
**Usage Examples:**
209
210
```bash
211
# Show bin directory path
212
yarn bin
213
214
# Show path to specific binary
215
yarn bin eslint
216
yarn bin @babel/cli
217
218
# Common usage in scripts
219
export PATH="$(yarn bin):$PATH"
220
```
221
222
**Output:**
223
- Without package name: Shows the `.bin` directory path
224
- With package name: Shows full path to the specific binary
225
226
## Advanced Information Queries
227
228
### Dependency Analysis
229
230
```bash
231
# Show dependency tree for specific package
232
yarn list --pattern "react*" --depth=2
233
234
# Find all packages depending on a specific package
235
yarn why lodash | grep "depends on it"
236
237
# Check for duplicate dependencies
238
yarn list --pattern "*" | grep -E "^\s+├─|^\s+└─" | sort | uniq -d
239
```
240
241
### Version Range Analysis
242
243
```bash
244
# Check what version would be installed
245
yarn info react@^17.0.0 version
246
247
# Compare current vs available versions
248
yarn outdated | grep "^react "
249
250
# Check if package satisfies semver range
251
yarn info react versions --json | jq '.data[] | select(test("^17\\."))'
252
```
253
254
### Registry Information
255
256
```bash
257
# Check package from different registry
258
yarn info react --registry https://registry.npmjs.org
259
260
# Show package download statistics (if supported by registry)
261
yarn info react dist
262
263
# Show package maintainers
264
yarn info react maintainers
265
```
266
267
### Workspace Information
268
269
```bash
270
# List packages in workspace
271
yarn workspaces info
272
273
# Show workspace dependency tree
274
yarn workspaces info --json
275
276
# Check why package is installed in workspace context
277
yarn workspace my-package why lodash
278
```
279
280
## JSON Output Format
281
282
Most information commands support `--json` flag for programmatic usage:
283
284
```bash
285
# Package info as JSON
286
yarn info react --json | jq '.data.version'
287
288
# List as JSON
289
yarn list --json | jq '.data.trees[].name'
290
291
# Outdated as JSON
292
yarn outdated --json | jq '.data.body[] | select(.current != .latest)'
293
294
# Workspaces as JSON
295
yarn workspaces info --json | jq 'keys[]'
296
```
297
298
## Integration with Package Managers
299
300
### CI/CD Integration
301
302
```bash
303
# Check for security vulnerabilities
304
yarn audit --json | jq '.data.vulnerabilities'
305
306
# Verify no packages are outdated in CI
307
yarn outdated --json | jq '.data.body | length' | xargs test 0 -eq
308
309
# Generate license report for compliance
310
yarn licenses generate-disclaimer > build/THIRD_PARTY_LICENSES.txt
311
```
312
313
### Development Workflow
314
315
```bash
316
# Quick dependency health check
317
yarn outdated && yarn audit
318
319
# Show package sizes (with additional tooling)
320
yarn list --json | jq -r '.data.trees[] | "\(.name)@\(.version)"' | xargs npm-check-size
321
322
# Find unused dependencies (with additional tooling)
323
npx depcheck --ignore-patterns="build/**"
324
```