2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-11-08 14:17:24 -05:00
|
|
|
|
2023-02-21 15:19:09 -05:00
|
|
|
use std::collections::BTreeMap;
|
2022-11-08 14:17:24 -05:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashSet;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use deno_core::anyhow::anyhow;
|
|
|
|
use deno_core::anyhow::bail;
|
|
|
|
use deno_core::anyhow::Context;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::parking_lot::Mutex;
|
2023-02-21 12:03:48 -05:00
|
|
|
use deno_graph::npm::NpmPackageNv;
|
2023-02-15 13:20:40 -05:00
|
|
|
use deno_graph::npm::NpmPackageReq;
|
|
|
|
use deno_graph::semver::VersionReq;
|
2022-11-08 14:17:24 -05:00
|
|
|
use serde::Deserialize;
|
|
|
|
use serde::Serialize;
|
|
|
|
|
2022-11-25 17:00:28 -05:00
|
|
|
use crate::args::Lockfile;
|
2022-11-08 14:17:24 -05:00
|
|
|
use crate::npm::cache::NpmPackageCacheFolderId;
|
|
|
|
use crate::npm::registry::NpmPackageVersionDistInfo;
|
|
|
|
use crate::npm::registry::NpmRegistryApi;
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
use super::NpmPackageId;
|
2022-11-08 14:17:24 -05:00
|
|
|
use super::NpmResolutionPackage;
|
|
|
|
|
|
|
|
/// Packages partitioned by if they are "copy" packages or not.
|
|
|
|
pub struct NpmPackagesPartitioned {
|
|
|
|
pub packages: Vec<NpmResolutionPackage>,
|
|
|
|
/// Since peer dependency resolution occurs based on ancestors and ancestor
|
|
|
|
/// siblings, this may sometimes cause the same package (name and version)
|
|
|
|
/// to have different dependencies based on where it appears in the tree.
|
|
|
|
/// For these packages, we create a "copy package" or duplicate of the package
|
|
|
|
/// whose dependencies are that of where in the tree they've resolved to.
|
|
|
|
pub copy_packages: Vec<NpmResolutionPackage>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NpmPackagesPartitioned {
|
|
|
|
pub fn into_all(self) -> Vec<NpmResolutionPackage> {
|
|
|
|
let mut packages = self.packages;
|
|
|
|
packages.extend(self.copy_packages);
|
|
|
|
packages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 15:19:09 -05:00
|
|
|
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
2022-11-08 14:17:24 -05:00
|
|
|
pub struct NpmResolutionSnapshot {
|
2023-02-21 12:03:48 -05:00
|
|
|
/// The unique package requirements map to a single npm package name and version.
|
2022-11-08 14:17:24 -05:00
|
|
|
#[serde(with = "map_to_vec")]
|
2023-02-21 12:03:48 -05:00
|
|
|
pub(super) package_reqs: HashMap<NpmPackageReq, NpmPackageNv>,
|
|
|
|
// Each root level npm package name and version maps to an exact npm package node id.
|
2022-11-08 14:17:24 -05:00
|
|
|
#[serde(with = "map_to_vec")]
|
2023-02-21 12:03:48 -05:00
|
|
|
pub(super) root_packages: HashMap<NpmPackageNv, NpmPackageId>,
|
|
|
|
pub(super) packages_by_name: HashMap<String, Vec<NpmPackageId>>,
|
|
|
|
#[serde(with = "map_to_vec")]
|
|
|
|
pub(super) packages: HashMap<NpmPackageId, NpmResolutionPackage>,
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
|
2023-02-21 15:19:09 -05:00
|
|
|
impl std::fmt::Debug for NpmResolutionSnapshot {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
// do a custom debug implementation that creates deterministic output for the tests
|
|
|
|
f.debug_struct("NpmResolutionSnapshot")
|
|
|
|
.field(
|
|
|
|
"package_reqs",
|
|
|
|
&self.package_reqs.iter().collect::<BTreeMap<_, _>>(),
|
|
|
|
)
|
|
|
|
.field(
|
|
|
|
"root_packages",
|
|
|
|
&self.root_packages.iter().collect::<BTreeMap<_, _>>(),
|
|
|
|
)
|
|
|
|
.field(
|
|
|
|
"packages_by_name",
|
|
|
|
&self.packages_by_name.iter().collect::<BTreeMap<_, _>>(),
|
|
|
|
)
|
|
|
|
.field(
|
|
|
|
"packages",
|
|
|
|
&self.packages.iter().collect::<BTreeMap<_, _>>(),
|
|
|
|
)
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 14:17:24 -05:00
|
|
|
// This is done so the maps with non-string keys get serialized and deserialized as vectors.
|
|
|
|
// Adapted from: https://github.com/serde-rs/serde/issues/936#issuecomment-302281792
|
|
|
|
mod map_to_vec {
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use serde::de::Deserialize;
|
|
|
|
use serde::de::Deserializer;
|
|
|
|
use serde::ser::Serializer;
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
pub fn serialize<S, K: Serialize, V: Serialize>(
|
|
|
|
map: &HashMap<K, V>,
|
|
|
|
serializer: S,
|
|
|
|
) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
serializer.collect_seq(map.iter())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deserialize<
|
|
|
|
'de,
|
|
|
|
D,
|
|
|
|
K: Deserialize<'de> + Eq + std::hash::Hash,
|
|
|
|
V: Deserialize<'de>,
|
|
|
|
>(
|
|
|
|
deserializer: D,
|
|
|
|
) -> Result<HashMap<K, V>, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
{
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
for (key, value) in Vec::<(K, V)>::deserialize(deserializer)? {
|
|
|
|
map.insert(key, value);
|
|
|
|
}
|
|
|
|
Ok(map)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NpmResolutionSnapshot {
|
|
|
|
/// Resolve a node package from a deno module.
|
|
|
|
pub fn resolve_package_from_deno_module(
|
|
|
|
&self,
|
|
|
|
req: &NpmPackageReq,
|
|
|
|
) -> Result<&NpmResolutionPackage, AnyError> {
|
2023-02-21 12:03:48 -05:00
|
|
|
match self
|
|
|
|
.package_reqs
|
|
|
|
.get(req)
|
|
|
|
.and_then(|nv| self.root_packages.get(nv))
|
|
|
|
.and_then(|id| self.packages.get(id))
|
|
|
|
{
|
|
|
|
Some(id) => Ok(id),
|
2022-11-08 14:17:24 -05:00
|
|
|
None => bail!("could not find npm package directory for '{}'", req),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
pub fn top_level_packages(&self) -> Vec<NpmPackageId> {
|
|
|
|
self.root_packages.values().cloned().collect::<Vec<_>>()
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn package_from_id(
|
|
|
|
&self,
|
2023-02-21 12:03:48 -05:00
|
|
|
id: &NpmPackageId,
|
2022-11-08 14:17:24 -05:00
|
|
|
) -> Option<&NpmResolutionPackage> {
|
|
|
|
self.packages.get(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn resolve_package_from_package(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
referrer: &NpmPackageCacheFolderId,
|
|
|
|
) -> Result<&NpmResolutionPackage, AnyError> {
|
|
|
|
// todo(dsherret): do we need an additional hashmap to get this quickly?
|
|
|
|
let referrer_package = self
|
|
|
|
.packages_by_name
|
2023-02-21 12:03:48 -05:00
|
|
|
.get(&referrer.nv.name)
|
2022-11-08 14:17:24 -05:00
|
|
|
.and_then(|packages| {
|
|
|
|
packages
|
|
|
|
.iter()
|
2023-02-21 12:03:48 -05:00
|
|
|
.filter(|p| p.nv.version == referrer.nv.version)
|
|
|
|
.filter_map(|node_id| {
|
|
|
|
let package = self.packages.get(node_id)?;
|
2022-11-08 14:17:24 -05:00
|
|
|
if package.copy_index == referrer.copy_index {
|
|
|
|
Some(package)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.next()
|
|
|
|
})
|
|
|
|
.ok_or_else(|| {
|
|
|
|
anyhow!("could not find referrer npm package '{}'", referrer)
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let name = name_without_path(name);
|
|
|
|
if let Some(id) = referrer_package.dependencies.get(name) {
|
|
|
|
return Ok(self.packages.get(id).unwrap());
|
|
|
|
}
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
if referrer_package.pkg_id.nv.name == name {
|
2022-11-08 14:17:24 -05:00
|
|
|
return Ok(referrer_package);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(bartlomieju): this should use a reverse lookup table in the
|
|
|
|
// snapshot instead of resolving best version again.
|
2023-01-31 21:27:40 -05:00
|
|
|
let any_version_req = VersionReq::parse_from_npm("*").unwrap();
|
|
|
|
if let Some(id) = self.resolve_best_package_id(name, &any_version_req) {
|
2022-11-08 14:17:24 -05:00
|
|
|
if let Some(pkg) = self.packages.get(&id) {
|
|
|
|
return Ok(pkg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bail!(
|
|
|
|
"could not find npm package '{}' referenced by '{}'",
|
|
|
|
name,
|
|
|
|
referrer
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all_packages(&self) -> Vec<NpmResolutionPackage> {
|
|
|
|
self.packages.values().cloned().collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all_packages_partitioned(&self) -> NpmPackagesPartitioned {
|
|
|
|
let mut packages = self.all_packages();
|
|
|
|
let mut copy_packages = Vec::with_capacity(packages.len() / 2); // at most 1 copy for every package
|
|
|
|
|
|
|
|
// partition out any packages that are "copy" packages
|
|
|
|
for i in (0..packages.len()).rev() {
|
|
|
|
if packages[i].copy_index > 0 {
|
|
|
|
copy_packages.push(packages.swap_remove(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NpmPackagesPartitioned {
|
|
|
|
packages,
|
|
|
|
copy_packages,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn resolve_best_package_id(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
2023-01-31 21:27:40 -05:00
|
|
|
version_req: &VersionReq,
|
2023-02-21 12:03:48 -05:00
|
|
|
) -> Option<NpmPackageId> {
|
2022-11-08 14:17:24 -05:00
|
|
|
// todo(dsherret): this is not exactly correct because some ids
|
|
|
|
// will be better than others due to peer dependencies
|
2023-02-21 12:03:48 -05:00
|
|
|
let mut maybe_best_id: Option<&NpmPackageId> = None;
|
|
|
|
if let Some(node_ids) = self.packages_by_name.get(name) {
|
|
|
|
for node_id in node_ids.iter() {
|
|
|
|
if version_req.matches(&node_id.nv.version) {
|
2022-11-08 14:17:24 -05:00
|
|
|
let is_best_version = maybe_best_id
|
|
|
|
.as_ref()
|
2023-02-21 12:03:48 -05:00
|
|
|
.map(|best_id| best_id.nv.version.cmp(&node_id.nv.version).is_lt())
|
2022-11-08 14:17:24 -05:00
|
|
|
.unwrap_or(true);
|
|
|
|
if is_best_version {
|
2023-02-21 12:03:48 -05:00
|
|
|
maybe_best_id = Some(node_id);
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maybe_best_id.cloned()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn from_lockfile(
|
|
|
|
lockfile: Arc<Mutex<Lockfile>>,
|
2023-02-21 12:03:48 -05:00
|
|
|
api: &NpmRegistryApi,
|
2022-11-08 14:17:24 -05:00
|
|
|
) -> Result<Self, AnyError> {
|
2023-02-21 12:03:48 -05:00
|
|
|
let mut package_reqs: HashMap<NpmPackageReq, NpmPackageNv>;
|
|
|
|
let mut root_packages: HashMap<NpmPackageNv, NpmPackageId>;
|
|
|
|
let mut packages_by_name: HashMap<String, Vec<NpmPackageId>>;
|
|
|
|
let mut packages: HashMap<NpmPackageId, NpmResolutionPackage>;
|
2022-11-08 14:17:24 -05:00
|
|
|
let mut copy_index_resolver: SnapshotPackageCopyIndexResolver;
|
|
|
|
|
|
|
|
{
|
|
|
|
let lockfile = lockfile.lock();
|
|
|
|
|
|
|
|
// pre-allocate collections
|
|
|
|
package_reqs =
|
|
|
|
HashMap::with_capacity(lockfile.content.npm.specifiers.len());
|
2023-02-21 12:03:48 -05:00
|
|
|
root_packages =
|
|
|
|
HashMap::with_capacity(lockfile.content.npm.specifiers.len());
|
2022-11-08 14:17:24 -05:00
|
|
|
let packages_len = lockfile.content.npm.packages.len();
|
|
|
|
packages = HashMap::with_capacity(packages_len);
|
|
|
|
packages_by_name = HashMap::with_capacity(packages_len); // close enough
|
|
|
|
copy_index_resolver =
|
|
|
|
SnapshotPackageCopyIndexResolver::with_capacity(packages_len);
|
|
|
|
let mut verify_ids = HashSet::with_capacity(packages_len);
|
|
|
|
|
|
|
|
// collect the specifiers to version mappings
|
|
|
|
for (key, value) in &lockfile.content.npm.specifiers {
|
|
|
|
let package_req = NpmPackageReq::from_str(key)
|
2023-01-27 10:43:16 -05:00
|
|
|
.with_context(|| format!("Unable to parse npm specifier: {key}"))?;
|
2023-02-21 12:03:48 -05:00
|
|
|
let package_id = NpmPackageId::from_serialized(value)?;
|
|
|
|
package_reqs.insert(package_req, package_id.nv.clone());
|
|
|
|
root_packages.insert(package_id.nv.clone(), package_id.clone());
|
2022-11-08 14:17:24 -05:00
|
|
|
verify_ids.insert(package_id.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
// then the packages
|
|
|
|
for (key, value) in &lockfile.content.npm.packages {
|
2023-02-21 12:03:48 -05:00
|
|
|
let package_id = NpmPackageId::from_serialized(key)?;
|
2022-11-08 14:17:24 -05:00
|
|
|
|
|
|
|
// collect the dependencies
|
|
|
|
let mut dependencies = HashMap::default();
|
|
|
|
|
|
|
|
packages_by_name
|
2023-02-21 12:03:48 -05:00
|
|
|
.entry(package_id.nv.name.to_string())
|
2022-11-08 14:17:24 -05:00
|
|
|
.or_default()
|
|
|
|
.push(package_id.clone());
|
|
|
|
|
|
|
|
for (name, specifier) in &value.dependencies {
|
2023-02-21 12:03:48 -05:00
|
|
|
let dep_id = NpmPackageId::from_serialized(specifier)?;
|
2022-11-08 14:17:24 -05:00
|
|
|
dependencies.insert(name.to_string(), dep_id.clone());
|
|
|
|
verify_ids.insert(dep_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
let package = NpmResolutionPackage {
|
2023-02-21 12:03:48 -05:00
|
|
|
pkg_id: package_id.clone(),
|
2022-11-08 14:17:24 -05:00
|
|
|
copy_index: copy_index_resolver.resolve(&package_id),
|
|
|
|
// temporary dummy value
|
2023-01-06 11:36:12 -05:00
|
|
|
dist: NpmPackageVersionDistInfo::default(),
|
2022-11-08 14:17:24 -05:00
|
|
|
dependencies,
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.insert(package_id, package);
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify that all these ids exist in packages
|
|
|
|
for id in &verify_ids {
|
|
|
|
if !packages.contains_key(id) {
|
|
|
|
bail!(
|
|
|
|
"the lockfile is corrupt. You can recreate it with --lock-write"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
api
|
|
|
|
.cache_in_parallel(packages_by_name.keys().cloned().collect())
|
|
|
|
.await?;
|
2022-11-08 14:17:24 -05:00
|
|
|
|
|
|
|
// ensure the dist is set for each package
|
|
|
|
for package in packages.values_mut() {
|
|
|
|
// this will read from the memory cache now
|
|
|
|
let version_info = match api
|
2023-02-21 12:03:48 -05:00
|
|
|
.package_version_info(&package.pkg_id.nv)
|
2022-11-08 14:17:24 -05:00
|
|
|
.await?
|
|
|
|
{
|
|
|
|
Some(version_info) => version_info,
|
|
|
|
None => {
|
2023-02-21 12:03:48 -05:00
|
|
|
bail!("could not find '{}' specified in the lockfile. Maybe try again with --reload", package.pkg_id.nv);
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
package.dist = version_info.dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
package_reqs,
|
2023-02-21 12:03:48 -05:00
|
|
|
root_packages,
|
2022-11-08 14:17:24 -05:00
|
|
|
packages_by_name,
|
|
|
|
packages,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SnapshotPackageCopyIndexResolver {
|
2023-02-21 12:03:48 -05:00
|
|
|
packages_to_copy_index: HashMap<NpmPackageId, usize>,
|
|
|
|
package_name_version_to_copy_count: HashMap<NpmPackageNv, usize>,
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SnapshotPackageCopyIndexResolver {
|
|
|
|
pub fn with_capacity(capacity: usize) -> Self {
|
|
|
|
Self {
|
|
|
|
packages_to_copy_index: HashMap::with_capacity(capacity),
|
|
|
|
package_name_version_to_copy_count: HashMap::with_capacity(capacity), // close enough
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_map_with_capacity(
|
2023-02-21 12:03:48 -05:00
|
|
|
mut packages_to_copy_index: HashMap<NpmPackageId, usize>,
|
2022-11-08 14:17:24 -05:00
|
|
|
capacity: usize,
|
|
|
|
) -> Self {
|
|
|
|
let mut package_name_version_to_copy_count =
|
|
|
|
HashMap::with_capacity(capacity); // close enough
|
|
|
|
if capacity > packages_to_copy_index.len() {
|
|
|
|
packages_to_copy_index.reserve(capacity - packages_to_copy_index.len());
|
|
|
|
}
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
for (node_id, index) in &packages_to_copy_index {
|
2022-11-08 14:17:24 -05:00
|
|
|
let entry = package_name_version_to_copy_count
|
2023-02-21 12:03:48 -05:00
|
|
|
.entry(node_id.nv.clone())
|
2022-11-08 14:17:24 -05:00
|
|
|
.or_insert(0);
|
|
|
|
if *entry < *index {
|
|
|
|
*entry = *index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Self {
|
|
|
|
packages_to_copy_index,
|
|
|
|
package_name_version_to_copy_count,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
pub fn resolve(&mut self, node_id: &NpmPackageId) -> usize {
|
|
|
|
if let Some(index) = self.packages_to_copy_index.get(node_id) {
|
2022-11-08 14:17:24 -05:00
|
|
|
*index
|
|
|
|
} else {
|
|
|
|
let index = *self
|
|
|
|
.package_name_version_to_copy_count
|
2023-02-21 12:03:48 -05:00
|
|
|
.entry(node_id.nv.clone())
|
2022-11-08 14:17:24 -05:00
|
|
|
.and_modify(|count| {
|
|
|
|
*count += 1;
|
|
|
|
})
|
|
|
|
.or_insert(0);
|
2023-02-21 12:03:48 -05:00
|
|
|
self.packages_to_copy_index.insert(node_id.clone(), index);
|
2022-11-08 14:17:24 -05:00
|
|
|
index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn name_without_path(name: &str) -> &str {
|
|
|
|
let mut search_start_index = 0;
|
|
|
|
if name.starts_with('@') {
|
|
|
|
if let Some(slash_index) = name.find('/') {
|
|
|
|
search_start_index = slash_index + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(slash_index) = &name[search_start_index..].find('/') {
|
|
|
|
// get the name up until the path slash
|
|
|
|
&name[0..search_start_index + slash_index]
|
|
|
|
} else {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_name_without_path() {
|
|
|
|
assert_eq!(name_without_path("foo"), "foo");
|
|
|
|
assert_eq!(name_without_path("@foo/bar"), "@foo/bar");
|
|
|
|
assert_eq!(name_without_path("@foo/bar/baz"), "@foo/bar");
|
|
|
|
assert_eq!(name_without_path("@hello"), "@hello");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_copy_index_resolver() {
|
|
|
|
let mut copy_index_resolver =
|
|
|
|
SnapshotPackageCopyIndexResolver::with_capacity(10);
|
|
|
|
assert_eq!(
|
|
|
|
copy_index_resolver
|
2023-02-21 12:03:48 -05:00
|
|
|
.resolve(&NpmPackageId::from_serialized("package@1.0.0").unwrap()),
|
2022-11-08 14:17:24 -05:00
|
|
|
0
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
copy_index_resolver
|
2023-02-21 12:03:48 -05:00
|
|
|
.resolve(&NpmPackageId::from_serialized("package@1.0.0").unwrap()),
|
2022-11-08 14:17:24 -05:00
|
|
|
0
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
copy_index_resolver.resolve(
|
2023-02-21 12:03:48 -05:00
|
|
|
&NpmPackageId::from_serialized("package@1.0.0_package-b@1.0.0")
|
2022-11-08 14:17:24 -05:00
|
|
|
.unwrap()
|
|
|
|
),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
copy_index_resolver.resolve(
|
2023-02-21 12:03:48 -05:00
|
|
|
&NpmPackageId::from_serialized(
|
2022-11-08 14:17:24 -05:00
|
|
|
"package@1.0.0_package-b@1.0.0__package-c@2.0.0"
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
),
|
|
|
|
2
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
copy_index_resolver.resolve(
|
2023-02-21 12:03:48 -05:00
|
|
|
&NpmPackageId::from_serialized("package@1.0.0_package-b@1.0.0")
|
2022-11-08 14:17:24 -05:00
|
|
|
.unwrap()
|
|
|
|
),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2023-02-21 12:03:48 -05:00
|
|
|
copy_index_resolver
|
|
|
|
.resolve(&NpmPackageId::from_serialized("package-b@1.0.0").unwrap()),
|
2022-11-08 14:17:24 -05:00
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|