Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/2.guide/6.badges.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ npmx.dev offers many different SVG badges with stats about any package via its A
- **maintainers**: Displays the total count of package maintainers. :img{src="https://img.shields.io/badge/%2306b6d4-06b6d4" class="inline align-middle h-5 w-14"}
- **deprecated**: Shows if the package is active or deprecated. :img{src="https://img.shields.io/badge/%2322c55e-22c55e" class="inline align-middle h-5 w-14"} / :img{src="https://img.shields.io/badge/%23ef4444-ef4444" class="inline align-middle h-5 w-14"}
- **name**: Simple badge displaying the package name. :img{src="https://img.shields.io/badge/%2364748b-64748b" class="inline align-middle h-5 w-14"}
- **likes**: Shows the total count of likes of the package. :img{src="https://img.shields.io/badge/%233b82f6-3b82f6" class="inline align-middle h-5 w-14"}

## Examples

Expand Down
1 change: 1 addition & 0 deletions docs/shared/utils/badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const BADGE_TYPES = Object.freeze([
'maintainers',
'deprecated',
'name',
'likes',
] as const)

export type BadgeType = (typeof BADGE_TYPES)[number]
Expand Down
7 changes: 7 additions & 0 deletions server/api/registry/badge/[type]/[...pkg].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ const badgeStrategies = {
color: isDeprecated ? COLORS.red : COLORS.green,
}
},

'likes': async (pkgData: globalThis.Packument) => {
const likesUtil = new PackageLikesUtils()
const { totalLikes } = await likesUtil.getLikes(pkgData.name)
Comment on lines +500 to +502
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'


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

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.

The only reason I suggested the frontend one was an attempt at distinguishing from other badges that use red to indicate a failure - but I think we could change this in a follow up if necessary

},
}

const BadgeTypeSchema = v.picklist(Object.keys(badgeStrategies) as [string, ...string[]])
Expand Down
Loading