feat: add image size verification script#696
Conversation
Closes #637 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughNew image-size validation: a Node script ( Changes
Sequence Diagram(s)sequenceDiagram
participant Git as Git / pre-commit
participant LintStaged as lint-staged
participant NodeScript as scripts/check-image-size.ts
participant FS as File System
Git->>LintStaged: trigger staged file hooks
LintStaged->>NodeScript: invoke check-image-size with file paths
NodeScript->>FS: stat each file, read size
NodeScript-->>LintStaged: return success or list of violations
alt violations found
LintStaged->>Git: fail commit (exit 1), print errors & guidance
else all ok
LintStaged->>Git: allow commit to proceed
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/check-image-size.ts (1)
10-16: Consider handling file access errors gracefully.
statSyncwill throw if a file doesn't exist or is inaccessible (e.g., deleted between staging and the hook running). While rare, this could crash the script with an unhelpful error.🛡️ Optional: Add try-catch for robustness
for (const file of files) { + try { const stats = statSync(file); if (stats.size > MAX_SIZE_BYTES) { const sizeKB = Math.round(stats.size / 1024); errors.push(` ${basename(file)} (${sizeKB} KB > ${MAX_SIZE_KB} KB)`); } + } catch (err) { + console.warn(`⚠️ Could not check ${basename(file)}: ${(err as Error).message}`); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/check-image-size.ts` around lines 10 - 16, The loop that checks file sizes currently calls statSync(file) which can throw if a file is missing or inaccessible; wrap the statSync call in a try-catch inside the for (const file of files) loop and on error either skip the file and optionally push a descriptive message into errors (e.g., `${basename(file)} (unavailable: ${err.message})`) or log it, ensuring you still compare stats.size > MAX_SIZE_BYTES when stat succeeds; reference the symbols files, statSync, basename, errors, MAX_SIZE_BYTES and MAX_SIZE_KB.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Around line 17-18: The lint-staged entry for "*. {ts,tsx,js,jsx,json,astro}"
currently runs "prettier --write src/" which ignores the list of staged files;
update that rule to run Prettier against the staged file paths (i.e., replace
the fixed "prettier --write src/" command with a command that accepts
lint-staged file args such as "prettier --write" so lint-staged will pass the
matched files), keeping the existing pattern name
("*.{ts,tsx,js,jsx,json,astro}") intact so only staged files are formatted.
---
Nitpick comments:
In `@scripts/check-image-size.ts`:
- Around line 10-16: The loop that checks file sizes currently calls
statSync(file) which can throw if a file is missing or inaccessible; wrap the
statSync call in a try-catch inside the for (const file of files) loop and on
error either skip the file and optionally push a descriptive message into errors
(e.g., `${basename(file)} (unavailable: ${err.message})`) or log it, ensuring
you still compare stats.size > MAX_SIZE_BYTES when stat succeeds; reference the
symbols files, statSync, basename, errors, MAX_SIZE_BYTES and MAX_SIZE_KB.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d536a106-61ac-4b6b-8161-7f953517b7b1
📒 Files selected for processing (2)
package.jsonscripts/check-image-size.ts
There was a problem hiding this comment.
for me 500 is too generic, in the project we have images for :
- avatars
- hero sections
- images for podcast
- images used in the news
i think 500 is great for avatars but for hero section or images used in the news/podcast i feel we can easily surpass the 500 KB threshold .
perhaps we can tolerate more in size depending on the image purpose
Different thresholds based on image purpose: - People, partners: 500 KB - News, podcasts, hero: 1000 KB - Events: 2000 KB - Other: 500 KB Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
check:imagesscript for manual usageCloses #637
🤖 Generated with Claude Code
Summary by CodeRabbit