@@ -105,6 +105,8 @@ impl MoonBitComponent {
105105 info ! ( "Generating MoonBit WIT bindings" ) ;
106106 let mut wit_bindgen = wit_bindgen_moonbit:: Opts {
107107 gen_dir : "gen" . to_string ( ) ,
108+ derive_eq : true ,
109+ derive_show : true ,
108110 ..Default :: default ( )
109111 }
110112 . build ( ) ;
@@ -255,7 +257,7 @@ impl MoonBitComponent {
255257 for ( package_name, interface_name) in & imported_interfaces {
256258 let pkg_namespace = package_name. namespace . to_snake_case ( ) ;
257259 let pkg_name = package_name. name . to_snake_case ( ) ;
258- let interface_name = interface_name. to_snake_case ( ) ;
260+ let interface_name = interface_name. to_lower_camel_case ( ) ;
259261
260262 let name = format ! (
261263 "{moonbit_root_package}/interface/{pkg_namespace}/{pkg_name}/{interface_name}"
@@ -285,7 +287,7 @@ impl MoonBitComponent {
285287 for ( package_name, interface_name) in & exported_interfaces {
286288 let pkg_namespace = package_name. namespace . to_snake_case ( ) ;
287289 let pkg_name = package_name. name . to_snake_case ( ) ;
288- let interface_name = interface_name. to_snake_case ( ) ;
290+ let interface_name = interface_name. to_lower_camel_case ( ) ;
289291
290292 let name = format ! (
291293 "{moonbit_root_package}/gen/interface/{pkg_namespace}/{pkg_name}/{interface_name}"
@@ -343,6 +345,19 @@ impl MoonBitComponent {
343345 Ok ( ( ) )
344346 }
345347
348+ pub fn set_warning_control (
349+ & mut self ,
350+ package_name : & str ,
351+ warning_control : Vec < WarningControl > ,
352+ ) -> anyhow:: Result < ( ) > {
353+ let package = self
354+ . packages
355+ . get_mut ( package_name)
356+ . ok_or_else ( || anyhow:: anyhow!( "Package '{package_name}' not found" ) ) ?;
357+ package. warning_control = warning_control;
358+ Ok ( ( ) )
359+ }
360+
346361 /// Defines a custom MoonBit package
347362 pub fn define_package ( & mut self , package : MoonBitPackage ) {
348363 debug ! ( "Adding MoonBit package: {}" , package. name) ;
@@ -367,6 +382,16 @@ impl MoonBitComponent {
367382 Ok ( ( ) )
368383 }
369384
385+ pub fn write_file ( & self , relative_path : & Utf8Path , contents : & str ) -> anyhow:: Result < ( ) > {
386+ let path = self . dir . join ( relative_path) ;
387+ info ! ( "Writing file: {path:?}" ) ;
388+ if let Some ( parent) = path. parent ( ) {
389+ std:: fs:: create_dir_all ( parent) . context ( "Creating directory for generated file" ) ?;
390+ }
391+ std:: fs:: write ( path, contents) ?;
392+ Ok ( ( ) )
393+ }
394+
370395 /// Writes the top level export stub for the selected world
371396 pub fn write_world_stub ( & self , moonbit_source : & str ) -> anyhow:: Result < ( ) > {
372397 let world_name = self . world_name ( ) ?;
@@ -396,7 +421,7 @@ impl MoonBitComponent {
396421 . join ( "interface" )
397422 . join ( package_namespace_snake)
398423 . join ( package_name_snake)
399- . join ( interface_name. to_snake_case ( ) )
424+ . join ( interface_name. to_lower_camel_case ( ) )
400425 . join ( "stub.mbt" ) ;
401426 info ! ( "Writing interface stub to {path}" ) ;
402427 std:: fs:: create_dir_all ( path. parent ( ) . unwrap ( ) )
@@ -420,7 +445,7 @@ impl MoonBitComponent {
420445 . join ( "interface" )
421446 . join ( package_namespace_snake)
422447 . join ( package_name_snake)
423- . join ( interface_name. to_snake_case ( ) )
448+ . join ( interface_name. to_lower_camel_case ( ) )
424449 . join ( "moon.pkg.json" ) ;
425450 info ! ( "Writing interface definition to {path}" ) ;
426451 std:: fs:: create_dir_all ( path. parent ( ) . unwrap ( ) )
@@ -537,11 +562,7 @@ impl MoonBitComponent {
537562 ) -> anyhow:: Result < ( ) > {
538563 info ! ( "Building MoonBit package: {package}" ) ;
539564
540- let mut args = vec ! [
541- "build-package" . to_string( ) ,
542- "-error-format" . to_string( ) ,
543- "json" . to_string( ) ,
544- ] ;
565+ let mut args = vec ! [ "build-package" . to_string( ) ] ;
545566 for file in mbt_files {
546567 let full_path = self . dir . join ( file) ;
547568 args. push ( full_path. to_string ( ) ) ;
@@ -741,18 +762,34 @@ impl MoonBitComponent {
741762 Ok ( pkg. link . wasm )
742763 }
743764
744- fn moonbit_root_package ( & self ) -> anyhow:: Result < String > {
765+ pub fn moonbit_root_package ( & self ) -> anyhow:: Result < String > {
766+ Ok ( format ! (
767+ "{}/{}" ,
768+ self . root_pkg_namespace( ) ?,
769+ self . root_pkg_name( ) ?
770+ ) )
771+ }
772+
773+ pub fn root_pkg_namespace ( & self ) -> anyhow:: Result < String > {
745774 let root_package_id = self . root_package_id . as_ref ( ) . unwrap ( ) ;
746775 let resolve = self . resolve . as_ref ( ) . unwrap ( ) ;
747776
748777 let root_package = resolve
749778 . packages
750779 . get ( * root_package_id)
751780 . ok_or_else ( || anyhow ! ( "Root package not found" ) ) ?;
752- Ok ( format ! (
753- "{}/{}" ,
754- root_package. name. namespace, root_package. name. name
755- ) )
781+ Ok ( root_package. name . namespace . to_string ( ) )
782+ }
783+
784+ pub fn root_pkg_name ( & self ) -> anyhow:: Result < String > {
785+ let root_package_id = self . root_package_id . as_ref ( ) . unwrap ( ) ;
786+ let resolve = self . resolve . as_ref ( ) . unwrap ( ) ;
787+
788+ let root_package = resolve
789+ . packages
790+ . get ( * root_package_id)
791+ . ok_or_else ( || anyhow ! ( "Root package not found" ) ) ?;
792+ Ok ( root_package. name . name . to_string ( ) )
756793 }
757794
758795 fn world_name ( & self ) -> anyhow:: Result < String > {
0 commit comments