Skip to content

Commit 538a5fe

Browse files
committed
feat: support pkg@version format in search
Searching for `esbuild@0.25.12` or `@angular/core@^18` and pressing Enter now navigates directly to the package version page (or semver filter for ranges) instead of returning no results. Since in the previous commit I added support for linking to the package page with the a pre-filled semver version specifier in the query string to populate the version filter, this supports both exact versions and semver ranges in the search input. Closes #1416
1 parent a45ad65 commit 538a5fe

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

app/pages/search.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@ function focusElement(el: HTMLElement) {
441441
el.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
442442
}
443443
444+
// Parse "pkg@version" from search input (e.g. "esbuild@0.25.12", "@angular/core@^18")
445+
function parsePackageAtVersion(input: string): { name: string; version?: string } {
446+
const atIndex = input.startsWith('@') ? input.indexOf('@', 1) : input.indexOf('@')
447+
if (atIndex > 0) {
448+
const version = input.slice(atIndex + 1)
449+
if (version) return { name: input.slice(0, atIndex), version }
450+
}
451+
return { name: input }
452+
}
453+
444454
// Navigate to package page
445455
async function navigateToPackage(packageName: string) {
446456
await navigateTo(packageRoute(packageName))
@@ -494,6 +504,12 @@ function handleResultsKeydown(e: KeyboardEvent) {
494504
const inputValue = (document.activeElement as HTMLInputElement).value.trim()
495505
if (!inputValue) return
496506
507+
// Handle "pkg@version" format (e.g. "esbuild@0.25.12", "@angular/core@^18")
508+
const { name, version } = parsePackageAtVersion(inputValue)
509+
if (version) {
510+
return navigateTo(packageRoute(name, version))
511+
}
512+
497513
// When instantSearch is off, commit the query so search starts
498514
committedQuery.value = inputValue
499515

0 commit comments

Comments
 (0)