Patch-Source: https://github.com/oriontvv/convfmt/pull/193 -- From 8c2d2f62071d0dc4e17cb6536cdab2bd60bd598a Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sat, 23 May 2026 23:55:49 +0200 Subject: [PATCH] make hocon optional hocon crate is unmaintained since 2023 and it pulls a huge dependency bloat. --- Cargo.toml | 6 +++++- src/lib.rs | 36 +++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 45c95ed..b218757 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,17 @@ categories = ["command-line-utilities"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["hocon"] +hocon = ["dep:hocon"] + [dependencies] anyhow = "1.0.100" bson = { version = "3.1.0", features = ["serde"] } clap = { version = "4.5.53", features = ["derive"] } csv = "1.4.0" hjson = "1.1.0" -hocon = { version = "0.9.0", features = ["serde-support"] } +hocon = { version = "0.9.0", features = ["serde-support"], optional = true } json5 = "1.3.0" linked-hash-map = "0.5.6" plist = "1.8.0" diff --git a/src/lib.rs b/src/lib.rs index e0530ae..030f570 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ mod csv_value; +#[cfg(feature = "hocon")] mod hocon_value; mod jsonl_value; mod xml_value; @@ -6,9 +7,10 @@ mod xml_value; use anyhow::Result; use serde::Serialize; +#[cfg(feature = "hocon")] +use crate::hocon_value::{HoconWrapper, load_hocon}; use crate::{ csv_value::{CsvWrapper, json_to_csv, load_csv}, - hocon_value::{HoconWrapper, load_hocon}, jsonl_value::{JsonlWrapper, json_to_jsonl, load_jsonl}, xml_value::{XmlWrapper, json_to_xml, load_xml}, }; @@ -18,6 +20,7 @@ pub enum Format { Bson, Csv, Hjson, + #[cfg(feature = "hocon")] Hocon, Json, Json5, @@ -36,6 +39,7 @@ pub enum Value { Bson(bson::Bson), Csv(CsvWrapper), Hjson(serde_hjson::Value), + #[cfg(feature = "hocon")] Hocon(HoconWrapper), Json(serde_json::Value), Json5(serde_json::Value), @@ -53,6 +57,7 @@ pub fn load_input(input: &[u8], format: Format) -> Result { Format::Bson => Value::Bson(bson::deserialize_from_slice(input)?), Format::Csv => Value::Csv(load_csv(input)?), Format::Hjson => Value::Hjson(serde_hjson::from_slice(input)?), + #[cfg(feature = "hocon")] Format::Hocon => Value::Hocon(load_hocon(input)?), Format::Json => Value::Json(serde_json::from_slice(input)?), Format::Json5 => Value::Json5(json5::from_str(str::from_utf8(input)?)?), @@ -81,7 +86,9 @@ pub fn dump_value(value: &Value, format: Format, is_compact: bool) -> Result serde_hjson::to_vec(value)?, + #[cfg(feature = "hocon")] (Format::Hocon, true) => serde_json::to_vec(value)?, + #[cfg(feature = "hocon")] (Format::Hocon, false) => serde_json::to_vec_pretty(value)?, (Format::Json, true) => serde_json::to_vec(value)?, (Format::Json, false) => serde_json::to_vec_pretty(value)?, @@ -136,6 +143,7 @@ mod tests { the_answer: 42 }"# } + #[cfg(feature = "hocon")] (Format::Hocon, _) => { r#" array: [a,b] @@ -246,7 +254,6 @@ the_answer: 42 #[case(Format::Json5, Format::Json, false)] #[case(Format::Json, Format::Bson, false)] #[case(Format::Bson, Format::Json5, true)] - #[case(Format::Hocon, Format::Json, false)] #[case(Format::Xml, Format::Yaml, false)] #[case(Format::Toml, Format::Xml, true)] #[case(Format::Toml, Format::Hjson, true)] @@ -273,6 +280,12 @@ the_answer: 42 assert_eq!(output, expected_output); } + #[cfg(feature = "hocon")] + #[test] + fn test_convert_formats_hocon() { + test_convert_formats(Format::Hocon, Format::Json, false); + } + #[rstest] #[case( Format::Csv, @@ -317,13 +330,6 @@ the_answer: 42 "#, true )] - #[case( - Format::Hocon, - Format::Json, - r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#, - r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#, - true - )] #[case( Format::Json, Format::Json, @@ -363,4 +369,16 @@ the_answer: 42 assert_eq!(output, expected_output); } + + #[cfg(feature = "hocon")] + #[test] + fn test_raw_convert_hocon() { + test_raw_convert( + Format::Hocon, + Format::Json, + r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#, + r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#, + true, + ); + } } -- 2.52.0