Skip to content

Commit

Permalink
fix: include all jsr deps in lockfile (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Feb 5, 2024
1 parent 12b73d5 commit 2b95dcd
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 31 deletions.
32 changes: 16 additions & 16 deletions src/graphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ impl LockfileNpmPackageId {
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
struct LockfilePkgReq(String);

#[derive(Debug)]
enum LockfileGraphPackage {
Jsr(LockfileJsrGraphPackage),
Npm(LockfileNpmGraphPackage),
}

#[derive(Debug)]
struct LockfileNpmGraphPackage {
/// Root ids that transitively reference this package.
root_ids: HashSet<LockfilePkgId>,
integrity: String,
dependencies: BTreeMap<String, LockfileNpmPackageId>,
}

#[derive(Default)]
#[derive(Debug, Default)]
struct LockfileJsrGraphPackage {
/// Root ids that transitively reference this package.
root_ids: HashSet<LockfilePkgId>,
Expand Down Expand Up @@ -286,21 +288,19 @@ impl<FNvToJsrUrl: Fn(&str) -> Option<String>>
for (id, package) in self.packages {
match package {
LockfileGraphPackage::Jsr(package) => {
if !package.dependencies.is_empty() {
packages.jsr.insert(
match id {
LockfilePkgId::Jsr(nv) => nv.0,
LockfilePkgId::Npm(_) => unreachable!(),
},
crate::JsrPackageInfo {
dependencies: package
.dependencies
.into_iter()
.map(|req| req.0)
.collect(),
},
);
}
packages.jsr.insert(
match id {
LockfilePkgId::Jsr(nv) => nv.0,
LockfilePkgId::Npm(_) => unreachable!(),
},
crate::JsrPackageInfo {
dependencies: package
.dependencies
.into_iter()
.map(|req| req.0)
.collect(),
},
);
}
LockfileGraphPackage::Npm(package) => {
packages.npm.insert(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub struct PackagesContent {

impl PackagesContent {
fn is_empty(&self) -> bool {
self.specifiers.is_empty() && self.npm.is_empty()
self.specifiers.is_empty() && self.npm.is_empty() && self.jsr.is_empty()
}
}

Expand Down
30 changes: 27 additions & 3 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ fn verify_packages_content(packages: &PackagesContent) {
for id in packages.specifiers.values() {
if let Some(npm_id) = id.strip_prefix("npm:") {
assert!(packages.npm.contains_key(npm_id), "Missing: {}", id);
} else if id.strip_prefix("jsr:").is_some() {
// ignore jsr packages because they won't be in the lockfile when they don't have dependencies
// todo(dsherret): actually include them here because we need to lock the manifest version
} else if let Some(jsr_id) = id.strip_prefix("jsr:") {
assert!(packages.jsr.contains_key(jsr_id), "Missing: {}", id);
} else {
panic!("Invalid package id: {}", id);
}
Expand All @@ -161,6 +160,31 @@ fn verify_packages_content(packages: &PackagesContent) {
);
}
}
for (pkg_id, package) in &packages.jsr {
for req in &package.dependencies {
let dep_id = match packages.specifiers.get(req) {
Some(dep_id) => dep_id,
None => panic!("Missing specifier for '{}' in '{}'", req, pkg_id),
};
if let Some(npm_id) = dep_id.strip_prefix("npm:") {
assert!(
packages.npm.contains_key(npm_id),
"Missing: '{}' dep in '{}'",
dep_id,
pkg_id,
);
} else if let Some(jsr_id) = dep_id.strip_prefix("jsr:") {
assert!(
packages.jsr.contains_key(jsr_id),
"Missing: '{}' dep in '{}'",
dep_id,
pkg_id,
);
} else {
panic!("Invalid package id: {}", dep_id);
}
}
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/config_changes/CircularJsrDep02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"specifiers": {
"jsr:@scope/package_a": "jsr:@scope/[email protected]",
"jsr:@scope/package_b": "jsr:@scope/[email protected]",
"jsr:@scope/package_c": "jsr:@scope/package_b@0.0.1"
"jsr:@scope/package_c": "jsr:@scope/package_c@0.0.1"
},
"jsr": {
"@scope/[email protected]": {
Expand Down
6 changes: 4 additions & 2 deletions tests/specs/config_changes/NoConfigMaintains.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down Expand Up @@ -225,7 +226,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down
6 changes: 4 additions & 2 deletions tests/specs/config_changes/NoConfigWorkspaceMaintains.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down Expand Up @@ -229,7 +230,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down
3 changes: 3 additions & 0 deletions tests/specs/config_changes/NoNpmMaintainsNpm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
"jsr:@scope/package_orphan": "jsr:@scope/[email protected]",
"npm:ts-morph": "npm:[email protected]"
},
"jsr": {
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
Expand Down
9 changes: 7 additions & 2 deletions tests/specs/config_changes/NoNpmWorkspaceMaintainsNpm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down Expand Up @@ -236,7 +237,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down Expand Up @@ -422,6 +424,9 @@
"specifiers": {
"jsr:@scope/package_orphan": "jsr:@scope/[email protected]"
},
"jsr": {
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
Expand Down
3 changes: 3 additions & 0 deletions tests/specs/config_changes/RemovedConfigRemoves.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@
"specifiers": {
"jsr:@scope/package_orphan": "jsr:@scope/[email protected]"
},
"jsr": {
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
Expand Down
3 changes: 3 additions & 0 deletions tests/specs/config_changes/RemovedDenoJsonRemoves.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@
"jsr:@scope/package_orphan": "jsr:@scope/[email protected]",
"npm:ts-morph": "npm:[email protected]"
},
"jsr": {
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
Expand Down
3 changes: 2 additions & 1 deletion tests/specs/config_changes/RemovedPackageJsonRemoves.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@
"dependencies": [
"jsr:@scope/package_a"
]
}
},
"@scope/[email protected]": {}
},
"npm": {
"@example/orphan": {
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/config_changes/RemovingOakThenDax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@
"jsr:@std/[email protected]"
]
},
"@dsherret/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {
"dependencies": [
"jsr:@std/assert@^0.210.0",
Expand All @@ -431,6 +435,8 @@
"jsr:@std/io@^0.210.0"
]
},
"@zome_unreferenced/[email protected]": {},
"@zome_unreferenced/[email protected]": {},
"jsr:@zome_unreferenced/[email protected]": {
"dependencies": [
"jsr:@zome_unreferenced/package_b"
Expand Down Expand Up @@ -653,6 +659,8 @@
"jsr:@zome_unreferenced/package_b": "jsr:@zome_unreferenced/[email protected]"
},
"jsr": {
"@zome_unreferenced/[email protected]": {},
"@zome_unreferenced/[email protected]": {},
"jsr:@zome_unreferenced/[email protected]": {
"dependencies": [
"jsr:@zome_unreferenced/package_b"
Expand Down
6 changes: 6 additions & 0 deletions tests/specs/config_changes/RemovingWorkspaceDep.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@
"jsr:@std/[email protected]"
]
},
"@dsherret/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {
"dependencies": [
"jsr:@std/assert@^0.210.0",
Expand All @@ -443,6 +447,8 @@
"jsr:@std/io@^0.210.0"
]
},
"@zome_unreferenced/[email protected]": {},
"@zome_unreferenced/[email protected]": {},
"jsr:@zome_unreferenced/[email protected]": {
"dependencies": [
"jsr:@zome_unreferenced/package_b"
Expand Down
6 changes: 6 additions & 0 deletions tests/specs/config_changes/RemovingWorkspaceMember.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@
"jsr:@std/[email protected]"
]
},
"@dsherret/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {},
"@std/[email protected]": {
"dependencies": [
"jsr:@std/assert@^0.210.0",
Expand All @@ -437,6 +441,8 @@
"jsr:@std/io@^0.210.0"
]
},
"@zome_unreferenced/[email protected]": {},
"@zome_unreferenced/[email protected]": {},
"jsr:@zome_unreferenced/[email protected]": {
"dependencies": [
"jsr:@zome_unreferenced/package_b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies": [
"jsr:@dsherret/[email protected]"
]
}
},
"@dsherret/[email protected]": {}
}
},
"remote": {
Expand Down Expand Up @@ -49,7 +50,8 @@
"dependencies": [
"jsr:@dsherret/[email protected]"
]
}
},
"@dsherret/[email protected]": {}
}
},
"remote": {
Expand Down Expand Up @@ -91,7 +93,8 @@
"dependencies": [
"jsr:@dsherret/[email protected]"
]
}
},
"@dsherret/[email protected]": {}
}
},
"remote": {
Expand Down

0 comments on commit 2b95dcd

Please sign in to comment.