diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-08 21:59:08 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-08 21:59:08 +0900 |
| commit | d0d05f14a4d1b36f517077ffdaa4b335c812190f (patch) | |
| tree | 76c2cd5e627963d9a23def6d414ba35153b354d6 /crates/mozart-registry/src/installed.rs | |
| parent | 9c2396134465613d3c650e881219572aecc777a5 (diff) | |
| download | php-mozart-d0d05f14a4d1b36f517077ffdaa4b335c812190f.tar.gz php-mozart-d0d05f14a4d1b36f517077ffdaa4b335c812190f.tar.zst php-mozart-d0d05f14a4d1b36f517077ffdaa4b335c812190f.zip | |
fix(suggests): align with Composer's SuggestsCommand pipeline
Port `Composer\Installer\SuggestedPackagesReporter` to
`mozart_core::installer` (modes, add_package, add_suggestions_from_package,
output, output_minimalistic, escape_output) and slim
`commands/suggests.rs` to mirror `SuggestsCommand::execute`. Defines
`HasSuggests`, `InstalledRepoLite`, `RootInfo` as the minimal stand-ins
for Composer's `PackageInterface` / `InstalledRepository` /
`onlyDependentsOf`.
Also fixes a latent bug where `provide`/`replace` virtuals were read
from `extra_fields` (always empty after a serde round-trip into
LockedPackage's typed fields) and moves the "additional suggestions
... --all" hint to fire after the rendered sections, matching
Composer's order.
Diffstat (limited to 'crates/mozart-registry/src/installed.rs')
| -rw-r--r-- | crates/mozart-registry/src/installed.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/mozart-registry/src/installed.rs b/crates/mozart-registry/src/installed.rs index da02c6a..108b844 100644 --- a/crates/mozart-registry/src/installed.rs +++ b/crates/mozart-registry/src/installed.rs @@ -1,3 +1,4 @@ +use mozart_core::installer::HasSuggests; use mozart_core::package::to_json_pretty; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; @@ -58,6 +59,24 @@ pub struct InstalledPackageEntry { pub extra_fields: BTreeMap<String, serde_json::Value>, } +impl HasSuggests for InstalledPackageEntry { + fn pretty_name(&self) -> &str { + &self.name + } + + fn suggests(&self) -> Vec<(String, String)> { + let Some(val) = self.extra_fields.get("suggest") else { + return Vec::new(); + }; + let Some(obj) = val.as_object() else { + return Vec::new(); + }; + obj.iter() + .filter_map(|(target, reason)| reason.as_str().map(|r| (target.clone(), r.to_string()))) + .collect() + } +} + impl Default for InstalledPackages { fn default() -> Self { Self::new() |
