backend-diet 1.0.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.

Potentially problematic release.


This version of backend-diet might be problematic. Click here for more details.

package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # backend-diet ๐Ÿฅ—
2
+
3
+ [![npm version](https://img.shields.io/npm/v/backend-diet?style=flat-square)](https://www.npmjs.com/package/backend-diet)
4
+ [![CI](https://github.com/1iPluto/backend-diet/actions/workflows/ci.yml/badge.svg)](https://github.com/1iPluto/backend-diet/actions/workflows/ci.yml)
5
+ [![Node >=18](https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=flat-square)](https://nodejs.org)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue?style=flat-square)](LICENSE)
7
+
8
+ > **Put your project on a diet.** Scan your source code, identify specific library functions you're actually using, and get native Node.js / Web API alternatives โ€” with code snippets, in your terminal, right now.
9
+
10
+ Most tools tell you a package is large. **backend-diet tells you exactly what to replace and how.**
11
+
12
+ ---
13
+
14
+ ## Features
15
+
16
+ | Feature | Description |
17
+ |---|---|
18
+ | **AST-accurate scanning** | Uses Babel to parse JS/TS/JSX/TSX โ€” no regex false positives |
19
+ | **Refactor Score** | A 0โ€“100 score graded CRITICAL โ†’ SVELTE showing how lean your project is |
20
+ | **Code snippets** | Every suggestion shows a before/after code snippet in the terminal |
21
+ | **Auto-Patch `--fix`** | Automatically rewrites trivial replacements (e.g. `uuidv4()` โ†’ `crypto.randomUUID()`) |
22
+ | **Badge generator `--badge`** | One command generates a Shields.io badge for your README |
23
+ | **Time Machine `--since`** | Tracks score history across git commits with an ASCII sparkline |
24
+ | **CI-friendly `--format json`** | Full JSON output for integration into CI pipelines |
25
+
26
+ ---
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ # No install needed โ€” run on any project instantly
32
+ npx backend-diet scan
33
+
34
+ # Global install
35
+ npm install -g backend-diet
36
+
37
+ # As a dev dependency
38
+ npm install --save-dev backend-diet
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Usage
44
+
45
+ ```bash
46
+ # Scan the current directory
47
+ backend-diet scan
48
+
49
+ # Scan a specific directory
50
+ backend-diet scan ./src
51
+
52
+ # Show trivial auto-patches (dry run)
53
+ backend-diet scan --fix
54
+
55
+ # Apply patches in-place
56
+ backend-diet scan --fix --yes
57
+
58
+ # Generate a README badge
59
+ backend-diet scan --badge
60
+
61
+ # Track score over the last 20 commits
62
+ backend-diet scan --since HEAD~20
63
+
64
+ # CI mode โ€” JSON output
65
+ backend-diet scan --format json
66
+
67
+ # Ignore vendor files
68
+ backend-diet scan --ignore "vendor/**" "generated/**"
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Refactor Score
74
+
75
+ ```
76
+ Score = 100 โˆ’ round((bytes_you_could_remove / total_dep_bytes) ร— 100)
77
+ ```
78
+
79
+ | Score | Grade | Meaning |
80
+ |---|---|---|
81
+ | 90โ€“100 | ๐Ÿฅ— SVELTE | Your project is already very lean |
82
+ | 70โ€“89 | โœ… HEALTHY | A few improvements possible |
83
+ | 40โ€“69 | โš ๏ธ NEEDS WORK | Significant savings on the table |
84
+ | 0โ€“39 | ๐Ÿ’€ CRITICAL | Heavy bloat detected (CI will exit 1) |
85
+
86
+ ---
87
+
88
+ ## Supported Packages
89
+
90
+ | Package | Coverage | Total Gzipped Size |
91
+ |---|---|---|
92
+ | `lodash` | 19 functions | ~24 KB |
93
+ | `moment` | 9 functions | ~72 KB |
94
+ | `axios` | 7 functions | ~14 KB |
95
+ | `uuid` | 2 functions | ~3.7 KB |
96
+ | `bluebird` | 9 functions | ~17 KB |
97
+ | `underscore` | 12 functions | ~6.8 KB |
98
+
99
+ ---
100
+
101
+ ## Auto-Patch Examples
102
+
103
+ ### `uuid` โ†’ `crypto.randomUUID()`
104
+
105
+ ```diff
106
+ - import { v4 as uuidv4 } from 'uuid';
107
+ - const id = uuidv4();
108
+ + const id = crypto.randomUUID();
109
+ ```
110
+
111
+ ### `_.cloneDeep` โ†’ `structuredClone()`
112
+
113
+ ```diff
114
+ - import { cloneDeep } from 'lodash';
115
+ - const copy = cloneDeep(obj);
116
+ + const copy = structuredClone(obj);
117
+ ```
118
+
119
+ ### `_.get` โ†’ Optional chaining
120
+
121
+ ```diff
122
+ - import { get } from 'lodash';
123
+ - const val = get(obj, 'a.b.c', defaultVal);
124
+ + const val = obj?.a?.b?.c ?? defaultVal;
125
+ ```
126
+
127
+ ---
128
+
129
+ ## CI Integration
130
+
131
+ Add to your `package.json` scripts:
132
+
133
+ ```json
134
+ {
135
+ "scripts": {
136
+ "diet": "backend-diet scan --format json"
137
+ }
138
+ }
139
+ ```
140
+
141
+ Or use it as a GitHub Actions step:
142
+
143
+ ```yaml
144
+ - name: Bundle diet check
145
+ run: npx backend-diet scan --format json
146
+ # Exits with code 1 if score is CRITICAL
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Time Machine
152
+
153
+ backend-diet saves a `.backend-diet-history.json` in your project root. Each scan appends an entry with the score, grade, and current git SHA.
154
+
155
+ ```bash
156
+ backend-diet scan --since HEAD~20
157
+ # Shows a sparkline: โ–โ–‚โ–ƒโ–ƒโ–„โ–…โ–…โ–†โ–…โ–„โ–ƒ
158
+ # "Score trending DOWN โ€” your bundle is getting fatter."
159
+ ```
160
+
161
+ Add `.backend-diet-history.json` to version control to share trends with your team.
162
+
163
+ ---
164
+
165
+ ## Contributing โ€” Add a Package to the Database
166
+
167
+ The diet database is the heart of this tool. Community contributions are the primary growth engine.
168
+
169
+ To add support for a new package:
170
+
171
+ 1. Fork the repo
172
+ 2. Create `src/database/packs/<package-name>.ts`
173
+ 3. Follow the `PackageEntry` interface (see `src/types.ts`)
174
+ 4. Export it and register it in `src/database/index.ts`
175
+ 5. Open a PR with the title: `feat: add <package-name> to diet database`
176
+
177
+ **The bar for a good entry:**
178
+ - Real package (check bundlephobia.com for size)
179
+ - Has a native Node โ‰ฅ18 alternative
180
+ - Snippet must be copy-pasteable and correct
181
+
182
+ ---
183
+
184
+ ## Conventional Commits
185
+
186
+ This project follows [Conventional Commits](https://www.conventionalcommits.org/):
187
+
188
+ ```
189
+ feat: add new package to diet database
190
+ fix: resolve false positive on namespace imports
191
+ perf: switch file walker to fast-glob
192
+ refactor: extract scorer into standalone module
193
+ docs: update Time Machine section in README
194
+ chore: upgrade @babel/traverse
195
+ test: add unit tests for lodash cloneDeep detection
196
+ ```
197
+
198
+ Releases and changelogs are automated from commit history using `standard-version`.
199
+
200
+ ---
201
+
202
+ ## Publishing a New Release
203
+
204
+ ```bash
205
+ # 1. Bump version (auto-updates package.json + CHANGELOG.md)
206
+ npx standard-version
207
+
208
+ # 2. Push with tags
209
+ git push --follow-tags origin main
210
+
211
+ # GitHub Actions auto-publishes to npm on tag push
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Author
217
+
218
+ **Marwan Said** ยท [github.com/1iPluto](https://github.com/1iPluto)
219
+
220
+ ---
221
+
222
+ ## License
223
+
224
+ MIT
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ require('../dist/cli.js');