aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/commands/config_helpers.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-08 23:03:11 +0900
committernsfisis <nsfisis@gmail.com>2026-05-08 23:03:11 +0900
commiteeb845f2f8629e3ccfb8ee1a1ec0602c0f186427 (patch)
tree5076422cf70ac92e1bc1e0424f0373100be5fd4c /crates/mozart/src/commands/config_helpers.rs
parent392cf71170bf2550aa657158e9efd2b890381a94 (diff)
downloadphp-mozart-eeb845f2f8629e3ccfb8ee1a1ec0602c0f186427.tar.gz
php-mozart-eeb845f2f8629e3ccfb8ee1a1ec0602c0f186427.tar.zst
php-mozart-eeb845f2f8629e3ccfb8ee1a1ec0602c0f186427.zip
fix(repository): align with Composer's RepositoryCommand pipeline
Introduce JsonConfigSource in mozart-core mirroring Composer's JsonConfigSource fallback logic (add/insert/set-url/remove repository), and BaseConfigContext mirroring BaseConfigCommand's initialize(). Key behaviour fixes: - list: synthesise [packagist.org] <disabled> only when no composer-type repo with a packagist.org host is present (was: always show enabled default) - disable: idempotent via add_repository(false) matching Composer's branch; now requires a name (no silent default to packagist.org) - enable: calls remove_repository only, no extra empty-array cleanup - set-url: preserves assoc-keyed format instead of converting to list - get-url: assoc fast-path + unquoted error message matching Composer - add: use regex pre-check (starts_with '{') instead of trial-parse - error messages reworded to match Composer verbatim (mozart brand kept) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands/config_helpers.rs')
-rw-r--r--crates/mozart/src/commands/config_helpers.rs55
1 files changed, 0 insertions, 55 deletions
diff --git a/crates/mozart/src/commands/config_helpers.rs b/crates/mozart/src/commands/config_helpers.rs
index c5cd187..f0aacbb 100644
--- a/crates/mozart/src/commands/config_helpers.rs
+++ b/crates/mozart/src/commands/config_helpers.rs
@@ -112,28 +112,6 @@ pub(crate) fn normalize_repositories(value: &serde_json::Value) -> Vec<serde_jso
}
}
-/// Convert a Composer-style associative `repositories` object to Mozart's
-/// array-of-objects format in-place. If `repositories` is already an array
-/// (or absent), this is a no-op.
-pub(crate) fn ensure_repositories_array(json: &mut serde_json::Value) {
- if json["repositories"].is_object() {
- let normalized = normalize_repositories(&json["repositories"].clone());
- json["repositories"] = serde_json::Value::Array(normalized);
- }
-}
-
-/// Find the index of a repository entry by name in a slice of normalized
-/// repository values. Matches against the `"name"` field.
-pub(crate) fn find_repo_by_name(repos: &[serde_json::Value], name: &str) -> Option<usize> {
- repos.iter().position(|entry| {
- entry
- .get("name")
- .and_then(|n| n.as_str())
- .map(|n| n == name)
- .unwrap_or(false)
- })
-}
-
/// Add a repository entry to the `repositories` array in json.
/// If `append` is true, push to end; otherwise insert at beginning.
/// Removes any existing entry with the same name first.
@@ -174,39 +152,6 @@ pub(crate) fn remove_repository(json: &mut serde_json::Value, name: &str) {
}
}
-/// Insert a repository entry before or after a named repository.
-/// Returns an error if the target repository is not found.
-pub(crate) fn insert_repository(
- json: &mut serde_json::Value,
- name: &str,
- config: serde_json::Value,
- target: &str,
- before: bool,
-) -> anyhow::Result<()> {
- if !json["repositories"].is_array() {
- json["repositories"] = serde_json::json!([]);
- }
-
- remove_repository(json, name);
-
- let repos = json["repositories"].as_array_mut().unwrap();
-
- let pos = repos
- .iter()
- .position(|entry| {
- entry.get("name").and_then(|n| n.as_str()) == Some(target)
- || entry
- .as_object()
- .map(|obj| obj.contains_key(target))
- .unwrap_or(false)
- })
- .ok_or_else(|| anyhow!("Repository \"{target}\" not found"))?;
-
- let insert_pos = if before { pos } else { pos + 1 };
- repos.insert(insert_pos, config);
- Ok(())
-}
-
/// Render a `serde_json::Value` as a human-readable string suitable for
/// single-line display (matching Composer's behaviour).
pub(crate) fn render_value(v: &serde_json::Value) -> String {