summaryrefslogtreecommitdiff
path: root/cli/util/fs.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-09-08 15:04:45 +0100
committerGitHub <noreply@github.com>2023-09-08 15:04:45 +0100
commit17276a1df9fb4926f813d2b8a5ac2a2a8bf289eb (patch)
tree7e511b1536692ab82c7ccc7f424cb572c211217e /cli/util/fs.rs
parent14522fc62886b95431f62d5bd21d70cfaac780ee (diff)
fix: empty include in config file excludes all (#20404)
Diffstat (limited to 'cli/util/fs.rs')
-rw-r--r--cli/util/fs.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index 2ccd70b6d..93403659a 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -239,14 +239,13 @@ impl<TFilter: Fn(&Path) -> bool> FileCollector<TFilter> {
pub fn collect_files(
&self,
- files: &[PathBuf],
+ files: Option<&[PathBuf]>,
) -> Result<Vec<PathBuf>, AnyError> {
let mut target_files = Vec::new();
- let files = if files.is_empty() {
- // collect files in the current directory when empty
- Cow::Owned(vec![PathBuf::from(".")])
- } else {
+ let files = if let Some(files) = files {
Cow::Borrowed(files)
+ } else {
+ Cow::Owned(vec![PathBuf::from(".")])
};
for file in files.iter() {
if let Ok(file) = canonicalize_path(file) {
@@ -312,11 +311,10 @@ pub fn collect_specifiers(
.ignore_vendor_folder();
let root_path = current_dir()?;
- let include_files = if files.include.is_empty() {
- // collect files in the current directory when empty
- Cow::Owned(vec![root_path.clone()])
+ let include_files = if let Some(include) = &files.include {
+ Cow::Borrowed(include)
} else {
- Cow::Borrowed(&files.include)
+ Cow::Owned(vec![root_path.clone()])
};
for path in include_files.iter() {
let path = path.to_string_lossy();
@@ -336,7 +334,7 @@ pub fn collect_specifiers(
};
let p = normalize_path(p);
if p.is_dir() {
- let test_files = file_collector.collect_files(&[p])?;
+ let test_files = file_collector.collect_files(Some(&[p]))?;
let mut test_files_as_urls = test_files
.iter()
.map(|f| ModuleSpecifier::from_file_path(f).unwrap())
@@ -776,7 +774,7 @@ mod tests {
.add_ignore_paths(&[ignore_dir_path.to_path_buf()]);
let result = file_collector
- .collect_files(&[root_dir_path.to_path_buf()])
+ .collect_files(Some(&[root_dir_path.to_path_buf()]))
.unwrap();
let expected = [
"README.md",
@@ -803,7 +801,7 @@ mod tests {
.ignore_node_modules()
.ignore_vendor_folder();
let result = file_collector
- .collect_files(&[root_dir_path.to_path_buf()])
+ .collect_files(Some(&[root_dir_path.to_path_buf()]))
.unwrap();
let expected = [
"README.md",
@@ -823,10 +821,10 @@ mod tests {
// test opting out of ignoring by specifying the dir
let result = file_collector
- .collect_files(&[
+ .collect_files(Some(&[
root_dir_path.to_path_buf(),
root_dir_path.to_path_buf().join("child/node_modules/"),
- ])
+ ]))
.unwrap();
let expected = [
"README.md",
@@ -894,11 +892,11 @@ mod tests {
let result = collect_specifiers(
&FilesConfig {
- include: vec![
+ include: Some(vec![
PathBuf::from("http://localhost:8080"),
root_dir_path.to_path_buf(),
PathBuf::from("https://localhost:8080".to_string()),
- ],
+ ]),
exclude: vec![ignore_dir_path.to_path_buf()],
},
predicate,
@@ -933,11 +931,11 @@ mod tests {
};
let result = collect_specifiers(
&FilesConfig {
- include: vec![PathBuf::from(format!(
+ include: Some(vec![PathBuf::from(format!(
"{}{}",
scheme,
root_dir_path.join("child").to_string().replace('\\', "/")
- ))],
+ ))]),
exclude: vec![],
},
predicate,