perf(module): swap `fzf` for `fuzzysort` · nuxt/cli@ff0cc23 · GitHub
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

‎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
import type { NuxtModule } from './_utils'
33

44
import { autocompleteMultiselect, isCancel } from '@clack/prompts'
5-
import { byLengthAsc, Fzf } from 'fzf'
5+
import fuzzysort from '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
return a.npm.localeCompare(b.npm)
3636
})
3737

38-
const fzf = new Fzf(sortedModules, {
39-
selector: m => `${m.npm} ${m.name} ${m.category}`,
40-
casing: 'case-insensitive',
41-
tiebreakers: [byLengthAsc],
42-
})
38+
const targets = 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
const clackOptions: Option<string>[] = sortedModules.map(m => ({
4546
value: m.npm,
@@ -53,7 +54,7 @@ export async function selectModulesAutocomplete(options: AutocompleteOptions): P
5354
return true
5455
let results = matches.get(search)
5556
if (!results) {
56-
results = new Set(fzf.find(search).map(r => r.item.npm))
57+
results = new Set(fuzzysort.go(search, targets, { keys: ['npm', 'name', 'category'] }).map(r => r.obj.value))
5758
matches.set(search, results)
5859
}
5960
return results.has(option.value)

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

Lines changed: 14 additions & 15 deletions

‎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)