Skip to content

Comments

feat: strip version info from the search query#1626

Open
Codefoxdev wants to merge 3 commits intonpmx-dev:mainfrom
Codefoxdev:feat/searchquery-version-stripping
Open

feat: strip version info from the search query#1626
Codefoxdev wants to merge 3 commits intonpmx-dev:mainfrom
Codefoxdev:feat/searchquery-version-stripping

Conversation

@Codefoxdev
Copy link

🔗 Linked issue

Partially addresses #1416

🧭 Context

Currently, when searching for a package along with version info (e.g. when copying a package name from the output of a package manager) it just returns random results, instead of useful ones. (e.g. https://npmx.dev/search?q=nuxt@3.4.1)

This pr strips the version info from the query to improve search results.

📚 Description

This pr implements a new regex query to extract essential date from the search query on the search page, such as package scope (which replaces an existing method), package specifier and (optionally) version info. The query is then reconstructed without version info to support the existing search api. It can currently parse a package name in the following format:

@scope/specifier@version

An object containing the separate parts of the query is exposed as the parsedQuery ref and it is able to be used for other features. (Such as implementing the other part of the linked issue)

@vercel
Copy link

vercel bot commented Feb 24, 2026

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

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

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c32e845 and 123a992.

📒 Files selected for processing (1)
  • app/pages/search.vue
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/pages/search.vue

📝 Walkthrough

Walkthrough

The search page component adds a new parsedQuery computed that parses the raw query into scope, name, version and a strippedQuery. packageScope and strippedQuery are now derived from parsedQuery. The search input now uses strippedQuery instead of the full raw query. The no-results message was updated to display strippedQuery. The previous inline extraction of packageScope from the raw query was removed and replaced by the centralized parsing logic.

Suggested reviewers

  • ghostdevv
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining why version info stripping is needed and detailing the regex-based parser implementation for extracting package scope, specifier, and version information.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

🧹 Nitpick comments (2)
app/pages/search.vue (2)

36-55: Tighten scope parsing and normalise trailing whitespace.

The current regex allows whitespace inside the captured scope and strippedQuery can insert double spaces when trailing already starts with one. Tightening the character classes and trimming the trailing chunk keeps scopes valid and avoids noisy search strings.

Suggested update
-  const match = q.match(/^(?:@([^/]+)\/)?([^/@ ]+)(?:@([^ ]*))?(.*)/)
+  const match = q.match(/^(?:@([^/\s]+)\/)?([^/@\s]+)(?:@([^\s]*))?(.*)/)
...
-  const strippedQuery = `${name} ${trailing ?? ''}`.trim()
+  const strippedQuery = `${name}${trailing ? ` ${trailing.trimStart()}` : ''}`.trim()

216-216: Keep exact‑match handling aligned with the stripped search term.

Now that search uses strippedQuery, versioned inputs like nuxt@3.4.1 will fetch results for nuxt, but exact‑match boosting/highlighting and claim/availability checks still compare against the raw query. Consider switching those comparisons to parsedQuery.value.name (or strippedQuery) so the UI behaviour matches the search term.


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c52d259 and c32e845.

📒 Files selected for processing (1)
  • app/pages/search.vue

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

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.

1 participant