@@ -523,10 +523,14 @@ pub fn compiler_args(
523523) -> Result < Vec < String > > {
524524 let bsc_flags = config:: flatten_flags ( & config. compiler_flags ) ;
525525 let dependency_paths = get_dependency_paths ( config, project_context, packages, is_type_dev) ;
526- let module_name = helpers:: file_path_to_module_name ( file_path, & config. get_namespace ( ) ) ;
526+ let multi_entry = config. is_multi_entry_enabled ( ) ;
527+ let module_name =
528+ helpers:: file_path_to_constructible_module_name ( file_path, & config. get_namespace ( ) , multi_entry) ;
527529
528530 let namespace_args = match & config. get_namespace ( ) {
529- packages:: Namespace :: NamespaceWithEntry { namespace : _, entry } if & module_name == entry => {
531+ packages:: Namespace :: NamespaceWithEntry { namespace : _, entry }
532+ if module_name. as_ref ( ) == Some ( entry) =>
533+ {
530534 // if the module is the entry we just want to open the namespace
531535 vec ! [
532536 "-open" . to_string( ) ,
@@ -567,12 +571,23 @@ pub fn compiler_args(
567571 } ;
568572
569573 let package_name_arg = vec ! [ "-bs-package-name" . to_string( ) , config. name. to_owned( ) ] ;
574+ let multi_entry_arg = if multi_entry {
575+ vec ! [ "-bs-multi-entry" . to_string( ) ]
576+ } else {
577+ vec ! [ ]
578+ } ;
570579
571580 let implementation_args = if is_interface {
572- debug ! ( "Compiling interface file: {}" , & module_name) ;
581+ debug ! (
582+ "Compiling interface file: {}" ,
583+ module_name. as_deref( ) . unwrap_or( "<private file module>" )
584+ ) ;
573585 vec ! [ ]
574586 } else {
575- debug ! ( "Compiling file: {}" , & module_name) ;
587+ debug ! (
588+ "Compiling file: {}" ,
589+ module_name. as_deref( ) . unwrap_or( "<private file module>" )
590+ ) ;
576591 let specs = root_config. get_package_specs ( ) ;
577592
578593 specs
@@ -621,6 +636,7 @@ pub fn compiler_args(
621636 warning_args,
622637 gentype_arg,
623638 experimental_args,
639+ multi_entry_arg,
624640 // vec!["-warn-error".to_string(), "A".to_string()],
625641 // ^^ this one fails for bisect-ppx
626642 // this is the default
@@ -751,6 +767,12 @@ fn compile_file(
751767 . map_err ( |e| anyhow ! ( e) ) ?;
752768 let basename =
753769 helpers:: file_path_to_compiler_asset_basename ( implementation_file_path, & package. namespace ) ;
770+ let is_constructible_module = helpers:: file_path_to_constructible_module_name (
771+ implementation_file_path,
772+ & package. namespace ,
773+ package. config . is_multi_entry_enabled ( ) ,
774+ )
775+ . is_some ( ) ;
754776 let has_interface = module. get_interface ( ) . is_some ( ) ;
755777 let is_type_dev = module. is_type_dev ;
756778 let to_mjs_args = compiler_args (
@@ -794,7 +816,7 @@ fn compile_file(
794816 let dir = Path :: new ( implementation_file_path) . parent ( ) . unwrap ( ) ;
795817
796818 // perhaps we can do this copying somewhere else
797- if !is_interface {
819+ if !is_interface && is_constructible_module {
798820 let _ = std:: fs:: copy (
799821 package
800822 . get_build_path ( )
@@ -819,7 +841,7 @@ fn compile_file(
819841 . join ( format ! ( "{basename}.cmt" ) ) ,
820842 ocaml_build_path_abs. join ( format ! ( "{basename}.cmt" ) ) ,
821843 ) ;
822- } else {
844+ } else if is_interface && is_constructible_module {
823845 let _ = std:: fs:: copy (
824846 package
825847 . get_build_path ( )
@@ -847,13 +869,15 @@ fn compile_file(
847869 )
848870 . expect ( "copying source file failed" ) ;
849871
850- let _ = std:: fs:: copy (
851- Path :: new ( & package. path ) . join ( path) ,
852- package
853- . get_ocaml_build_path ( )
854- . join ( std:: path:: Path :: new ( path) . file_name ( ) . unwrap ( ) ) ,
855- )
856- . expect ( "copying source file failed" ) ;
872+ if is_constructible_module {
873+ let _ = std:: fs:: copy (
874+ Path :: new ( & package. path ) . join ( path) ,
875+ package
876+ . get_ocaml_build_path ( )
877+ . join ( std:: path:: Path :: new ( path) . file_name ( ) . unwrap ( ) ) ,
878+ )
879+ . expect ( "copying source file failed" ) ;
880+ }
857881 }
858882 if let SourceType :: SourceFile ( SourceFile {
859883 implementation : Implementation { path, .. } ,
@@ -869,13 +893,15 @@ fn compile_file(
869893 )
870894 . expect ( "copying source file failed" ) ;
871895
872- let _ = std:: fs:: copy (
873- Path :: new ( & package. path ) . join ( path) ,
874- package
875- . get_ocaml_build_path ( )
876- . join ( std:: path:: Path :: new ( path) . file_name ( ) . unwrap ( ) ) ,
877- )
878- . expect ( "copying source file failed" ) ;
896+ if is_constructible_module {
897+ let _ = std:: fs:: copy (
898+ Path :: new ( & package. path ) . join ( path) ,
899+ package
900+ . get_ocaml_build_path ( )
901+ . join ( std:: path:: Path :: new ( path) . file_name ( ) . unwrap ( ) ) ,
902+ )
903+ . expect ( "copying source file failed" ) ;
904+ }
879905 }
880906
881907 // copy js file
0 commit comments