Skip to content

feat: add likes badge type (#2412)#2478

Open
t128n wants to merge 4 commits intonpmx-dev:mainfrom
t128n:feat/like-badge
Open

feat: add likes badge type (#2412)#2478
t128n wants to merge 4 commits intonpmx-dev:mainfrom
t128n:feat/like-badge

Conversation

@t128n
Copy link
Copy Markdown
Contributor

@t128n t128n commented Apr 11, 2026

🔗 Linked issue

Resolves #2412

🧭 Context

In #2412, it was requested to have a badge variant that shows the likes a specific package has on npmx.dev.

This PR introduces a likes-type badge.

📚 Description

This PR adds a badge type called likes and integrates the logic of the https://npmx.dev/api/social/likes/[pkg] endpoint into it.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs.npmx.dev Ready Ready Preview, Comment Apr 12, 2026 7:19am
npmx.dev Ready Ready Preview, Comment Apr 12, 2026 7:19am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Apr 12, 2026 7:19am

Request Review

@t128n t128n marked this pull request as ready for review April 11, 2026 19:54
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ebf1df04-b7d9-4b6c-9c37-ac4b5f563daa

📥 Commits

Reviewing files that changed from the base of the PR and between 50025b1 and 617d167.

📒 Files selected for processing (2)
  • docs/content/2.guide/6.badges.md
  • server/api/registry/badge/[type]/[...pkg].get.ts
✅ Files skipped from review due to trivial changes (1)
  • docs/content/2.guide/6.badges.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/api/registry/badge/[type]/[...pkg].get.ts

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new likes badge type that displays the total package likes count.
  • Documentation

    • Updated badge type documentation to include the new likes badge.

Walkthrough

Adds a new likes badge: documentation updated to list the likes badge; docs/shared/utils/badges.ts now includes 'likes' in BADGE_TYPES (expanding BadgeType); and the badge API (server/api/registry/badge/[type]/[...pkg].get.ts) adds a likes strategy that returns { label: 'likes', value: String(totalLikes ?? 0), color: COLORS.red }.

Changes

Cohort / File(s) Summary
Documentation
docs/content/2.guide/6.badges.md
Added likes entry to the "Available Badge Types" list and badge image/style reference.
Shared docs utils
docs/shared/utils/badges.ts
Added 'likes' to the frozen BADGE_TYPES array; exported BadgeType union now includes 'likes'.
Badge API
server/api/registry/badge/[type]/[...pkg].get.ts
Added badgeStrategies['likes'] that uses PackageLikesUtils.getLikes(pkg) and returns badge payload with label: 'likes', value: String(totalLikes ?? 0), and color: COLORS.red; allowed type keys now include 'likes' via Object.keys(badgeStrategies).

Possibly related PRs

Suggested reviewers

  • danielroe
  • ghostdevv
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing a new likes badge type, which is the primary objective of this pull request.
Description check ✅ Passed The description clearly explains the context, purpose, and implementation of the likes badge feature, relating directly to the changeset.
Linked Issues check ✅ Passed The PR fully implements the requested feature from issue #2412: it adds an official likes badge type that displays package likes without requiring users to parse the API endpoint directly.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the likes badge feature: documentation updates, type definitions, and badge strategy implementation. No extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/api/registry/badge/[type]/[...pkg].get.ts (1)

504-504: Avoid a non-zero fallback for likes count.

Line 504 uses totalLikes ?? 10, which can surface an arbitrary likes value. Prefer 0 (or no fallback if the contract guarantees a number).

♻️ Suggested change
-    return { label: 'likes', value: String(totalLikes ?? 10), color: COLORS.blue }
+    return { label: 'likes', value: String(totalLikes ?? 0), color: COLORS.blue }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ccf0e408-d5fe-4809-995c-430e925268b9

📥 Commits

Reviewing files that changed from the base of the PR and between 0164064 and a916a98.

📒 Files selected for processing (3)
  • docs/content/2.guide/6.badges.md
  • docs/shared/utils/badges.ts
  • server/api/registry/badge/[type]/[...pkg].get.ts

Comment on lines +500 to +502
'likes': async (pkgData: globalThis.Packument) => {
const likesUtil = new PackageLikesUtils()
const { totalLikes } = await likesUtil.getLikes(pkgData.name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify symbol usage and import presence for PackageLikesUtils
rg -n "PackageLikesUtils" "server/api/registry/badge/[type]/[...pkg].get.ts" "server/utils/atproto/utils/likes.ts"
rg -n "from '#server/utils/atproto/utils/likes'" "server/api/registry/badge/[type]/[...pkg].get.ts"

Repository: npmx-dev/npmx.dev

Length of output: 344


🏁 Script executed:

#!/bin/bash
# Check all imports in the target file to see the import pattern
head -50 "server/api/registry/badge/[type]/[...pkg].get.ts" | grep -n "^import\|^export"

Repository: npmx-dev/npmx.dev

Length of output: 676


🏁 Script executed:

#!/bin/bash
# Verify the path alias and check if there are any wildcard imports that could provide PackageLikesUtils
rg -n "^import.*from.*atproto" "server/api/registry/badge/[type]/[...pkg].get.ts"

Repository: npmx-dev/npmx.dev

Length of output: 43


🏁 Script executed:

#!/bin/bash
# Verify the proposed import path and check other imports from likes utilities
rg -n "import.*PackageLikesUtils\|from.*likes" "server/utils/atproto/utils/likes.ts"

Repository: npmx-dev/npmx.dev

Length of output: 43


Add missing import for PackageLikesUtils to fix type-checking error.

Line 501 instantiates PackageLikesUtils, but the file does not import it. Add the following import to resolve the unresolved symbol:

 import { handleApiError } from '#server/utils/error-handler'
+import { PackageLikesUtils } from '#server/utils/atproto/utils/likes'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'likes': async (pkgData: globalThis.Packument) => {
const likesUtil = new PackageLikesUtils()
const { totalLikes } = await likesUtil.getLikes(pkgData.name)
import { handleApiError } from '#server/utils/error-handler'
import { PackageLikesUtils } from '#server/utils/atproto/utils/likes'

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/content/2.guide/6.badges.md (1)

31-31: Polish wording for readability.

Consider rephrasing to “Shows the total number of likes for the package” for more natural wording in docs.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eb86405a-ee45-4f31-9b31-0d747a424d41

📥 Commits

Reviewing files that changed from the base of the PR and between a916a98 and 11c42f4.

📒 Files selected for processing (2)
  • docs/content/2.guide/6.badges.md
  • server/api/registry/badge/[type]/[...pkg].get.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/api/registry/badge/[type]/[...pkg].get.ts

Other entries also use similar phrasing as "Lists the total count of
package dependencies.".
To maintain consistency, adopt original phrasing.
const likesUtil = new PackageLikesUtils()
const { totalLikes } = await likesUtil.getLikes(pkgData.name)

return { label: 'likes', value: String(totalLikes ?? 0), color: COLORS.blue }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the default colour should be red? 👀 We could use the same colour that we do on the frontend

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - originally went with blue because of the likes itself are on stored via ATProtocol but red feels nice as well.

Went with the badge-default red

instead of text-red-500 (oklch(63.7% 0.237 25.331) / #fb2c36) which is used for the heart in the LikeCard

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

like counter badge

2 participants