From 77b2d2fd0a00ba09a3d4db60531b35b4f7f9ee48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 23 Apr 2024 18:42:55 +0100 Subject: [PATCH] feat: add NpmResolutionPackage.bin (#44) --- src/lib.rs | 3 +++ src/resolution/graph.rs | 1 + src/resolution/snapshot.rs | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 106e9c9..ca77ea3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ use std::collections::HashSet; use deno_semver::package::PackageNv; use deno_semver::Version; +use registry::NpmPackageVersionBinEntry; use registry::NpmPackageVersionDistInfo; use resolution::SerializedNpmResolutionSnapshotPackage; use serde::Deserialize; @@ -243,6 +244,7 @@ pub struct NpmResolutionPackage { /// which could be different from the package name. pub dependencies: HashMap, pub optional_dependencies: HashSet, + pub bin: Option, } impl std::fmt::Debug for NpmResolutionPackage { @@ -274,6 +276,7 @@ impl NpmResolutionPackage { dist: self.dist.clone(), dependencies: self.dependencies.clone(), optional_dependencies: self.optional_dependencies.clone(), + bin: self.bin.clone(), } } diff --git a/src/resolution/graph.rs b/src/resolution/graph.rs index b627f99..91281c3 100644 --- a/src/resolution/graph.rs +++ b/src/resolution/graph.rs @@ -675,6 +675,7 @@ impl Graph { .keys() .cloned() .collect(), + bin: version_info.bin.clone(), }, ); } diff --git a/src/resolution/snapshot.rs b/src/resolution/snapshot.rs index 08a7664..2d7041f 100644 --- a/src/resolution/snapshot.rs +++ b/src/resolution/snapshot.rs @@ -30,6 +30,7 @@ use super::NpmPackageVersionNotFound; use super::NpmPackageVersionResolutionError; use crate::registry::NpmPackageInfo; +use crate::registry::NpmPackageVersionBinEntry; use crate::registry::NpmPackageVersionDistInfo; use crate::registry::NpmRegistryApi; use crate::registry::NpmRegistryPackageInfoLoadError; @@ -113,6 +114,7 @@ pub struct SerializedNpmResolutionSnapshotPackage { /// which could be different from the package name. pub dependencies: HashMap, pub optional_dependencies: HashSet, + pub bin: Option, } #[derive(Default, Clone, Serialize, Deserialize, PartialEq, Eq)] @@ -236,6 +238,7 @@ impl NpmResolutionSnapshot { dist: package.dist, dependencies: package.dependencies, optional_dependencies: package.optional_dependencies, + bin: package.bin, }, ); } @@ -294,6 +297,7 @@ impl NpmResolutionSnapshot { // the fields below are stripped from the output system: Default::default(), optional_dependencies: Default::default(), + bin: None, }; for (key, dep_id) in &pkg.dependencies { let dep = self.packages.get(dep_id).unwrap(); @@ -973,6 +977,7 @@ pub async fn snapshot_from_lockfile<'a>( .optional_dependencies .into_keys() .collect(), + bin: version_info.bin.clone(), }); } Err(err) => { @@ -1073,6 +1078,7 @@ mod tests { system: Default::default(), dist: Default::default(), optional_dependencies: HashSet::from(["c".to_string()]), + bin: None, }, SerializedNpmResolutionSnapshotPackage { id: NpmPackageId::from_serialized("b@1.0.0").unwrap(), @@ -1080,6 +1086,7 @@ mod tests { system: Default::default(), dist: Default::default(), optional_dependencies: Default::default(), + bin: None, }, SerializedNpmResolutionSnapshotPackage { id: NpmPackageId::from_serialized("c@1.0.0").unwrap(), @@ -1090,6 +1097,7 @@ mod tests { }, dist: Default::default(), optional_dependencies: Default::default(), + bin: None, }, SerializedNpmResolutionSnapshotPackage { id: NpmPackageId::from_serialized("d@1.0.0").unwrap(), @@ -1097,6 +1105,7 @@ mod tests { system: Default::default(), dist: Default::default(), optional_dependencies: Default::default(), + bin: None, }, ], } @@ -1207,6 +1216,7 @@ mod tests { system: Default::default(), dist: Default::default(), optional_dependencies: Default::default(), + bin: None, } }