roast-my-codebase 1.2.0 → 1.3.1

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.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ BundleSizeScanner,
4
+ formatBytes
5
+ } from "./chunk-32UIGL7K.js";
6
+ export {
7
+ BundleSizeScanner,
8
+ formatBytes
9
+ };
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/scanners/bundle.ts
4
+ import fg from "fast-glob";
5
+ import fs from "fs";
6
+ import path from "path";
7
+
8
+ // src/utils/constants.ts
9
+ var SOURCE_EXTENSIONS = [
10
+ ".ts",
11
+ ".tsx",
12
+ ".js",
13
+ ".jsx",
14
+ ".mjs",
15
+ ".cjs",
16
+ ".py",
17
+ // Python
18
+ ".go",
19
+ // Go
20
+ ".rs",
21
+ // Rust
22
+ ".java",
23
+ // Java
24
+ ".cs",
25
+ // C#
26
+ ".rb",
27
+ // Ruby
28
+ ".php",
29
+ // PHP
30
+ ".swift",
31
+ // Swift
32
+ ".kt",
33
+ // Kotlin
34
+ ".kts"
35
+ // Kotlin script
36
+ ];
37
+ var IGNORE_PATTERNS = [
38
+ "**/node_modules/**",
39
+ "**/dist/**",
40
+ "**/build/**",
41
+ "**/.next/**",
42
+ "**/coverage/**",
43
+ "**/.git/**",
44
+ "**/.turbo/**",
45
+ "**/.cache/**",
46
+ "**/out/**",
47
+ "**/.output/**"
48
+ ];
49
+ function buildIgnorePatterns(extraPatterns = []) {
50
+ return [...IGNORE_PATTERNS, ...extraPatterns];
51
+ }
52
+ var SAFE_GLOB_OPTIONS = {
53
+ followSymbolicLinks: false,
54
+ deep: 20
55
+ };
56
+ var LARGE_FILE_THRESHOLDS = {
57
+ warning: 500,
58
+ large: 1e3,
59
+ extreme: 2e3
60
+ };
61
+ var HEALTH_DEDUCTIONS = {
62
+ unusedDependency: -2,
63
+ todo: -0.25,
64
+ largeFile: -3,
65
+ extremeFile: -5,
66
+ circularDependency: -5,
67
+ criticalIssue: -10,
68
+ excessiveDeps: -5,
69
+ deepNesting: -2,
70
+ utilExplosion: -1,
71
+ complexFunction: -2,
72
+ veryComplexFunction: -4,
73
+ duplicateCode: -3,
74
+ deadExport: -1,
75
+ typeSafetyIssue: -2,
76
+ criticalTypeSafety: -5,
77
+ gitChurn: -3,
78
+ largePRSize: -2,
79
+ secret: -10,
80
+ envInGit: -10,
81
+ evalUsage: -3,
82
+ missingTest: -0.5,
83
+ frameworkViolation: -2
84
+ };
85
+
86
+ // src/scanners/bundle.ts
87
+ function formatBytes(bytes) {
88
+ if (bytes < 1024) return `${bytes} B`;
89
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
90
+ return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
91
+ }
92
+ var OUTPUT_DIRS = ["dist", "build", ".next", "out", ".output"];
93
+ var BundleSizeScanner = class {
94
+ constructor() {
95
+ this.name = "bundle-size";
96
+ }
97
+ async scan(rootDir) {
98
+ let outputDir = null;
99
+ for (const dir of OUTPUT_DIRS) {
100
+ const candidate = path.join(rootDir, dir);
101
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
102
+ outputDir = candidate;
103
+ break;
104
+ }
105
+ }
106
+ if (!outputDir) {
107
+ return {
108
+ findings: [],
109
+ stats: { skipped: true, reason: "No build output found (run build first)" }
110
+ };
111
+ }
112
+ const files = await fg(["**/*.{js,mjs,cjs,css,wasm}"], {
113
+ cwd: outputDir,
114
+ ignore: ["**/node_modules/**", "**/*.map", "**/*.LICENSE.*"],
115
+ ...SAFE_GLOB_OPTIONS,
116
+ absolute: true
117
+ });
118
+ const currentSizes = {};
119
+ let totalBytes = 0;
120
+ for (const file of files) {
121
+ const rel = path.relative(outputDir, file).replace(/\\/g, "/");
122
+ const size = fs.statSync(file).size;
123
+ currentSizes[rel] = size;
124
+ totalBytes += size;
125
+ }
126
+ const cachePath = path.join(rootDir, ".roast-bundle-sizes.json");
127
+ let previousCache = null;
128
+ if (fs.existsSync(cachePath)) {
129
+ try {
130
+ previousCache = JSON.parse(fs.readFileSync(cachePath, "utf-8"));
131
+ } catch {
132
+ }
133
+ }
134
+ const findings = [];
135
+ if (!previousCache) {
136
+ if (totalBytes > 5 * 1024 * 1024) {
137
+ findings.push({
138
+ id: "bundle-size-total-critical",
139
+ severity: "critical",
140
+ category: "bundle-size",
141
+ message: `Total bundle size is ${formatBytes(totalBytes)} \u2014 that's a lot to send over the wire`,
142
+ detail: `${formatBytes(totalBytes)}`
143
+ });
144
+ } else if (totalBytes > 1024 * 1024) {
145
+ findings.push({
146
+ id: "bundle-size-total-warning",
147
+ severity: "warning",
148
+ category: "bundle-size",
149
+ message: `Total bundle size is ${formatBytes(totalBytes)}`,
150
+ detail: `${formatBytes(totalBytes)}`
151
+ });
152
+ }
153
+ } else {
154
+ const previousSizes = previousCache.sizes;
155
+ for (const [file, curr] of Object.entries(currentSizes)) {
156
+ const prev = previousSizes[file];
157
+ if (prev === void 0) {
158
+ if (curr > 100 * 1024) {
159
+ findings.push({
160
+ id: `bundle-size-new-${file}`,
161
+ severity: "info",
162
+ category: "bundle-size",
163
+ message: `New bundle file ${file} (${formatBytes(curr)})`,
164
+ file,
165
+ detail: formatBytes(curr)
166
+ });
167
+ }
168
+ } else {
169
+ const delta = (curr - prev) / prev * 100;
170
+ const growthBytes = curr - prev;
171
+ if (delta > 50 && growthBytes > 50 * 1024) {
172
+ findings.push({
173
+ id: `bundle-size-critical-${file}`,
174
+ severity: "critical",
175
+ category: "bundle-size",
176
+ message: `${file} grew ${delta.toFixed(0)}% (${formatBytes(prev)} \u2192 ${formatBytes(curr)})`,
177
+ file,
178
+ detail: `+${delta.toFixed(0)}%`
179
+ });
180
+ } else if (delta > 10 && growthBytes > 10 * 1024) {
181
+ findings.push({
182
+ id: `bundle-size-warning-${file}`,
183
+ severity: "warning",
184
+ category: "bundle-size",
185
+ message: `${file} grew ${delta.toFixed(0)}% (${formatBytes(prev)} \u2192 ${formatBytes(curr)})`,
186
+ file,
187
+ detail: `+${delta.toFixed(0)}%`
188
+ });
189
+ }
190
+ }
191
+ }
192
+ for (const file of Object.keys(previousSizes)) {
193
+ if (!(file in currentSizes)) {
194
+ findings.push({
195
+ id: `bundle-size-removed-${file}`,
196
+ severity: "info",
197
+ category: "bundle-size",
198
+ message: `${file} removed from bundle`,
199
+ file
200
+ });
201
+ }
202
+ }
203
+ const prevTotal = Object.values(previousSizes).reduce((a, b) => a + b, 0);
204
+ if (prevTotal > 0) {
205
+ const totalDelta = (totalBytes - prevTotal) / prevTotal * 100;
206
+ if (totalDelta > 20) {
207
+ findings.push({
208
+ id: "bundle-size-total-growth",
209
+ severity: "warning",
210
+ category: "bundle-size",
211
+ message: `Total bundle size grew ${totalDelta.toFixed(0)}% (${formatBytes(prevTotal)} \u2192 ${formatBytes(totalBytes)})`,
212
+ detail: `+${totalDelta.toFixed(0)}%`
213
+ });
214
+ }
215
+ }
216
+ }
217
+ const newCache = { timestamp: Date.now(), sizes: currentSizes };
218
+ try {
219
+ fs.writeFileSync(cachePath, JSON.stringify(newCache, null, 2), "utf-8");
220
+ } catch {
221
+ }
222
+ const relativeOutputDir = outputDir.replace(rootDir, ".");
223
+ return {
224
+ findings,
225
+ stats: {
226
+ totalBytes,
227
+ totalFormatted: formatBytes(totalBytes),
228
+ fileCount: files.length,
229
+ outputDir: relativeOutputDir,
230
+ hasBaseline: previousCache !== null
231
+ }
232
+ };
233
+ }
234
+ };
235
+
236
+ export {
237
+ SOURCE_EXTENSIONS,
238
+ IGNORE_PATTERNS,
239
+ buildIgnorePatterns,
240
+ SAFE_GLOB_OPTIONS,
241
+ LARGE_FILE_THRESHOLDS,
242
+ HEALTH_DEDUCTIONS,
243
+ formatBytes,
244
+ BundleSizeScanner
245
+ };