ng-di-graph 0.1.0
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/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/cli/index.cjs +1907 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/core/error-handler.d.ts +89 -0
- package/dist/core/graph-builder.d.ts +13 -0
- package/dist/core/graph-filter.d.ts +12 -0
- package/dist/core/logger.d.ts +95 -0
- package/dist/core/output-handler.d.ts +12 -0
- package/dist/core/parser.d.ts +252 -0
- package/dist/formatters/json-formatter.d.ts +24 -0
- package/dist/formatters/mermaid-formatter.d.ts +31 -0
- package/dist/tests/helpers/test-utils.d.ts +107 -0
- package/dist/types/index.d.ts +102 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yoshiro Matsumoto
|
|
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
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# ng-di-graph
|
|
2
|
+
|
|
3
|
+
[](https://github.com/m-yoshiro/ng-di-graph/actions/workflows/ci.yml)
|
|
4
|
+
[](package.json)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A command-line tool that analyzes Angular TypeScript codebases to extract dependency injection relationships.
|
|
8
|
+
|
|
9
|
+
**Target Angular Versions:** 17-20
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Node.js 20.x LTS (see `.node-version`; e.g., `mise use node@$(cat .node-version)`)
|
|
14
|
+
- npm 10+ (ships with Node 20). Use your preferred version manager (mise recommended) to match the pinned runtime before installing dependencies.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
✨ **Complete Feature Set** - Production-ready dependency graph analysis for Angular applications
|
|
19
|
+
|
|
20
|
+
- 🔍 **Dependency Analysis** - Extract DI relationships from `@Injectable`, `@Component`, and `@Directive` classes
|
|
21
|
+
- 🎯 **Constructor Injection** - Analyze constructor parameters with type annotations and `@Inject()` tokens
|
|
22
|
+
- 🏷️ **Decorator Flags** - Capture `@Optional`, `@Self`, `@SkipSelf`, and `@Host` parameter decorators
|
|
23
|
+
- 📊 **Multiple Output Formats** - JSON (machine-readable) and Mermaid (visual flowcharts)
|
|
24
|
+
- 🎨 **Entry Point Filtering** - Generate sub-graphs from specific starting nodes
|
|
25
|
+
- 🔄 **Bidirectional Analysis** - Explore upstream dependencies, downstream consumers, or both
|
|
26
|
+
- 🔁 **Circular Detection** - Automatically detect and report circular dependencies
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install -g ng-di-graph
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Analyze an Angular project and output JSON
|
|
38
|
+
ng-di-graph --project ./my-angular-app/tsconfig.json --format json
|
|
39
|
+
|
|
40
|
+
# Generate a Mermaid flowchart
|
|
41
|
+
ng-di-graph --project ./tsconfig.json --format mermaid --out graph.mmd
|
|
42
|
+
|
|
43
|
+
# Analyze dependencies of a specific component
|
|
44
|
+
ng-di-graph --project ./tsconfig.json --entry AppComponent --format mermaid
|
|
45
|
+
|
|
46
|
+
# Show verbose logging with detailed type resolution
|
|
47
|
+
ng-di-graph --project ./tsconfig.json --verbose
|
|
48
|
+
|
|
49
|
+
# Include parameter decorator flags
|
|
50
|
+
ng-di-graph --project ./tsconfig.json --include-decorators
|
|
51
|
+
|
|
52
|
+
# Analyze upstream dependencies (who depends on this?)
|
|
53
|
+
ng-di-graph --project ./tsconfig.json --entry UserService --direction upstream
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## CLI Reference
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
ng-di-graph [options]
|
|
60
|
+
|
|
61
|
+
Options:
|
|
62
|
+
-p, --project <path> Path to tsconfig.json (default: ./tsconfig.json)
|
|
63
|
+
-f, --format <format> Output format: json | mermaid (default: json)
|
|
64
|
+
-e, --entry <symbol...> Starting nodes for sub-graph filtering
|
|
65
|
+
-d, --direction <dir> Filter direction: upstream | downstream | both (default: downstream)
|
|
66
|
+
--include-decorators Include @Optional, @Self, @SkipSelf, @Host flags in output
|
|
67
|
+
--out <file> Output file path (prints to stdout if omitted)
|
|
68
|
+
-v, --verbose Show detailed parsing and resolution information
|
|
69
|
+
-h, --help Display help information
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Option Details
|
|
73
|
+
|
|
74
|
+
- **`--project`**: Specifies the TypeScript configuration file to use for project analysis
|
|
75
|
+
- **`--format`**: Choose between JSON (structured data) or Mermaid (visual diagram)
|
|
76
|
+
- **`--entry`**: Filter the graph to show only dependencies related to specified symbols (supports multiple entries)
|
|
77
|
+
- **`--direction`**:
|
|
78
|
+
- `downstream` (default): Show what the entry depends on
|
|
79
|
+
- `upstream`: Show what depends on the entry
|
|
80
|
+
- `both`: Show both upstream and downstream dependencies
|
|
81
|
+
- **`--include-decorators`**: Add parameter decorator information to edge flags
|
|
82
|
+
- **`--out`**: Save output to a file instead of stdout
|
|
83
|
+
- **`--verbose`**: Enable detailed logging including timing metrics, memory usage, and type resolution details
|
|
84
|
+
|
|
85
|
+
## Output Formats
|
|
86
|
+
|
|
87
|
+
### JSON Format
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"nodes": [
|
|
92
|
+
{ "id": "AppComponent", "kind": "component" },
|
|
93
|
+
{ "id": "UserService", "kind": "service" },
|
|
94
|
+
{ "id": "AuthService", "kind": "service" }
|
|
95
|
+
],
|
|
96
|
+
"edges": [
|
|
97
|
+
{
|
|
98
|
+
"from": "AppComponent",
|
|
99
|
+
"to": "UserService",
|
|
100
|
+
"flags": { "optional": false }
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"from": "UserService",
|
|
104
|
+
"to": "AuthService",
|
|
105
|
+
"flags": { "optional": true, "self": false }
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"circularDependencies": []
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Node Kinds:**
|
|
113
|
+
- `service` - Classes decorated with `@Injectable()`
|
|
114
|
+
- `component` - Classes decorated with `@Component()`
|
|
115
|
+
- `directive` - Classes decorated with `@Directive()`
|
|
116
|
+
- `unknown` - Could not determine decorator type
|
|
117
|
+
|
|
118
|
+
**Edge Flags** (when `--include-decorators` is used):
|
|
119
|
+
- `optional` - Parameter has `@Optional()` decorator
|
|
120
|
+
- `self` - Parameter has `@Self()` decorator
|
|
121
|
+
- `skipSelf` - Parameter has `@SkipSelf()` decorator
|
|
122
|
+
- `host` - Parameter has `@Host()` decorator
|
|
123
|
+
|
|
124
|
+
### Mermaid Format
|
|
125
|
+
|
|
126
|
+
```mermaid
|
|
127
|
+
flowchart LR
|
|
128
|
+
AppComponent --> UserService
|
|
129
|
+
UserService --> AuthService
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Mermaid diagrams can be:
|
|
133
|
+
- Rendered in GitHub/GitLab markdown
|
|
134
|
+
- Viewed in the [Mermaid Live Editor](https://mermaid.live/)
|
|
135
|
+
- Embedded in documentation sites
|
|
136
|
+
- Converted to images using CLI tools
|
|
137
|
+
|
|
138
|
+
## Use Cases
|
|
139
|
+
|
|
140
|
+
### 1. Test Planning
|
|
141
|
+
Quickly identify all dependencies of a component to plan test mocks:
|
|
142
|
+
```bash
|
|
143
|
+
ng-di-graph --project ./tsconfig.json --entry MyComponent --format json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 2. Impact Analysis
|
|
147
|
+
Find all consumers of a service before making breaking changes:
|
|
148
|
+
```bash
|
|
149
|
+
ng-di-graph --project ./tsconfig.json --entry UserService --direction upstream
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 3. Documentation
|
|
153
|
+
Generate visual dependency diagrams for README or design docs:
|
|
154
|
+
```bash
|
|
155
|
+
ng-di-graph --project ./tsconfig.json --format mermaid --out docs/architecture.mmd
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 4. Circular Dependency Detection
|
|
159
|
+
Identify circular dependencies in your DI graph:
|
|
160
|
+
```bash
|
|
161
|
+
ng-di-graph --project ./tsconfig.json --verbose
|
|
162
|
+
# Check the "circularDependencies" array in output
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 5. Debugging Type Issues
|
|
166
|
+
Investigate type resolution problems with verbose logging:
|
|
167
|
+
```bash
|
|
168
|
+
ng-di-graph --project ./tsconfig.json --verbose
|
|
169
|
+
# Shows detailed type resolution and warnings
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Error Handling
|
|
173
|
+
|
|
174
|
+
The tool provides graceful error handling:
|
|
175
|
+
|
|
176
|
+
- **File Parsing Failures** - Skips unparseable files and continues processing
|
|
177
|
+
- **Type Resolution Issues** - Logs warnings for `any`/`unknown` types
|
|
178
|
+
- **Missing tsconfig.json** - Clear error message with suggestion
|
|
179
|
+
- **Invalid CLI Arguments** - Help message with usage examples
|
|
180
|
+
- **Circular Dependencies** - Detected and reported without blocking analysis
|
|
181
|
+
- **Memory Constraints** - Suggestions for chunking large codebases
|
|
182
|
+
|
|
183
|
+
Exit codes:
|
|
184
|
+
- `0` - Success
|
|
185
|
+
- `1` - Fatal error (invalid config, parsing failure, etc.)
|
|
186
|
+
|
|
187
|
+
## Contributing
|
|
188
|
+
|
|
189
|
+
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for development setup, code quality standards, and the pull request process.
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT License - See [LICENSE](LICENSE) file for details
|
|
194
|
+
|
|
195
|
+
## Version
|
|
196
|
+
|
|
197
|
+
Current version: **0.1.0**
|
|
198
|
+
|
|
199
|
+
All core features are complete and production-ready.
|