Skip to content

Commit 0c36cb5

Browse files
committed
Try and check the file type when allowing dev dependency access.
1 parent 9068abb commit 0c36cb5

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

rewatch/src/build/compile.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,14 @@ pub fn compiler_args(
365365
) -> Vec<String> {
366366
let bsc_flags = config::flatten_flags(&config.bsc_flags);
367367

368-
let dependency_paths =
369-
get_dependency_paths(config, project_root, workspace_root, packages, build_dev_deps);
368+
let dependency_paths = get_dependency_paths(
369+
config,
370+
project_root,
371+
workspace_root,
372+
packages,
373+
build_dev_deps,
374+
file_path,
375+
);
370376

371377
let module_name = helpers::file_path_to_module_name(file_path, &config.get_namespace());
372378

@@ -499,12 +505,37 @@ impl DependentPackage {
499505
}
500506
}
501507

508+
fn is_file_type_dev(config: &config::Config, file_path: &Path) -> bool {
509+
let Some(sources) = &config.sources else {
510+
return false;
511+
};
512+
match sources {
513+
config::OneOrMore::Multiple(multiple) => {
514+
for source in multiple.iter() {
515+
match source {
516+
config::Source::Qualified(config::PackageSource {
517+
dir: dir,
518+
subdirs: _,
519+
type_: Some(type_),
520+
}) if *type_ == String::from("dev") => {
521+
return Path::new(dir) == file_path.parent().unwrap();
522+
}
523+
_ => {}
524+
}
525+
}
526+
false
527+
}
528+
_ => todo!(),
529+
}
530+
}
531+
502532
fn get_dependency_paths(
503533
config: &config::Config,
504534
project_root: &Path,
505535
workspace_root: &Option<PathBuf>,
506536
packages: &Option<&AHashMap<String, packages::Package>>,
507537
build_dev_deps: bool,
538+
file_path: &Path,
508539
) -> Vec<Vec<String>> {
509540
let normal_deps = config
510541
.bs_dependencies
@@ -513,7 +544,10 @@ fn get_dependency_paths(
513544
.into_iter()
514545
.map(DependentPackage::Normal)
515546
.collect();
516-
let dev_deps = if build_dev_deps {
547+
// We need to check if the current file is listed as type: "dev"
548+
// Only then it has access of using the bs-dev-dependencies
549+
let is_file_type_dev = is_file_type_dev(config, file_path);
550+
let dev_deps = if build_dev_deps && is_file_type_dev {
517551
config
518552
.bs_dev_dependencies
519553
.clone()

0 commit comments

Comments
 (0)