Skip to content

feat: add package dependents list page#2208

Open
thealxlabs wants to merge 7 commits intonpmx-dev:mainfrom
thealxlabs:feat/dependents-page
Open

feat: add package dependents list page#2208
thealxlabs wants to merge 7 commits intonpmx-dev:mainfrom
thealxlabs:feat/dependents-page

Conversation

@thealxlabs
Copy link

@thealxlabs thealxlabs commented Mar 22, 2026

🔗 Linked issue

resolves #1987
resolves #31

🧭 Context

There was no way to browse which packages depend on a given npm package from within npmx.dev. This is a commonly requested feature that npm.js itself surfaces.

📚 Description

  • Added a new /package/:name/dependents page (app/pages/package/[[org]]/[name]/dependents.vue) that lists packages depending on the viewed package, with pagination.
  • Added a server API route (server/api/registry/dependents/[...pkg].get.ts) that queries the npm search API with dependencies:<name> and returns a paginated, simplified package list.
  • Added a "Dependents" tab to the package header navigation (app/components/Package/Header.vue).
  • Also includes: provenance link touch target fix (fix: use jsdelivr's content-type header to detect binary file #2036 a11y header), i18n schema updates for the new package.dependents keys and common.previous/common.next.

A unit test (test/unit/app/server/dependents.spec.ts) verifies the npm search response mapping logic including optional field fallbacks, pagination offset computation, and size capping.

@vercel
Copy link

vercel bot commented Mar 22, 2026

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

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Mar 22, 2026 7:56pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 22, 2026 7:56pm
npmx-lunaria Ignored Ignored Mar 22, 2026 7:56pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

Adds a new "Dependents" page at app/pages/package/[[org]]/[name]/dependents.vue that fetches paginated dependents from a new cached API endpoint server/api/registry/dependents/[...pkg].get.ts (queries the npm registry search API). Extends Package Header (app/components/Package/Header.vue) to accept page = 'dependents' and render a dependents navigation link. Adds i18n schema and English translations for pagination and dependents UI strings. Introduces unit tests for mapping npm search responses and pagination/size logic. Minor UI spacing adjustment for the provenance button icon.

Possibly related PRs

Suggested labels

needs review

Suggested reviewers

  • danielroe
  • alexdln
  • graphieros
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive Issue #2036 requires binary file detection improvements via content-type headers, but changes are not evident in the code. Issue #31 requires sorting dependents by download count, which is not implemented. Verify whether #2036 changes were intended in this PR or deferred. Implement sorting by download count in the dependents API and UI to address #31.
Out of Scope Changes check ❓ Inconclusive The PR includes a provenance link CSS adjustment (py-1.25 to py-1.5) that appears tangential to the core dependents feature and linked issue requirements. Clarify whether the CSS spacing change for the provenance link is a necessary a11y fix for #2036 or should be separated into a distinct commit.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, detailing the new dependents feature, API route, header navigation updates, i18n changes, and unit tests included in the PR.

✏️ 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
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: 4

🧹 Nitpick comments (3)
test/unit/app/server/dependents.spec.ts (1)

92-110: Consider testing the actual API handler instead of duplicating mapping logic.

The tests define a local mapNpmSearchResponse function that mirrors the production code. If the production logic changes, these tests won't catch regressions. Consider importing or invoking the actual handler to ensure tests remain coupled to production behaviour.

app/pages/package/[[org]]/[name]/dependents.vue (2)

166-179: Inconsistent icon placement between pagination buttons.

The "Previous" button uses classicon prop for the icon, whilst the "Next" button uses an inline <span> element. Consider using the same approach for both buttons for consistency.

♻️ Proposed fix for consistent button styling
-        <ButtonBase variant="secondary" :disabled="page >= totalPages - 1" `@click`="nextPage">
+        <ButtonBase
+          variant="secondary"
+          :disabled="page >= totalPages - 1"
+          `@click`="nextPage"
+          icon-position="end"
+        >
           {{ $t('common.next') }}
-          <span class="i-lucide:chevron-right w-4 h-4" aria-hidden="true" />
+          <template `#icon`>
+            <span class="i-lucide:chevron-right" aria-hidden="true" />
+          </template>
         </ButtonBase>

Alternatively, verify if ButtonBase supports classicon with right-side positioning, similar to the left chevron pattern.


84-87: Consider using i18n for SEO metadata.

The SEO title and description use hardcoded English strings. For consistency with other localised content, consider using translation keys, though SEO metadata often intentionally uses specific formats for search engine optimisation.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c79f601-4587-4965-9ff4-0be29bc445fc

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2fc1a and f6f50c0.

📒 Files selected for processing (5)
  • app/components/Package/Header.vue
  • app/pages/package/[[org]]/[name]/dependents.vue
  • i18n/schema.json
  • server/api/registry/dependents/[...pkg].get.ts
  • test/unit/app/server/dependents.spec.ts

Comment on lines +48 to +55
try {
const data = await $fetch<NpmSearchResult>(NPM_SEARCH_BASE, {
query: {
text: `dependencies:${packageName}`,
size,
from,
},
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

npm registry search API sort by popularity or downloads

💡 Result:

Yes, the npm registry provides a search API endpoint that supports sorting by popularity or downloads via weighted scoring factors. The endpoint is GET https://registry.npmjs.org/-/v1/search. Key query parameters for sorting: - text: the search query (required for searching) - size: number of results (default 20, max 250) - from: offset for pagination - quality: weight (0-1) for quality score - popularity: weight (0-1) for popularity score (based on downloads and other metrics) - maintenance: weight (0-1) for maintenance score To sort primarily by popularity, set popularity=1.0&quality=0&maintenance=0. Results are scored as a weighted combination, normalized as a unit vector. Example to get top 10 results for "react" sorted by popularity: curl "https://registry.npmjs.org/-/v1/search?text=react&size=10&popularity=1.0&quality=0&maintenance=0" Each result includes a "score" object with final score and detail breakdown (quality, popularity, maintenance), plus searchScore for text relevance. This is the official public API, actively used by libraries like libnpmsearch (npm/npm/libnpmsearch), which passes these opts directly to the endpoint. Popularity incorporates download stats and other factors. Note: No direct "sort=downloads" parameter; use popularity weighting. For exact download counts, use separate /downloads/point endpoints, but not for search sorting.

Citations:


🏁 Script executed:

# First, locate and examine the file
find . -name "[...pkg].get.ts" -o -name "*dependents*" -type f | head -20

Repository: npmx-dev/npmx.dev

Length of output: 152


🏁 Script executed:

# Let's search for the specific file pattern
fd "dependents.*pkg" --type f

Repository: npmx-dev/npmx.dev

Length of output: 43


🏁 Script executed:

# Search for the file in api registry directory
fd -t f "pkg" server/api/registry/dependents/

Repository: npmx-dev/npmx.dev

Length of output: 107


🏁 Script executed:

# Try a broader search
git ls-files | grep -i dependents

Repository: npmx-dev/npmx.dev

Length of output: 195


🏁 Script executed:

cat -n server/api/registry/dependents/\[...\pkg\].get.ts

Repository: npmx-dev/npmx.dev

Length of output: 2768


Add popularity weighting to npm search query to sort dependents by download count.

The current implementation passes only text, size, and from parameters to the npm search API, which returns results sorted by relevance. PR objective #31 requires sorting by download count. The npm search API supports popularity weighting via the popularity parameter (0–1 scale, based on downloads). To prioritise downloads, add popularity: 1.0, quality: 0, maintenance: 0 to the query object (lines 50–54).

Comment on lines +81 to +84
getKey: event => {
const pkg = getRouterParam(event, 'pkg') ?? ''
const query = getQuery(event)
return `dependents:v1:${pkg}:p${query.page ?? 0}:s${query.size ?? 20}`
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Cache key may not match decoded package name.

The cache key uses the raw route param getRouterParam(event, 'pkg'), but the handler decodes the package name with decodeURIComponent(rawName) on line 37. For URL-encoded package names (e.g., %40scope%2Fpkg), the cache key and actual query could diverge, causing unnecessary cache misses or stale entries.

🔧 Proposed fix to use decoded package name in cache key
   getKey: event => {
     const pkg = getRouterParam(event, 'pkg') ?? ''
+    const decodedPkg = decodeURIComponent(pkg)
     const query = getQuery(event)
-    return `dependents:v1:${pkg}:p${query.page ?? 0}:s${query.size ?? 20}`
+    return `dependents:v1:${decodedPkg}:p${query.page ?? 0}:s${query.size ?? 20}`
   },
📝 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
getKey: event => {
const pkg = getRouterParam(event, 'pkg') ?? ''
const query = getQuery(event)
return `dependents:v1:${pkg}:p${query.page ?? 0}:s${query.size ?? 20}`
getKey: event => {
const pkg = getRouterParam(event, 'pkg') ?? ''
const decodedPkg = decodeURIComponent(pkg)
const query = getQuery(event)
return `dependents:v1:${decodedPkg}:p${query.page ?? 0}:s${query.size ?? 20}`
},

@github-actions
Copy link

github-actions bot commented Mar 22, 2026

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
i18n/locales/en.json Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/components/Package/Header.vue 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@howwohmm howwohmm left a comment

Choose a reason for hiding this comment

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

good feature — fills a real gap. a few issues from the full diff:

  1. silent error masking in the API route. the catch block (line ~72) returns { total: 0, packages: [] } for all errors — 429 rate limits, 500s, network timeouts all become "no dependents found." the client error state will never trigger since useLazyFetch sees a valid 200. the user sees the empty state instead of an error. consider re-throwing non-404 errors so the client can surface the error state.

  2. displayVersion type mismatch. in dependents.vue, you pass pkg.value?.requestedVersion (a string) as display-version, but PackageHeader types it as PackumentVersion | null. this will cause a TS error and runtime issues if the header accesses .funding or other version object fields.

  3. npm search total is an estimate. for popular packages, the real dependent count is often 10-100x higher than what npm search returns. consider adding "(approximate)" next to the count, or noting the data source.

  4. tests re-implement the mapping logic rather than importing the actual handler. if the server logic diverges, the tests won't catch it. the timeline PR (#2245) imports the handler directly — worth aligning.

the provenance touch target fix (py-1.25py-1.5) is unrelated — might be cleaner as a separate commit.

Copy link
Contributor

@howwohmm howwohmm left a comment

Choose a reason for hiding this comment

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

correction on point 2 from my earlier review — requestedVersion is typed as SlimPackumentVersion | null (which extends PackumentVersion), not a string. so the displayVersion prop is type-safe. apologies for the false flag.

points 1 (silent error masking in the API route), 3 (npm search total is approximate), and 4 (tests re-implementing mapping logic) still hold.

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.

sort dependents by download count Add package dependents/dependees list to package detail view

2 participants