depgraph-core 1.0.0-beta β†’ 1.0.1-beta

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.
Files changed (2) hide show
  1. package/README.md +226 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # πŸ“Š DepGraph Core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/depgraph-core.svg)](https://www.npmjs.com/package/depgraph-core)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
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.
7
+
8
+ ---
9
+
10
+ ## πŸš€ Key Features
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.
18
+
19
+ ---
20
+
21
+ ## πŸ“¦ Installation
22
+
23
+ ### Global Installation
24
+ Install `depgraph-core` globally via npm to run it anywhere:
25
+
26
+ ```bash
27
+ npm install -g depgraph-core
28
+ ```
29
+
30
+ ### Run with `npx`
31
+ Alternatively, execute it directly without local installation:
32
+
33
+ ```bash
34
+ npx depgraph-core <projectDir> [options]
35
+ ```
36
+
37
+ ---
38
+
39
+ ## πŸ› οΈ CLI Usage
40
+
41
+ ```bash
42
+ depgraph <projectDir> [options]
43
+ ```
44
+
45
+ ### Options
46
+
47
+ | Flag | Parameter | Description | Default |
48
+ | :--- | :--- | :--- | :--- |
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. | β€” |
54
+
55
+ ### Examples
56
+
57
+ #### 1. Generate a dependency report for a project
58
+ ```bash
59
+ depgraph ./src
60
+ ```
61
+
62
+ #### 2. Run with custom output path
63
+ ```bash
64
+ depgraph ./src --output ./reports/graph-report.json
65
+ ```
66
+
67
+ #### 3. Simulate impact of modifying a critical component or helper
68
+ ```bash
69
+ depgraph ./src --impact "getUserById" "adding middleName field to returned object"
70
+ ```
71
+
72
+ #### 4. Run in CI Mode (silencing color output)
73
+ ```bash
74
+ depgraph ./src --no-color --output ./ci/depgraph.json
75
+ ```
76
+
77
+ ---
78
+
79
+ ## πŸ’₯ Impact Simulation Mechanics
80
+
81
+ When you simulate an impact using `--impact <name> <desc>`, the tool performs the following operations:
82
+ 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)
89
+ 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.
94
+
95
+ ---
96
+
97
+ ## πŸ“ Output JSON Schema
98
+
99
+ The tool generates a JSON report containing the following structure:
100
+
101
+ ```json
102
+ {
103
+ "meta": {
104
+ "version": "1.0.0",
105
+ "timestamp": "2026-07-16T02:45:52.311Z",
106
+ "totalFiles": 25,
107
+ "totalLines": 1968
108
+ },
109
+ "summary": {
110
+ "totalNodes": 55,
111
+ "totalEdges": 191,
112
+ "entryPoints": [ "main__app" ],
113
+ "leafNodes": [ "formatDate__utils" ],
114
+ "isolatedNodes": [],
115
+ "criticalNodes": [ "dbClient__db" ]
116
+ },
117
+ "nodes": [
118
+ {
119
+ "id": "getUserById__userService",
120
+ "name": "getUserById",
121
+ "type": "function",
122
+ "file": "src/services/userService.ts",
123
+ "line": 15,
124
+ "lang": "js",
125
+ "complexity": "low",
126
+ "inDegree": 3,
127
+ "outDegree": 1,
128
+ "centralityScore": 7,
129
+ "connections": [ "dbClient__db", "getUserRoute__userController" ]
130
+ }
131
+ ],
132
+ "edges": [
133
+ {
134
+ "from": "getUserRoute__userController",
135
+ "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" ]
152
+ }
153
+ ],
154
+ "impact": {
155
+ "targetNode": "getUserById__userService",
156
+ "changeDescription": "adding middleName",
157
+ "riskScore": 52,
158
+ "riskLevel": "HIGH",
159
+ "affectedNodes": [
160
+ {
161
+ "nodeId": "getUserRoute__userController",
162
+ "name": "getUserRoute",
163
+ "file": "src/controllers/userController.ts",
164
+ "depth": 1,
165
+ "impact": "critical",
166
+ "reason": "getUserRoute directly imports getUserById",
167
+ "changeRequired": "Update getUserRoute to handle the new interface of getUserById",
168
+ "breakingChange": true
169
+ }
170
+ ],
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
+ ]
181
+ }
182
+ }
183
+ ```
184
+
185
+ ---
186
+
187
+ ## πŸ’» Development & Contribution
188
+
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:
193
+ ```bash
194
+ npm install
195
+ ```
196
+
197
+ ### 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
+ ```
221
+
222
+ ---
223
+
224
+ ## πŸ“„ License
225
+
226
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "depgraph-core",
3
- "version": "1.0.0-beta",
3
+ "version": "1.0.1-beta",
4
4
  "description": "Dependency mapping and impact simulation for JS/TS projects",
5
5
  "main": "depgraph.js",
6
6
  "bin": {
@@ -28,4 +28,4 @@
28
28
  "typescript": "^6.0.3",
29
29
  "vitest": "^4.1.10"
30
30
  }
31
- }
31
+ }