mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-04-10 22:00:55 +01:00
fix: add missing run alias behaviour
The `run <alias>` behaviour was documented yet missing. This commit adds it.
This commit is contained in:
parent
12c62d315d
commit
0e73db2831
2 changed files with 23 additions and 8 deletions
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
- Fix path dependencies using project's workspace dependencies by @daimond113
|
||||
- Fix binary linkers not being created for non-direct dependencies by @daimond113
|
||||
- Add missing `run <alias>` behaviour by @daimond113
|
||||
|
||||
### Changed
|
||||
- Binary linkers are now done in Rust to simplify their implementation and cross-runtime portability by @daimond113
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::cli::up_to_date_lockfile;
|
||||
use crate::cli::{style::WARN_STYLE, up_to_date_lockfile};
|
||||
use anyhow::Context as _;
|
||||
use clap::Args;
|
||||
use futures::{StreamExt as _, TryStreamExt as _};
|
||||
use pesde::{
|
||||
errors::{ManifestReadError, WorkspaceMembersError},
|
||||
linking::generator::generate_bin_linking_module,
|
||||
manifest::Alias,
|
||||
names::{PackageName, PackageNames},
|
||||
source::traits::{GetTargetOptions, PackageRef as _, PackageSource as _, RefreshOptions},
|
||||
Project, MANIFEST_FILE_NAME,
|
||||
|
@ -28,7 +29,7 @@ pub struct RunCommand {
|
|||
|
||||
impl RunCommand {
|
||||
pub async fn run(self, project: Project) -> anyhow::Result<()> {
|
||||
let run = |root: &Path, file_path: &Path| {
|
||||
let run = |root: &Path, file_path: &Path| -> ! {
|
||||
let mut caller = tempfile::NamedTempFile::new().expect("failed to create tempfile");
|
||||
caller
|
||||
.write_all(
|
||||
|
@ -60,12 +61,13 @@ impl RunCommand {
|
|||
project.package_dir(),
|
||||
&script_path.to_path(project.package_dir()),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
anyhow::bail!("no package or script specified, and no bin path found in manifest")
|
||||
};
|
||||
|
||||
let mut package_info = None;
|
||||
|
||||
if let Ok(pkg_name) = package_or_script.parse::<PackageName>() {
|
||||
let graph = if let Some(lockfile) = up_to_date_lockfile(&project).await? {
|
||||
lockfile.graph
|
||||
|
@ -80,12 +82,28 @@ impl RunCommand {
|
|||
.filter(|(id, node)| *id.name() == pkg_name && node.direct.is_some())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let (id, node) = match versions.len() {
|
||||
package_info = Some(match versions.len() {
|
||||
0 => anyhow::bail!("package not found"),
|
||||
1 => versions.pop().unwrap(),
|
||||
_ => anyhow::bail!("multiple versions found. use the package's alias instead."),
|
||||
});
|
||||
} else if let Ok(alias) = package_or_script.parse::<Alias>() {
|
||||
if let Some(lockfile) = up_to_date_lockfile(&project).await? {
|
||||
package_info = lockfile
|
||||
.graph
|
||||
.into_iter()
|
||||
.find(|(_, node)| node.direct.as_ref().is_some_and(|(a, _, _)| alias == *a));
|
||||
} else {
|
||||
eprintln!(
|
||||
"{}",
|
||||
WARN_STYLE.apply_to(
|
||||
"outdated lockfile, please run the install command first to use an alias"
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
if let Some((id, node)) = package_info {
|
||||
let container_folder = node.container_folder_from_project(
|
||||
&id,
|
||||
&project,
|
||||
|
@ -122,7 +140,6 @@ impl RunCommand {
|
|||
let path = bin_path.to_path(&container_folder);
|
||||
|
||||
run(&path, &path);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Ok(manifest) = project.deser_manifest().await {
|
||||
|
@ -131,7 +148,6 @@ impl RunCommand {
|
|||
project.package_dir(),
|
||||
&script_path.to_path(project.package_dir()),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +210,5 @@ impl RunCommand {
|
|||
};
|
||||
|
||||
run(&root, &path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue