dart-decimate 0.0.75 → 0.0.77
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 +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -10
- package/package.json +2 -2
- package/src/baseline.rs +5 -16
- package/src/cli/issue_filter_args.rs +10 -0
- package/src/config/rule_aliases.rs +6 -0
- package/src/config/rules.rs +3 -6
- package/src/dependencies/analyze.rs +14 -3
- package/src/dependencies/overrides.rs +9 -1
- package/src/dependencies/package_cycles.rs +69 -0
- package/src/dependencies/package_graph.rs +53 -0
- package/src/dependencies/usage.rs +9 -0
- package/src/dependencies.rs +63 -8
- package/src/explain.rs +21 -9
- package/src/extract/members.rs +159 -6
- package/src/extract/tests.rs +35 -0
- package/src/extract.rs +48 -51
- package/src/generated.rs +10 -1
- package/src/graph/augment_tests.rs +1 -0
- package/src/graph/package_config_tests.rs +3 -0
- package/src/graph/pubspec_tests.rs +1 -0
- package/src/graph/tests.rs +3 -0
- package/src/graph/uri_tests.rs +1 -0
- package/src/health/coverage.rs +1 -1
- package/src/health/tests.rs +54 -0
- package/src/health/thresholds.rs +1 -1
- package/src/health/types.rs +2 -2
- package/src/intelligence/tests.rs +2 -0
- package/src/lib.rs +5 -10
- package/src/manifest.rs +3 -2
- package/src/mcp/cli_args/value_args.rs +1 -0
- package/src/output/dependency_findings.rs +41 -2
- package/src/output/human_details.rs +8 -0
- package/src/output/suppressions.rs +1 -0
- package/src/output/symbol_findings.rs +6 -2
- package/src/output/types.rs +10 -6
- package/src/output.rs +2 -0
- package/src/report_schema.rs +2 -0
- package/src/security_gate.rs +3 -6
- package/src/symbols/duplicate_declarations.rs +237 -0
- package/src/symbols/tests.rs +1 -0
- package/src/symbols.rs +354 -10
- package/src/widgets/resolution.rs +6 -6
- package/src/widgets.rs +1 -4
package/Cargo.lock
CHANGED
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
|
-
pnpm dlx dart-decimate@0.0.
|
|
93
|
+
pnpm dlx dart-decimate@0.0.77
|
|
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.77"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
```
|
|
@@ -117,7 +117,7 @@ pnpm run dart-decimate
|
|
|
117
117
|
If you prefer Cargo, install the matching tagged source:
|
|
118
118
|
|
|
119
119
|
```bash
|
|
120
|
-
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.
|
|
120
|
+
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.77 --locked
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
The npm release `X.Y.Z` and Cargo tag `vX.Y.Z` are verified against each other
|
|
@@ -128,7 +128,7 @@ Confirm a Cargo build's version with:
|
|
|
128
128
|
|
|
129
129
|
```bash
|
|
130
130
|
dart-decimate --version
|
|
131
|
-
# dart-decimate 0.0.
|
|
131
|
+
# dart-decimate 0.0.77
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
## pnpm dlx
|
|
@@ -187,7 +187,7 @@ Dart Decimate finds:
|
|
|
187
187
|
- unused public exports
|
|
188
188
|
- unused type aliases
|
|
189
189
|
- unused enum values
|
|
190
|
-
- unused private class members
|
|
190
|
+
- unused private class members, and unused public members of classes in `lib/`
|
|
191
191
|
- unrendered Flutter widgets
|
|
192
192
|
- missing entry points
|
|
193
193
|
- stale `dart-decimate-ignore` comments
|
|
@@ -219,7 +219,7 @@ Cyclomatic complexity means "how many paths can this function take?"
|
|
|
219
219
|
Cognitive complexity means "how hard is this function to understand?"
|
|
220
220
|
|
|
221
221
|
CRAP score combines complexity with test coverage. A complex function with poor
|
|
222
|
-
coverage gets a worse score.
|
|
222
|
+
coverage gets a worse score. A score equal to `max_crap` is reported.
|
|
223
223
|
|
|
224
224
|
Dart Decimate finds:
|
|
225
225
|
|
|
@@ -337,6 +337,7 @@ Dart Decimate finds:
|
|
|
337
337
|
- imports missing from `pubspec.yaml`
|
|
338
338
|
- unused dependency overrides
|
|
339
339
|
- invalid dependency overrides
|
|
340
|
+
- local packages that depend on each other, even with no file import cycle
|
|
340
341
|
- imports into another package's private `lib/src`
|
|
341
342
|
- duplicate public API exports
|
|
342
343
|
|
|
@@ -539,7 +540,7 @@ Example shape:
|
|
|
539
540
|
{
|
|
540
541
|
"schema_version": "dart-decimate.report.v1",
|
|
541
542
|
"kind": "combined",
|
|
542
|
-
"tool": "dart-decimate 0.0.
|
|
543
|
+
"tool": "dart-decimate 0.0.77",
|
|
543
544
|
"command": "check",
|
|
544
545
|
"verdict": "fail",
|
|
545
546
|
"summary": {
|
|
@@ -555,7 +556,7 @@ Example shape:
|
|
|
555
556
|
|
|
556
557
|
The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
|
|
557
558
|
string includes the producing version so saved reports identify the exact
|
|
558
|
-
build, for example `dart-decimate 0.0.
|
|
559
|
+
build, for example `dart-decimate 0.0.77`.
|
|
559
560
|
|
|
560
561
|
When grouped security findings hide additional occurrences, `next_steps` can
|
|
561
562
|
include `review-security-surface`, which reruns
|
|
@@ -643,7 +644,7 @@ you need the installed binary's exact list.
|
|
|
643
644
|
For a complete repository check, including discovered local packages:
|
|
644
645
|
|
|
645
646
|
```bash
|
|
646
|
-
pnpm dlx dart-decimate@0.0.
|
|
647
|
+
pnpm dlx dart-decimate@0.0.77 --strict
|
|
647
648
|
```
|
|
648
649
|
|
|
649
650
|
This runs every enabled check from the repository root. The default duplication
|
|
@@ -686,7 +687,7 @@ This repository forbids `unsafe_code`.
|
|
|
686
687
|
|
|
687
688
|
## Release Flow
|
|
688
689
|
|
|
689
|
-
Current source version: `0.0.
|
|
690
|
+
Current source version: `0.0.77`.
|
|
690
691
|
|
|
691
692
|
After the first public release, changes should go through pull requests. PRs to
|
|
692
693
|
`main` must bump both `Cargo.toml` and `package.json` above the base branch and to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.77",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "2.6.
|
|
58
|
+
"@biomejs/biome": "2.6.7",
|
|
59
59
|
"@types/node": "26.6.6"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/baseline.rs
CHANGED
|
@@ -192,12 +192,9 @@ pub fn regression_baseline_from_report(report: &JsonReport) -> RegressionBaselin
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
/// Load a baseline from disk.
|
|
195
|
+
/// Load a baseline from disk, failing on an unreadable, malformed or unsupported file.
|
|
196
196
|
///
|
|
197
197
|
/// # Errors
|
|
198
|
-
///
|
|
199
|
-
/// Returns [`BaselineError`] when the file is unreadable, malformed, or uses an
|
|
200
|
-
/// unsupported schema version.
|
|
201
198
|
pub fn load_baseline(path: impl AsRef<Path>) -> Result<Baseline, BaselineError> {
|
|
202
199
|
let path = path.as_ref();
|
|
203
200
|
let source = fs::read_to_string(path).map_err(|source| BaselineError::Read {
|
|
@@ -218,12 +215,9 @@ pub fn load_baseline(path: impl AsRef<Path>) -> Result<Baseline, BaselineError>
|
|
|
218
215
|
Ok(baseline)
|
|
219
216
|
}
|
|
220
217
|
|
|
221
|
-
/// Load a count-based regression baseline
|
|
218
|
+
/// Load a count-based regression baseline, failing on an unreadable, malformed or unsupported file.
|
|
222
219
|
///
|
|
223
220
|
/// # Errors
|
|
224
|
-
///
|
|
225
|
-
/// Returns [`BaselineError`] when the file is unreadable, malformed, or uses an
|
|
226
|
-
/// unsupported schema version.
|
|
227
221
|
pub fn load_regression_baseline(
|
|
228
222
|
path: impl AsRef<Path>,
|
|
229
223
|
) -> Result<RegressionBaseline, BaselineError> {
|
|
@@ -247,22 +241,16 @@ pub fn load_regression_baseline(
|
|
|
247
241
|
Ok(baseline)
|
|
248
242
|
}
|
|
249
243
|
|
|
250
|
-
/// Save a baseline to disk.
|
|
244
|
+
/// Save a baseline to disk, failing when the directory or file cannot be written.
|
|
251
245
|
///
|
|
252
246
|
/// # Errors
|
|
253
|
-
///
|
|
254
|
-
/// Returns [`BaselineError`] when the parent directory cannot be created or the
|
|
255
|
-
/// file cannot be written.
|
|
256
247
|
pub fn save_baseline(path: impl AsRef<Path>, baseline: &Baseline) -> Result<(), BaselineError> {
|
|
257
248
|
save_json(path, baseline)
|
|
258
249
|
}
|
|
259
250
|
|
|
260
|
-
/// Save a count-based regression baseline
|
|
251
|
+
/// Save a count-based regression baseline, failing when the directory or file cannot be written.
|
|
261
252
|
///
|
|
262
253
|
/// # Errors
|
|
263
|
-
///
|
|
264
|
-
/// Returns [`BaselineError`] when the parent directory cannot be created or the
|
|
265
|
-
/// file cannot be written.
|
|
266
254
|
pub fn save_regression_baseline(
|
|
267
255
|
path: impl AsRef<Path>,
|
|
268
256
|
baseline: &RegressionBaseline,
|
|
@@ -575,6 +563,7 @@ fn recompute_summary(report: &mut JsonReport) {
|
|
|
575
563
|
&report.findings,
|
|
576
564
|
FindingKind::MisconfiguredDependencyOverride,
|
|
577
565
|
);
|
|
566
|
+
report.summary.package_cycles = kind_count(&report.findings, FindingKind::PackageCycle);
|
|
578
567
|
report.summary.unlisted_dependencies =
|
|
579
568
|
kind_count(&report.findings, FindingKind::UnlistedDependency);
|
|
580
569
|
report.summary.private_src_imports =
|
|
@@ -82,6 +82,10 @@ fn shared_issue_filter_command(command: Command) -> Command {
|
|
|
82
82
|
"misconfigured-dependency-overrides",
|
|
83
83
|
"Report only invalid pub dependency overrides",
|
|
84
84
|
))
|
|
85
|
+
.arg(filter_arg(
|
|
86
|
+
"package-cycles",
|
|
87
|
+
"Report only local packages that depend on each other",
|
|
88
|
+
))
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
pub(super) fn issue_filters(command: ReportCommand, matches: &ArgMatches) -> IssueFilters {
|
|
@@ -165,6 +169,12 @@ fn push_dependency_filters(matches: &ArgMatches, kinds: &mut Vec<FindingKind>) {
|
|
|
165
169
|
"misconfigured-dependency-overrides",
|
|
166
170
|
&[FindingKind::MisconfiguredDependencyOverride],
|
|
167
171
|
);
|
|
172
|
+
push_flag(
|
|
173
|
+
matches,
|
|
174
|
+
kinds,
|
|
175
|
+
"package-cycles",
|
|
176
|
+
&[FindingKind::PackageCycle],
|
|
177
|
+
);
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
fn push_graph_filters(matches: &ArgMatches, kinds: &mut Vec<FindingKind>) {
|
|
@@ -195,6 +195,7 @@ fn all_known_aliases() -> Vec<&'static str> {
|
|
|
195
195
|
FindingKind::TestOnlyDependency,
|
|
196
196
|
FindingKind::UnusedDependencyOverride,
|
|
197
197
|
FindingKind::MisconfiguredDependencyOverride,
|
|
198
|
+
FindingKind::PackageCycle,
|
|
198
199
|
FindingKind::UnlistedDependency,
|
|
199
200
|
FindingKind::CodeDuplication,
|
|
200
201
|
FindingKind::HighCyclomaticComplexity,
|
|
@@ -418,6 +419,11 @@ fn dependency_kind_aliases(kind: FindingKind) -> Option<Vec<&'static str>> {
|
|
|
418
419
|
FindingKind::MisconfiguredDependencyOverride => {
|
|
419
420
|
Some(misconfigured_dependency_override_aliases().into())
|
|
420
421
|
}
|
|
422
|
+
FindingKind::PackageCycle => Some(vec![
|
|
423
|
+
"dart-decimate/package-cycle",
|
|
424
|
+
"package-cycle",
|
|
425
|
+
"package-cycles",
|
|
426
|
+
]),
|
|
421
427
|
FindingKind::UnlistedDependency => Some(vec![
|
|
422
428
|
"dart-decimate/unlisted-dependency",
|
|
423
429
|
"unlisted-dependency",
|
package/src/config/rules.rs
CHANGED
|
@@ -25,11 +25,9 @@ pub enum RuleLevel {
|
|
|
25
25
|
/// Rule severity configuration keyed by rule id or alias.
|
|
26
26
|
pub type RuleConfig = BTreeMap<String, RuleLevel>;
|
|
27
27
|
|
|
28
|
-
/// Validate all configured rule names.
|
|
28
|
+
/// Validate all configured rule names, failing on an unsupported rule key.
|
|
29
29
|
///
|
|
30
30
|
/// # Errors
|
|
31
|
-
///
|
|
32
|
-
/// Returns [`RuleError`] when a rule key is not supported by Dart Decimate.
|
|
33
31
|
pub fn validate_rules(rules: &RuleConfig) -> Result<(), RuleError> {
|
|
34
32
|
let _ = RuleMatcher::new(rules)?;
|
|
35
33
|
Ok(())
|
|
@@ -57,11 +55,9 @@ pub fn missing_suppression_reasons_enabled(rules: &RuleConfig) -> bool {
|
|
|
57
55
|
})
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
/// Apply configured rule severities to
|
|
58
|
+
/// Apply configured rule severities to a built report, failing on an unsupported rule key.
|
|
61
59
|
///
|
|
62
60
|
/// # Errors
|
|
63
|
-
///
|
|
64
|
-
/// Returns [`RuleError`] when a rule key is not supported by Dart Decimate.
|
|
65
61
|
pub fn apply_rules_to_report(report: &mut JsonReport, rules: &RuleConfig) -> Result<(), RuleError> {
|
|
66
62
|
let rules = RuleMatcher::new(rules)?;
|
|
67
63
|
if rules.is_empty() {
|
|
@@ -203,6 +199,7 @@ fn recompute_summary(report: &mut JsonReport) {
|
|
|
203
199
|
&report.findings,
|
|
204
200
|
FindingKind::MisconfiguredDependencyOverride,
|
|
205
201
|
);
|
|
202
|
+
summary.package_cycles = kind_count(&report.findings, FindingKind::PackageCycle);
|
|
206
203
|
summary.unlisted_dependencies = kind_count(&report.findings, FindingKind::UnlistedDependency);
|
|
207
204
|
summary.private_src_imports = kind_count(&report.findings, FindingKind::PrivateSrcImport);
|
|
208
205
|
summary.dead_files = kind_count(&report.findings, FindingKind::DeadFile);
|
|
@@ -8,11 +8,11 @@ use crate::package_map::PackageMap;
|
|
|
8
8
|
use crate::{DartFile, DependencyKind, Location, extract_dart_file, scan::ScannedProject};
|
|
9
9
|
|
|
10
10
|
use super::codegen::codegen_dependencies_for_file;
|
|
11
|
-
use super::usage::DependencyUsage;
|
|
11
|
+
use super::usage::{DependencyUsage, is_library_file};
|
|
12
12
|
use super::{
|
|
13
13
|
DependencyHygieneError, DependencyHygieneReport, DependencyIssue, PrivateSrcImport, PubPackage,
|
|
14
14
|
UnlistedPackageDependency, UnusedPackageDependency, dependency_issue, discover_packages,
|
|
15
|
-
imports_private_src, owning_package, package_name,
|
|
15
|
+
imports_private_src, owning_package, package_cycles, package_name,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
type PackageUsage = BTreeMap<PathBuf, BTreeMap<String, DependencyUsage>>;
|
|
@@ -20,6 +20,7 @@ type PackageUsage = BTreeMap<PathBuf, BTreeMap<String, DependencyUsage>>;
|
|
|
20
20
|
#[derive(Default)]
|
|
21
21
|
struct ImportUsage {
|
|
22
22
|
used_by_package: PackageUsage,
|
|
23
|
+
library_imports: BTreeMap<PathBuf, BTreeSet<String>>,
|
|
23
24
|
unlisted_by_identity: BTreeMap<(PathBuf, String), UnlistedPackageDependency>,
|
|
24
25
|
private_src_imports: Vec<PrivateSrcImport>,
|
|
25
26
|
}
|
|
@@ -37,9 +38,11 @@ pub fn analyze_dependency_hygiene(
|
|
|
37
38
|
|
|
38
39
|
sort_unused_dependencies(&mut unused_dependencies);
|
|
39
40
|
sort_private_src_imports(&mut imports.private_src_imports);
|
|
41
|
+
let package_cycles = package_cycles(&packages, &imports.library_imports);
|
|
40
42
|
|
|
41
43
|
Ok(DependencyHygieneReport {
|
|
42
44
|
unused_dependencies,
|
|
45
|
+
package_cycles,
|
|
43
46
|
misconfigured_dependency_overrides: packages
|
|
44
47
|
.into_iter()
|
|
45
48
|
.flat_map(|package| package.misconfigured_dependency_overrides)
|
|
@@ -170,6 +173,14 @@ fn record_directive(
|
|
|
170
173
|
return;
|
|
171
174
|
}
|
|
172
175
|
|
|
176
|
+
if is_library_file(&owner.root, file_path) {
|
|
177
|
+
usage
|
|
178
|
+
.library_imports
|
|
179
|
+
.entry(owner.root.clone())
|
|
180
|
+
.or_default()
|
|
181
|
+
.insert(dependency.clone());
|
|
182
|
+
}
|
|
183
|
+
|
|
173
184
|
if imports_private_src(specifier) && !is_generated_dart_path(file_path) {
|
|
174
185
|
usage.private_src_imports.push(PrivateSrcImport {
|
|
175
186
|
package: owner.name.clone(),
|
|
@@ -264,7 +275,7 @@ fn unused_dependency(
|
|
|
264
275
|
usage.record_tooling();
|
|
265
276
|
}
|
|
266
277
|
let usage = usage.any().then_some(usage);
|
|
267
|
-
let issue = dependency_issue(dependency, usage.as_ref(), package
|
|
278
|
+
let issue = dependency_issue(dependency, usage.as_ref(), package)?;
|
|
268
279
|
Some(UnusedPackageDependency {
|
|
269
280
|
package: package.name.clone(),
|
|
270
281
|
pubspec_path: dependency.source_path.clone(),
|
|
@@ -37,6 +37,14 @@ pub enum DependencyOverrideMisconfigReason {
|
|
|
37
37
|
EmptyValue,
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
pub(super) fn is_blank_override_value(value: &Value) -> bool {
|
|
41
|
+
value.is_null() || value.as_str().is_some_and(|text| text.trim().is_empty())
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pub(super) fn is_honored_override_entry(name: &str, value: &Value) -> bool {
|
|
45
|
+
valid_dart_package_name(name) && !is_blank_override_value(value)
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
pub(super) fn misconfigured_dependency_overrides(
|
|
41
49
|
value: &Value,
|
|
42
50
|
source: &str,
|
|
@@ -52,7 +60,7 @@ pub(super) fn misconfigured_dependency_overrides(
|
|
|
52
60
|
let raw_key = name.clone();
|
|
53
61
|
let reason = if !valid_dart_package_name(name) {
|
|
54
62
|
DependencyOverrideMisconfigReason::UnparsableKey
|
|
55
|
-
} else if value
|
|
63
|
+
} else if is_blank_override_value(value) {
|
|
56
64
|
DependencyOverrideMisconfigReason::EmptyValue
|
|
57
65
|
} else {
|
|
58
66
|
return None;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
|
|
4
|
+
use petgraph::algo::tarjan_scc;
|
|
5
|
+
use petgraph::graph::DiGraph;
|
|
6
|
+
use serde::{Deserialize, Serialize};
|
|
7
|
+
|
|
8
|
+
use super::{DependencySection, PubPackage};
|
|
9
|
+
|
|
10
|
+
/// Local pub packages whose runtime dependencies, backed by `lib/` imports, form a loop.
|
|
11
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
12
|
+
pub struct PackageCycle {
|
|
13
|
+
/// Package names in the cycle, sorted for deterministic output.
|
|
14
|
+
pub packages: Vec<String>,
|
|
15
|
+
/// Pubspec paths of those packages, in the same order.
|
|
16
|
+
pub pubspec_paths: Vec<PathBuf>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pub(super) fn package_cycles(
|
|
20
|
+
packages: &[PubPackage],
|
|
21
|
+
library_imports: &BTreeMap<PathBuf, BTreeSet<String>>,
|
|
22
|
+
) -> Vec<PackageCycle> {
|
|
23
|
+
let mut graph = DiGraph::<usize, ()>::new();
|
|
24
|
+
let nodes = (0..packages.len())
|
|
25
|
+
.map(|index| graph.add_node(index))
|
|
26
|
+
.collect::<Vec<_>>();
|
|
27
|
+
let mut by_name = BTreeMap::new();
|
|
28
|
+
for (index, package) in packages.iter().enumerate() {
|
|
29
|
+
by_name.entry(package.name.as_str()).or_insert(index);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (index, package) in packages.iter().enumerate() {
|
|
33
|
+
let imported = library_imports.get(&package.root);
|
|
34
|
+
for dependency in &package.dependencies {
|
|
35
|
+
let Some(&target) = by_name.get(dependency.name.as_str()) else {
|
|
36
|
+
continue;
|
|
37
|
+
};
|
|
38
|
+
if target != index
|
|
39
|
+
&& dependency.section == DependencySection::Dependencies
|
|
40
|
+
&& imported.is_some_and(|imported| imported.contains(&dependency.name))
|
|
41
|
+
{
|
|
42
|
+
graph.update_edge(nodes[index], nodes[target], ());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let mut cycles = tarjan_scc(&graph)
|
|
48
|
+
.into_iter()
|
|
49
|
+
.filter(|component| component.len() > 1)
|
|
50
|
+
.map(|component| {
|
|
51
|
+
let mut members = component
|
|
52
|
+
.into_iter()
|
|
53
|
+
.map(|node| &packages[graph[node]])
|
|
54
|
+
.collect::<Vec<_>>();
|
|
55
|
+
members.sort_by(|left, right| {
|
|
56
|
+
(&left.name, &left.pubspec_path).cmp(&(&right.name, &right.pubspec_path))
|
|
57
|
+
});
|
|
58
|
+
PackageCycle {
|
|
59
|
+
packages: members.iter().map(|package| package.name.clone()).collect(),
|
|
60
|
+
pubspec_paths: members
|
|
61
|
+
.iter()
|
|
62
|
+
.map(|package| package.pubspec_path.clone())
|
|
63
|
+
.collect(),
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.collect::<Vec<_>>();
|
|
67
|
+
cycles.sort_by(|left, right| left.packages.cmp(&right.packages));
|
|
68
|
+
cycles
|
|
69
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
use std::fs;
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
use serde::Deserialize;
|
|
6
|
+
|
|
7
|
+
#[derive(Deserialize)]
|
|
8
|
+
struct PackageGraphFile {
|
|
9
|
+
roots: Vec<String>,
|
|
10
|
+
packages: Vec<PackageGraphEntry>,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#[derive(Deserialize)]
|
|
14
|
+
struct PackageGraphEntry {
|
|
15
|
+
name: String,
|
|
16
|
+
#[serde(default)]
|
|
17
|
+
dependencies: Vec<String>,
|
|
18
|
+
#[serde(default, rename = "devDependencies")]
|
|
19
|
+
dev_dependencies: Vec<String>,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub(super) fn needed_packages(package_root: &Path, package_name: &str) -> Option<BTreeSet<String>> {
|
|
23
|
+
let source = package_root
|
|
24
|
+
.ancestors()
|
|
25
|
+
.map(|dir| dir.join(".dart_tool/package_graph.json"))
|
|
26
|
+
.find(|path| path.is_file())
|
|
27
|
+
.and_then(|path| fs::read_to_string(path).ok())?;
|
|
28
|
+
let graph = serde_json::from_str::<PackageGraphFile>(&source).ok()?;
|
|
29
|
+
if !graph.roots.iter().any(|root| root == package_name) {
|
|
30
|
+
return None;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let edges = graph
|
|
34
|
+
.packages
|
|
35
|
+
.iter()
|
|
36
|
+
.map(|package| (package.name.as_str(), package))
|
|
37
|
+
.collect::<BTreeMap<_, _>>();
|
|
38
|
+
let mut needed = BTreeSet::new();
|
|
39
|
+
let mut frontier = graph.roots.iter().map(String::as_str).collect::<Vec<_>>();
|
|
40
|
+
while let Some(name) = frontier.pop() {
|
|
41
|
+
if !needed.insert(name.to_owned()) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let Some(package) = edges.get(name) else {
|
|
45
|
+
continue;
|
|
46
|
+
};
|
|
47
|
+
frontier.extend(package.dependencies.iter().map(String::as_str));
|
|
48
|
+
if graph.roots.iter().any(|root| root == name) {
|
|
49
|
+
frontier.extend(package.dev_dependencies.iter().map(String::as_str));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
Some(needed)
|
|
53
|
+
}
|
|
@@ -24,6 +24,15 @@ impl DependencyUsage {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
pub(super) fn is_library_file(package_root: &Path, path: &Path) -> bool {
|
|
28
|
+
path.strip_prefix(package_root).is_ok_and(|relative| {
|
|
29
|
+
matches!(
|
|
30
|
+
relative.components().next(),
|
|
31
|
+
Some(std::path::Component::Normal(name)) if name == "lib"
|
|
32
|
+
)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
pub(super) fn allows_dev_dependency(package_root: &Path, path: &Path) -> bool {
|
|
28
37
|
let relative = path.strip_prefix(package_root).unwrap_or(path);
|
|
29
38
|
!matches!(
|
package/src/dependencies.rs
CHANGED
|
@@ -16,14 +16,18 @@ pub(crate) use codegen::file_uses_codegen_dependency;
|
|
|
16
16
|
mod discovery;
|
|
17
17
|
mod flutter_usage;
|
|
18
18
|
mod overrides;
|
|
19
|
+
mod package_cycles;
|
|
20
|
+
mod package_graph;
|
|
19
21
|
mod private_src_imports;
|
|
20
22
|
mod pubspec_document;
|
|
21
23
|
mod pubspec_entry;
|
|
22
24
|
mod usage;
|
|
23
25
|
pub use analyze::analyze_dependency_hygiene;
|
|
24
26
|
use discovery::discover_packages;
|
|
25
|
-
use overrides::misconfigured_dependency_overrides;
|
|
26
27
|
pub use overrides::{DependencyOverrideMisconfigReason, MisconfiguredDependencyOverride};
|
|
28
|
+
use overrides::{is_honored_override_entry, misconfigured_dependency_overrides};
|
|
29
|
+
pub use package_cycles::PackageCycle;
|
|
30
|
+
use package_cycles::package_cycles;
|
|
27
31
|
pub use private_src_imports::PrivateSrcImport;
|
|
28
32
|
use private_src_imports::imports_private_src;
|
|
29
33
|
use pubspec_document::{declared_dependencies_from_source, dependency_location};
|
|
@@ -40,6 +44,8 @@ pub struct DependencyHygieneReport {
|
|
|
40
44
|
pub unlisted_dependencies: Vec<UnlistedPackageDependency>,
|
|
41
45
|
/// Imports into another package's private `lib/src` implementation tree.
|
|
42
46
|
pub private_src_imports: Vec<PrivateSrcImport>,
|
|
47
|
+
/// Local packages that depend on each other through their pubspecs.
|
|
48
|
+
pub package_cycles: Vec<PackageCycle>,
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
/// A declared pub dependency that has no Dart import/export usage.
|
|
@@ -132,7 +138,7 @@ pub enum DependencyIssue {
|
|
|
132
138
|
DevDependencyInProduction,
|
|
133
139
|
/// Runtime dependency is imported only from development-only files.
|
|
134
140
|
TestOnlyDependency,
|
|
135
|
-
/// Dependency override is absent from the resolved
|
|
141
|
+
/// Dependency override is absent from the lockfile or not reached by the resolved package graph.
|
|
136
142
|
UnusedDependencyOverride,
|
|
137
143
|
}
|
|
138
144
|
|
|
@@ -283,6 +289,43 @@ pub(super) struct PubPackage {
|
|
|
283
289
|
flutter_metadata_dependencies: BTreeSet<String>,
|
|
284
290
|
misconfigured_dependency_overrides: Vec<MisconfiguredDependencyOverride>,
|
|
285
291
|
locked_packages: Option<BTreeSet<String>>,
|
|
292
|
+
needed_packages: Option<BTreeSet<String>>,
|
|
293
|
+
application: bool,
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
pub(crate) struct PackageScope {
|
|
297
|
+
pub(crate) root: PathBuf,
|
|
298
|
+
pub(crate) application: bool,
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
pub(crate) fn package_scopes(root: &Path) -> Vec<PackageScope> {
|
|
302
|
+
discover_packages(root)
|
|
303
|
+
.unwrap_or_default()
|
|
304
|
+
.into_iter()
|
|
305
|
+
.map(|package| PackageScope {
|
|
306
|
+
root: package.root,
|
|
307
|
+
application: package.application,
|
|
308
|
+
})
|
|
309
|
+
.collect()
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
fn is_application(value: &Value, root: &Path, name: &str) -> bool {
|
|
313
|
+
if root.join("lib").join(format!("{name}.dart")).is_file() {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
let has_main = root.join("lib").join("main.dart").is_file();
|
|
317
|
+
if string_field(value, "publish_to") == Some("none") {
|
|
318
|
+
return has_main
|
|
319
|
+
|| fs::read_dir(root.join("bin")).is_ok_and(|entries| {
|
|
320
|
+
entries
|
|
321
|
+
.flatten()
|
|
322
|
+
.any(|entry| entry.path().extension().is_some_and(|ext| ext == "dart"))
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
has_main
|
|
326
|
+
&& mapping_field(value, "dependencies")
|
|
327
|
+
.is_some_and(|dependencies| dependencies.contains_key("flutter"))
|
|
328
|
+
&& !mapping_field(value, "flutter").is_some_and(|flutter| flutter.contains_key("plugin"))
|
|
286
329
|
}
|
|
287
330
|
|
|
288
331
|
impl PubPackage {
|
|
@@ -319,7 +362,7 @@ struct DeclaredDependency {
|
|
|
319
362
|
fn dependency_issue(
|
|
320
363
|
dependency: &DeclaredDependency,
|
|
321
364
|
usage: Option<&DependencyUsage>,
|
|
322
|
-
|
|
365
|
+
package: &PubPackage,
|
|
323
366
|
) -> Option<DependencyIssue> {
|
|
324
367
|
match dependency.section {
|
|
325
368
|
DependencySection::Dependencies => match usage {
|
|
@@ -332,10 +375,17 @@ fn dependency_issue(
|
|
|
332
375
|
Some(_) => None,
|
|
333
376
|
None => Some(DependencyIssue::UnusedDevDependency),
|
|
334
377
|
},
|
|
335
|
-
DependencySection::DependencyOverrides =>
|
|
336
|
-
|
|
337
|
-
.
|
|
338
|
-
|
|
378
|
+
DependencySection::DependencyOverrides => {
|
|
379
|
+
let missing_from_lock = package
|
|
380
|
+
.locked_packages
|
|
381
|
+
.as_ref()
|
|
382
|
+
.is_some_and(|locked| !locked.contains(&dependency.name));
|
|
383
|
+
let unneeded = package
|
|
384
|
+
.needed_packages
|
|
385
|
+
.as_ref()
|
|
386
|
+
.is_some_and(|needed| !needed.contains(&dependency.name));
|
|
387
|
+
(missing_from_lock || unneeded).then_some(DependencyIssue::UnusedDependencyOverride)
|
|
388
|
+
}
|
|
339
389
|
}
|
|
340
390
|
}
|
|
341
391
|
|
|
@@ -353,6 +403,9 @@ pub(super) fn read_package(path: &Path) -> Result<Option<PubPackage>, Dependency
|
|
|
353
403
|
let overrides = read_pubspec_overrides(&root)?;
|
|
354
404
|
let flutter_metadata_dependencies = flutter_usage::flutter_metadata_dependencies(&root, &value);
|
|
355
405
|
|
|
406
|
+
let needed_packages = package_graph::needed_packages(&root, name);
|
|
407
|
+
let application = is_application(&value, &root, name);
|
|
408
|
+
|
|
356
409
|
Ok(Some(PubPackage {
|
|
357
410
|
name: name.to_owned(),
|
|
358
411
|
root,
|
|
@@ -367,6 +420,8 @@ pub(super) fn read_package(path: &Path) -> Result<Option<PubPackage>, Dependency
|
|
|
367
420
|
overrides.as_ref(),
|
|
368
421
|
),
|
|
369
422
|
locked_packages: read_locked_packages(path),
|
|
423
|
+
needed_packages,
|
|
424
|
+
application,
|
|
370
425
|
}))
|
|
371
426
|
}
|
|
372
427
|
|
|
@@ -507,7 +562,7 @@ fn declared_dependencies_for_sections(
|
|
|
507
562
|
mapping.iter().filter_map(move |(name, value)| {
|
|
508
563
|
let name = name.clone();
|
|
509
564
|
if section == DependencySection::DependencyOverrides
|
|
510
|
-
&&
|
|
565
|
+
&& !is_honored_override_entry(&name, value)
|
|
511
566
|
{
|
|
512
567
|
return None;
|
|
513
568
|
}
|