dep-brain 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -9
- package/LICENSE +21 -21
- package/README.md +198 -197
- package/depbrain.config.json +20 -20
- package/depbrain.config.schema.json +38 -38
- package/dist/cli.js +52 -17
- package/package.json +53 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
## Unreleased
|
|
6
|
-
|
|
7
|
-
- Workspace-aware analysis for npm workspaces.
|
|
8
|
-
- Config loading and CI policy controls.
|
|
9
|
-
- Improved duplicate detection and unused dependency heuristics.
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
- Workspace-aware analysis for npm workspaces.
|
|
8
|
+
- Config loading and CI policy controls.
|
|
9
|
+
- Improved duplicate detection and unused dependency heuristics.
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Vijay prakash
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vijay prakash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,197 +1,198 @@
|
|
|
1
|
-
# Dependency Brain
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/dep-brain)
|
|
4
|
-
[](https://www.npmjs.com/package/dep-brain)
|
|
5
|
-
[](LICENSE)
|
|
6
|
-
|
|
7
|
-
`dep-brain` is a CLI and library for analyzing dependency health in JavaScript and TypeScript projects.
|
|
8
|
-
|
|
9
|
-
## Vision
|
|
10
|
-
|
|
11
|
-
`npm audit + depcheck + dedupe + intelligence = one tool`
|
|
12
|
-
|
|
13
|
-
## What It Does
|
|
14
|
-
|
|
15
|
-
- Detect duplicate dependencies from `package-lock.json`
|
|
16
|
-
- Detect likely unused dependencies from source imports and scripts
|
|
17
|
-
- Detect outdated packages
|
|
18
|
-
- Highlight dependency risk signals
|
|
19
|
-
- Generate a simple project health score
|
|
20
|
-
- Output reports in human-readable or JSON format
|
|
21
|
-
|
|
22
|
-
## Current MVP Features
|
|
23
|
-
|
|
24
|
-
- Duplicate dependency detection with lockfile instance tracking
|
|
25
|
-
- Unused dependency detection with runtime vs dev-tool heuristics
|
|
26
|
-
- Outdated dependency reporting with `major`, `minor`, and `patch` classification
|
|
27
|
-
- Risk analysis based on npm package metadata
|
|
28
|
-
- Config loading from `depbrain.config.json`
|
|
29
|
-
- Ignore rules for noisy dependencies and checks
|
|
30
|
-
- CI-friendly policy evaluation with non-zero exit codes
|
|
31
|
-
- Workspace-aware analysis for npm workspaces
|
|
32
|
-
- Console reporting
|
|
33
|
-
- JSON output via `--json`
|
|
34
|
-
- Library entrypoint for programmatic use
|
|
35
|
-
|
|
36
|
-
## CLI Usage
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
npm install -g dep-brain
|
|
40
|
-
dep-brain analyze
|
|
41
|
-
|
|
42
|
-
npx dep-brain analyze
|
|
43
|
-
npx dep-brain analyze --json
|
|
44
|
-
npx dep-brain analyze ./path-to-project
|
|
45
|
-
npx dep-brain analyze --config depbrain.config.json
|
|
46
|
-
npx dep-brain analyze --min-score 90 --fail-on-risks
|
|
47
|
-
npx dep-brain analyze ./path-to-project --fail-on-unused --json
|
|
48
|
-
|
|
49
|
-
dep-brain config
|
|
50
|
-
dep-brain config --config depbrain.config.json
|
|
51
|
-
|
|
52
|
-
dep-brain help
|
|
53
|
-
dep-brain analyze --help
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
- `ignore.
|
|
117
|
-
- `ignore.
|
|
118
|
-
- `ignore.
|
|
119
|
-
- `ignore.
|
|
120
|
-
- `ignore.
|
|
121
|
-
- `
|
|
122
|
-
- `policy.
|
|
123
|
-
- `policy.
|
|
124
|
-
- `policy.
|
|
125
|
-
- `policy.
|
|
126
|
-
- `
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
- `depbrain.config.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
dep-brain analyze --
|
|
142
|
-
dep-brain analyze --
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
dep-brain config
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
npm
|
|
159
|
-
npm run
|
|
160
|
-
npm run
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|--
|
|
169
|
-
|--
|
|
170
|
-
|
|
171
|
-
| |--
|
|
172
|
-
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
| |--
|
|
176
|
-
| |--
|
|
177
|
-
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
|
181
|
-
`--
|
|
182
|
-
|
|
183
|
-
|--
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
- Improve
|
|
191
|
-
-
|
|
192
|
-
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
-
|
|
1
|
+
# Dependency Brain
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/dep-brain)
|
|
4
|
+
[](https://www.npmjs.com/package/dep-brain)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
`dep-brain` is a CLI and library for analyzing dependency health in JavaScript and TypeScript projects.
|
|
8
|
+
|
|
9
|
+
## Vision
|
|
10
|
+
|
|
11
|
+
`npm audit + depcheck + dedupe + intelligence = one tool`
|
|
12
|
+
|
|
13
|
+
## What It Does
|
|
14
|
+
|
|
15
|
+
- Detect duplicate dependencies from `package-lock.json`
|
|
16
|
+
- Detect likely unused dependencies from source imports and scripts
|
|
17
|
+
- Detect outdated packages
|
|
18
|
+
- Highlight dependency risk signals
|
|
19
|
+
- Generate a simple project health score
|
|
20
|
+
- Output reports in human-readable or JSON format
|
|
21
|
+
|
|
22
|
+
## Current MVP Features
|
|
23
|
+
|
|
24
|
+
- Duplicate dependency detection with lockfile instance tracking
|
|
25
|
+
- Unused dependency detection with runtime vs dev-tool heuristics
|
|
26
|
+
- Outdated dependency reporting with `major`, `minor`, and `patch` classification
|
|
27
|
+
- Risk analysis based on npm package metadata
|
|
28
|
+
- Config loading from `depbrain.config.json`
|
|
29
|
+
- Ignore rules for noisy dependencies and checks
|
|
30
|
+
- CI-friendly policy evaluation with non-zero exit codes
|
|
31
|
+
- Workspace-aware analysis for npm workspaces
|
|
32
|
+
- Console reporting
|
|
33
|
+
- JSON output via `--json`
|
|
34
|
+
- Library entrypoint for programmatic use
|
|
35
|
+
|
|
36
|
+
## CLI Usage
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g dep-brain
|
|
40
|
+
dep-brain analyze
|
|
41
|
+
|
|
42
|
+
npx dep-brain analyze
|
|
43
|
+
npx dep-brain analyze --json
|
|
44
|
+
npx dep-brain analyze ./path-to-project
|
|
45
|
+
npx dep-brain analyze --config depbrain.config.json
|
|
46
|
+
npx dep-brain analyze --min-score 90 --fail-on-risks
|
|
47
|
+
npx dep-brain analyze ./path-to-project --fail-on-unused --json
|
|
48
|
+
|
|
49
|
+
dep-brain config
|
|
50
|
+
dep-brain config --config depbrain.config.json
|
|
51
|
+
|
|
52
|
+
dep-brain help
|
|
53
|
+
dep-brain analyze --help
|
|
54
|
+
dep-brain --version
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Workspaces
|
|
58
|
+
|
|
59
|
+
If the root `package.json` defines `workspaces`, `dep-brain` analyzes each workspace package and reports per-package results. Aggregated counts are still shown at the top-level summary.
|
|
60
|
+
|
|
61
|
+
## Example Output
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
Project Health: 78/100
|
|
65
|
+
Path: /your/project
|
|
66
|
+
Policy: FAIL
|
|
67
|
+
|
|
68
|
+
WARN Duplicates: 2
|
|
69
|
+
OK Unused: 0
|
|
70
|
+
WARN Outdated: 3
|
|
71
|
+
OK Risks: 0
|
|
72
|
+
|
|
73
|
+
Duplicate dependencies:
|
|
74
|
+
- ansi-regex: 5.0.1, 6.0.1
|
|
75
|
+
|
|
76
|
+
Outdated dependencies:
|
|
77
|
+
- chalk: ^4.1.2 -> 5.4.1 [major]
|
|
78
|
+
|
|
79
|
+
Policy reasons:
|
|
80
|
+
- Score 78 is below minimum 90
|
|
81
|
+
|
|
82
|
+
Suggestions:
|
|
83
|
+
- Consider consolidating ansi-regex to one version
|
|
84
|
+
- Review chalk: ^4.1.2 -> 5.4.1 (major)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## JSON Output
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
dep-brain analyze --json
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Config File
|
|
94
|
+
|
|
95
|
+
Create a `depbrain.config.json` file in the project root:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"ignore": {
|
|
100
|
+
"unused": ["eslint"],
|
|
101
|
+
"outdated": ["typescript"]
|
|
102
|
+
},
|
|
103
|
+
"policy": {
|
|
104
|
+
"minScore": 90,
|
|
105
|
+
"failOnUnused": true,
|
|
106
|
+
"failOnRisks": true
|
|
107
|
+
},
|
|
108
|
+
"report": {
|
|
109
|
+
"maxSuggestions": 3
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Supported sections:
|
|
115
|
+
|
|
116
|
+
- `ignore.dependencies`
|
|
117
|
+
- `ignore.devDependencies`
|
|
118
|
+
- `ignore.unused`
|
|
119
|
+
- `ignore.duplicates`
|
|
120
|
+
- `ignore.outdated`
|
|
121
|
+
- `ignore.risks`
|
|
122
|
+
- `policy.minScore`
|
|
123
|
+
- `policy.failOnDuplicates`
|
|
124
|
+
- `policy.failOnUnused`
|
|
125
|
+
- `policy.failOnOutdated`
|
|
126
|
+
- `policy.failOnRisks`
|
|
127
|
+
- `report.maxSuggestions`
|
|
128
|
+
|
|
129
|
+
Sample config file:
|
|
130
|
+
|
|
131
|
+
- `depbrain.config.json`
|
|
132
|
+
- `depbrain.config.schema.json`
|
|
133
|
+
|
|
134
|
+
## CI Behavior
|
|
135
|
+
|
|
136
|
+
`dep-brain` now returns a non-zero exit code when configured policy checks fail.
|
|
137
|
+
|
|
138
|
+
Examples:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
dep-brain analyze --fail-on-unused
|
|
142
|
+
dep-brain analyze --min-score 85 --fail-on-risks
|
|
143
|
+
dep-brain analyze --config depbrain.config.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Config Debugging
|
|
147
|
+
|
|
148
|
+
Print the resolved config (after defaults and CLI overrides):
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
dep-brain config
|
|
152
|
+
dep-brain config --config depbrain.config.json
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npm install
|
|
159
|
+
npm run typecheck
|
|
160
|
+
npm run test
|
|
161
|
+
npm run build
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Project Structure
|
|
165
|
+
|
|
166
|
+
```text
|
|
167
|
+
src/
|
|
168
|
+
|-- cli.ts
|
|
169
|
+
|-- index.ts
|
|
170
|
+
|-- core/
|
|
171
|
+
| |-- analyzer.ts
|
|
172
|
+
| |-- graph-builder.ts
|
|
173
|
+
| `-- scorer.ts
|
|
174
|
+
|-- checks/
|
|
175
|
+
| |-- duplicate.ts
|
|
176
|
+
| |-- unused.ts
|
|
177
|
+
| |-- outdated.ts
|
|
178
|
+
| `-- risk.ts
|
|
179
|
+
|-- reporters/
|
|
180
|
+
| |-- console.ts
|
|
181
|
+
| `-- json.ts
|
|
182
|
+
`-- utils/
|
|
183
|
+
|-- file-parser.ts
|
|
184
|
+
|-- npm-api.ts
|
|
185
|
+
`-- config.ts
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Roadmap Direction
|
|
189
|
+
|
|
190
|
+
- Improve false-positive reduction for unused dependency detection
|
|
191
|
+
- Improve monorepo and workspace support
|
|
192
|
+
- Strengthen risk scoring and suggestions
|
|
193
|
+
- Add CI and GitHub Action support in later releases
|
|
194
|
+
|
|
195
|
+
## Repository Notes
|
|
196
|
+
|
|
197
|
+
- Project brief: [docs/project-brief.md](./docs/project-brief.md)
|
|
198
|
+
- Implementation history: [docs/implementation-log.md](./docs/implementation-log.md)
|
package/depbrain.config.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ignore": {
|
|
3
|
-
"unused": [],
|
|
4
|
-
"outdated": [],
|
|
5
|
-
"duplicates": [],
|
|
6
|
-
"risks": [],
|
|
7
|
-
"dependencies": [],
|
|
8
|
-
"devDependencies": []
|
|
9
|
-
},
|
|
10
|
-
"policy": {
|
|
11
|
-
"minScore": 85,
|
|
12
|
-
"failOnUnused": false,
|
|
13
|
-
"failOnOutdated": false,
|
|
14
|
-
"failOnDuplicates": false,
|
|
15
|
-
"failOnRisks": false
|
|
16
|
-
},
|
|
17
|
-
"report": {
|
|
18
|
-
"maxSuggestions": 5
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"ignore": {
|
|
3
|
+
"unused": [],
|
|
4
|
+
"outdated": [],
|
|
5
|
+
"duplicates": [],
|
|
6
|
+
"risks": [],
|
|
7
|
+
"dependencies": [],
|
|
8
|
+
"devDependencies": []
|
|
9
|
+
},
|
|
10
|
+
"policy": {
|
|
11
|
+
"minScore": 85,
|
|
12
|
+
"failOnUnused": false,
|
|
13
|
+
"failOnOutdated": false,
|
|
14
|
+
"failOnDuplicates": false,
|
|
15
|
+
"failOnRisks": false
|
|
16
|
+
},
|
|
17
|
+
"report": {
|
|
18
|
+
"maxSuggestions": 5
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"title": "Dependency Brain Config",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"additionalProperties": false,
|
|
6
|
-
"properties": {
|
|
7
|
-
"ignore": {
|
|
8
|
-
"type": "object",
|
|
9
|
-
"additionalProperties": false,
|
|
10
|
-
"properties": {
|
|
11
|
-
"dependencies": { "type": "array", "items": { "type": "string" } },
|
|
12
|
-
"devDependencies": { "type": "array", "items": { "type": "string" } },
|
|
13
|
-
"unused": { "type": "array", "items": { "type": "string" } },
|
|
14
|
-
"duplicates": { "type": "array", "items": { "type": "string" } },
|
|
15
|
-
"outdated": { "type": "array", "items": { "type": "string" } },
|
|
16
|
-
"risks": { "type": "array", "items": { "type": "string" } }
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"policy": {
|
|
20
|
-
"type": "object",
|
|
21
|
-
"additionalProperties": false,
|
|
22
|
-
"properties": {
|
|
23
|
-
"minScore": { "type": "number" },
|
|
24
|
-
"failOnUnused": { "type": "boolean" },
|
|
25
|
-
"failOnOutdated": { "type": "boolean" },
|
|
26
|
-
"failOnDuplicates": { "type": "boolean" },
|
|
27
|
-
"failOnRisks": { "type": "boolean" }
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"report": {
|
|
31
|
-
"type": "object",
|
|
32
|
-
"additionalProperties": false,
|
|
33
|
-
"properties": {
|
|
34
|
-
"maxSuggestions": { "type": "number" }
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "Dependency Brain Config",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"additionalProperties": false,
|
|
6
|
+
"properties": {
|
|
7
|
+
"ignore": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"additionalProperties": false,
|
|
10
|
+
"properties": {
|
|
11
|
+
"dependencies": { "type": "array", "items": { "type": "string" } },
|
|
12
|
+
"devDependencies": { "type": "array", "items": { "type": "string" } },
|
|
13
|
+
"unused": { "type": "array", "items": { "type": "string" } },
|
|
14
|
+
"duplicates": { "type": "array", "items": { "type": "string" } },
|
|
15
|
+
"outdated": { "type": "array", "items": { "type": "string" } },
|
|
16
|
+
"risks": { "type": "array", "items": { "type": "string" } }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"policy": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"additionalProperties": false,
|
|
22
|
+
"properties": {
|
|
23
|
+
"minScore": { "type": "number" },
|
|
24
|
+
"failOnUnused": { "type": "boolean" },
|
|
25
|
+
"failOnOutdated": { "type": "boolean" },
|
|
26
|
+
"failOnDuplicates": { "type": "boolean" },
|
|
27
|
+
"failOnRisks": { "type": "boolean" }
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"report": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"additionalProperties": false,
|
|
33
|
+
"properties": {
|
|
34
|
+
"maxSuggestions": { "type": "number" }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -6,11 +6,13 @@ import { promises as fs } from "node:fs";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
async function main() {
|
|
8
8
|
const args = process.argv.slice(2);
|
|
9
|
-
const
|
|
9
|
+
const firstArg = args[0];
|
|
10
|
+
const command = firstArg && !firstArg.startsWith("--") ? firstArg : "analyze";
|
|
10
11
|
const optionValues = new Map();
|
|
11
12
|
const flags = new Set();
|
|
12
13
|
const positionals = [];
|
|
13
|
-
|
|
14
|
+
const startIndex = firstArg && !firstArg.startsWith("--") ? 1 : 0;
|
|
15
|
+
for (let index = startIndex; index < args.length; index += 1) {
|
|
14
16
|
const value = args[index];
|
|
15
17
|
if (!value?.startsWith("--")) {
|
|
16
18
|
positionals.push(value);
|
|
@@ -30,6 +32,11 @@ async function main() {
|
|
|
30
32
|
printHelp();
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
35
|
+
if (flags.has("--version")) {
|
|
36
|
+
const version = await loadPackageVersion();
|
|
37
|
+
console.log(version ?? "unknown");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
33
40
|
if (command !== "analyze") {
|
|
34
41
|
if (command === "config") {
|
|
35
42
|
if (!(await hasPackageJson(targetPath))) {
|
|
@@ -37,13 +44,21 @@ async function main() {
|
|
|
37
44
|
process.exitCode = 1;
|
|
38
45
|
return;
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
try {
|
|
48
|
+
const config = await analyzeProject({
|
|
49
|
+
rootDir: targetPath,
|
|
50
|
+
configPath: optionValues.get("--config"),
|
|
51
|
+
config: buildCliConfig(flags, optionValues)
|
|
52
|
+
});
|
|
53
|
+
console.log(JSON.stringify(config.config, null, 2));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("Failed to resolve config.");
|
|
58
|
+
console.error(error);
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
47
62
|
}
|
|
48
63
|
console.error(`Unknown command: ${command}`);
|
|
49
64
|
printHelp();
|
|
@@ -55,14 +70,21 @@ async function main() {
|
|
|
55
70
|
process.exitCode = 1;
|
|
56
71
|
return;
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
try {
|
|
74
|
+
const cliConfig = buildCliConfig(flags, optionValues);
|
|
75
|
+
const result = await analyzeProject({
|
|
76
|
+
rootDir: targetPath,
|
|
77
|
+
configPath: optionValues.get("--config"),
|
|
78
|
+
config: cliConfig
|
|
79
|
+
});
|
|
80
|
+
console.log(flags.has("--json") ? renderJsonReport(result) : renderConsoleReport(result));
|
|
81
|
+
if (!result.policy.passed) {
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error("Analysis failed.");
|
|
87
|
+
console.error(error);
|
|
66
88
|
process.exitCode = 1;
|
|
67
89
|
}
|
|
68
90
|
}
|
|
@@ -105,6 +127,7 @@ function printHelp() {
|
|
|
105
127
|
console.log(" dep-brain analyze [path] [--json] [--config path] [--min-score n] [--fail-on-risks] [--fail-on-outdated] [--fail-on-unused] [--fail-on-duplicates]");
|
|
106
128
|
console.log(" dep-brain config [path] [--config path]");
|
|
107
129
|
console.log(" dep-brain help");
|
|
130
|
+
console.log(" dep-brain --version");
|
|
108
131
|
console.log("");
|
|
109
132
|
console.log("Options:");
|
|
110
133
|
console.log(" --json Output JSON for analysis");
|
|
@@ -115,4 +138,16 @@ function printHelp() {
|
|
|
115
138
|
console.log(" --fail-on-unused Fail when unused dependencies exist");
|
|
116
139
|
console.log(" --fail-on-duplicates Fail when duplicates exist");
|
|
117
140
|
console.log(" --help Show this help output");
|
|
141
|
+
console.log(" --version Show CLI version");
|
|
142
|
+
}
|
|
143
|
+
async function loadPackageVersion() {
|
|
144
|
+
try {
|
|
145
|
+
const pkgPath = new URL("../package.json", import.meta.url);
|
|
146
|
+
const content = await fs.readFile(pkgPath, "utf8");
|
|
147
|
+
const pkg = JSON.parse(content);
|
|
148
|
+
return pkg.version ?? null;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
118
153
|
}
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dep-brain",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "CLI and library for dependency health analysis",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"bin": {
|
|
9
|
-
"dep-brain": "dist/cli.js"
|
|
10
|
-
},
|
|
11
|
-
"files": [
|
|
12
|
-
"dist",
|
|
13
|
-
"README.md",
|
|
14
|
-
"LICENSE",
|
|
15
|
-
"CHANGELOG.md",
|
|
16
|
-
"depbrain.config.json",
|
|
17
|
-
"depbrain.config.schema.json"
|
|
18
|
-
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc -p tsconfig.json",
|
|
21
|
-
"clean": "if exist dist rmdir /s /q dist",
|
|
22
|
-
"dev": "tsx src/cli.ts analyze",
|
|
23
|
-
"start": "node dist/cli.js analyze",
|
|
24
|
-
"test": "npm run build && node tests/run.js",
|
|
25
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"dependencies",
|
|
29
|
-
"cli",
|
|
30
|
-
"analysis",
|
|
31
|
-
"npm",
|
|
32
|
-
"audit"
|
|
33
|
-
],
|
|
34
|
-
"author": "",
|
|
35
|
-
"license": "MIT",
|
|
36
|
-
"repository": {
|
|
37
|
-
"type": "git",
|
|
38
|
-
"url": "git+ssh://git@github.com/prakashu51/dep-brain.git"
|
|
39
|
-
},
|
|
40
|
-
"bugs": {
|
|
41
|
-
"url": "https://github.com/prakashu51/dep-brain/issues"
|
|
42
|
-
},
|
|
43
|
-
"homepage": "https://github.com/prakashu51/dep-brain#readme",
|
|
44
|
-
"engines": {
|
|
45
|
-
"node": ">=18"
|
|
46
|
-
},
|
|
47
|
-
"dependencies": {},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@types/node": "^24.5.2",
|
|
50
|
-
"tsx": "^4.20.5",
|
|
51
|
-
"typescript": "^5.9.2"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dep-brain",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "CLI and library for dependency health analysis",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"dep-brain": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"depbrain.config.json",
|
|
17
|
+
"depbrain.config.schema.json"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"clean": "if exist dist rmdir /s /q dist",
|
|
22
|
+
"dev": "tsx src/cli.ts analyze",
|
|
23
|
+
"start": "node dist/cli.js analyze",
|
|
24
|
+
"test": "npm run build && node tests/run.js",
|
|
25
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"dependencies",
|
|
29
|
+
"cli",
|
|
30
|
+
"analysis",
|
|
31
|
+
"npm",
|
|
32
|
+
"audit"
|
|
33
|
+
],
|
|
34
|
+
"author": "",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+ssh://git@github.com/prakashu51/dep-brain.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/prakashu51/dep-brain/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/prakashu51/dep-brain#readme",
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^24.5.2",
|
|
50
|
+
"tsx": "^4.20.5",
|
|
51
|
+
"typescript": "^5.9.2"
|
|
52
|
+
}
|
|
53
|
+
}
|