From 636f1016e70ce1822fba9fc83d3d103829a731f7 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Wed, 10 Sep 2025 23:05:15 -0400 Subject: [PATCH 1/4] eng-847 compile roam against db ts --- packages/database/package.json | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/packages/database/package.json b/packages/database/package.json index e25eef1f6..ca32d3c2a 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -4,40 +4,20 @@ "private": true, "license": "Apache-2.0", "exports": { - "./lib/*": { - "types": "./dist/src/lib/*.d.ts", - "require": "./dist/src/lib/*.js", - "default": "./dist/src/lib/*.js" - }, + "./lib/*": "./src/lib/*.ts", "./dbDotEnv": { "types": "./types/dbDotEnv.d.ts", "import": "./src/dbDotEnv.mjs", "require": "./src/dbDotEnv.mjs", "default": "./src/dbDotEnv.mjs" }, - "./dbTypes": { - "types": "./dist/src/dbTypes.d.ts", - "require": "./dist/src/dbTypes.js", - "default": "./dist/src/dbTypes.js" - }, - "./inputTypes": { - "types": "./dist/src/inputTypes.d.ts", - "default": "./dist/src/inputTypes.d.ts" - } + "./dbTypes": "./src/dbTypes.ts", + "./inputTypes": "./src/inputTypes.ts" }, "typesVersions": { "*": { - "lib/*": [ - "dist/src/lib/*.d.ts" - ], "./dbDotEnv": [ - "src/dbDotEnv.d.ts" - ], - "./dbTypes": [ - "dist/src/dbTypes.d.ts" - ], - "./inputTypes": [ - "dist/src/inputTypes.d.ts" + "types/dbDotEnv.d.ts" ] } }, From 252e57b6b0b28c26c9fdc91b31e6b32ccdc83b78 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 11 Sep 2025 10:13:03 -0400 Subject: [PATCH 2/4] Also make utils and ui co-compile rather than build. Adjust turbo dependencies. --- packages/database/package.json | 2 +- packages/ui/package.json | 20 ++++---------------- packages/utils/package.json | 15 ++------------- turbo.json | 15 ++++++++++++--- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/packages/database/package.json b/packages/database/package.json index ca32d3c2a..af9a1dce8 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -27,7 +27,7 @@ "compile": "tsc", "serve": "supabase start && tsx scripts/createEnv.mts && supabase functions serve", "stop": "supabase stop", - "check-types": "tsc --emitDeclarationOnly --skipLibCheck", + "check-types": "tsc --noEmit --skipLibCheck", "check-schema": "tsx scripts/lint.ts && supabase stop && npm run dbdiff", "lint": "eslint . && tsx scripts/lint.ts", "lint:fix": "tsx scripts/lint.ts -f", diff --git a/packages/ui/package.json b/packages/ui/package.json index 0bd7892dd..33d873238 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -7,21 +7,9 @@ "./globals.css": "./src/globals.css", "./postcss.config": "./postcss.config.mjs", "./tailwind.config": "./tailwind.config.ts", - "./lib/*": { - "types": "./dist/src/lib/*.d.ts", - "require": "./dist/src/lib/*.js", - "default": "./dist/src/lib/*.js" - }, - "./hooks/*": { - "types": "./dist/src/hooks/*.d.ts", - "require": "./dist/src/hooks/*.js", - "default": "./dist/src/hooks/*.js" - }, - "./components/*": { - "types": "./dist/src/components/*.d.ts", - "require": "./dist/src/components/*.js", - "default": "./dist/src/components/*.js" - } + "./lib/*": "./src/lib/*.ts", + "./hooks/*": "./src/hooks/*.ts", + "./components/*": "./src/components/*.tsx" }, "typesVersions": { "*": { @@ -41,7 +29,7 @@ "build": "tsc", "lint:fix": "eslint . --fix", "generate:component": "turbo gen react-component", - "check-types": "tsc --emitDeclarationOnly --skipLibCheck", + "check-types": "tsc --noEmit --skipLibCheck", "ui": "npx shadcn@latest" }, "devDependencies": { diff --git a/packages/utils/package.json b/packages/utils/package.json index b2fb97a35..1496dc975 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -4,22 +4,11 @@ "private": true, "license": "Apache-2.0", "exports": { - "./*": { - "types": "./dist/src/*.d.ts", - "require": "./dist/src/*.js", - "default": "./dist/src/*.js" - } - }, - "typesVersions": { - "*": { - "*": [ - "dist/src/*.d.ts" - ] - } + "./*": "./src/*.ts" }, "scripts": { "build": "tsc", - "check-types": "tsc --emitDeclarationOnly --skipLibCheck", + "check-types": "tsc --noEmit --skipLibCheck", "lint": "eslint ." } } diff --git a/turbo.json b/turbo.json index 073e1b63f..88b2cfb1b 100644 --- a/turbo.json +++ b/turbo.json @@ -40,12 +40,11 @@ ], "tasks": { "build": { - "dependsOn": ["^build"], + "dependsOn": ["@repo/database#genenv"], "inputs": ["$TURBO_DEFAULT$", ".env*"], "outputs": [".next/**", "!.next/cache/**", "dist/**", "src/dbTypes.ts"] }, "build-schema": { - "dependsOn": ["^build-schema"], "inputs": ["$TURBO_DEFAULT$", ".env*"], "outputs": ["src/dbTypes.ts"] }, @@ -60,7 +59,17 @@ "cache": false, "persistent": true, "inputs": ["$TURBO_DEFAULT$", ".env*"], - "dependsOn": ["^build"] + "dependsOn": ["@repo/database#genenv"] + }, + "roam#dev": { + "with": ["@repo/database#dev"] + }, + "website#dev": { + "with": ["@repo/database#dev"] + }, + "genenv": { + "inputs": ["SUPABASE_USE_DB"], + "outputs": [".env*"] }, "deploy": { "cache": false, From 430cae835ecb56574e61ec5af906b8e26193c822 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 11 Sep 2025 19:26:53 -0400 Subject: [PATCH 3/4] ENG-821 Rewrite createEnv.mts to be more resilient. (#434) Specifically, allows it to be called in a non-dev environment. --- packages/database/package.json | 5 +- packages/database/scripts/createEnv.mts | 111 ++++++++++++++---------- 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/packages/database/package.json b/packages/database/package.json index af9a1dce8..d2b4212d0 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -24,15 +24,14 @@ "scripts": { "init": "supabase login", "dev": "tsx scripts/dev.ts", - "compile": "tsc", "serve": "supabase start && tsx scripts/createEnv.mts && supabase functions serve", "stop": "supabase stop", "check-types": "tsc --noEmit --skipLibCheck", "check-schema": "tsx scripts/lint.ts && supabase stop && npm run dbdiff", "lint": "eslint . && tsx scripts/lint.ts", "lint:fix": "tsx scripts/lint.ts -f", - "build": "tsc", - "build-schema": "tsx scripts/build.ts && npm run genenv -- local", + "build": "tsx scripts/createEnv.mts && tsc", + "build-schema": "tsx scripts/build.ts && tsx scripts/createEnv.mts -- local", "test": "tsc && cucumber-js", "genenv": "tsx scripts/createEnv.mts", "gentypes:production": "supabase start && supabase gen types typescript --project-id \"$SUPABASE_PROJECT_ID\" --schema public > src/dbTypes.ts", diff --git a/packages/database/scripts/createEnv.mts b/packages/database/scripts/createEnv.mts index 93f3e1e49..514b91e70 100644 --- a/packages/database/scripts/createEnv.mts +++ b/packages/database/scripts/createEnv.mts @@ -1,25 +1,20 @@ import { execSync } from "node:child_process"; -import { appendFileSync, writeFileSync } from "fs"; -import { join, dirname } from "path"; -import { fileURLToPath } from "url"; +import { appendFileSync, writeFileSync } from "node:fs"; +import { join, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; import dotenv from "dotenv"; import { Vercel } from "@vercel/sdk"; const __dirname = dirname(fileURLToPath(import.meta.url)); const projectRoot = join(__dirname, ".."); +const baseParams: Record = {}; -if (process.env.HOME === "/vercel") process.exit(0); - -dotenv.config(); - -const variant = - (process.argv.length === 3 - ? process.argv[2] - : process.env["SUPABASE_USE_DB"]) || "local"; - -if (["local", "branch", "production", "all"].indexOf(variant) === -1) { - console.error("Invalid variant: " + variant); - process.exit(-1); +enum Variant { + local = "local", + branch = "branch", + production = "production", + all = "all", + none = "none", } // option to override in .env, but otherwise use our values @@ -27,8 +22,11 @@ const projectIdOrName: string = process.env["VERCEL_PROJECT_ID"] || process.env["VERCEL_PROJECT_NAME"] || "discourse-graph"; -const baseParams: Record = {}; -const vercelToken = process.env["VERCEL_TOKEN"]; + +const getVercelToken = () => { + dotenv.config(); + return process.env["VERCEL_TOKEN"]; +}; const makeLocalEnv = () => { const stdout = execSync("supabase status -o env", { @@ -49,7 +47,7 @@ const makeLocalEnv = () => { ); }; -const makeBranchEnv = async (vercel: Vercel) => { +const makeBranchEnv = async (vercel: Vercel, vercelToken: string) => { let branch: string; if (process.env.SUPABASE_GIT_BRANCH) { // allow to override current branch @@ -88,7 +86,7 @@ const makeBranchEnv = async (vercel: Vercel) => { appendFileSync(".env.branch", `NEXT_API_ROOT="${url}/api"\n`); }; -const makeProductionEnv = async (vercel: Vercel) => { +const makeProductionEnv = async (vercel: Vercel, vercelToken: string) => { const result = await vercel.deployments.getDeployments({ ...baseParams, projectId: projectIdOrName, @@ -100,38 +98,61 @@ const makeProductionEnv = async (vercel: Vercel) => { throw new Error("No production deployment found"); } const url = result.deployments[0]!.url; - console.log(url); execSync( `vercel -t ${vercelToken} env pull --environment production .env.production`, ); appendFileSync(".env.production", `NEXT_API_ROOT="${url}/api"\n`); }; -try { - if (variant === "local" || variant === "all") { - makeLocalEnv(); - if (variant === "local") process.exit(0); - } - if (!vercelToken) { - console.error("Missing VERCEL_TOKEN in .env"); - process.exit(-1); - } - // option to override in .env, but otherwise use our values - const teamId = process.env["VERCEL_TEAM_ID"]; - const teamSlug = process.env["VERCEL_TEAM_SLUG"] || "discourse-graphs"; - if (teamId) { - baseParams.teamId = teamId; - } else { - baseParams.slug = teamSlug; - } - const vercel = new Vercel({ bearerToken: vercelToken }); - if (variant === "branch" || variant === "all") { - await makeBranchEnv(vercel); +const main = async (variant: Variant) => { + if ( + process.env.HOME === "/vercel" || + process.env.GITHUB_ACTIONS !== undefined + ) + return; + + if (variant === Variant.none) return; + + try { + if (variant === Variant.local || variant === Variant.all) { + makeLocalEnv(); + if (variant === Variant.local) return; + } + const vercelToken = getVercelToken(); + if (!vercelToken) { + throw Error("Missing VERCEL_TOKEN in .env"); + } + // option to override in .env, but otherwise use our values + const teamId = process.env["VERCEL_TEAM_ID"]; + const teamSlug = process.env["VERCEL_TEAM_SLUG"] || "discourse-graphs"; + if (teamId) { + baseParams.teamId = teamId; + } else { + baseParams.slug = teamSlug; + } + const vercel = new Vercel({ bearerToken: vercelToken }); + if (variant === Variant.branch || variant === Variant.all) { + await makeBranchEnv(vercel, vercelToken); + } + if (variant === Variant.production || variant === Variant.all) { + await makeProductionEnv(vercel, vercelToken); + } + } catch (err) { + console.error(err); + throw err; } - if (variant === "production" || variant === "all") { - await makeProductionEnv(vercel); +}; + +if (fileURLToPath(import.meta.url) === process.argv[1]) { + const variantS: string = + (process.argv.length === 3 + ? process.argv[2] + : process.env["SUPABASE_USE_DB"]) || "none"; + + const variant = (Variant as Record)[variantS]; + if (variant === undefined) { + throw Error("Invalid variant: " + variant); } -} catch (err) { - console.error(err); - throw err; + console.log(variant); + await main(variant); } From d2cf3e9738294b78e666e62b9dd0588c8dcde4b4 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 11 Sep 2025 19:54:26 -0400 Subject: [PATCH 4/4] corrections --- packages/database/package.json | 1 - packages/database/scripts/createEnv.mts | 3 ++- packages/ui/package.json | 13 ------------- turbo.json | 2 +- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/packages/database/package.json b/packages/database/package.json index d2b4212d0..160a01d2a 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -8,7 +8,6 @@ "./dbDotEnv": { "types": "./types/dbDotEnv.d.ts", "import": "./src/dbDotEnv.mjs", - "require": "./src/dbDotEnv.mjs", "default": "./src/dbDotEnv.mjs" }, "./dbTypes": "./src/dbTypes.ts", diff --git a/packages/database/scripts/createEnv.mts b/packages/database/scripts/createEnv.mts index 514b91e70..67af5ca11 100644 --- a/packages/database/scripts/createEnv.mts +++ b/packages/database/scripts/createEnv.mts @@ -105,6 +105,7 @@ const makeProductionEnv = async (vercel: Vercel, vercelToken: string) => { }; const main = async (variant: Variant) => { + // Do not execute in deployment or github action. if ( process.env.HOME === "/vercel" || process.env.GITHUB_ACTIONS !== undefined @@ -138,7 +139,7 @@ const main = async (variant: Variant) => { await makeProductionEnv(vercel, vercelToken); } } catch (err) { - console.error(err); + console.error("variant ", variant, " error ", err); throw err; } }; diff --git a/packages/ui/package.json b/packages/ui/package.json index 33d873238..83919d9c3 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -11,19 +11,6 @@ "./hooks/*": "./src/hooks/*.ts", "./components/*": "./src/components/*.tsx" }, - "typesVersions": { - "*": { - "lib/*": [ - "dist/lib/*.d.ts" - ], - "hooks/*": [ - "dist/hooks/*.d.ts" - ], - "components/*": [ - "dist/components/*.d.ts" - ] - } - }, "scripts": { "lint": "eslint .", "build": "tsc", diff --git a/turbo.json b/turbo.json index 88b2cfb1b..c96451b0e 100644 --- a/turbo.json +++ b/turbo.json @@ -68,7 +68,7 @@ "with": ["@repo/database#dev"] }, "genenv": { - "inputs": ["SUPABASE_USE_DB"], + "env": ["SUPABASE_USE_DB"], "outputs": [".env*"] }, "deploy": {