@gld5000-cli/dependency-finder 1.0.0 → 1.0.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/README.md
CHANGED
|
@@ -1,66 +1,185 @@
|
|
|
1
1
|
# [@gld5000-cli/dependency-finder](https://www.npmjs.com/package/@gld5000-cli/dependency-finder)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@gld5000-cli/dependency-finder)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
A CLI tool that analyzes your codebase to find component dependencies and identify unused components. Perfect for refactoring, deprecation planning, and keeping your codebase clean.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔍 **Dependency Analysis** - Scans your components and finds all files that import them
|
|
11
|
+
- 📊 **Usage Reports** - Generates detailed JSON reports categorizing components by usage
|
|
12
|
+
- 🎯 **Dead Code Detection** - Identifies components with zero dependents (potential candidates for removal)
|
|
13
|
+
- ⚙️ **Flexible Configuration** - Customize search patterns, target paths, and ignore patterns
|
|
14
|
+
- 🚀 **Zero Config** - Works out of the box with sensible defaults for React/TypeScript projects
|
|
15
|
+
- 📁 **Batch Analysis** - Analyze multiple component directories at once
|
|
16
|
+
|
|
17
|
+
## Use Cases
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
- **Identify Unused Components** - Find components that are never imported or used
|
|
20
|
+
- **Refactoring Priorities** - Determine which components are most heavily used before making breaking changes
|
|
21
|
+
- **Deprecation Planning** - Safely deprecate components by knowing exactly where they're used
|
|
22
|
+
- **Code Cleanup** - Remove dead code with confidence
|
|
23
|
+
- **Codebase Health** - Get insights into component coupling and usage patterns
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
- Node.js 14.x or higher
|
|
28
|
+
|
|
29
|
+
## Run with prompts
|
|
14
30
|
|
|
15
31
|
```
|
|
16
|
-
|
|
32
|
+
npx @gld5000-cli/dependency-finder
|
|
17
33
|
```
|
|
18
34
|
|
|
19
|
-
|
|
35
|
+
## Run with arguments
|
|
20
36
|
|
|
21
37
|
```
|
|
22
|
-
|
|
38
|
+
npx @gld5000-cli/dependency-finder [Component directory] [Dependents paths] [File ignore patterns]
|
|
23
39
|
```
|
|
24
40
|
|
|
25
|
-
###
|
|
41
|
+
### Arguments
|
|
42
|
+
|
|
43
|
+
| Argument | Description | Default | Example |
|
|
44
|
+
| ------------------------ | ------------------------------------------------------------ | ----------------------------------------- | ------------------------------- |
|
|
45
|
+
| **Component directory** | Glob pattern for component files to analyze | `./components/**/*.tsx` | `./src/components/**/*.tsx` |
|
|
46
|
+
| **Dependents paths** | Pipe-separated glob patterns for where to search for imports | `./components/**/*.tsx\|./pages/**/*.tsx` | `./src/**/*.tsx\|./app/**/*.ts` |
|
|
47
|
+
| **File ignore patterns** | Pipe-separated patterns to exclude from analysis | `.test\|.stories` | `.test\|.spec\|.mock` |
|
|
48
|
+
|
|
49
|
+
### Example Usage
|
|
26
50
|
|
|
51
|
+
```bash
|
|
52
|
+
# Analyze all TSX components in a specific structure
|
|
53
|
+
npx @gld5000-cli/dependency-finder "./components/**/*.tsx" "./components/**/*.tsx|./pages/**/*.tsx" ".test|.stories"
|
|
54
|
+
|
|
55
|
+
# Analyze TypeScript files across the entire src directory
|
|
56
|
+
npx @gld5000-cli/dependency-finder "./src/components/**/*.ts" "./src/**/*.ts" ".test|.spec"
|
|
57
|
+
|
|
58
|
+
# Analyze React components including JSX
|
|
59
|
+
npx @gld5000-cli/dependency-finder "./components/**/*.{tsx,jsx}" "./src/**/*.{tsx,jsx}|./pages/**/*.{tsx,jsx}" ".test|.stories|.mock"
|
|
27
60
|
```
|
|
28
|
-
|
|
61
|
+
|
|
62
|
+
## Output
|
|
63
|
+
|
|
64
|
+
The tool generates a `dependents-report.json` file in your project root with the following structure:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"noDependents": {
|
|
69
|
+
"count": 2,
|
|
70
|
+
"results": [
|
|
71
|
+
{
|
|
72
|
+
"matches": [],
|
|
73
|
+
"filePath": "components/Button/index.tsx",
|
|
74
|
+
"dependents": []
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"matches": ["UnusedComponent"],
|
|
78
|
+
"filePath": "components/UnusedComponent.tsx",
|
|
79
|
+
"dependents": []
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
"someDependents": {
|
|
84
|
+
"count": 1,
|
|
85
|
+
"results": [
|
|
86
|
+
{
|
|
87
|
+
"matches": ["Header"],
|
|
88
|
+
"filePath": "components/Header.tsx",
|
|
89
|
+
"dependents": [
|
|
90
|
+
{
|
|
91
|
+
"filePath": "pages/index.tsx",
|
|
92
|
+
"matches": ["import { Header } from '../components/Header'"]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"filePath": "pages/about.tsx",
|
|
96
|
+
"matches": ["import { Header } from '../components/Header'"]
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
29
103
|
```
|
|
30
104
|
|
|
31
|
-
|
|
105
|
+
### Understanding the Output
|
|
32
106
|
|
|
107
|
+
- **noDependents**: Components with zero imports (candidates for removal)
|
|
108
|
+
- `count`: Number of unused components
|
|
109
|
+
- `results`: Array of unused component details
|
|
110
|
+
- **someDependents**: Components that are imported somewhere
|
|
111
|
+
- `count`: Number of used components
|
|
112
|
+
- `results`: Array of components with their import locations
|
|
113
|
+
- **matches**: Export names found in the component file
|
|
114
|
+
- **dependents**: List of files that import this component and the exact import statements
|
|
115
|
+
|
|
116
|
+
## How It Works
|
|
117
|
+
|
|
118
|
+
1. **Discover Components** - Scans your codebase using the component directory pattern to find all component files
|
|
119
|
+
2. **Extract Exports** - Identifies exported components in each file
|
|
120
|
+
3. **Search for Imports** - Searches target paths for import statements referencing each component
|
|
121
|
+
4. **Categorize Results** - Groups components into those with dependents and those without
|
|
122
|
+
5. **Generate Report** - Creates a detailed JSON report with all findings
|
|
123
|
+
|
|
124
|
+
The tool uses glob patterns for flexible file matching and supports filtering to exclude test files, stories, and other non-production code.
|
|
125
|
+
|
|
126
|
+
## Examples
|
|
127
|
+
|
|
128
|
+
### Find Unused Components in a Large Project
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npx @gld5000-cli/dependency-finder "./src/components/**/*.tsx" "./src/**/*.tsx|./app/**/*.tsx" ".test|.stories|.spec"
|
|
33
132
|
```
|
|
34
|
-
npm update @gld5000-cli/dependency-finder
|
|
35
|
-
```
|
|
36
133
|
|
|
37
|
-
|
|
134
|
+
After running, check `dependents-report.json` and review the `noDependents` section for components that can be safely removed.
|
|
135
|
+
|
|
136
|
+
### Audit Before Deprecating a Component Library
|
|
38
137
|
|
|
138
|
+
```bash
|
|
139
|
+
npx @gld5000-cli/dependency-finder "./components/**/*.tsx" "./pages/**/*.tsx|./features/**/*.tsx|./layouts/**/*.tsx" ".test"
|
|
39
140
|
```
|
|
40
|
-
|
|
141
|
+
|
|
142
|
+
Review the `someDependents` section to see exactly where each component is used before deprecating or refactoring.
|
|
143
|
+
|
|
144
|
+
### Quick Check on Component Usage
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Run with defaults for standard React project structure
|
|
148
|
+
npx @gld5000-cli/dependency-finder
|
|
41
149
|
```
|
|
42
150
|
|
|
151
|
+
Follow the prompts to customize paths for your project structure.
|
|
152
|
+
|
|
153
|
+
## Contributing
|
|
154
|
+
|
|
155
|
+
Contributions are welcome! Feel free to:
|
|
156
|
+
|
|
157
|
+
- Report bugs by opening an issue
|
|
158
|
+
- Suggest new features
|
|
159
|
+
- Submit pull requests
|
|
160
|
+
|
|
161
|
+
Please ensure any changes include appropriate tests.
|
|
43
162
|
|
|
44
163
|
## License
|
|
45
164
|
|
|
46
|
-
MIT License
|
|
47
|
-
|
|
48
|
-
Copyright (c) 2026 Gareth L Devlin
|
|
49
|
-
|
|
50
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
51
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
52
|
-
in the Software without restriction, including without limitation the rights
|
|
53
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
54
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
55
|
-
furnished to do so, subject to the following conditions:
|
|
56
|
-
|
|
57
|
-
The above copyright notice and this permission notice shall be included in all
|
|
58
|
-
copies or substantial portions of the Software.
|
|
59
|
-
|
|
60
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
61
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
62
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
63
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
64
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
65
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
165
|
+
MIT License
|
|
166
|
+
|
|
167
|
+
Copyright (c) 2026 Gareth L Devlin
|
|
168
|
+
|
|
169
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
170
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
171
|
+
in the Software without restriction, including without limitation the rights
|
|
172
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
173
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
174
|
+
furnished to do so, subject to the following conditions:
|
|
175
|
+
|
|
176
|
+
The above copyright notice and this permission notice shall be included in all
|
|
177
|
+
copies or substantial portions of the Software.
|
|
178
|
+
|
|
179
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
180
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
181
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
182
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
183
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
184
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
66
185
|
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gld5000-cli/dependency-finder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Finds how many dependents your components have.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"author": "GLD5000",
|
|
24
24
|
"type": "commonjs",
|
|
25
|
+
"bin": "bin/index.mjs",
|
|
25
26
|
"main": "src/index.mjs",
|
|
26
27
|
"scripts": {
|
|
27
28
|
"test": "node test/test.mjs"
|
package/test/test.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { runDependencyFinder } from "../src/index.mjs";
|
|
2
|
-
import { answerStringQuestion } from "@gld5000-cli/readline";
|
|
3
|
-
|
|
4
|
-
const args = process.argv.slice(2);
|
|
5
|
-
const defaultSearchPattern = "./components/**/*.tsx";
|
|
6
|
-
const searchPattern =
|
|
7
|
-
args[0] ||
|
|
8
|
-
(await answerStringQuestion(
|
|
9
|
-
"Where are your components?",
|
|
10
|
-
defaultSearchPattern,
|
|
11
|
-
));
|
|
12
|
-
|
|
13
|
-
const defaultTargetPaths = "./components/**/*.tsx|./pages/**/*.tsx";
|
|
14
|
-
const targetPaths = `${
|
|
15
|
-
args[1] ||
|
|
16
|
-
(await answerStringQuestion(
|
|
17
|
-
"Which folders should we check for imports (pipe-separated)?",
|
|
18
|
-
defaultTargetPaths,
|
|
19
|
-
))
|
|
20
|
-
}`.split("|");
|
|
21
|
-
|
|
22
|
-
const defaultIgnorePatterns = ".test|.stories";
|
|
23
|
-
const ignorePatterns = `${
|
|
24
|
-
args[2] ||
|
|
25
|
-
(await answerStringQuestion(
|
|
26
|
-
"Which filename patterns should be ignored (pipe-separated)?",
|
|
27
|
-
defaultIgnorePatterns,
|
|
28
|
-
))
|
|
29
|
-
}`.split("|");
|
|
30
|
-
// node test/test.mjs "test/test-components/**/*.tsx" "test/test-components/**/*.tsx" ".test|.stories"
|
|
31
|
-
console.log(
|
|
32
|
-
"searchPattern:",
|
|
33
|
-
searchPattern,
|
|
34
|
-
"targetPaths:",
|
|
35
|
-
targetPaths,
|
|
36
|
-
"ignorePatterns:",
|
|
37
|
-
ignorePatterns,
|
|
38
|
-
);
|
|
39
|
-
runDependencyFinder(searchPattern, targetPaths, ignorePatterns);
|