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
15 changes: 12 additions & 3 deletions apps/roam/scripts/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import esbuild from "esbuild";
import fs from "fs";
import path from "path";
import { z } from "zod";
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
// import { envContents } from "@repo/database/dbDotEnv";
const { envContents } = require("@repo/database/dbDotEnv");
let envContents = null;

try {
const dbDotEnv = require("@repo/database/dbDotEnv");
envContents = dbDotEnv.envContents;
} catch (error) {
if ((error as Error).message.includes("Cannot find module")) {
console.error("Build the database module before compiling roam");
process.exit(1);
}
throw error;
}

// https://github.com/evanw/esbuild/issues/337#issuecomment-954633403
const importAsGlobals = (
Expand Down
9 changes: 4 additions & 5 deletions apps/roam/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { put } from "@vercel/blob";
import fs, { readFileSync } from "fs";
import { join } from "path";
import { compile } from "./compile";
import { config } from "@repo/database/dbDotEnv";
import { execSync } from "child_process";

if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
config();
}

const deploy = async () => {
Expand Down Expand Up @@ -38,10 +40,7 @@ const deploy = async () => {
// 2. GitHub Actions environment variable for pushes/tags
process.env.GITHUB_REF_NAME ||
// 3. Local Git branch resolution
require("child_process")
.execSync("git rev-parse --abbrev-ref HEAD")
.toString()
.trim() ||
execSync("git rev-parse --abbrev-ref HEAD").toString().trim() ||
// 4. Final fallback
"main";

Expand Down
6 changes: 1 addition & 5 deletions apps/roam/src/utils/conceptConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import getDiscourseRelations from "./getDiscourseRelations";
import type { DiscourseRelation } from "./getDiscourseRelations";
import type { SupabaseContext } from "~/utils/supabaseContext";

// import type { LocalConceptDataInput } from "@repo/database/inputTypes";
// TODO: Change to apps/roam to ESM and delete below
// // linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
// Define the type locally to avoid ESM import issues
type LocalConceptDataInput = any;
import type { LocalConceptDataInput } from "@repo/database/inputTypes";

const getNodeExtraData = (
node_uid: string,
Expand Down
12 changes: 6 additions & 6 deletions apps/roam/src/utils/hyde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getLoggedInClient } from "./supabaseContext";
import { Result } from "./types";
import normalizePageTitle from "roamjs-components/queries/normalizePageTitle";
import findDiscourseNode from "./findDiscourseNode";
const { nextApiRoot } = require("@repo/utils/execContext");
import { nextApiRoot } from "@repo/utils/execContext";

type ApiEmbeddingResponse = {
data: Array<{
Expand Down Expand Up @@ -93,11 +93,11 @@ const generateHypotheticalNode: HypotheticalNodeGenerator = async ({
}) => {
const { relationLabel, relatedNodeText, relatedNodeFormat } = relationType;

const userPromptContent = `Given the source discourse node \`\`\`${node}\`\`\`,
and considering the relation \`\`\`${relationLabel}\`\`\`
which typically connects to a node of type \`\`\`${relatedNodeText}\`\`\`
(formatted like \`\`\`${relatedNodeFormat}\`\`\`),
generate a hypothetical related discourse node text that would plausibly fit this relationship.
const userPromptContent = `Given the source discourse node \`\`\`${node}\`\`\`,
and considering the relation \`\`\`${relationLabel}\`\`\`
which typically connects to a node of type \`\`\`${relatedNodeText}\`\`\`
(formatted like \`\`\`${relatedNodeFormat}\`\`\`),
generate a hypothetical related discourse node text that would plausibly fit this relationship.
Only return the text of the hypothetical node.`;
const requestBody = {
documents: [{ role: "user", content: userPromptContent }],
Expand Down
18 changes: 4 additions & 14 deletions apps/roam/src/utils/supabaseContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ import getRoamUrl from "roamjs-components/dom/getRoamUrl";
import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage";
import getBlockProps from "~/utils/getBlockProps";
import setBlockProps from "~/utils/setBlockProps";
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
// import type { Enums } from "@repo/database/dbTypes";
// import type { DGSupabaseClient } from "@repo/database/lib/client";
// import {
// fetchOrCreateSpaceDirect,
// fetchOrCreatePlatformAccount,
// createLoggedInClient,
// } from "@repo/database/lib/contextFunctions";
const {
import type { Enums } from "@repo/database/dbTypes";
import type { DGSupabaseClient } from "@repo/database/lib/client";
import {
fetchOrCreateSpaceDirect,
fetchOrCreatePlatformAccount,
createLoggedInClient,
} = require("@repo/database/lib/contextFunctions");
// TEMP TODO: Change to apps/roam to ESM
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
type DGSupabaseClient = any; // Supabase client type
type Enums<T> = T extends "Platform" ? "Roam" | "Obsidian" : never;
} from "@repo/database/lib/contextFunctions";

declare const crypto: { randomUUID: () => string };

Expand Down
3 changes: 1 addition & 2 deletions apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { type RoamDiscourseNodeData } from "./getAllDiscourseNodesSince";
import { type SupabaseContext } from "./supabaseContext";
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
const { nextApiRoot } = require("@repo/utils/execContext");
import { nextApiRoot } from "@repo/utils/execContext";
type LocalContentDataInput = any;
type DGSupabaseClient = any;
type Json = any;
Expand Down
11 changes: 7 additions & 4 deletions apps/roam/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"extends": "@repo/typescript-config/react-library.json",
"include": ["src", "src/types.d.ts", "tailwind.config.ts", "tests", "scripts"],
"include": [
"src",
"src/types.d.ts",
"tailwind.config.ts",
"tests",
"scripts"
],
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"allowJs": false,
"esModuleInterop": false,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"noUncheckedIndexedAccess": false
}
}
1 change: 0 additions & 1 deletion apps/website/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ const nextConfig = {
serverRuntimeConfig: {
maxDuration: 300,
},
transpilePackages: ["@repo/database", "@repo/utils", "@repo/ui"],
};
export default nextConfig;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/database/cucumber.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"default": {
"loader": ["ts-node/esm"],
"import": ["features/step-definitions/**/*.ts"]
"requireModule": ["ts-node/register"],
"require": ["features/step-definitions/**/*.ts"]
}
}
48 changes: 39 additions & 9 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,54 @@
"version": "0.0.0",
"private": true,
"license": "Apache-2.0",
"type": "module",
"exports": {
"./lib/*": "./src/lib/*.ts",
"./dbDotEnv": "./src/dbDotEnv.ts",
"./dbTypes": "./src/dbTypes.ts",
"./inputTypes": "./src/inputTypes.ts"
"./lib/*": {
"types": "./dist/src/lib/*.d.ts",
"require": "./dist/src/lib/*.js",
"default": "./dist/src/lib/*.js"
},
"./dbDotEnv": {
"types": "./dist/src/dbDotEnv.d.ts",
"require": "./dist/src/dbDotEnv.js",
"default": "./dist/src/dbDotEnv.js"
},
"./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"
}
},
"typesVersions": {
"*": {
"lib/*": [
"dist/src/lib/*.d.ts"
],
"./dbDotEnv": [
"dist/src/dbDotEnv.d.ts"
],
"./dbTypes": [
"dist/src/dbTypes.d.ts"
],
"./inputTypes": [
"dist/src/inputTypes.d.ts"
]
}
},
"scripts": {
"init": "supabase login",
"dev": "supabase start && tsx scripts/createEnv.ts && supabase functions serve",
"dev": "supabase start && tsx scripts/createEnv.mts && supabase functions serve",
"stop": "supabase stop",
"check-types": "tsc --noEmit --skipLibCheck",
"check-types": "tsc --emitDeclarationOnly --skipLibCheck",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want the check-types to emit declarations? Aren't we just running a check here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the package declarations are not generated, the check of the apps, that refer to those declarations, fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

@maparent
Can you show me an example of what you are referring to? This wasn't the case previously when I initially checked in check-types, and I just just changed them all to noEmit and it ran successfully for me

image

I also cd packages/database and ran npm run check-types successfully
image

"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": "tsx scripts/build.ts && npm run genenv -- local",
"build": "tsc && tsx scripts/build.ts && npm run genenv -- local",
"test": "tsc && cucumber-js",
"genenv": "tsx scripts/createEnv.ts",
"genenv": "tsx scripts/createEnv.mts",
"gentypes:production": "supabase start && supabase gen types typescript --project-id \"$SUPABASE_PROJECT_ID\" --schema public > src/dbTypes.ts",
"dbdiff": "supabase stop && supabase db diff",
"dbdiff:save": "supabase stop && supabase db diff -f",
Expand Down
10 changes: 6 additions & 4 deletions packages/database/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { writeFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, "..");

if (process.env.HOME !== "/vercel") {
Expand All @@ -12,10 +12,12 @@ if (process.env.HOME !== "/vercel") {
execSync("supabase migrations up", { cwd: projectRoot, stdio: "inherit" });
const stdout = execSync(
"supabase gen types typescript --local --schema public",
{ encoding: "utf8" , cwd: projectRoot },
{ encoding: "utf8", cwd: projectRoot },
);
writeFileSync(
join(projectRoot, "src", "dbTypes.ts"),
"// Generated by supabase -- do not edit\n" + stdout,
);
writeFileSync(join(projectRoot, "src", "dbTypes.ts"),
"// Generated by supabase -- do not edit\n" + stdout);
} catch (err) {
console.error(err);
throw err;
Expand Down
2 changes: 1 addition & 1 deletion packages/database/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ const main = () => {
process.exit(1);
}
};
if (import.meta.url === `file://${process.argv[1]}`) main();
if (__filename === process.argv[1]) main();
5 changes: 2 additions & 3 deletions packages/database/scripts/lint.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { exec } from "node:child_process";
import { readdir, Dirent } from "node:fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, "..");

const main = () => {
Expand Down Expand Up @@ -66,4 +65,4 @@ const main = () => {
process.exit(1);
}
};
if (import.meta.url === `file://${process.argv[1]}`) main();
if (__filename === process.argv[1]) main();
12 changes: 9 additions & 3 deletions packages/database/src/dbDotEnv.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import dotenv from "dotenv";
import { readFileSync, existsSync } from "fs";
import { join, dirname } from "path";
import { join, dirname, basename } from "path";
import { fileURLToPath } from "url";
Copy link
Contributor

Choose a reason for hiding this comment

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

unused

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

used at line 8.

Copy link
Contributor

Choose a reason for hiding this comment

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

@maparent fileURLToPath is unused
image


const __dirname = dirname(dirname(fileURLToPath(import.meta.url)));
const findRoot = (): string => {
let dir = __filename;
while (basename(dir) !== "database") {
dir = dirname(dir);
}
return dir;
};

export const getVariant = (): string | null => {
if (process.env.HOME === "/vercel" || process.env.GITHUB_ACTIONS === "true")
Expand All @@ -23,7 +29,7 @@ export const getVariant = (): string | null => {
export const envFilePath = () => {
const variant: string | null = getVariant();
if (variant === null) return null;
const name = join(__dirname, `.env.${variant}`);
const name = join(findRoot(), `.env.${variant}`);
return existsSync(name) ? name : null;
};

Expand Down
1 change: 0 additions & 1 deletion packages/database/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
"noEmit": true,
"outDir": "dist"
},
"include": [
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@repo/eslint-config",
"version": "0.0.0",
"type": "module",
"license": "Apache-2.0",
"private": true,
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"incremental": false,
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "NodeNext",
"module": "nodenext",
"moduleDetection": "force",
"moduleResolution": "NodeNext",
"moduleResolution": "nodenext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true,
Expand Down
38 changes: 30 additions & 8 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,45 @@
"version": "0.0.0",
"private": true,
"license": "Apache-2.0",
"type": "module",
"exports": {
"./globals.css": "./src/globals.css",
"./postcss.config": "./postcss.config.mjs",
"./tailwind.config": "./tailwind.config.ts",
"./lib/*": "./src/lib/*.ts",
"./hooks/*": [
"./src/hooks/*.ts",
"./src/hooks/*.tsx"
],
"./components/*": "./src/components/*.tsx"
"./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"
]
}
},
"scripts": {
"lint": "eslint .",
"build": "tsc",
"lint:fix": "eslint . --fix",
"generate:component": "turbo gen react-component",
"check-types": "tsc --noEmit --skipLibCheck",
"check-types": "tsc --emitDeclarationOnly --skipLibCheck",
"ui": "npx shadcn@latest"
},
"devDependencies": {
Expand Down
Loading