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
@@ -0,0 +1,495 @@
1
+ use std::collections::{BTreeMap, BTreeSet};
2
+ use std::fs;
3
+ use std::path::{Path, PathBuf};
4
+
5
+ use serde::Deserialize;
6
+ use serde_yaml_ng::{Mapping, Value};
7
+
8
+ use crate::graph::{GraphError, normalize_path};
9
+
10
+ #[derive(Debug, Clone, Default)]
11
+ pub(crate) struct PackageMap {
12
+ by_name: BTreeMap<String, PackageRoot>,
13
+ }
14
+
15
+ #[derive(Debug, Clone, PartialEq, Eq)]
16
+ struct PackageRoot {
17
+ root: PathBuf,
18
+ package_path: PathBuf,
19
+ local: bool,
20
+ }
21
+
22
+ #[derive(Debug, Clone, PartialEq, Eq)]
23
+ pub(crate) struct PackageResolution {
24
+ pub(crate) path: PathBuf,
25
+ pub(crate) local: bool,
26
+ }
27
+
28
+ impl PackageMap {
29
+ pub(crate) fn discover(root: &Path) -> Result<Self, GraphError> {
30
+ if let Some(config) = PackageConfigFile::read(root)? {
31
+ return Ok(Self::from_package_config(
32
+ root,
33
+ &config.config_dir,
34
+ &config.config,
35
+ ));
36
+ }
37
+
38
+ let mut packages = Self::default();
39
+ let mut visited = BTreeSet::new();
40
+ packages.discover_pubspec(root, &mut visited)?;
41
+ packages.discover_nested_pubspecs(root, &mut visited)?;
42
+ Ok(packages)
43
+ }
44
+
45
+ pub(crate) fn names(&self) -> Vec<&str> {
46
+ self.by_name.keys().map(String::as_str).collect()
47
+ }
48
+
49
+ pub(crate) fn local_roots(&self) -> BTreeSet<PathBuf> {
50
+ self.by_name
51
+ .values()
52
+ .filter(|package| package.local)
53
+ .map(|package| package.root.clone())
54
+ .collect()
55
+ }
56
+
57
+ pub(crate) fn resolve(&self, package: &str, path: &str) -> Option<PackageResolution> {
58
+ self.by_name.get(package).map(|root| PackageResolution {
59
+ path: normalize_path(&root.package_path.join(path)),
60
+ local: root.local,
61
+ })
62
+ }
63
+
64
+ fn from_package_config(root: &Path, config_dir: &Path, config: &PackageConfig) -> Self {
65
+ let config_root = config_dir.parent().unwrap_or(config_dir);
66
+ let by_name = config
67
+ .packages
68
+ .iter()
69
+ .filter_map(|package| {
70
+ let root_uri = package.root_uri.as_deref()?;
71
+ let package_uri = package.package_uri.as_deref().unwrap_or("lib/");
72
+ let package_root = resolve_config_uri(config_dir, root_uri)?;
73
+ let package_path = resolve_package_uri(&package_root, package_uri)?;
74
+ let local =
75
+ is_local_package_config_root(root, config_root, root_uri, &package_root);
76
+ Some((
77
+ package.name.clone(),
78
+ PackageRoot {
79
+ root: package_root,
80
+ package_path,
81
+ local,
82
+ },
83
+ ))
84
+ })
85
+ .collect();
86
+
87
+ Self { by_name }
88
+ }
89
+
90
+ fn discover_pubspec(
91
+ &mut self,
92
+ package_root: &Path,
93
+ visited: &mut BTreeSet<PathBuf>,
94
+ ) -> Result<(), GraphError> {
95
+ let package_root = normalize_path(package_root);
96
+ if !visited.insert(package_root.clone()) {
97
+ return Ok(());
98
+ }
99
+
100
+ let Some(pubspec) = Pubspec::read(&package_root)? else {
101
+ return Ok(());
102
+ };
103
+
104
+ if let Some(name) = pubspec.name {
105
+ self.insert(name, package_root.clone(), PathBuf::from("lib"));
106
+ }
107
+
108
+ for dependency in pubspec.path_dependencies {
109
+ let dependency_root = normalize_path(&package_root.join(dependency.path));
110
+ if !dependency_root.join("pubspec.yaml").is_file() {
111
+ continue;
112
+ }
113
+ self.insert(
114
+ dependency.name,
115
+ dependency_root.clone(),
116
+ PathBuf::from("lib"),
117
+ );
118
+ self.discover_pubspec(&dependency_root, visited)?;
119
+ }
120
+
121
+ for member in pubspec.workspace_members {
122
+ for member_root in expand_workspace_member(&package_root, &member)? {
123
+ self.discover_pubspec(&member_root, visited)?;
124
+ }
125
+ }
126
+
127
+ Ok(())
128
+ }
129
+
130
+ fn discover_nested_pubspecs(
131
+ &mut self,
132
+ dir: &Path,
133
+ visited: &mut BTreeSet<PathBuf>,
134
+ ) -> Result<(), GraphError> {
135
+ let entries = fs::read_dir(dir).map_err(|source| GraphError::ReadDir {
136
+ path: dir.to_path_buf(),
137
+ source,
138
+ })?;
139
+
140
+ for entry in entries {
141
+ let entry = entry.map_err(|source| GraphError::ReadDirEntry {
142
+ path: dir.to_path_buf(),
143
+ source,
144
+ })?;
145
+ let path = entry.path();
146
+ let file_type = entry.file_type().map_err(|source| GraphError::FileType {
147
+ path: path.clone(),
148
+ source,
149
+ })?;
150
+
151
+ if file_type.is_dir() {
152
+ if should_skip_dir(&path) {
153
+ continue;
154
+ }
155
+ self.discover_nested_pubspecs(&path, visited)?;
156
+ } else if file_type.is_file()
157
+ && path.file_name().is_some_and(|name| name == "pubspec.yaml")
158
+ && let Some(package_root) = path.parent()
159
+ {
160
+ self.discover_pubspec(package_root, visited)?;
161
+ }
162
+ }
163
+
164
+ Ok(())
165
+ }
166
+
167
+ fn insert(&mut self, name: String, root: PathBuf, package_uri: PathBuf) {
168
+ self.by_name.insert(
169
+ name,
170
+ PackageRoot {
171
+ package_path: normalize_path(&root.join(package_uri)),
172
+ root,
173
+ local: true,
174
+ },
175
+ );
176
+ }
177
+ }
178
+
179
+ #[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
180
+ struct PackageConfig {
181
+ #[serde(default)]
182
+ packages: Vec<PackageConfigPackage>,
183
+ }
184
+
185
+ #[derive(Debug, Clone, PartialEq, Eq)]
186
+ struct PackageConfigFile {
187
+ config_dir: PathBuf,
188
+ config: PackageConfig,
189
+ }
190
+
191
+ impl PackageConfigFile {
192
+ fn read(root: &Path) -> Result<Option<Self>, GraphError> {
193
+ let Some(path) = find_package_config(root) else {
194
+ return Ok(None);
195
+ };
196
+ let source = match fs::read_to_string(&path) {
197
+ Ok(source) => source,
198
+ Err(source) => return Err(GraphError::ReadPackageConfig { path, source }),
199
+ };
200
+
201
+ let config =
202
+ serde_json::from_str(&source).map_err(|source| GraphError::ParsePackageConfig {
203
+ path: path.clone(),
204
+ source,
205
+ })?;
206
+ let config_dir = path
207
+ .parent()
208
+ .map_or_else(|| root.join(".dart_tool"), Path::to_path_buf);
209
+ Ok(Some(Self { config_dir, config }))
210
+ }
211
+ }
212
+
213
+ fn find_package_config(root: &Path) -> Option<PathBuf> {
214
+ root.ancestors()
215
+ .map(|dir| dir.join(".dart_tool/package_config.json"))
216
+ .find(|path| path.is_file())
217
+ }
218
+
219
+ #[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
220
+ #[serde(rename_all = "camelCase")]
221
+ struct PackageConfigPackage {
222
+ name: String,
223
+ root_uri: Option<String>,
224
+ package_uri: Option<String>,
225
+ }
226
+
227
+ #[derive(Debug, Clone, PartialEq, Eq)]
228
+ struct PathDependency {
229
+ name: String,
230
+ path: PathBuf,
231
+ }
232
+
233
+ #[derive(Debug, Clone, Default, PartialEq, Eq)]
234
+ struct Pubspec {
235
+ name: Option<String>,
236
+ workspace_members: Vec<String>,
237
+ path_dependencies: Vec<PathDependency>,
238
+ }
239
+
240
+ impl Pubspec {
241
+ fn read(package_root: &Path) -> Result<Option<Self>, GraphError> {
242
+ let path = package_root.join("pubspec.yaml");
243
+ let source = match fs::read_to_string(&path) {
244
+ Ok(source) => source,
245
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
246
+ Err(source) => return Err(GraphError::ReadPubspec { path, source }),
247
+ };
248
+ let value = serde_yaml_ng::from_str::<Value>(&source).map_err(|source| {
249
+ GraphError::ParsePubspec {
250
+ path: path.clone(),
251
+ source,
252
+ }
253
+ })?;
254
+
255
+ let overrides = read_pubspec_overrides(package_root)?;
256
+ Ok(Some(Self::from_values(&value, overrides.as_ref())))
257
+ }
258
+
259
+ fn from_values(value: &Value, overrides: Option<&Value>) -> Self {
260
+ let workspace_source = overrides
261
+ .filter(|value| has_top_level_field(value, "workspace"))
262
+ .unwrap_or(value);
263
+ Self {
264
+ name: string_field(value, "name").map(str::to_owned),
265
+ workspace_members: string_sequence_field(workspace_source, "workspace"),
266
+ path_dependencies: path_dependencies(value, overrides),
267
+ }
268
+ }
269
+ }
270
+
271
+ fn read_pubspec_overrides(package_root: &Path) -> Result<Option<Value>, GraphError> {
272
+ let path = package_root.join("pubspec_overrides.yaml");
273
+ let source = match fs::read_to_string(&path) {
274
+ Ok(source) => source,
275
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
276
+ Err(source) => return Err(GraphError::ReadPubspec { path, source }),
277
+ };
278
+ serde_yaml_ng::from_str::<Value>(&source)
279
+ .map(Some)
280
+ .map_err(|source| GraphError::ParsePubspec { path, source })
281
+ }
282
+
283
+ fn resolve_config_uri(config_dir: &Path, uri: &str) -> Option<PathBuf> {
284
+ if let Some(path) = uri.strip_prefix("file://") {
285
+ let path = percent_decode(path)?;
286
+ return Some(normalize_path(Path::new(&path)));
287
+ }
288
+ if uri.contains(':') {
289
+ return None;
290
+ }
291
+
292
+ let uri = percent_decode(uri)?;
293
+ Some(normalize_path(&config_dir.join(uri)))
294
+ }
295
+
296
+ fn resolve_package_uri(package_root: &Path, uri: &str) -> Option<PathBuf> {
297
+ if let Some(path) = uri.strip_prefix("file://") {
298
+ let path = percent_decode(path)?;
299
+ return Some(normalize_path(Path::new(&path)));
300
+ }
301
+ if uri.contains(':') {
302
+ return None;
303
+ }
304
+
305
+ let uri = percent_decode(uri)?;
306
+ Some(normalize_path(&package_root.join(uri)))
307
+ }
308
+
309
+ fn percent_decode(value: &str) -> Option<String> {
310
+ let bytes = value.as_bytes();
311
+ let mut decoded = Vec::with_capacity(bytes.len());
312
+ let mut index = 0;
313
+
314
+ while index < bytes.len() {
315
+ if bytes[index] == b'%' {
316
+ let high = hex_value(*bytes.get(index + 1)?)?;
317
+ let low = hex_value(*bytes.get(index + 2)?)?;
318
+ decoded.push(high << 4 | low);
319
+ index += 3;
320
+ } else {
321
+ decoded.push(bytes[index]);
322
+ index += 1;
323
+ }
324
+ }
325
+
326
+ String::from_utf8(decoded).ok()
327
+ }
328
+
329
+ fn hex_value(value: u8) -> Option<u8> {
330
+ match value {
331
+ b'0'..=b'9' => Some(value - b'0'),
332
+ b'a'..=b'f' => Some(value - b'a' + 10),
333
+ b'A'..=b'F' => Some(value - b'A' + 10),
334
+ _ => None,
335
+ }
336
+ }
337
+
338
+ fn is_local_package_config_root(
339
+ root: &Path,
340
+ config_root: &Path,
341
+ root_uri: &str,
342
+ package_root: &Path,
343
+ ) -> bool {
344
+ (is_relative_uri(root_uri)
345
+ || package_root.starts_with(root)
346
+ || package_root.starts_with(config_root))
347
+ && !is_pub_cache_path(package_root)
348
+ }
349
+
350
+ fn is_relative_uri(uri: &str) -> bool {
351
+ !uri.contains(':')
352
+ }
353
+
354
+ fn is_pub_cache_path(path: &Path) -> bool {
355
+ path.components()
356
+ .any(|component| component.as_os_str() == ".pub-cache")
357
+ }
358
+
359
+ fn path_dependencies(value: &Value, overrides: Option<&Value>) -> Vec<PathDependency> {
360
+ let mut dependencies = ["dependencies", "dev_dependencies"]
361
+ .into_iter()
362
+ .filter_map(|section| mapping_field(value, section))
363
+ .flat_map(path_dependencies_from_mapping)
364
+ .collect::<Vec<_>>();
365
+ let override_source = overrides
366
+ .filter(|value| has_top_level_field(value, "dependency_overrides"))
367
+ .unwrap_or(value);
368
+ dependencies.extend(
369
+ mapping_field(override_source, "dependency_overrides")
370
+ .into_iter()
371
+ .flat_map(path_dependencies_from_mapping),
372
+ );
373
+ dependencies
374
+ }
375
+
376
+ fn path_dependencies_from_mapping(mapping: &Mapping) -> Vec<PathDependency> {
377
+ mapping
378
+ .iter()
379
+ .filter_map(|(name, dependency)| {
380
+ let name = name.as_str()?.to_owned();
381
+ let path = string_field(dependency, "path")?;
382
+ Some(PathDependency {
383
+ name,
384
+ path: PathBuf::from(path),
385
+ })
386
+ })
387
+ .collect()
388
+ }
389
+
390
+ fn mapping_field<'value>(value: &'value Value, field: &str) -> Option<&'value Mapping> {
391
+ value
392
+ .as_mapping()?
393
+ .get(Value::String(field.to_owned()))?
394
+ .as_mapping()
395
+ }
396
+
397
+ fn string_field<'value>(value: &'value Value, field: &str) -> Option<&'value str> {
398
+ value
399
+ .as_mapping()?
400
+ .get(Value::String(field.to_owned()))?
401
+ .as_str()
402
+ }
403
+
404
+ fn string_sequence_field(value: &Value, field: &str) -> Vec<String> {
405
+ value
406
+ .as_mapping()
407
+ .and_then(|mapping| mapping.get(Value::String(field.to_owned())))
408
+ .and_then(Value::as_sequence)
409
+ .into_iter()
410
+ .flatten()
411
+ .filter_map(Value::as_str)
412
+ .map(str::to_owned)
413
+ .collect()
414
+ }
415
+
416
+ fn has_top_level_field(value: &Value, field: &str) -> bool {
417
+ value
418
+ .as_mapping()
419
+ .is_some_and(|mapping| mapping.contains_key(Value::String(field.to_owned())))
420
+ }
421
+
422
+ fn expand_workspace_member(root: &Path, member: &str) -> Result<Vec<PathBuf>, GraphError> {
423
+ if !contains_glob_pattern(member) {
424
+ return Ok(vec![normalize_path(&root.join(member))]);
425
+ }
426
+
427
+ let pattern_path = root.join(member).join("pubspec.yaml");
428
+ let pattern = pattern_path.to_string_lossy().into_owned();
429
+ let entries = glob::glob(&pattern).map_err(|source| GraphError::WorkspacePattern {
430
+ pattern: pattern.clone(),
431
+ source,
432
+ })?;
433
+
434
+ entries
435
+ .map(|entry| {
436
+ let pubspec_path = entry.map_err(|source| GraphError::WorkspaceGlob {
437
+ pattern: pattern.clone(),
438
+ source,
439
+ })?;
440
+ Ok(pubspec_path
441
+ .parent()
442
+ .map_or_else(|| normalize_path(root), normalize_path))
443
+ })
444
+ .collect()
445
+ }
446
+
447
+ fn contains_glob_pattern(value: &str) -> bool {
448
+ value.contains('*') || value.contains('?') || value.contains('[')
449
+ }
450
+
451
+ fn should_skip_dir(path: &Path) -> bool {
452
+ matches!(
453
+ path.file_name().and_then(|name| name.to_str()),
454
+ Some(".dart_tool" | ".git" | ".idea" | ".pub-cache" | "build" | "target")
455
+ )
456
+ }
457
+
458
+ #[cfg(test)]
459
+ mod tests {
460
+ use tempfile::TempDir;
461
+
462
+ use super::*;
463
+
464
+ #[test]
465
+ fn skips_missing_path_dependencies_from_nested_pubspec_overrides()
466
+ -> Result<(), Box<dyn std::error::Error>> {
467
+ let fixture = TempDir::new()?;
468
+ write(&fixture, "pubspec.yaml", "name: hydrated_bloc\n")?;
469
+ write(
470
+ &fixture,
471
+ "example/pubspec.yaml",
472
+ "name: example\ndependencies:\n hydrated_bloc: ^10.0.0\n",
473
+ )?;
474
+ write(
475
+ &fixture,
476
+ "example/pubspec_overrides.yaml",
477
+ "dependency_overrides:\n bloc:\n path: ../../bloc\n",
478
+ )?;
479
+
480
+ let packages = PackageMap::discover(fixture.path())?;
481
+
482
+ assert_eq!(packages.names(), vec!["example", "hydrated_bloc"]);
483
+ assert!(packages.resolve("bloc", "bloc.dart").is_none());
484
+
485
+ Ok(())
486
+ }
487
+
488
+ fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
489
+ let path = fixture.path().join(path);
490
+ if let Some(parent) = path.parent() {
491
+ fs::create_dir_all(parent)?;
492
+ }
493
+ fs::write(path, source)
494
+ }
495
+ }