depgraph-core 1.0.2 β 1.0.3
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/README.md +181 -105
- package/depgraph-output.json +1273 -233
- package/depgraph.js +349 -66
- package/docs/README.md +56 -0
- package/docs/architecture.md +89 -0
- package/docs/data-types.md +218 -0
- package/docs/language-registry.md +205 -0
- package/docs/stage-collector.md +109 -0
- package/docs/stage-graph.md +157 -0
- package/docs/stage-impact.md +154 -0
- package/docs/stage-metrics.md +113 -0
- package/docs/stage-output.md +144 -0
- package/docs/stage-parser.md +144 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,33 +3,30 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/depgraph-core)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
**DepGraph Core** is a powerful static analysis
|
|
6
|
+
**DepGraph Core** is a powerful static analysis CLI that maps code dependencies and simulates the ripple-effect impact of changes in JavaScript, TypeScript, Python, and Go projects. By parsing imports, exports, functions, and classes, DepGraph constructs a comprehensive dependency graph, computes centrality metrics, and generates impact simulations β helping you prevent regression bugs in large codebases.
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
## π Key Features
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
- π **Automated Code Parsing**: Supports JS, TS, React (`.js`, `.jsx`, `.ts`, `.tsx`, `.mjs`, `.cjs`), Python (`.py`), and Go (`.go`) β extracting functions, classes, interfaces, types, React hooks/components, and Express routes.
|
|
13
|
+
- πΈοΈ **Dependency Graph Reconstruction**: Resolves local imports and links entities across files to build a full topology map of your codebase.
|
|
14
|
+
- π **Metrics & Centrality Analysis**: Calculates in-degree, out-degree, and centrality scores for every entity to automatically identify **Critical Nodes**.
|
|
15
|
+
- π₯ **Impact Simulation Engine**: Runs a reverse BFS to model the cascading impact of changing a specific function or class. Generates a risk score, lists affected nodes, and provides an actionable testing plan.
|
|
16
|
+
- 𧬠**Git Diff Integration**: Automatically detects changed entities from your git history (uncommitted changes, a specific commit, or a branch comparison) and runs impact simulation on every changed function β no manual target needed.
|
|
17
|
+
- π₯οΈ **Rich CLI Interface**: Colorized, human-readable output with a `--no-color` flag for CI/CD pipelines.
|
|
18
|
+
- πΎ **Detailed JSON Output**: Exports a comprehensive report containing graph structure, metrics, and simulation results.
|
|
18
19
|
|
|
19
20
|
---
|
|
20
21
|
|
|
21
22
|
## π¦ Installation
|
|
22
23
|
|
|
23
|
-
### Global
|
|
24
|
-
Install `depgraph-core` globally via npm to run it anywhere:
|
|
25
|
-
|
|
24
|
+
### Global (recommended)
|
|
26
25
|
```bash
|
|
27
26
|
npm install -g depgraph-core
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
###
|
|
31
|
-
Alternatively, execute it directly without local installation:
|
|
32
|
-
|
|
29
|
+
### Via `npx` (no install required)
|
|
33
30
|
```bash
|
|
34
31
|
npx depgraph-core <projectDir> [options]
|
|
35
32
|
```
|
|
@@ -46,73 +43,195 @@ depgraph <projectDir> [options]
|
|
|
46
43
|
|
|
47
44
|
| Flag | Parameter | Description | Default |
|
|
48
45
|
| :--- | :--- | :--- | :--- |
|
|
49
|
-
| `--output` | `<file>` | Output path for the generated JSON report
|
|
50
|
-
| `--impact` | `<name> <desc>` |
|
|
51
|
-
| `--verbose` | β | Print per-file parsing
|
|
52
|
-
| `--no-color` | β | Disable
|
|
53
|
-
| `--help`, `-h` | β |
|
|
46
|
+
| `--output` | `<file>` | Output path for the generated JSON report | `./depgraph-output.json` |
|
|
47
|
+
| `--impact` | `<name> <desc>` | Manually simulate changing a specific entity | β |
|
|
48
|
+
| `--verbose` | β | Print per-file parsing details | `false` |
|
|
49
|
+
| `--no-color` | β | Disable ANSI color output (for CI/CD) | `false` |
|
|
50
|
+
| `--help`, `-h` | β | Show help message | β |
|
|
51
|
+
|
|
52
|
+
### Git Flags
|
|
53
|
+
|
|
54
|
+
| Flag | Parameter | Description |
|
|
55
|
+
| :--- | :--- | :--- |
|
|
56
|
+
| `--git-impact` | β | Auto-detect changed entities from git diff and run impact simulation |
|
|
57
|
+
| `--commit` | `<sha>` | Analyze a specific commit (vs its parent) |
|
|
58
|
+
| `--from` | `<branch>` | Compare from this branch (use with `--to`) |
|
|
59
|
+
| `--to` | `<branch>` | Compare to this branch (use with `--from`) |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## π Examples
|
|
54
64
|
|
|
55
|
-
###
|
|
65
|
+
### Standard Usage
|
|
56
66
|
|
|
57
|
-
####
|
|
67
|
+
#### Map a project
|
|
58
68
|
```bash
|
|
59
69
|
depgraph ./src
|
|
60
70
|
```
|
|
61
71
|
|
|
62
|
-
####
|
|
72
|
+
#### Custom output path
|
|
63
73
|
```bash
|
|
64
74
|
depgraph ./src --output ./reports/graph-report.json
|
|
65
75
|
```
|
|
66
76
|
|
|
67
|
-
####
|
|
77
|
+
#### Manually simulate a change
|
|
68
78
|
```bash
|
|
69
79
|
depgraph ./src --impact "getUserById" "adding middleName field to returned object"
|
|
70
80
|
```
|
|
71
81
|
|
|
72
|
-
####
|
|
82
|
+
#### CI mode
|
|
73
83
|
```bash
|
|
74
84
|
depgraph ./src --no-color --output ./ci/depgraph.json
|
|
75
85
|
```
|
|
76
86
|
|
|
77
87
|
---
|
|
78
88
|
|
|
89
|
+
### 𧬠Git Diff Integration
|
|
90
|
+
|
|
91
|
+
`--git-impact` automatically reads your git diff, detects every function or class that changed, and runs an impact simulation for each one β no need to manually select a target entity.
|
|
92
|
+
|
|
93
|
+
#### βοΈ How It Works under the Hood
|
|
94
|
+
|
|
95
|
+
1. **Git Diff Execution**: Runs the appropriate git command depending on the mode:
|
|
96
|
+
- **Uncommitted Changes**: `git diff HEAD` (detects staged & unstaged changes).
|
|
97
|
+
- **Last Commit (or Specific Commit)**: `git diff <commit>~1 <commit>` (compares the target commit against its parent).
|
|
98
|
+
- **Branch Comparison**: `git diff <from>...<to>` (finds the merge base and diffs to the target branch).
|
|
99
|
+
2. **Context Parsing**: Scans git diff context lines (headers starting with `@@`) to extract target entities.
|
|
100
|
+
3. **No Regex Duplication**: Reuses the regex patterns defined in the language parsers (`jsEntityPatterns`, `pyEntityPatterns`, `goEntityPatterns`) via the language registry.
|
|
101
|
+
4. **Fallback Parsers**: Contains built-in fallback parser logic for popular OOP languages like Java (`.java`) and C# (`.cs`) to extract method signatures.
|
|
102
|
+
5. **Change Description Generation**: Automatically analyzes added/removed lines in the change hunk to build descriptive labels (e.g. `getUserById: 3 line(s) changed to 2 new line(s)`).
|
|
103
|
+
|
|
104
|
+
#### π Git Commands Reference
|
|
105
|
+
|
|
106
|
+
| Mode | CLI Command | Under-the-hood Command | Description |
|
|
107
|
+
| :--- | :--- | :--- | :--- |
|
|
108
|
+
| **Uncommitted Changes** | `depgraph ./src --git-impact` | `git diff HEAD` | Analyze your current workspace changes |
|
|
109
|
+
| **Last Commit** | `depgraph ./src --git-impact --commit HEAD` | `git diff HEAD~1 HEAD` | Analyze the last commit |
|
|
110
|
+
| **Specific Commit** | `depgraph ./src --git-impact --commit <sha>` | `git diff <sha>~1 <sha>` | Analyze any commit by its SHA |
|
|
111
|
+
| **Branch Comparison** | `depgraph ./src --git-impact --from main --to feature/auth` | `git diff main...feature/auth` | Compare two branches |
|
|
112
|
+
|
|
113
|
+
#### π₯οΈ CLI Output Example
|
|
114
|
+
|
|
115
|
+
Running `--git-impact` displays a colorized report of detected entities and runs an impact simulation for each one:
|
|
116
|
+
|
|
117
|
+
```text
|
|
118
|
+
βββββββββββββββββββββββββββββββββββββββββ
|
|
119
|
+
DepGraph v1.0.0
|
|
120
|
+
βββββββββββββββββββββββββββββββββββββββββ
|
|
121
|
+
|
|
122
|
+
π Scanning .
|
|
123
|
+
|
|
124
|
+
π Graph Summary
|
|
125
|
+
Files : 27
|
|
126
|
+
Nodes : 76
|
|
127
|
+
Edges : 252
|
|
128
|
+
|
|
129
|
+
π Reading git diff...
|
|
130
|
+
|
|
131
|
+
Found 2 changed entity(s):
|
|
132
|
+
β slugify (src/languages/javascript.ts)
|
|
133
|
+
β LanguageParser (src/languages/registry.ts)
|
|
134
|
+
|
|
135
|
+
Running impact simulation...
|
|
136
|
+
|
|
137
|
+
ββββββββββββββββββββββββββββββββββββββββββ
|
|
138
|
+
|
|
139
|
+
π₯ Impact Simulation
|
|
140
|
+
Target : slugify__javascript
|
|
141
|
+
Change : slugify: 16 line(s) added
|
|
142
|
+
Risk Score : 0
|
|
143
|
+
Risk Level : LOW
|
|
144
|
+
|
|
145
|
+
β No affected nodes found
|
|
146
|
+
|
|
147
|
+
π§ͺ Testing Plan
|
|
148
|
+
β Test slugify directly after making changes
|
|
149
|
+
|
|
150
|
+
π‘ Recommendations
|
|
151
|
+
β Standard PR process is sufficient
|
|
152
|
+
β Unit tests for the changed node are enough
|
|
153
|
+
|
|
154
|
+
ββββββββββββββββββββββββββββββββββββββββββ
|
|
155
|
+
|
|
156
|
+
π₯ Impact Simulation
|
|
157
|
+
Target : LanguageParser__registry
|
|
158
|
+
Change : LanguageParser: 6 line(s) added
|
|
159
|
+
Risk Score : 100
|
|
160
|
+
Risk Level : CRITICAL
|
|
161
|
+
|
|
162
|
+
π Affected Nodes (3)
|
|
163
|
+
|
|
164
|
+
[CRITICAL] extractEntities
|
|
165
|
+
file : src/languages/go.ts
|
|
166
|
+
reason : extractEntities directly imports LanguageParser
|
|
167
|
+
action : Update extractEntities to handle the new interface of LanguageParser
|
|
168
|
+
breaking: YES
|
|
169
|
+
|
|
170
|
+
[CRITICAL] extractImports
|
|
171
|
+
file : src/languages/go.ts
|
|
172
|
+
reason : extractImports directly imports LanguageParser
|
|
173
|
+
action : Update extractImports to handle the new interface of LanguageParser
|
|
174
|
+
breaking: YES
|
|
175
|
+
|
|
176
|
+
[CRITICAL] extractExports
|
|
177
|
+
file : src/languages/go.ts
|
|
178
|
+
reason : extractExports directly imports LanguageParser
|
|
179
|
+
action : Update extractExports to handle the new interface of LanguageParser
|
|
180
|
+
breaking: YES
|
|
181
|
+
|
|
182
|
+
π§ͺ Testing Plan
|
|
183
|
+
β Test LanguageParser directly after making changes
|
|
184
|
+
β Regression test extractEntities β direct dependent
|
|
185
|
+
β Regression test extractImports β direct dependent
|
|
186
|
+
β Regression test extractExports β direct dependent
|
|
187
|
+
β Run full test suite β 3 nodes affected
|
|
188
|
+
|
|
189
|
+
π‘ Recommendations
|
|
190
|
+
β Full team review required before merging
|
|
191
|
+
β Consider a phased rollout
|
|
192
|
+
β Run full regression test suite
|
|
193
|
+
β 3 breaking change(s) must be updated before deploying
|
|
194
|
+
|
|
195
|
+
β
Output written to ./depgraph-output.json
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Supported languages for diff parsing:** JavaScript/TypeScript, Python, Go. Java and C# method signatures are handled via a built-in fallback.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
79
202
|
## π₯ Impact Simulation Mechanics
|
|
80
203
|
|
|
81
|
-
When
|
|
204
|
+
When running `--impact` or `--git-impact`, the tool performs:
|
|
205
|
+
|
|
82
206
|
1. **Target Identification**: Locates the node matching the provided name.
|
|
83
|
-
2. **Reverse BFS Traversal**: Traverses backwards up the dependency graph up to
|
|
84
|
-
3. **Risk Scoring**: Calculates a score from `0
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
207
|
+
2. **Reverse BFS Traversal**: Traverses backwards up the dependency graph (up to depth 10) to find all direct and indirect dependents.
|
|
208
|
+
3. **Risk Scoring**: Calculates a score from `0β100` based on:
|
|
209
|
+
- Number of critical-impact nodes (depth 1)
|
|
210
|
+
- Number of high-impact nodes (depth 2)
|
|
211
|
+
- Number of medium/low-impact nodes
|
|
212
|
+
- The target node's in-degree
|
|
89
213
|
4. **Risk Level Mapping**:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
214
|
+
- π΄ **CRITICAL** (β₯ 75): Comprehensive review, phased rollout, full regression testing.
|
|
215
|
+
- π‘ **HIGH** (50β74): Tech lead review, feature flag recommended.
|
|
216
|
+
- π΅ **MEDIUM** (25β49): Standard peer review, targeted module testing.
|
|
217
|
+
- π’ **LOW** (< 25): Standard PR process is sufficient.
|
|
94
218
|
|
|
95
219
|
---
|
|
96
220
|
|
|
97
221
|
## π Output JSON Schema
|
|
98
222
|
|
|
99
|
-
The tool generates a JSON report containing the following structure:
|
|
100
|
-
|
|
101
223
|
```json
|
|
102
224
|
{
|
|
103
225
|
"meta": {
|
|
104
|
-
"version": "1.0.
|
|
105
|
-
"timestamp": "2026-07-
|
|
106
|
-
"totalFiles":
|
|
107
|
-
"totalLines":
|
|
226
|
+
"version": "1.0.2",
|
|
227
|
+
"timestamp": "2026-07-20T05:14:00.000Z",
|
|
228
|
+
"totalFiles": 26,
|
|
229
|
+
"totalLines": 2957
|
|
108
230
|
},
|
|
109
231
|
"summary": {
|
|
110
|
-
"totalNodes":
|
|
111
|
-
"totalEdges":
|
|
112
|
-
"
|
|
113
|
-
"leafNodes": [ "formatDate__utils" ],
|
|
114
|
-
"isolatedNodes": [],
|
|
115
|
-
"criticalNodes": [ "dbClient__db" ]
|
|
232
|
+
"totalNodes": 70,
|
|
233
|
+
"totalEdges": 252,
|
|
234
|
+
"criticalNodes": ["simulateImpact__impact", "buildGraph__graph"]
|
|
116
235
|
},
|
|
117
236
|
"nodes": [
|
|
118
237
|
{
|
|
@@ -125,30 +244,14 @@ The tool generates a JSON report containing the following structure:
|
|
|
125
244
|
"complexity": "low",
|
|
126
245
|
"inDegree": 3,
|
|
127
246
|
"outDegree": 1,
|
|
128
|
-
"centralityScore": 7
|
|
129
|
-
"connections": [ "dbClient__db", "getUserRoute__userController" ]
|
|
247
|
+
"centralityScore": 7
|
|
130
248
|
}
|
|
131
249
|
],
|
|
132
250
|
"edges": [
|
|
133
251
|
{
|
|
134
252
|
"from": "getUserRoute__userController",
|
|
135
253
|
"to": "getUserById__userService",
|
|
136
|
-
"type": "imports"
|
|
137
|
-
"description": "getUserRoute imports getUserById from userService"
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
-
"files": [
|
|
141
|
-
{
|
|
142
|
-
"filePath": "src/services/userService.ts",
|
|
143
|
-
"lang": "js",
|
|
144
|
-
"lines": 42,
|
|
145
|
-
"entities": [
|
|
146
|
-
{ "name": "getUserById", "type": "function", "line": 15, "complexity": "low" }
|
|
147
|
-
],
|
|
148
|
-
"imports": [
|
|
149
|
-
{ "source": "../db", "names": ["dbClient"], "isLocal": true }
|
|
150
|
-
],
|
|
151
|
-
"exports": [ "getUserById" ]
|
|
254
|
+
"type": "imports"
|
|
152
255
|
}
|
|
153
256
|
],
|
|
154
257
|
"impact": {
|
|
@@ -158,26 +261,15 @@ The tool generates a JSON report containing the following structure:
|
|
|
158
261
|
"riskLevel": "HIGH",
|
|
159
262
|
"affectedNodes": [
|
|
160
263
|
{
|
|
161
|
-
"nodeId": "getUserRoute__userController",
|
|
162
264
|
"name": "getUserRoute",
|
|
163
265
|
"file": "src/controllers/userController.ts",
|
|
164
266
|
"depth": 1,
|
|
165
267
|
"impact": "critical",
|
|
166
|
-
"reason": "getUserRoute directly imports getUserById",
|
|
167
|
-
"changeRequired": "Update getUserRoute to handle the new interface of getUserById",
|
|
168
268
|
"breakingChange": true
|
|
169
269
|
}
|
|
170
270
|
],
|
|
171
|
-
"
|
|
172
|
-
"
|
|
173
|
-
"Test getUserById directly after making changes",
|
|
174
|
-
"Regression test getUserRoute β direct dependent"
|
|
175
|
-
],
|
|
176
|
-
"recommendations": [
|
|
177
|
-
"Tech lead review recommended",
|
|
178
|
-
"Feature flag this change",
|
|
179
|
-
"1 breaking change(s) must be updated before deploying"
|
|
180
|
-
]
|
|
271
|
+
"testingPlan": ["Test getUserById directly", "Regression test getUserRoute"],
|
|
272
|
+
"recommendations": ["Tech lead review recommended", "Feature flag this change"]
|
|
181
273
|
}
|
|
182
274
|
}
|
|
183
275
|
```
|
|
@@ -186,41 +278,25 @@ The tool generates a JSON report containing the following structure:
|
|
|
186
278
|
|
|
187
279
|
## π» Development & Contribution
|
|
188
280
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
### Setup & Installation
|
|
192
|
-
Clone the repository and install development dependencies:
|
|
281
|
+
### Setup
|
|
193
282
|
```bash
|
|
283
|
+
git clone https://github.com/arafat2020/depgraph.git
|
|
284
|
+
cd depgraph
|
|
194
285
|
npm install
|
|
195
286
|
```
|
|
196
287
|
|
|
197
288
|
### Commands
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
```
|
|
207
|
-
* **Rebuild Code for Release**:
|
|
208
|
-
Cleans, recompiles, and bundles the source:
|
|
209
|
-
```bash
|
|
210
|
-
npm run release
|
|
211
|
-
```
|
|
212
|
-
* **Run Test Suite**:
|
|
213
|
-
Uses `vitest` for running tests:
|
|
214
|
-
```bash
|
|
215
|
-
# Watch mode
|
|
216
|
-
npm run test
|
|
217
|
-
|
|
218
|
-
# Run tests once (useful for CI)
|
|
219
|
-
npm run test:run
|
|
220
|
-
```
|
|
289
|
+
|
|
290
|
+
| Command | Description |
|
|
291
|
+
| :--- | :--- |
|
|
292
|
+
| `npm run build` | Compile TypeScript β `dist/` |
|
|
293
|
+
| `npm run bundle` | Bundle `dist/main.js` β `depgraph.js` via esbuild |
|
|
294
|
+
| `npm run release` | Build + bundle in one step |
|
|
295
|
+
| `npm run test` | Run tests in watch mode (vitest) |
|
|
296
|
+
| `npm run test:run` | Run tests once (for CI) |
|
|
221
297
|
|
|
222
298
|
---
|
|
223
299
|
|
|
224
300
|
## π License
|
|
225
301
|
|
|
226
|
-
This project is licensed under the MIT License
|
|
302
|
+
This project is licensed under the MIT License β see the [LICENSE](LICENSE) file for details.
|