diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-05 15:12:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-05 15:12:57 +0900 |
| commit | 2ad57b7efb685040b24d93aab5b81ddfbd0ebefb (patch) | |
| tree | 9ee877ed2abc055cc91f2b7120a6122917fa6998 /crates/mozart/src/commands/archive.rs | |
| parent | d4df60e70a4581aba6308f803ec7f9473d2671d8 (diff) | |
| download | php-mozart-2ad57b7efb685040b24d93aab5b81ddfbd0ebefb.tar.gz php-mozart-2ad57b7efb685040b24d93aab5b81ddfbd0ebefb.tar.zst php-mozart-2ad57b7efb685040b24d93aab5b81ddfbd0ebefb.zip | |
feat(core): add Composer struct mirroring requireComposer/tryComposer
Introduce mozart_core::composer::Composer with require()/try_load()
constructors and a config() accessor, modelled on PHP Composer's
BaseCommand::requireComposer / tryComposer. ComposerConfig and
composer_home move into mozart-core so Composer::load can resolve
placeholders consistently.
Migrate dump-autoload, archive, exec and run-script away from ad-hoc
composer.json reads. exec and run-script now fail when composer.json
is missing instead of silently falling back to "vendor/bin",
matching the upstream requireComposer contract.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands/archive.rs')
| -rw-r--r-- | crates/mozart/src/commands/archive.rs | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/crates/mozart/src/commands/archive.rs b/crates/mozart/src/commands/archive.rs index faa0e94..ca57259 100644 --- a/crates/mozart/src/commands/archive.rs +++ b/crates/mozart/src/commands/archive.rs @@ -104,24 +104,26 @@ pub async fn execute( None => std::env::current_dir()?, }; - // 2. Load config for format/dir defaults from composer.json's "config" section + // 2. Load Composer state for format/dir defaults. Composer's + // `archive` command falls back to `Factory::createConfig()` when no + // composer.json is present, so we mirror that by treating a missing + // file as "use defaults" (Composer::try_load returns None). + let composer = mozart_core::composer::Composer::try_load(&working_dir)?; let composer_json_path = working_dir.join("composer.json"); - let (config_archive_format, config_archive_dir) = if composer_json_path.exists() { - let content = std::fs::read_to_string(&composer_json_path)?; - let value: serde_json::Value = serde_json::from_str(&content)?; - let fmt = value - .get("config") - .and_then(|c| c.get("archive-format")) - .and_then(|v| v.as_str()) - .map(|s| s.to_string()); - let dir = value - .get("config") - .and_then(|c| c.get("archive-dir")) - .and_then(|v| v.as_str()) - .map(|s| s.to_string()); - (fmt, dir) - } else { - (None, None) + let (config_archive_format, config_archive_dir) = match composer.as_ref() { + Some(c) => { + let cfg = c.config(); + let fmt = cfg + .get("archive-format") + .and_then(|v| v.as_str()) + .map(|s| s.to_string()); + let dir = cfg + .get("archive-dir") + .and_then(|v| v.as_str()) + .map(|s| s.to_string()); + (fmt, dir) + } + None => (None, None), }; // 3. Determine format: args -> config -> default "tar" |
