Skip to content

Commit 297bf24

Browse files
committed
refactor(module): search with fzf instead of fuse.js
1 parent 4582c22 commit 297bf24

3 files changed

Lines changed: 25 additions & 35 deletions

File tree

‎packages/nuxt-cli/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"consola": "^3.4.2",
5454
"defu": "^6.1.7",
5555
"exsolve": "^1.1.0",
56-
"fuse.js": "^7.4.2",
5756
"fzf": "^0.5.2",
5857
"get-port-please": "^3.2.0",
5958
"giget": "^3.3.0",

‎packages/nuxt-cli/src/commands/module/search.ts‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process'
22

33
import{box}from'@clack/prompts'
44
import{defineCommand}from'citty'
5-
importFusefrom'fuse.js'
5+
import{byLengthAsc,Fzf}from'fzf'
66
importcolorsfrom'picocolors'
77
import{kebabCase,upperFirst}from'scule'
88

@@ -54,36 +54,36 @@ async function findModuleByKeywords(query: string, nuxtVersion: string) {
5454
constcompatibleModules=allModules.filter(m=>
5555
checkNuxtCompatibility(m,nuxtVersion),
5656
)
57-
constfuse=newFuse(compatibleModules,{
58-
threshold: 0.1,
59-
keys: [
60-
{name: 'name',weight: 1},
61-
{name: 'npm',weight: 1},
62-
{name: 'repo',weight: 1},
63-
{name: 'tags',weight: 1},
64-
{name: 'category',weight: 1},
65-
{name: 'description',weight: 0.5},
66-
{name: 'maintainers.name',weight: 0.5},
67-
{name: 'maintainers.github',weight: 0.5},
68-
],
57+
constfzf=newFzf(compatibleModules,{
58+
selector: m=>[
59+
m.name,
60+
m.npm,
61+
m.repo,
62+
m.tags?.join(' '),
63+
m.category,
64+
m.description,
65+
m.maintainers.map(maintainer=>`${maintainer.name}${maintainer.github}`).join(' '),
66+
].filter(Boolean).join(' '),
67+
casing: 'case-insensitive',
68+
tiebreakers: [byLengthAsc],
6969
})
7070

71-
constresults=fuse.search(query).map((result)=>{
71+
constresults=fzf.find(query).map(({ item })=>{
7272
constres: Record<string,string>={
73-
name: result.item.name,
74-
package: result.item.npm,
75-
homepage: colors.cyan(result.item.website),
76-
compatibility: `nuxt: ${result.item.compatibility?.nuxt||'*'}`,
77-
repository: result.item.github,
78-
description: result.item.description,
79-
install: `npx nuxt add ${result.item.name}`,
80-
stars: colors.yellow(formatNumber(result.item.stats.stars)),
81-
monthlyDownloads: colors.yellow(formatNumber(result.item.stats.downloads)),
73+
name: item.name,
74+
package: item.npm,
75+
homepage: colors.cyan(item.website),
76+
compatibility: `nuxt: ${item.compatibility?.nuxt||'*'}`,
77+
repository: item.github,
78+
description: item.description,
79+
install: `npx nuxt add ${item.name}`,
80+
stars: colors.yellow(formatNumber(item.stats.stars)),
81+
monthlyDownloads: colors.yellow(formatNumber(item.stats.downloads)),
8282
}
83-
if(result.item.github===result.item.website){
83+
if(item.github===item.website){
8484
deleteres.homepage
8585
}
86-
if(result.item.name===result.item.npm){
86+
if(item.name===item.npm){
8787
deleteres.packageName
8888
}
8989
returnres

‎pnpm-lock.yaml‎

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)