aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src')
-rw-r--r--crates/shirabe-external-packages/src/composer/metadata_minifier/metadata_minifier.rs31
1 files changed, 26 insertions, 5 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.
}