Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This pull request adds support for calculating and displaying directory sizes in the package file browser. Previously, only individual file sizes were shown; now directories display the recursive total of all files they contain, matching the behavior of npm's package explorer.
Changes:
- Implemented recursive directory size calculation in the file tree conversion logic
- Updated type documentation to clarify that size applies to both files and directories
- Bumped API cache key version to invalidate old cached responses
- Modified UI to display sizes for both files and directories
- Added comprehensive test coverage for directory size calculations
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
server/utils/file-tree.ts |
Added recursive directory size calculation using reduce to sum all child node sizes |
shared/types/npm-registry.ts |
Updated JSDoc comment to document that size field applies to directories (as recursive totals) and files |
server/api/registry/files/[...pkg].get.ts |
Incremented cache key from v1 to v2 to invalidate stale cached responses with old structure |
app/components/Code/DirectoryListing.vue |
Changed condition from checking file type and size to type-safe number check to display sizes for both files and directories |
test/unit/server/utils/file-tree.spec.ts |
Added assertions to verify directory sizes are calculated correctly including nested directories and empty directories |
📝 WalkthroughWalkthroughThis change extends the file tree structure to include size information for directory nodes. The 🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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.
🧹 Nitpick comments (1)
app/components/Code/DirectoryListing.vue (1)
123-125:typeof node.size === 'number'is the right guard – minor UX note for the0case.The check correctly supersedes a truthiness test and handles both
size === 0and type-narrowing forbytesFormatter.format. One consequence: empty directories (whose computedsizeis always0) will now render "0 B" in the listing. If that's undesirable, a simple additional guard would suppress it:✨ Optional: suppress "0 B" for empty directories
-<span v-if="typeof node.size === 'number'" class="text-end text-xs text-fg-subtle"> +<span v-if="typeof node.size === 'number' && node.size > 0" class="text-end text-xs text-fg-subtle">
|
Hi @wojtekmaj , very nice feature)
|
@alex-key Heh, looks like you've found a bug - but not in my PR, but in npmx in general. Taking /fast-xml-parser/lib/fxbuilder.min.js as an example, which is 8414 bytes long, npm reports its size as 8.41 kB, we as 8.2 kB. So we give size as KiB while we say it's kB. Will fix in a separate PR cause it has nothing to do with that one. There you go: #1541 |


Before/After:
npm reference: