|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { createRequire } from "node:module"; |
| 3 | +import path from "node:path"; |
| 4 | +import { fileURLToPath } from "node:url"; |
| 5 | +import { describe, expect, it } from "vitest"; |
| 6 | + |
| 7 | +const here = path.dirname(fileURLToPath(import.meta.url)); |
| 8 | +const root = path.resolve(here, "../../.."); |
| 9 | +const require = createRequire(path.join(here, "../package.json")); |
| 10 | + |
| 11 | +/** The catalog's flat `name: version` entries (pnpm-workspace.yaml). */ |
| 12 | +function catalog(): Record<string, string> { |
| 13 | + const out: Record<string, string> = {}; |
| 14 | + let inside = false; |
| 15 | + for (const line of readFileSync(path.join(root, "pnpm-workspace.yaml"), "utf8").split("\n")) { |
| 16 | + if (/^catalog:\s*$/.test(line)) inside = true; |
| 17 | + else if (inside && /^\S/.test(line)) break; |
| 18 | + else if (inside) { |
| 19 | + const m = line.match(/^\s+"?([^":]+)"?:\s*(\S+)/); |
| 20 | + if (m?.[1] && m[2]) out[m[1]] = m[2]; |
| 21 | + } |
| 22 | + } |
| 23 | + return out; |
| 24 | +} |
| 25 | + |
| 26 | +describe("better-auth family pins", () => { |
| 27 | + // `@better-auth/api-key` names @better-auth/core, @better-auth/utils and better-call as open |
| 28 | + // peers. Left to npm, a fresh install picks newer releases whose own peers conflict with |
| 29 | + // better-auth's, and `npm create cloudhal` spins forever resolving them (found on 0.1.0). |
| 30 | + // @cloudhal/api therefore depends on exactly the versions better-auth itself uses. |
| 31 | + it("@cloudhal/api pins the versions better-auth depends on", () => { |
| 32 | + // better-auth's exports hide package.json: find it from its entry point. |
| 33 | + let dir = path.dirname(require.resolve("better-auth")); |
| 34 | + while (path.basename(dir) !== "better-auth") dir = path.dirname(dir); |
| 35 | + const ba = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")) as { |
| 36 | + dependencies: Record<string, string>; |
| 37 | + }; |
| 38 | + const api = JSON.parse(readFileSync(path.join(here, "../package.json"), "utf8")) as { |
| 39 | + dependencies: Record<string, string>; |
| 40 | + }; |
| 41 | + const versions = catalog(); |
| 42 | + for (const name of ["@better-auth/core", "@better-auth/utils", "better-call"]) { |
| 43 | + expect(api.dependencies[name], name).toBe("catalog:"); |
| 44 | + expect(versions[name], name).toBe(ba.dependencies[name]); |
| 45 | + } |
| 46 | + }); |
| 47 | +}); |
0 commit comments