aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
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
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')
-rw-r--r--crates/shirabe/src/command/base_dependency_command.rs8
-rw-r--r--crates/shirabe/src/command/bump_command.rs2
-rw-r--r--crates/shirabe/src/command/check_platform_reqs_command.rs6
-rw-r--r--crates/shirabe/src/command/create_project_command.rs2
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs6
-rw-r--r--crates/shirabe/src/command/show_command.rs12
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs2
-rw-r--r--crates/shirabe/src/dependency_resolver/rule.rs10
-rw-r--r--crates/shirabe/src/installer.rs4
-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
-rw-r--r--crates/shirabe/src/repository/filesystem_repository.rs4
-rw-r--r--crates/shirabe/src/repository/installed_repository.rs11
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs6
18 files changed, 44 insertions, 77 deletions
diff --git a/crates/shirabe/src/command/base_dependency_command.rs b/crates/shirabe/src/command/base_dependency_command.rs
index 5dfb13f..4f929c8 100644
--- a/crates/shirabe/src/command/base_dependency_command.rs
+++ b/crates/shirabe/src/command/base_dependency_command.rs
@@ -357,11 +357,7 @@ pub trait BaseDependencyCommand: BaseCommand {
name_with_link,
version,
link.get_description().to_string(),
- format!(
- "{} ({})",
- link.get_target(),
- link.get_pretty_constraint().unwrap_or("")
- ),
+ format!("{} ({})", link.get_target(), link.get_pretty_constraint()),
]);
if let Some(children_vec) = children {
queue.extend(children_vec);
@@ -438,7 +434,7 @@ pub trait BaseDependencyCommand: BaseCommand {
prev_color,
link.get_target(),
prev_color,
- link.get_pretty_constraint().unwrap_or("")
+ link.get_pretty_constraint(),
);
let circular_warn = if children.is_none() {
"(circular dependency aborted here)"
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs
index f322ec0..d477747 100644
--- a/crates/shirabe/src/command/bump_command.rs
+++ b/crates/shirabe/src/command/bump_command.rs
@@ -236,7 +236,7 @@ impl BumpCommand {
if PlatformRepository::is_platform_package(pkg_name) {
continue;
}
- let current_constraint = link.get_pretty_constraint()?;
+ let current_constraint = link.get_pretty_constraint();
let package_opt = repo.find_package(
pkg_name,
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index 5225f7e..05f7e9b 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -287,9 +287,7 @@ impl CheckPlatformReqsCommand {
);
failed_req.insert(
"constraint".to_string(),
- Box::new(PhpMixed::String(
- link.get_pretty_constraint().unwrap_or("").to_string(),
- )),
+ Box::new(PhpMixed::String(link.get_pretty_constraint().to_string())),
);
row.insert(
"failed_requirement".to_string(),
@@ -327,7 +325,7 @@ impl CheckPlatformReqsCommand {
link.get_source(),
link.get_description(),
link.get_target(),
- link.get_pretty_constraint().unwrap_or(""),
+ link.get_pretty_constraint(),
))
} else {
PhpMixed::String(String::new())
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index 8485069..b13a3d0 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -517,7 +517,7 @@ impl CreateProjectCommand {
let _method = format!("get{}", meta.method);
let links: Vec<crate::package::Link> = vec![];
for link in links {
- if link.get_pretty_constraint().as_deref().ok() == Some("self.version") {
+ if link.get_pretty_constraint() == "self.version" {
config_source.add_link(
r#type,
link.get_target(),
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index 1f2ef5b..72b635f 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -887,7 +887,7 @@ pub trait PackageDiscoveryTrait {
candidate.get_pretty_name(),
candidate.get_pretty_version(),
link.get_target(),
- link.get_pretty_constraint().unwrap_or(""),
+ link.get_pretty_constraint(),
link.get_target(),
));
} else {
@@ -896,7 +896,7 @@ pub trait PackageDiscoveryTrait {
candidate.get_pretty_name(),
candidate.get_pretty_version(),
link.get_target(),
- link.get_pretty_constraint().unwrap_or(""),
+ link.get_pretty_constraint(),
));
}
continue;
@@ -930,7 +930,7 @@ pub trait PackageDiscoveryTrait {
candidate.get_pretty_name(),
candidate.get_pretty_version(),
link.get_target(),
- link.get_pretty_constraint().unwrap_or(""),
+ link.get_pretty_constraint(),
platform_pkg_version,
));
}
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 9592f4e..299ba1e 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -1811,7 +1811,7 @@ impl ShowCommand {
io.write(&format!(
"{} <comment>{}</comment>",
link.1.get_target(),
- link.1.get_pretty_constraint().unwrap_or("")
+ link.1.get_pretty_constraint(),
));
}
}
@@ -2173,7 +2173,7 @@ impl ShowCommand {
for link in links.iter() {
m.insert(
link.1.get_target().to_string(),
- PhpMixed::String(link.1.get_pretty_constraint().unwrap_or("").to_string()),
+ PhpMixed::String(link.1.get_pretty_constraint().to_string()),
);
}
json.insert(
@@ -2309,7 +2309,7 @@ impl ShowCommand {
tree_child_desc.insert("name".to_string(), PhpMixed::String(require_name.clone()));
tree_child_desc.insert(
"version".to_string(),
- PhpMixed::String(require.get_pretty_constraint().unwrap_or("").to_string()),
+ PhpMixed::String(require.get_pretty_constraint().to_string()),
);
let deep_children = self
@@ -2452,11 +2452,11 @@ impl ShowCommand {
packages_in_tree: &[PhpMixed],
) -> anyhow::Result<Vec<IndexMap<String, PhpMixed>>> {
let mut children: Vec<IndexMap<String, PhpMixed>> = Vec::new();
- let version_arg: PhpMixed = if link.get_pretty_constraint().ok() == Some("self.version") {
+ let version_arg: PhpMixed = if link.get_pretty_constraint() == "self.version" {
// pass the ConstraintInterface object — signal via Null in this scalar shape
PhpMixed::Null
} else {
- PhpMixed::String(link.get_pretty_constraint().unwrap_or("").to_string())
+ PhpMixed::String(link.get_pretty_constraint().to_string())
};
let (package, _) = self.get_package(installed_repo, remote_repos, name, version_arg)?;
if let Some(package) = package {
@@ -2469,7 +2469,7 @@ impl ShowCommand {
tree_child_desc.insert("name".to_string(), PhpMixed::String(require_name.clone()));
tree_child_desc.insert(
"version".to_string(),
- PhpMixed::String(require.get_pretty_constraint().unwrap_or("").to_string()),
+ PhpMixed::String(require.get_pretty_constraint().to_string()),
);
if !in_array(
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index 874d56e..47cf3b5 100644
--- a/crates/shirabe/src/dependency_resolver/problem.rs
+++ b/crates/shirabe/src/dependency_resolver/problem.rs
@@ -1153,7 +1153,7 @@ impl Problem {
if link.get_target() == package_name {
return Some(format!(
"{} {}d by {}",
- link.get_pretty_constraint().unwrap_or(""),
+ link.get_pretty_constraint(),
substr(link.get_description(), 0, Some(-1)),
selected.get_pretty_string()
));
diff --git a/crates/shirabe/src/dependency_resolver/rule.rs b/crates/shirabe/src/dependency_resolver/rule.rs
index 3d7bb2d..7804b99 100644
--- a/crates/shirabe/src/dependency_resolver/rule.rs
+++ b/crates/shirabe/src/dependency_resolver/rule.rs
@@ -441,7 +441,7 @@ impl Rule {
conflict_target = format!(
"{} {}",
package1.get_pretty_name(),
- link.get_pretty_constraint().unwrap_or("")
+ link.get_pretty_constraint(),
);
}
@@ -453,16 +453,14 @@ impl Rule {
for provide in package1.get_provides().values() {
if provide.get_target() == link.get_target() {
provide_type = Some("provides");
- provided =
- Some(provide.get_pretty_constraint().unwrap_or("").to_string());
+ provided = Some(provide.get_pretty_constraint().to_string());
break;
}
}
for replace in package1.get_replaces().values() {
if replace.get_target() == link.get_target() {
provide_type = Some("replaces");
- provided =
- Some(replace.get_pretty_constraint().unwrap_or("").to_string());
+ provided = Some(replace.get_pretty_constraint().to_string());
break;
}
}
@@ -470,7 +468,7 @@ impl Rule {
conflict_target = format!(
"{} {} ({} {} {} {})",
link.get_target(),
- link.get_pretty_constraint().unwrap_or(""),
+ link.get_pretty_constraint(),
package1.get_pretty_string(),
pt,
link.get_target(),
diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs
index 3ab88c2..2783364 100644
--- a/crates/shirabe/src/installer.rs
+++ b/crates/shirabe/src/installer.rs
@@ -1582,9 +1582,7 @@ impl Installer {
if PlatformRepository::is_platform_package(link.get_target()) {
platform_reqs.insert(
link.get_target().to_string(),
- link.get_pretty_constraint()
- .map(|s| s.to_string())
- .unwrap_or_default(),
+ link.get_pretty_constraint().to_string(),
);
}
}
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,
diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs
index c373bd9..d9d3289 100644
--- a/crates/shirabe/src/repository/filesystem_repository.rs
+++ b/crates/shirabe/src/repository/filesystem_repository.rs
@@ -559,7 +559,7 @@ impl FilesystemRepository {
todo!("mutate nested versions['versions'][target]['dev_requirement']");
#[allow(unreachable_code)]
{
- let mut replaced = replace.get_pretty_constraint().unwrap_or("").to_string();
+ let mut replaced = replace.get_pretty_constraint().to_string();
if replaced == "self.version" {
replaced = package.get_pretty_version().to_string();
}
@@ -576,7 +576,7 @@ impl FilesystemRepository {
todo!("mutate nested versions['versions'][target]['dev_requirement']");
#[allow(unreachable_code)]
{
- let mut provided = provide.get_pretty_constraint().unwrap_or("").to_string();
+ let mut provided = provide.get_pretty_constraint().to_string();
if provided == "self.version" {
provided = package.get_pretty_version().to_string();
}
diff --git a/crates/shirabe/src/repository/installed_repository.rs b/crates/shirabe/src/repository/installed_repository.rs
index e6f022e..b8321d6 100644
--- a/crates/shirabe/src/repository/installed_repository.rs
+++ b/crates/shirabe/src/repository/installed_repository.rs
@@ -282,11 +282,7 @@ impl InstalledRepository {
link.get_target().to_string(),
MatchAllConstraint::new(None).into(),
Some(Link::TYPE_REQUIRE.to_string()),
- Some(format!(
- "{} {}",
- link.get_pretty_constraint().unwrap_or_default(),
- description
- )),
+ format!("{} {}", link.get_pretty_constraint(), description),
),
None,
));
@@ -351,10 +347,7 @@ impl InstalledRepository {
link.get_target().to_string(),
MatchAllConstraint::new(None).into(),
Some(Link::TYPE_DOES_NOT_REQUIRE.to_string()),
- Some(format!(
- "but {} is installed",
- pkg.get_pretty_version()
- )),
+ format!("but {} is installed", pkg.get_pretty_version()),
),
None,
));
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 957e335..3a59475 100644
--- a/crates/shirabe/src/repository/platform_repository.rs
+++ b/crates/shirabe/src/repository/platform_repository.rs
@@ -1775,7 +1775,7 @@ impl PlatformRepository {
"lib-uuid".to_string(),
SimpleConstraint::new("=".to_string(), version.to_string(), None).into(),
Some(Link::TYPE_REPLACE.to_string()),
- Some(ext.get_pretty_version().to_string()),
+ ext.get_pretty_version().to_string(),
),
);
ext.inner.set_replaces(replaces);
@@ -1840,7 +1840,7 @@ impl PlatformRepository {
format!("lib-{}", replace_lower),
SimpleConstraint::new("=".to_string(), version.to_string(), None).into(),
Some(Link::TYPE_REPLACE.to_string()),
- Some(lib.get_pretty_version().to_string()),
+ lib.get_pretty_version().to_string(),
),
);
}
@@ -1854,7 +1854,7 @@ impl PlatformRepository {
format!("lib-{}", provide_lower),
SimpleConstraint::new("=".to_string(), version.to_string(), None).into(),
Some(Link::TYPE_PROVIDE.to_string()),
- Some(lib.get_pretty_version().to_string()),
+ lib.get_pretty_version().to_string(),
),
);
}