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
36 changes: 7 additions & 29 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,33 @@
"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"
]
}
},
"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 --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",
"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",
Expand Down
112 changes: 67 additions & 45 deletions packages/database/scripts/createEnv.mts
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
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<string, string> = {};

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
const projectIdOrName: string =
process.env["VERCEL_PROJECT_ID"] ||
process.env["VERCEL_PROJECT_NAME"] ||
"discourse-graph";
const baseParams: Record<string, string> = {};
const vercelToken = process.env["VERCEL_TOKEN"];

const getVercelToken = () => {
dotenv.config();
return process.env["VERCEL_TOKEN"];
};

const makeLocalEnv = () => {
const stdout = execSync("supabase status -o env", {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -100,38 +98,62 @@ 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) => {
// Do not execute in deployment or github action.
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("variant ", variant, " 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<string, Variant>)[variantS];
if (variant === undefined) {
throw Error("Invalid variant: " + variant);
}
} catch (err) {
console.error(err);
throw err;
console.log(variant);
await main(variant);
}
33 changes: 4 additions & 29 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,16 @@
"./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"
}
},
"typesVersions": {
"*": {
"lib/*": [
"dist/lib/*.d.ts"
],
"hooks/*": [
"dist/hooks/*.d.ts"
],
"components/*": [
"dist/components/*.d.ts"
]
}
"./lib/*": "./src/lib/*.ts",
"./hooks/*": "./src/hooks/*.ts",
"./components/*": "./src/components/*.tsx"
},
Comment on lines +10 to 13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Source .ts/.tsx exports: ensure apps transpile external packages.

Same risk as utils; verify Next/Vite transpile @repo/ui and that Storybook (if any) is configured similarly.

Use the same script I shared for utils; additionally check for Storybook:


🏁 Script executed:

#!/bin/bash
fd -t f -a 'main.(js|ts|cjs|mjs|ts|tsx)' apps | rg -n 'storybook' -n || true

Length of output: 0


🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "=== packages/ui/package.json (summary) ==="
if [ -f packages/ui/package.json ]; then
  jq '{name: .name, main: .main, types: .types, exports: .exports, files: .files}' packages/ui/package.json || true
  echo "---- full file ----"
  sed -n '1,240p' packages/ui/package.json || true
else
  echo "packages/ui/package.json not found"
fi

echo
echo "=== Search for storybook references and .storybook dirs ==="
rg -n --hidden --no-ignore -S "storybook" || true
find . -type d -name ".storybook" -print || true

echo
echo "=== Search for Next/Vite transpile-related config/usages ==="
rg -n --hidden --no-ignore -S "transpilePackages|next-transpile-modules|withTM|transpile" || true
rg -n --hidden --no-ignore -S "vite.config|optimizeDeps|noExternal|ssr.noExternal|server.noExternal" || true

echo
echo "=== Show next.config.* files (if any) ==="
find . -type f -name "next.config.*" -print -exec sed -n '1,240p' {} \; || true

echo
echo "=== Show vite.config.* files (if any) ==="
find . -type f -name "vite.config.*" -print -exec sed -n '1,240p' {} \; || true

echo
echo "=== Search for imports referencing a ui package (patterns) ==="
rg -n --hidden --no-ignore -S "from ['\"][^'\"]*ui['\"]|require\\(['\"][^'\"]*ui['\"]\\)" || true

echo
echo "=== Search apps/ for package.json scripts mentioning storybook or next/vite ==="
rg -n --hidden --no-ignore -S '"storybook"|"next"|"vite"' apps || true

Length of output: 3756


Exporting source (.ts/.tsx) from @repo/ui — publish compiled JS or enable per-app transpilation

  • packages/ui/package.json — exports target ./src/.ts/.tsx, main/types are null, while typesVersions point at dist/.d.ts; this mismatch requires either shipping compiled JS (dist) and updating main/types/exports or intentionally relying on consumer transpilation.
  • apps/website/next.config.ts — no transpilePackages / next-transpile-modules configuration found; Next will not transpile node_modules by default, so consuming the source exports will break.
  • No Storybook config or storybook scripts detected; if Storybook is used, configure it to transpile @repo/ui or publish compiled output.
🤖 Prompt for AI Agents
In packages/ui/package.json around lines 10–13, the package currently exports
source files (./src/*.ts/.tsx) while main/types are null and typesVersions point
to dist/*.d.ts, causing a mismatch; fix by either (A) publishing compiled
output: add a build step that outputs JS and .d.ts into dist, set "main" to
dist/index.js and "types" to dist/index.d.ts, update the "exports" map to point
to ./dist/*, include dist in "files" and ensure typesVersions match dist, and
update npmignore/packlist so dist is published; or (B) opt into consumer
transpilation: keep source exports but document this and configure consuming
apps—add next.config.js transpilePackages: ['@repo/ui'] (or
next-transpile-modules) and update Storybook webpack to transpile
@repo/ui—choose one approach and make package.json and build/config changes
consistently.

"scripts": {
"lint": "eslint .",
"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": {
Expand Down
15 changes: 2 additions & 13 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
}
}
15 changes: 12 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@
],
"tasks": {
"build": {
"dependsOn": ["^build"],
"dependsOn": ["@repo/database#genenv"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted in future PR

"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"]
},
Expand All @@ -60,7 +59,17 @@
"cache": false,
"persistent": true,
"inputs": ["$TURBO_DEFAULT$", ".env*"],
"dependsOn": ["^build"]
"dependsOn": ["@repo/database#genenv"]
Copy link
Contributor

@mdroidian mdroidian Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted in future

},
"roam#dev": {
"with": ["@repo/database#dev"]
},
"website#dev": {
"with": ["@repo/database#dev"]
},
"genenv": {
"env": ["SUPABASE_USE_DB"],
"outputs": [".env*"]
},
"deploy": {
"cache": false,
Expand Down