aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-semver/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-02 22:46:44 +0900
committernsfisis <nsfisis@gmail.com>2026-05-02 22:46:44 +0900
commit3c61a7e1e557e3b90128d2ec29227f166b17c05b (patch)
treee68f5a03ac3ca5ba3a1ab29de755b18e0f3228e5 /crates/mozart-semver/src
parent8da98493daf5013585e07ec98ca6960a42924edf (diff)
downloadphp-mozart-3c61a7e1e557e3b90128d2ec29227f166b17c05b.tar.gz
php-mozart-3c61a7e1e557e3b90128d2ec29227f166b17c05b.tar.zst
php-mozart-3c61a7e1e557e3b90128d2ec29227f166b17c05b.zip
feat(resolver): support inline #ref pin and default-branch alias
Adds the missing pieces for installer fixtures that pin a dev package via `dev-foo#hex` or rely on Composer's `default-branch: true` synthetic `9999999-dev` alias. Mirrors Composer at four layers: 1. `mozart_semver::parse_single` strips `dev-...#hex` / `....x-dev#hex` suffixes from constraints (Composer's `parseConstraint` regex). 2. `PackagistVersion` carries `default_branch`. When set on a `dev-` package with no numeric prefix, `packagist_to_pool_inputs` emits the synthetic `9999999-dev` alias — but skips it when an explicit `extra.branch-alias` already covers the version (matches `ArrayLoader::getBranchAlias`). 3. `RuleSetGenerator::generate` picks up `addRulesForRootAliases`: any pool alias whose target was added gets its own alias↔target rules so the SAT solver pulls them in together. 4. `lockfile::generate_lock_file` extracts root `#hex` overrides from `require`/`require-dev` and rewrites source/dist references (and github/gitlab/bitbucket archive URLs) on the matched package, the `setSourceDistReferences` ladder Composer runs in `PoolBuilder`. Resolver also infers `Stability::Dev` from a `dev-foo` style single-atom constraint when no explicit `@flag` is given, mirroring the second loop of `RootPackageLoader::extractStabilityFlags` so the package isn't filtered out under default `stable` minimum-stability. Newly green: install_branch_alias_composer_repo, install_reference, conflict_with_alias_prevents_update_if_not_required, unbounded_conflict_matches_default_branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-semver/src')
-rw-r--r--crates/mozart-semver/src/lib.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/mozart-semver/src/lib.rs b/crates/mozart-semver/src/lib.rs
index dfb0db2..a15db13 100644
--- a/crates/mozart-semver/src/lib.rs
+++ b/crates/mozart-semver/src/lib.rs
@@ -669,12 +669,50 @@ fn split_and(s: &str) -> Vec<String> {
parts
}
+/// Strip `#ref` suffix from `dev-...#hex` / `....x-dev#hex` constraint
+/// strings. Mirrors Composer's
+/// `'{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$}i'` regex strip in
+/// `VersionParser::parseConstraint`. Returns a `Cow` so callers that pass
+/// constraints without `#` see no allocation.
+fn strip_constraint_ref(s: &str) -> std::borrow::Cow<'_, str> {
+ let lower = s.to_lowercase();
+ let Some(hash_pos) = s.find('#') else {
+ return std::borrow::Cow::Borrowed(s);
+ };
+ let head = &lower[..hash_pos];
+ let rest = &s[hash_pos + 1..];
+ if rest.is_empty() {
+ return std::borrow::Cow::Borrowed(s);
+ }
+ // Accept `dev-foo` or `1.2.x-dev` style prefixes only, mirroring the
+ // Composer regex. Anything else (e.g. URLs, comments) is left alone.
+ let head_no_space = !head
+ .chars()
+ .any(|c: char| c.is_whitespace() || c == ',' || c == '@');
+ if !head_no_space {
+ return std::borrow::Cow::Borrowed(s);
+ }
+ let matches = head.starts_with("dev-") || head.ends_with(".x-dev");
+ if matches {
+ std::borrow::Cow::Owned(s[..hash_pos].to_string())
+ } else {
+ std::borrow::Cow::Borrowed(s)
+ }
+}
+
/// Parse a single constraint part.
fn parse_single(s: &str) -> Result<VersionConstraint, String> {
if s == "*" || s.is_empty() {
return Ok(VersionConstraint::Single(Constraint::Any));
}
+ // Strip `#ref` suffixes from `dev-...#hex` / `....x-dev#hex` constraints —
+ // they pin a source reference at the root level (handled by the
+ // installer) and are not part of the version match. Mirrors Composer's
+ // `VersionParser::parseConstraint` `'{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$}i'` strip.
+ let s = strip_constraint_ref(s);
+ let s = s.as_ref();
+
// Caret: ^1.2.3
if let Some(rest) = s.strip_prefix('^') {
return parse_caret(rest);