@@ -10,6 +10,7 @@ fn get_dep_modules(
10
10
package_modules : & AHashSet < String > ,
11
11
valid_modules : & AHashSet < String > ,
12
12
package : & packages:: Package ,
13
+ build_state : & BuildState ,
13
14
) -> AHashSet < String > {
14
15
let mut deps = AHashSet :: new ( ) ;
15
16
let ast_file = package. get_build_path ( ) . join ( ast_file) ;
@@ -33,6 +34,24 @@ fn get_dep_modules(
33
34
}
34
35
}
35
36
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
+
36
55
return deps
37
56
. iter ( )
38
57
. map ( |dep| {
@@ -59,11 +78,28 @@ fn get_dep_modules(
59
78
}
60
79
} )
61
80
. filter ( |dep| {
62
- valid_modules. contains ( dep)
81
+ // First check if the module exists
82
+ let module_exists = valid_modules. contains ( dep)
63
83
&& match namespace. to_owned ( ) {
64
84
Some ( namespace) => !dep. eq ( & namespace) ,
65
85
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 ;
66
96
}
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
67
103
} )
68
104
. collect :: < AHashSet < String > > ( ) ;
69
105
}
@@ -87,6 +123,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
87
123
package. modules . as_ref ( ) . unwrap ( ) ,
88
124
all_mod,
89
125
& package,
126
+ build_state,
90
127
) ;
91
128
92
129
if let Some ( interface) = & source_file. interface {
@@ -98,6 +135,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
98
135
package. modules . as_ref ( ) . unwrap ( ) ,
99
136
all_mod,
100
137
& package,
138
+ build_state,
101
139
) )
102
140
}
103
141
match & package. namespace {
0 commit comments