import { Rule , Oracle } from "@siteimprove/alfa-act" ; import { Result , Err } from "@siteimprove/alfa-result" ; public export type Interviewer < I = unknown , T = unknown , Q = never , S = T > = ( input : I , rules : Iterable < Rule < I , T , Q , S > > ) => Oracle < I , T , Q , S > ; public export namespace Interviewer { export async function load < I , T = unknown , Q = never , S = T > ( name , defaultScope = "@siteimprove" ) { let scope ; if ( name . startsWith ( "@" ) ) { const match = name . match ( /^(@[^/]+)\/(.+)$/ ) ; if ( match !== null ) { scope = match [ 1 ] ; name = match [ 2 ] ; } } const patterns = [ ... candidates ( name , scope ) ] ; if ( scope === undefined ) { patterns . push ( ... candidates ( name , defaultScope ) ) ; try { const path = await import ( "path" ) ; patterns . push ( path . resolve ( name ) ) ; } catch { } } for ( const pattern of patterns ) { try { const module = await import ( pattern ) ; return Result . of ( module . default ( ) ) ; } catch { continue ; } } return Err . of ( `No interviewer named "${ name }" was found at:\n\n${ patterns . map ( ( pattern ) => "  " + pattern ) . join ( "\n" ) }` ) ; } } const prefix = "alfa-interviewer-" ; function * candidates ( name , scope ? ) { scope = scope === undefined ? "" : scope + "/" ; if ( ! name . startsWith ( prefix ) ) { yield scope + prefix + name ; } yield scope + name ; }