diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-07 12:16:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-07 12:17:24 +0900 |
| commit | 14138dde4a8c874bdc498edd25d1a2d7dc9022be (patch) | |
| tree | 6c1cc375a7dd2e4ba3294918fe689f6b734fd434 | |
| parent | 54af47e286d0fb601e2e60aeb19002f6b7937574 (diff) | |
| download | php-shirabe-14138dde4a8c874bdc498edd25d1a2d7dc9022be.tar.gz php-shirabe-14138dde4a8c874bdc498edd25d1a2d7dc9022be.tar.zst php-shirabe-14138dde4a8c874bdc498edd25d1a2d7dc9022be.zip | |
feat(metadata-minifier): port expand for minified package metadata
Implement MetadataMinifier::expand with the PHP list-of-arrays signature
(Vec<IndexMap>) and wire it into ComposerRepository so composer/2.0
minified package metadata is expanded, resolving the phase-b TODO.
minify() is left unported as it is not used in Composer itself.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3 files changed, 27 insertions, 8 deletions
diff --git a/crates/shirabe-external-packages/src/composer/metadata_minifier/metadata_minifier.rs b/crates/shirabe-external-packages/src/composer/metadata_minifier/metadata_minifier.rs index 8861936..f97209d 100644 --- a/crates/shirabe-external-packages/src/composer/metadata_minifier/metadata_minifier.rs +++ b/crates/shirabe-external-packages/src/composer/metadata_minifier/metadata_minifier.rs @@ -5,11 +5,32 @@ use shirabe_php_shim::PhpMixed; pub struct MetadataMinifier; impl MetadataMinifier { - pub fn expand(_minified_data: IndexMap<String, PhpMixed>) -> IndexMap<String, PhpMixed> { - todo!() - } + pub fn expand(versions: Vec<IndexMap<String, PhpMixed>>) -> Vec<IndexMap<String, PhpMixed>> { + let mut expanded: Vec<IndexMap<String, PhpMixed>> = Vec::new(); + let mut expanded_version: Option<IndexMap<String, PhpMixed>> = None; + for version_data in versions { + if expanded_version.as_ref().map_or(true, |ev| ev.is_empty()) { + expanded.push(version_data.clone()); + expanded_version = Some(version_data); + continue; + } + + // add any changes from the previous version to the expanded one + let ev = expanded_version.as_mut().unwrap(); + for (key, val) in version_data { + if matches!(&val, PhpMixed::String(s) if s == "__unset") { + ev.shift_remove(&key); + } else { + ev.insert(key, val); + } + } - pub fn minify(_packages: IndexMap<String, PhpMixed>) -> IndexMap<String, PhpMixed> { - todo!() + expanded.push(ev.clone()); + } + + expanded } + + // MetadataMinifier::minify() is not ported because it is not used in Composer itself. + // The function is mainly for package repositories. } diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index 20d9974..d8559b7 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -539,7 +539,6 @@ impl VersionGuesser { let branch_clone = branch.clone(); let cmd_line: Vec<String> = array_map( move |component: &String| -> String { - // TODO(phase-b): str_replace with array arguments — emulating let r1 = str_replace("%candidate%", &candidate_clone, component); str_replace("%branch%", &branch_clone, &r1) }, diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index f9fa551..644ece7 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -1794,8 +1794,7 @@ impl ComposerRepository { .and_then(|v| v.as_string()) .map_or(false, |s| s == "composer/2.0"); if minified { - // TODO(phase-b): MetadataMinifier::expand expects/returns IndexMap but versions is Vec - versions = todo!("MetadataMinifier::expand signature mismatch with Vec<IndexMap>"); + versions = MetadataMinifier::expand(versions); } names_found.insert(real_name.clone(), true); |
