From b5b3257caccd7ecd1db3e30242ed43e3a80bf561 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:50:14 +0100 Subject: [PATCH] fix: install dependencies of packages in x command --- CHANGELOG.md | 3 ++ src/cli/commands/execute.rs | 56 ++++++++++++++++++++++++++++++------- src/cli/commands/install.rs | 2 +- src/cli/commands/mod.rs | 2 +- src/cli/commands/publish.rs | 7 +++-- src/cli/commands/update.rs | 2 +- src/resolver.rs | 5 ++-- 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a158959..1e2f410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Make `includes` use glob patterns by @daimond113 - Use symlinks for workspace dependencies to not require reinstalling by @daimond113 +### Fixed +- Install dependencies of packages in `x` command + ## [0.5.0-rc.12] - 2024-11-22 ### Added - Support fallback Wally registries by @daimond113 diff --git a/src/cli/commands/execute.rs b/src/cli/commands/execute.rs index 93c41fe..4e7cd8e 100644 --- a/src/cli/commands/execute.rs +++ b/src/cli/commands/execute.rs @@ -1,7 +1,8 @@ -use crate::cli::{config::read_config, VersionedPackageName}; +use crate::cli::{config::read_config, progress_bar, VersionedPackageName}; use anyhow::Context; use clap::Args; use fs_err::tokio as fs; +use indicatif::MultiProgress; use pesde::{ linking::generator::generate_bin_linking_module, manifest::target::TargetKind, @@ -31,7 +32,12 @@ pub struct ExecuteCommand { } impl ExecuteCommand { - pub async fn run(self, project: Project, reqwest: reqwest::Client) -> anyhow::Result<()> { + pub async fn run( + self, + project: Project, + multi: MultiProgress, + reqwest: reqwest::Client, + ) -> anyhow::Result<()> { let index = match self.index { Some(index) => Some(index), None => read_config().await.ok().map(|c| c.default_index), @@ -77,24 +83,54 @@ impl ExecuteCommand { log::info!("found package {}@{version}", pkg_ref.name); + let tmp_dir = project.cas_dir().join(".tmp"); + fs::create_dir_all(&tmp_dir) + .await + .context("failed to create temporary directory")?; + let tempdir = + tempfile::tempdir_in(tmp_dir).context("failed to create temporary directory")?; + + let project = Project::new( + tempdir.path(), + None::, + project.data_dir(), + project.cas_dir(), + project.auth_config().clone(), + ); + let (fs, target) = source .download(&pkg_ref, &project, &reqwest) .await .context("failed to download package")?; let bin_path = target.bin_path().context("package has no binary export")?; - let tmp_dir = project.cas_dir().join(".tmp"); - fs::create_dir_all(&tmp_dir) - .await - .context("failed to create temporary directory")?; - - let tempdir = - tempfile::tempdir_in(tmp_dir).context("failed to create temporary directory")?; - fs.write_to(tempdir.path(), project.cas_dir(), true) .await .context("failed to write package contents")?; + let mut refreshed_sources = HashSet::new(); + + let graph = project + .dependency_graph(None, &mut refreshed_sources, true) + .await + .context("failed to build dependency graph")?; + + let rx = project + .download_graph(&graph, &mut refreshed_sources, &reqwest, true, true) + .await + .context("failed to download dependencies")? + .0; + + progress_bar( + graph.values().map(|versions| versions.len() as u64).sum(), + rx, + &multi, + "📥 ".to_string(), + "downloading dependencies".to_string(), + "downloaded dependencies".to_string(), + ) + .await?; + let mut caller = tempfile::NamedTempFile::new_in(tempdir.path()).context("failed to create tempfile")?; caller diff --git a/src/cli/commands/install.rs b/src/cli/commands/install.rs index 3a6df0f..b89a08f 100644 --- a/src/cli/commands/install.rs +++ b/src/cli/commands/install.rs @@ -195,7 +195,7 @@ impl InstallCommand { println!("{} 📦 building dependency graph", job(2)); let graph = project - .dependency_graph(old_graph.as_ref(), &mut refreshed_sources) + .dependency_graph(old_graph.as_ref(), &mut refreshed_sources, false) .await .context("failed to build dependency graph")?; diff --git a/src/cli/commands/mod.rs b/src/cli/commands/mod.rs index e32b042..566b342 100644 --- a/src/cli/commands/mod.rs +++ b/src/cli/commands/mod.rs @@ -96,7 +96,7 @@ impl Subcommand { Subcommand::Add(add) => add.run(project).await, Subcommand::Update(update) => update.run(project, multi, reqwest).await, Subcommand::Outdated(outdated) => outdated.run(project).await, - Subcommand::Execute(execute) => execute.run(project, reqwest).await, + Subcommand::Execute(execute) => execute.run(project, multi, reqwest).await, } } } diff --git a/src/cli/commands/publish.rs b/src/cli/commands/publish.rs index b56b407..3d7a54d 100644 --- a/src/cli/commands/publish.rs +++ b/src/cli/commands/publish.rs @@ -230,9 +230,10 @@ info: otherwise, the file was deemed unnecessary, if you don't understand why, p ); } - if roblox_target.as_mut().is_some_and(|build_files| { - build_files.insert(first_part.to_string()) - }) { + if roblox_target + .as_mut() + .is_some_and(|build_files| build_files.insert(first_part.to_string())) + { println!( "{}: {name} was not in build files, adding {first_part}", "warn".yellow().bold() diff --git a/src/cli/commands/update.rs b/src/cli/commands/update.rs index 697a5d2..ea0f866 100644 --- a/src/cli/commands/update.rs +++ b/src/cli/commands/update.rs @@ -31,7 +31,7 @@ impl UpdateCommand { ); let graph = project - .dependency_graph(None, &mut refreshed_sources) + .dependency_graph(None, &mut refreshed_sources, false) .await .context("failed to build dependency graph")?; diff --git a/src/resolver.rs b/src/resolver.rs index b9ac644..c9ab73a 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -19,6 +19,7 @@ impl Project { &self, previous_graph: Option<&DependencyGraph>, refreshed_sources: &mut HashSet, + manifest_transformed: bool, ) -> Result> { let manifest = self .deser_manifest() @@ -139,7 +140,7 @@ impl Project { ); let source = match &specifier { DependencySpecifiers::Pesde(specifier) => { - let index_url = if depth == 0 || overridden { + let index_url = if !manifest_transformed && (depth == 0 || overridden) { let index_name = specifier.index.as_deref().unwrap_or(DEFAULT_INDEX_NAME); manifest @@ -163,7 +164,7 @@ impl Project { } #[cfg(feature = "wally-compat")] DependencySpecifiers::Wally(specifier) => { - let index_url = if depth == 0 || overridden { + let index_url = if !manifest_transformed && (depth == 0 || overridden) { let index_name = specifier.index.as_deref().unwrap_or(DEFAULT_INDEX_NAME); manifest