File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,6 +161,27 @@ export default function usePantry() {
161161 }
162162 }
163163
164+ /// finds a project that matches the input string on either name, display-name or FQD project name
165+ /// - Returns: Project[] since there may by multiple matches, if you want a single match you should use `project()`
166+ async function find ( name : string ) {
167+ //TODO not very performant due to serial awaits
168+ const rv : ReturnType < typeof project > [ ] = [ ]
169+ for await ( const pkg of ls ( ) ) {
170+ const proj = project ( pkg . project )
171+ if ( pkg . project == name ) {
172+ rv . push ( proj )
173+ continue
174+ }
175+ const yaml = await proj . yaml ( )
176+ if ( yaml [ "display-name" ] == name ) {
177+ rv . push ( proj )
178+ } else if ( ( await proj . provides ( ) ) . includes ( name ) ) {
179+ rv . push ( proj )
180+ }
181+ }
182+ return rv
183+ }
184+
164185 async function which ( { interprets : extension } : { interprets : string } ) : Promise < Interpreter | undefined > {
165186 if ( extension [ 0 ] == '.' ) extension = extension . slice ( 1 )
166187 if ( ! extension ) return
@@ -205,6 +226,7 @@ export default function usePantry() {
205226 which,
206227 ls,
207228 project,
229+ find,
208230 parse_pkgs_node,
209231 expand_env_obj,
210232 missing,
You can’t perform that action at this time.
0 commit comments