Skip to content

Commit

Permalink
refactor: upgrade to deno_lockfile 0.23 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Aug 28, 2024
1 parent 569ee26 commit 3a32441
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ license = "MIT"
[dependencies]
anyhow = "1.0.70"
async-trait = "0.1.68"
deno_semver = "0.5.10"
deno_lockfile = "0.22.0"
deno_semver = "0.5.11"
deno_lockfile = "0.23.0"
monch = "0.5.0"
log = "0.4"
serde = { version = "1.0.130", features = ["derive", "rc"] }
Expand Down
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,26 @@ impl NpmPackageId {
self.as_serialized_with_level(0)
}

pub fn peer_deps_serialized(&self) -> String {
self.peer_serialized_with_level(0)
}

fn as_serialized_with_level(&self, level: usize) -> String {
// WARNING: This should not change because it's used in the lockfile
let mut result = format!(
"{}@{}",
format!(
"{}@{}{}",
if level == 0 {
Cow::Borrowed(&self.nv.name)
} else {
Cow::Owned(self.nv.name.replace('/', "+"))
},
self.nv.version
);
self.nv.version,
self.peer_serialized_with_level(level)
)
}

fn peer_serialized_with_level(&self, level: usize) -> String {
let mut result = String::new();
for peer in &self.peer_dependencies {
// unfortunately we can't do something like `_3` when
// this gets deep because npm package names can start
Expand Down
2 changes: 1 addition & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl NpmPackageInfo {

#[derive(Debug, Clone, Error)]
#[error(
"Error in {parent_nv} parsing version requirement for dependency: {key}@{version_req}\n\n{source:#}"
"Error in {parent_nv} parsing version requirement for dependency: {key}@{version_req}"
)]
pub struct NpmDependencyEntryError {
/// Name and version of the package that has this dependency.
Expand Down
33 changes: 12 additions & 21 deletions src/resolution/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::sync::Arc;
use deno_lockfile::Lockfile;
use deno_semver::package::PackageNv;
use deno_semver::package::PackageReq;
use deno_semver::package::PackageReqParseError;
use deno_semver::VersionReq;
use futures::stream::FuturesOrdered;
use futures::StreamExt;
Expand Down Expand Up @@ -781,12 +780,6 @@ fn name_without_path(name: &str) -> &str {

#[derive(Debug, Error)]
pub enum IncompleteSnapshotFromLockfileError {
#[error("Unable to parse npm specifier: {key}")]
ReqParse {
key: String,
#[source]
source: PackageReqParseError,
},
#[error(transparent)]
PackageIdDeserialization(#[from] NpmPackageIdDeserializationError),
}
Expand Down Expand Up @@ -819,17 +812,15 @@ pub fn incomplete_snapshot_from_lockfile(
);
// collect the specifiers to version mappings
for (key, value) in &lockfile.content.packages.specifiers {
if let Some(key) = key.strip_prefix("npm:") {
if let Some(value) = value.strip_prefix("npm:") {
let package_req = PackageReq::from_str(key).map_err(|e| {
IncompleteSnapshotFromLockfileError::ReqParse {
key: key.to_string(),
source: e,
}
})?;
let package_id = NpmPackageId::from_serialized(value)?;
root_packages.insert(package_req, package_id.clone());
match key.kind {
deno_semver::package::PackageKind::Npm => {
let package_id = NpmPackageId::from_serialized(&format!(
"{}@{}",
key.req.name, value
))?;
root_packages.insert(key.req.clone(), package_id);
}
deno_semver::package::PackageKind::Jsr => {}
}
}

Expand Down Expand Up @@ -1371,7 +1362,7 @@ mod tests {
}

#[tokio::test]
async fn test_snapshot_from_lockfile_v3() {
async fn test_snapshot_from_lockfile_v4() {
let api = TestNpmRegistryApi::default();
api.ensure_package_version_with_integrity(
"chalk",
Expand All @@ -1389,9 +1380,9 @@ mod tests {
content: r#"{
"version": "4",
"specifiers": {
"npm:chalk@5": "npm:chalk@5.3.0",
"npm:emoji-regex": "npm:emoji-regex@10.2.1",
"deno:path": "deno:@std/path@1.0.0"
"npm:chalk@5": "5.3.0",
"npm:emoji-regex": "10.2.1",
"jsr:@std/path": "1.0.0"
},
"npm": {
"chalk@5.3.0": {
Expand Down

0 comments on commit 3a32441

Please sign in to comment.