Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Mops CLI Changelog

## Next
- Fix `mops install` (and any `--lock check` flow) failing with "Mismatched number of resolved packages" when a project's resolved dependencies include multiple aliases (e.g. `base`, `base@0`, `base@0.16`) that pin to the same `name@version`

## 2.12.1
- `mops check`/`build`/`check-stable` skip migration staging when only the pending `next` migration is needed, so `moc` diagnostics reference the real `next-migration/<file>` path.
Expand Down
3 changes: 2 additions & 1 deletion cli/integrity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ async function getResolvedMopsPackageIds(): Promise<string[]> {
let packageIds = Object.entries(resolvedPackages)
.filter(([_, version]) => getDependencyType(version) === "mops")
.map(([name, version]) => getPackageId(name, version));
return packageIds;
// dedupe: aliases like `base@0`, `base@0.16` collapse to the same packageId
return [...new Set(packageIds)];
}

// get hash of local file from '.mops' dir by fileId
Expand Down
21 changes: 21 additions & 0 deletions cli/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,25 @@ describe("install", () => {

// mops add/remove/update/sync are not separately tested here because they
// all route through the same checkIntegrity code path tested above.

// Regression: aliases pinning the same package@version (e.g. `core` and
// `core@1` both at "1.0.0") inflated the resolved-packageIds count and
// tripped the lockfile integrity check with a spurious
// "Mismatched number of resolved packages" error. See issue #506.
test("integrity check passes when aliases resolve to the same package@version", async () => {
const cwd = path.join(import.meta.dirname, "install/aliases");
const lockFile = path.join(cwd, "mops.lock");
rmSync(lockFile, { force: true });
try {
const result = await cli(["install"], { cwd, env: { CI: undefined } });
expect(result.stderr).not.toMatch(
/Mismatched number of resolved packages/,
);
expect(result.exitCode).toBe(0);
expect(existsSync(lockFile)).toBe(true);
} finally {
rmSync(lockFile, { force: true });
rmSync(path.join(cwd, ".mops"), { recursive: true, force: true });
}
});
});
3 changes: 3 additions & 0 deletions cli/tests/install/aliases/mops.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[dependencies]
core = "1.0.0"
"core@1" = "1.0.0"
Loading