0
# Package Inspection and Analysis
1
2
Inspect installed packages, check for outdated dependencies, audit security vulnerabilities, and analyze package relationships with pnpm's comprehensive analysis tools.
3
4
## Capabilities
5
6
### List Installed Packages
7
8
Display installed packages with various output formats and filtering options.
9
10
```bash { .api }
11
/**
12
* List installed packages with dependency tree
13
* Shows package versions, locations, and relationships
14
*/
15
pnpm list [pkg] [options]
16
pnpm ls [pkg] [options]
17
```
18
19
**Options:**
20
```bash { .api }
21
--depth <number> # Limit dependency tree depth
22
--long # Show extended package information
23
--parseable # Machine-readable output
24
--global # List global packages
25
--recursive # List in all workspace packages
26
--filter <pattern> # Filter workspace packages
27
--json # JSON output format
28
--prod # Production dependencies only
29
--dev # Development dependencies only
30
--no-optional # Exclude optional dependencies
31
```
32
33
**Usage Examples:**
34
35
```bash
36
# List all packages
37
pnpm list
38
39
# List specific package
40
pnpm list react
41
42
# List with limited depth
43
pnpm list --depth=1
44
45
# List in long format
46
pnpm list --long
47
48
# List global packages
49
pnpm list --global
50
51
# List in all workspaces
52
pnpm list --recursive
53
54
# List production dependencies only
55
pnpm list --prod
56
57
# JSON output
58
pnpm list --json
59
```
60
61
### Extended Package Listing
62
63
Show detailed package information including descriptions, sizes, and metadata.
64
65
```bash { .api }
66
/**
67
* List packages with extended information
68
* Includes descriptions, repository URLs, and package sizes
69
*/
70
pnpm ll [options]
71
pnpm la [options]
72
```
73
74
**Usage Examples:**
75
76
```bash
77
# Extended listing
78
pnpm ll
79
80
# Extended listing with filtering
81
pnpm ll --filter "@myorg/*"
82
83
# Extended global listing
84
pnpm ll --global
85
```
86
87
### Package Dependency Analysis
88
89
Analyze why a package is installed and show its dependency chain.
90
91
```bash { .api }
92
/**
93
* Show why a package is installed
94
* Displays dependency chain from root to target package
95
*/
96
pnpm why <pkg> [options]
97
```
98
99
**Options:**
100
```bash { .api }
101
--recursive # Check in all workspace packages
102
--global # Check global packages
103
--json # JSON output format
104
--long # Show detailed information
105
```
106
107
**Usage Examples:**
108
109
```bash
110
# Show why package is installed
111
pnpm why lodash
112
113
# Show in all workspaces
114
pnpm why --recursive react
115
116
# Show global dependency reasons
117
pnpm why --global typescript
118
119
# JSON output
120
pnpm why --json express
121
```
122
123
## Update Analysis
124
125
### Check Outdated Packages
126
127
Identify packages that have newer versions available.
128
129
```bash { .api }
130
/**
131
* Check for outdated packages
132
* Shows current vs latest versions with update information
133
*/
134
pnpm outdated [pkg] [options]
135
```
136
137
**Options:**
138
```bash { .api }
139
--recursive # Check in all workspace packages
140
--global # Check global packages
141
--long # Show extended information
142
--json # JSON output format
143
--compatible # Show only compatible updates
144
--filter <pattern> # Filter workspace packages
145
```
146
147
**Usage Examples:**
148
149
```bash
150
# Check all outdated packages
151
pnpm outdated
152
153
# Check specific package
154
pnpm outdated react
155
156
# Check in all workspaces
157
pnpm outdated --recursive
158
159
# Check global packages
160
pnpm outdated --global
161
162
# Show only compatible updates
163
pnpm outdated --compatible
164
165
# JSON output for automation
166
pnpm outdated --json
167
```
168
169
### License Information
170
171
Show license information for installed packages.
172
173
```bash { .api }
174
/**
175
* Show licenses of installed packages
176
* Displays license types and compliance information
177
*/
178
pnpm licenses <command> [options]
179
```
180
181
**Available Commands:**
182
- `list` - List all package licenses
183
- `ls` - Alias for list
184
185
**Options:**
186
```bash { .api }
187
--recursive # Check in all workspace packages
188
--json # JSON output format
189
--long # Show detailed license information
190
```
191
192
**Usage Examples:**
193
194
```bash
195
# List all licenses
196
pnpm licenses list
197
198
# List in JSON format
199
pnpm licenses list --json
200
201
# List in all workspaces
202
pnpm licenses list --recursive
203
204
# Detailed license information
205
pnpm licenses list --long
206
```
207
208
## Security Analysis
209
210
### Security Audit
211
212
Perform security vulnerability audits on installed packages.
213
214
```bash { .api }
215
/**
216
* Run security vulnerability audit
217
* Checks packages against known vulnerability databases
218
*/
219
pnpm audit [options]
220
```
221
222
**Options:**
223
```bash { .api }
224
--recursive # Audit in all workspace packages
225
--json # JSON output format
226
--audit-level <level> # Set severity level (low, moderate, high, critical)
227
--fix # Automatically fix vulnerabilities where possible
228
--dry-run # Show what would be fixed without applying changes
229
```
230
231
**Usage Examples:**
232
233
```bash
234
# Basic security audit
235
pnpm audit
236
237
# Audit all workspaces
238
pnpm audit --recursive
239
240
# JSON output for CI/CD
241
pnpm audit --json
242
243
# Audit with specific severity level
244
pnpm audit --audit-level high
245
246
# Auto-fix vulnerabilities
247
pnpm audit --fix
248
249
# Preview fixes without applying
250
pnpm audit --fix --dry-run
251
```
252
253
### Audit Output Formats
254
255
Understanding audit output and severity levels:
256
257
```bash { .api }
258
# Severity levels
259
critical # Immediate action required
260
high # Should be addressed soon
261
moderate # Should be addressed when convenient
262
low # Informational, consider addressing
263
264
# Audit summary shows:
265
- Total vulnerabilities by severity
266
- Packages requiring updates
267
- Suggested fix commands
268
- Manual review items
269
```
270
271
## Package Information
272
273
### Package Details
274
275
Get detailed information about specific packages from the registry.
276
277
```bash { .api }
278
# Show package information (npm compatibility commands)
279
pnpm show <pkg>[@version] [field]
280
pnpm view <pkg>[@version] [field]
281
pnpm info <pkg>[@version] [field]
282
```
283
284
**Usage Examples:**
285
286
```bash
287
# Show package information
288
pnpm show react
289
290
# Show specific version
291
pnpm show react@18.2.0
292
293
# Show specific field
294
pnpm show react version
295
pnpm show react dependencies
296
297
# Show all versions
298
pnpm show react versions --json
299
```
300
301
### Package Search
302
303
Search for packages in the registry.
304
305
```bash { .api }
306
# Search packages (npm compatibility)
307
pnpm search <query>
308
pnpm s <query>
309
pnpm se <query>
310
```
311
312
**Usage Examples:**
313
314
```bash
315
# Search for packages
316
pnpm search react testing
317
318
# Short form
319
pnpm s "http client"
320
```
321
322
## Workspace Analysis
323
324
### Workspace Package Overview
325
326
Analyze packages across workspace for consistency and issues.
327
328
```bash { .api }
329
# List all workspace packages
330
pnpm list --recursive --depth=0
331
332
# Show workspace package locations
333
pnpm list --recursive --long
334
335
# Check for inconsistent dependencies
336
pnpm outdated --recursive
337
338
# Audit all workspace packages
339
pnpm audit --recursive
340
```
341
342
### Dependency Relationship Analysis
343
344
Understand dependencies between workspace packages.
345
346
```bash { .api }
347
# Show workspace dependency graph
348
pnpm list --recursive --json | # process for visualization
349
350
# Find packages depending on specific package
351
pnpm why --recursive <package-name>
352
353
# Check version consistency across workspace
354
pnpm outdated --recursive --json
355
```
356
357
## Output Formats and Parsing
358
359
### JSON Output
360
361
Most inspection commands support JSON output for programmatic processing:
362
363
```bash { .api }
364
# JSON output examples
365
pnpm list --json # Dependency tree as JSON
366
pnpm outdated --json # Outdated packages as JSON
367
pnpm audit --json # Audit results as JSON
368
pnpm licenses list --json # License information as JSON
369
```
370
371
### Parseable Output
372
373
Some commands support parseable output for scripting:
374
375
```bash { .api }
376
# Parseable output examples
377
pnpm list --parseable # Tab-separated values
378
pnpm --parseable <command> # Machine-readable format
379
```
380
381
### Long Format Output
382
383
Extended information display:
384
385
```bash { .api }
386
# Long format examples
387
pnpm list --long # Extended package information
388
pnpm ll # Long listing by default
389
pnpm outdated --long # Detailed update information
390
```
391
392
## Automation and CI/CD
393
394
### Exit Codes
395
396
Commands return appropriate exit codes for automation:
397
398
```bash { .api }
399
# Exit codes
400
0 # Success, no issues found
401
1 # Issues found (vulnerabilities, outdated packages, etc.)
402
2 # Command error or invalid usage
403
```
404
405
### CI/CD Integration Examples
406
407
```bash { .api }
408
# Check for outdated packages in CI
409
if ! pnpm outdated --json > outdated.json; then
410
echo "Outdated packages found"
411
cat outdated.json
412
fi
413
414
# Security audit in CI pipeline
415
pnpm audit --audit-level moderate --json > audit.json
416
if [ $? -ne 0 ]; then
417
echo "Security vulnerabilities found"
418
exit 1
419
fi
420
421
# License compliance check
422
pnpm licenses list --json > licenses.json
423
# Process licenses.json for compliance
424
```
425
426
### Filtering for Large Workspaces
427
428
Efficiently analyze large workspaces:
429
430
```bash { .api }
431
# Target specific package types
432
pnpm outdated --filter "@myorg/web-*"
433
pnpm audit --filter "frontend-*"
434
435
# Check only changed packages
436
pnpm list --filter "...[HEAD~1]"
437
pnpm outdated --filter "[origin/main]"
438
439
# Production dependency analysis
440
pnpm list --prod --recursive
441
pnpm audit --audit-level high --recursive
442
```
443
444
## Performance Considerations
445
446
### Large Workspace Optimization
447
448
Optimize inspection commands for large workspaces:
449
450
```bash { .api }
451
# Limit depth for faster execution
452
pnpm list --depth=1 --recursive
453
454
# Use filtering to reduce scope
455
pnpm outdated --filter "changed-packages"
456
457
# Parallel execution where supported
458
pnpm audit --recursive # Runs in parallel across packages
459
```
460
461
### Caching Results
462
463
Some commands cache results for improved performance:
464
465
```bash { .api }
466
# Registry information is cached
467
pnpm show <package> # Cached for subsequent calls
468
pnpm outdated # Uses cached registry data
469
470
# Clear cache if needed
471
pnpm cache clean
472
```