Skip to content

Commit 35a2d55

Browse files
authored
ENG-785 Use commonjs in whole project (#377)
1 parent 60b9692 commit 35a2d55

File tree

25 files changed

+148
-81
lines changed

25 files changed

+148
-81
lines changed

apps/roam/scripts/compile.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ import esbuild from "esbuild";
22
import fs from "fs";
33
import path from "path";
44
import { z } from "zod";
5-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
6-
// import { envContents } from "@repo/database/dbDotEnv";
7-
const { envContents } = require("@repo/database/dbDotEnv");
5+
let envContents = null;
6+
7+
try {
8+
const dbDotEnv = require("@repo/database/dbDotEnv");
9+
envContents = dbDotEnv.envContents;
10+
} catch (error) {
11+
if ((error as Error).message.includes("Cannot find module")) {
12+
console.error("Build the database module before compiling roam");
13+
process.exit(1);
14+
}
15+
throw error;
16+
}
817

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

apps/roam/scripts/deploy.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ 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";
6+
import { execSync } from "child_process";
57

68
if (process.env.NODE_ENV !== "production") {
7-
require("dotenv").config();
9+
config();
810
}
911

1012
const deploy = async () => {
@@ -38,10 +40,7 @@ const deploy = async () => {
3840
// 2. GitHub Actions environment variable for pushes/tags
3941
process.env.GITHUB_REF_NAME ||
4042
// 3. Local Git branch resolution
41-
require("child_process")
42-
.execSync("git rev-parse --abbrev-ref HEAD")
43-
.toString()
44-
.trim() ||
43+
execSync("git rev-parse --abbrev-ref HEAD").toString().trim() ||
4544
// 4. Final fallback
4645
"main";
4746

apps/roam/src/utils/conceptConversion.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import getDiscourseRelations from "./getDiscourseRelations";
33
import type { DiscourseRelation } from "./getDiscourseRelations";
44
import type { SupabaseContext } from "~/utils/supabaseContext";
55

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

128
const getNodeExtraData = (
139
node_uid: string,

apps/roam/src/utils/hyde.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getLoggedInClient } from "./supabaseContext";
33
import { Result } from "./types";
44
import normalizePageTitle from "roamjs-components/queries/normalizePageTitle";
55
import findDiscourseNode from "./findDiscourseNode";
6-
const { nextApiRoot } = require("@repo/utils/execContext");
6+
import { nextApiRoot } from "@repo/utils/execContext";
77

88
type ApiEmbeddingResponse = {
99
data: Array<{
@@ -93,11 +93,11 @@ const generateHypotheticalNode: HypotheticalNodeGenerator = async ({
9393
}) => {
9494
const { relationLabel, relatedNodeText, relatedNodeFormat } = relationType;
9595

96-
const userPromptContent = `Given the source discourse node \`\`\`${node}\`\`\`,
97-
and considering the relation \`\`\`${relationLabel}\`\`\`
98-
which typically connects to a node of type \`\`\`${relatedNodeText}\`\`\`
99-
(formatted like \`\`\`${relatedNodeFormat}\`\`\`),
100-
generate a hypothetical related discourse node text that would plausibly fit this relationship.
96+
const userPromptContent = `Given the source discourse node \`\`\`${node}\`\`\`,
97+
and considering the relation \`\`\`${relationLabel}\`\`\`
98+
which typically connects to a node of type \`\`\`${relatedNodeText}\`\`\`
99+
(formatted like \`\`\`${relatedNodeFormat}\`\`\`),
100+
generate a hypothetical related discourse node text that would plausibly fit this relationship.
101101
Only return the text of the hypothetical node.`;
102102
const requestBody = {
103103
documents: [{ role: "user", content: userPromptContent }],

apps/roam/src/utils/supabaseContext.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@ import getRoamUrl from "roamjs-components/dom/getRoamUrl";
66
import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage";
77
import getBlockProps from "~/utils/getBlockProps";
88
import setBlockProps from "~/utils/setBlockProps";
9-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
10-
// import type { Enums } from "@repo/database/dbTypes";
11-
// import type { DGSupabaseClient } from "@repo/database/lib/client";
12-
// import {
13-
// fetchOrCreateSpaceDirect,
14-
// fetchOrCreatePlatformAccount,
15-
// createLoggedInClient,
16-
// } from "@repo/database/lib/contextFunctions";
17-
const {
9+
import type { Enums } from "@repo/database/dbTypes";
10+
import type { DGSupabaseClient } from "@repo/database/lib/client";
11+
import {
1812
fetchOrCreateSpaceDirect,
1913
fetchOrCreatePlatformAccount,
2014
createLoggedInClient,
21-
} = require("@repo/database/lib/contextFunctions");
22-
// TEMP TODO: Change to apps/roam to ESM
23-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
24-
type DGSupabaseClient = any; // Supabase client type
25-
type Enums<T> = T extends "Platform" ? "Roam" | "Obsidian" : never;
15+
} from "@repo/database/lib/contextFunctions";
2616

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

apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22
import { type RoamDiscourseNodeData } from "./getAllDiscourseNodesSince";
33
import { type SupabaseContext } from "./supabaseContext";
4-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
5-
const { nextApiRoot } = require("@repo/utils/execContext");
4+
import { nextApiRoot } from "@repo/utils/execContext";
65
type LocalContentDataInput = any;
76
type DGSupabaseClient = any;
87
type Json = any;

apps/roam/tsconfig.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"extends": "@repo/typescript-config/react-library.json",
3-
"include": ["src", "src/types.d.ts", "tailwind.config.ts", "tests", "scripts"],
3+
"include": [
4+
"src",
5+
"src/types.d.ts",
6+
"tailwind.config.ts",
7+
"tests",
8+
"scripts"
9+
],
410
"compilerOptions": {
511
"baseUrl": ".",
612
"outDir": "dist",
713
"allowJs": false,
8-
"esModuleInterop": false,
9-
"forceConsistentCasingInFileNames": true,
10-
"jsx": "react",
1114
"noUncheckedIndexedAccess": false
1215
}
1316
}

apps/website/next.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ const nextConfig = {
55
serverRuntimeConfig: {
66
maxDuration: 300,
77
},
8-
transpilePackages: ["@repo/database", "@repo/utils", "@repo/ui"],
98
};
109
export default nextConfig;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/database/cucumber.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"default": {
3-
"loader": ["ts-node/esm"],
4-
"import": ["features/step-definitions/**/*.ts"]
3+
"requireModule": ["ts-node/register"],
4+
"require": ["features/step-definitions/**/*.ts"]
55
}
66
}

0 commit comments

Comments
 (0)