prunify 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/README.md +198 -0
- package/dist/cli.cjs +1195 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1174 -0
- package/dist/cli.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# ๐งน prunify
|
|
2
|
+
|
|
3
|
+
> npm run clean. ship with confidence.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/prunify)
|
|
6
|
+
[](https://www.npmjs.com/package/prunify)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
**prunify** is a zero-config CLI that audits your TypeScript or JavaScript codebase for:
|
|
10
|
+
|
|
11
|
+
- ๐๏ธ **Dead files and exports** โ files and named exports that are never imported anywhere
|
|
12
|
+
- ๐ **Duplicate code** โ functions with identical bodies or suspiciously similar names, duplicate constants
|
|
13
|
+
- โป๏ธ **Circular imports** โ dependency cycles that can cause runtime bugs and build issues
|
|
14
|
+
- ๐ฆ **Unused dependencies** โ packages declared in `package.json` that are never imported
|
|
15
|
+
- ๐ **Health score** โ a 0โ100 score summarising all findings, with optional HTML gauge output
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Global install
|
|
23
|
+
npm install -g prunify
|
|
24
|
+
|
|
25
|
+
# Or run directly without installing
|
|
26
|
+
npx prunify
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Analyse the current directory
|
|
35
|
+
npx prunify
|
|
36
|
+
|
|
37
|
+
# Analyse a specific project
|
|
38
|
+
npx prunify --dir ./my-app
|
|
39
|
+
|
|
40
|
+
# Only check dead code and circular imports
|
|
41
|
+
npx prunify --only dead-code,circular
|
|
42
|
+
|
|
43
|
+
# CI mode โ exits 1 if any issues found
|
|
44
|
+
npx prunify --ci
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## CLI Flags
|
|
50
|
+
|
|
51
|
+
| Flag | Type | Default | Description |
|
|
52
|
+
|------|------|---------|-------------|
|
|
53
|
+
| `--dir <path>` | `string` | `cwd` | Root directory to analyse. Must contain a `package.json`. |
|
|
54
|
+
| `--entry <path>` | `string` | auto-detected | Override the entry point file (e.g. `src/main.ts`). prunify auto-detects `pages/`, `app/`, `src/index.ts`, or reads `package.json` `"main"`. |
|
|
55
|
+
| `--only <modules>` | `string` | all | Comma-separated list of modules to run: `dead-code`, `dupes`, `circular`, `deps`, `health`. |
|
|
56
|
+
| `--ignore <pattern>` | `string` | โ | Glob pattern to exclude from analysis. Repeatable. |
|
|
57
|
+
| `--out <path>` | `string` | `<dir>/prunify-reports/` | Directory to write report files to. |
|
|
58
|
+
| `--html` | `boolean` | `false` | Also generate `code_health.html` โ a self-contained file with a colour-coded score gauge. |
|
|
59
|
+
| `--delete` | `boolean` | `false` | After analysis, prompt to permanently delete dead files. |
|
|
60
|
+
| `--ci` | `boolean` | `false` | Non-interactive CI mode. Exits with code `1` if any issues are found. |
|
|
61
|
+
| `-v, --version` | โ | โ | Print the installed version. |
|
|
62
|
+
|
|
63
|
+
### Examples
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Ignore test fixtures and generated files
|
|
67
|
+
npx prunify --ignore "tests/fixtures/**" --ignore "src/generated/**"
|
|
68
|
+
|
|
69
|
+
# Write reports to a custom folder
|
|
70
|
+
npx prunify --out reports/
|
|
71
|
+
|
|
72
|
+
# Full health report with HTML gauge
|
|
73
|
+
npx prunify --only health --html
|
|
74
|
+
|
|
75
|
+
# Specify entry point explicitly
|
|
76
|
+
npx prunify --dir ./packages/core --entry src/index.ts
|
|
77
|
+
|
|
78
|
+
# Delete dead files after confirming in prompt
|
|
79
|
+
npx prunify --delete
|
|
80
|
+
|
|
81
|
+
# Strict CI gate โ fails the build if issues exist
|
|
82
|
+
npx prunify --ci
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Sample Output
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
๐งน prunify โ npm run clean. ship with confidence.
|
|
91
|
+
|
|
92
|
+
โ Parsed codebase โ 142 file(s) found
|
|
93
|
+
โ Import graph built โ 389 edge(s)
|
|
94
|
+
|
|
95
|
+
โ Dead code analysis complete โ 7 item(s) found
|
|
96
|
+
โ Duplicate scan complete โ 3 duplicate block(s) found
|
|
97
|
+
โ Circular import analysis complete โ 2 cycle(s) found
|
|
98
|
+
โ Dependency audit complete โ 4 issue(s) found
|
|
99
|
+
|
|
100
|
+
Summary
|
|
101
|
+
|
|
102
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ
|
|
103
|
+
โ Check โ Found โ Output File โ
|
|
104
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโค
|
|
105
|
+
โ Dead Files / Exports โ 7 โ dead-code.txt โ
|
|
106
|
+
โ Duplicate Clusters โ 3 โ dupes.md โ
|
|
107
|
+
โ Unused Packages โ 4 โ deps.md โ
|
|
108
|
+
โ Circular Deps โ 2 โ circular.txt โ
|
|
109
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโ
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Report files in `prunify-reports/`
|
|
113
|
+
|
|
114
|
+
| File | Contents |
|
|
115
|
+
|------|----------|
|
|
116
|
+
| `dead-code.txt` | Dead files with chain analysis and recoverable byte count |
|
|
117
|
+
| `dupes.md` | Duplicate function clusters with AI refactor prompts |
|
|
118
|
+
| `circular.txt` | Circular dependency chains |
|
|
119
|
+
| `deps.md` | Unused / missing packages |
|
|
120
|
+
| `code_health.txt` | Combined health score + all findings (with `--only health`) |
|
|
121
|
+
| `code_health.html` | Self-contained HTML with SVG gauge (with `--html`) |
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Add to `.gitignore`
|
|
126
|
+
|
|
127
|
+
prunify automatically appends `prunify-reports/` to your `.gitignore`. If you prefer to commit reports, remove the entry.
|
|
128
|
+
|
|
129
|
+
```gitignore
|
|
130
|
+
# added by prunify
|
|
131
|
+
prunify-reports/
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## How the Health Score Works
|
|
137
|
+
|
|
138
|
+
Starting from **100**, points are deducted per finding:
|
|
139
|
+
|
|
140
|
+
| Finding | Deduction | Cap |
|
|
141
|
+
|---------|-----------|-----|
|
|
142
|
+
| Dead file | โ2 | โ20 |
|
|
143
|
+
| Duplicate function cluster | โ3 | โ15 |
|
|
144
|
+
| Circular dependency | โ5 | โ20 |
|
|
145
|
+
| Unused package | โ2 | โ10 |
|
|
146
|
+
| Barrel file (โฅ 15 exports) | โ1 | โ10 |
|
|
147
|
+
| Long file (> 300 lines) | โ1 | โ10 |
|
|
148
|
+
|
|
149
|
+
A score of **โฅ 80** is green, **50โ79** is amber, **< 50** is red.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Requirements
|
|
154
|
+
|
|
155
|
+
- Node.js **โฅ 18**
|
|
156
|
+
- Works with TypeScript **and** JavaScript projects
|
|
157
|
+
- Reads `tsconfig.json` automatically for path-alias resolution
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Contributing
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
git clone https://github.com/YOUR_USERNAME/prunify.git
|
|
165
|
+
cd prunify
|
|
166
|
+
npm install
|
|
167
|
+
npm test # run the test suite
|
|
168
|
+
npm run build # compile to dist/
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Issues and PRs are welcome at [github.com/YOUR_USERNAME/prunify](https://github.com/YOUR_USERNAME/prunify/issues).
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
|
178
|
+
โโโ cli.ts # Entry point
|
|
179
|
+
โโโ core/
|
|
180
|
+
โ โโโ parser.ts # File discovery + ts-morph AST parsing
|
|
181
|
+
โ โโโ graph.ts # Import graph builder + DFS/SCC traversal
|
|
182
|
+
โ โโโ reporter.ts # Markdown/JSON output writer
|
|
183
|
+
โโโ modules/
|
|
184
|
+
โ โโโ dead-code.ts
|
|
185
|
+
โ โโโ dupe-finder.ts
|
|
186
|
+
โ โโโ circular.ts
|
|
187
|
+
โ โโโ dep-check.ts
|
|
188
|
+
โ โโโ health-report.ts
|
|
189
|
+
โโโ prompt-gen/
|
|
190
|
+
โ โโโ templates.ts # LLM prompt generators
|
|
191
|
+
โโโ utils/
|
|
192
|
+
โโโ file.ts # Glob + file helpers
|
|
193
|
+
โโโ ast.ts # ts-morph AST helpers
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT
|