Skip to content

Commit 7e759e6

Browse files
authored
Don't add deps to modules that are in packages that are not a dependency (#165)
1 parent 38e04d7 commit 7e759e6

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/build/deps.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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() + "/" + ast_file;
@@ -30,6 +31,24 @@ fn get_dep_modules(
3031
panic!("Could not read file {}", ast_file);
3132
}
3233

34+
// Get the list of allowed dependency packages for this package
35+
let allowed_dependencies: AHashSet<String> = package
36+
.config
37+
.bs_dependencies
38+
.as_ref()
39+
.unwrap_or(&vec![])
40+
.iter()
41+
.chain(
42+
package
43+
.config
44+
.bs_dev_dependencies
45+
.as_ref()
46+
.unwrap_or(&vec![])
47+
.iter(),
48+
)
49+
.cloned()
50+
.collect();
51+
3352
return deps
3453
.iter()
3554
.map(|dep| {
@@ -56,11 +75,28 @@ fn get_dep_modules(
5675
}
5776
})
5877
.filter(|dep| {
59-
valid_modules.contains(dep)
78+
// First check if the module exists
79+
let module_exists = valid_modules.contains(dep)
6080
&& match namespace.to_owned() {
6181
Some(namespace) => !dep.eq(&namespace),
6282
None => true,
83+
};
84+
85+
if !module_exists {
86+
return false;
87+
}
88+
89+
if let Some(dep_module) = build_state.modules.get(dep) {
90+
// If the module exists, check if it's in the same package (always allowed)
91+
if dep_module.package_name == package.name {
92+
return true;
6393
}
94+
95+
// If it's in a different package, check if that package is a declared dependency
96+
return allowed_dependencies.contains(&dep_module.package_name);
97+
}
98+
99+
true
64100
})
65101
.collect::<AHashSet<String>>();
66102
}
@@ -84,6 +120,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
84120
package.modules.as_ref().unwrap(),
85121
all_mod,
86122
&package,
123+
build_state,
87124
);
88125

89126
if let Some(interface) = &source_file.interface {
@@ -95,6 +132,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
95132
package.modules.as_ref().unwrap(),
96133
all_mod,
97134
&package,
135+
build_state,
98136
))
99137
}
100138
match &package.namespace {

0 commit comments

Comments
 (0)