prunify 0.1.1 โ†’ 0.1.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,29 +1,50 @@
1
+ <div align="center">
2
+
1
3
  # ๐Ÿงน prunify
2
4
 
3
- > npm run clean. ship with confidence.
5
+ **npm run clean. ship with confidence.**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/prunify.svg?style=flat-square)](https://www.npmjs.com/package/prunify)
8
+ [![npm downloads](https://img.shields.io/npm/dw/prunify.svg?style=flat-square)](https://www.npmjs.com/package/prunify)
9
+ [![Node.js โ‰ฅ 18](https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=flat-square)](https://nodejs.org)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-ready-blue?style=flat-square)](https://www.typescriptlang.org)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](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
- [![npm version](https://img.shields.io/npm/v/prunify.svg)](https://www.npmjs.com/package/prunify)
6
- [![npm downloads](https://img.shields.io/npm/dw/prunify.svg)](https://www.npmjs.com/package/prunify)
7
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
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
+ ![prunify demo](.github/assets/demo.gif)
23
+ ```
24
+
25
+ ---
8
26
 
9
- **prunify** is a zero-config CLI that audits your TypeScript or JavaScript codebase for:
27
+ ## What it detects
10
28
 
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
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
- # Global install
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
- # Only check dead code and circular imports
61
+ # Run only specific checks
41
62
  npx prunify --only dead-code,circular
42
63
 
43
- # CI mode โ€” exits 1 if any issues found
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 | 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. |
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
- ### Examples
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 with HTML gauge
128
+ # Full health report as HTML
73
129
  npx prunify --only health --html
74
130
 
75
- # Specify entry point explicitly
76
- npx prunify --dir ./packages/core --entry src/index.ts
131
+ # Only check unused public assets
132
+ npx prunify --only assets
77
133
 
78
- # Delete dead files after confirming in prompt
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
- ## Sample Output
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 / 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`) |
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
- ## Add to `.gitignore`
159
+ ## How Dead Code Detection Works
126
160
 
127
- prunify automatically appends `prunify-reports/` to your `.gitignore`. If you prefer to commit reports, remove the entry.
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
- ```gitignore
130
- # added by prunify
131
- prunify-reports/
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
- A score of **โ‰ฅ 80** is green, **50โ€“79** is amber, **< 50** is red.
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 **โ‰ฅ 18**
156
- - Works with TypeScript **and** JavaScript projects
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/YOUR_USERNAME/prunify.git
244
+ git clone https://github.com/DhananjaySarathe/prunify.git
165
245
  cd prunify
166
246
  npm install
167
- npm test # run the test suite
168
- npm run build # compile to dist/
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
- Issues and PRs are welcome at [github.com/YOUR_USERNAME/prunify](https://github.com/YOUR_USERNAME/prunify/issues).
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
- ## License
259
+ Please open an issue first for large changes so we can discuss the approach.
176
260
 
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
- ```
261
+ ---
195
262
 
196
263
  ## License
197
264
 
198
- MIT
265
+ MIT ยฉ [Dhananjay Sarathe](https://github.com/DhananjaySarathe)