@@ -67,6 +67,14 @@ pub fn get_build_path(canonical_path: &str) -> String {
6767 format ! ( "{}/lib/bs" , canonical_path)
6868}
6969
70+ pub fn get_js_path ( canonical_path : & str ) -> String {
71+ format ! ( "{}/lib/js" , canonical_path)
72+ }
73+
74+ pub fn get_es6_path ( canonical_path : & str ) -> String {
75+ format ! ( "{}/lib/es6" , canonical_path)
76+ }
77+
7078pub fn get_ocaml_build_path ( canonical_path : & str ) -> String {
7179 format ! ( "{}/lib/ocaml" , canonical_path)
7280}
@@ -80,6 +88,14 @@ impl Package {
8088 get_build_path ( & self . path )
8189 }
8290
91+ pub fn get_js_path ( & self ) -> String {
92+ get_js_path ( & self . path )
93+ }
94+
95+ pub fn get_es6_path ( & self ) -> String {
96+ get_es6_path ( & self . path )
97+ }
98+
8399 pub fn get_mlmap_path ( & self ) -> String {
84100 self . get_build_path ( )
85101 + "/"
@@ -590,8 +606,48 @@ pub fn parse_packages(build_state: &mut BuildState) {
590606 }
591607 let build_path_abs = package. get_build_path ( ) ;
592608 let bs_build_path = package. get_ocaml_build_path ( ) ;
593- helpers:: create_build_path ( & build_path_abs) ;
594- helpers:: create_build_path ( & bs_build_path) ;
609+ helpers:: create_path ( & build_path_abs) ;
610+ helpers:: create_path ( & bs_build_path) ;
611+ let root_config = build_state
612+ . get_package ( & build_state. root_config_name )
613+ . expect ( "cannot find root config" ) ;
614+
615+ root_config. config . get_package_specs ( ) . iter ( ) . for_each ( |spec| {
616+ if !spec. in_source {
617+ // we don't want to calculate this if we don't have out of source specs
618+ // we do this twice, but we almost never have multiple package specs
619+ // so this optimization is less important
620+ let relative_dirs: AHashSet < PathBuf > = match & package. source_files {
621+ Some ( source_files) => source_files
622+ . keys ( )
623+ . map ( |source_file| {
624+ Path :: new ( source_file)
625+ . parent ( )
626+ . expect ( "parent dir not found" )
627+ . to_owned ( )
628+ } )
629+ . collect ( ) ,
630+ _ => AHashSet :: new ( ) ,
631+ } ;
632+ if spec. is_common_js ( ) {
633+ helpers:: create_path ( & package. get_js_path ( ) ) ;
634+ relative_dirs. iter ( ) . for_each ( |path_buf| {
635+ helpers:: create_path_for_path ( & Path :: join (
636+ & PathBuf :: from ( package. get_js_path ( ) ) ,
637+ path_buf,
638+ ) )
639+ } )
640+ } else {
641+ helpers:: create_path ( & package. get_es6_path ( ) ) ;
642+ relative_dirs. iter ( ) . for_each ( |path_buf| {
643+ helpers:: create_path_for_path ( & Path :: join (
644+ & PathBuf :: from ( package. get_es6_path ( ) ) ,
645+ path_buf,
646+ ) )
647+ } )
648+ }
649+ }
650+ } ) ;
595651
596652 package. namespace . to_suffix ( ) . iter ( ) . for_each ( |namespace| {
597653 // generate the mlmap "AST" file for modules that have a namespace configured
0 commit comments