diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/mozart-core/src/composer.rs | 2 | ||||
| -rw-r--r-- | crates/mozart-core/src/factory.rs | 10 | ||||
| -rw-r--r-- | crates/mozart-registry/src/cache.rs | 4 | ||||
| -rw-r--r-- | crates/mozart/src/commands.rs | 22 | ||||
| -rw-r--r-- | crates/mozart/src/commands/bump.rs | 2 | ||||
| -rw-r--r-- | crates/mozart/src/commands/clear_cache.rs | 2 | ||||
| -rw-r--r-- | crates/mozart/src/commands/dump_autoload.rs | 83 | ||||
| -rw-r--r-- | crates/mozart/src/commands/reinstall.rs | 31 | ||||
| -rw-r--r-- | crates/mozart/src/commands/status.rs | 2 | ||||
| -rw-r--r-- | crates/mozart/src/commands/validate.rs | 2 |
10 files changed, 74 insertions, 86 deletions
diff --git a/crates/mozart-core/src/composer.rs b/crates/mozart-core/src/composer.rs index c76f428..64c3c97 100644 --- a/crates/mozart-core/src/composer.rs +++ b/crates/mozart-core/src/composer.rs @@ -246,7 +246,7 @@ impl LocalRepository { /// "at most one package of each name, with aliases unfolded". Mozart /// does not yet model alias packages, so this is currently a straight /// pass-through over the loaded packages. - pub fn canonical_packages(&self) -> impl Iterator<Item = &LocalPackage> { + pub fn get_canonical_packages(&self) -> impl Iterator<Item = &LocalPackage> { self.packages.iter() } diff --git a/crates/mozart-core/src/factory.rs b/crates/mozart-core/src/factory.rs index 6602056..a7a690c 100644 --- a/crates/mozart-core/src/factory.rs +++ b/crates/mozart-core/src/factory.rs @@ -429,7 +429,7 @@ mod tests { let pkg = composer .repository_manager() .local_repository() - .canonical_packages() + .get_canonical_packages() .next() .unwrap(); @@ -457,7 +457,7 @@ mod tests { let pkg = composer .repository_manager() .local_repository() - .canonical_packages() + .get_canonical_packages() .next() .unwrap(); @@ -478,7 +478,7 @@ mod tests { let count = composer .repository_manager() .local_repository() - .canonical_packages() + .get_canonical_packages() .count(); assert_eq!(count, 0); } @@ -499,7 +499,7 @@ mod tests { let names: Vec<&str> = composer .repository_manager() .local_repository() - .canonical_packages() + .get_canonical_packages() .map(|p| p.pretty_name()) .collect(); assert_eq!(names, vec!["a/a", "b/b"]); @@ -541,7 +541,7 @@ mod tests { let pkg = composer .repository_manager() .local_repository() - .canonical_packages() + .get_canonical_packages() .next() .unwrap(); diff --git a/crates/mozart-registry/src/cache.rs b/crates/mozart-registry/src/cache.rs index 3ba3258..39e3e8d 100644 --- a/crates/mozart-registry/src/cache.rs +++ b/crates/mozart-registry/src/cache.rs @@ -298,7 +298,7 @@ impl Cache { /// Each top-level subdirectory is one bare mirror keyed by sanitized URL. /// Deletes entire subdirectories whose mtime is older than `ttl_seconds`. /// Mirrors Composer's `Cache::gcVcsCache`. - pub fn gc_vcs(&self, ttl_seconds: u64) -> anyhow::Result<()> { + pub fn gc_vcs_cache(&self, ttl_seconds: u64) -> anyhow::Result<()> { if !self.enabled || !self.root.exists() { return Ok(()); } @@ -541,7 +541,7 @@ mod tests { ) .unwrap(); - cache.gc_vcs(3600).unwrap(); + cache.gc_vcs_cache(3600).unwrap(); assert!(!old_mirror.exists(), "expired mirror should be removed"); assert!(new_mirror.exists(), "fresh mirror should remain"); diff --git a/crates/mozart/src/commands.rs b/crates/mozart/src/commands.rs index 1717437..f9b8880 100644 --- a/crates/mozart/src/commands.rs +++ b/crates/mozart/src/commands.rs @@ -312,3 +312,25 @@ pub async fn execute(cli: &Cli) -> anyhow::Result<()> { Commands::Validate(args) => validate::execute(args, cli, &console).await, } } + +/// Creates PlatformRequirementFilter from CLI options. Priority: +/// +/// 1. `--ignore-platform-reqs` → ignore every platform requirement +/// 2. `--ignore-platform-req <name>...` (non-empty) → ignore the listed names +/// 3. neither → ignore nothing +/// +/// ref: \Composer\Command\BaseCommand::getPlatformRequirementFilter() +pub(crate) fn get_platform_requirement_filter( + ignore_platform_reqs: bool, + ignore_platform_req: &[String], +) -> anyhow::Result<mozart_core::composer::PlatformRequirementFilter> { + use mozart_core::composer::PlatformRequirementFilter; + + if ignore_platform_reqs { + return Ok(PlatformRequirementFilter::ignore_all()); + } + if !ignore_platform_req.is_empty() { + return PlatformRequirementFilter::from_list(ignore_platform_req); + } + Ok(PlatformRequirementFilter::ignore_nothing()) +} diff --git a/crates/mozart/src/commands/bump.rs b/crates/mozart/src/commands/bump.rs index 6c53784..1ed4c54 100644 --- a/crates/mozart/src/commands/bump.rs +++ b/crates/mozart/src/commands/bump.rs @@ -327,7 +327,7 @@ fn build_locked_versions_from_local( repo: &LocalRepository, ) -> IndexMap<String, (String, Option<String>)> { let mut map: IndexMap<String, (String, Option<String>)> = IndexMap::new(); - for pkg in repo.canonical_packages() { + for pkg in repo.get_canonical_packages() { map.insert( pkg.pretty_name().to_lowercase(), (pkg.pretty_version().to_string(), None), diff --git a/crates/mozart/src/commands/clear_cache.rs b/crates/mozart/src/commands/clear_cache.rs index ee8aad9..8fdf665 100644 --- a/crates/mozart/src/commands/clear_cache.rs +++ b/crates/mozart/src/commands/clear_cache.rs @@ -68,7 +68,7 @@ pub async fn execute( match key { "cache-files-dir" => cache.gc(config.cache_files_ttl, config.cache_files_maxsize)?, "cache-repo-dir" => cache.gc(config.cache_files_ttl, 1024 * 1024 * 1024 /* 1GB, this should almost never clear anything that is not outdated */)?, - "cache-vcs-dir" => cache.gc_vcs(config.cache_files_ttl)?, + "cache-vcs-dir" => cache.gc_vcs_cache(config.cache_files_ttl)?, _ => unreachable!(), }; } else { diff --git a/crates/mozart/src/commands/dump_autoload.rs b/crates/mozart/src/commands/dump_autoload.rs index f2db011..0f3366c 100644 --- a/crates/mozart/src/commands/dump_autoload.rs +++ b/crates/mozart/src/commands/dump_autoload.rs @@ -1,6 +1,6 @@ use clap::Args; use mozart_autoload::AutoloadGeneratorExt; -use mozart_core::composer::{AutoloadDumpOptions, Composer, PlatformRequirementFilter}; +use mozart_core::composer::{AutoloadDumpOptions, Composer}; use mozart_core::console_writeln; #[derive(Args, Default)] @@ -55,14 +55,16 @@ pub async fn execute( cli: &super::Cli, console: &mozart_core::console::Console, ) -> anyhow::Result<()> { - let working_dir = cli.working_dir()?; - let composer = Composer::require(&working_dir)?; + let composer = Composer::require(cli.working_dir()?)?; + + let installation_manager = composer.installation_manager(); + let local_repo = composer.repository_manager().local_repository(); + let package = composer.package(); + let config = composer.config(); let missing_dependencies = { - let installation_manager = composer.installation_manager(); - let local_repo = composer.repository_manager().local_repository(); let mut missing = false; - for local_pkg in local_repo.canonical_packages() { + for local_pkg in local_repo.get_canonical_packages() { if let Some(install_path) = installation_manager.get_install_path(local_pkg) && !install_path.exists() { @@ -77,13 +79,12 @@ pub async fn execute( missing }; - let optimize = args.optimize || composer.config().optimize_autoloader; - let class_map_authoritative = - args.classmap_authoritative || composer.config().classmap_authoritative; + let optimize = args.optimize || config.optimize_autoloader; + let authoritative = args.classmap_authoritative || config.classmap_authoritative; let apcu_prefix = args.apcu_prefix.clone(); - let apcu = apcu_prefix.is_some() || args.apcu || composer.config().apcu_autoloader; + let apcu = apcu_prefix.is_some() || args.apcu || config.apcu_autoloader; - let do_optimize = optimize || class_map_authoritative; + let do_optimize = optimize || authoritative; if args.strict_psr && !do_optimize { anyhow::bail!( "--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative." @@ -95,17 +96,16 @@ pub async fn execute( ); } - console_writeln!( - console, - "<info>{}</info>", - if class_map_authoritative { - "Generating optimized autoload files (authoritative)" - } else if optimize { - "Generating optimized autoload files" - } else { - "Generating autoload files" - } - ); + if authoritative { + console_writeln!( + console, + "<info>Generating optimized autoload files (authoritative)</info>", + ); + } else if optimize { + console_writeln!(console, "<info>Generating optimized autoload files</info>"); + } else { + console_writeln!(console, "<info>Generating autoload files</info>"); + } let dev_mode = if args.dev { Some(true) @@ -119,20 +119,23 @@ pub async fn execute( } let options = AutoloadDumpOptions { dev_mode, - class_map_authoritative, + class_map_authoritative: authoritative, apcu, apcu_prefix, run_scripts: true, dry_run: args.dry_run, - platform_requirement_filter: get_platform_requirement_filter(args)?, + platform_requirement_filter: super::get_platform_requirement_filter( + args.ignore_platform_reqs, + &args.ignore_platform_req, + )?, }; let class_map = composer.autoload_generator().dump( &options, - composer.config(), - composer.repository_manager().local_repository(), - composer.package(), - composer.installation_manager(), + config, + local_repo, + package, + installation_manager, "composer", optimize, None, @@ -141,7 +144,7 @@ pub async fn execute( )?; let number_of_classes = class_map.count(); - if class_map_authoritative { + if authoritative { console_writeln!( console, "<info>Generated optimized autoload files (authoritative) containing {number_of_classes} classes</info>", @@ -156,9 +159,7 @@ pub async fn execute( } if missing_dependencies || args.strict_psr && class_map.has_psr_violations() { - return Err(mozart_core::exit_code::bail_silent( - mozart_core::exit_code::GENERAL_ERROR, - )); + return Err(mozart_core::exit_code::bail_silent(1)); } if args.strict_ambiguous && class_map.has_ambiguous_classes(false) { @@ -167,21 +168,3 @@ pub async fn execute( Ok(()) } - -/// Mirror of `BaseCommand::getPlatformRequirementFilter` for the -/// `dump-autoload` command. Priority: -/// 1. `--ignore-platform-reqs` → ignore every platform requirement -/// 2. `--ignore-platform-req <name>...` (non-empty) → ignore the listed -/// names (with `*` glob support) -/// 3. neither → ignore nothing -fn get_platform_requirement_filter( - args: &DumpAutoloadArgs, -) -> anyhow::Result<PlatformRequirementFilter> { - if args.ignore_platform_reqs { - return Ok(PlatformRequirementFilter::ignore_all()); - } - if !args.ignore_platform_req.is_empty() { - return PlatformRequirementFilter::from_list(&args.ignore_platform_req); - } - Ok(PlatformRequirementFilter::ignore_nothing()) -} diff --git a/crates/mozart/src/commands/reinstall.rs b/crates/mozart/src/commands/reinstall.rs index 206d2bf..ececa96 100644 --- a/crates/mozart/src/commands/reinstall.rs +++ b/crates/mozart/src/commands/reinstall.rs @@ -1,8 +1,6 @@ use clap::Args; use mozart_autoload::AutoloadGeneratorExt; -use mozart_core::composer::{ - AutoloadDumpOptions, Composer, LocalPackage, PlatformRequirementFilter, -}; +use mozart_core::composer::{AutoloadDumpOptions, Composer, LocalPackage}; use mozart_core::console_format; use mozart_core::validation::package_name_to_regexp; @@ -78,7 +76,7 @@ pub async fn execute( anyhow::bail!("You cannot specify package names and filter by type at the same time."); } let lower_types: Vec<String> = args.r#type.iter().map(|t| t.to_lowercase()).collect(); - for package in local_repo.canonical_packages() { + for package in local_repo.get_canonical_packages() { // Composer compares against `getType()` — packages without a // `type` are normalised to `library` by the package loader. let pt = package.package_type().unwrap_or("library").to_lowercase(); @@ -94,7 +92,7 @@ pub async fn execute( for pattern in &args.packages { let pattern_regexp = package_name_to_regexp(pattern); let mut matched = false; - for package in local_repo.canonical_packages() { + for package in local_repo.get_canonical_packages() { if pattern_regexp.is_match(package.pretty_name()) { matched = true; packages_to_reinstall.push(package); @@ -201,7 +199,10 @@ pub async fn execute( apcu_prefix, run_scripts: false, dry_run: false, - platform_requirement_filter: get_platform_requirement_filter(args)?, + platform_requirement_filter: super::get_platform_requirement_filter( + args.ignore_platform_reqs, + &args.ignore_platform_req, + )?, }; let _class_map = composer.autoload_generator().dump( @@ -222,21 +223,3 @@ pub async fn execute( Ok(()) } - -/// Mirror of `BaseCommand::getPlatformRequirementFilter` for the -/// `reinstall` command. Priority: -/// 1. `--ignore-platform-reqs` → ignore every platform requirement -/// 2. `--ignore-platform-req <name>...` (non-empty) → ignore the listed -/// names (with `*` glob support) -/// 3. neither → ignore nothing -fn get_platform_requirement_filter( - args: &ReinstallArgs, -) -> anyhow::Result<PlatformRequirementFilter> { - if args.ignore_platform_reqs { - return Ok(PlatformRequirementFilter::ignore_all()); - } - if !args.ignore_platform_req.is_empty() { - return PlatformRequirementFilter::from_list(&args.ignore_platform_req); - } - Ok(PlatformRequirementFilter::ignore_nothing()) -} diff --git a/crates/mozart/src/commands/status.rs b/crates/mozart/src/commands/status.rs index 30d7396..b6802a3 100644 --- a/crates/mozart/src/commands/status.rs +++ b/crates/mozart/src/commands/status.rs @@ -37,7 +37,7 @@ pub async fn execute( let mut unpushed_changes: IndexMap<String, String> = IndexMap::new(); let mut vcs_version_changes: IndexMap<String, VcsVerChange> = IndexMap::new(); - for package in installed_repo.canonical_packages() { + for package in installed_repo.get_canonical_packages() { let Some(downloader) = dm.for_package(package) else { continue; }; diff --git a/crates/mozart/src/commands/validate.rs b/crates/mozart/src/commands/validate.rs index 539ff20..3fd1f56 100644 --- a/crates/mozart/src/commands/validate.rs +++ b/crates/mozart/src/commands/validate.rs @@ -193,7 +193,7 @@ fn validate_dependencies( for package in composer .repository_manager() .local_repository() - .canonical_packages() + .get_canonical_packages() { // Mirrors Composer: `if ($package->getType() === 'metapackage') { continue; }` if package.package_type() == Some("metapackage") { |
