pruny 1.0.4 → 1.0.6

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.
Files changed (3) hide show
  1. package/docs/index.md +92 -0
  2. package/llms.txt +37 -10
  3. package/package.json +1 -1
package/docs/index.md ADDED
@@ -0,0 +1,92 @@
1
+ # Pruny
2
+
3
+ > Find and remove unused Next.js API routes.
4
+
5
+ ## Summary
6
+ Pruny is a CLI tool that scans Next.js projects (App Router) to identify API routes that are not referenced in the codebase. It supports auto-detection of usage via `fetch`, `axios`, and `useSWR`, and respects `vercel.json` cron jobs.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install -g pruny
12
+ # or run directly
13
+ npx pruny
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Scan Mode
19
+ Scans the current directory or specified directory for unused routes.
20
+ ```bash
21
+ npx pruny
22
+ npx pruny --dir ./src
23
+ ```
24
+
25
+ ### Fix Mode (Deletion)
26
+ Automatically deletes the folders of unused API routes.
27
+ ```bash
28
+ npx pruny --fix
29
+ ```
30
+
31
+ ### JSON Output
32
+ Outputs the results in JSON format for program consumption.
33
+ ```bash
34
+ npx pruny --json
35
+ ```
36
+
37
+ ## Configuration
38
+ Pruny looks for `pruny.config.json` in the project root.
39
+
40
+ ```json
41
+ {
42
+ "dir": "./",
43
+ "ignore": {
44
+ "routes": ["/api/webhooks/**", "/api/cron/**"],
45
+ "folders": ["node_modules", ".next", "dist", ".git"],
46
+ "files": ["*.test.ts", "*.spec.ts"]
47
+ },
48
+ "extensions": [".ts", ".tsx", ".js", ".jsx"]
49
+ }
50
+ ```
51
+
52
+ ## Advanced Usage & Limitations
53
+
54
+ ### Dynamic Routes & Custom Clients
55
+ Pruny detects API usage by static analysis of string literals.
56
+ - **Supported**:
57
+ - `fetch('/api/users')`
58
+ - `` fetch(`/api/users/${id}`) `` (Template literals with constant prefix)
59
+ - `axios.get('/api/items')`
60
+ - `useSWR('/api/data')`
61
+ - **Limitations**:
62
+ - **Runtime Construction**: Routes constructed purely at runtime without a static `/api/` prefix literal cannot be detected.
63
+ - ❌ `fetch(myUrlVariable)` -> **False Positive** (Pruny thinks route is unused)
64
+ - ✅ `fetch('/api/' + myUrlVariable)` -> **Detected**
65
+ - **Custom Wrappers**: If you wrap `fetch` in a custom `apiClient` without standard method names, use `// pruny-ignore` (future feature) or manually ignore the route in config.
66
+
67
+ ### Monorepo / Multi-App Setup
68
+ For monorepos with multiple Next.js apps (e.g., `apps/web`, `apps/admin`):
69
+
70
+ 1. **Run per package**:
71
+ ```bash
72
+ cd apps/web && npx pruny
73
+ ```
74
+ 2. **Run from root with --dir**:
75
+ ```bash
76
+ # Scan specific app
77
+ npx pruny --dir ./apps/web
78
+
79
+ # Scan another app
80
+ npx pruny --dir ./apps/admin
81
+ ```
82
+ *Note: Pruny's config resolution looks for `pruny.config.json` in the specific `dir` being scanned.*
83
+
84
+ ### Vercel Cron Detection
85
+ Pruny automatically parses `vercel.json` to process cron jobs.
86
+ - It looks for `crons: [{ path: "/api/cron/job" }]` array.
87
+ - Any route path found in `vercel.json` is automatically marked as **USED**.
88
+ - This prevents accidental deletion of server-side cron handlers that are never "fetched" by client code.
89
+
90
+ ## Source Code
91
+ - Repository: https://github.com/WebNaresh/pruny
92
+ - Registry: https://www.npmjs.com/package/pruny
package/llms.txt CHANGED
@@ -49,16 +49,43 @@ Pruny looks for `pruny.config.json` in the project root.
49
49
  }
50
50
  ```
51
51
 
52
- ## How Detection Works
53
- 1. **Discovery**: Finds all `app/api/**/route.{ts,js}` files.
54
- 2. **Scanning**: Greps all source files for usage patterns like:
55
- - `fetch('/api/my-route')`
56
- - `axios.get('/api/my-route')`
57
- - `useSWR('/api/my-route')`
58
- - Template literals: `` `/api/${variable}` `` (matches exact prefix)
59
- 3. **Exclusions**:
60
- - Routes defined in `vercel.json` crons are automatically marked as used.
61
- - Routes matching `ignore.routes` glob patterns are skipped.
52
+ ## Advanced Usage & Limitations
53
+
54
+ ### Dynamic Routes & Custom Clients
55
+ Pruny detects API usage by static analysis of string literals.
56
+ - **Supported**:
57
+ - `fetch('/api/users')`
58
+ - `` fetch(`/api/users/${id}`) `` (Template literals with constant prefix)
59
+ - `axios.get('/api/items')`
60
+ - `useSWR('/api/data')`
61
+ - **Limitations**:
62
+ - **Runtime Construction**: Routes constructed purely at runtime without a static `/api/` prefix literal cannot be detected.
63
+ - ❌ `fetch(myUrlVariable)` -> **False Positive** (Pruny thinks route is unused)
64
+ - ✅ `fetch('/api/' + myUrlVariable)` -> **Detected**
65
+ - **Custom Wrappers**: If you wrap `fetch` in a custom `apiClient` without standard method names, use `// pruny-ignore` (future feature) or manually ignore the route in config.
66
+
67
+ ### Monorepo / Multi-App Setup
68
+ For monorepos with multiple Next.js apps (e.g., `apps/web`, `apps/admin`):
69
+
70
+ 1. **Run per package**:
71
+ ```bash
72
+ cd apps/web && npx pruny
73
+ ```
74
+ 2. **Run from root with --dir**:
75
+ ```bash
76
+ # Scan specific app
77
+ npx pruny --dir ./apps/web
78
+
79
+ # Scan another app
80
+ npx pruny --dir ./apps/admin
81
+ ```
82
+ *Note: Pruny's config resolution looks for `pruny.config.json` in the specific `dir` being scanned.*
83
+
84
+ ### Vercel Cron Detection
85
+ Pruny automatically parses `vercel.json` to process cron jobs.
86
+ - It looks for `crons: [{ path: "/api/cron/job" }]` array.
87
+ - Any route path found in `vercel.json` is automatically marked as **USED**.
88
+ - This prevents accidental deletion of server-side cron handlers that are never "fetched" by client code.
62
89
 
63
90
  ## Source Code
64
91
  - Repository: https://github.com/WebNaresh/pruny
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Find and remove unused Next.js API routes",
5
5
  "type": "module",
6
6
  "bin": {