dart-decimate 0.0.67 → 0.0.68

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 CHANGED
@@ -102,16 +102,16 @@ checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
102
102
 
103
103
  [[package]]
104
104
  name = "dart-decimate"
105
- version = "0.0.67"
105
+ version = "0.0.68"
106
106
  dependencies = [
107
107
  "clap",
108
108
  "glob",
109
109
  "ignore",
110
+ "noyalib",
110
111
  "petgraph",
111
112
  "rayon",
112
113
  "serde",
113
114
  "serde_json",
114
- "serde_yaml_ng",
115
115
  "tempfile",
116
116
  "thiserror",
117
117
  "toml",
@@ -165,6 +165,12 @@ version = "0.1.5"
165
165
  source = "registry+https://github.com/rust-lang/crates.io-index"
166
166
  checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
167
167
 
168
+ [[package]]
169
+ name = "foldhash"
170
+ version = "0.2.0"
171
+ source = "registry+https://github.com/rust-lang/crates.io-index"
172
+ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
173
+
168
174
  [[package]]
169
175
  name = "getrandom"
170
176
  version = "0.4.3"
@@ -201,7 +207,7 @@ version = "0.15.5"
201
207
  source = "registry+https://github.com/rust-lang/crates.io-index"
202
208
  checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
203
209
  dependencies = [
204
- "foldhash",
210
+ "foldhash 0.1.5",
205
211
  ]
206
212
 
207
213
  [[package]]
@@ -234,6 +240,8 @@ checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
234
240
  dependencies = [
235
241
  "equivalent",
236
242
  "hashbrown 0.17.1",
243
+ "serde",
244
+ "serde_core",
237
245
  ]
238
246
 
239
247
  [[package]]
@@ -248,6 +256,12 @@ version = "0.2.189"
248
256
  source = "registry+https://github.com/rust-lang/crates.io-index"
249
257
  checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
250
258
 
259
+ [[package]]
260
+ name = "libm"
261
+ version = "0.2.16"
262
+ source = "registry+https://github.com/rust-lang/crates.io-index"
263
+ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
264
+
251
265
  [[package]]
252
266
  name = "linux-raw-sys"
253
267
  version = "0.12.1"
@@ -266,6 +280,24 @@ version = "2.8.3"
266
280
  source = "registry+https://github.com/rust-lang/crates.io-index"
267
281
  checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
268
282
 
283
+ [[package]]
284
+ name = "noyalib"
285
+ version = "0.0.58"
286
+ source = "registry+https://github.com/rust-lang/crates.io-index"
287
+ checksum = "3fad8f1a552070f6ba5f60f25e880f7b6daeda8fe138f589345141d31a21a3bb"
288
+ dependencies = [
289
+ "hashbrown 0.17.1",
290
+ "indexmap",
291
+ "itoa",
292
+ "libm",
293
+ "memchr",
294
+ "rustc-hash",
295
+ "ryu",
296
+ "serde_core",
297
+ "serde_ignored",
298
+ "smallvec",
299
+ ]
300
+
269
301
  [[package]]
270
302
  name = "once_cell"
271
303
  version = "1.21.4"
@@ -357,6 +389,12 @@ version = "0.8.11"
357
389
  source = "registry+https://github.com/rust-lang/crates.io-index"
358
390
  checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
359
391
 
392
+ [[package]]
393
+ name = "rustc-hash"
394
+ version = "2.1.3"
395
+ source = "registry+https://github.com/rust-lang/crates.io-index"
396
+ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
397
+
360
398
  [[package]]
361
399
  name = "rustix"
362
400
  version = "1.1.5"
@@ -415,12 +453,23 @@ dependencies = [
415
453
  "syn",
416
454
  ]
417
455
 
456
+ [[package]]
457
+ name = "serde_ignored"
458
+ version = "0.1.14"
459
+ source = "registry+https://github.com/rust-lang/crates.io-index"
460
+ checksum = "115dffd5f3853e06e746965a20dcbae6ee747ae30b543d91b0e089668bb07798"
461
+ dependencies = [
462
+ "serde",
463
+ "serde_core",
464
+ ]
465
+
418
466
  [[package]]
419
467
  name = "serde_json"
420
- version = "1.0.151"
468
+ version = "1.0.154"
421
469
  source = "registry+https://github.com/rust-lang/crates.io-index"
422
- checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
470
+ checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
423
471
  dependencies = [
472
+ "foldhash 0.2.0",
424
473
  "indexmap",
425
474
  "itoa",
426
475
  "memchr",
@@ -431,32 +480,25 @@ dependencies = [
431
480
 
432
481
  [[package]]
433
482
  name = "serde_spanned"
434
- version = "1.1.1"
483
+ version = "1.1.2"
435
484
  source = "registry+https://github.com/rust-lang/crates.io-index"
436
- checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
485
+ checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c"
437
486
  dependencies = [
438
487
  "serde_core",
439
488
  ]
440
489
 
441
- [[package]]
442
- name = "serde_yaml_ng"
443
- version = "0.10.0"
444
- source = "registry+https://github.com/rust-lang/crates.io-index"
445
- checksum = "7b4db627b98b36d4203a7b458cf3573730f2bb591b28871d916dfa9efabfd41f"
446
- dependencies = [
447
- "indexmap",
448
- "itoa",
449
- "ryu",
450
- "serde",
451
- "unsafe-libyaml",
452
- ]
453
-
454
490
  [[package]]
455
491
  name = "shlex"
456
492
  version = "2.0.1"
457
493
  source = "registry+https://github.com/rust-lang/crates.io-index"
458
494
  checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
459
495
 
496
+ [[package]]
497
+ name = "smallvec"
498
+ version = "1.16.3"
499
+ source = "registry+https://github.com/rust-lang/crates.io-index"
500
+ checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b"
501
+
460
502
  [[package]]
461
503
  name = "streaming-iterator"
462
504
  version = "0.1.9"
@@ -515,9 +557,9 @@ dependencies = [
515
557
 
516
558
  [[package]]
517
559
  name = "toml"
518
- version = "1.1.6+spec-1.1.0"
560
+ version = "1.1.8+spec-1.1.0"
519
561
  source = "registry+https://github.com/rust-lang/crates.io-index"
520
- checksum = "920602543f0911ab71da12c50d59701da54c196d1a2bf5cb4b75667f137a406a"
562
+ checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d"
521
563
  dependencies = [
522
564
  "indexmap",
523
565
  "serde_core",
@@ -530,33 +572,33 @@ dependencies = [
530
572
 
531
573
  [[package]]
532
574
  name = "toml_datetime"
533
- version = "1.1.1+spec-1.1.0"
575
+ version = "1.1.2+spec-1.1.0"
534
576
  source = "registry+https://github.com/rust-lang/crates.io-index"
535
- checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
577
+ checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053"
536
578
  dependencies = [
537
579
  "serde_core",
538
580
  ]
539
581
 
540
582
  [[package]]
541
583
  name = "toml_parser"
542
- version = "1.1.3+spec-1.1.0"
584
+ version = "1.1.5+spec-1.1.0"
543
585
  source = "registry+https://github.com/rust-lang/crates.io-index"
544
- checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
586
+ checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"
545
587
  dependencies = [
546
588
  "winnow",
547
589
  ]
548
590
 
549
591
  [[package]]
550
592
  name = "toml_writer"
551
- version = "1.1.2+spec-1.1.0"
593
+ version = "1.1.3+spec-1.1.0"
552
594
  source = "registry+https://github.com/rust-lang/crates.io-index"
553
- checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
595
+ checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770"
554
596
 
555
597
  [[package]]
556
598
  name = "tree-sitter"
557
- version = "0.27.0"
599
+ version = "0.27.1"
558
600
  source = "registry+https://github.com/rust-lang/crates.io-index"
559
- checksum = "2038684e0058edba0d17302619f62eabce4a8e11c6ac59506996a8d79848851d"
601
+ checksum = "a5129de2ccc97808c4583d48f1fb44576d015cf241e432800572bda11ef30c3b"
560
602
  dependencies = [
561
603
  "cc",
562
604
  "regex",
@@ -577,9 +619,9 @@ dependencies = [
577
619
 
578
620
  [[package]]
579
621
  name = "tree-sitter-language"
580
- version = "0.1.8"
622
+ version = "0.1.9"
581
623
  source = "registry+https://github.com/rust-lang/crates.io-index"
582
- checksum = "ca0d1bf6fdd806e43ae5198f82f527056d359def39e54e67a0f478ac09dac081"
624
+ checksum = "d0af592be68c579aa78a16846bd19422978c3c52e438523d45ff5d1bff1f9d4a"
583
625
 
584
626
  [[package]]
585
627
  name = "unicode-ident"
@@ -587,12 +629,6 @@ version = "1.0.26"
587
629
  source = "registry+https://github.com/rust-lang/crates.io-index"
588
630
  checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
589
631
 
590
- [[package]]
591
- name = "unsafe-libyaml"
592
- version = "0.2.11"
593
- source = "registry+https://github.com/rust-lang/crates.io-index"
594
- checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
595
-
596
632
  [[package]]
597
633
  name = "walkdir"
598
634
  version = "2.5.0"
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "dart-decimate"
3
- version = "0.0.67"
3
+ version = "0.0.68"
4
4
  edition = "2024"
5
5
  rust-version = "1.90"
6
6
  description = "Rust-native codebase intelligence for Dart and Flutter module graphs."
@@ -17,11 +17,11 @@ include = ["/Cargo.toml", "/Cargo.lock", "/README.md", "/LICENSE", "/src/**"]
17
17
  clap = { version = "4", default-features = false, features = ["std", "help", "usage", "error-context", "suggestions"] }
18
18
  glob = "0.3"
19
19
  ignore = "0.4"
20
+ noyalib = "0.0.58"
20
21
  petgraph = "0.8"
21
22
  rayon = "1"
22
23
  serde = { version = "1", features = ["derive"] }
23
24
  serde_json = "1"
24
- serde_yaml_ng = "0.10"
25
25
  tempfile = "3"
26
26
  thiserror = "2"
27
27
  toml = "1.1"
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.67
93
+ pnpm dlx dart-decimate@0.0.68
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.67"
104
+ "dart-decimate": "0.0.68"
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.67 --locked
120
+ cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.68 --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.67
131
+ # dart-decimate 0.0.68
132
132
  ```
133
133
 
134
134
  ## pnpm dlx
@@ -539,7 +539,7 @@ Example shape:
539
539
  {
540
540
  "schema_version": "dart-decimate.report.v1",
541
541
  "kind": "combined",
542
- "tool": "dart-decimate 0.0.67",
542
+ "tool": "dart-decimate 0.0.68",
543
543
  "command": "check",
544
544
  "verdict": "fail",
545
545
  "summary": {
@@ -555,7 +555,7 @@ Example shape:
555
555
 
556
556
  The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
557
557
  string includes the producing version so saved reports identify the exact
558
- build, for example `dart-decimate 0.0.67`.
558
+ build, for example `dart-decimate 0.0.68`.
559
559
 
560
560
  When grouped security findings hide additional occurrences, `next_steps` can
561
561
  include `review-security-surface`, which reruns
@@ -643,7 +643,7 @@ you need the installed binary's exact list.
643
643
  For a complete repository check, including discovered local packages:
644
644
 
645
645
  ```bash
646
- pnpm dlx dart-decimate@0.0.67 --strict
646
+ pnpm dlx dart-decimate@0.0.68 --strict
647
647
  ```
648
648
 
649
649
  This runs every enabled check from the repository root. The default duplication
@@ -686,7 +686,7 @@ This repository forbids `unsafe_code`.
686
686
 
687
687
  ## Release Flow
688
688
 
689
- Current source version: `0.0.67`.
689
+ Current source version: `0.0.68`.
690
690
 
691
691
  After the first public release, changes should go through pull requests. PRs to
692
692
  `main` must bump both `Cargo.toml` and `package.json` above the base branch and to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dart-decimate",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -60,7 +60,7 @@
60
60
  }
61
61
  },
62
62
  "devDependencies": {
63
- "@biomejs/biome": "2.5.14",
64
- "@types/node": "22.20.4"
63
+ "@biomejs/biome": "2.5.15",
64
+ "@types/node": "22.20.5"
65
65
  }
66
66
  }
@@ -103,7 +103,7 @@ fn file_has_main(file: &crate::DartFile) -> bool {
103
103
 
104
104
  fn patrol_test_suffix(root: &Path) -> Option<String> {
105
105
  let source = fs::read_to_string(root.join("pubspec.yaml")).ok()?;
106
- let pubspec = serde_yaml_ng::from_str::<serde_yaml_ng::Value>(&source).ok()?;
106
+ let pubspec = crate::package_map::parse_yaml(&source).ok()?;
107
107
  pubspec
108
108
  .get("patrol")?
109
109
  .get("test_file_suffix")?
@@ -2,8 +2,8 @@ use std::collections::BTreeSet;
2
2
  use std::fs;
3
3
  use std::path::Path;
4
4
 
5
+ use noyalib::Value;
5
6
  use serde_json::Value as JsonValue;
6
- use serde_yaml_ng::Value;
7
7
 
8
8
  pub(super) fn flutter_metadata_dependencies(
9
9
  package_root: &Path,
@@ -88,5 +88,5 @@ fn collect_plugin_names(value: &JsonValue, dependencies: &mut BTreeSet<String>)
88
88
  }
89
89
 
90
90
  fn mapping_field<'value>(value: &'value Value, key: &str) -> Option<&'value Value> {
91
- value.as_mapping()?.get(Value::String(key.to_owned()))
91
+ value.as_mapping()?.get(key)
92
92
  }
@@ -1,7 +1,7 @@
1
1
  use std::path::{Path, PathBuf};
2
2
 
3
+ use noyalib::Value;
3
4
  use serde::{Deserialize, Serialize};
4
- use serde_yaml_ng::Value;
5
5
 
6
6
  use crate::Location;
7
7
 
@@ -49,10 +49,8 @@ pub(super) fn misconfigured_dependency_overrides(
49
49
  overrides
50
50
  .iter()
51
51
  .filter_map(|(name, value)| {
52
- let raw_key = name
53
- .as_str()
54
- .map_or_else(|| format!("{name:?}"), ToOwned::to_owned);
55
- let reason = if !name.as_str().is_some_and(valid_dart_package_name) {
52
+ let raw_key = name.clone();
53
+ let reason = if !valid_dart_package_name(name) {
56
54
  DependencyOverrideMisconfigReason::UnparsableKey
57
55
  } else if value.is_null() {
58
56
  DependencyOverrideMisconfigReason::EmptyValue
@@ -62,7 +60,7 @@ pub(super) fn misconfigured_dependency_overrides(
62
60
  Some(MisconfiguredDependencyOverride {
63
61
  package: package.to_owned(),
64
62
  pubspec_path: pubspec_path.to_path_buf(),
65
- dependency: name.as_str().map(ToOwned::to_owned),
63
+ dependency: Some(name.clone()),
66
64
  location: dependency_location(
67
65
  source,
68
66
  DependencySection::DependencyOverrides,
@@ -1,4 +1,4 @@
1
- use serde_yaml_ng::Value;
1
+ use noyalib::Value;
2
2
 
3
3
  use super::DependencySection;
4
4
  use crate::Location;
@@ -49,7 +49,7 @@ fn is_safe_scalar_value(value: &str) -> bool {
49
49
  {
50
50
  return false;
51
51
  }
52
- serde_yaml_ng::from_str::<Value>(value)
52
+ crate::package_map::parse_yaml(value)
53
53
  .is_ok_and(|value| !matches!(value, Value::Mapping(_) | Value::Sequence(_) | Value::Null))
54
54
  }
55
55
 
@@ -2,11 +2,12 @@ use std::collections::BTreeSet;
2
2
  use std::fs;
3
3
  use std::path::{Path, PathBuf};
4
4
 
5
+ use noyalib::{Mapping, Value};
5
6
  use serde::{Deserialize, Serialize};
6
- use serde_yaml_ng::{Mapping, Value};
7
7
  use thiserror::Error;
8
8
 
9
9
  use crate::graph::normalize_path;
10
+ use crate::package_map::parse_yaml;
10
11
  use crate::{DependencyKind, ExtractError, GraphError, Location};
11
12
 
12
13
  mod analyze;
@@ -192,12 +193,10 @@ pub enum DependencyHygieneError {
192
193
  /// Pubspec path.
193
194
  path: PathBuf,
194
195
  /// Underlying YAML parse error.
195
- source: serde_yaml_ng::Error,
196
+ source: Box<noyalib::Error>,
196
197
  },
197
198
  }
198
199
 
199
- /// Find local pubspec declarations for one dependency package.
200
- ///
201
200
  /// # Errors
202
201
  ///
203
202
  /// Returns [`DependencyHygieneError`] if pubspec discovery or parsing fails.
@@ -240,8 +239,6 @@ pub fn declared_package_dependencies(
240
239
  Ok(declarations)
241
240
  }
242
241
 
243
- /// List local pub packages under a root.
244
- ///
245
242
  /// # Errors
246
243
  ///
247
244
  /// Returns [`DependencyHygieneError`] if pubspec discovery or parsing fails.
@@ -388,11 +385,9 @@ fn read_pubspec_source(path: &Path) -> Result<String, DependencyHygieneError> {
388
385
  }
389
386
 
390
387
  fn parse_pubspec_value(path: &Path, source: &str) -> Result<Value, DependencyHygieneError> {
391
- serde_yaml_ng::from_str::<Value>(source).map_err(|source| {
392
- DependencyHygieneError::ParsePubspec {
393
- path: path.to_path_buf(),
394
- source,
395
- }
388
+ parse_yaml(source).map_err(|source| DependencyHygieneError::ParsePubspec {
389
+ path: path.to_path_buf(),
390
+ source: Box::new(source),
396
391
  })
397
392
  }
398
393
 
@@ -416,15 +411,9 @@ fn read_pubspec_overrides(
416
411
  fn read_locked_packages(pubspec_path: &Path) -> Option<BTreeSet<String>> {
417
412
  let lock_path = pubspec_path.with_file_name("pubspec.lock");
418
413
  let source = fs::read_to_string(lock_path).ok()?;
419
- let value = serde_yaml_ng::from_str::<Value>(&source).ok()?;
414
+ let value = parse_yaml(&source).ok()?;
420
415
  let packages = mapping_field(&value, "packages")?;
421
- Some(
422
- packages
423
- .keys()
424
- .filter_map(Value::as_str)
425
- .map(ToOwned::to_owned)
426
- .collect(),
427
- )
416
+ Some(packages.keys().cloned().collect())
428
417
  }
429
418
 
430
419
  fn merged_declared_dependencies(
@@ -516,7 +505,7 @@ fn declared_dependencies_for_sections(
516
505
  })
517
506
  .flat_map(|(section, mapping)| {
518
507
  mapping.iter().filter_map(move |(name, value)| {
519
- let name = name.as_str()?.to_owned();
508
+ let name = name.clone();
520
509
  if section == DependencySection::DependencyOverrides
521
510
  && (!valid_dart_package_name(&name) || value.is_null())
522
511
  {
@@ -564,23 +553,17 @@ pub(crate) fn valid_dart_package_name(name: &str) -> bool {
564
553
  }
565
554
 
566
555
  fn mapping_field<'value>(value: &'value Value, field: &str) -> Option<&'value Mapping> {
567
- value
568
- .as_mapping()?
569
- .get(Value::String(field.to_owned()))?
570
- .as_mapping()
556
+ value.as_mapping()?.get(field)?.as_mapping()
571
557
  }
572
558
 
573
559
  fn string_field<'value>(value: &'value Value, field: &str) -> Option<&'value str> {
574
- value
575
- .as_mapping()?
576
- .get(Value::String(field.to_owned()))?
577
- .as_str()
560
+ value.as_mapping()?.get(field)?.as_str()
578
561
  }
579
562
 
580
563
  fn has_top_level_field(value: &Value, field: &str) -> bool {
581
564
  value
582
565
  .as_mapping()
583
- .is_some_and(|mapping| mapping.contains_key(Value::String(field.to_owned())))
566
+ .is_some_and(|mapping| mapping.contains_key(field))
584
567
  }
585
568
 
586
569
  #[cfg(test)]
@@ -22,7 +22,7 @@ fn pubspec_has_top_level_key(package_root: &Path, key: &str) -> bool {
22
22
  let path = package_root.join("pubspec.yaml");
23
23
  fs::read_to_string(path)
24
24
  .ok()
25
- .and_then(|source| serde_yaml_ng::from_str::<serde_yaml_ng::Value>(&source).ok())
25
+ .and_then(|source| crate::package_map::parse_yaml(&source).ok())
26
26
  .is_some_and(|pubspec| pubspec.get(key).is_some())
27
27
  }
28
28
 
package/src/generated.rs CHANGED
@@ -133,16 +133,16 @@ fn flutter_l10n_config(directory: &Path) -> Option<FlutterL10nConfig> {
133
133
 
134
134
  fn read_flutter_l10n_config(project_root: &Path, config_path: &Path) -> Option<FlutterL10nConfig> {
135
135
  let source = fs::read_to_string(config_path).ok()?;
136
- let config = serde_yaml_ng::from_str::<serde_yaml_ng::Value>(&source).ok()?;
136
+ let config = crate::package_map::parse_yaml(&source).ok()?;
137
137
  let output_file = config
138
138
  .get("output-localization-file")
139
- .and_then(serde_yaml_ng::Value::as_str)
139
+ .and_then(noyalib::Value::as_str)
140
140
  .unwrap_or("app_localizations.dart")
141
141
  .to_owned();
142
142
  let output_dir = config
143
143
  .get("output-dir")
144
- .and_then(serde_yaml_ng::Value::as_str)
145
- .or_else(|| config.get("arb-dir").and_then(serde_yaml_ng::Value::as_str))
144
+ .and_then(noyalib::Value::as_str)
145
+ .or_else(|| config.get("arb-dir").and_then(noyalib::Value::as_str))
146
146
  .unwrap_or("lib/l10n");
147
147
  Some(FlutterL10nConfig {
148
148
  output_dir: project_root.join(output_dir),
package/src/graph.rs CHANGED
@@ -237,7 +237,7 @@ pub enum GraphError {
237
237
  /// Pubspec path.
238
238
  path: PathBuf,
239
239
  /// Underlying YAML parse error.
240
- source: serde_yaml_ng::Error,
240
+ source: Box<noyalib::Error>,
241
241
  },
242
242
  /// A discovered `.dart_tool/package_config.json` could not be read.
243
243
  #[error("failed to read package config {path}: {source}")]
@@ -273,17 +273,9 @@ pub enum GraphError {
273
273
  },
274
274
  }
275
275
 
276
- /// Build a directed module graph from extracted Dart file facts.
277
- ///
278
- /// Local relative imports and exports are resolved from the source file's
279
- /// directory. `package:` imports resolve through Pub package metadata,
280
- /// including `.dart_tool/package_config.json`, workspaces, path dependencies,
281
- /// same-package imports, and owner-local copied packages with duplicate names.
282
- ///
283
276
  /// # Errors
284
277
  ///
285
- /// Returns [`GraphError`] if package config or declared Pub package metadata
286
- /// cannot be read or parsed, or if a workspace glob entry is invalid.
278
+ /// Returns [`GraphError`] if Pub package metadata cannot be read or parsed, or a workspace glob is invalid.
287
279
  pub fn build_module_graph(
288
280
  root: impl AsRef<Path>,
289
281
  files: &[DartFile],
@@ -291,8 +283,6 @@ pub fn build_module_graph(
291
283
  build_module_graph_with_options(root, files, &GraphOptions::default())
292
284
  }
293
285
 
294
- /// Build a directed module graph using explicit graph construction options.
295
- ///
296
286
  /// # Errors
297
287
  ///
298
288
  /// Returns [`GraphError`] under the same conditions as [`build_module_graph`].
@@ -2,8 +2,8 @@ use std::collections::{BTreeMap, BTreeSet};
2
2
  use std::fs;
3
3
  use std::path::{Path, PathBuf};
4
4
 
5
+ use noyalib::{DuplicateKeyPolicy, Mapping, MergeKeyPolicy, ParserConfig, Value};
5
6
  use serde::Deserialize;
6
- use serde_yaml_ng::{Mapping, Value};
7
7
 
8
8
  use crate::graph::{GraphError, normalize_path};
9
9
  use crate::scan::{IgnoreMatcher, project_walk};
@@ -342,11 +342,9 @@ impl Pubspec {
342
342
  Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
343
343
  Err(source) => return Err(GraphError::ReadPubspec { path, source }),
344
344
  };
345
- let value = serde_yaml_ng::from_str::<Value>(&source).map_err(|source| {
346
- GraphError::ParsePubspec {
347
- path: path.clone(),
348
- source,
349
- }
345
+ let value = parse_yaml(&source).map_err(|source| GraphError::ParsePubspec {
346
+ path: path.clone(),
347
+ source: Box::new(source),
350
348
  })?;
351
349
 
352
350
  let overrides = read_pubspec_overrides(package_root)?;
@@ -372,9 +370,20 @@ fn read_pubspec_overrides(package_root: &Path) -> Result<Option<Value>, GraphErr
372
370
  Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
373
371
  Err(source) => return Err(GraphError::ReadPubspec { path, source }),
374
372
  };
375
- serde_yaml_ng::from_str::<Value>(&source)
373
+ parse_yaml(&source)
376
374
  .map(Some)
377
- .map_err(|source| GraphError::ParsePubspec { path, source })
375
+ .map_err(|source| GraphError::ParsePubspec {
376
+ path,
377
+ source: Box::new(source),
378
+ })
379
+ }
380
+
381
+ pub(crate) fn parse_yaml(source: &str) -> Result<Value, noyalib::Error> {
382
+ let config = ParserConfig::new()
383
+ .duplicate_key_policy(DuplicateKeyPolicy::Error)
384
+ .merge_key_policy(MergeKeyPolicy::AsOrdinary)
385
+ .alias_anchor_ratio(None);
386
+ noyalib::from_str_with_config(source, &config)
378
387
  }
379
388
 
380
389
  fn resolve_config_uri(config_dir: &Path, uri: &str) -> Option<PathBuf> {
@@ -466,7 +475,7 @@ fn path_dependencies(value: &Value, overrides: Option<&Value>) -> Vec<PathDepend
466
475
  if let Some(overrides) = mapping_field(override_source, "dependency_overrides") {
467
476
  let override_names = overrides
468
477
  .keys()
469
- .filter_map(Value::as_str)
478
+ .map(String::as_str)
470
479
  .collect::<BTreeSet<_>>();
471
480
  dependencies.retain(|dependency| !override_names.contains(dependency.name.as_str()));
472
481
  }
@@ -482,7 +491,7 @@ fn path_dependencies_from_mapping(mapping: &Mapping) -> Vec<PathDependency> {
482
491
  mapping
483
492
  .iter()
484
493
  .filter_map(|(name, dependency)| {
485
- let name = name.as_str()?.to_owned();
494
+ let name = name.clone();
486
495
  let path = string_field(dependency, "path")?;
487
496
  Some(PathDependency {
488
497
  name,
@@ -493,23 +502,17 @@ fn path_dependencies_from_mapping(mapping: &Mapping) -> Vec<PathDependency> {
493
502
  }
494
503
 
495
504
  fn mapping_field<'value>(value: &'value Value, field: &str) -> Option<&'value Mapping> {
496
- value
497
- .as_mapping()?
498
- .get(Value::String(field.to_owned()))?
499
- .as_mapping()
505
+ value.as_mapping()?.get(field)?.as_mapping()
500
506
  }
501
507
 
502
508
  fn string_field<'value>(value: &'value Value, field: &str) -> Option<&'value str> {
503
- value
504
- .as_mapping()?
505
- .get(Value::String(field.to_owned()))?
506
- .as_str()
509
+ value.as_mapping()?.get(field)?.as_str()
507
510
  }
508
511
 
509
512
  fn string_sequence_field(value: &Value, field: &str) -> Vec<String> {
510
513
  value
511
514
  .as_mapping()
512
- .and_then(|mapping| mapping.get(Value::String(field.to_owned())))
515
+ .and_then(|mapping| mapping.get(field))
513
516
  .and_then(Value::as_sequence)
514
517
  .into_iter()
515
518
  .flatten()
@@ -521,7 +524,7 @@ fn string_sequence_field(value: &Value, field: &str) -> Vec<String> {
521
524
  fn has_top_level_field(value: &Value, field: &str) -> bool {
522
525
  value
523
526
  .as_mapping()
524
- .is_some_and(|mapping| mapping.contains_key(Value::String(field.to_owned())))
527
+ .is_some_and(|mapping| mapping.contains_key(field))
525
528
  }
526
529
 
527
530
  fn expand_workspace_member(root: &Path, member: &str) -> Result<Vec<PathBuf>, GraphError> {
@@ -591,6 +594,55 @@ mod tests {
591
594
  Ok(())
592
595
  }
593
596
 
597
+ #[test]
598
+ fn rejects_pubspec_with_duplicate_keys() -> Result<(), Box<dyn std::error::Error>> {
599
+ let fixture = TempDir::new()?;
600
+ write(
601
+ &fixture,
602
+ "pubspec.yaml",
603
+ "name: app\ndependencies:\n a:\n path: a\ndependencies: {}\n",
604
+ )?;
605
+
606
+ match PackageMap::discover(fixture.path()) {
607
+ Err(GraphError::ParsePubspec { path, .. }) => {
608
+ assert_eq!(path, fixture.path().join("pubspec.yaml"));
609
+ }
610
+ other => panic!("expected duplicate key parse error, got {other:?}"),
611
+ }
612
+
613
+ Ok(())
614
+ }
615
+
616
+ #[test]
617
+ fn parses_pubspec_that_reuses_one_anchor_many_times() -> Result<(), Box<dyn std::error::Error>>
618
+ {
619
+ let fixture = TempDir::new()?;
620
+ write(
621
+ &fixture,
622
+ "pubspec.yaml",
623
+ &format!(
624
+ "name: app\nshared: &v x\nlist: [{}]\n",
625
+ ["*v"; 11].join(", ")
626
+ ),
627
+ )?;
628
+
629
+ let packages = PackageMap::discover(fixture.path())?;
630
+
631
+ assert_eq!(packages.names(), vec!["app"]);
632
+
633
+ Ok(())
634
+ }
635
+
636
+ #[test]
637
+ fn keeps_yaml_merge_keys_literal() -> Result<(), Box<dyn std::error::Error>> {
638
+ let value = parse_yaml("name: app\ntemplate: &t {dependencies: {a: ^1.0.0}}\n<<: *t\n")?;
639
+
640
+ assert!(value.get("dependencies").is_none());
641
+ assert!(value.get("<<").is_some());
642
+
643
+ Ok(())
644
+ }
645
+
594
646
  #[test]
595
647
  fn optional_nested_pubspec_parse_failure_does_not_poison_later_strict_discovery()
596
648
  -> Result<(), Box<dyn std::error::Error>> {
package/src/scan.rs CHANGED
@@ -68,7 +68,7 @@ pub enum ScanError {
68
68
  /// Pubspec path.
69
69
  path: PathBuf,
70
70
  /// Underlying YAML parse error.
71
- source: serde_yaml_ng::Error,
71
+ source: Box<noyalib::Error>,
72
72
  },
73
73
  /// A pub workspace glob pattern was invalid.
74
74
  #[error("invalid pub workspace glob pattern {pattern}: {source}")]
@@ -102,11 +102,6 @@ pub enum ScanError {
102
102
  Graph(#[from] GraphError),
103
103
  }
104
104
 
105
- /// Discover, parse, and graph all `.dart` files under `root` and discovered
106
- /// local package roots.
107
- ///
108
- /// Parsing is parallelized with Rayon after a deterministic filesystem walk.
109
- ///
110
105
  /// # Errors
111
106
  ///
112
107
  /// Returns [`ScanError`] when discovery, parsing, or graph construction fails.
@@ -114,11 +109,6 @@ pub fn scan_project(root: impl AsRef<Path>) -> Result<ScannedProject, ScanError>
114
109
  scan_project_with_options(root, &ScanOptions::default())
115
110
  }
116
111
 
117
- /// Discover, parse, and graph all non-ignored `.dart` files under `root` and
118
- /// discovered local package roots.
119
- ///
120
- /// Parsing is parallelized with Rayon after a deterministic filesystem walk.
121
- ///
122
112
  /// # Errors
123
113
  ///
124
114
  /// Returns [`ScanError`] when discovery, parsing, or graph construction fails.
@@ -242,8 +232,7 @@ fn discover_dart_files(
242
232
  Ok(())
243
233
  }
244
234
 
245
- /// Walk `dir` with the project's ignore rules: `.gitignore`, the configured
246
- /// ignore patterns, skipped tool directories and nested checkouts.
235
+ /// Skips `.gitignore` and configured ignores, tool directories and nested checkouts.
247
236
  pub(crate) fn project_walk(root: &Path, dir: &Path, ignore_matcher: &IgnoreMatcher) -> Walk {
248
237
  let filter_root = root.to_path_buf();
249
238
  let filter_matcher = ignore_matcher.clone();
@@ -304,8 +293,7 @@ fn has_skipped_directory(root: &Path, path: &Path) -> bool {
304
293
  .is_some_and(|parent| parent.ancestors().any(should_skip_dir))
305
294
  }
306
295
 
307
- /// Whether `dir` is the root of its own Git or Jujutsu checkout, such as a
308
- /// nested worktree or clone, which belongs to a separate package graph.
296
+ /// A nested Git or Jujutsu checkout belongs to a separate package graph.
309
297
  pub(crate) fn is_repository_root(dir: &Path) -> bool {
310
298
  dir.join(".git").exists() || dir.join(".jj").exists()
311
299
  }