From d0edb5b7ac3456f99c2f2576e8992cc12d60574a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 5 Jun 2026 04:45:11 +0900 Subject: refactor(json): model JsonFile encode/write options as a typed struct Replace the i64 bitmask + encode_with_indent split with a JsonEncodeOptions struct (Default = JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE, default indent). encode/write each get a default form plus an explicit encode_with_options/write_with_options variant, mirroring PHP's optional $options argument. write_with_options always encodes with self.indent, matching PHP write(). Also reconcile call sites with the PHP sources: most ported sites passed 0 where Composer omits the argument (= default flags), so JsonManipulator/ShowCommand and JsonConfigSource now use the default options; only ComposerRepository and Locker genuinely pass 0. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/repository/vcs/vcs_driver.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/src/repository/vcs/vcs_driver.rs') diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index 15dd722..8c3b571 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -3,14 +3,13 @@ use chrono::{DateTime, Utc}; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; -use shirabe_php_shim::{ - JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed, extension_loaded, -}; +use shirabe_php_shim::{PhpMixed, extension_loaded}; use crate::cache::Cache; use crate::config::Config; use crate::downloader::TransportException; use crate::io::IOInterface; +use crate::json::JsonEncodeOptions; use crate::json::JsonFile; use crate::repository::vcs::VcsDriverInterface; use crate::util::Filesystem; @@ -188,9 +187,12 @@ pub trait VcsDriver: VcsDriverInterface { .map(|(k, v)| (k.clone(), Box::new(v.clone()))) .collect(), ); - let encoded = JsonFile::encode( + let encoded = JsonFile::encode_with_options( &composer_mixed, - JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES, + JsonEncodeOptions { + pretty_print: false, + ..Default::default() + }, ); self.cache_mut().map(|c| c.write(identifier, &encoded)); } -- cgit v1.3.1