Skip to content

Commit ff0cc23

Browse files
committed
perf(module): swap fzf for fuzzysort
1 parent 0673103 commit ff0cc23

4 files changed

Lines changed: 30 additions & 30 deletions

File tree

‎packages/nuxt-cli/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"consola": "^3.4.2",
6868
"defu": "^6.1.7",
6969
"exsolve": "^1.1.1",
70-
"fzf": "^0.5.2",
70+
"fuzzysort": "^3.1.0",
7171
"get-port-please": "^3.2.0",
7272
"nypm": "^0.6.9",
7373
"obug": "^2.1.4",

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Option } from '@clack/prompts'
22
importtype{NuxtModule}from'./_utils'
33

44
import{autocompleteMultiselect,isCancel}from'@clack/prompts'
5-
import{byLengthAsc,Fzf}from'fzf'
5+
importfuzzysortfrom'fuzzysort'
66
import{hasTTY}from'std-env'
77

88
import{logger}from'../../utils/logger'
@@ -35,11 +35,12 @@ export async function selectModulesAutocomplete(options: AutocompleteOptions): P
3535
returna.npm.localeCompare(b.npm)
3636
})
3737

38-
constfzf=newFzf(sortedModules,{
39-
selector: m=>`${m.npm}${m.name}${m.category}`,
40-
casing: 'case-insensitive',
41-
tiebreakers: [byLengthAsc],
42-
})
38+
consttargets=sortedModules.map(m=>({
39+
value: m.npm,
40+
npm: fuzzysort.prepare(m.npm),
41+
name: fuzzysort.prepare(m.name),
42+
category: fuzzysort.prepare(m.category),
43+
}))
4344

4445
constclackOptions: Option<string>[]=sortedModules.map(m=>({
4546
value: m.npm,
@@ -53,7 +54,7 @@ export async function selectModulesAutocomplete(options: AutocompleteOptions): P
5354
returntrue
5455
letresults=matches.get(search)
5556
if(!results){
56-
results=newSet(fzf.find(search).map(r=>r.item.npm))
57+
results=newSet(fuzzysort.go(search,targets,{keys: ['npm','name','category']}).map(r=>r.obj.value))
5758
matches.set(search,results)
5859
}
5960
returnresults.has(option.value)

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import process from 'node:process'
33
import{styleText}from'node:util'
44
import{box}from'@clack/prompts'
55
import{defineCommand}from'citty'
6-
import{byLengthAsc,Fzf}from'fzf'
6+
importfuzzysortfrom'fuzzysort'
77
import{kebabCase,upperFirst}from'scule'
88

99
import{formatInfoBox}from'../../utils/formatting'
@@ -64,21 +64,20 @@ async function findModuleByKeywords(query: string, nuxtVersion: string) {
6464
constcompatibleModules=allModules.filter(m=>
6565
checkNuxtCompatibility(m,nuxtVersion),
6666
)
67-
constfzf=newFzf(compatibleModules,{
68-
selector: m=>[
69-
m.name,
70-
m.npm,
71-
m.repo,
72-
m.tags?.join(' '),
73-
m.category,
74-
m.description,
75-
m.maintainers.map(maintainer=>`${maintainer.name}${maintainer.github}`).join(' '),
76-
].filter(Boolean).join(' '),
77-
casing: 'case-insensitive',
78-
tiebreakers: [byLengthAsc],
79-
})
67+
consttargets=compatibleModules.map(item=>({
68+
item,
69+
name: fuzzysort.prepare(item.name),
70+
npm: fuzzysort.prepare(item.npm),
71+
rest: fuzzysort.prepare([
72+
item.repo,
73+
item.tags?.join(' '),
74+
item.category,
75+
item.description,
76+
item.maintainers.map(maintainer=>`${maintainer.name}${maintainer.github}`).join(' '),
77+
].filter(Boolean).join(' ')),
78+
}))
8079

81-
constresults=fzf.find(query).map(({ item })=>{
80+
constresults=fuzzysort.go(query,targets,{keys: ['name','npm','rest'],all: !query}).map(({obj: {item}})=>{
8281
constres: Record<string,string>={
8382
name: item.name,
8483
package: item.npm,

‎pnpm-lock.yaml‎

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

0 commit comments

Comments
 (0)