You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/technical/detectors/npm_detector.md
+54-30Lines changed: 54 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,35 +2,37 @@
2
2
3
3
## Purpose & Scope
4
4
5
-
The NPM detector identifies Node.js packages managed by `npm` in project environments. It provides structured package information with intelligent package manager detection to avoid conflicts with other Node.js package managers (yarn, pnpm, bun).
5
+
The NPM detector identifies Node.js packages managed by `npm` in both project and system environments. It supports multi-location detection to capture project dependencies and globally installed packages simultaneously.
6
6
7
7
## Key Features
8
8
9
+
### Multi-Location Detection
10
+
11
+
Detects npm packages in multiple locations:
12
+
13
+
-**Local dependencies**: Project-level packages via `npm list --json --depth=0`
14
+
-**Global packages**: System-level packages via `npm list -g --json --depth=0`
15
+
-**Mixed output**: Returns both when present in same environment
16
+
9
17
### Smart Package Manager Detection
10
18
11
-
The detector avoids conflicts with other Node.js package managers by checking for lock files:
19
+
For local projects, avoids conflicts with other Node.js package managers:
12
20
13
21
**Exclusion checks:**
14
22
15
-
-`yarn.lock` exists → Skip (defer to yarn)
16
-
-`pnpm-lock.yaml` exists → Skip (defer to pnpm)
17
-
-`bun.lockb` exists → Skip (defer to bun)
23
+
-`yarn.lock` exists → Skip local detection (defer to yarn)
24
+
-`pnpm-lock.yaml` exists → Skip local detection (defer to pnpm)
25
+
-`bun.lockb` exists → Skip local detection (defer to bun)
18
26
19
27
**Inclusion checks:**
20
28
21
-
-`package.json` or `package-lock.json` exists
29
+
-`package.json`, `node_modules`, or `package-lock.json` exists
22
30
- No conflicting lock files present
23
31
24
-
### Project Context Detection
25
-
26
-
Determines scope based on project indicators:
27
-
28
-
-**Project scope**: When `package.json` or `node_modules` exists
29
-
-**System scope**: When no project indicators found
32
+
## Commands Used
30
33
31
-
## Command Used
32
-
33
-
-**Package listing**: `npm list --json --depth=0` for structured JSON output of direct dependencies only
34
+
-**Local packages**: `npm list --json --depth=0`
35
+
-**Global packages**: `npm list -g --json --depth=0`
34
36
35
37
## Hash Generation
36
38
@@ -45,7 +47,7 @@ Individual package-level hashes are **not implemented** for npm dependencies. Th
45
47
46
48
### Directory Content Hashing
47
49
48
-
For project-scoped dependencies, generates location-based hashes by scanning the project directory while excluding:
50
+
Generates location-based hashes for both project and system locations while excluding:
49
51
50
52
- npm cache directories (`node_modules/.cache`)
51
53
- Log files (`*.log`)
@@ -54,32 +56,54 @@ For project-scoped dependencies, generates location-based hashes by scanning the
54
56
55
57
## Output Format
56
58
57
-
**Project Scope** (with location hash):
58
-
59
-
- Includes `scope: "project"`, project location, and content hash
60
-
- Contains only direct dependencies from the project
61
-
62
-
**System Scope** (no location/hash):
63
-
64
-
- Includes `scope: "system"`
65
-
- Contains system-wide npm packages
59
+
**Single Location** (project or system):
60
+
61
+
```json
62
+
{
63
+
"scope": "project"| "system",
64
+
"location": "/path/to/location",
65
+
"hash": "abc123...",
66
+
"dependencies": {...}
67
+
}
68
+
```
69
+
70
+
**Mixed Locations** (both project and global):
71
+
72
+
```json
73
+
{
74
+
"scope": "mixed",
75
+
"locations": {
76
+
"/path/to/project": {
77
+
"scope": "project",
78
+
"hash": "abc123...",
79
+
"dependencies": {...}
80
+
},
81
+
"/usr/lib/node_modules": {
82
+
"scope": "system",
83
+
"hash": "def456...",
84
+
"dependencies": {...}
85
+
}
86
+
}
87
+
}
88
+
```
66
89
67
90
## Benefits
68
91
92
+
-**Complete visibility**: Captures both project and global npm packages
69
93
-**Conflict avoidance**: Prevents npm from running in yarn/pnpm/bun projects
70
-
-**Project isolation**: Distinguishes project dependencies from system packages
94
+
-**Multi-location support**: Follows pip_detector pattern for consistency
0 commit comments