dart-decimate 0.0.1

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.
Files changed (188) hide show
  1. package/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
package/src/routes.rs ADDED
@@ -0,0 +1,354 @@
1
+ use std::collections::BTreeMap;
2
+ use std::path::{Path, PathBuf};
3
+
4
+ use serde::{Deserialize, Serialize};
5
+
6
+ use crate::generated::is_generated_dart_path;
7
+ use crate::{DartRouteDeclaration, Location, scan::ScannedProject};
8
+
9
+ /// `GoRouter` route collision analysis.
10
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11
+ pub struct RouteCollisionReport {
12
+ /// Duplicate route paths or names.
13
+ pub collisions: Vec<RouteCollision>,
14
+ }
15
+
16
+ /// A route path or route name declared by more than one typed route.
17
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18
+ pub struct RouteCollision {
19
+ /// Collision category.
20
+ pub kind: RouteCollisionKind,
21
+ /// Human-readable conflicting path or name.
22
+ pub value: String,
23
+ /// Declarations that share this route identity.
24
+ pub declarations: Vec<RouteCollisionDeclaration>,
25
+ }
26
+
27
+ /// Collision category.
28
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
29
+ #[serde(rename_all = "kebab-case")]
30
+ pub enum RouteCollisionKind {
31
+ /// Two or more routes resolve to the same path pattern.
32
+ Path,
33
+ /// Two or more routes use the same route name.
34
+ Name,
35
+ }
36
+
37
+ /// One route declaration participating in a collision.
38
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39
+ pub struct RouteCollisionDeclaration {
40
+ /// Dart file containing the route declaration.
41
+ pub path: PathBuf,
42
+ /// Typed route data class.
43
+ pub route_class: String,
44
+ /// Location of the annotation or route constructor.
45
+ pub location: Location,
46
+ }
47
+
48
+ /// Detect duplicate `GoRouter` paths and names.
49
+ #[must_use]
50
+ pub fn detect_route_collisions(project: &ScannedProject) -> RouteCollisionReport {
51
+ let mut path_groups = BTreeMap::<String, CollisionGroup>::new();
52
+ let mut name_groups = BTreeMap::<String, CollisionGroup>::new();
53
+
54
+ for file in &project.files {
55
+ if is_generated_dart_path(&file.path) || is_test_dart(&file.path) {
56
+ continue;
57
+ }
58
+ for route in &file.routes {
59
+ let declaration = collision_declaration(&file.path, route);
60
+ let scope = route_collision_scope(&file.path, route);
61
+ if let Some(path) = &route.path {
62
+ let key = scoped_collision_key(scope.as_deref(), &route_path_key(path));
63
+ path_groups
64
+ .entry(key)
65
+ .or_insert_with(|| CollisionGroup::new(path.clone()))
66
+ .declarations
67
+ .push(declaration.clone());
68
+ }
69
+ if let Some(name) = &route.name {
70
+ let key = scoped_collision_key(scope.as_deref(), name);
71
+ name_groups
72
+ .entry(key)
73
+ .or_insert_with(|| CollisionGroup::new(name.clone()))
74
+ .declarations
75
+ .push(declaration);
76
+ }
77
+ }
78
+ }
79
+
80
+ RouteCollisionReport {
81
+ collisions: collisions(RouteCollisionKind::Path, path_groups)
82
+ .into_iter()
83
+ .chain(collisions(RouteCollisionKind::Name, name_groups))
84
+ .collect(),
85
+ }
86
+ }
87
+
88
+ #[derive(Debug, Clone)]
89
+ struct CollisionGroup {
90
+ value: String,
91
+ declarations: Vec<RouteCollisionDeclaration>,
92
+ }
93
+
94
+ impl CollisionGroup {
95
+ fn new(value: String) -> Self {
96
+ Self {
97
+ value,
98
+ declarations: Vec::new(),
99
+ }
100
+ }
101
+ }
102
+
103
+ fn collisions(
104
+ kind: RouteCollisionKind,
105
+ groups: BTreeMap<String, CollisionGroup>,
106
+ ) -> Vec<RouteCollision> {
107
+ groups
108
+ .into_values()
109
+ .filter_map(|mut group| {
110
+ group.declarations.sort_by(|left, right| {
111
+ (
112
+ &left.path,
113
+ left.location.line,
114
+ left.location.column,
115
+ &left.route_class,
116
+ )
117
+ .cmp(&(
118
+ &right.path,
119
+ right.location.line,
120
+ right.location.column,
121
+ &right.route_class,
122
+ ))
123
+ });
124
+ (group.declarations.len() > 1).then_some(RouteCollision {
125
+ kind,
126
+ value: group.value,
127
+ declarations: group.declarations,
128
+ })
129
+ })
130
+ .collect()
131
+ }
132
+
133
+ fn collision_declaration(path: &Path, route: &DartRouteDeclaration) -> RouteCollisionDeclaration {
134
+ RouteCollisionDeclaration {
135
+ path: path.to_path_buf(),
136
+ route_class: route.route_class.clone(),
137
+ location: route.location,
138
+ }
139
+ }
140
+
141
+ fn route_collision_scope(path: &Path, route: &DartRouteDeclaration) -> Option<String> {
142
+ (route.route_class == "GoRoute").then(|| path.to_string_lossy().into_owned())
143
+ }
144
+
145
+ fn scoped_collision_key(scope: Option<&str>, value: &str) -> String {
146
+ match scope {
147
+ Some(scope) => format!("{scope}\0{value}"),
148
+ None => value.to_owned(),
149
+ }
150
+ }
151
+
152
+ fn route_path_key(path: &str) -> String {
153
+ normalize_route_path(path)
154
+ .split('/')
155
+ .map(|segment| {
156
+ if segment.starts_with(':') {
157
+ ":"
158
+ } else {
159
+ segment
160
+ }
161
+ })
162
+ .collect::<Vec<_>>()
163
+ .join("/")
164
+ }
165
+
166
+ fn normalize_route_path(path: &str) -> String {
167
+ let mut normalized = path.replace("//", "/");
168
+ while normalized.len() > 1 && normalized.ends_with('/') {
169
+ normalized.pop();
170
+ }
171
+ if normalized.is_empty() {
172
+ "/".to_owned()
173
+ } else if normalized.starts_with('/') {
174
+ normalized
175
+ } else {
176
+ format!("/{normalized}")
177
+ }
178
+ }
179
+
180
+ fn is_test_dart(path: &Path) -> bool {
181
+ path.file_name()
182
+ .and_then(|name| name.to_str())
183
+ .is_some_and(|name| name.ends_with("_test.dart"))
184
+ || path.components().any(|component| {
185
+ component.as_os_str().to_str().is_some_and(|segment| {
186
+ matches!(segment, "test" | "integration_test" | "test_driver")
187
+ })
188
+ })
189
+ }
190
+
191
+ #[cfg(test)]
192
+ mod tests {
193
+ use crate::extract_dart_source;
194
+
195
+ use super::*;
196
+
197
+ #[test]
198
+ fn detects_param_name_route_collisions() -> Result<(), Box<dyn std::error::Error>> {
199
+ let project = test_project(&[
200
+ (
201
+ "lib/a.dart",
202
+ "@TypedGoRoute<UserRoute>(path: '/users/:id')\nclass UserRoute extends GoRouteData {}\n",
203
+ ),
204
+ (
205
+ "lib/b.dart",
206
+ "@TypedGoRoute<MemberRoute>(path: '/users/:userId')\nclass MemberRoute extends GoRouteData {}\n",
207
+ ),
208
+ ])?;
209
+
210
+ let report = detect_route_collisions(&project);
211
+
212
+ assert_eq!(report.collisions.len(), 1);
213
+ assert_eq!(report.collisions[0].kind, RouteCollisionKind::Path);
214
+ assert_eq!(report.collisions[0].declarations.len(), 2);
215
+ Ok(())
216
+ }
217
+
218
+ #[test]
219
+ fn does_not_collide_static_and_dynamic_siblings() -> Result<(), Box<dyn std::error::Error>> {
220
+ let project = test_project(&[
221
+ (
222
+ "lib/a.dart",
223
+ "@TypedGoRoute<NewUserRoute>(path: '/users/new')\nclass NewUserRoute extends GoRouteData {}\n",
224
+ ),
225
+ (
226
+ "lib/b.dart",
227
+ "@TypedGoRoute<UserRoute>(path: '/users/:id')\nclass UserRoute extends GoRouteData {}\n",
228
+ ),
229
+ ])?;
230
+
231
+ let report = detect_route_collisions(&project);
232
+
233
+ assert!(report.collisions.is_empty());
234
+ Ok(())
235
+ }
236
+
237
+ #[test]
238
+ fn does_not_collide_same_child_segment_under_different_parents()
239
+ -> Result<(), Box<dyn std::error::Error>> {
240
+ let source = "
241
+ @TypedGoRoute<UserRoute>(
242
+ path: '/users',
243
+ routes: [TypedGoRoute<UserDetailsRoute>(path: 'details')],
244
+ )
245
+ class UserRoute extends GoRouteData {}
246
+
247
+ @TypedGoRoute<OrderRoute>(
248
+ path: '/orders',
249
+ routes: [TypedGoRoute<OrderDetailsRoute>(path: 'details')],
250
+ )
251
+ class OrderRoute extends GoRouteData {}
252
+ ";
253
+ let project = test_project(&[("lib/routes.dart", source)])?;
254
+
255
+ let report = detect_route_collisions(&project);
256
+
257
+ assert!(report.collisions.is_empty());
258
+ Ok(())
259
+ }
260
+
261
+ #[test]
262
+ fn does_not_collide_raw_routes_from_independent_files() -> Result<(), Box<dyn std::error::Error>>
263
+ {
264
+ let project = test_project(&[
265
+ (
266
+ "example/lib/app_a.dart",
267
+ "final router = GoRouter(routes: [GoRoute(path: '/', builder: (_, _) => const SizedBox())]);",
268
+ ),
269
+ (
270
+ "example/lib/app_b.dart",
271
+ "final router = GoRouter(routes: [GoRoute(path: '/', builder: (_, _) => const SizedBox())]);",
272
+ ),
273
+ ])?;
274
+
275
+ let report = detect_route_collisions(&project);
276
+
277
+ assert!(report.collisions.is_empty());
278
+ Ok(())
279
+ }
280
+
281
+ #[test]
282
+ fn still_collides_raw_routes_inside_one_route_file() -> Result<(), Box<dyn std::error::Error>> {
283
+ let project = test_project(&[(
284
+ "lib/router.dart",
285
+ "
286
+ final router = GoRouter(routes: [
287
+ GoRoute(path: '/', builder: (_, _) => const SizedBox()),
288
+ GoRoute(path: '/', builder: (_, _) => const SizedBox()),
289
+ ]);
290
+ ",
291
+ )])?;
292
+
293
+ let report = detect_route_collisions(&project);
294
+
295
+ assert_eq!(report.collisions.len(), 1);
296
+ assert_eq!(report.collisions[0].kind, RouteCollisionKind::Path);
297
+ Ok(())
298
+ }
299
+
300
+ #[test]
301
+ fn skips_test_route_fixtures() -> Result<(), Box<dyn std::error::Error>> {
302
+ let project = test_project(&[
303
+ (
304
+ "test/app_router_test.dart",
305
+ "final routes = [GoRoute(path: '/settings', builder: (_, _) => const SizedBox())];",
306
+ ),
307
+ (
308
+ "integration_test/app_flow_test.dart",
309
+ "final routes = [GoRoute(path: '/settings', builder: (_, _) => const SizedBox())];",
310
+ ),
311
+ ])?;
312
+
313
+ let report = detect_route_collisions(&project);
314
+
315
+ assert!(report.collisions.is_empty());
316
+ Ok(())
317
+ }
318
+
319
+ #[test]
320
+ fn skips_generated_route_companions() -> Result<(), Box<dyn std::error::Error>> {
321
+ let project = test_project(&[
322
+ (
323
+ "lib/routes.dart",
324
+ "@TypedGoRoute<HomeRoute>(path: '/')\nclass HomeRoute extends GoRouteData {}\n",
325
+ ),
326
+ (
327
+ "lib/routes.gen.dart",
328
+ "@TypedGoRoute<GeneratedRoute>(path: '/')\nclass GeneratedRoute extends GoRouteData {}\n",
329
+ ),
330
+ (
331
+ "lib/routes.mocks.dart",
332
+ "@TypedGoRoute<MockRoute>(path: '/')\nclass MockRoute extends GoRouteData {}\n",
333
+ ),
334
+ ])?;
335
+
336
+ let report = detect_route_collisions(&project);
337
+
338
+ assert!(report.collisions.is_empty());
339
+ Ok(())
340
+ }
341
+
342
+ fn test_project(
343
+ sources: &[(&str, &str)],
344
+ ) -> Result<ScannedProject, Box<dyn std::error::Error>> {
345
+ let temp = tempfile::tempdir()?;
346
+ let root = temp.path().to_path_buf();
347
+ let files = sources
348
+ .iter()
349
+ .map(|(path, source)| extract_dart_source(root.join(path), source))
350
+ .collect::<Result<Vec<_>, _>>()?;
351
+ let graph = crate::build_module_graph(&root, &files)?;
352
+ Ok(ScannedProject { root, files, graph })
353
+ }
354
+ }
@@ -0,0 +1,250 @@
1
+ use std::fs;
2
+
3
+ use tempfile::TempDir;
4
+
5
+ use super::*;
6
+
7
+ #[test]
8
+ fn scans_dart_files_in_parallel_and_skips_build_outputs() -> Result<(), Box<dyn std::error::Error>>
9
+ {
10
+ let fixture = tempfile::tempdir()?;
11
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
12
+ write(
13
+ &fixture,
14
+ "lib/main.dart",
15
+ "import 'live.dart';\nvoid main() {}\n",
16
+ )?;
17
+ write(&fixture, "lib/live.dart", "class Live {}\n")?;
18
+ write(&fixture, "build/generated.dart", "class Generated {}\n")?;
19
+
20
+ let project = scan_project(fixture.path())?;
21
+
22
+ assert_eq!(project.files.len(), 2);
23
+ assert_eq!(project.graph.node_count(), 2);
24
+ assert_eq!(project.graph.edge_count(), 1);
25
+
26
+ Ok(())
27
+ }
28
+
29
+ #[test]
30
+ fn skips_rust_target_fixture_pubspecs() -> Result<(), Box<dyn std::error::Error>> {
31
+ let fixture = tempfile::tempdir()?;
32
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
33
+ write(&fixture, "lib/main.dart", "void main() {}\n")?;
34
+ write(
35
+ &fixture,
36
+ "target/stale_fixture/pubspec.yaml",
37
+ "name: stale_fixture\nworkspace:\n - missing/*\n",
38
+ )?;
39
+ write(
40
+ &fixture,
41
+ "target/stale_fixture/lib/generated.dart",
42
+ "class Generated {}\n",
43
+ )?;
44
+
45
+ let project = scan_project(fixture.path())?;
46
+
47
+ assert_eq!(project.files.len(), 1);
48
+ assert_eq!(project.files[0].path, fixture.path().join("lib/main.dart"));
49
+
50
+ Ok(())
51
+ }
52
+
53
+ #[test]
54
+ fn scans_local_path_dependencies_for_graph_resolution() -> Result<(), Box<dyn std::error::Error>> {
55
+ let fixture = tempfile::tempdir()?;
56
+ write(
57
+ &fixture,
58
+ "app/pubspec.yaml",
59
+ "name: app\ndependencies:\n shared:\n path: ../shared\n",
60
+ )?;
61
+ write(
62
+ &fixture,
63
+ "app/lib/main.dart",
64
+ "import 'package:shared/shared.dart';\nvoid main() {}\n",
65
+ )?;
66
+ write(&fixture, "shared/pubspec.yaml", "name: shared\n")?;
67
+ write(&fixture, "shared/lib/shared.dart", "class Shared {}\n")?;
68
+
69
+ let project = scan_project(fixture.path().join("app"))?;
70
+
71
+ assert_eq!(project.files.len(), 2);
72
+ assert_eq!(project.graph.edge_count(), 1);
73
+ assert!(project.graph.unresolved().is_empty());
74
+
75
+ Ok(())
76
+ }
77
+
78
+ #[test]
79
+ fn scans_local_package_config_roots_for_graph_resolution() -> Result<(), Box<dyn std::error::Error>>
80
+ {
81
+ let fixture = tempfile::tempdir()?;
82
+ write(
83
+ &fixture,
84
+ "app/.dart_tool/package_config.json",
85
+ r#"{
86
+ "configVersion": 2,
87
+ "packages": [
88
+ {"name": "app", "rootUri": "../", "packageUri": "lib/"},
89
+ {"name": "shared", "rootUri": "../../shared", "packageUri": "lib/"}
90
+ ]
91
+ }
92
+ "#,
93
+ )?;
94
+ write(
95
+ &fixture,
96
+ "app/lib/main.dart",
97
+ "import 'package:shared/shared.dart';\nvoid main() {}\n",
98
+ )?;
99
+ write(&fixture, "shared/lib/shared.dart", "class Shared {}\n")?;
100
+
101
+ let project = scan_project(fixture.path().join("app"))?;
102
+
103
+ assert_eq!(project.files.len(), 2);
104
+ assert_eq!(project.graph.edge_count(), 1);
105
+ assert!(project.graph.unresolved().is_empty());
106
+
107
+ Ok(())
108
+ }
109
+
110
+ #[test]
111
+ fn scans_workspace_package_config_from_member_root() -> Result<(), Box<dyn std::error::Error>> {
112
+ let fixture = tempfile::tempdir()?;
113
+ write(
114
+ &fixture,
115
+ ".dart_tool/package_config.json",
116
+ r#"{
117
+ "configVersion": 2,
118
+ "packages": [
119
+ {"name": "app", "rootUri": "../packages/app", "packageUri": "lib/"},
120
+ {"name": "shared", "rootUri": "../packages/shared", "packageUri": "lib/"}
121
+ ]
122
+ }
123
+ "#,
124
+ )?;
125
+ write(
126
+ &fixture,
127
+ "pubspec.yaml",
128
+ "name: workspace\nworkspace:\n - packages/*\n",
129
+ )?;
130
+ write(
131
+ &fixture,
132
+ "packages/app/pubspec.yaml",
133
+ "name: app\nresolution: workspace\ndependencies:\n shared: ^1.0.0\n",
134
+ )?;
135
+ write(
136
+ &fixture,
137
+ "packages/app/lib/main.dart",
138
+ "import 'package:shared/shared.dart';\nvoid main() {}\n",
139
+ )?;
140
+ write(
141
+ &fixture,
142
+ "packages/shared/pubspec.yaml",
143
+ "name: shared\nresolution: workspace\n",
144
+ )?;
145
+ write(
146
+ &fixture,
147
+ "packages/shared/lib/shared.dart",
148
+ "class Shared {}\n",
149
+ )?;
150
+
151
+ let project = scan_project(fixture.path().join("packages/app"))?;
152
+
153
+ assert_eq!(project.files.len(), 2);
154
+ assert_eq!(project.graph.edge_count(), 1);
155
+ assert!(project.graph.unresolved().is_empty());
156
+
157
+ Ok(())
158
+ }
159
+
160
+ #[test]
161
+ fn does_not_scan_pub_cache_package_config_roots() -> Result<(), Box<dyn std::error::Error>> {
162
+ let fixture = tempfile::tempdir()?;
163
+ write(
164
+ &fixture,
165
+ "app/.dart_tool/package_config.json",
166
+ r#"{
167
+ "configVersion": 2,
168
+ "packages": [
169
+ {"name": "app", "rootUri": "../", "packageUri": "lib/"},
170
+ {"name": "hosted", "rootUri": "../../.pub-cache/hosted/hosted-1.0.0", "packageUri": "lib/"}
171
+ ]
172
+ }
173
+ "#,
174
+ )?;
175
+ write(
176
+ &fixture,
177
+ "app/lib/main.dart",
178
+ "import 'package:hosted/hosted.dart';\nvoid main() {}\n",
179
+ )?;
180
+ write(
181
+ &fixture,
182
+ ".pub-cache/hosted/hosted-1.0.0/lib/hosted.dart",
183
+ "class Hosted {}\n",
184
+ )?;
185
+
186
+ let project = scan_project(fixture.path().join("app"))?;
187
+
188
+ assert_eq!(project.files.len(), 1);
189
+ assert_eq!(project.graph.edge_count(), 0);
190
+ assert!(project.graph.unresolved().is_empty());
191
+
192
+ Ok(())
193
+ }
194
+
195
+ #[test]
196
+ fn scans_pub_workspace_member_files() -> Result<(), Box<dyn std::error::Error>> {
197
+ let fixture = tempfile::tempdir()?;
198
+ write(
199
+ &fixture,
200
+ "pubspec.yaml",
201
+ "name: app\nworkspace:\n - packages/*\n",
202
+ )?;
203
+ write(
204
+ &fixture,
205
+ "lib/main.dart",
206
+ "import 'package:shared/shared.dart';\nvoid main() {}\n",
207
+ )?;
208
+ write(&fixture, "packages/shared/pubspec.yaml", "name: shared\n")?;
209
+ write(
210
+ &fixture,
211
+ "packages/shared/lib/shared.dart",
212
+ "class Shared {}\n",
213
+ )?;
214
+
215
+ let project = scan_project(fixture.path())?;
216
+
217
+ assert_eq!(project.files.len(), 2);
218
+ assert_eq!(project.graph.edge_count(), 1);
219
+ assert!(project.graph.unresolved().is_empty());
220
+
221
+ Ok(())
222
+ }
223
+
224
+ #[test]
225
+ fn scans_all_conditional_import_targets() -> Result<(), Box<dyn std::error::Error>> {
226
+ let fixture = tempfile::tempdir()?;
227
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
228
+ write(
229
+ &fixture,
230
+ "lib/main.dart",
231
+ "import 'io.dart' if (dart.library.html) 'web.dart';\nvoid main() {}\n",
232
+ )?;
233
+ write(&fixture, "lib/io.dart", "class Io {}\n")?;
234
+ write(&fixture, "lib/web.dart", "class Web {}\n")?;
235
+
236
+ let project = scan_project(fixture.path())?;
237
+
238
+ assert_eq!(project.graph.edge_count(), 2);
239
+ assert!(project.graph.unresolved().is_empty());
240
+
241
+ Ok(())
242
+ }
243
+
244
+ fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
245
+ let path = fixture.path().join(path);
246
+ if let Some(parent) = path.parent() {
247
+ fs::create_dir_all(parent)?;
248
+ }
249
+ fs::write(path, source)
250
+ }