-
-
Notifications
You must be signed in to change notification settings - Fork 432
feat: route pkg@version from deps, direct nav, and search for any valid specifier
#1723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
serhalp
wants to merge
5
commits into
main
Choose a base branch
from
serhalp/fix-version-sorting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a45ad65
fix: route dependency version ranges to pkg page with semver filter i…
serhalp 538a5fe
feat: support `pkg@version` format in search
serhalp db110a6
refactor: extract parsePackageSpecifier as a shared util
serhalp d6a0372
test: add e2e test for package@version search navigation
serhalp dffa4f2
docs: document the new version features
serhalp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import process from 'node:process' | ||
| import type { CachedFetchResult } from '#shared/utils/fetch-cache-config' | ||
| import { parsePackageSpecifier } from '#shared/utils/parse-package-param' | ||
| import { createFetch } from 'ofetch' | ||
|
|
||
| /** | ||
|
|
@@ -65,42 +66,6 @@ function getFixturePath(type: FixtureType, name: string): string { | |
| return `${dir}:${filename.replace(/\//g, ':')}` | ||
| } | ||
|
|
||
| /** | ||
| * Parse a scoped package name with optional version. | ||
| * Handles formats like: @scope/name, @scope/name@version, name, name@version | ||
| */ | ||
| function parseScopedPackageWithVersion(input: string): { name: string; version?: string } { | ||
| if (input.startsWith('@')) { | ||
| // Scoped package: @scope/name or @scope/name@version | ||
| const slashIndex = input.indexOf('/') | ||
| if (slashIndex === -1) { | ||
| // Invalid format like just "@scope" | ||
| return { name: input } | ||
| } | ||
| const afterSlash = input.slice(slashIndex + 1) | ||
| const atIndex = afterSlash.indexOf('@') | ||
| if (atIndex === -1) { | ||
| // @scope/name (no version) | ||
| return { name: input } | ||
| } | ||
| // @scope/name@version | ||
| return { | ||
| name: input.slice(0, slashIndex + 1 + atIndex), | ||
| version: afterSlash.slice(atIndex + 1), | ||
| } | ||
| } | ||
|
|
||
| // Unscoped package: name or name@version | ||
| const atIndex = input.indexOf('@') | ||
| if (atIndex === -1) { | ||
| return { name: input } | ||
| } | ||
| return { | ||
| name: input.slice(0, atIndex), | ||
| version: input.slice(atIndex + 1), | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
-68
to
-103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this intentional? 👀 CI seems to be failing now |
||
| function getMockForUrl(url: string): MockResult | null { | ||
| const urlObj = URL.parse(url) | ||
| if (!urlObj) return null | ||
|
|
@@ -137,6 +102,56 @@ function getMockForUrl(url: string): MockResult | null { | |
| } | ||
| } | ||
|
|
||
| // npms.io API - return mock package score data | ||
| if (host === 'api.npms.io') { | ||
| const packageMatch = decodeURIComponent(pathname).match(/^\/v2\/package\/(.+)$/) | ||
| if (packageMatch?.[1]) { | ||
| return { | ||
| data: { | ||
| analyzedAt: new Date().toISOString(), | ||
| collected: { | ||
| metadata: { name: packageMatch[1] }, | ||
| }, | ||
| score: { | ||
| final: 0.75, | ||
| detail: { | ||
| quality: 0.8, | ||
| popularity: 0.7, | ||
| maintenance: 0.75, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // jsdelivr CDN - return 404 for README files, etc. | ||
| if (host === 'cdn.jsdelivr.net') { | ||
| // Return null data which will cause a 404 - README files are optional | ||
| return { data: null } | ||
| } | ||
|
|
||
| // jsdelivr data API - return mock file listing | ||
| if (host === 'data.jsdelivr.com') { | ||
| const packageMatch = decodeURIComponent(pathname).match(/^\/v1\/packages\/npm\/(.+)$/) | ||
| if (packageMatch?.[1]) { | ||
| const pkgWithVersion = packageMatch[1] | ||
| const parsed = parsePackageSpecifier(pkgWithVersion) | ||
| return { | ||
| data: { | ||
| type: 'npm', | ||
| name: parsed.name, | ||
| version: parsed.version || 'latest', | ||
| files: [ | ||
| { name: 'package.json', hash: 'abc123', size: 1000 }, | ||
| { name: 'index.js', hash: 'def456', size: 500 }, | ||
| { name: 'README.md', hash: 'ghi789', size: 2000 }, | ||
| ], | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Gravatar API - return 404 (avatars not needed in tests) | ||
| if (host === 'www.gravatar.com') { | ||
| return { data: null } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { expect, test } from './test-utils' | ||
|
|
||
| test.describe('Search pkg@version navigation', () => { | ||
| test('esbuild@0.25.12 → navigates to exact version page', async ({ page, goto }) => { | ||
| await goto('/search', { waitUntil: 'hydration' }) | ||
|
|
||
| const searchInput = page.locator('input[type="search"]') | ||
| await searchInput.fill('esbuild@0.25.12') | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| await expect(page).toHaveURL(/\/package\/esbuild\/v\/0\.25\.12/) | ||
| }) | ||
|
|
||
| test('@angular/core@18.0.0 → navigates to scoped exact version page', async ({ page, goto }) => { | ||
| await goto('/search', { waitUntil: 'hydration' }) | ||
|
|
||
| const searchInput = page.locator('input[type="search"]') | ||
| await searchInput.fill('@angular/core@18.0.0') | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| await expect(page).toHaveURL(/\/package\/@angular\/core\/v\/18\.0\.0/) | ||
| }) | ||
|
|
||
| test('react@^18.0.0 → navigates to package page with semver filter', async ({ page, goto }) => { | ||
| await goto('/search', { waitUntil: 'hydration' }) | ||
|
|
||
| const searchInput = page.locator('input[type="search"]') | ||
| await searchInput.fill('react@^18.0.0') | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| await expect(page).toHaveURL(/\/package\/react\?semver=/) | ||
| await expect(page).toHaveURL(/#versions/) | ||
| }) | ||
|
|
||
| test('@angular/core@^18 || ^19 → navigates to package page with semver filter', async ({ | ||
| page, | ||
| goto, | ||
| }) => { | ||
| await goto('/search', { waitUntil: 'hydration' }) | ||
|
|
||
| const searchInput = page.locator('input[type="search"]') | ||
| await searchInput.fill('@angular/core@^18 || ^19') | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| await expect(page).toHaveURL(/\/package\/@angular\/core\?semver=/) | ||
| await expect(page).toHaveURL(/#versions/) | ||
| }) | ||
|
|
||
| test('nuxt@latest → navigates to package page with semver filter for dist-tag', async ({ | ||
| page, | ||
| goto, | ||
| }) => { | ||
| await goto('/search', { waitUntil: 'hydration' }) | ||
|
|
||
| const searchInput = page.locator('input[type="search"]') | ||
| await searchInput.fill('nuxt@latest') | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| await expect(page).toHaveURL(/\/package\/nuxt\?semver=latest/) | ||
| await expect(page).toHaveURL(/#versions/) | ||
| }) | ||
|
|
||
| test('plain package name without @ version → does not trigger version navigation', async ({ | ||
| page, | ||
| goto, | ||
| }) => { | ||
| await goto('/search?q=vue', { waitUntil: 'hydration' }) | ||
|
|
||
| // Wait for search results to load | ||
| await expect(page.locator('text=/found \\d+|showing \\d+/i').first()).toBeVisible({ | ||
| timeout: 15000, | ||
| }) | ||
|
|
||
| const searchInput = page.locator('input[type="search"]') | ||
| await searchInput.focus() | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| // Should navigate to the package page (exact match), not a version page | ||
| await expect(page).toHaveURL(/\/package\/vue$/) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 163
🏁 Script executed:
cat -n app/components/Package/Versions.vue | head -150Repository: npmx-dev/npmx.dev
Length of output: 5561
🏁 Script executed:
rg -n 'watch\(|onBeforeRouteUpdate' app/components/Package/Versions.vueRepository: npmx-dev/npmx.dev
Length of output: 188
🏁 Script executed:
rg -n 'Versions\.vue\|<Versions' app/pages/ -A 3Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 344
🏁 Script executed:
rg -n '<Versions' app/ -B 2 -A 2Repository: npmx-dev/npmx.dev
Length of output: 587
🏁 Script executed:
fd -name '\[name\].vue' app/pages/package/Repository: npmx-dev/npmx.dev
Length of output: 291
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 103
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 6760
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 106
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 221
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 271
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 292
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 2760
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 718
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1041
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 10420
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 8047
🏁 Script executed:
cat -n app/components/Package/Versions.vue | tail -50Repository: npmx-dev/npmx.dev
Length of output: 1819
🏁 Script executed:
rg -n 'onBeforeRouteUpdate\|watch.*route' app/components/Package/Versions.vueRepository: npmx-dev/npmx.dev
Length of output: 43
Watch
route.query.semverto sync filter state on navigation.The
semverFilteris initialised once at component setup fromroute.query.semver. Without a watcher on the route parameter, internal navigation (e.g., from/package/foo?semver=^1to/package/foo?semver=^2) won't update the filter because the component instance reuses without unmounting. Add a watcher onroute.query.semverto keep the filter in sync with URL changes.