Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 package likes. :img{src="https://img.shields.io/badge/%23ef4444-ef4444" 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.red }
},
}

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