diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-11 02:05:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-11 02:05:34 +0900 |
| commit | 4df5f8491320e5795718cf0222e80fa27e57c8ad (patch) | |
| tree | 707e19f34dbdef18490ec3245d34389e3d189a57 /crates/mozart-core/src/repository_utils.rs | |
| parent | 8871b923fa3df1935c263db155cb8bc3d59705cd (diff) | |
| download | php-mozart-4df5f8491320e5795718cf0222e80fa27e57c8ad.tar.gz php-mozart-4df5f8491320e5795718cf0222e80fa27e57c8ad.tar.zst php-mozart-4df5f8491320e5795718cf0222e80fa27e57c8ad.zip | |
refactor(package): rename traits and switch dep maps to IndexMap
Rename Package/CompletePackage to PackageInterface/CompletePackageInterface
to mirror Composer's interface names, and split each into its own module
under crates/mozart-core/src/package/.
Switch dependency-link and metadata maps from BTreeMap to indexmap::IndexMap
so serialized JSON preserves the original key ordering rather than sorting
alphabetically — matching PHP associative-array semantics. The
--sort-packages behaviour in `require` is preserved via sort_unstable_keys.
Diffstat (limited to 'crates/mozart-core/src/repository_utils.rs')
| -rw-r--r-- | crates/mozart-core/src/repository_utils.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/crates/mozart-core/src/repository_utils.rs b/crates/mozart-core/src/repository_utils.rs index b16a0d6..7a797c4 100644 --- a/crates/mozart-core/src/repository_utils.rs +++ b/crates/mozart-core/src/repository_utils.rs @@ -19,7 +19,7 @@ use std::collections::BTreeSet; /// `package_name` only in that case. pub trait Required { fn package_name(&self) -> &str; - fn requires(&self) -> &std::collections::BTreeMap<String, String>; + fn requires(&self) -> &indexmap::IndexMap<String, String>; fn package_names(&self) -> Option<Vec<&str>> { None } @@ -38,8 +38,8 @@ pub trait Required { /// discovered, matching PHP's `$bucket[] = $candidate;` push pattern. pub fn filter_required_packages<P, V>( packages: &[P], - requirer_requires: &std::collections::BTreeMap<String, V>, - requirer_dev_requires: Option<&std::collections::BTreeMap<String, V>>, + requirer_requires: &indexmap::IndexMap<String, V>, + requirer_dev_requires: Option<&indexmap::IndexMap<String, V>>, ) -> Vec<usize> where P: Required, @@ -78,24 +78,23 @@ where #[cfg(test)] mod tests { use super::*; - use std::collections::BTreeMap; struct Pkg { name: String, - requires: BTreeMap<String, String>, + requires: indexmap::IndexMap<String, String>, } impl Required for Pkg { fn package_name(&self) -> &str { &self.name } - fn requires(&self) -> &BTreeMap<String, String> { + fn requires(&self) -> &indexmap::IndexMap<String, String> { &self.requires } } fn pkg(name: &str, requires: &[&str]) -> Pkg { - let mut r = BTreeMap::new(); + let mut r = indexmap::IndexMap::new(); for n in requires { r.insert(n.to_string(), "*".to_string()); } @@ -105,8 +104,8 @@ mod tests { } } - fn root_requires(names: &[&str]) -> BTreeMap<String, String> { - let mut m = BTreeMap::new(); + fn root_requires(names: &[&str]) -> indexmap::IndexMap<String, String> { + let mut m = indexmap::IndexMap::new(); for n in names { m.insert(n.to_string(), "*".to_string()); } @@ -167,7 +166,7 @@ mod tests { #[test] fn empty_requires_yields_nothing() { let packages = vec![pkg("a/a", &[]), pkg("b/b", &[])]; - let root: BTreeMap<String, String> = BTreeMap::new(); + let root: indexmap::IndexMap<_, ()> = indexmap::IndexMap::new(); let kept = filter_required_packages(&packages, &root, None); assert!(kept.is_empty()); } |
