Skip to content

Commit 209587d

Browse files
committed
ENG-815:
There are circular dependencies within `packages/database`, especially of stepdefs.ts on dbDotEnv, which is why I made it a mjs module. The alternative is to not compile stepdefs; cucumber can use it by reference. Then dbDotEnv can then be a mts module. We then have to compile it first (in a bootstrap stage) and then require it everywhere. Ensure stepdef and scripts are type-checked, now that they're not compiled.
1 parent fff8975 commit 209587d

File tree

16 files changed

+82
-59
lines changed

16 files changed

+82
-59
lines changed

apps/roam/scripts/compile.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,7 @@ const getVersion = (): string => {
1818
const getBuildDate = (): string => {
1919
return new Date().toISOString().split("T")[0]; // YYYY-MM-DD format
2020
};
21-
let envContents = null;
22-
23-
try {
24-
const dbDotEnv = require("@repo/database/dbDotEnv");
25-
envContents = dbDotEnv.envContents;
26-
} catch (error) {
27-
if ((error as Error).message.includes("Cannot find module")) {
28-
console.error("Build the database module before compiling roam");
29-
process.exit(1);
30-
}
31-
throw error;
32-
}
21+
const { envContents } = require("@repo/database/dbDotEnv");
3322

3423
// https://github.com/evanw/esbuild/issues/337#issuecomment-954633403
3524
const importAsGlobals = (

apps/roam/scripts/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { put } from "@vercel/blob";
22
import fs, { readFileSync } from "fs";
33
import { join } from "path";
44
import { compile } from "./compile";
5-
import { config } from "@repo/database/dbDotEnv";
5+
const { config } = require("@repo/database/dbDotEnv");
66
import { execSync } from "child_process";
77

88
if (process.env.NODE_ENV !== "production") {

apps/website/app/utils/supabase/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createServerClient } from "@supabase/ssr";
22
import { NextResponse, type NextRequest } from "next/server";
3-
import { envContents } from "@repo/database/dbDotEnv";
3+
const { envContents } = require("@repo/database/dbDotEnv");
44

55
// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth
66

apps/website/app/utils/supabase/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createServerClient, type CookieOptions } from "@supabase/ssr";
22
import { cookies } from "next/headers";
33
import type { Database } from "@repo/database/dbTypes";
4-
import { envContents } from "@repo/database/dbDotEnv";
4+
const { envContents } = require("@repo/database/dbDotEnv");
55

66
// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth
77

apps/website/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NextConfig } from "next";
2-
import { config } from "@repo/database/dbDotEnv";
2+
const { config } = require("@repo/database/dbDotEnv");
33

44
config();
55

packages/database/doc/tasks.dot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ deploy
2020
deploy_functions
2121
migrate
2222
gentypes
23+
bootstrap
2324

2425
/* supabase functions */
2526
node [color=purple]
@@ -58,6 +59,7 @@ cucumber_js
5859
s_migrate -> migrations_up
5960
dev -> setup
6061
dev -> serve
62+
setup -> bootstrap
6163
setup -> genenv
6264
setup -> migrate
6365
serve -> s_serve
@@ -83,4 +85,5 @@ cucumber_js
8385
build -> tsc
8486
s_genTypes -> generate_schema
8587
s_migrate -> sup_start
88+
bootstrap -> tsc
8689
}

packages/database/features/step-definitions/stepdefs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from "assert";
22
import { Given, When, Then, world, type DataTable } from "@cucumber/cucumber";
33
import { createClient } from "@supabase/supabase-js";
44
import { Constants, type Database, type Enums } from "@repo/database/dbTypes";
5-
import { getVariant, config } from "@repo/database/dbDotEnv";
5+
const { getVariant, config } = require("@repo/database/dbDotEnv");
66

77
import {
88
spaceAnonUserEmail,

packages/database/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
"exports": {
77
"./lib/*": "./src/lib/*.ts",
88
"./dbDotEnv": {
9-
"types": "./types/dbDotEnv.d.ts",
10-
"import": "./src/dbDotEnv.mjs",
11-
"default": "./src/dbDotEnv.mjs"
9+
"types": "./dist/src/dbDotEnv.d.mts",
10+
"import": "./dist/src/dbDotEnv.mjs",
11+
"require": "./dist/src/dbDotEnv.mjs",
12+
"default": "./dist/src/dbDotEnv.mjs"
1213
},
1314
"./dbTypes": "./src/dbTypes.ts",
1415
"./inputTypes": "./src/inputTypes.ts"
1516
},
1617
"typesVersions": {
1718
"*": {
1819
"./dbDotEnv": [
19-
"types/dbDotEnv.d.ts"
20+
"dist/src/dbDotEnv.d.mts"
2021
]
2122
}
2223
},
2324
"scripts": {
2425
"init": "supabase login",
25-
"setup": "npm run genenv && npm run migrate",
26+
"setup": "npm run bootstrap && npm run genenv && npm run migrate",
27+
"bootstrap": "tsc -p tsconfig_bootstrap.json",
2628
"dev": "npm run setup && npm run serve",
2729
"build": "npm run setup && tsc",
2830
"serve": "tsx scripts/serve.ts",
2931
"stop": "supabase stop",
30-
"check-types": "tsc --noEmit --skipLibCheck",
32+
"check-types": "tsc -p tsconfig_lint.json",
3133
"check-schema": "tsx scripts/lintSchemas.ts && supabase stop && npm run dbdiff",
3234
"lint": "eslint . && tsx scripts/lintSchemas.ts && tsx scripts/lintFunctions.ts",
3335
"lint:fix": "eslint --fix . && tsx scripts/lintSchemas.ts -f && tsx scripts/lintFunctions.ts",

packages/database/scripts/genTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execSync } from "node:child_process";
22
import { writeFileSync } from "fs";
33
import { join, dirname } from "path";
4-
import { getVariant } from "@repo/database/dbDotEnv";
4+
import { getVariant } from "../src/dbDotEnv.mts";
55

66
const __dirname = dirname(__filename);
77
const projectRoot = join(__dirname, "..");

packages/database/scripts/serve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execSync } from "node:child_process";
22
import { writeFileSync } from "fs";
33
import { join, dirname } from "path";
4-
import { getVariant } from "@repo/database/dbDotEnv";
4+
import { getVariant } from "../src/dbDotEnv.mts";
55

66
const __dirname = dirname(__filename);
77
const projectRoot = join(__dirname, "..");

0 commit comments

Comments
 (0)