mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
fix: sync scripts repo in background
This commit is contained in:
parent
92c6120d24
commit
70d07feb70
6 changed files with 69 additions and 22 deletions
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
- Use updated aliases when reusing lockfile dependencies by @daimond113
|
||||
- Listen for device flow completion without requiring pressing enter by @daimond113
|
||||
- Sync scripts repo in background by @daimond113
|
||||
|
||||
### Performance
|
||||
- Clone dependency repos shallowly by @daimond113
|
||||
|
|
|
@ -10,7 +10,10 @@ use pesde::{
|
|||
manifest::{target::TargetKind, DependencyType},
|
||||
Project, MANIFEST_FILE_NAME,
|
||||
};
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
use std::{
|
||||
collections::{BTreeSet, HashSet},
|
||||
thread::JoinHandle,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args, Copy, Clone)]
|
||||
pub struct InstallCommand {
|
||||
|
@ -93,6 +96,7 @@ impl InstallCommand {
|
|||
project: Project,
|
||||
multi: MultiProgress,
|
||||
reqwest: reqwest::blocking::Client,
|
||||
update_task: &mut Option<JoinHandle<()>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut refreshed_sources = HashSet::new();
|
||||
|
||||
|
@ -182,6 +186,11 @@ impl InstallCommand {
|
|||
.dependency_graph(old_graph.as_ref(), &mut refreshed_sources)
|
||||
.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(
|
||||
&project,
|
||||
&mut refreshed_sources,
|
||||
|
@ -274,7 +283,7 @@ impl InstallCommand {
|
|||
graph: downloaded_graph,
|
||||
|
||||
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")?;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use indicatif::MultiProgress;
|
||||
use pesde::Project;
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
mod add;
|
||||
mod auth;
|
||||
|
@ -77,13 +78,16 @@ impl Subcommand {
|
|||
project: Project,
|
||||
multi: MultiProgress,
|
||||
reqwest: reqwest::blocking::Client,
|
||||
update_task: JoinHandle<()>,
|
||||
) -> anyhow::Result<()> {
|
||||
match self {
|
||||
let mut update_task = Some(update_task);
|
||||
|
||||
let res = match self {
|
||||
Subcommand::Auth(auth) => auth.run(project, reqwest),
|
||||
Subcommand::Config(config) => config.run(),
|
||||
Subcommand::Init(init) => init.run(project),
|
||||
Subcommand::Run(run) => run.run(project),
|
||||
Subcommand::Install(install) => install.run(project, multi, reqwest),
|
||||
Subcommand::Run(run) => run.run(project, &mut update_task),
|
||||
Subcommand::Install(install) => install.run(project, multi, reqwest, &mut update_task),
|
||||
Subcommand::Publish(publish) => publish.run(project, reqwest),
|
||||
#[cfg(feature = "version-management")]
|
||||
Subcommand::SelfInstall(self_install) => self_install.run(),
|
||||
|
@ -94,9 +98,15 @@ impl Subcommand {
|
|||
#[cfg(feature = "version-management")]
|
||||
Subcommand::SelfUpgrade(self_upgrade) => self_upgrade.run(reqwest),
|
||||
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::Execute(execute) => execute.run(project, reqwest),
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(handle) = update_task.take() {
|
||||
handle.join().expect("failed to join update task");
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ use pesde::{
|
|||
Project, PACKAGES_CONTAINER_NAME,
|
||||
};
|
||||
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)]
|
||||
pub struct RunCommand {
|
||||
|
@ -22,8 +24,16 @@ pub struct RunCommand {
|
|||
}
|
||||
|
||||
impl RunCommand {
|
||||
pub fn run(self, project: Project) -> anyhow::Result<()> {
|
||||
let run = |path: PathBuf| {
|
||||
pub fn run(
|
||||
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");
|
||||
caller
|
||||
.write_all(
|
||||
|
|
|
@ -4,7 +4,7 @@ use clap::Args;
|
|||
use colored::Colorize;
|
||||
use indicatif::MultiProgress;
|
||||
use pesde::{lockfile::Lockfile, Project};
|
||||
use std::collections::HashSet;
|
||||
use std::{collections::HashSet, thread::JoinHandle};
|
||||
|
||||
#[derive(Debug, Args, Copy, Clone)]
|
||||
pub struct UpdateCommand {
|
||||
|
@ -19,6 +19,7 @@ impl UpdateCommand {
|
|||
project: Project,
|
||||
multi: MultiProgress,
|
||||
reqwest: reqwest::blocking::Client,
|
||||
update_task: &mut Option<JoinHandle<()>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut refreshed_sources = HashSet::new();
|
||||
|
||||
|
@ -37,6 +38,10 @@ impl UpdateCommand {
|
|||
.dependency_graph(None, &mut refreshed_sources)
|
||||
.context("failed to build dependency graph")?;
|
||||
|
||||
if let Some(handle) = update_task.take() {
|
||||
handle.join().expect("failed to join update task");
|
||||
}
|
||||
|
||||
project
|
||||
.write_lockfile(Lockfile {
|
||||
name: manifest.name,
|
||||
|
@ -58,7 +63,7 @@ impl UpdateCommand {
|
|||
)?,
|
||||
|
||||
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")?;
|
||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -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 clap::Parser;
|
||||
use colored::Colorize;
|
||||
|
@ -8,14 +13,9 @@ use std::{
|
|||
collections::HashSet,
|
||||
fs::create_dir_all,
|
||||
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;
|
||||
pub mod util;
|
||||
|
||||
|
@ -257,12 +257,24 @@ fn run() -> anyhow::Result<()> {
|
|||
display_err(check_for_updates(&reqwest), " while checking for updates");
|
||||
}
|
||||
|
||||
let project_2 = project.clone();
|
||||
let update_task = spawn(move || {
|
||||
display_err(
|
||||
update_repo_dependencies(&project),
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue