prunify 0.1.1 โ 0.1.4
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 +166 -99
- package/dist/cli.cjs +485 -158
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +485 -158
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,29 +1,50 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# ๐งน prunify
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**npm run clean. ship with confidence.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/prunify)
|
|
8
|
+
[](https://www.npmjs.com/package/prunify)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](https://www.typescriptlang.org)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
**prunify** is a zero-config CLI that audits TypeScript and JavaScript codebases for dead code, duplicate logic, circular imports, unused dependencies, and unused public assets โ then gives you a single health score so you know exactly where to clean up.
|
|
4
18
|
|
|
5
|
-
[
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
> **Add a demo GIF here** โ record your terminal with [Terminalizer](https://github.com/faressoft/terminalizer) or [asciinema](https://asciinema.org) and drop the `.gif` in `.github/assets/demo.gif`
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+

|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
8
26
|
|
|
9
|
-
|
|
27
|
+
## What it detects
|
|
10
28
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
| Module | What it finds |
|
|
30
|
+
|--------|---------------|
|
|
31
|
+
| ๐๏ธ **Dead code** | Files and named exports that are never imported anywhere in the codebase |
|
|
32
|
+
| ๐ **Duplicate code** | Functions with identical bodies, suspiciously similar names, and duplicate constants |
|
|
33
|
+
| โป๏ธ **Circular imports** | Dependency cycles that can cause runtime bugs and bundler issues |
|
|
34
|
+
| ๐ฆ **Unused dependencies** | Packages declared in `package.json` that are never actually imported |
|
|
35
|
+
| ๐ผ๏ธ **Unused assets** | Images, fonts, videos and other files in `public/` that are never referenced in source |
|
|
36
|
+
| ๐ **Health score** | A 0โ100 score summarising all findings, with optional HTML gauge output |
|
|
16
37
|
|
|
17
38
|
---
|
|
18
39
|
|
|
19
40
|
## Installation
|
|
20
41
|
|
|
21
42
|
```bash
|
|
22
|
-
#
|
|
23
|
-
npm install -g prunify
|
|
24
|
-
|
|
25
|
-
# Or run directly without installing
|
|
43
|
+
# Run directly (no install needed)
|
|
26
44
|
npx prunify
|
|
45
|
+
|
|
46
|
+
# Or install globally
|
|
47
|
+
npm install -g prunify
|
|
27
48
|
```
|
|
28
49
|
|
|
29
50
|
---
|
|
@@ -37,99 +58,116 @@ npx prunify
|
|
|
37
58
|
# Analyse a specific project
|
|
38
59
|
npx prunify --dir ./my-app
|
|
39
60
|
|
|
40
|
-
#
|
|
61
|
+
# Run only specific checks
|
|
41
62
|
npx prunify --only dead-code,circular
|
|
42
63
|
|
|
43
|
-
#
|
|
64
|
+
# Override the entry point
|
|
65
|
+
npx prunify --entry src/main.tsx
|
|
66
|
+
|
|
67
|
+
# Generate an HTML report with health gauge
|
|
68
|
+
npx prunify --html
|
|
69
|
+
|
|
70
|
+
# CI mode โ exits with code 1 if any issues found
|
|
44
71
|
npx prunify --ci
|
|
45
72
|
```
|
|
46
73
|
|
|
47
74
|
---
|
|
48
75
|
|
|
76
|
+
## Sample Output
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
๐งน prunify โ npm run clean. ship with confidence.
|
|
80
|
+
|
|
81
|
+
โ Parsed codebase โ 142 file(s) found
|
|
82
|
+
โ Import graph built โ 389 edge(s)
|
|
83
|
+
|
|
84
|
+
โ Dead code analysis complete โ 7 item(s) found
|
|
85
|
+
โ Duplicate scan complete โ 3 duplicate block(s) found
|
|
86
|
+
โ Circular import analysis complete โ 2 cycle(s) found
|
|
87
|
+
โ Dependency audit complete โ 4 issue(s) found
|
|
88
|
+
โ Asset scan complete โ 5 unused / 23 total
|
|
89
|
+
|
|
90
|
+
Summary
|
|
91
|
+
|
|
92
|
+
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
|
|
93
|
+
โ Check โ Found โ Output File โ
|
|
94
|
+
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโโโโโโโค
|
|
95
|
+
โ Dead Files / Exports โ 7 โ dead-code.txt โ
|
|
96
|
+
โ Duplicate Clusters โ 3 โ dupes.md โ
|
|
97
|
+
โ Unused Packages โ 4 โ deps.md โ
|
|
98
|
+
โ Circular Deps โ 2 โ circular.txt โ
|
|
99
|
+
โ Unused Assets โ 5 โ assets.md โ
|
|
100
|
+
โโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโดโโโโโโโโโโโโโโโโโโโ
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
49
105
|
## CLI Flags
|
|
50
106
|
|
|
51
|
-
| Flag |
|
|
52
|
-
|
|
53
|
-
| `--dir <path>` | `
|
|
54
|
-
| `--entry <path>` |
|
|
55
|
-
| `--only <modules>` |
|
|
56
|
-
| `--ignore <pattern>` |
|
|
57
|
-
| `--out <path>` |
|
|
58
|
-
| `--html` | `
|
|
59
|
-
| `--delete` | `
|
|
60
|
-
| `--ci` | `
|
|
61
|
-
| `-v, --version` | โ |
|
|
107
|
+
| Flag | Default | Description |
|
|
108
|
+
|------|---------|-------------|
|
|
109
|
+
| `--dir <path>` | `cwd` | Root directory to analyse. Must contain a `package.json`. |
|
|
110
|
+
| `--entry <path>` | auto-detected | Override the entry point (e.g. `src/main.tsx`). prunify auto-detects `pages/`, `app/`, `src/index`, `src/main`, `src/App`, and common root entries. |
|
|
111
|
+
| `--only <modules>` | all | Comma-separated modules to run: `dead-code`, `dupes`, `circular`, `deps`, `assets`, `health`. |
|
|
112
|
+
| `--ignore <pattern>` | โ | Glob pattern to exclude from analysis. Repeatable. |
|
|
113
|
+
| `--out <path>` | `<dir>/prunify-reports/` | Directory to write report files to. |
|
|
114
|
+
| `--html` | `false` | Generate `code_health.html` โ a self-contained page with an SVG score gauge. |
|
|
115
|
+
| `--delete` | `false` | After analysis, prompt to permanently delete dead files. |
|
|
116
|
+
| `--ci` | `false` | Non-interactive mode. Exits `1` if any issues are found. |
|
|
117
|
+
| `-v, --version` | โ | Print the installed version. |
|
|
62
118
|
|
|
63
|
-
###
|
|
119
|
+
### More examples
|
|
64
120
|
|
|
65
121
|
```bash
|
|
66
122
|
# Ignore test fixtures and generated files
|
|
67
123
|
npx prunify --ignore "tests/fixtures/**" --ignore "src/generated/**"
|
|
68
124
|
|
|
69
125
|
# Write reports to a custom folder
|
|
70
|
-
npx prunify --out reports
|
|
126
|
+
npx prunify --out ./reports
|
|
71
127
|
|
|
72
|
-
# Full health report
|
|
128
|
+
# Full health report as HTML
|
|
73
129
|
npx prunify --only health --html
|
|
74
130
|
|
|
75
|
-
#
|
|
76
|
-
npx prunify --
|
|
131
|
+
# Only check unused public assets
|
|
132
|
+
npx prunify --only assets
|
|
77
133
|
|
|
78
|
-
# Delete dead files after
|
|
134
|
+
# Delete dead files after reviewing
|
|
79
135
|
npx prunify --delete
|
|
80
136
|
|
|
81
|
-
# Strict CI gate โ fails the build if issues exist
|
|
137
|
+
# Strict CI gate โ fails the build if any issues exist
|
|
82
138
|
npx prunify --ci
|
|
83
139
|
```
|
|
84
140
|
|
|
85
141
|
---
|
|
86
142
|
|
|
87
|
-
##
|
|
143
|
+
## Report Files
|
|
88
144
|
|
|
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/`
|
|
145
|
+
All reports are written to `prunify-reports/` (auto-added to `.gitignore`).
|
|
113
146
|
|
|
114
147
|
| File | Contents |
|
|
115
148
|
|------|----------|
|
|
116
|
-
| `dead-code.txt` | Dead files with chain analysis and recoverable byte count |
|
|
117
|
-
| `dupes.md` | Duplicate function clusters with AI refactor prompts |
|
|
149
|
+
| `dead-code.txt` | Dead files and exports with chain analysis and recoverable byte count |
|
|
150
|
+
| `dupes.md` | Duplicate function clusters with AI-ready refactor prompts |
|
|
118
151
|
| `circular.txt` | Circular dependency chains |
|
|
119
|
-
| `deps.md` | Unused
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
152
|
+
| `deps.md` | Unused packages |
|
|
153
|
+
| `assets.md` | Unused files found in `public/` with sizes |
|
|
154
|
+
| `health-report.md` | Combined report with health score (with `--only health`) |
|
|
155
|
+
| `code_health.html` | Self-contained HTML page with SVG score gauge (with `--html`) |
|
|
122
156
|
|
|
123
157
|
---
|
|
124
158
|
|
|
125
|
-
##
|
|
159
|
+
## How Dead Code Detection Works
|
|
126
160
|
|
|
127
|
-
prunify
|
|
161
|
+
prunify builds a directed import graph of your entire codebase, then runs a depth-first traversal starting from your entry points.
|
|
128
162
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
163
|
+
**Entry point auto-detection order:**
|
|
164
|
+
|
|
165
|
+
1. Next.js โ all files inside `pages/` and `app/` directories
|
|
166
|
+
2. `package.json` `"main"` and `"module"` fields
|
|
167
|
+
3. Common fallbacks โ `src/main`, `src/index`, `src/App`, `index` (all TS/JS extensions)
|
|
168
|
+
4. If none found โ files with no importers are used as roots (safest heuristic)
|
|
169
|
+
|
|
170
|
+
Any file not reachable from an entry point is flagged as dead. Circular dependencies are handled correctly โ files in a cycle that are reachable from an entry point are always marked live.
|
|
133
171
|
|
|
134
172
|
---
|
|
135
173
|
|
|
@@ -146,53 +184,82 @@ Starting from **100**, points are deducted per finding:
|
|
|
146
184
|
| Barrel file (โฅ 15 exports) | โ1 | โ10 |
|
|
147
185
|
| Long file (> 300 lines) | โ1 | โ10 |
|
|
148
186
|
|
|
149
|
-
|
|
187
|
+
| Score | Grade |
|
|
188
|
+
|-------|-------|
|
|
189
|
+
| โฅ 80 | ๐ข Good |
|
|
190
|
+
| 50โ79 | ๐ก Fair |
|
|
191
|
+
| < 50 | ๐ด Poor |
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## How Asset Detection Works
|
|
196
|
+
|
|
197
|
+
prunify scans your `public/` folder for image, font, video, and document files (`.png`, `.jpg`, `.svg`, `.webp`, `.woff2`, `.ttf`, `.mp4`, `.pdf`, and more).
|
|
198
|
+
|
|
199
|
+
For each asset it checks whether the filename or its public-root-relative path (e.g. `/icons/logo.svg`) appears anywhere in your source files โ including TS, JS, CSS, SCSS, HTML, and JSON. Assets not referenced anywhere are flagged as unused.
|
|
200
|
+
|
|
201
|
+
> **Note:** Assets served via a CDN or referenced only at runtime (e.g. dynamically constructed URLs) may appear as unused. Review the report before deleting.
|
|
150
202
|
|
|
151
203
|
---
|
|
152
204
|
|
|
153
205
|
## Requirements
|
|
154
206
|
|
|
155
|
-
- Node.js
|
|
156
|
-
- Works with TypeScript
|
|
157
|
-
- Reads `tsconfig.json` automatically for path-alias resolution
|
|
207
|
+
- **Node.js โฅ 18**
|
|
208
|
+
- Works with **TypeScript and JavaScript** projects
|
|
209
|
+
- Reads `tsconfig.json` automatically for path-alias resolution (`@/`, `~`, etc.)
|
|
210
|
+
- No config file needed
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Project Structure
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
src/
|
|
218
|
+
โโโ cli.ts # Entry point & CLI flag handling
|
|
219
|
+
โโโ core/
|
|
220
|
+
โ โโโ parser.ts # File discovery + ts-morph AST parsing
|
|
221
|
+
โ โโโ graph.ts # Import graph builder, DFS traversal, cycle detection
|
|
222
|
+
โ โโโ reporter.ts # Markdown / JSON / HTML output writer
|
|
223
|
+
โโโ modules/
|
|
224
|
+
โ โโโ dead-code.ts # Dead file + dead export detection
|
|
225
|
+
โ โโโ dupe-finder.ts # Duplicate function + constant detection
|
|
226
|
+
โ โโโ circular.ts # Circular import detection
|
|
227
|
+
โ โโโ dep-check.ts # package.json dependency audit
|
|
228
|
+
โ โโโ assets.ts # Unused public asset detection
|
|
229
|
+
โ โโโ health-report.ts # Health score + combined report
|
|
230
|
+
โโโ prompt-gen/
|
|
231
|
+
โ โโโ templates.ts # AI prompt generators for refactor suggestions
|
|
232
|
+
โโโ utils/
|
|
233
|
+
โโโ file.ts # Glob helpers
|
|
234
|
+
โโโ ast.ts # ts-morph AST helpers
|
|
235
|
+
```
|
|
158
236
|
|
|
159
237
|
---
|
|
160
238
|
|
|
161
239
|
## Contributing
|
|
162
240
|
|
|
241
|
+
Contributions are welcome! Here's how to get started:
|
|
242
|
+
|
|
163
243
|
```bash
|
|
164
|
-
git clone https://github.com/
|
|
244
|
+
git clone https://github.com/DhananjaySarathe/prunify.git
|
|
165
245
|
cd prunify
|
|
166
246
|
npm install
|
|
167
|
-
|
|
168
|
-
npm run
|
|
247
|
+
|
|
248
|
+
npm test # run the test suite
|
|
249
|
+
npm run build # compile to dist/
|
|
250
|
+
npm run dev # watch mode
|
|
169
251
|
```
|
|
170
252
|
|
|
171
|
-
|
|
253
|
+
### Adding a new module
|
|
172
254
|
|
|
173
|
-
|
|
255
|
+
1. Create `src/modules/your-module.ts` โ export a `run*Module(...)` (sync) and `run*(...)` (async CLI) function
|
|
256
|
+
2. Wire it into `src/cli.ts` โ add to the `Module` type, `ALL_MODULES`, and the run block
|
|
257
|
+
3. Add tests in `tests/modules/your-module.test.ts`
|
|
174
258
|
|
|
175
|
-
|
|
259
|
+
Please open an issue first for large changes so we can discuss the approach.
|
|
176
260
|
|
|
177
|
-
|
|
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
|
-
```
|
|
261
|
+
---
|
|
195
262
|
|
|
196
263
|
## License
|
|
197
264
|
|
|
198
|
-
MIT
|
|
265
|
+
MIT ยฉ [Dhananjay Sarathe](https://github.com/DhananjaySarathe)
|