dart-decimate 0.0.12 → 0.0.14
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 +75 -1
- package/Cargo.toml +2 -1
- package/README.md +31 -27
- package/npm/scripts/postinstall.js +33 -12
- package/npm/scripts/test-npx-local.js +7 -2
- package/npm/scripts/test-npx-mcp-local.js +3 -1
- package/npm/scripts/test-npx-prebuilt.js +33 -13
- package/npm/scripts/test-postinstall-prebuilt.js +33 -13
- package/package.json +11 -1
- package/src/changed_scope.rs +4 -7
- package/src/cli/audit_run.rs +1 -3
- package/src/cli/decision_surface_run.rs +1 -3
- package/src/cli/entry_points.rs +75 -13
- package/src/dart_parser.rs +1 -3
- package/src/dependencies/codegen.rs +26 -0
- package/src/dependencies.rs +1 -0
- package/src/dependency_scripts.rs +42 -8
- package/src/extract.rs +6 -0
- package/src/git_command.rs +58 -0
- package/src/graph.rs +5 -0
- package/src/lib.rs +1 -0
- package/src/manifest.rs +1 -1
- package/src/output/graph_findings.rs +117 -43
- package/src/output/route_cycle/classification.rs +862 -0
- package/src/output/route_cycle/navigation.rs +6 -1
- package/src/output/route_cycle/registry_api.rs +268 -0
- package/src/output/route_cycle.rs +28 -162
- package/src/output/types.rs +3 -3
- package/src/output.rs +2 -2
- package/src/scan/tests.rs +133 -0
- package/src/scan.rs +122 -47
- package/src/security/detect.rs +1275 -10
- package/src/security_gate.rs +3 -5
- package/src/trace.rs +22 -13
- package/src/widgets/inheritance.rs +250 -0
- package/src/widgets/params.rs +81 -1
- package/src/widgets/patterns.rs +32 -25
- package/src/widgets/reads.rs +61 -11
- package/src/widgets/resolution.rs +281 -0
- package/src/widgets/unrendered.rs +111 -47
- package/src/widgets.rs +69 -11
package/src/scan.rs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
-
use std::fs;
|
|
3
2
|
use std::path::{Path, PathBuf};
|
|
4
3
|
|
|
5
4
|
use glob::Pattern;
|
|
5
|
+
use ignore::WalkBuilder;
|
|
6
|
+
use ignore::gitignore::GitignoreBuilder;
|
|
6
7
|
use rayon::prelude::*;
|
|
7
8
|
use serde::{Deserialize, Serialize};
|
|
8
9
|
use thiserror::Error;
|
|
@@ -11,7 +12,7 @@ use crate::graph::normalize_path;
|
|
|
11
12
|
use crate::package_map::PackageMap;
|
|
12
13
|
use crate::{
|
|
13
14
|
DartFile, ExtractError, GraphError, GraphOptions, ModuleGraph, build_module_graph_with_options,
|
|
14
|
-
extract_dart_file,
|
|
15
|
+
extract_dart_file, git_command,
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
/// Parsed Dart files plus their resolved module graph.
|
|
@@ -45,29 +46,13 @@ pub enum ScanError {
|
|
|
45
46
|
/// Underlying IO error.
|
|
46
47
|
source: std::io::Error,
|
|
47
48
|
},
|
|
48
|
-
/// A
|
|
49
|
-
#[error("failed to
|
|
50
|
-
|
|
49
|
+
/// A scan root could not be traversed.
|
|
50
|
+
#[error("failed to walk directory {path}: {source}")]
|
|
51
|
+
Walk {
|
|
51
52
|
/// Directory path.
|
|
52
53
|
path: PathBuf,
|
|
53
|
-
/// Underlying
|
|
54
|
-
source:
|
|
55
|
-
},
|
|
56
|
-
/// A directory entry could not be read.
|
|
57
|
-
#[error("failed to read directory entry under {path}: {source}")]
|
|
58
|
-
ReadDirEntry {
|
|
59
|
-
/// Directory being scanned.
|
|
60
|
-
path: PathBuf,
|
|
61
|
-
/// Underlying IO error.
|
|
62
|
-
source: std::io::Error,
|
|
63
|
-
},
|
|
64
|
-
/// A file type could not be read.
|
|
65
|
-
#[error("failed to read file type for {path}: {source}")]
|
|
66
|
-
FileType {
|
|
67
|
-
/// Entry path.
|
|
68
|
-
path: PathBuf,
|
|
69
|
-
/// Underlying IO error.
|
|
70
|
-
source: std::io::Error,
|
|
54
|
+
/// Underlying ignore-aware walk error.
|
|
55
|
+
source: ignore::Error,
|
|
71
56
|
},
|
|
72
57
|
/// A pubspec could not be read while expanding local packages.
|
|
73
58
|
#[error("failed to read pubspec {path}: {source}")]
|
|
@@ -150,7 +135,19 @@ pub fn scan_project_with_options(
|
|
|
150
135
|
|
|
151
136
|
let mut paths = BTreeSet::new();
|
|
152
137
|
for scan_root in &scan_roots {
|
|
138
|
+
if scan_roots
|
|
139
|
+
.iter()
|
|
140
|
+
.any(|other| other != scan_root && scan_root.starts_with(other))
|
|
141
|
+
{
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
let tracked = tracked_dart_files(&root, scan_root, &ignore_matcher);
|
|
145
|
+
if scan_root != &root && tracked.is_empty() && ignored_by_parent_gitignore(&root, scan_root)
|
|
146
|
+
{
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
153
149
|
discover_dart_files(&root, scan_root, &ignore_matcher, &mut paths)?;
|
|
150
|
+
paths.extend(tracked);
|
|
154
151
|
}
|
|
155
152
|
let paths = paths.into_iter().collect::<Vec<_>>();
|
|
156
153
|
|
|
@@ -160,13 +157,14 @@ pub fn scan_project_with_options(
|
|
|
160
157
|
.collect::<Result<Vec<_>, _>>()?;
|
|
161
158
|
files.sort_by(|left, right| left.path.cmp(&right.path));
|
|
162
159
|
|
|
163
|
-
let graph = build_module_graph_with_options(
|
|
160
|
+
let mut graph = build_module_graph_with_options(
|
|
164
161
|
&root,
|
|
165
162
|
&files,
|
|
166
163
|
&GraphOptions {
|
|
167
164
|
conditional_environment: options.conditional_environment.clone(),
|
|
168
165
|
},
|
|
169
166
|
)?;
|
|
167
|
+
graph.suppress_existing_unresolved_targets();
|
|
170
168
|
|
|
171
169
|
Ok(ScannedProject {
|
|
172
170
|
root,
|
|
@@ -176,6 +174,39 @@ pub fn scan_project_with_options(
|
|
|
176
174
|
})
|
|
177
175
|
}
|
|
178
176
|
|
|
177
|
+
fn ignored_by_parent_gitignore(root: &Path, scan_root: &Path) -> bool {
|
|
178
|
+
let Some(repository_root) = root
|
|
179
|
+
.ancestors()
|
|
180
|
+
.find(|ancestor| ancestor.join(".git").exists() || ancestor.join(".jj").exists())
|
|
181
|
+
else {
|
|
182
|
+
return false;
|
|
183
|
+
};
|
|
184
|
+
if !scan_root.starts_with(repository_root) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
let Some(parent) = scan_root.parent() else {
|
|
188
|
+
return false;
|
|
189
|
+
};
|
|
190
|
+
let mut directories = parent
|
|
191
|
+
.ancestors()
|
|
192
|
+
.take_while(|ancestor| ancestor.starts_with(repository_root))
|
|
193
|
+
.collect::<Vec<_>>();
|
|
194
|
+
directories.reverse();
|
|
195
|
+
|
|
196
|
+
let mut builder = GitignoreBuilder::new(repository_root);
|
|
197
|
+
for directory in directories {
|
|
198
|
+
let path = directory.join(".gitignore");
|
|
199
|
+
if path.is_file() && builder.add(path).is_some() {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
builder.build().ok().is_some_and(|gitignore| {
|
|
204
|
+
gitignore
|
|
205
|
+
.matched_path_or_any_parents(scan_root, true)
|
|
206
|
+
.is_ignore()
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
179
210
|
fn normalize_scan_root(root: &Path) -> Result<PathBuf, ScanError> {
|
|
180
211
|
if root.is_absolute() {
|
|
181
212
|
return Ok(normalize_path(root));
|
|
@@ -191,41 +222,85 @@ fn discover_dart_files(
|
|
|
191
222
|
ignore_matcher: &IgnoreMatcher,
|
|
192
223
|
paths: &mut BTreeSet<PathBuf>,
|
|
193
224
|
) -> Result<(), ScanError> {
|
|
194
|
-
let
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
225
|
+
let filter_root = root.to_path_buf();
|
|
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
|
+
});
|
|
198
244
|
|
|
199
|
-
for
|
|
200
|
-
let entry =
|
|
245
|
+
for result in builder.build() {
|
|
246
|
+
let entry = result.map_err(|source| ScanError::Walk {
|
|
201
247
|
path: dir.to_path_buf(),
|
|
202
248
|
source,
|
|
203
249
|
})?;
|
|
204
250
|
let path = entry.path();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if should_skip_dir(&path) {
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
if ignore_matcher.matches(root, &path) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
discover_dart_files(root, &path, ignore_matcher, paths)?;
|
|
218
|
-
} else if file_type.is_file()
|
|
219
|
-
&& path.extension().is_some_and(|ext| ext == "dart")
|
|
220
|
-
&& !ignore_matcher.matches(root, &path)
|
|
251
|
+
if entry
|
|
252
|
+
.file_type()
|
|
253
|
+
.is_some_and(|file_type| file_type.is_file())
|
|
254
|
+
&& path
|
|
255
|
+
.extension()
|
|
256
|
+
.is_some_and(|extension| extension == "dart")
|
|
221
257
|
{
|
|
222
|
-
paths.insert(normalize_path(
|
|
258
|
+
paths.insert(normalize_path(path));
|
|
223
259
|
}
|
|
224
260
|
}
|
|
225
261
|
|
|
226
262
|
Ok(())
|
|
227
263
|
}
|
|
228
264
|
|
|
265
|
+
fn tracked_dart_files(
|
|
266
|
+
root: &Path,
|
|
267
|
+
scan_root: &Path,
|
|
268
|
+
ignore_matcher: &IgnoreMatcher,
|
|
269
|
+
) -> BTreeSet<PathBuf> {
|
|
270
|
+
let Ok(output) = git_command::for_repository(scan_root)
|
|
271
|
+
.args(["ls-files", "--cached", "-z"])
|
|
272
|
+
.output()
|
|
273
|
+
else {
|
|
274
|
+
return BTreeSet::new();
|
|
275
|
+
};
|
|
276
|
+
if !output.status.success() {
|
|
277
|
+
return BTreeSet::new();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
output
|
|
281
|
+
.stdout
|
|
282
|
+
.split(|byte| *byte == 0)
|
|
283
|
+
.filter_map(|path| std::str::from_utf8(path).ok())
|
|
284
|
+
.map(|path| normalize_path(&scan_root.join(path)))
|
|
285
|
+
.filter(|path| {
|
|
286
|
+
path.starts_with(scan_root)
|
|
287
|
+
&& path.is_file()
|
|
288
|
+
&& path
|
|
289
|
+
.extension()
|
|
290
|
+
.is_some_and(|extension| extension == "dart")
|
|
291
|
+
&& !ignore_matcher.matches(root, path)
|
|
292
|
+
&& !has_skipped_directory(scan_root, path)
|
|
293
|
+
})
|
|
294
|
+
.collect()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
fn has_skipped_directory(root: &Path, path: &Path) -> bool {
|
|
298
|
+
path.strip_prefix(root)
|
|
299
|
+
.ok()
|
|
300
|
+
.and_then(Path::parent)
|
|
301
|
+
.is_some_and(|parent| parent.ancestors().any(should_skip_dir))
|
|
302
|
+
}
|
|
303
|
+
|
|
229
304
|
fn should_skip_dir(path: &Path) -> bool {
|
|
230
305
|
matches!(
|
|
231
306
|
path.file_name().and_then(|name| name.to_str()),
|