2024-03-27 19:56:19 +00:00
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
2024-03-04 20:18:49 +00:00
|
|
|
|
|
|
|
use semver::Version;
|
|
|
|
use tempfile::tempdir;
|
|
|
|
|
|
|
|
use pesde::{
|
|
|
|
dependencies::{
|
|
|
|
registry::{RegistryDependencySpecifier, RegistryPackageRef},
|
|
|
|
resolution::ResolvedPackage,
|
|
|
|
DependencySpecifier, PackageRef,
|
|
|
|
},
|
2024-03-24 13:31:11 +00:00
|
|
|
index::Index,
|
2024-03-04 20:18:49 +00:00
|
|
|
manifest::{DependencyType, Manifest, Realm},
|
2024-03-24 13:31:11 +00:00
|
|
|
package_name::StandardPackageName,
|
|
|
|
project::{Project, DEFAULT_INDEX_NAME},
|
2024-03-04 20:18:49 +00:00
|
|
|
};
|
|
|
|
use prelude::*;
|
|
|
|
|
|
|
|
mod prelude;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_resolves_package() {
|
|
|
|
let dir = tempdir().unwrap();
|
|
|
|
let dir_path = dir.path().to_path_buf();
|
|
|
|
let index = InMemoryIndex::new();
|
|
|
|
|
|
|
|
let version_str = "0.1.0";
|
|
|
|
let version: Version = version_str.parse().unwrap();
|
|
|
|
let version_2_str = "0.1.1";
|
|
|
|
let version_2: Version = version_2_str.parse().unwrap();
|
|
|
|
|
|
|
|
let description = "test package";
|
|
|
|
|
2024-03-24 13:31:11 +00:00
|
|
|
let pkg_name = StandardPackageName::new("test", "test").unwrap();
|
2024-03-04 20:18:49 +00:00
|
|
|
|
|
|
|
let pkg_manifest = Manifest {
|
|
|
|
name: pkg_name.clone(),
|
|
|
|
version: version.clone(),
|
|
|
|
exports: Default::default(),
|
|
|
|
path_style: Default::default(),
|
|
|
|
private: true,
|
|
|
|
realm: None,
|
2024-03-24 13:31:11 +00:00
|
|
|
indices: Default::default(),
|
2024-03-24 17:48:26 +00:00
|
|
|
#[cfg(feature = "wally")]
|
2024-03-24 17:38:18 +00:00
|
|
|
sourcemap_generator: None,
|
2024-03-26 22:39:58 +00:00
|
|
|
overrides: Default::default(),
|
2024-03-24 17:38:18 +00:00
|
|
|
|
2024-03-27 19:56:19 +00:00
|
|
|
dependencies: Default::default(),
|
|
|
|
peer_dependencies: Default::default(),
|
2024-03-04 20:18:49 +00:00
|
|
|
description: Some(description.to_string()),
|
|
|
|
license: None,
|
|
|
|
authors: None,
|
2024-03-16 16:31:27 +00:00
|
|
|
repository: None,
|
2024-03-04 20:18:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut pkg_2_manifest = pkg_manifest.clone();
|
|
|
|
pkg_2_manifest.version = version_2.clone();
|
|
|
|
|
|
|
|
let index = index
|
|
|
|
.with_scope(pkg_name.scope(), BTreeSet::from([0]))
|
2024-03-24 13:31:11 +00:00
|
|
|
.with_package(pkg_name.scope(), pkg_manifest.try_into().unwrap())
|
|
|
|
.with_package(pkg_name.scope(), pkg_2_manifest.try_into().unwrap());
|
2024-03-04 20:18:49 +00:00
|
|
|
|
|
|
|
let specifier = DependencySpecifier::Registry(RegistryDependencySpecifier {
|
|
|
|
name: pkg_name.clone(),
|
|
|
|
version: format!("={version_str}").parse().unwrap(),
|
|
|
|
realm: None,
|
2024-03-24 13:31:11 +00:00
|
|
|
index: DEFAULT_INDEX_NAME.to_string(),
|
2024-03-04 20:18:49 +00:00
|
|
|
});
|
|
|
|
let specifier_2 = DependencySpecifier::Registry(RegistryDependencySpecifier {
|
|
|
|
name: pkg_name.clone(),
|
|
|
|
version: format!(">{version_str}").parse().unwrap(),
|
|
|
|
realm: None,
|
2024-03-24 13:31:11 +00:00
|
|
|
index: DEFAULT_INDEX_NAME.to_string(),
|
2024-03-04 20:18:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let user_manifest = Manifest {
|
|
|
|
name: "test/user".parse().unwrap(),
|
|
|
|
version: version.clone(),
|
|
|
|
exports: Default::default(),
|
|
|
|
path_style: Default::default(),
|
|
|
|
private: true,
|
|
|
|
realm: None,
|
2024-03-24 13:31:11 +00:00
|
|
|
indices: Default::default(),
|
2024-03-24 17:48:26 +00:00
|
|
|
#[cfg(feature = "wally")]
|
2024-03-24 17:38:18 +00:00
|
|
|
sourcemap_generator: None,
|
2024-03-26 22:39:58 +00:00
|
|
|
overrides: Default::default(),
|
2024-03-24 17:38:18 +00:00
|
|
|
|
2024-03-27 19:56:19 +00:00
|
|
|
dependencies: BTreeMap::from([("test".to_string(), specifier.clone())]),
|
|
|
|
peer_dependencies: BTreeMap::from([("test2".to_string(), specifier_2.clone())]),
|
2024-03-04 20:18:49 +00:00
|
|
|
description: Some(description.to_string()),
|
|
|
|
license: None,
|
|
|
|
authors: None,
|
2024-03-16 16:31:27 +00:00
|
|
|
repository: None,
|
2024-03-04 20:18:49 +00:00
|
|
|
};
|
|
|
|
|
2024-03-24 13:31:11 +00:00
|
|
|
let mut project = Project::new(
|
|
|
|
&dir_path,
|
|
|
|
&dir_path,
|
|
|
|
HashMap::from([(
|
|
|
|
DEFAULT_INDEX_NAME.to_string(),
|
|
|
|
Box::new(index.clone()) as Box<dyn Index>,
|
|
|
|
)]),
|
|
|
|
user_manifest,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-04 20:18:49 +00:00
|
|
|
|
2024-03-24 13:31:11 +00:00
|
|
|
let manifest = project.manifest().clone();
|
2024-03-25 16:29:31 +00:00
|
|
|
let graph = manifest.dependency_graph(&mut project, false).unwrap();
|
|
|
|
assert_eq!(graph.children.len(), 1);
|
|
|
|
let versions = graph.children.get(&pkg_name.clone().into()).unwrap();
|
2024-03-04 20:18:49 +00:00
|
|
|
assert_eq!(versions.len(), 2);
|
|
|
|
let resolved_pkg = versions.get(&version).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
resolved_pkg,
|
|
|
|
&ResolvedPackage {
|
|
|
|
pkg_ref: PackageRef::Registry(RegistryPackageRef {
|
|
|
|
name: pkg_name.clone(),
|
|
|
|
version: version.clone(),
|
2024-03-24 13:31:11 +00:00
|
|
|
index_url: index.url().clone(),
|
2024-03-04 20:18:49 +00:00
|
|
|
}),
|
|
|
|
dependencies: Default::default(),
|
|
|
|
realm: Realm::Shared,
|
|
|
|
dep_type: DependencyType::Normal,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
let resolved_pkg_2 = versions.get(&version_2).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
resolved_pkg_2,
|
|
|
|
&ResolvedPackage {
|
|
|
|
pkg_ref: PackageRef::Registry(RegistryPackageRef {
|
|
|
|
name: pkg_name.clone(),
|
|
|
|
version: version_2.clone(),
|
2024-03-24 13:31:11 +00:00
|
|
|
index_url: index.url().clone(),
|
2024-03-04 20:18:49 +00:00
|
|
|
}),
|
|
|
|
dependencies: Default::default(),
|
|
|
|
realm: Realm::Shared,
|
|
|
|
dep_type: DependencyType::Normal,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|