Open History to see the last commit
1import { spawnSync } from "node:child_process"
2import { mkdir } from "node:fs/promises"
3import { join, resolve } from "node:path"
4import { existsSync } from "node:fs"
5const root = resolve(import.meta.dirname, "..")
6const backend = process.env.NEON_REALTIME_BACKEND_DIR
7if (!backend)
8 throw new Error("Set NEON_REALTIME_BACKEND_DIR to your matching Realtime backend checkout.")
9// The backend oracle smoke test needs matching SDK sources. The application
10// itself always uses the published @neon/realtime dependency.
11const neon = process.env.NEON_PKGS_DIR
12if (!neon) throw new Error("Set NEON_PKGS_DIR to your matching SDK source checkout.")
13const local = join(root, ".local/realtime")
14function run(cwd: string, bin: string, args: string[], env = process.env) {
15 const result = spawnSync(bin, args, { cwd, env, stdio: "inherit" })
16 if (result.error) throw result.error
17 if (result.status !== 0) throw new Error(`${bin} failed (${result.status})`)
18}
19await mkdir(local, { recursive: true })
20if (existsSync(join(root, ".local/dev/pgdata/postmaster.pid"))) {
21 throw new Error("Stop pnpm dev:local before rebuilding its Postgres extensions.")
22}
23const cached = existsSync(join(local, "pg_install/v18/bin/pg_config"))
24if (!cached) {
25 const expected = spawnSync("git", ["rev-parse", "HEAD:vendor/postgres-v18"], {
26 cwd: backend,
27 encoding: "utf8",
28 }).stdout?.trim()
29 const actual = spawnSync("git", ["-C", "vendor/postgres-v18", "rev-parse", "HEAD"], {
30 cwd: backend,
31 encoding: "utf8",
32 }).stdout?.trim()
33 if (actual && expected !== actual)
34 throw new Error(
35 "The backend's Postgres submodule is at a different revision. Use a source-matched checkout for setup; this script preserves existing checkouts.",
36 )
37}
38run(
39 backend,
40 "make",
41 [
42 "-j8",
43 "realtime-client-oracle-smoke",
44 `POSTGRES_INSTALL_DIR=${join(local, "pg_install")}`,
45 `PGRX_HOME=${join(local, "pgrx")}`,
46 `BUILD_DIR=${join(local, "build")}`,
47 ...(cached ? ["PG_INSTALL_CACHED=1"] : []),
48 ],
49 {
50 ...process.env,
51 NEON_PKGS_CHECKOUT: neon,
52 ...(existsSync(join(neon, "node_modules")) ? { NEON_PKGS_SKIP_INSTALL: "1" } : {}),
53 },
54)
55run(backend, "cargo", [
56 "build",
57 "--locked",
58 "--manifest-path",
59 "pgxn/neon_realtime/Cargo.toml",
60 "-p",
61 "realtime-proxy",
62 "--bin",
63 "realtime-proxy",
64])
65console.log("Local backend built and smoke-tested. Run pnpm dev:local.")