diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-23 01:11:23 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-23 01:11:23 +0900 |
| commit | 40bd784824dc5f40e22908ff35d4ae693696ba89 (patch) | |
| tree | c4175c1a46dae44b21ebd7314c8965f010175097 /crates/mozart/src | |
| parent | 28c8c8dfb0dff4dc87d585e06faaf96a4c2eefde (diff) | |
| download | php-mozart-40bd784824dc5f40e22908ff35d4ae693696ba89.tar.gz php-mozart-40bd784824dc5f40e22908ff35d4ae693696ba89.tar.zst php-mozart-40bd784824dc5f40e22908ff35d4ae693696ba89.zip | |
fix(depends): prefer installed packages over lockfile and add platform support
Without --locked, prefer vendor/composer/installed.json over composer.lock
to match Composer's data source priority. Add platform packages (php, ext-*,
lib-*) from detect_platform() so queries like `depends php` work. Show a
specific error message when a platform package is not found.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src')
| -rw-r--r-- | crates/mozart/src/commands/dependency.rs | 27 | ||||
| -rw-r--r-- | crates/mozart/src/commands/depends.rs | 6 |
2 files changed, 31 insertions, 2 deletions
diff --git a/crates/mozart/src/commands/dependency.rs b/crates/mozart/src/commands/dependency.rs index 5073be0..f2856d9 100644 --- a/crates/mozart/src/commands/dependency.rs +++ b/crates/mozart/src/commands/dependency.rs @@ -59,12 +59,35 @@ pub fn load_packages(working_dir: &Path, locked: bool) -> Result<Vec<PackageInfo let composer_json_path = working_dir.join("composer.json"); // Load locked / installed packages - let mut packages: Vec<PackageInfo> = if locked || lock_path.exists() { + let mut packages: Vec<PackageInfo> = if locked { load_from_lockfile(&lock_path)? } else { - load_from_installed(working_dir)? + let installed = load_from_installed(working_dir); + match installed { + Ok(pkgs) if !pkgs.is_empty() => pkgs, + _ => { + if lock_path.exists() { + load_from_lockfile(&lock_path)? + } else { + vec![] + } + } + } }; + // Add platform packages (php, ext-*, lib-*, composer-*-api) + let platform = mozart_core::platform::detect_platform(); + for pp in &platform { + packages.push(PackageInfo { + name: pp.name.clone(), + version: pp.version.clone(), + require: BTreeMap::new(), + require_dev: BTreeMap::new(), + conflict: BTreeMap::new(), + is_root: false, + }); + } + // Add the root package (composer.json) as a synthetic entry if composer_json_path.exists() && let Ok(root) = mozart_core::package::read_from_file(&composer_json_path) diff --git a/crates/mozart/src/commands/depends.rs b/crates/mozart/src/commands/depends.rs index 673fd35..c65f775 100644 --- a/crates/mozart/src/commands/depends.rs +++ b/crates/mozart/src/commands/depends.rs @@ -44,6 +44,12 @@ pub async fn execute( // Verify the target package is known let target_known = packages.iter().any(|p| p.name.to_lowercase() == target); + if !target_known && mozart_core::platform::is_platform_package(&target) { + anyhow::bail!( + "Could not find platform package \"{}\". Is PHP available?", + args.package + ); + } if !target_known { anyhow::bail!( "Could not find package \"{}\" in your project", |
