Skip to content

Commit c99e7ab

Browse files
remove the compare command from the bundle-size script
1 parent bd0cde3 commit c99e7ab

File tree

3 files changed

+4
-152
lines changed

3 files changed

+4
-152
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ This script automatically:
334334
1. Stashes any uncommitted changes
335335
2. Checks out and builds the base branch (default: `master`)
336336
3. Checks out and builds your current branch
337-
4. Compares the sizes and shows a detailed report
337+
4. Compares the size and total execution time (loading + running) and shows a detailed report
338338

339339
Options:
340340

bin/compare-bundle-sizes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ git checkout "$CURRENT_BRANCH" --quiet
6363
pnpm install --frozen-lockfile 2>&1 | grep -v "^$" | head -5 || true
6464
pnpm run build 2>&1 | grep -v "^$" | tail -3 || true
6565

66-
echo -e "${BLUE}Updating limits${NC}"
66+
echo -e "${BLUE}Updating limits of current branch relative to the results of the base branch...${NC}"
6767
node scripts/bundle-size.mjs set-limits --base /tmp/base-sizes.json
6868

69+
# Run size-limit that will use the dynamic limits created after checking base branch results
6970
pnpm exec size-limit

scripts/bundle-size.mjs

Lines changed: 1 addition & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
*
55
* Commands:
66
* set-limits - Update .size-limit.json with dynamic limits (base + threshold)
7-
* compare - Compare two size measurements and print a report
87
*
98
* Usage:
109
* node scripts/bundle-size.mjs set-limits --base <file> [--config <file>] [--threshold <bytes>]
11-
* node scripts/bundle-size.mjs compare --base <file> --current <file> [--threshold <bytes>]
1210
*
1311
* Examples:
1412
* node scripts/bundle-size.mjs set-limits --base /tmp/base-sizes.json
15-
* node scripts/bundle-size.mjs compare --base /tmp/base-sizes.json --current /tmp/current-sizes.json
1613
*/
1714

1815
import fs from 'fs';
@@ -53,15 +50,6 @@ function formatTime(ms) {
5350
return `${ms.toFixed(0)} ms`;
5451
}
5552

56-
/**
57-
* Format size difference with percentage
58-
*/
59-
function formatDiff(diff, percent) {
60-
if (diff === 0) return '0%';
61-
const sign = diff > 0 ? '+' : '';
62-
return `${sign}${formatSize(Math.abs(diff))} (${sign}${percent.toFixed(2)}%)`;
63-
}
64-
6553
/**
6654
* Parse command line arguments
6755
*/
@@ -170,127 +158,6 @@ function setLimits(options) {
170158
console.log(`${colors.green}Updated ${configPath}${colors.reset}`);
171159
}
172160

