dart-decimate 0.0.9 → 0.0.11

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 (48) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +50 -58
  4. package/package.json +1 -1
  5. package/src/cli/analyze.rs +6 -3
  6. package/src/cli/entry_points.rs +18 -2
  7. package/src/cli/list_run.rs +1 -0
  8. package/src/cli/tests.rs +74 -0
  9. package/src/config/rules.rs +50 -13
  10. package/src/dependencies/analyze.rs +7 -1
  11. package/src/dependencies/tests.rs +29 -0
  12. package/src/dependencies.rs +19 -0
  13. package/src/dependency_scripts.rs +2 -0
  14. package/src/dupes/declarations.rs +512 -0
  15. package/src/dupes/packages.rs +213 -0
  16. package/src/dupes/tests.rs +197 -0
  17. package/src/dupes.rs +57 -19
  18. package/src/extract/reference_tests.rs +106 -0
  19. package/src/extract/references.rs +264 -2
  20. package/src/extract/tests.rs +25 -0
  21. package/src/extract.rs +6 -3
  22. package/src/generated.rs +96 -3
  23. package/src/graph/package_config_tests.rs +123 -0
  24. package/src/graph/tests.rs +125 -0
  25. package/src/graph.rs +6 -5
  26. package/src/output/feature_flag_findings.rs +63 -1
  27. package/src/output/graph_findings.rs +73 -37
  28. package/src/output/route_cycle/aliases.rs +875 -0
  29. package/src/output/route_cycle/navigation.rs +1005 -0
  30. package/src/output/route_cycle/receivers.rs +41 -0
  31. package/src/output/route_cycle/state_context.rs +209 -0
  32. package/src/output/route_cycle/tests.rs +175 -0
  33. package/src/output/route_cycle.rs +730 -0
  34. package/src/output/security_findings.rs +15 -2
  35. package/src/output/tests.rs +104 -1
  36. package/src/output.rs +2 -1
  37. package/src/package_map.rs +220 -28
  38. package/src/routes.rs +6 -1
  39. package/src/scan.rs +15 -5
  40. package/src/security/detect.rs +140 -6
  41. package/src/security/tests.rs +96 -0
  42. package/src/trace.rs +1 -1
  43. package/src/widgets/forwarding.rs +684 -0
  44. package/src/widgets/patterns.rs +2595 -0
  45. package/src/widgets/reads.rs +616 -0
  46. package/src/widgets/tests.rs +1837 -55
  47. package/src/widgets/unrendered.rs +150 -0
  48. package/src/widgets.rs +25 -93
@@ -1,6 +1,6 @@
1
1
  use tree_sitter::Node;
2
2
 
3
- use super::IdentifierReference;
3
+ use super::{IdentifierReference, Location};
4
4
 
