Skip to content

Commit 34d9810

Browse files
committed
fix(core): ensure ignored paths are not visited
Fixes #311
1 parent ad9f0ab commit 34d9810

3 files changed

Lines changed: 89 additions & 25 deletions

File tree

Cargo.lock

Lines changed: 70 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ clap = { version = "4.5.53", features = ["cargo"] }
2020
color-print = "0.3.7"
2121
colored = "3.0.0"
2222
env_logger = "0.11.8"
23-
glob = "0.3.3"
2423
globset = "0.4.18"
24+
ignore = "0.4.25"
2525
indicatif = "0.18.3"
2626
itertools = "0.14.0"
2727
lazy_static = "1.5.0"

src/packages.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
rcfile::Rcfile,
99
specifier::Specifier,
1010
},
11-
glob::glob,
11+
ignore::{overrides::OverrideBuilder, WalkBuilder},
1212
log::debug,
1313
serde::Deserialize,
1414
serde_json::Value,
@@ -35,6 +35,7 @@ impl Packages {
3535
/// Get every package.json file matched by the user's source patterns
3636
pub fn from_config(config: &Config) -> Self {
3737
let file_paths = get_file_paths(config);
38+
debug!("Found file paths: {file_paths:?}");
3839
let mut packages = Self::new();
3940
file_paths.iter().for_each(|file_path| {
4041
if let Some(package_json) = PackageJson::from_file(file_path) {
@@ -177,22 +178,18 @@ pub fn normalize_pattern(pattern: String) -> String {
177178
/// Resolve every source glob pattern into their absolute file paths of
178179
/// package.json files
179180
fn get_file_paths(config: &Config) -> Vec<PathBuf> {
180-
get_source_patterns(config)
181-
.iter()
182-
.map(|pattern| {
183-
if PathBuf::from(pattern).is_absolute() {
184-
pattern.clone()
185-
} else {
186-
config.cli.cwd.join(pattern).to_str().unwrap().to_string()
187-
}
188-
})
189-
.flat_map(|pattern| glob(&pattern).ok())
190-
.flat_map(|paths| {
191-
paths.filter_map(Result::ok).fold(vec![], |mut paths, path| {
192-
paths.push(path.clone());
193-
paths
194-
})
195-
})
181+
let cwd = &config.cli.cwd;
182+
let source_patterns = get_source_patterns(config);
183+
let mut glob_filters = OverrideBuilder::new(cwd);
184+
for source_pattern in source_patterns {
185+
glob_filters.add(&source_pattern).unwrap();
186+
}
187+
WalkBuilder::new(cwd)
188+
.overrides(glob_filters.build().unwrap())
189+
.build()
190+
.filter_map(Result::ok)
191+
.filter(|entry| entry.file_type().is_some_and(|ft| ft.is_file()))
192+
.map(|entry| entry.into_path())
196193
.collect()
197194
}
198195

@@ -233,6 +230,10 @@ fn get_source_patterns(config: &Config) -> Vec<String> {
233230
})
234231
})
235232
.map(|patterns| patterns.into_iter().map(normalize_pattern).collect())
233+
.map(|patterns| {
234+
debug!("Found patterns: {patterns:?}");
235+
patterns
236+
})
236237
.or_else(get_default_patterns)
237238
.unwrap()
238239
}

0 commit comments

Comments
 (0)