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/package/locker.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'crates/shirabe/src/package') diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index e90a8f0..59b81b1 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -14,6 +14,7 @@ use shirabe_php_shim::{ use crate::installer::InstallationManager; use crate::io::IOInterface; +use crate::json::JsonEncodeOptions; use crate::json::JsonFile; use crate::package::BasePackageHandle; use crate::package::CompleteAliasPackageHandle; @@ -133,14 +134,14 @@ impl Locker { Ok(hash( "md5", - &JsonFile::encode( + &JsonFile::encode_with_options( &PhpMixed::Array( relevant_content .into_iter() .map(|(k, v)| (k, Box::new(v))) .collect(), ), - 0, + JsonEncodeOptions::none(), ), )) } @@ -634,13 +635,9 @@ impl Locker { } else { self.virtual_file_written = true; let parsed = JsonFile::parse_json( - Some(&JsonFile::encode_with_indent( - &PhpMixed::Array(lock.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), - shirabe_php_shim::JSON_UNESCAPED_SLASHES - | shirabe_php_shim::JSON_PRETTY_PRINT - | shirabe_php_shim::JSON_UNESCAPED_UNICODE, - JsonFile::INDENT_DEFAULT, - )), + Some(&JsonFile::encode(&PhpMixed::Array( + lock.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), + ))), None, )?; let parsed_map: IndexMap = match parsed { -- cgit v1.3.1