dart-decimate 0.0.47 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +5 -5
- package/Cargo.toml +1 -1
- package/README.md +8 -8
- package/package.json +2 -2
- package/src/dependencies/discovery.rs +15 -46
- package/src/dependencies/tests.rs +66 -0
- package/src/output/route_cycle/aliases.rs +12 -0
- package/src/package_map.rs +41 -26
- package/src/scan.rs +34 -25
package/Cargo.lock
CHANGED
|
@@ -51,18 +51,18 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
|
51
51
|
|
|
52
52
|
[[package]]
|
|
53
53
|
name = "clap"
|
|
54
|
-
version = "4.6.
|
|
54
|
+
version = "4.6.7"
|
|
55
55
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
-
checksum = "
|
|
56
|
+
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
|
57
57
|
dependencies = [
|
|
58
58
|
"clap_builder",
|
|
59
59
|
]
|
|
60
60
|
|
|
61
61
|
[[package]]
|
|
62
62
|
name = "clap_builder"
|
|
63
|
-
version = "4.6.
|
|
63
|
+
version = "4.6.7"
|
|
64
64
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
-
checksum = "
|
|
65
|
+
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
|
|
66
66
|
dependencies = [
|
|
67
67
|
"anstyle",
|
|
68
68
|
"clap_lex",
|
|
@@ -102,7 +102,7 @@ checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
|
|
102
102
|
|
|
103
103
|
[[package]]
|
|
104
104
|
name = "dart-decimate"
|
|
105
|
-
version = "0.0.
|
|
105
|
+
version = "0.0.49"
|
|
106
106
|
dependencies = [
|
|
107
107
|
"clap",
|
|
108
108
|
"glob",
|
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ You do not need to install anything permanently. Use the command above.
|
|
|
90
90
|
For repeatable automation, pin the version:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npx --yes dart-decimate@0.0.
|
|
93
|
+
npx --yes dart-decimate@0.0.49
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
Add this to `package.json` if you want a short project command:
|
|
@@ -101,7 +101,7 @@ Add this to `package.json` if you want a short project command:
|
|
|
101
101
|
"dart-decimate": "dart-decimate json ."
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"dart-decimate": "0.0.
|
|
104
|
+
"dart-decimate": "0.0.49"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
```
|
|
@@ -115,7 +115,7 @@ npm run dart-decimate
|
|
|
115
115
|
If you prefer Cargo, install the matching tagged source:
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.
|
|
118
|
+
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.49 --locked
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
The npm release `X.Y.Z` and Cargo tag `vX.Y.Z` are verified against each other
|
|
@@ -126,7 +126,7 @@ Confirm a Cargo build's version with:
|
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
128
|
dart-decimate --version
|
|
129
|
-
# dart-decimate 0.0.
|
|
129
|
+
# dart-decimate 0.0.49
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
## npx
|
|
@@ -536,7 +536,7 @@ Example shape:
|
|
|
536
536
|
{
|
|
537
537
|
"schema_version": "dart-decimate.report.v1",
|
|
538
538
|
"kind": "combined",
|
|
539
|
-
"tool": "dart-decimate 0.0.
|
|
539
|
+
"tool": "dart-decimate 0.0.49",
|
|
540
540
|
"command": "check",
|
|
541
541
|
"verdict": "fail",
|
|
542
542
|
"summary": {
|
|
@@ -552,7 +552,7 @@ Example shape:
|
|
|
552
552
|
|
|
553
553
|
The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
|
|
554
554
|
string includes the producing version so saved reports identify the exact
|
|
555
|
-
build, for example `dart-decimate 0.0.
|
|
555
|
+
build, for example `dart-decimate 0.0.49`.
|
|
556
556
|
|
|
557
557
|
When grouped security findings hide additional occurrences, `next_steps` can
|
|
558
558
|
include `review-security-surface`, which reruns
|
|
@@ -640,7 +640,7 @@ you need the installed binary's exact list.
|
|
|
640
640
|
For a complete repository check, including discovered local packages:
|
|
641
641
|
|
|
642
642
|
```bash
|
|
643
|
-
npx --yes dart-decimate@0.0.
|
|
643
|
+
npx --yes dart-decimate@0.0.49 --strict
|
|
644
644
|
```
|
|
645
645
|
|
|
646
646
|
This runs every enabled check from the repository root. The default duplication
|
|
@@ -683,7 +683,7 @@ This repository forbids `unsafe_code`.
|
|
|
683
683
|
|
|
684
684
|
## Release Flow
|
|
685
685
|
|
|
686
|
-
Current source version: `0.0.
|
|
686
|
+
Current source version: `0.0.49`.
|
|
687
687
|
|
|
688
688
|
After the first public release, changes should go through pull requests. Every
|
|
689
689
|
PR to `main` must bump both `Cargo.toml` and `package.json` above the base
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@biomejs/biome": "2.5.
|
|
56
|
+
"@biomejs/biome": "2.5.14"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
use std::
|
|
2
|
-
use std::path::{Path, PathBuf};
|
|
1
|
+
use std::path::Path;
|
|
3
2
|
|
|
4
3
|
use crate::graph::normalize_path;
|
|
4
|
+
use crate::scan::{IgnoreMatcher, project_walk};
|
|
5
5
|
|
|
6
6
|
use super::{DependencyHygieneError, PubPackage, read_package};
|
|
7
7
|
|
|
8
8
|
pub(super) fn discover_packages(root: &Path) -> Result<Vec<PubPackage>, DependencyHygieneError> {
|
|
9
9
|
let mut pubspecs = Vec::new();
|
|
10
|
-
|
|
10
|
+
for entry in project_walk(root, root, &IgnoreMatcher::default()) {
|
|
11
|
+
let entry = entry.map_err(|error| DependencyHygieneError::ReadDir {
|
|
12
|
+
path: root.to_path_buf(),
|
|
13
|
+
source: std::io::Error::other(error),
|
|
14
|
+
})?;
|
|
15
|
+
if entry
|
|
16
|
+
.file_type()
|
|
17
|
+
.is_some_and(|file_type| file_type.is_file())
|
|
18
|
+
&& entry.file_name() == "pubspec.yaml"
|
|
19
|
+
{
|
|
20
|
+
pubspecs.push(normalize_path(entry.path()));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
let mut packages = pubspecs
|
|
12
24
|
.into_iter()
|
|
13
25
|
.filter_map(|path| read_package(&path).transpose())
|
|
@@ -15,46 +27,3 @@ pub(super) fn discover_packages(root: &Path) -> Result<Vec<PubPackage>, Dependen
|
|
|
15
27
|
packages.sort_by(|left, right| left.root.cmp(&right.root));
|
|
16
28
|
Ok(packages)
|
|
17
29
|
}
|
|
18
|
-
|
|
19
|
-
fn discover_pubspecs(
|
|
20
|
-
dir: &Path,
|
|
21
|
-
pubspecs: &mut Vec<PathBuf>,
|
|
22
|
-
) -> Result<(), DependencyHygieneError> {
|
|
23
|
-
let entries = fs::read_dir(dir).map_err(|source| DependencyHygieneError::ReadDir {
|
|
24
|
-
path: dir.to_path_buf(),
|
|
25
|
-
source,
|
|
26
|
-
})?;
|
|
27
|
-
|
|
28
|
-
for entry in entries {
|
|
29
|
-
let entry = entry.map_err(|source| DependencyHygieneError::ReadDirEntry {
|
|
30
|
-
path: dir.to_path_buf(),
|
|
31
|
-
source,
|
|
32
|
-
})?;
|
|
33
|
-
let path = entry.path();
|
|
34
|
-
let file_type = entry
|
|
35
|
-
.file_type()
|
|
36
|
-
.map_err(|source| DependencyHygieneError::FileType {
|
|
37
|
-
path: path.clone(),
|
|
38
|
-
source,
|
|
39
|
-
})?;
|
|
40
|
-
|
|
41
|
-
if file_type.is_dir() {
|
|
42
|
-
if should_skip_dir(&path) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
discover_pubspecs(&path, pubspecs)?;
|
|
46
|
-
} else if file_type.is_file() && path.file_name().is_some_and(|name| name == "pubspec.yaml")
|
|
47
|
-
{
|
|
48
|
-
pubspecs.push(normalize_path(&path));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Ok(())
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
pub(super) fn should_skip_dir(path: &Path) -> bool {
|
|
56
|
-
matches!(
|
|
57
|
-
path.file_name().and_then(|name| name.to_str()),
|
|
58
|
-
Some(".dart_tool" | ".git" | ".idea" | ".pub-cache" | "build" | "target")
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -629,6 +629,72 @@ fn analyzes_workspace_packages_independently() -> Result<(), Box<dyn std::error:
|
|
|
629
629
|
Ok(())
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
+
#[test]
|
|
633
|
+
fn skips_nested_checkout_packages_and_sources() -> Result<(), Box<dyn std::error::Error>> {
|
|
634
|
+
let fixture = tempfile::tempdir()?;
|
|
635
|
+
let app_pubspec = "name: app\ndependencies:\n path: ^1.0.0\n";
|
|
636
|
+
let app_main = "import 'package:path/path.dart';\nvoid main() {}\n";
|
|
637
|
+
write(&fixture, "pubspec.yaml", app_pubspec)?;
|
|
638
|
+
write(&fixture, "lib/main.dart", app_main)?;
|
|
639
|
+
write(&fixture, "packages/feature/pubspec.yaml", "name: feature\n")?;
|
|
640
|
+
write(
|
|
641
|
+
&fixture,
|
|
642
|
+
"packages/feature/lib/feature.dart",
|
|
643
|
+
"class Feature {}\n",
|
|
644
|
+
)?;
|
|
645
|
+
write(
|
|
646
|
+
&fixture,
|
|
647
|
+
"worktrees/wt1/.git",
|
|
648
|
+
"gitdir: ../../.git/worktrees/wt1\n",
|
|
649
|
+
)?;
|
|
650
|
+
write(&fixture, "worktrees/wt1/pubspec.yaml", app_pubspec)?;
|
|
651
|
+
write(&fixture, "worktrees/wt1/test/main_test.dart", app_main)?;
|
|
652
|
+
let project = scan_project(fixture.path())?;
|
|
653
|
+
|
|
654
|
+
let packages = discover_packages(&project.root)?;
|
|
655
|
+
let report = analyze_dependency_hygiene(&project)?;
|
|
656
|
+
|
|
657
|
+
assert_eq!(
|
|
658
|
+
packages
|
|
659
|
+
.iter()
|
|
660
|
+
.map(|package| package.name.as_str())
|
|
661
|
+
.collect::<Vec<_>>(),
|
|
662
|
+
vec!["app", "feature"]
|
|
663
|
+
);
|
|
664
|
+
assert!(
|
|
665
|
+
project
|
|
666
|
+
.files
|
|
667
|
+
.iter()
|
|
668
|
+
.all(|file| !file.path.to_string_lossy().contains("worktrees"))
|
|
669
|
+
);
|
|
670
|
+
assert!(report.unused_dependencies.is_empty());
|
|
671
|
+
|
|
672
|
+
Ok(())
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
#[test]
|
|
676
|
+
fn skips_gitignored_nested_package_dependencies() -> Result<(), Box<dyn std::error::Error>> {
|
|
677
|
+
let fixture = tempfile::tempdir()?;
|
|
678
|
+
write(&fixture, ".gitignore", "scratch/\n")?;
|
|
679
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
680
|
+
write(&fixture, "lib/main.dart", "void main() {}\n")?;
|
|
681
|
+
write(
|
|
682
|
+
&fixture,
|
|
683
|
+
"scratch/pkg/pubspec.yaml",
|
|
684
|
+
"name: pkg\ndependencies:\n http: ^1.0.0\n",
|
|
685
|
+
)?;
|
|
686
|
+
let project = scan_project(fixture.path())?;
|
|
687
|
+
|
|
688
|
+
let packages = discover_packages(&project.root)?;
|
|
689
|
+
let report = analyze_dependency_hygiene(&project)?;
|
|
690
|
+
|
|
691
|
+
assert_eq!(packages.len(), 1);
|
|
692
|
+
assert_eq!(packages[0].name, "app");
|
|
693
|
+
assert!(report.unused_dependencies.is_empty());
|
|
694
|
+
|
|
695
|
+
Ok(())
|
|
696
|
+
}
|
|
697
|
+
|
|
632
698
|
#[test]
|
|
633
699
|
fn reports_dev_dependency_in_production_for_owning_workspace_package()
|
|
634
700
|
-> Result<(), Box<dyn std::error::Error>> {
|
|
@@ -570,6 +570,11 @@ fn scoped_header_binding_exists(
|
|
|
570
570
|
) {
|
|
571
571
|
return false;
|
|
572
572
|
}
|
|
573
|
+
if for_in_iterable(scope, path_child) {
|
|
574
|
+
// The iterable is evaluated in the enclosing scope, so even
|
|
575
|
+
// `for (final route in route.go(context))` reads the outer `route`.
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
573
578
|
if header_field_binding_exists(scope, path_child, usage_start, name, source) {
|
|
574
579
|
return true;
|
|
575
580
|
}
|
|
@@ -618,6 +623,13 @@ fn catch_header_binding_exists(
|
|
|
618
623
|
false
|
|
619
624
|
}
|
|
620
625
|
|
|
626
|
+
fn for_in_iterable(scope: Node<'_>, path_child: Node<'_>) -> bool {
|
|
627
|
+
matches!(scope.kind(), "for_element" | "for_statement")
|
|
628
|
+
&& scope
|
|
629
|
+
.child_by_field_name("value")
|
|
630
|
+
.is_some_and(|value| same_node(value, path_child))
|
|
631
|
+
}
|
|
632
|
+
|
|
621
633
|
fn catch_body_child(node: Node<'_>) -> bool {
|
|
622
634
|
matches!(node.kind(), "block" | "function_body")
|
|
623
635
|
}
|
package/src/package_map.rs
CHANGED
|
@@ -6,6 +6,7 @@ use serde::Deserialize;
|
|
|
6
6
|
use serde_yaml_ng::{Mapping, Value};
|
|
7
7
|
|
|
8
8
|
use crate::graph::{GraphError, normalize_path};
|
|
9
|
+
use crate::scan::{IgnoreMatcher, project_walk};
|
|
9
10
|
|
|
10
11
|
#[derive(Debug, Clone, Default)]
|
|
11
12
|
pub(crate) struct PackageMap {
|
|
@@ -199,28 +200,15 @@ impl PackageMap {
|
|
|
199
200
|
dir: &Path,
|
|
200
201
|
visited: &mut BTreeSet<PathBuf>,
|
|
201
202
|
) -> Result<(), GraphError> {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
source,
|
|
205
|
-
})?;
|
|
206
|
-
|
|
207
|
-
for entry in entries {
|
|
208
|
-
let entry = entry.map_err(|source| GraphError::ReadDirEntry {
|
|
203
|
+
for entry in project_walk(dir, dir, &IgnoreMatcher::default()) {
|
|
204
|
+
let entry = entry.map_err(|error| GraphError::ReadDir {
|
|
209
205
|
path: dir.to_path_buf(),
|
|
210
|
-
source,
|
|
206
|
+
source: std::io::Error::other(error),
|
|
211
207
|
})?;
|
|
212
208
|
let path = entry.path();
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
})?;
|
|
217
|
-
|
|
218
|
-
if file_type.is_dir() {
|
|
219
|
-
if should_skip_dir(&path) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
self.discover_nested_pubspecs(&path, visited)?;
|
|
223
|
-
} else if file_type.is_file()
|
|
209
|
+
if entry
|
|
210
|
+
.file_type()
|
|
211
|
+
.is_some_and(|file_type| file_type.is_file())
|
|
224
212
|
&& path.file_name().is_some_and(|name| name == "pubspec.yaml")
|
|
225
213
|
&& let Some(package_root) = path.parent()
|
|
226
214
|
{
|
|
@@ -565,13 +553,6 @@ fn contains_glob_pattern(value: &str) -> bool {
|
|
|
565
553
|
value.contains('*') || value.contains('?') || value.contains('[')
|
|
566
554
|
}
|
|
567
555
|
|
|
568
|
-
fn should_skip_dir(path: &Path) -> bool {
|
|
569
|
-
matches!(
|
|
570
|
-
path.file_name().and_then(|name| name.to_str()),
|
|
571
|
-
Some(".dart_tool" | ".git" | ".idea" | ".pub-cache" | "build" | "target")
|
|
572
|
-
)
|
|
573
|
-
}
|
|
574
|
-
|
|
575
556
|
#[cfg(test)]
|
|
576
557
|
mod tests {
|
|
577
558
|
use tempfile::TempDir;
|
|
@@ -676,6 +657,40 @@ mod tests {
|
|
|
676
657
|
Ok(())
|
|
677
658
|
}
|
|
678
659
|
|
|
660
|
+
#[test]
|
|
661
|
+
fn skips_nested_checkouts_but_keeps_nested_local_packages()
|
|
662
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
663
|
+
let fixture = TempDir::new()?;
|
|
664
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
665
|
+
write(&fixture, "packages/feature/pubspec.yaml", "name: feature\n")?;
|
|
666
|
+
write(
|
|
667
|
+
&fixture,
|
|
668
|
+
"worktrees/wt1/.git",
|
|
669
|
+
"gitdir: ../../.git/worktrees/wt1\n",
|
|
670
|
+
)?;
|
|
671
|
+
write(&fixture, "worktrees/wt1/pubspec.yaml", "name: app_copy\n")?;
|
|
672
|
+
|
|
673
|
+
let packages = PackageMap::discover(fixture.path())?;
|
|
674
|
+
|
|
675
|
+
assert_eq!(packages.names(), vec!["app", "feature"]);
|
|
676
|
+
|
|
677
|
+
Ok(())
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
#[test]
|
|
681
|
+
fn skips_gitignored_nested_pubspecs() -> Result<(), Box<dyn std::error::Error>> {
|
|
682
|
+
let fixture = TempDir::new()?;
|
|
683
|
+
write(&fixture, ".gitignore", "scratch/\n")?;
|
|
684
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
685
|
+
write(&fixture, "scratch/pkg/pubspec.yaml", "name: pkg\n")?;
|
|
686
|
+
|
|
687
|
+
let packages = PackageMap::discover(fixture.path())?;
|
|
688
|
+
|
|
689
|
+
assert_eq!(packages.names(), vec!["app"]);
|
|
690
|
+
|
|
691
|
+
Ok(())
|
|
692
|
+
}
|
|
693
|
+
|
|
679
694
|
fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
|
|
680
695
|
let path = fixture.path().join(path);
|
|
681
696
|
if let Some(parent) = path.parent() {
|
package/src/scan.rs
CHANGED
|
@@ -2,8 +2,8 @@ use std::collections::{BTreeMap, BTreeSet};
|
|
|
2
2
|
use std::path::{Path, PathBuf};
|
|
3
3
|
|
|
4
4
|
use glob::Pattern;
|
|
5
|
-
use ignore::WalkBuilder;
|
|
6
5
|
use ignore::gitignore::GitignoreBuilder;
|
|
6
|
+
use ignore::{Walk, WalkBuilder};
|
|
7
7
|
use rayon::prelude::*;
|
|
8
8
|
use serde::{Deserialize, Serialize};
|
|
9
9
|
use thiserror::Error;
|
|
@@ -177,7 +177,7 @@ pub fn scan_project_with_options(
|
|
|
177
177
|
fn ignored_by_parent_gitignore(root: &Path, scan_root: &Path) -> bool {
|
|
178
178
|
let Some(repository_root) = root
|
|
179
179
|
.ancestors()
|
|
180
|
-
.find(|ancestor|
|
|
180
|
+
.find(|ancestor| is_repository_root(ancestor))
|
|
181
181
|
else {
|
|
182
182
|
return false;
|
|
183
183
|
};
|
|
@@ -222,27 +222,7 @@ fn discover_dart_files(
|
|
|
222
222
|
ignore_matcher: &IgnoreMatcher,
|
|
223
223
|
paths: &mut BTreeSet<PathBuf>,
|
|
224
224
|
) -> Result<(), ScanError> {
|
|
225
|
-
|
|
226
|
-
let filter_matcher = ignore_matcher.clone();
|
|
227
|
-
let has_repository_ancestor = dir
|
|
228
|
-
.ancestors()
|
|
229
|
-
.any(|ancestor| ancestor.join(".git").exists() || ancestor.join(".jj").exists());
|
|
230
|
-
let mut builder = WalkBuilder::new(dir);
|
|
231
|
-
builder
|
|
232
|
-
.standard_filters(false)
|
|
233
|
-
.git_ignore(true)
|
|
234
|
-
.parents(has_repository_ancestor)
|
|
235
|
-
.require_git(has_repository_ancestor)
|
|
236
|
-
.filter_entry(move |entry| {
|
|
237
|
-
entry.depth() == 0
|
|
238
|
-
|| !(filter_matcher.matches(&filter_root, entry.path())
|
|
239
|
-
|| entry
|
|
240
|
-
.file_type()
|
|
241
|
-
.is_some_and(|file_type| file_type.is_dir())
|
|
242
|
-
&& should_skip_dir(entry.path()))
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
for result in builder.build() {
|
|
225
|
+
for result in project_walk(root, dir, ignore_matcher) {
|
|
246
226
|
let entry = result.map_err(|source| ScanError::Walk {
|
|
247
227
|
path: dir.to_path_buf(),
|
|
248
228
|
source,
|
|
@@ -262,6 +242,29 @@ fn discover_dart_files(
|
|
|
262
242
|
Ok(())
|
|
263
243
|
}
|
|
264
244
|
|
|
245
|
+
/// Walk `dir` with the project's ignore rules: `.gitignore`, the configured
|
|
246
|
+
/// ignore patterns, skipped tool directories and nested checkouts.
|
|
247
|
+
pub(crate) fn project_walk(root: &Path, dir: &Path, ignore_matcher: &IgnoreMatcher) -> Walk {
|
|
248
|
+
let filter_root = root.to_path_buf();
|
|
249
|
+
let filter_matcher = ignore_matcher.clone();
|
|
250
|
+
let has_repository_ancestor = dir.ancestors().any(is_repository_root);
|
|
251
|
+
let mut builder = WalkBuilder::new(dir);
|
|
252
|
+
builder
|
|
253
|
+
.standard_filters(false)
|
|
254
|
+
.git_ignore(true)
|
|
255
|
+
.parents(has_repository_ancestor)
|
|
256
|
+
.require_git(has_repository_ancestor)
|
|
257
|
+
.filter_entry(move |entry| {
|
|
258
|
+
entry.depth() == 0
|
|
259
|
+
|| !(filter_matcher.matches(&filter_root, entry.path())
|
|
260
|
+
|| entry
|
|
261
|
+
.file_type()
|
|
262
|
+
.is_some_and(|file_type| file_type.is_dir())
|
|
263
|
+
&& (should_skip_dir(entry.path()) || is_repository_root(entry.path())))
|
|
264
|
+
});
|
|
265
|
+
builder.build()
|
|
266
|
+
}
|
|
267
|
+
|
|
265
268
|
fn tracked_dart_files(
|
|
266
269
|
root: &Path,
|
|
267
270
|
scan_root: &Path,
|
|
@@ -301,6 +304,12 @@ fn has_skipped_directory(root: &Path, path: &Path) -> bool {
|
|
|
301
304
|
.is_some_and(|parent| parent.ancestors().any(should_skip_dir))
|
|
302
305
|
}
|
|
303
306
|
|
|
307
|
+
/// Whether `dir` is the root of its own Git or Jujutsu checkout, such as a
|
|
308
|
+
/// nested worktree or clone, which belongs to a separate package graph.
|
|
309
|
+
pub(crate) fn is_repository_root(dir: &Path) -> bool {
|
|
310
|
+
dir.join(".git").exists() || dir.join(".jj").exists()
|
|
311
|
+
}
|
|
312
|
+
|
|
304
313
|
fn should_skip_dir(path: &Path) -> bool {
|
|
305
314
|
matches!(
|
|
306
315
|
path.file_name().and_then(|name| name.to_str()),
|
|
@@ -308,8 +317,8 @@ fn should_skip_dir(path: &Path) -> bool {
|
|
|
308
317
|
)
|
|
309
318
|
}
|
|
310
319
|
|
|
311
|
-
#[derive(Debug, Clone)]
|
|
312
|
-
struct IgnoreMatcher {
|
|
320
|
+
#[derive(Debug, Clone, Default)]
|
|
321
|
+
pub(crate) struct IgnoreMatcher {
|
|
313
322
|
patterns: Vec<Pattern>,
|
|
314
323
|
}
|
|
315
324
|
|