fix: dont inherit workspace by path dependencies

This commit is contained in:
daimond113 2025-03-08 23:24:35 +01:00
parent 9ad691ee94
commit 41337ac96a
No known key found for this signature in database
GPG key ID: 640DC95EC1190354
2 changed files with 56 additions and 5 deletions

View file

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- Fix path dependencies using project's workspace dependencies by @daimond113
## [0.6.0] - 2025-02-22 ## [0.6.0] - 2025-02-22
### Added ### Added
- Improve installation experience by @lukadev-0 - Improve installation experience by @lukadev-0

View file

@ -1,18 +1,20 @@
use crate::{ use crate::{
deser_manifest, deser_manifest, find_roots,
manifest::target::Target, manifest::target::Target,
names::PackageNames, names::PackageNames,
reporters::DownloadProgressReporter, reporters::DownloadProgressReporter,
source::{ source::{
fs::PackageFs, fs::PackageFs,
ids::VersionId, ids::VersionId,
path::pkg_ref::PathPackageRef, path::{pkg_ref::PathPackageRef, specifier::PathDependencySpecifier},
specifiers::DependencySpecifiers, specifiers::DependencySpecifiers,
traits::{DownloadOptions, GetTargetOptions, PackageSource, ResolveOptions}, traits::{DownloadOptions, GetTargetOptions, PackageSource, ResolveOptions},
ResolveResult, ResolveResult,
}, },
Project,
}; };
use std::collections::BTreeMap; use futures::TryStreamExt as _;
use std::collections::{BTreeMap, HashMap};
use tracing::instrument; use tracing::instrument;
/// The path package reference /// The path package reference
@ -36,10 +38,29 @@ impl PackageSource for PathPackageSource {
async fn resolve( async fn resolve(
&self, &self,
specifier: &Self::Specifier, specifier: &Self::Specifier,
_options: &ResolveOptions, options: &ResolveOptions,
) -> Result<ResolveResult<Self::Ref>, Self::ResolveError> { ) -> Result<ResolveResult<Self::Ref>, Self::ResolveError> {
let ResolveOptions { project, .. } = options;
let manifest = deser_manifest(&specifier.path).await?; let manifest = deser_manifest(&specifier.path).await?;
let (path_package_dir, path_workspace_dir) = find_roots(specifier.path.clone()).await?;
let path_project = Project::new(
path_package_dir,
path_workspace_dir,
// these don't matter, we're not using any functionality which uses them
project.data_dir(),
project.cas_dir(),
project.auth_config().clone(),
);
let workspace_members = path_project
.workspace_members(true)
.await?
.map_ok(|(path, manifest)| ((manifest.name, manifest.target.kind()), path))
.try_collect::<HashMap<_, _>>()
.await?;
let pkg_ref = PathPackageRef { let pkg_ref = PathPackageRef {
path: specifier.path.clone(), path: specifier.path.clone(),
dependencies: manifest dependencies: manifest
@ -73,7 +94,20 @@ impl PackageSource for PathPackageSource {
.to_string(); .to_string();
} }
DependencySpecifiers::Git(_) => {} DependencySpecifiers::Git(_) => {}
DependencySpecifiers::Workspace(_) => {} DependencySpecifiers::Workspace(specifier) => {
let member = (
specifier.name.clone(),
specifier.target.unwrap_or(manifest.target.kind()),
);
spec = DependencySpecifiers::Path(PathDependencySpecifier {
path: workspace_members.get(&member).cloned().ok_or(
errors::ResolveError::WorkspacePackageNotFound(
member.0, member.1,
),
)?,
});
}
DependencySpecifiers::Path(_) => {} DependencySpecifiers::Path(_) => {}
} }
@ -122,6 +156,7 @@ impl PackageSource for PathPackageSource {
/// Errors that can occur when using a path package source /// Errors that can occur when using a path package source
pub mod errors { pub mod errors {
use crate::{manifest::target::TargetKind, names::PackageName};
use std::path::PathBuf; use std::path::PathBuf;
use thiserror::Error; use thiserror::Error;
@ -145,6 +180,18 @@ pub mod errors {
/// An index of the package was not found /// An index of the package was not found
#[error("index {0} not found in package {1}")] #[error("index {0} not found in package {1}")]
IndexNotFound(String, PathBuf), IndexNotFound(String, PathBuf),
/// Finding the package roots failed
#[error("failed to find package roots")]
FindRoots(#[from] crate::errors::FindRootsError),
/// Finding workspace members failed
#[error("failed to find workspace members")]
WorkspaceMembers(#[from] crate::errors::WorkspaceMembersError),
/// Workspace package not found
#[error("workspace package {0} {1} not found in package")]
WorkspacePackageNotFound(PackageName, TargetKind),
} }
/// Errors that can occur when downloading a path package /// Errors that can occur when downloading a path package