5
5
  pub(super) fn extract_identifier_references(
6
6
  root: Node<'_>,
@@ -16,6 +16,10 @@ fn collect_identifier_references(
16
16
  source: &str,
17
17
  references: &mut Vec<IdentifierReference>,
18
18
  ) {
19
+ if node.kind() == "string_literal" {
20
+ collect_string_interpolation_references(node, source, references);
21
+ }
22
+
19
23
  if is_reference_identifier(node, source) {
20
24
  if let Ok(name) = node.utf8_text(source.as_bytes()) {
21
25
  references.push(IdentifierReference {
@@ -26,11 +30,269 @@ fn collect_identifier_references(
26
30
  }
27
31
 
28
32
  let mut cursor = node.walk();
29
- for child in node.named_children(&mut cursor) {
33
+ for child in node.children(&mut cursor) {
30
34
  collect_identifier_references(child, source, references);
31
35
  }
32
36
  }
33
37
 
38
+ fn collect_string_interpolation_references(
39
+ node: Node<'_>,
40
+ source: &str,
41
+ references: &mut Vec<IdentifierReference>,
42
+ ) {
43
+ let mut cursor = node.walk();
44
+ let segments = node
45
+ .children(&mut cursor)
46
+ .filter(|child| is_string_literal_segment(child.kind()))
47
+ .collect::<Vec<_>>();
48
+ if !segments.is_empty() {
49
+ for segment in segments {
50
+ if is_raw_string_literal_segment(segment.kind()) {
51
+ continue;
52
+ }
53
+ let Ok(text) = segment.utf8_text(source.as_bytes()) else {
54
+ continue;
55
+ };
56
+ collect_string_segment_interpolation_references(
57
+ text,
58
+ segment.start_byte(),
59
+ source,
60
+ references,
61
+ );
62
+ }
63
+ return;
64
+ }
65
+
66
+ let Ok(text) = node.utf8_text(source.as_bytes()) else {
67
+ return;
68
+ };
69
+ if is_raw_string_literal(text) {
70
+ return;
71
+ }
72
+ collect_string_segment_interpolation_references(text, node.start_byte(), source, references);
73
+ }
74
+
75
+ fn collect_string_segment_interpolation_references(
76
+ text: &str,
77
+ base_byte: usize,
78
+ source: &str,
79
+ references: &mut Vec<IdentifierReference>,
80
+ ) {
81
+ let bytes = text.as_bytes();
82
+ let mut index = 0;
83
+ while let Some(relative) = bytes[index..].iter().position(|byte| *byte == b'$') {
84
+ let dollar = index + relative;
85
+ index = dollar + 1;
86
+ if is_escaped_dollar(bytes, dollar) {
87
+ continue;
88
+ }
89
+ let interpolation_start = dollar + 1;
90
+ if bytes.get(interpolation_start) == Some(&b'{') {
91
+ let Some(end) = interpolation_body_end(text, interpolation_start + 1) else {
92
+ continue;
93
+ };
94
+ index = end + 1;
95
+ continue;
96
+ }
97
+ if let Some((name, start)) = interpolation_identifier(text, interpolation_start) {
98
+ references.push(IdentifierReference {
99
+ name: name.to_owned(),
100
+ location: location_at(source, base_byte + start),
101
+ });
102
+ index = start + name.len();
103
+ }
104
+ }
105
+ }
106
+
107
+ fn is_string_literal_segment(kind: &str) -> bool {
108
+ kind.starts_with("raw_string_literal") || kind.starts_with("string_literal_")
109
+ }
110
+
111
+ fn is_raw_string_literal_segment(kind: &str) -> bool {
112
+ kind.starts_with("raw_string_literal")
113
+ }
114
+
115
+ fn is_raw_string_literal(text: &str) -> bool {
116
+ text.trim_start().starts_with("r'")
117
+ || text.trim_start().starts_with("r\"")
118
+ || text.trim_start().starts_with("R'")
119
+ || text.trim_start().starts_with("R\"")
120
+ }
121
+
122
+ fn is_escaped_dollar(bytes: &[u8], dollar: usize) -> bool {
123
+ let mut slash_count = 0;
124
+ let mut index = dollar;
125
+ while index > 0 && bytes[index - 1] == b'\\' {
126
+ slash_count += 1;
127
+ index -= 1;
128
+ }
129
+ slash_count % 2 == 1
130
+ }
131
+
132
+ fn interpolation_identifier(text: &str, start: usize) -> Option<(&str, usize)> {
133
+ let bytes = text.as_bytes();
134
+ let end = identifier_end(bytes, start)?;
135
+ Some((&text[start..end], start))
136
+ }
137
+
138
+ fn interpolation_body_end(text: &str, start: usize) -> Option<usize> {
139
+ let bytes = text.as_bytes();
140
+ let mut index = start;
141
+ let mut brace_depth = 0;
142
+ while index < bytes.len() {
143
+ if line_comment_start(bytes, index) {
144
+ index = line_comment_end(bytes, index);
145
+ continue;
146
+ }
147
+ if block_comment_start(bytes, index) {
148
+ index = block_comment_end(bytes, index);
149
+ continue;
150
+ }
151
+ match bytes[index] {
152
+ b'}' if brace_depth == 0 => return Some(index),
153
+ b'}' => brace_depth -= 1,
154
+ b'{' => brace_depth += 1,
155
+ b'r' | b'R' if raw_quoted_segment_start(bytes, index).is_some() => {
156
+ index = raw_quoted_segment_end(bytes, index);
157
+ continue;
158
+ }
159
+ b'\'' | b'"' => {
160
+ index = quoted_segment_end(bytes, index);
161
+ continue;
162
+ }
163
+ _ => {}
164
+ }
165
+ index += 1;
166
+ }
167
+ None
168
+ }
169
+
170
+ fn line_comment_start(bytes: &[u8], start: usize) -> bool {
171
+ bytes.get(start) == Some(&b'/') && bytes.get(start + 1) == Some(&b'/')
172
+ }
173
+
174
+ fn line_comment_end(bytes: &[u8], start: usize) -> usize {
175
+ bytes[start + 2..]
176
+ .iter()
177
+ .position(|byte| *byte == b'\n')
178
+ .map_or(bytes.len(), |relative| start + 2 + relative + 1)
179
+ }
180
+
181
+ fn block_comment_start(bytes: &[u8], start: usize) -> bool {
182
+ bytes.get(start) == Some(&b'/') && bytes.get(start + 1) == Some(&b'*')
183
+ }
184
+
185
+ fn block_comment_end(bytes: &[u8], start: usize) -> usize {
186
+ let mut index = start + 2;
187
+ let mut depth = 1;
188
+ while index + 1 < bytes.len() {
189
+ if block_comment_start(bytes, index) {
190
+ depth += 1;
191
+ index += 2;
192
+ continue;
193
+ }
194
+ if bytes[index] == b'*' && bytes[index + 1] == b'/' {
195
+ depth -= 1;
196
+ index += 2;
197
+ if depth == 0 {
198
+ return index;
199
+ }
200
+ continue;
201
+ }
202
+ index += 1;
203
+ }
204
+ bytes.len()
205
+ }
206
+
207
+ fn raw_quoted_segment_start(bytes: &[u8], start: usize) -> Option<usize> {
208
+ let quote_start = start + 1;
209
+ matches!(bytes.get(quote_start), Some(b'\'' | b'"')).then_some(quote_start)
210
+ }
211
+
212
+ fn raw_quoted_segment_end(bytes: &[u8], start: usize) -> usize {
213
+ let Some(quote_start) = raw_quoted_segment_start(bytes, start) else {
214
+ return start + 1;
215
+ };
216
+ let quote = bytes[quote_start];
217
+ let is_triple =
218
+ bytes.get(quote_start + 1) == Some(&quote) && bytes.get(quote_start + 2) == Some(&quote);
219
+ let mut index = quote_start + if is_triple { 3 } else { 1 };
220
+ while index < bytes.len() {
221
+ if is_triple {
222
+ if bytes[index] == quote
223
+ && bytes.get(index + 1) == Some(&quote)
224
+ && bytes.get(index + 2) == Some(&quote)
225
+ {
226
+ return index + 3;
227
+ }
228
+ } else if bytes[index] == quote {
229
+ return index + 1;
230
+ }
231
+ index += 1;
232
+ }
233
+ bytes.len()
234
+ }
235
+
236
+ fn quoted_segment_end(bytes: &[u8], start: usize) -> usize {
237
+ let quote = bytes[start];
238
+ let is_triple = bytes.get(start + 1) == Some(&quote) && bytes.get(start + 2) == Some(&quote);
239
+ let mut index = start + if is_triple { 3 } else { 1 };
240
+ while index < bytes.len() {
241
+ if bytes[index] == b'\\' {
242
+ index += 2;
243
+ continue;
244
+ }
245
+ if is_triple {
246
+ if bytes[index] == quote
247
+ && bytes.get(index + 1) == Some(&quote)
248
+ && bytes.get(index + 2) == Some(&quote)
249
+ {
250
+ return index + 3;
251
+ }
252
+ } else if bytes[index] == quote {
253
+ return index + 1;
254
+ }
255
+ index += 1;
256
+ }
257
+ bytes.len()
258
+ }
259
+
260
+ fn identifier_end(bytes: &[u8], start: usize) -> Option<usize> {
261
+ if !bytes
262
+ .get(start)
263
+ .is_some_and(|byte| is_identifier_start(*byte))
264
+ {
265
+ return None;
266
+ }
267
+ let mut end = start + 1;
268
+ while bytes.get(end).is_some_and(|byte| is_identifier_part(*byte)) {
269
+ end += 1;
270
+ }
271
+ Some(end)
272
+ }
273
+
274
+ const fn is_identifier_start(byte: u8) -> bool {
275
+ byte == b'_' || byte.is_ascii_alphabetic()
276
+ }
277
+
278
+ const fn is_identifier_part(byte: u8) -> bool {
279
+ is_identifier_start(byte) || byte.is_ascii_digit()
280
+ }
281
+
282
+ fn location_at(source: &str, byte_offset: usize) -> Location {
283
+ let mut line = 1;
284
+ let mut column = 0;
285
+ for byte in source[..byte_offset].bytes() {
286
+ if byte == b'\n' {
287
+ line += 1;
288
+ column = 0;
289
+ } else {
290
+ column += 1;
291
+ }
292
+ }
293
+ Location { line, column }
294
+ }
295
+
34
296
  fn is_reference_identifier(node: Node<'_>, source: &str) -> bool {
35
297
  if !matches!(node.kind(), "identifier" | "type_identifier") {
36
298
  return false;
@@ -600,6 +600,31 @@ void boot(Config config) {
600
600
  Ok(())
601
601
  }
602
602
 
603
+ #[test]
604
+ fn extracts_interpolation_references_without_raw_string_prefixes() -> Result<(), ExtractError> {
605
+ let source = r#"
606
+ void boot(String suffix, String escaped) {
607
+ print('$suffix ${suffix.toUpperCase()} ${r"raw literal"} \$escaped');
608
+ }
609
+ "#;
610
+
611
+ let extracted = extract_dart_source("lib/interpolation.dart", source)?;
612
+ let references = extracted
613
+ .references
614
+ .iter()
615
+ .map(|reference| reference.name.as_str())
616
+ .collect::<Vec<_>>();
617
+
618
+ assert!(references.contains(&"suffix"));
619
+ assert!(references.contains(&"toUpperCase"));
620
+ assert!(!references.contains(&"r"));
621
+ assert!(!references.contains(&"raw"));
622
+ assert!(!references.contains(&"literal"));
623
+ assert!(!references.contains(&"escaped"));
624
+
625
+ Ok(())
626
+ }
627
+
603
628
  #[test]
604
629
  fn extracts_references_from_annotations_generics_and_patterns() -> Result<(), ExtractError> {
605
630
  let source = "\
package/src/extract.rs CHANGED
@@ -82,8 +82,8 @@ pub struct DartFile {
82
82
  pub declarations: Vec<TopLevelDeclaration>,
83
83
  /// Class-like member declarations in source order.
84
84
  pub members: Vec<MemberDeclaration>,
85
- /// Identifier uses in source order, excluding import/export metadata and
86
- /// obvious declaration-name positions.
85
+ /// Identifier uses in source order, including non-raw string interpolation,
86
+ /// excluding import/export metadata and obvious declaration-name positions.
87
87
  pub references: Vec<IdentifierReference>,
88
88
  /// Type references from public declaration signatures, excluding bodies.
89
89
  pub signature_references: Vec<SignatureReference>,
@@ -212,7 +212,8 @@ pub struct MemberDeclaration {
212
212
  pub location: Location,
213
213
  }
214
214
 
215
- /// A syntactic identifier or type identifier use.
215
+ /// A syntactic identifier or type identifier use, including references found in
216
+ /// non-raw string interpolation.
216
217
  #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
217
218
  pub struct IdentifierReference {
218
219
  /// Referenced identifier text.
@@ -675,6 +676,8 @@ fn find_first_named_descendant_with_cursor<'tree>(
675
676
  #[cfg(test)]
676
677
  mod error_tests;
677
678
  #[cfg(test)]
679
+ mod reference_tests;
680
+ #[cfg(test)]
678
681
  mod string_tests;
679
682
  #[cfg(test)]
680
683
  mod tests;
package/src/generated.rs CHANGED
@@ -10,9 +10,12 @@ pub(crate) const GENERATED_DART_SUFFIXES: &[&str] = &[
10
10
 
11
11
  #[must_use]
12
12
  pub(crate) fn is_generated_dart_path(path: &Path) -> bool {
13
- path.file_name()
14
- .and_then(|name| name.to_str())
15
- .is_some_and(is_generated_dart_file_name)
13
+ let Some(file_name) = path.file_name().and_then(|name| name.to_str()) else {
14
+ return false;
15
+ };
16
+ is_generated_dart_file_name(file_name)
17
+ || is_flutter_gen_l10n_path(path, file_name)
18
+ || is_flutterfire_options_path(path)
16
19
  }
17
20
 
18
21
  #[must_use]
@@ -22,6 +25,65 @@ pub(crate) fn is_generated_dart_file_name(name: &str) -> bool {
22
25
  .any(|suffix| name.ends_with(suffix))
23
26
  }
24
27
 
28
+ fn is_flutter_gen_l10n_path(path: &Path, file_name: &str) -> bool {
29
+ (file_name == "app_localizations.dart"
30
+ || file_name
31
+ .strip_prefix("app_localizations_")
32
+ .is_some_and(is_flutter_gen_l10n_locale_file))
33
+ && path.components().any(|component| {
34
+ matches!(
35
+ component.as_os_str().to_str(),
36
+ Some("l10n" | "gen_l10n" | "generated")
37
+ )
38
+ })
39
+ }
40
+
41
+ fn is_flutter_gen_l10n_locale_file(name: &str) -> bool {
42
+ let Some(locale) = name.strip_suffix(".dart") else {
43
+ return false;
44
+ };
45
+ let parts = locale.split('_').collect::<Vec<_>>();
46
+ match parts.as_slice() {
47
+ [language] => is_language_subtag(language),
48
+ [language, script_or_region] => {
49
+ is_language_subtag(language)
50
+ && (is_script_subtag(script_or_region) || is_region_subtag(script_or_region))
51
+ }
52
+ [language, script, region] => {
53
+ is_language_subtag(language) && is_script_subtag(script) && is_region_subtag(region)
54
+ }
55
+ _ => false,
56
+ }
57
+ }
58
+
59
+ fn is_language_subtag(part: &str) -> bool {
60
+ matches!(part.len(), 2 | 3) && part.bytes().all(|byte| byte.is_ascii_lowercase())
61
+ }
62
+
63
+ fn is_script_subtag(part: &str) -> bool {
64
+ part.len() == 4
65
+ && part.bytes().enumerate().all(|(index, byte)| match index {
66
+ 0 => byte.is_ascii_uppercase(),
67
+ _ => byte.is_ascii_lowercase(),
68
+ })
69
+ }
70
+
71
+ fn is_region_subtag(part: &str) -> bool {
72
+ (part.len() == 2 && part.bytes().all(|byte| byte.is_ascii_uppercase()))
73
+ || (part.len() == 3 && part.bytes().all(|byte| byte.is_ascii_digit()))
74
+ }
75
+
76
+ #[must_use]
77
+ pub(crate) fn is_flutterfire_options_path(path: &Path) -> bool {
78
+ path.file_name()
79
+ .and_then(|name| name.to_str())
80
+ .is_some_and(|file_name| file_name == "firebase_options.dart")
81
+ && path
82
+ .parent()
83
+ .and_then(|parent| parent.file_name())
84
+ .is_some_and(|parent| parent == "lib")
85
+ }
86
+
25
87
  #[cfg(test)]
26
88
  mod tests {
27
89
  use std::path::Path;
@@ -50,4 +112,35 @@ mod tests {
50
112
  assert!(!is_generated_dart_file_name(file_name), "{file_name}");
51
113
  }
52
114
  }
115
+
116
+ #[test]
117
+ fn recognizes_flutter_generated_entry_files() {
118
+ for path in [
119
+ Path::new("lib/l10n/app_localizations.dart"),
120
+ Path::new("lib/l10n/app_localizations_en.dart"),
121
+ Path::new("lib/l10n/app_localizations_en_US.dart"),
122
+ Path::new("lib/l10n/app_localizations_zh_Hant.dart"),
123
+ Path::new("lib/l10n/app_localizations_sr_Latn_RS.dart"),
124
+ Path::new("lib/l10n/app_localizations_es_419.dart"),
125
+ Path::new("lib/gen_l10n/app_localizations_es.dart"),
126
+ Path::new("lib/firebase_options.dart"),
127
+ Path::new("packages/foo/lib/firebase_options.dart"),
128
+ ] {
129
+ assert!(is_generated_dart_path(path), "{}", path.display());
130
+ }
131
+ }
132
+
133
+ #[test]
134
+ fn rejects_handwritten_app_localizations_sources() {
135
+ for path in [
136
+ Path::new("lib/l10n/app_localizations_repository.dart"),
137
+ Path::new("lib/l10n/app_localizations_en_US_helper.dart"),
138
+ Path::new("lib/l10n/app_localizations_.dart"),
139
+ Path::new("lib/l10n/app_localizations_en-us.dart"),
140
+ Path::new("lib/src/firebase_options.dart"),
141
+ Path::new("packages/foo/lib/config/firebase_options.dart"),
142
+ ] {
143
+ assert!(!is_generated_dart_path(path), "{}", path.display());
144
+ }
145
+ }
53
146
  }
@@ -64,6 +64,113 @@ fn resolves_package_imports_using_ancestor_package_config_from_member_root()
64
64
  Ok(())
65
65
  }
66
66
 
67
+ #[test]
68
+ fn nested_pubspec_missing_path_dependency_does_not_use_ancestor_package_config()
69
+ -> Result<(), Box<dyn std::error::Error>> {
70
+ let fixture = tempfile::tempdir()?;
71
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
72
+ write(&fixture, "functions/worker/pubspec.yaml", "name: worker\n")?;
73
+ write(&fixture, "packages/shared/pubspec.yaml", "name: shared\n")?;
74
+ write(
75
+ &fixture,
76
+ ".dart_tool/package_config.json",
77
+ r#"{
78
+ "configVersion": 2,
79
+ "packages": [
80
+ {"name": "app", "rootUri": "../", "packageUri": "lib/"},
81
+ {"name": "shared", "rootUri": "../packages/shared", "packageUri": "lib/"}
82
+ ]
83
+ }
84
+ "#,
85
+ )?;
86
+ let worker = dart_file(
87
+ fixture.path().join("functions/worker/lib/worker.dart"),
88
+ "package:shared/shared.dart",
89
+ );
90
+ let shared = empty_dart_file(fixture.path().join("packages/shared/lib/shared.dart"));
91
+
92
+ let graph = build_module_graph(fixture.path(), &[worker, shared])?;
93
+
94
+ assert_eq!(graph.edge_count(), 0);
95
+ assert!(graph.unresolved().is_empty());
96
+
97
+ Ok(())
98
+ }
99
+
100
+ #[test]
101
+ fn nested_pubspec_missing_path_dependency_ignores_unowned_nested_pubspec()
102
+ -> Result<(), Box<dyn std::error::Error>> {
103
+ let fixture = tempfile::tempdir()?;
104
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
105
+ write(&fixture, "functions/worker/pubspec.yaml", "name: worker\n")?;
106
+ write(&fixture, "functions/shared/pubspec.yaml", "name: shared\n")?;
107
+ write(
108
+ &fixture,
109
+ ".dart_tool/package_config.json",
110
+ r#"{
111
+ "configVersion": 2,
112
+ "packages": [
113
+ {"name": "app", "rootUri": "../", "packageUri": "lib/"}
114
+ ]
115
+ }
116
+ "#,
117
+ )?;
118
+ let worker = dart_file(
119
+ fixture.path().join("functions/worker/lib/worker.dart"),
120
+ "package:shared/shared.dart",
121
+ );
122
+ let shared = empty_dart_file(fixture.path().join("functions/shared/lib/shared.dart"));
123
+
124
+ let graph = build_module_graph(fixture.path(), &[worker, shared])?;
125
+
126
+ assert_eq!(graph.edge_count(), 0);
127
+ assert!(graph.unresolved().is_empty());
128
+
129
+ Ok(())
130
+ }
131
+
132
+ #[test]
133
+ fn nested_pubspec_path_dependency_resolves_before_ancestor_package_config()
134
+ -> Result<(), Box<dyn std::error::Error>> {
135
+ let fixture = tempfile::tempdir()?;
136
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
137
+ write(
138
+ &fixture,
139
+ "functions/worker/pubspec.yaml",
140
+ "name: worker\ndependencies:\n shared:\n path: ../shared\n",
141
+ )?;
142
+ write(&fixture, "functions/shared/pubspec.yaml", "name: shared\n")?;
143
+ write(&fixture, "packages/shared/pubspec.yaml", "name: shared\n")?;
144
+ write(
145
+ &fixture,
146
+ ".dart_tool/package_config.json",
147
+ r#"{
148
+ "configVersion": 2,
149
+ "packages": [
150
+ {"name": "app", "rootUri": "../", "packageUri": "lib/"},
151
+ {"name": "shared", "rootUri": "../packages/shared", "packageUri": "lib/"}
152
+ ]
153
+ }
154
+ "#,
155
+ )?;
156
+ let worker = dart_file(
157
+ fixture.path().join("functions/worker/lib/worker.dart"),
158
+ "package:shared/shared.dart",
159
+ );
160
+ let local_shared = empty_dart_file(fixture.path().join("functions/shared/lib/shared.dart"));
161
+ let configured_shared = empty_dart_file(fixture.path().join("packages/shared/lib/shared.dart"));
162
+
163
+ let graph = build_module_graph(fixture.path(), &[worker, local_shared, configured_shared])?;
164
+
165
+ assert_eq!(graph.edge_count(), 1);
166
+ assert_eq!(
167
+ strip_root(fixture.path(), &graph.dependencies()[0].to_path),
168
+ PathBuf::from("functions/shared/lib/shared.dart")
169
+ );
170
+
171
+ Ok(())
172
+ }
173
+
67
174
  fn dart_file(path: PathBuf, import_uri: &str) -> DartFile {
68
175
  DartFile {
69
176
  path,
@@ -87,6 +194,22 @@ fn dart_file(path: PathBuf, import_uri: &str) -> DartFile {
87
194
  }
88
195
  }
89
196
 
197
+ fn empty_dart_file(path: PathBuf) -> DartFile {
198
+ DartFile {
199
+ path,
200
+ library: None,
201
+ part_of: None,
202
+ imports: Vec::new(),
203
+ exports: Vec::new(),
204
+ parts: Vec::new(),
205
+ declarations: Vec::new(),
206
+ members: Vec::new(),
207
+ references: Vec::new(),
208
+ signature_references: Vec::new(),
209
+ routes: Vec::new(),
210
+ }
211
+ }
212
+
90
213
  fn strip_root(root: &Path, path: &Path) -> PathBuf {
91
214
  path.strip_prefix(root).unwrap_or(path).to_path_buf()
92
215
  }