173-
/**
174-
* Get diff color based on threshold
175-
*/
176-
function getDiffColor(diff, threshold) {
177-
if (diff > threshold) return colors.red;
178-
if (diff > 0) return colors.yellow;
179-
return colors.green;
180-
}
181-
182-
/**
183-
* Print a single result row
184-
*/
185-
function printResultRow(result, maxNameLen, threshold) {
186-
const status = result.exceeded
187-
? `${colors.red}❌ EXCEEDED${colors.reset}`
188-
: `${colors.green}✅ OK${colors.reset}`;
189-
190-
const diffColor = getDiffColor(result.diff, threshold);
191-
const diffStr = `${diffColor}${formatDiff(result.diff, result.percent)}${colors.reset}`;
192-
193-
const namePart = result.name.padEnd(maxNameLen + 2);
194-
const basePart = formatSize(result.baseSize).padStart(12);
195-
const currentPart = formatSize(result.currentSize).padStart(12);
196-
const diffPart = diffStr.padStart(20 + 9);
197-
198-
console.log(`${namePart}${basePart}${currentPart}${diffPart} ${status}`);
199-
}
200-
201-
/**
202-
* Command: compare
203-
* Compares two size measurements and prints a report
204-
*/
205-
function compare(options) {
206-
const basePath = options.base;
207-
const currentPath = options.current;
208-
const threshold = parseInt(options.threshold, 10) || DEFAULT_THRESHOLD;
209-
const json = options.json === true || options.json === 'true';
210-
211-
if (!basePath || !currentPath) {
212-
console.error(`${colors.red}Error: --base <file> and --current <file> are required${colors.reset}`);
213-
process.exit(1);
214-
}
215-
216-
const baseSizes = readJsonFileOrExit(basePath);
217-
const currentSizes = readJsonFileOrExit(currentPath);
218-
219-
const results = currentSizes.map((current) => {
220-
const base = baseSizes.find((b) => b.name === current.name) || { size: 0 };
221-
const diff = current.size - base.size;
222-
const percent = base.size > 0 ? (diff / base.size) * 100 : 0;
223-
const exceeded = diff > threshold;
224-
225-
return {
226-
name: current.name,
227-
baseSize: base.size,
228-
currentSize: current.size,
229-
diff,
230-
percent,
231-
exceeded,
232-
};
233-
});
234-
235-
const hasExceeded = results.some((r) => r.exceeded);
236-
237-
if (json) {
238-
// JSON output for programmatic use
239-
console.log(
240-
JSON.stringify(
241-
{
242-
threshold,
243-
hasExceeded,
244-
results: results.map((r) => ({
245-
name: r.name,
246-
baseSize: r.baseSize,
247-
currentSize: r.currentSize,
248-
diff: r.diff,
249-
percentChange: r.percent,
250-
exceeded: r.exceeded,
251-
})),
252-
},
253-
null,
254-
2,
255-
),
256-
);
257-
} else {
258-
// Pretty table output
259-
const maxNameLen = Math.max(...results.map((r) => r.name.length));
260-
const separator = '━'.repeat(76);
261-
const thinSeparator = '─'.repeat(maxNameLen + 2 + 12 + 12 + 20 + 12);
262-
263-
console.log('');
264-
console.log(`${colors.blue}${separator}${colors.reset}`);
265-
console.log(`${colors.blue}Bundle Size Report${colors.reset}`);
266-
console.log(`${colors.blue}${separator}${colors.reset}`);
267-
console.log('');
268-
269-
const header = `${'Package'.padEnd(maxNameLen + 2)}${'Base'.padStart(12)}${'Current'.padStart(
270-
12,
271-
)}${'Diff'.padStart(20)} Status`;
272-
console.log(header);
273-
console.log(thinSeparator);
274-
275-
results.forEach((r) => printResultRow(r, maxNameLen, threshold));
276-
277-
console.log('');
278-
console.log(thinSeparator);
279-
console.log(`Threshold: ${formatSize(threshold)} (base + ${formatSize(threshold)})`);
280-
console.log('');
281-
282-
if (hasExceeded) {
283-
console.log(`${colors.red}❌ Some packages exceeded the size threshold!${colors.reset}`);
284-
} else {
285-
console.log(`${colors.green}✅ All packages within threshold.${colors.reset}`);
286-
}
287-
}
288-
289-
if (hasExceeded) {
290-
process.exit(1);
291-
}
292-
}
293-
294161
/**
295162
* Print usage help
296163
*/
@@ -300,32 +167,19 @@ ${colors.blue}Bundle Size Utilities${colors.reset}
300167
301168
${colors.yellow}Commands:${colors.reset}
302169
set-limits Update .size-limit.json with dynamic limits
303-
compare Compare two size measurements and print report
304170
305171
${colors.yellow}Usage:${colors.reset}
306172
node scripts/bundle-size.mjs set-limits --base <file> [options]
307-
node scripts/bundle-size.mjs compare --base <file> --current <file> [options]
308173
309174
${colors.yellow}Options for set-limits:${colors.reset}
310175
--base <file> Path to base sizes JSON (required)
311176
--config <file> Path to .size-limit.json (default: .size-limit.json)
312177
--threshold <bytes> Size threshold in bytes (default: 512)
313-
314-
${colors.yellow}Options for compare:${colors.reset}
315-
--base <file> Path to base sizes JSON (required)
316-
--current <file> Path to current sizes JSON (required)
317-
--threshold <bytes> Size threshold in bytes (default: 512)
318-
--json Output results as JSON
178+
--timePercentageThreshold <percentage> Acceptable increase percentage in total time
319179
320180
${colors.yellow}Examples:${colors.reset}
321181
# Set dynamic limits from base sizes
322182
node scripts/bundle-size.mjs set-limits --base /tmp/base-sizes.json
323-
324-
# Compare sizes with custom threshold (1KB)
325-
node scripts/bundle-size.mjs compare --base base.json --current current.json --threshold 1024
326-
327-
# Get comparison as JSON
328-
node scripts/bundle-size.mjs compare --base base.json --current current.json --json
329183
`);
330184
}
331185

@@ -337,9 +191,6 @@ switch (command) {
337191
case 'set-limits':
338192
setLimits(args);
339193
break;
340-
case 'compare':
341-
compare(args);
342-
break;
343194
case 'help':
344195
case '--help':
345196
case '-h':

0 commit comments

Comments
 (0)