33 detect_indent:: detect_indent,
44 detect_newline_style:: LineEnding ,
55 serde_json:: Value as JsonValue ,
6- serde_yaml:: { Mapping , Value as YamlValue } ,
76 std:: {
87 fs,
98 path:: { Path , PathBuf } ,
109 process:: Command ,
1110 rc:: Rc ,
1211 } ,
1312 thiserror:: Error ,
13+ yaml_serde:: { Mapping , Value as YamlValue } ,
1414} ;
1515
1616/// A YAML file held in memory alongside its raw text and a queue of
1717/// pending edit operations. The dual model lets reads (`json_view`,
18- /// `pnpm_catalog_names`, etc.) hit the parsed `serde_yaml ::Value` while
18+ /// `pnpm_catalog_names`, etc.) hit the parsed `yaml_serde ::Value` while
1919/// writes replay `patches` against the original `raw` text via the
2020/// `yamlpatch` crate so comments / blank lines / indent are preserved.
2121#[ derive( Debug ) ]
2222pub struct YamlFile {
2323 pub filepath : PathBuf ,
2424 pub formatting : DetectedFormatting ,
25- pub contents : serde_yaml :: Value ,
25+ pub contents : yaml_serde :: Value ,
2626 /// Original on-disk text. Empty for auto-created files.
2727 pub raw : String ,
2828 /// Edit operations recorded since load (or since last write).
@@ -47,13 +47,13 @@ impl YamlFile {
4747#[ derive( Debug , Clone ) ]
4848pub enum PendingYamlOp {
4949 /// Replace the value at `segments`.
50- Replace { segments : Vec < String > , value : serde_yaml :: Value } ,
50+ Replace { segments : Vec < String > , value : yaml_serde :: Value } ,
5151 /// Add `key: value` at the mapping referenced by `segments`. Empty
5252 /// `segments` targets the document root.
5353 Add {
5454 segments : Vec < String > ,
5555 key : String ,
56- value : serde_yaml :: Value ,
56+ value : yaml_serde :: Value ,
5757 } ,
5858 /// Remove the entry at `segments`.
5959 Remove { segments : Vec < String > } ,
@@ -86,9 +86,9 @@ pub enum DiskIoError {
8686 #[ error( "Failed to serialise JSON:\n \n {0}" ) ]
8787 JsonSerialize ( #[ source] serde_json:: Error ) ,
8888 #[ error( "Failed to parse YAML:\n \n {0}" ) ]
89- YamlParse ( #[ source] serde_yaml :: Error ) ,
89+ YamlParse ( #[ source] yaml_serde :: Error ) ,
9090 #[ error( "Failed to serialise YAML:\n \n {0}" ) ]
91- YamlSerialize ( #[ source] serde_yaml :: Error ) ,
91+ YamlSerialize ( #[ source] yaml_serde :: Error ) ,
9292 #[ error( "Failed to parse YAML for format-preserving write:\n \n {0}" ) ]
9393 YamlPatchParse ( #[ source] yamlpath:: QueryError ) ,
9494 #[ error( "Failed to apply YAML patch:\n \n {0}" ) ]
@@ -313,7 +313,7 @@ pub trait DiskIo {
313313 fn write_json_file < V : serde:: ser:: Serialize > ( & self , file : & File < V > ) -> Result < ( ) , DiskIoError > ;
314314 /// Write a YAML file to disk. Format-preserving via `yamlpatch` when
315315 /// `file.raw` is non-empty and `file.patches` is non-empty; otherwise
316- /// the in-memory `contents` is serialised fresh via `serde_yaml `.
316+ /// the in-memory `contents` is serialised fresh via `yaml_serde `.
317317 fn write_yaml_file ( & self , file : & YamlFile ) -> Result < ( ) , DiskIoError > ;
318318 /// Find every `package.json` under `root` that matches `patterns`,
319319 /// honouring `.gitignore` and skipping `node_modules`/`.git`. Patterns
@@ -411,7 +411,7 @@ impl DiskIo for LiveDiskIo {
411411 fn read_yaml_typed < V : serde:: de:: DeserializeOwned > ( & self , filepath : & Path ) -> Option < Result < File < V > , DiskIoError > > {
412412 self . read_textfile ( filepath) . map ( |res| {
413413 res. and_then ( |file| {
414- serde_yaml :: from_str :: < V > ( & file. contents )
414+ yaml_serde :: from_str :: < V > ( & file. contents )
415415 . map_err ( DiskIoError :: YamlParse )
416416 . map ( |parsed| File {
417417 filepath : file. filepath ,
@@ -497,7 +497,7 @@ pub(crate) fn get_pretty_json_bytes<V: serde::ser::Serialize>(file: &File<V>) ->
497497///
498498/// Two paths:
499499///
500- /// - **Empty `raw` (auto-created file) OR no patches recorded**: serialize `contents` fresh via `serde_yaml ::to_string`. Nothing exists to
500+ /// - **Empty `raw` (auto-created file) OR no patches recorded**: serialize `contents` fresh via `yaml_serde ::to_string`. Nothing exists to
501501/// preserve.
502502/// - **Non-empty `raw` AND patches recorded**: build a `yamlpath::Document` from the original text, replay each `PendingYamlOp` as a
503503/// `yamlpatch::Patch`, and return the resulting `.source()` text. Comments, blank lines, key order, and indent are preserved.
@@ -507,7 +507,7 @@ pub(crate) fn get_pretty_json_bytes<V: serde::ser::Serialize>(file: &File<V>) ->
507507/// instead of silently degrading.
508508pub fn render_yaml_bytes ( file : & YamlFile ) -> Result < Vec < u8 > , DiskIoError > {
509509 if file. raw . is_empty ( ) || file. patches . is_empty ( ) {
510- let yaml = serde_yaml :: to_string ( & file. contents ) . map_err ( DiskIoError :: YamlSerialize ) ?;
510+ let yaml = yaml_serde :: to_string ( & file. contents ) . map_err ( DiskIoError :: YamlSerialize ) ?;
511511 let mut bytes = yaml. into_bytes ( ) ;
512512 bytes. extend ( file. formatting . newline . as_bytes ( ) ) ;
513513 return Ok ( bytes) ;
@@ -550,11 +550,11 @@ fn route_from_segments(segments: &[String]) -> yamlpath::Route<'static> {
550550/// starts with a reserved indicator (`@`, `` ` ``) or contains
551551/// syntactically significant punctuation. yamlpatch's `Op::Add`
552552/// inserts the key verbatim into the output text, so any quoting must
553- /// be baked into the string we hand it. Defers to `serde_yaml ` for the
553+ /// be baked into the string we hand it. Defers to `yaml_serde ` for the
554554/// quote decision so we match standard scalar emission rules.
555555fn yaml_quote_key ( key : & str ) -> String {
556556 let value = YamlValue :: String ( key. to_string ( ) ) ;
557- let serialised = serde_yaml :: to_string ( & value) . expect ( "string serialisation cannot fail" ) ;
557+ let serialised = yaml_serde :: to_string ( & value) . expect ( "string serialisation cannot fail" ) ;
558558 serialised. trim_end ( ) . to_string ( )
559559}
560560
@@ -576,7 +576,7 @@ pub fn parse_yaml_file(raw: String, filepath: PathBuf) -> Option<YamlFile> {
576576/// where the I/O layer already wraps errors.
577577fn parse_yaml_file_strict ( raw : String , filepath : PathBuf ) -> Result < YamlFile , DiskIoError > {
578578 let formatting = detect_formatting ( & raw ) ;
579- let contents = serde_yaml :: from_str :: < YamlValue > ( & raw ) . map_err ( DiskIoError :: YamlParse ) ?;
579+ let contents = yaml_serde :: from_str :: < YamlValue > ( & raw ) . map_err ( DiskIoError :: YamlParse ) ?;
580580 Ok ( YamlFile {
581581 filepath,
582582 formatting,
@@ -1004,7 +1004,7 @@ fn ensure_catalog_block<'a>(file: &'a mut YamlFile, catalog_name: &str) -> &'a m
10041004 }
10051005}
10061006
1007- /// Convert a `serde_yaml ::Value` into a `serde_json::Value` for JSON pointer
1007+ /// Convert a `yaml_serde ::Value` into a `serde_json::Value` for JSON pointer
10081008/// access. Hand-rolled to avoid any reliance on the yaml crate's `Serialize`
10091009/// quirks. Yaml mappings with non-string keys produce `null` for that entry.
10101010pub ( crate ) fn yaml_to_json ( yaml : & YamlValue ) -> JsonValue {
0 commit comments