aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-06 15:16:07 +0900
committernsfisis <nsfisis@gmail.com>2026-06-06 15:17:00 +0900
commit1e7aabcae1b2139aa20a80fbf303c74388933f55 (patch)
tree07c5f4e7502841fef21909b2aa8269e6e71fb2a3 /crates/shirabe/src/package
parentadba8b1969a3f40245324d7feb5905693ca65d5e (diff)
downloadphp-shirabe-1e7aabcae1b2139aa20a80fbf303c74388933f55.tar.gz
php-shirabe-1e7aabcae1b2139aa20a80fbf303c74388933f55.tar.zst
php-shirabe-1e7aabcae1b2139aa20a80fbf303c74388933f55.zip
fix(array-dumper): emit package links and require Link pretty constraint
Resolve the phase-b TODO that left the supported-link-types loop as dead code (links were always an empty Vec), so requires/conflicts/provides/ replaces/require-dev are dumped again via PackageInterface::get_links_for_type, matching the PHP magic-call loop. Every Link in production is constructed with a pretty constraint (all ArrayLoader/AliasPackage/PlatformRepository/InstalledRepository sites pass one), so make Link::pretty_constraint a required String instead of Option<String>. get_pretty_constraint() now returns &str directly rather than anyhow::Result<&str>, dropping the unreachable UnexpectedValueException guard, and all call sites are updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package')
-rw-r--r--crates/shirabe/src/package/alias_package.rs8
-rw-r--r--crates/shirabe/src/package/dumper/array_dumper.rs13
-rw-r--r--crates/shirabe/src/package/link.rs18
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs2
-rw-r--r--crates/shirabe/src/package/locker.rs5
-rw-r--r--crates/shirabe/src/package/version/version_selector.rs2
6 files changed, 16 insertions, 32 deletions
diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs
index 7ab1967..657b007 100644
--- a/crates/shirabe/src/package/alias_package.rs
+++ b/crates/shirabe/src/package/alias_package.rs
@@ -144,7 +144,7 @@ impl AliasPackage {
let mut new_links: Vec<Link> = vec![];
for link in links.values() {
// link is self.version, but must be replacing also the replaced version
- if link.get_pretty_constraint().unwrap_or("") == "self.version" {
+ if link.get_pretty_constraint() == "self.version" {
let constraint = SimpleConstraint::new(
"=".to_string(),
self.version.to_string(),
@@ -155,7 +155,7 @@ impl AliasPackage {
link.get_target().to_string(),
constraint.into(),
Some(link_type.to_string()),
- Some(pretty_version.clone()),
+ pretty_version.clone(),
);
new_links.push(new_link);
}
@@ -165,7 +165,7 @@ impl AliasPackage {
}
} else {
for link in links.values_mut() {
- if link.get_pretty_constraint().unwrap_or("") == "self.version" {
+ if link.get_pretty_constraint() == "self.version" {
if link_type == Link::TYPE_REQUIRE {
self.has_self_version_requires = true;
}
@@ -179,7 +179,7 @@ impl AliasPackage {
link.get_target().to_string(),
constraint.into(),
Some(link_type.to_string()),
- Some(pretty_version.clone()),
+ pretty_version.clone(),
);
}
}
diff --git a/crates/shirabe/src/package/dumper/array_dumper.rs b/crates/shirabe/src/package/dumper/array_dumper.rs
index 6a693bd..4217308 100644
--- a/crates/shirabe/src/package/dumper/array_dumper.rs
+++ b/crates/shirabe/src/package/dumper/array_dumper.rs
@@ -122,21 +122,16 @@ impl ArrayDumper {
data.insert("dist".to_string(), PhpMixed::Array(dist));
}
- // corresponds to: foreach (BasePackage::$supportedLinkTypes as $type => $opts) { $links = $package->{'get'.ucfirst($opts['method'])}(); ... }
- for (type_name, opts) in SUPPORTED_LINK_TYPES.iter() {
- // TODO(phase-b): PackageInterface needs get_links_by_method to mimic PHP magic call
- let links: Vec<crate::package::Link> = Vec::new();
- let _ = (&opts.method, &package);
+ for type_name in SUPPORTED_LINK_TYPES.keys() {
+ let links = package.get_links_for_type(type_name);
if links.is_empty() {
continue;
}
let mut link_map: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- for link in &links {
+ for link in links.values() {
link_map.insert(
link.get_target().to_string(),
- Box::new(PhpMixed::String(
- link.get_pretty_constraint().unwrap_or_default().to_string(),
- )),
+ Box::new(PhpMixed::String(link.get_pretty_constraint().to_string())),
);
}
link_map.sort_keys();
diff --git a/crates/shirabe/src/package/link.rs b/crates/shirabe/src/package/link.rs
index 13bd66b..ab1e9c6 100644
--- a/crates/shirabe/src/package/link.rs
+++ b/crates/shirabe/src/package/link.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Package/Link.php
-use shirabe_php_shim::UnexpectedValueException;
use shirabe_semver::constraint::AnyConstraint;
use crate::package::PackageInterfaceHandle;
@@ -10,7 +9,7 @@ pub struct Link {
pub(crate) target: String,
pub(crate) constraint: AnyConstraint,
pub(crate) description: String,
- pub(crate) pretty_constraint: Option<String>,
+ pub(crate) pretty_constraint: String,
}
impl Clone for Link {
@@ -65,7 +64,7 @@ impl Link {
target: String,
constraint: AnyConstraint,
description: Option<String>,
- pretty_constraint: Option<String>,
+ pretty_constraint: String,
) -> Self {
let description = description.unwrap_or_else(|| Self::TYPE_UNKNOWN.to_string());
let description = if description == Self::TYPE_DEV_REQUIRE {
@@ -98,17 +97,8 @@ impl Link {
&self.constraint
}
- pub fn get_pretty_constraint(&self) -> anyhow::Result<&str> {
- match &self.pretty_constraint {
- None => Err(anyhow::anyhow!(UnexpectedValueException {
- message: format!(
- "Link {} has been misconfigured and had no prettyConstraint given.",
- self.to_string()
- ),
- code: 0,
- })),
- Some(s) => Ok(s.as_str()),
- }
+ pub fn get_pretty_constraint(&self) -> &str {
+ &self.pretty_constraint
}
pub fn to_string(&self) -> String {
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index 52f3da1..965cc55 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -874,7 +874,7 @@ impl ArrayLoader {
target.to_string(),
parsed_constraint,
Some(description.to_string()),
- Some(pretty_constraint.to_string()),
+ pretty_constraint.to_string(),
))
}
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 47a9974..51177db 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -957,7 +957,7 @@ impl Locker {
if PlatformRepository::is_platform_package(&link.get_target()) {
continue;
}
- if link.get_pretty_constraint().ok() == Some("self.version") {
+ if link.get_pretty_constraint() == "self.version" {
continue;
}
if installed_repo
@@ -995,7 +995,6 @@ impl Locker {
PhpMixed::String(
provider_link
.get_pretty_constraint()
- .unwrap_or_default()
.to_string(),
),
PhpMixed::String(format!(
@@ -1015,7 +1014,7 @@ impl Locker {
set.description,
link.get_target(),
description,
- link.get_pretty_constraint().unwrap_or_default()
+ link.get_pretty_constraint(),
));
} else {
missing_requirement_info.push(format!(
diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs
index 9e41f97..ecf08b5 100644
--- a/crates/shirabe/src/package/version/version_selector.rs
+++ b/crates/shirabe/src/package/version/version_selector.rs
@@ -200,7 +200,7 @@ impl VersionSelector {
pkg.get_pretty_version(),
link.get_description(),
link.get_target(),
- link.get_pretty_constraint().unwrap_or_default(),
+ link.get_pretty_constraint(),
reason
),
true,