refactor: remove hack in x command

This commit is contained in:
daimond113 2025-04-28 22:31:24 +02:00
parent e4f496ffab
commit 0f63044fa6
No known key found for this signature in database
GPG key ID: 640DC95EC1190354
2 changed files with 24 additions and 28 deletions

View file

@ -18,9 +18,7 @@ use pesde::{
source::{
ids::PackageId,
pesde::{specifier::PesdeDependencySpecifier, PesdePackageSource},
traits::{
DownloadOptions, GetTargetOptions, PackageSource as _, RefreshOptions, ResolveOptions,
},
traits::{DownloadOptions, PackageSource as _, RefreshOptions, ResolveOptions},
PackageSources,
},
Project, RefreshedSources, DEFAULT_INDEX_NAME,
@ -79,6 +77,7 @@ impl ExecuteCommand {
None => read_config().await.ok().map(|c| c.default_index),
}
.context("no index specified")?;
let source = PesdePackageSource::new(index);
refreshed_sources
.refresh(
@ -132,10 +131,24 @@ impl ExecuteCommand {
project.auth_config().clone(),
);
let id = Arc::new(PackageId::new(
PackageNames::Pesde(self.package.0.clone()),
v_id,
));
let name = self.package.0.clone();
let mut file = source
.read_index_file(&name, &project)
.await
.context("failed to read package index file")?
.context("package doesn't exist on the index")?;
let entry = file
.entries
.remove(&v_id)
.context("version id not present in index file")?;
let bin_path = entry
.target
.bin_path()
.context("package has no binary export")?;
let id = Arc::new(PackageId::new(PackageNames::Pesde(name), v_id));
let fs = source
.download(
@ -154,22 +167,6 @@ impl ExecuteCommand {
.await
.context("failed to write package contents")?;
let target = source
.get_target(
&pkg_ref,
&GetTargetOptions {
project: project.clone(),
path: tempdir.path().into(),
id: id.clone(),
// HACK: the pesde package source doesn't use the engines, so we can just use an empty map
engines: Default::default(),
},
)
.await
.context("failed to get target")?;
let bin_path = target.bin_path().context("package has no binary export")?;
let graph = project
.dependency_graph(None, refreshed_sources.clone(), true)
.await
@ -203,7 +200,7 @@ impl ExecuteCommand {
anyhow::Ok((
tempdir,
compatible_runtime(target.kind(), &engines)?,
compatible_runtime(entry.target.kind(), &engines)?,
bin_path.to_relative_path_buf(),
))
},

View file

@ -8,19 +8,18 @@ use inquire::validator::Validation;
use pesde::{
errors::ManifestReadError,
manifest::{target::TargetKind, DependencyType},
names::{PackageName, PackageNames},
names::PackageName,
source::{
git_index::GitBasedSource as _,
ids::PackageId,
pesde::{specifier::PesdeDependencySpecifier, PesdePackageSource},
specifiers::DependencySpecifiers,
traits::{GetTargetOptions, PackageSource as _, RefreshOptions, ResolveOptions},
traits::{PackageSource as _, RefreshOptions, ResolveOptions},
PackageSources,
},
Project, RefreshedSources, DEFAULT_INDEX_NAME, SCRIPTS_LINK_FOLDER,
};
use semver::VersionReq;
use std::{fmt::Display, path::Path, str::FromStr as _, sync::Arc};
use std::{fmt::Display, str::FromStr as _};
#[derive(Debug, Args)]
pub struct InitCommand;