feat: strip version info from the search query#1626
feat: strip version info from the search query#1626Codefoxdev wants to merge 3 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe search page component adds a new Suggested reviewers
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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
strippedQuerycan insert double spaces whentrailingalready 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 likenuxt@3.4.1will fetch results fornuxt, but exact‑match boosting/highlighting and claim/availability checks still compare against the rawquery. Consider switching those comparisons toparsedQuery.value.name(orstrippedQuery) so the UI behaviour matches the search term.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🔗 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:
An object containing the separate parts of the query is exposed as the
parsedQueryref and it is able to be used for other features. (Such as implementing the other part of the linked issue)