diff options
Diffstat (limited to 'crates/mozart/src/commands')
| -rw-r--r-- | crates/mozart/src/commands/browse.rs | 3 | ||||
| -rw-r--r-- | crates/mozart/src/commands/bump.rs | 16 | ||||
| -rw-r--r-- | crates/mozart/src/commands/diagnose.rs | 7 | ||||
| -rw-r--r-- | crates/mozart/src/commands/exec.rs | 3 | ||||
| -rw-r--r-- | crates/mozart/src/commands/install.rs | 45 | ||||
| -rw-r--r-- | crates/mozart/src/commands/licenses.rs | 28 | ||||
| -rw-r--r-- | crates/mozart/src/commands/validate.rs | 4 |
7 files changed, 57 insertions, 49 deletions
diff --git a/crates/mozart/src/commands/browse.rs b/crates/mozart/src/commands/browse.rs index f646577..d7c9ce2 100644 --- a/crates/mozart/src/commands/browse.rs +++ b/crates/mozart/src/commands/browse.rs @@ -4,6 +4,7 @@ use mozart_core::console::Console; use mozart_core::console_writeln; use mozart_core::console_writeln_error; use mozart_core::exit_code; +use mozart_core::package::Package; use mozart_core::repository::browse_repos::{BrowseRepos, CompletePackageView}; use mozart_core::repository::cache::{Cache, build_cache_config}; use mozart_core::repository::installed::InstalledPackages; @@ -42,7 +43,7 @@ pub async fn execute(args: &BrowseArgs, cli: &super::Cli, console: &Console) -> working_dir.display() ) })?; - vec![composer.package().name.clone()] + vec![composer.package().name().to_string()] } else { args.packages.clone() }; diff --git a/crates/mozart/src/commands/bump.rs b/crates/mozart/src/commands/bump.rs index ee611d1..f7c8142 100644 --- a/crates/mozart/src/commands/bump.rs +++ b/crates/mozart/src/commands/bump.rs @@ -3,6 +3,7 @@ use clap::Args; use indexmap::IndexMap; use mozart_core::composer::LocalRepository; use mozart_core::console::Console; +use mozart_core::package::{Link, Package}; use mozart_core::{console_writeln, console_writeln_error}; use std::collections::BTreeMap; use std::path::Path; @@ -128,13 +129,13 @@ pub async fn do_bump( build_locked_versions_from_local(composer.repository_manager().local_repository()) }; - let package_type = composer.package().package_type.as_deref(); - if package_type != Some("project") && !dev_only { + let package_type = composer.package().package_type(); + if package_type != "project" && !dev_only { console_writeln_error!( io, "<warning>Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.</warning>", ); - if package_type.is_none() { + if package_type == "library" { console_writeln_error!( io, "<warning>If your package is not a library, you can explicitly specify the \"type\" by using \"composer config type project\".</warning>", @@ -146,12 +147,12 @@ pub async fn do_bump( } } - let mut tasks: Vec<(&'static str, &BTreeMap<String, String>)> = Vec::new(); + let mut tasks: Vec<(&'static str, &BTreeMap<String, Link>)> = Vec::new(); if !dev_only { - tasks.push(("require", &composer.package().require)); + tasks.push(("require", composer.package().requires())); } if !no_dev_only { - tasks.push(("require-dev", &composer.package().require_dev)); + tasks.push(("require-dev", composer.package().dev_requires())); } let stripped_filter: Option<Vec<String>> = if packages_filter.is_empty() { @@ -169,7 +170,8 @@ pub async fn do_bump( let mut updates: BTreeMap<&'static str, BTreeMap<String, String>> = BTreeMap::new(); for (key, reqs) in &tasks { - for (pkg_name, constraint) in reqs.iter() { + for (pkg_name, link) in reqs.iter() { + let constraint = &link.constraint; if mozart_core::platform::is_platform_package(pkg_name) { continue; } diff --git a/crates/mozart/src/commands/diagnose.rs b/crates/mozart/src/commands/diagnose.rs index 17a8b78..2e171e5 100644 --- a/crates/mozart/src/commands/diagnose.rs +++ b/crates/mozart/src/commands/diagnose.rs @@ -8,6 +8,7 @@ use mozart_core::console::Console; use mozart_core::console_writeln; use mozart_core::factory::create_config; use mozart_core::http::HttpDownloader; +use mozart_core::package::CompletePackage; use std::borrow::Cow; use std::path::Path; @@ -430,11 +431,11 @@ pub async fn execute( // Step 13: every additional `composer`-type repo. if let Some(composer) = &composer { - for repo in composer.package().repositories.iter() { - if repo.repo_type != "composer" { + for repo in composer.package().repositories().iter() { + if repo.get("type").and_then(|v| v.as_str()) != Some("composer") { continue; } - let Some(url) = repo.url.as_deref() else { + let Some(url) = repo.get("url").and_then(|v| v.as_str()) else { continue; }; if !url.starts_with("http") { diff --git a/crates/mozart/src/commands/exec.rs b/crates/mozart/src/commands/exec.rs index 2b3c836..63c29c9 100644 --- a/crates/mozart/src/commands/exec.rs +++ b/crates/mozart/src/commands/exec.rs @@ -1,6 +1,7 @@ use crate::composer::Composer; use clap::Args; use mozart_core::console_writeln; +use mozart_core::package::Package; use std::path::{Path, PathBuf}; #[derive(Args)] @@ -125,7 +126,7 @@ fn get_binaries(composer: &Composer, bin_dir: &Path) -> Vec<(String, bool)> { let local_bins: Vec<(String, bool)> = composer .package() - .bin + .binaries() .iter() .filter_map(|e| Some(PathBuf::from(e).file_name()?.to_string_lossy().into_owned())) .map(|e| (e, true)) diff --git a/crates/mozart/src/commands/install.rs b/crates/mozart/src/commands/install.rs index 59d400b..4a997dd 100644 --- a/crates/mozart/src/commands/install.rs +++ b/crates/mozart/src/commands/install.rs @@ -2,6 +2,7 @@ use clap::Args; use indexmap::IndexSet; use mozart_core::console; use mozart_core::console_format; +use mozart_core::package::{Package, RootPackage, RootPackageData}; use mozart_core::repository::installed; use mozart_core::repository::installer_executor::{ Action, ExecuteContext, FilesystemExecutor, InstallerExecutor, PackageOperation, @@ -151,7 +152,7 @@ impl Default for InstallConfig { /// strings combined so a future "swap for SAT-verify" change is a single /// function replacement. fn verify_lock( - root: &mozart_core::package::RawPackageData, + root: &RootPackageData, lock: &lockfile::LockFile, dev_mode: bool, ignore_platform_reqs: bool, @@ -181,7 +182,7 @@ fn verify_lock( /// Returns the list of "Root composer.json requires …" diagnostic lines (one /// per failing requirement). An empty vec means everything is satisfied. fn verify_lock_platform_problems( - root: &mozart_core::package::RawPackageData, + root: &RootPackageData, lock: &lockfile::LockFile, dev_mode: bool, ignore_platform_reqs: bool, @@ -260,18 +261,16 @@ fn verify_lock_same_name_problems(lock: &lockfile::LockFile, dev_mode: bool) -> /// must bail with exit-code 2 before any package operations run. fn verify_lock_root_require_problems( lock: &lockfile::LockFile, - root: &mozart_core::package::RawPackageData, + root: &RootPackageData, dev_mode: bool, ) -> Vec<String> { use mozart_semver::{Version, VersionConstraint}; - let Some(root_version) = root.version.as_deref() else { - return Vec::new(); - }; - if root.name.is_empty() || root_version.is_empty() { + let root_version = root.pretty_version(); + if root_version == "1.0.0+no-version-set" || root.name().is_empty() || root_version.is_empty() { return Vec::new(); } - let root_name_lower = root.name.to_lowercase(); + let root_name_lower = root.name().to_string(); let Ok(parsed_root_version) = Version::parse(root_version) else { return Vec::new(); }; @@ -395,7 +394,7 @@ fn verify_lock_conflict_problems(lock: &lockfile::LockFile, dev_mode: bool) -> V /// composer.json overrides the lock on duplicate keys (matching Composer's /// "composer.json as source of truth" rule for shared platform reqs). fn combine_platform_requirements( - root: &mozart_core::package::RawPackageData, + root: &RootPackageData, lock: &lockfile::LockFile, dev_mode: bool, ) -> BTreeMap<String, String> { @@ -416,17 +415,17 @@ fn combine_platform_requirements( } } - for (name, constraint) in &root.require { + for (name, link) in root.requires() { let lower = name.to_lowercase(); if mozart_core::platform::is_platform_package(&lower) { - combined.insert(lower, constraint.clone()); + combined.insert(lower, link.constraint.clone()); } } if dev_mode { - for (name, constraint) in &root.require_dev { + for (name, link) in root.dev_requires() { let lower = name.to_lowercase(); if mozart_core::platform::is_platform_package(&lower) { - combined.insert(lower, constraint.clone()); + combined.insert(lower, link.constraint.clone()); } } } @@ -991,8 +990,9 @@ pub async fn run( )); } - let root_pkg = mozart_core::package::read_from_file(&composer_json_path)?; - root_pkg.validate_root_does_not_self_require()?; + let raw_pkg = mozart_core::package::read_from_file(&composer_json_path)?; + raw_pkg.validate_root_does_not_self_require()?; + let root_pkg = RootPackageData::from_raw(raw_pkg); let missing = lock.get_missing_requirement_info(&root_pkg, dev_mode); if !missing.is_empty() { for line in &missing { @@ -1003,9 +1003,8 @@ pub async fn run( // but proceed with what the lock already covers instead of // bailing with ERROR_LOCK_FILE_INVALID. let allow_missing = root_pkg - .extra_fields - .get("config") - .and_then(|v| v.get("allow-missing-requirements")) + .config() + .get("allow-missing-requirements") .and_then(|v| v.as_bool()) .unwrap_or(false); if !allow_missing { @@ -1432,15 +1431,15 @@ mod tests { fn root_with_require( require: &[(&str, &str)], require_dev: &[(&str, &str)], - ) -> mozart_core::package::RawPackageData { - let mut root = mozart_core::package::RawPackageData::new("__root__".to_string()); + ) -> RootPackageData { + let mut raw = mozart_core::package::RawPackageData::new("__root__".to_string()); for (k, v) in require { - root.require.insert((*k).to_string(), (*v).to_string()); + raw.require.insert((*k).to_string(), (*v).to_string()); } for (k, v) in require_dev { - root.require_dev.insert((*k).to_string(), (*v).to_string()); + raw.require_dev.insert((*k).to_string(), (*v).to_string()); } - root + RootPackageData::from_raw(raw) } fn lock_with_platform( diff --git a/crates/mozart/src/commands/licenses.rs b/crates/mozart/src/commands/licenses.rs index 344a5fa..7a3847f 100644 --- a/crates/mozart/src/commands/licenses.rs +++ b/crates/mozart/src/commands/licenses.rs @@ -4,6 +4,7 @@ use indexmap::IndexMap; use mozart_core::console::Console; use mozart_core::console::hyperlink; use mozart_core::console_writeln; +use mozart_core::package::Package; use mozart_core::package_info; use mozart_core::package_info::PackageUrls; use mozart_core::package_sorter::sort_packages_alphabetically; @@ -84,21 +85,24 @@ pub async fn execute( let root = composer.package(); - // RawPackageData stores `license` as `Option<String>` only, so we - // re-parse the composer.json to also accept the array form Composer - // recognises via `RootPackageLoader`'s `(array) $config['license']` - // coercion. Track widening `RawPackageData::license` separately. + // Re-parse composer.json to handle the array form of `license` — + // `RawPackageData` only deserializes the string form, so both string + // and array values must be read from the raw JSON here. let root_licenses = read_root_licenses(&working_dir.join("composer.json"))?; - let root_pretty_name = root.name.clone(); - let root_version = root - .version - .clone() - .unwrap_or_else(|| "No version set".to_string()); + let root_pretty_name = root.name().to_string(); + let root_version = { + let v = root.pretty_version(); + if v == "1.0.0+no-version-set" { + "No version set".to_string() + } else { + v.to_string() + } + }; let mut entries = if args.locked { load_locked_entries(&working_dir, args.no_dev)? } else { - load_installed_entries(&working_dir, &root.require, args.no_dev)? + load_installed_entries(&working_dir, root.requires(), args.no_dev)? }; sort_packages_alphabetically(&mut entries, |e| e.name.as_str()); @@ -138,9 +142,9 @@ fn read_root_licenses(composer_json_path: &std::path::Path) -> anyhow::Result<Ve }) } -fn load_installed_entries( +fn load_installed_entries<V>( working_dir: &std::path::Path, - root_requires: &BTreeMap<String, String>, + root_requires: &BTreeMap<String, V>, no_dev: bool, ) -> anyhow::Result<Vec<LicenseEntry>> { let vendor_dir = working_dir.join("vendor"); diff --git a/crates/mozart/src/commands/validate.rs b/crates/mozart/src/commands/validate.rs index 853eb2b..7595ee5 100644 --- a/crates/mozart/src/commands/validate.rs +++ b/crates/mozart/src/commands/validate.rs @@ -3,7 +3,7 @@ use clap::Args; use mozart_core::config_validator::{ValidationResult, ValidatorOptions, validate_manifest}; use mozart_core::console_format; use mozart_core::console_writeln; -use mozart_core::package::RawPackageData; +use mozart_core::package::RootPackageData; use std::path::{Path, PathBuf}; #[derive(Args)] @@ -324,7 +324,7 @@ fn validate_dependencies_vendor_walk( fn check_lock_freshness( composer_json_content: &str, composer_json_path: &Path, - root_package: Option<&RawPackageData>, + root_package: Option<&RootPackageData>, lock_errors: &mut Vec<String>, ) { let lock_path = composer_json_path |
