From 5254a9e9b698c3618229f4f802b39a82baf9169a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 5 May 2026 20:34:27 +0900 Subject: feat(core): port Factory::createConfig() as factory::create_config() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds crates/mozart-core/src/factory.rs with get_cache_dir(), get_data_dir(), and create_config() — a Rust port of Composer\Factory::createConfig() (auth loading and htaccess creation are out of scope for now). Also fixes a correctness bug on Linux: the previous Config::default() resolved cache-dir to $XDG_CONFIG_HOME/composer/cache via the {$home}/cache placeholder, whereas Composer uses the XDG cache base ($XDG_CACHE_HOME or ~/.cache), giving ~/.cache/composer. Callers updated: - Composer::load() uses create_config() as the global baseline before merging project-level config. - config command execute_read() builds the global baseline with create_config() and overlays local config on top when not --global, matching Composer's actual layering order. Co-Authored-By: Claude Sonnet 4.6 --- crates/mozart/src/commands/config.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/mozart/src/commands') diff --git a/crates/mozart/src/commands/config.rs b/crates/mozart/src/commands/config.rs index 40336f3..274dcde 100644 --- a/crates/mozart/src/commands/config.rs +++ b/crates/mozart/src/commands/config.rs @@ -60,7 +60,8 @@ pub struct ConfigArgs { pub source: bool, } -use mozart_core::config::{Config, resolve_references}; +use mozart_core::config::resolve_references; +use mozart_core::factory::create_config; /// Classification of config key value types for validation and normalization. #[derive(Debug)] @@ -754,13 +755,11 @@ fn execute_read( console: &mozart_core::console::Console, ) -> anyhow::Result<()> { // Build the effective config for config-section keys. - let mut config = Config::default(); + // Global baseline (defaults + platform dirs + $COMPOSER_HOME/config.json), + // then overlay project config on top when not in --global mode. + let mut config = create_config()?; - if args.global { - let global_config_path = composer_home().join("config.json"); - let overrides = load_config_section(&global_config_path)?; - config.merge(&overrides)?; - } else { + if !args.global { let wd = cli.working_dir()?; let composer_json = wd.join("composer.json"); let overrides = load_config_section(&composer_json)?; @@ -857,6 +856,7 @@ fn execute_read( #[cfg(test)] mod tests { use super::*; + use mozart_core::config::Config; #[test] fn test_defaults_contain_expected_keys() { -- cgit v1.3.1