Skip to content

Commit 4be097c

Browse files
ggreifclaude
andcommitted
fix(integrity): dedupe packageIds when counting resolved packages
`getResolvedMopsPackageIds()` produces one entry per dependency-table row, including alias rows like `base`, `base@0`, `base@0.16` all resolving to the same `base@0.16.0`. The subsequent length comparison against `Object.keys(lockFileJson.hashes).length` then fails — the hashes object is naturally deduplicated by its packageId keys, so the two counts diverge by the number of alias duplicates. Compare unique packageId counts via `Set` to match the lock file's semantics. Fixes #506 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 37bd049 commit 4be097c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

cli/integrity.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ export async function checkLockFile(force = false) {
267267
}
268268
}
269269

270-
// check number of packages
271-
if (Object.keys(lockFileJson.hashes).length !== packageIds.length) {
270+
// check number of packages — packageIds can contain duplicates when
271+
// multiple aliases (e.g. `base`, `base@0`, `base@0.16`) resolve to the
272+
// same package@version, while lockFileJson.hashes is keyed by packageId
273+
// and naturally deduplicated. Compare unique counts to avoid a spurious
274+
// mismatch.
275+
let uniquePackageIdCount = new Set(packageIds).size;
276+
if (Object.keys(lockFileJson.hashes).length !== uniquePackageIdCount) {
272277
console.error("Integrity check failed");
273278
console.error(
274-
`Mismatched number of resolved packages: ${JSON.stringify(Object.keys(lockFileJson.hashes).length)} vs ${JSON.stringify(packageIds.length)}`,
279+
`Mismatched number of resolved packages: ${JSON.stringify(Object.keys(lockFileJson.hashes).length)} vs ${JSON.stringify(uniquePackageIdCount)}`,
275280
);
276281
process.exit(1);
277282
}

0 commit comments

Comments
 (0)