From 8871b923fa3df1935c263db155cb8bc3d59705cd Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 10 May 2026 23:58:26 +0900 Subject: refactor(downloader): turn DownloadManager into downloader registry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reshape DownloadManager from a hard-coded VCS match into a registry of DownloaderInterface instances keyed by source type, mirroring Composer's DownloadManager — with prefer-source/dist preferences, an IO handle, and a files cache. ArchiveManager now resolves dist sources through a shared DownloadManager instead of calling download_dist directly, and Composer::require / try_load take an IO so it flows through the factory wiring. --- crates/mozart/src/commands/create_project.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'crates/mozart/src/commands/create_project.rs') diff --git a/crates/mozart/src/commands/create_project.rs b/crates/mozart/src/commands/create_project.rs index 276bd3a..08e146e 100644 --- a/crates/mozart/src/commands/create_project.rs +++ b/crates/mozart/src/commands/create_project.rs @@ -2,6 +2,7 @@ use clap::Args; use indexmap::IndexMap; use mozart_core::console::IoInterface; use mozart_core::console_format; +use mozart_core::factory::create_config; use mozart_core::package::{self, Stability}; use mozart_core::repository::downloader; use mozart_core::repository::lockfile; @@ -11,6 +12,8 @@ use mozart_core::repository::version; use mozart_core::validation; use std::path::{Path, PathBuf}; +use crate::factory::create_download_manager; + #[derive(Args)] pub struct CreateProjectArgs { /// Package name to install @@ -337,7 +340,7 @@ pub async fn execute( let secure_http = !args.no_secure_http; install_project( - &io, + io, cli, args, args.package.as_deref(), @@ -362,7 +365,7 @@ pub async fn execute( #[allow(clippy::too_many_arguments)] async fn install_project( - io: &std::sync::Arc>>, + io: std::sync::Arc>>, cli: &super::Cli, args: &CreateProjectArgs, package_name: Option<&str>, @@ -395,7 +398,7 @@ async fn install_project( let root_result = if let Some(name) = package_name { Some( install_root_package( - io, + io.clone(), cli, args, name, @@ -647,7 +650,7 @@ async fn install_project( #[allow(clippy::too_many_arguments)] async fn install_root_package( - io: &std::sync::Arc>>, + io: std::sync::Arc>>, cli: &super::Cli, _args: &CreateProjectArgs, package_name: &str, @@ -733,7 +736,6 @@ async fn install_root_package( // --- Find the best candidate matching constraint + stability --- let cache_config = mozart_core::repository::cache::build_cache_config(cli.no_cache); let repo_cache = mozart_core::repository::cache::Cache::repo(&cache_config); - let files_cache = mozart_core::repository::cache::Cache::files(&cache_config); let versions = packagist::fetch_package_versions(&name, &repo_cache).await?; @@ -786,13 +788,11 @@ async fn install_root_package( let mut progress = downloader::DownloadProgress::new(!no_progress, format!("{name} ({concrete_version})")); - let bytes = downloader::download_dist( - &dist.url, - dist.shasum.as_deref(), - Some(&mut progress), - &files_cache, - ) - .await?; + let config = create_config()?; + let download_manager = create_download_manager(io.clone(), &config); + let bytes = download_manager + .download_legacy(&dist.url, dist.shasum.as_deref(), Some(&mut progress)) + .await?; progress.finish(); -- cgit v1.3.1