fix: sync scripts repo in background

This commit is contained in:
daimond113 2024-10-20 18:13:08 +02:00
parent 92c6120d24
commit 70d07feb70
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
6 changed files with 69 additions and 22 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Use updated aliases when reusing lockfile dependencies by @daimond113 - Use updated aliases when reusing lockfile dependencies by @daimond113
- Listen for device flow completion without requiring pressing enter by @daimond113 - Listen for device flow completion without requiring pressing enter by @daimond113
- Sync scripts repo in background by @daimond113
### Performance ### Performance
- Clone dependency repos shallowly by @daimond113 - Clone dependency repos shallowly by @daimond113

View file

@ -10,7 +10,10 @@ use pesde::{
manifest::{target::TargetKind, DependencyType}, manifest::{target::TargetKind, DependencyType},
Project, MANIFEST_FILE_NAME, Project, MANIFEST_FILE_NAME,
}; };
use std::collections::{BTreeSet, HashSet}; use std::{
collections::{BTreeSet, HashSet},
thread::JoinHandle,
};
#[derive(Debug, Args, Copy, Clone)] #[derive(Debug, Args, Copy, Clone)]
pub struct InstallCommand { pub struct InstallCommand {
@ -93,6 +96,7 @@ impl InstallCommand {
project: Project, project: Project,
multi: MultiProgress, multi: MultiProgress,
reqwest: reqwest::blocking::Client, reqwest: reqwest::blocking::Client,
update_task: &mut Option<JoinHandle<()>>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut refreshed_sources = HashSet::new(); let mut refreshed_sources = HashSet::new();
@ -182,6 +186,11 @@ impl InstallCommand {
.dependency_graph(old_graph.as_ref(), &mut refreshed_sources) .dependency_graph(old_graph.as_ref(), &mut refreshed_sources)
.context("failed to build dependency graph")?; .context("failed to build dependency graph")?;
if let Some(task) = update_task.take() {
log::debug!("waiting for update task to finish");
task.join().expect("failed to join update task");
}
let downloaded_graph = download_graph( let downloaded_graph = download_graph(
&project, &project,
&mut refreshed_sources, &mut refreshed_sources,
@ -274,7 +283,7 @@ impl InstallCommand {
graph: downloaded_graph, graph: downloaded_graph,
workspace: run_on_workspace_members(&project, |project| { workspace: run_on_workspace_members(&project, |project| {
self.run(project, multi.clone(), reqwest.clone()) self.run(project, multi.clone(), reqwest.clone(), &mut None)
})?, })?,
}) })
.context("failed to write lockfile")?; .context("failed to write lockfile")?;

View file

@ -1,5 +1,6 @@
use indicatif::MultiProgress; use indicatif::MultiProgress;
use pesde::Project; use pesde::Project;
use std::thread::JoinHandle;
mod add; mod add;
mod auth; mod auth;
@ -77,13 +78,16 @@ impl Subcommand {
project: Project, project: Project,
multi: MultiProgress, multi: MultiProgress,
reqwest: reqwest::blocking::Client, reqwest: reqwest::blocking::Client,
update_task: JoinHandle<()>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match self { let mut update_task = Some(update_task);
let res = match self {
Subcommand::Auth(auth) => auth.run(project, reqwest), Subcommand::Auth(auth) => auth.run(project, reqwest),
Subcommand::Config(config) => config.run(), Subcommand::Config(config) => config.run(),
Subcommand::Init(init) => init.run(project), Subcommand::Init(init) => init.run(project),
Subcommand::Run(run) => run.run(project), Subcommand::Run(run) => run.run(project, &mut update_task),
Subcommand::Install(install) => install.run(project, multi, reqwest), Subcommand::Install(install) => install.run(project, multi, reqwest, &mut update_task),
Subcommand::Publish(publish) => publish.run(project, reqwest), Subcommand::Publish(publish) => publish.run(project, reqwest),
#[cfg(feature = "version-management")] #[cfg(feature = "version-management")]
Subcommand::SelfInstall(self_install) => self_install.run(), Subcommand::SelfInstall(self_install) => self_install.run(),
@ -94,9 +98,15 @@ impl Subcommand {
#[cfg(feature = "version-management")] #[cfg(feature = "version-management")]
Subcommand::SelfUpgrade(self_upgrade) => self_upgrade.run(reqwest), Subcommand::SelfUpgrade(self_upgrade) => self_upgrade.run(reqwest),
Subcommand::Add(add) => add.run(project), Subcommand::Add(add) => add.run(project),
Subcommand::Update(update) => update.run(project, multi, reqwest), Subcommand::Update(update) => update.run(project, multi, reqwest, &mut update_task),
Subcommand::Outdated(outdated) => outdated.run(project), Subcommand::Outdated(outdated) => outdated.run(project),
Subcommand::Execute(execute) => execute.run(project, reqwest), Subcommand::Execute(execute) => execute.run(project, reqwest),
};
if let Some(handle) = update_task.take() {
handle.join().expect("failed to join update task");
} }
res
} }
} }

View file

@ -8,7 +8,9 @@ use pesde::{
Project, PACKAGES_CONTAINER_NAME, Project, PACKAGES_CONTAINER_NAME,
}; };
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use std::{env::current_dir, ffi::OsString, io::Write, path::PathBuf, process::Command}; use std::{
env::current_dir, ffi::OsString, io::Write, path::PathBuf, process::Command, thread::JoinHandle,
};
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct RunCommand { pub struct RunCommand {
@ -22,8 +24,16 @@ pub struct RunCommand {
} }
impl RunCommand { impl RunCommand {
pub fn run(self, project: Project) -> anyhow::Result<()> { pub fn run(
let run = |path: PathBuf| { self,
project: Project,
update_task: &mut Option<JoinHandle<()>>,
) -> anyhow::Result<()> {
let mut run = |path: PathBuf| {
if let Some(handle) = update_task.take() {
handle.join().expect("failed to join update task");
}
let mut caller = tempfile::NamedTempFile::new().expect("failed to create tempfile"); let mut caller = tempfile::NamedTempFile::new().expect("failed to create tempfile");
caller caller
.write_all( .write_all(

View file

@ -4,7 +4,7 @@ use clap::Args;
use colored::Colorize; use colored::Colorize;
use indicatif::MultiProgress; use indicatif::MultiProgress;
use pesde::{lockfile::Lockfile, Project}; use pesde::{lockfile::Lockfile, Project};
use std::collections::HashSet; use std::{collections::HashSet, thread::JoinHandle};
#[derive(Debug, Args, Copy, Clone)] #[derive(Debug, Args, Copy, Clone)]
pub struct UpdateCommand { pub struct UpdateCommand {
@ -19,6 +19,7 @@ impl UpdateCommand {
project: Project, project: Project,
multi: MultiProgress, multi: MultiProgress,
reqwest: reqwest::blocking::Client, reqwest: reqwest::blocking::Client,
update_task: &mut Option<JoinHandle<()>>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut refreshed_sources = HashSet::new(); let mut refreshed_sources = HashSet::new();
@ -37,6 +38,10 @@ impl UpdateCommand {
.dependency_graph(None, &mut refreshed_sources) .dependency_graph(None, &mut refreshed_sources)
.context("failed to build dependency graph")?; .context("failed to build dependency graph")?;
if let Some(handle) = update_task.take() {
handle.join().expect("failed to join update task");
}
project project
.write_lockfile(Lockfile { .write_lockfile(Lockfile {
name: manifest.name, name: manifest.name,
@ -58,7 +63,7 @@ impl UpdateCommand {
)?, )?,
workspace: run_on_workspace_members(&project, |project| { workspace: run_on_workspace_members(&project, |project| {
self.run(project, multi.clone(), reqwest.clone()) self.run(project, multi.clone(), reqwest.clone(), &mut None)
})?, })?,
}) })
.context("failed to write lockfile")?; .context("failed to write lockfile")?;

View file

@ -1,3 +1,8 @@
#[cfg(feature = "version-management")]
use crate::cli::version::{
check_for_updates, current_version, get_or_download_version, max_installed_version,
};
use crate::cli::{auth::get_tokens, home_dir, repos::update_repo_dependencies, HOME_DIR};
use anyhow::Context; use anyhow::Context;
use clap::Parser; use clap::Parser;
use colored::Colorize; use colored::Colorize;
@ -8,14 +13,9 @@ use std::{
collections::HashSet, collections::HashSet,
fs::create_dir_all, fs::create_dir_all,
path::{Path, PathBuf}, path::{Path, PathBuf},
thread::spawn,
}; };
#[cfg(feature = "version-management")]
use crate::cli::version::{
check_for_updates, current_version, get_or_download_version, max_installed_version,
};
use crate::cli::{auth::get_tokens, home_dir, repos::update_repo_dependencies, HOME_DIR};
mod cli; mod cli;
pub mod util; pub mod util;
@ -257,12 +257,24 @@ fn run() -> anyhow::Result<()> {
display_err(check_for_updates(&reqwest), " while checking for updates"); display_err(check_for_updates(&reqwest), " while checking for updates");
} }
display_err( let project_2 = project.clone();
update_repo_dependencies(&project), let update_task = spawn(move || {
" while updating repository dependencies", display_err(
); update_repo_dependencies(&project_2),
" while updating repository dependencies",
);
});
Cli::parse().subcommand.run(project, multi, reqwest) let cli = match Cli::try_parse() {
Ok(cli) => cli,
Err(err) => {
let _ = err.print();
update_task.join().expect("failed to join update task");
std::process::exit(err.exit_code());
}
};
cli.subcommand.run(project, multi, reqwest, update_task)
} }
fn display_err(result: anyhow::Result<()>, prefix: &str) { fn display_err(result: anyhow::Result<()>, prefix: &str) {