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 CHANGED
@@ -3,33 +3,30 @@
3
3
  [![npm version](https://img.shields.io/npm/v/depgraph-core.svg)](https://www.npmjs.com/package/depgraph-core)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- **DepGraph Core** is a powerful static analysis tool designed to map code dependencies and simulate the ripple effect/impact of changes in JavaScript and TypeScript projects. By parsing imports, exports, functions, classes, and routing definitions, DepGraph constructs a comprehensive dependency graph, computes critical centrality metrics, and generates interactive impact simulations to prevent regression bugs in large codebases.
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
- * πŸ” **Automated Code Parsing**: Parses JavaScript, TypeScript, React components/hooks (`.js`, `.jsx`, `.ts`, `.tsx`, `.mjs`, `.cjs`), extracting functions, classes, interfaces, types, React constructs, and Express API routes.
13
- * πŸ•ΈοΈ **Dependency Graph Reconstruction**: Resolves local imports and links entities across files to construct an internal representation of your codebase topology.
14
- * πŸ“ˆ **Metrics & Centrality Analysis**: Calculates in-degree, out-degree, and centrality scores for every entity to automatically identify **Critical Nodes** (nodes that, if modified, carry high regression risks).
15
- * πŸ’₯ **Impact Simulation Engine**: Runs a reverse Breadth-First Search (BFS) to model the cascading impact of changes to a specific function or component. Generates a risk score, details affected nodes, defines a targeted testing plan, and provides actionable engineering recommendations.
16
- * πŸ–₯️ **Rich CLI Interface**: Colorized and structured console feedback designed for human readability, with a `--no-color` flag optimized for CI/CD pipelines.
17
- * πŸ’Ύ **Detailed JSON Outputs**: Exports a comprehensive report containing metadata, files breakdown, graph structure, and simulation metrics.
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 Installation
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
- ### Run with `npx`
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. | `./depgraph-output.json` |
50
- | `--impact` | `<name> <desc>` | Simulate changing a specific entity. Must supply its name and a reason/description. | `N/A` |
51
- | `--verbose` | β€” | Print per-file parsing and details. | `false` |
52
- | `--no-color` | β€” | Disable terminal ANSI color output (recommended for CI/CD logs). | `false` |
53
- | `--help`, `-h` | β€” | Display help message. | β€” |
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
- ### Examples
65
+ ### Standard Usage
56
66
 
57
- #### 1. Generate a dependency report for a project
67
+ #### Map a project
58
68
  ```bash
59
69
  depgraph ./src
60
70
  ```
61
71
 
62
- #### 2. Run with custom output path
72
+ #### Custom output path
63
73
  ```bash
64
74
  depgraph ./src --output ./reports/graph-report.json
65
75
  ```
66
76
 
67
- #### 3. Simulate impact of modifying a critical component or helper
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
- #### 4. Run in CI Mode (silencing color output)
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 you simulate an impact using `--impact <name> <desc>`, the tool performs the following operations:
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 a depth of 10 nodes to discover all direct and indirect dependents.
84
- 3. **Risk Scoring**: Calculates a score from `0` to `100` based on:
85
- * Number of critical-impact nodes (depth 1)
86
- * Number of high-impact nodes (depth 2)
87
- * Number of medium/low-impact nodes
88
- * The target node's in-degree (how many other entities import it)
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
- * πŸ”΄ **CRITICAL** (Score $\ge$ 75): Requires comprehensive review, phased rollouts, and global regression testing.
91
- * 🟑 **HIGH** (Score 50–74): Tech lead review recommended, feature flag encouraged.
92
- * πŸ”΅ **MEDIUM** (Score 25–49): Standard peer code review, targeted module testing.
93
- * 🟒 **LOW** (Score < 25): Standard PR process is sufficient.
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.0",
105
- "timestamp": "2026-07-16T02:45:52.311Z",
106
- "totalFiles": 25,
107
- "totalLines": 1968
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": 55,
111
- "totalEdges": 191,
112
- "entryPoints": [ "main__app" ],
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
- "breakingChanges": [...],
172
- "testingPlan": [
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
- If you are developing or contributing to `depgraph-core`, follow these steps:
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
- * **Compile TypeScript**:
199
- ```bash
200
- npm run build
201
- ```
202
- * **Create Production Bundle**:
203
- Bundles the application into a standalone executable file `depgraph.js` via `esbuild`:
204
- ```bash
205
- npm run bundle
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 - see the [LICENSE](LICENSE) file for details.
302
+ This project is licensed under the MIT License β€” see the [LICENSE](LICENSE) file for details.