Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/build/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn get_dep_modules(
package_modules: &AHashSet<String>,
valid_modules: &AHashSet<String>,
package: &packages::Package,
build_state: &BuildState,
) -> AHashSet<String> {
let mut deps = AHashSet::new();
let ast_file = package.get_build_path() + "/" + ast_file;
Expand All @@ -30,6 +31,24 @@ fn get_dep_modules(
panic!("Could not read file {}", ast_file);
}

// Get the list of allowed dependency packages for this package
let allowed_dependencies: AHashSet<String> = package
.config
.bs_dependencies
.as_ref()
.unwrap_or(&vec![])
.iter()
.chain(
package
.config
.bs_dev_dependencies
.as_ref()
.unwrap_or(&vec![])
.iter(),
)
.cloned()
.collect();

return deps
.iter()
.map(|dep| {
Expand All @@ -56,11 +75,28 @@ fn get_dep_modules(
}
})
.filter(|dep| {
valid_modules.contains(dep)
// First check if the module exists
let module_exists = valid_modules.contains(dep)
&& match namespace.to_owned() {
Some(namespace) => !dep.eq(&namespace),
None => true,
};

if !module_exists {
return false;
}

if let Some(dep_module) = build_state.modules.get(dep) {
// If the module exists, check if it's in the same package (always allowed)
if dep_module.package_name == package.name {
return true;
}

// If it's in a different package, check if that package is a declared dependency
return allowed_dependencies.contains(&dep_module.package_name);
}

true
})
.collect::<AHashSet<String>>();
}
Expand All @@ -84,6 +120,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
package.modules.as_ref().unwrap(),
all_mod,
&package,
build_state,
);

if let Some(interface) = &source_file.interface {
Expand All @@ -95,6 +132,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
package.modules.as_ref().unwrap(),
all_mod,
&package,
build_state,
))
}
match &package.namespace {
Expand Down