@@ -10,6 +10,7 @@ fn get_dep_modules(
1010    package_modules :  & AHashSet < String > , 
1111    valid_modules :  & AHashSet < String > , 
1212    package :  & packages:: Package , 
13+     build_state :  & BuildState , 
1314)  -> AHashSet < String >  { 
1415    let  mut  deps = AHashSet :: new ( ) ; 
1516    let  ast_file = package. get_build_path ( ) . join ( ast_file) ; 
@@ -33,6 +34,24 @@ fn get_dep_modules(
3334        } 
3435    } 
3536
37+     // Get the list of allowed dependency packages for this package 
38+     let  allowed_dependencies:  AHashSet < String >  = package
39+         . config 
40+         . bs_dependencies 
41+         . as_ref ( ) 
42+         . unwrap_or ( & vec ! [ ] ) 
43+         . iter ( ) 
44+         . chain ( 
45+             package
46+                 . config 
47+                 . bs_dev_dependencies 
48+                 . as_ref ( ) 
49+                 . unwrap_or ( & vec ! [ ] ) 
50+                 . iter ( ) , 
51+         ) 
52+         . cloned ( ) 
53+         . collect ( ) ; 
54+ 
3655    return  deps
3756        . iter ( ) 
3857        . map ( |dep| { 
@@ -59,11 +78,28 @@ fn get_dep_modules(
5978            } 
6079        } ) 
6180        . filter ( |dep| { 
62-             valid_modules. contains ( dep) 
81+             // First check if the module exists 
82+             let  module_exists = valid_modules. contains ( dep) 
6383                && match  namespace. to_owned ( )  { 
6484                    Some ( namespace)  => !dep. eq ( & namespace) , 
6585                    None  => true , 
86+                 } ; 
87+ 
88+             if  !module_exists { 
89+                 return  false ; 
90+             } 
91+ 
92+             if  let  Some ( dep_module)  = build_state. modules . get ( dep)  { 
93+                 // If the module exists, check if it's in the same package (always allowed) 
94+                 if  dep_module. package_name  == package. name  { 
95+                     return  true ; 
6696                } 
97+ 
98+                 // If it's in a different package, check if that package is a declared dependency 
99+                 return  allowed_dependencies. contains ( & dep_module. package_name ) ; 
100+             } 
101+ 
102+             true 
67103        } ) 
68104        . collect :: < AHashSet < String > > ( ) ; 
69105} 
@@ -87,6 +123,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
87123                        package. modules . as_ref ( ) . unwrap ( ) , 
88124                        all_mod, 
89125                        & package, 
126+                         build_state, 
90127                    ) ; 
91128
92129                    if  let  Some ( interface)  = & source_file. interface  { 
@@ -98,6 +135,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
98135                            package. modules . as_ref ( ) . unwrap ( ) , 
99136                            all_mod, 
100137                            & package, 
138+                             build_state, 
101139                        ) ) 
102140                    } 
103141                    match  & package. namespace  { 
0 commit comments