dart-decimate 0.0.62 → 0.0.64
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 +10 -9
- package/package.json +1 -1
- package/src/dependencies/analyze.rs +5 -5
- package/src/dependency_scripts.rs +104 -8
- package/src/trace.rs +8 -6
- package/src/widgets/unrendered.rs +32 -2
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.64
|
|
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.64"
|
|
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.64 --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.64
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
## pnpm dlx
|
|
@@ -346,7 +346,8 @@ imports and owner-local path dependencies local. Workspace members and copied
|
|
|
346
346
|
nested packages with the same package name are resolved by owner. Non-Dart
|
|
347
347
|
tooling references in Flutter config files, including launcher and splash
|
|
348
348
|
config, workflow files, Makefiles, and `tool/` scripts can count as dependency
|
|
349
|
-
usage.
|
|
349
|
+
usage. Shell scripts anywhere in a package count a dependency they invoke with
|
|
350
|
+
`dart run <pkg>`, `dart pub run <pkg>`, or `flutter pub run <pkg>`. Envied annotations count `envied_generator`/`build_runner`, FlutterGen
|
|
350
351
|
configuration counts `flutter_gen_runner`, and Dart tests count the `test`
|
|
351
352
|
runner. Known generator-internal imports from generated Dart, such as
|
|
352
353
|
`package:slang/generated.dart`, are not reported as unlisted dependencies.
|
|
@@ -538,7 +539,7 @@ Example shape:
|
|
|
538
539
|
{
|
|
539
540
|
"schema_version": "dart-decimate.report.v1",
|
|
540
541
|
"kind": "combined",
|
|
541
|
-
"tool": "dart-decimate 0.0.
|
|
542
|
+
"tool": "dart-decimate 0.0.64",
|
|
542
543
|
"command": "check",
|
|
543
544
|
"verdict": "fail",
|
|
544
545
|
"summary": {
|
|
@@ -554,7 +555,7 @@ Example shape:
|
|
|
554
555
|
|
|
555
556
|
The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
|
|
556
557
|
string includes the producing version so saved reports identify the exact
|
|
557
|
-
build, for example `dart-decimate 0.0.
|
|
558
|
+
build, for example `dart-decimate 0.0.64`.
|
|
558
559
|
|
|
559
560
|
When grouped security findings hide additional occurrences, `next_steps` can
|
|
560
561
|
include `review-security-surface`, which reruns
|
|
@@ -642,7 +643,7 @@ you need the installed binary's exact list.
|
|
|
642
643
|
For a complete repository check, including discovered local packages:
|
|
643
644
|
|
|
644
645
|
```bash
|
|
645
|
-
pnpm dlx dart-decimate@0.0.
|
|
646
|
+
pnpm dlx dart-decimate@0.0.64 --strict
|
|
646
647
|
```
|
|
647
648
|
|
|
648
649
|
This runs every enabled check from the repository root. The default duplication
|
|
@@ -685,7 +686,7 @@ This repository forbids `unsafe_code`.
|
|
|
685
686
|
|
|
686
687
|
## Release Flow
|
|
687
688
|
|
|
688
|
-
Current source version: `0.0.
|
|
689
|
+
Current source version: `0.0.64`.
|
|
689
690
|
|
|
690
691
|
After the first public release, changes should go through pull requests. PRs to
|
|
691
692
|
`main` must bump both `Cargo.toml` and `package.json` above the base branch and to
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use std::collections::{BTreeMap, BTreeSet};
|
|
2
2
|
use std::path::{Path, PathBuf};
|
|
3
3
|
|
|
4
|
-
use crate::dependency_scripts::package_used_in_tooling;
|
|
4
|
+
use crate::dependency_scripts::{package_used_in_tooling, shell_script_packages};
|
|
5
5
|
use crate::generated::is_generated_dart_path;
|
|
6
6
|
use crate::graph::resolve_local_uri;
|
|
7
7
|
use crate::package_map::PackageMap;
|
|
@@ -24,8 +24,6 @@ struct ImportUsage {
|
|
|
24
24
|
private_src_imports: Vec<PrivateSrcImport>,
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/// Analyze Dart `package:` imports against pubspec dependency declarations.
|
|
28
|
-
///
|
|
29
27
|
/// # Errors
|
|
30
28
|
///
|
|
31
29
|
/// Returns [`DependencyHygieneError`] if pubspec discovery or parsing fails.
|
|
@@ -233,8 +231,9 @@ fn unused_dependencies(
|
|
|
233
231
|
let mut unused_dependencies = Vec::new();
|
|
234
232
|
for package in packages {
|
|
235
233
|
let used = used_by_package.get(&package.root);
|
|
234
|
+
let script_packages = shell_script_packages(&package.root);
|
|
236
235
|
for dependency in &package.dependencies {
|
|
237
|
-
if let Some(unused) = unused_dependency(package, dependency, used) {
|
|
236
|
+
if let Some(unused) = unused_dependency(package, dependency, used, &script_packages) {
|
|
238
237
|
unused_dependencies.push(unused);
|
|
239
238
|
}
|
|
240
239
|
}
|
|
@@ -246,6 +245,7 @@ fn unused_dependency(
|
|
|
246
245
|
package: &PubPackage,
|
|
247
246
|
dependency: &super::DeclaredDependency,
|
|
248
247
|
used: Option<&BTreeMap<String, DependencyUsage>>,
|
|
248
|
+
script_packages: &BTreeSet<String>,
|
|
249
249
|
) -> Option<UnusedPackageDependency> {
|
|
250
250
|
if dependency.name == package.name {
|
|
251
251
|
return None;
|
|
@@ -260,7 +260,7 @@ fn unused_dependency(
|
|
|
260
260
|
.and_then(|used| used.get(&dependency.name))
|
|
261
261
|
.copied()
|
|
262
262
|
.unwrap_or_default();
|
|
263
|
-
if package_used_in_tooling(&package.root, &dependency.name) {
|
|
263
|
+
if package_used_in_tooling(&package.root, &dependency.name, script_packages) {
|
|
264
264
|
usage.record_tooling();
|
|
265
265
|
}
|
|
266
266
|
let usage = usage.any().then_some(usage);
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
use std::collections::BTreeSet;
|
|
1
2
|
use std::fs;
|
|
2
3
|
use std::path::{Path, PathBuf};
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
use crate::scan::{IgnoreMatcher, project_walk};
|
|
6
|
+
|
|
7
|
+
pub(crate) fn package_used_in_tooling(
|
|
8
|
+
package_root: &Path,
|
|
9
|
+
dependency: &str,
|
|
10
|
+
script_packages: &BTreeSet<String>,
|
|
11
|
+
) -> bool {
|
|
12
|
+
script_packages.contains(dependency)
|
|
13
|
+
|| pubspec_has_top_level_key(package_root, dependency)
|
|
6
14
|
|| known_tooling_convention(package_root, dependency)
|
|
7
15
|
|| tooling_files(package_root).into_iter().any(|path| {
|
|
8
16
|
fs::read_to_string(path)
|
|
@@ -87,13 +95,75 @@ fn collect_matching_files(dir: &Path, paths: &mut Vec<PathBuf>) {
|
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
fn is_tooling_file(path: &Path) -> bool {
|
|
98
|
+
is_shell_script(path)
|
|
99
|
+
|| matches!(
|
|
100
|
+
path.extension().and_then(|extension| extension.to_str()),
|
|
101
|
+
Some("yaml" | "yml")
|
|
102
|
+
)
|
|
103
|
+
|| path
|
|
104
|
+
.file_name()
|
|
105
|
+
.and_then(|name| name.to_str())
|
|
106
|
+
.is_some_and(|name| name == "Makefile")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fn is_shell_script(path: &Path) -> bool {
|
|
90
110
|
matches!(
|
|
91
111
|
path.extension().and_then(|extension| extension.to_str()),
|
|
92
|
-
Some("
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
Some("sh" | "bash" | "zsh")
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
pub(crate) fn shell_script_packages(package_root: &Path) -> BTreeSet<String> {
|
|
117
|
+
let mut packages = BTreeSet::new();
|
|
118
|
+
for entry in project_walk(package_root, package_root, &IgnoreMatcher::default()).flatten() {
|
|
119
|
+
let path = entry.path();
|
|
120
|
+
if entry
|
|
121
|
+
.file_type()
|
|
122
|
+
.is_some_and(|file_type| file_type.is_file())
|
|
123
|
+
&& is_shell_script(path)
|
|
124
|
+
&& owned_by_package(package_root, path)
|
|
125
|
+
&& let Ok(source) = fs::read_to_string(path)
|
|
126
|
+
{
|
|
127
|
+
collect_run_packages(&source, &mut packages);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
packages
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fn owned_by_package(package_root: &Path, path: &Path) -> bool {
|
|
134
|
+
path.ancestors()
|
|
135
|
+
.skip(1)
|
|
136
|
+
.take_while(|dir| *dir != package_root)
|
|
137
|
+
.all(|dir| !dir.join("pubspec.yaml").is_file())
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
fn collect_run_packages(source: &str, packages: &mut BTreeSet<String>) {
|
|
141
|
+
for line in source.replace("\\\n", " ").lines() {
|
|
142
|
+
let words = line
|
|
143
|
+
.split(|ch: char| ch.is_whitespace() || ";&|()`\"'".contains(ch))
|
|
144
|
+
.filter(|word| !word.is_empty())
|
|
145
|
+
.take_while(|word| !word.starts_with('#'))
|
|
146
|
+
.collect::<Vec<_>>();
|
|
147
|
+
for (index, word) in words.iter().enumerate() {
|
|
148
|
+
let arguments = match (
|
|
149
|
+
word.rsplit('/').next(),
|
|
150
|
+
words.get(index + 1),
|
|
151
|
+
words.get(index + 2),
|
|
152
|
+
) {
|
|
153
|
+
(Some("dart"), Some(&"run"), _) => &words[index + 2..],
|
|
154
|
+
(Some("dart" | "flutter"), Some(&"pub"), Some(&"run")) => &words[index + 3..],
|
|
155
|
+
_ => continue,
|
|
156
|
+
};
|
|
157
|
+
if let Some(package) = arguments
|
|
158
|
+
.iter()
|
|
159
|
+
.find(|argument| !argument.starts_with('-'))
|
|
160
|
+
.and_then(|target| target.split(':').next())
|
|
161
|
+
.filter(|package| !package.is_empty())
|
|
162
|
+
{
|
|
163
|
+
packages.insert(package.to_owned());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
97
167
|
}
|
|
98
168
|
|
|
99
169
|
fn source_mentions_dependency(source: &str, dependency: &str) -> bool {
|
|
@@ -105,7 +175,33 @@ fn source_mentions_dependency(source: &str, dependency: &str) -> bool {
|
|
|
105
175
|
|
|
106
176
|
#[cfg(test)]
|
|
107
177
|
mod tests {
|
|
108
|
-
use
|
|
178
|
+
use std::collections::BTreeSet;
|
|
179
|
+
|
|
180
|
+
use super::{collect_run_packages, source_mentions_dependency};
|
|
181
|
+
|
|
182
|
+
#[test]
|
|
183
|
+
fn collects_packages_only_from_run_commands() {
|
|
184
|
+
let mut packages = BTreeSet::new();
|
|
185
|
+
collect_run_packages(
|
|
186
|
+
"set -e\n\
|
|
187
|
+
dart run sentry_dart_plugin\n\
|
|
188
|
+
fvm flutter pub run flutter_launcher_icons:main\n\
|
|
189
|
+
\"$FLUTTER_ROOT/bin/dart\" pub run --verbose build_runner build\n\
|
|
190
|
+
dart run \\\n --enable-asserts melos:melos bootstrap\n\
|
|
191
|
+
# dart run commented_out\n\
|
|
192
|
+
echo dart pub get mentioned_package\n",
|
|
193
|
+
&mut packages,
|
|
194
|
+
);
|
|
195
|
+
assert_eq!(
|
|
196
|
+
packages.into_iter().collect::<Vec<_>>(),
|
|
197
|
+
[
|
|
198
|
+
"build_runner",
|
|
199
|
+
"flutter_launcher_icons",
|
|
200
|
+
"melos",
|
|
201
|
+
"sentry_dart_plugin"
|
|
202
|
+
]
|
|
203
|
+
);
|
|
204
|
+
}
|
|
109
205
|
|
|
110
206
|
#[test]
|
|
111
207
|
fn matches_dependency_tokens_without_substrings() {
|
package/src/trace.rs
CHANGED
|
@@ -7,7 +7,7 @@ use crate::dependencies::{
|
|
|
7
7
|
DeclaredPackageDependency, LocalPubPackage, declared_package_dependencies,
|
|
8
8
|
file_uses_codegen_dependency, local_pub_packages,
|
|
9
9
|
};
|
|
10
|
-
use crate::dependency_scripts::package_used_in_tooling;
|
|
10
|
+
use crate::dependency_scripts::{package_used_in_tooling, shell_script_packages};
|
|
11
11
|
use crate::graph::normalize_against;
|
|
12
12
|
use crate::output::TRACE_SCHEMA_VERSION;
|
|
13
13
|
use crate::semantic::{SemanticDecision, SemanticIdentity};
|
|
@@ -331,8 +331,6 @@ pub fn trace_symbol(
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
/// Build a read-only trace for one pub dependency.
|
|
335
|
-
///
|
|
336
334
|
/// # Errors
|
|
337
335
|
///
|
|
338
336
|
/// Returns [`DependencyHygieneError`] if local pubspec discovery or parsing fails.
|
|
@@ -365,9 +363,13 @@ pub fn trace_dependency(
|
|
|
365
363
|
.collect::<Vec<_>>();
|
|
366
364
|
let declared = !declared_in.is_empty();
|
|
367
365
|
let total_import_count = importing_files.len();
|
|
368
|
-
let used_in_scripts = packages
|
|
369
|
-
|
|
370
|
-
|
|
366
|
+
let used_in_scripts = packages.iter().any(|package| {
|
|
367
|
+
package_used_in_tooling(
|
|
368
|
+
&package.root,
|
|
369
|
+
dependency,
|
|
370
|
+
&shell_script_packages(&package.root),
|
|
371
|
+
)
|
|
372
|
+
});
|
|
371
373
|
let used_in_codegen = project
|
|
372
374
|
.files
|
|
373
375
|
.iter()
|
|
@@ -437,16 +437,46 @@ fn function_expression_body_constructor_name(node: Node<'_>, source: &str) -> Op
|
|
|
437
437
|
if node.kind() != "call_expression" {
|
|
438
438
|
return None;
|
|
439
439
|
}
|
|
440
|
-
let
|
|
440
|
+
let callee = node.child_by_field_name("function")?;
|
|
441
|
+
let (function, named_constructor) = if callee.kind() == "member_expression" {
|
|
442
|
+
(
|
|
443
|
+
callee.child_by_field_name("object")?,
|
|
444
|
+
Some(callee.child_by_field_name("property")?),
|
|
445
|
+
)
|
|
446
|
+
} else {
|
|
447
|
+
(callee, None)
|
|
448
|
+
};
|
|
441
449
|
if function.kind() != "function_expression" {
|
|
442
450
|
return None;
|
|
443
451
|
}
|
|
444
452
|
let body = function.child_by_field_name("body")?;
|
|
445
|
-
let expression = body.named_child(0)?;
|
|
453
|
+
let mut expression = body.named_child(0)?;
|
|
454
|
+
while expression.kind() == "conditional_expression" {
|
|
455
|
+
expression = expression.child_by_field_name("alternative")?;
|
|
456
|
+
}
|
|
457
|
+
if let Some(named_constructor) = named_constructor {
|
|
458
|
+
return split_closure_body_named_constructor(expression, named_constructor, source);
|
|
459
|
+
}
|
|
446
460
|
constructor_call_type_name(expression, source)
|
|
447
461
|
.or_else(|| split_closure_body_constructor_name(node, expression, source))
|
|
448
462
|
}
|
|
449
463
|
|
|
464
|
+
fn split_closure_body_named_constructor(
|
|
465
|
+
expression: Node<'_>,
|
|
466
|
+
named_constructor: Node<'_>,
|
|
467
|
+
source: &str,
|
|
468
|
+
) -> Option<String> {
|
|
469
|
+
if !matches!(expression.kind(), "identifier" | "type_identifier") {
|
|
470
|
+
return None;
|
|
471
|
+
}
|
|
472
|
+
let constructor = format!(
|
|
473
|
+
"{}.{}",
|
|
474
|
+
expression.utf8_text(source.as_bytes()).ok()?,
|
|
475
|
+
named_constructor.utf8_text(source.as_bytes()).ok()?
|
|
476
|
+
);
|
|
477
|
+
(!constructor_name_candidates(&constructor).is_empty()).then_some(constructor)
|
|
478
|
+
}
|
|
479
|
+
|
|
450
480
|
fn constructor_call_type_name(node: Node<'_>, source: &str) -> Option<String> {
|
|
451
481
|
if !is_object_constructor(node) {
|
|
452
482
|
return None;
|