diff options
Diffstat (limited to 'crates/mozart-registry/src/installer_executor')
3 files changed, 88 insertions, 8 deletions
diff --git a/crates/mozart-registry/src/installer_executor/filesystem.rs b/crates/mozart-registry/src/installer_executor/filesystem.rs index 185e5b9..cceb5da 100644 --- a/crates/mozart-registry/src/installer_executor/filesystem.rs +++ b/crates/mozart-registry/src/installer_executor/filesystem.rs @@ -29,7 +29,13 @@ impl InstallerExecutor for FilesystemExecutor { op: PackageOperation<'_>, ctx: &ExecuteContext, ) -> anyhow::Result<()> { - let pkg = op.package(); + // Marking an alias as installed has no filesystem side effects — + // the target package's files are already in vendor/. Mirrors + // Composer's `MarkAliasInstalledOperation` which the installation + // manager only uses to update the in-memory installed repository. + let Some(pkg) = op.package() else { + return Ok(()); + }; // Try source install if --prefer-source and source info is available. if ctx.prefer_source diff --git a/crates/mozart-registry/src/installer_executor/mod.rs b/crates/mozart-registry/src/installer_executor/mod.rs index c70fe12..ff3d7a8 100644 --- a/crates/mozart-registry/src/installer_executor/mod.rs +++ b/crates/mozart-registry/src/installer_executor/mod.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; -use crate::lockfile::LockedPackage; +use crate::lockfile::{LockAlias, LockedPackage}; pub mod filesystem; pub mod trace_recorder; @@ -35,18 +35,75 @@ pub enum PackageOperation<'a> { from_version: &'a str, package: &'a LockedPackage, }, + /// Mark an alias of a real package as installed. No filesystem effects — + /// only the trace recorder needs this. Mirrors Composer's + /// `MarkAliasInstalledOperation`. + MarkAliasInstalled { + /// The alias entry from `composer.lock`'s `aliases[]` block. Carries + /// pretty + normalized alias version and the target's pretty version. + alias: &'a LockAlias, + /// The target package the alias points at — used to source the + /// reference suffix for the trace line. + target: &'a LockedPackage, + }, } impl<'a> PackageOperation<'a> { - pub fn package(&self) -> &'a LockedPackage { + pub fn package(&self) -> Option<&'a LockedPackage> { match self { PackageOperation::Install { package } | PackageOperation::Update { package, .. } => { - package + Some(package) } + PackageOperation::MarkAliasInstalled { .. } => None, } } } +/// Mirror Composer's `BasePackage::getFullPrettyVersion()` for a `LockedPackage`. +/// +/// For dev-stability versions backed by a git/hg source, append the reference +/// (truncated to 7 chars when it looks like a 40-char sha1). Otherwise return +/// the pretty version unchanged. +pub fn format_full_pretty_version(pkg: &LockedPackage) -> String { + format_full_pretty_with_pretty(&pkg.version, pkg) +} + +/// Same as [`format_full_pretty_version`] but lets the caller supply an +/// alternate pretty version (used by `MarkAliasInstalled` so the alias's +/// `3.2.x-dev` text is rendered with the *target's* reference). +pub fn format_full_pretty_with_pretty(pretty_version: &str, pkg: &LockedPackage) -> String { + let is_dev = mozart_semver::Version::parse(&pkg.version) + .map(|v| matches!(v.pre_release.as_deref(), Some("dev")) || v.is_dev_branch) + .unwrap_or(false); + if !is_dev { + return pretty_version.to_string(); + } + let source_ref = pkg.source.as_ref().and_then(|s| s.reference.as_deref()); + let dist_ref = pkg.dist.as_ref().and_then(|d| d.reference.as_deref()); + let source_type = pkg.source.as_ref().map(|s| s.source_type.as_str()); + // Composer falls back to dist reference only when no source type is set + // (or the package isn't git/hg — in which case the dev display is skipped + // entirely above). + let reference = source_ref.or(match source_type { + Some("git") | Some("hg") => None, + _ => dist_ref, + }); + let Some(reference) = reference else { + return pretty_version.to_string(); + }; + if matches!(source_type, Some("git") | Some("hg")) && reference.len() == 40 { + format!("{} {}", pretty_version, &reference[..7]) + } else if matches!(source_type, Some("svn")) { + // svn references are revision numbers, never truncated + format!("{} {}", pretty_version, reference) + } else if reference.len() == 40 { + // dist-ref fallback (no git/hg source) — Composer truncates here too + format!("{} {}", pretty_version, &reference[..7]) + } else { + format!("{} {}", pretty_version, reference) + } +} + /// Per-call configuration shared across executor methods. Owned by the /// caller (typically `install_from_lock`) so the executor sees a consistent /// view across an entire install/update run. diff --git a/crates/mozart-registry/src/installer_executor/trace_recorder.rs b/crates/mozart-registry/src/installer_executor/trace_recorder.rs index c924d73..44fceea 100644 --- a/crates/mozart-registry/src/installer_executor/trace_recorder.rs +++ b/crates/mozart-registry/src/installer_executor/trace_recorder.rs @@ -16,7 +16,10 @@ use mozart_semver::Version; -use super::{ExecuteContext, InstallerExecutor, PackageOperation}; +use super::{ + ExecuteContext, InstallerExecutor, PackageOperation, format_full_pretty_version, + format_full_pretty_with_pretty, +}; /// Recording-only executor. Construct with [`TraceRecorderExecutor::new`], /// then read [`TraceRecorderExecutor::trace`] after the run completes. @@ -58,8 +61,11 @@ impl InstallerExecutor for TraceRecorderExecutor { ) -> anyhow::Result<()> { match op { PackageOperation::Install { package } => { - self.trace - .push(format!("Installing {} ({})", package.name, package.version)); + self.trace.push(format!( + "Installing {} ({})", + package.name, + format_full_pretty_version(package) + )); } PackageOperation::Update { from_version, @@ -72,7 +78,18 @@ impl InstallerExecutor for TraceRecorderExecutor { }; self.trace.push(format!( "{} {} ({} => {})", - action, package.name, from_version, package.version + action, + package.name, + from_version, + format_full_pretty_version(package) + )); + } + PackageOperation::MarkAliasInstalled { alias, target } => { + let alias_full = format_full_pretty_with_pretty(&alias.alias, target); + let target_full = format_full_pretty_version(target); + self.trace.push(format!( + "Marking {} ({}) as installed, alias of {} ({})", + alias.package, alias_full, alias.package, target_full )); } } |
