@@ -2,7 +2,7 @@ import process from 'node:process'
22
33import { box } from '@clack/prompts'
44import { defineCommand } from 'citty'
5- import Fuse from 'fuse.js '
5+ import { byLengthAsc , Fzf } from 'fzf '
66import colors from 'picocolors'
77import { kebabCase , upperFirst } from 'scule'
88
@@ -54,36 +54,36 @@ async function findModuleByKeywords(query: string, nuxtVersion: string) {
5454 const compatibleModules = allModules . filter ( m =>
5555 checkNuxtCompatibility ( m , nuxtVersion ) ,
5656 )
57- const fuse = new Fuse ( 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+ const fzf = new Fzf ( 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- const results = fuse . search ( query ) . map ( ( result ) => {
71+ const results = fzf . find ( query ) . map ( ( { item } ) => {
7272 const res : 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 delete res . homepage
8585 }
86- if ( result . item . name === result . item . npm ) {
86+ if ( item . name === item . npm ) {
8787 delete res . packageName
8888 }
8989 return res
0 commit comments