@@ -79,41 +79,46 @@ impl FileSystemPackageResolver {
7979 // First check to see if a directory exists.
8080 // If so, then treat it as a textual WIT package.
8181 #[ cfg( feature = "wit" ) ]
82- if path . is_dir ( ) {
83- log :: debug! (
84- "loading WIT package from directory `{path}`" ,
85- path = path . display ( )
86- ) ;
87-
82+ {
83+ let pkg_res_failure = |e| Error :: PackageResolutionFailure {
84+ name : key . name . to_string ( ) ,
85+ span : * span ,
86+ source : e ,
87+ } ;
8888 let mut resolve = wit_parser:: Resolve :: new ( ) ;
89- let ( pkg, _) =
90- resolve
91- . push_dir ( & path)
92- . map_err ( |e| Error :: PackageResolutionFailure {
93- name : key. name . to_string ( ) ,
94- span : * span,
95- source : e,
96- } ) ?;
97-
98- packages. insert (
99- * key,
100- Arc :: new (
101- wit_component:: encode ( Some ( true ) , & resolve, pkg)
102- . with_context ( || {
103- format ! (
104- "failed to encode WIT package from directory `{path}`" ,
105- path = path. display( )
106- )
107- } )
108- . map_err ( |e| Error :: PackageResolutionFailure {
109- name : key. name . to_string ( ) ,
110- span : * span,
111- source : e,
112- } ) ?,
113- ) ,
114- ) ;
115-
116- continue ;
89+ let pkg = if path. is_dir ( ) {
90+ log:: debug!(
91+ "loading WIT package from directory `{path}`" ,
92+ path = path. display( )
93+ ) ;
94+
95+ let ( pkg, _) = resolve. push_dir ( & path) . map_err ( pkg_res_failure) ?;
96+ Some ( pkg)
97+ } else if path. extension ( ) . and_then ( std:: ffi:: OsStr :: to_str) == Some ( "wit" ) {
98+ let unresolved = wit_parser:: UnresolvedPackage :: parse_file ( & path)
99+ . map_err ( pkg_res_failure) ?;
100+ let pkg = resolve. push ( unresolved) . map_err ( pkg_res_failure) ?;
101+ Some ( pkg)
102+ } else {
103+ None
104+ } ;
105+ if let Some ( pkg) = pkg {
106+ packages. insert (
107+ * key,
108+ Arc :: new (
109+ wit_component:: encode ( Some ( true ) , & resolve, pkg)
110+ . with_context ( || {
111+ format ! (
112+ "failed to encode WIT package from `{path}`" ,
113+ path = path. display( )
114+ )
115+ } )
116+ . map_err ( pkg_res_failure) ?,
117+ ) ,
118+ ) ;
119+
120+ continue ;
121+ }
117122 }
118123
119124 if !path. is_file ( ) {
0 commit comments