Skip to content

Commit d3d023d

Browse files
committed
Expand search for type:dev in rescript config.
1 parent c4be983 commit d3d023d

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

rewatch/src/config.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,35 @@ impl Source {
108108
},
109109
}
110110
}
111+
112+
fn find_is_type_dev_for_sub_folder(
113+
&self,
114+
relative_parent_path: &Path,
115+
relative_source_file: &Path,
116+
) -> bool {
117+
match &self {
118+
Source::Shorthand(sub_folder) => {
119+
relative_parent_path.join(Path::new(sub_folder)) == *relative_source_file
120+
}
121+
Source::Qualified(package_source) => {
122+
// Note that we no longer check if type_ is dev of the nested subfolder.
123+
// A parent was type:dev, so we assume all subfolders are as well.
124+
let next_parent_path = relative_parent_path.join(Path::new(&package_source.dir));
125+
if next_parent_path == *relative_source_file {
126+
return true;
127+
};
128+
129+
match &package_source.subdirs {
130+
None => false,
131+
Some(Subdirs::Recurse(false)) => false,
132+
Some(Subdirs::Recurse(true)) => relative_source_file.starts_with(&next_parent_path),
133+
Some(Subdirs::Qualified(nested_sources)) => nested_sources.iter().any(|nested_source| {
134+
nested_source.find_is_type_dev_for_sub_folder(&next_parent_path, relative_source_file)
135+
}),
136+
}
137+
}
138+
}
139+
}
111140
}
112141

113142
impl Eq for Source {}
@@ -502,7 +531,23 @@ impl Config {
502531
};
503532

504533
package_sources.iter().any(|package_source| {
505-
Path::new(&package_source.dir) == relative_parent && package_source.is_type_dev()
534+
if !package_source.is_type_dev() {
535+
false
536+
} else {
537+
let dir_path = Path::new(&package_source.dir);
538+
if dir_path == relative_parent {
539+
return true;
540+
};
541+
542+
match &package_source.subdirs {
543+
None => false,
544+
Some(Subdirs::Recurse(false)) => false,
545+
Some(Subdirs::Recurse(true)) => relative_path.starts_with(dir_path),
546+
Some(Subdirs::Qualified(sub_dirs)) => sub_dirs.iter().any(|sub_dir| {
547+
sub_dir.find_is_type_dev_for_sub_folder(Path::new(relative_path), relative_parent)
548+
}),
549+
}
550+
}
506551
})
507552
}
508553
}

0 commit comments

Comments
 (0)