@@ -0,0 +1,122 @@
1+#!/usr/bin/env bun
2+/**
3+ * Pre-publish verification script.
4+ *
5+ * Checks that:
6+ * 1. All workspace package.json versions match each other
7+ * 2. bun.lock workspace versions match package.json versions
8+ * 3. No stale lockfile entries that would cause bun publish to resolve wrong versions
9+ *
10+ * Run before publishing: bun run scripts/prepublish-check.ts
11+ */
12+
13+import { readFileSync } from "fs";
14+import { resolve } from "path";
15+
16+const ROOT = resolve(import.meta.dirname, "..");
17+const PACKAGES = ["types", "core", "components"] as const;
18+
19+let failed = false;
20+
21+function fail(msg: string) {
22+ console.error(`❌ ${msg}`);
23+ failed = true;
24+}
25+
26+function pass(msg: string) {
27+ console.log(`✅ ${msg}`);
28+}
29+
30+// 1. Read all package.json versions
31+const packageVersions: Record<string, string> = {};
32+for (const pkg of PACKAGES) {
33+ const pkgJson = JSON.parse(
34+ readFileSync(resolve(ROOT, `packages/${pkg}/package.json`), "utf-8"),
35+ );
36+ packageVersions[pkg] = pkgJson.version;
37+}
38+
39+console.log("\n--- Package versions (package.json) ---");
40+for (const pkg of PACKAGES) {
41+ console.log(` @cel-tui/${pkg}: ${packageVersions[pkg]}`);
42+}
43+
44+// 2. Check all versions match
45+const versions = new Set(Object.values(packageVersions));
46+if (versions.size === 1) {
47+ pass(`All package.json versions match: ${[...versions][0]}`);
48+} else {
49+ fail(`Package versions don't match: ${JSON.stringify(packageVersions)}`);
50+}
51+
52+// 3. Read bun.lock and check workspace versions
53+const lockContent = readFileSync(resolve(ROOT, "bun.lock"), "utf-8");
54+
55+console.log("\n--- Lockfile workspace versions ---");
56+for (const pkg of PACKAGES) {
57+ const pattern = new RegExp(
58+ `"packages/${pkg}":\\s*\\{[^}]*"version":\\s*"([^"]+)"`,
59+ "s",
60+ );
61+ const match = lockContent.match(pattern);
62+ if (!match) {
63+ fail(`Could not find packages/${pkg} version in bun.lock`);
64+ continue;
65+ }
66+ const lockVersion = match[1];
67+ console.log(
68+ ` @cel-tui/${pkg}: ${lockVersion} (lockfile) vs ${packageVersions[pkg]} (package.json)`,
69+ );
70+ if (lockVersion === packageVersions[pkg]) {
71+ pass(`@cel-tui/${pkg} lockfile version matches package.json`);
72+ } else {
73+ fail(
74+ `@cel-tui/${pkg} lockfile version MISMATCH: bun.lock has ${lockVersion}, package.json has ${packageVersions[pkg]}. Run: rm bun.lock && bun install`,
75+ );
76+ }
77+}
78+
79+// 4. Check workspace dependencies point to workspace packages (not pinned old versions)
80+console.log("\n--- Workspace dependency checks ---");
81+const corePkg = JSON.parse(
82+ readFileSync(resolve(ROOT, "packages/core/package.json"), "utf-8"),
83+);
84+const compPkg = JSON.parse(
85+ readFileSync(resolve(ROOT, "packages/components/package.json"), "utf-8"),
86+);
87+
88+const workspaceDeps: [string, string, string][] = [
89+ ["core", "@cel-tui/types", corePkg.dependencies?.["@cel-tui/types"]],
90+ ["components", "@cel-tui/types", compPkg.dependencies?.["@cel-tui/types"]],
91+ ["components", "@cel-tui/core", compPkg.dependencies?.["@cel-tui/core"]],
92+];
93+
94+for (const [pkg, dep, value] of workspaceDeps) {
95+ if (value === "workspace:*") {
96+ pass(
97+ `@cel-tui/${pkg} → ${dep} uses workspace:* (will resolve from lockfile)`,
98+ );
99+ } else if (value) {
100+ // If using explicit versions, check they match the target package version
101+ const targetPkg = dep.replace("@cel-tui/", "") as (typeof PACKAGES)[number];
102+ if (value === packageVersions[targetPkg]) {
103+ pass(
104+ `@cel-tui/${pkg} → ${dep} pinned to ${value} (matches current version)`,
105+ );
106+ } else {
107+ fail(
108+ `@cel-tui/${pkg} → ${dep} pinned to ${value} but current version is ${packageVersions[targetPkg]}`,
109+ );
110+ }
111+ }
112+}
113+
114+console.log("");
115+if (failed) {
116+ console.error(
117+ "🚫 Pre-publish checks FAILED. Fix the issues above before publishing.",
118+ );
119+ process.exit(1);
120+} else {
121+ console.log("🎉 All pre-publish checks passed. Safe to publish.");
122+}