Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Aug 26, 2025

https://linear.app/discourse-graphs/issue/ENG-785/use-commonjs-in-whole-project

  • Remove module from database, and adjust code accordingly
  • One exception gets kept as a mts file.
  • Ensure all projects' builds result in a dist folder.
  • Revert most of ENG-767 Roam tsc fixes #359, so we use imports instead of require.

Note: At this point, cucumber tests are broken, still working on that.

Summary by CodeRabbit

  • Bug Fixes

    • Hypothetical node generation now returns only the node text, producing cleaner, more consistent results.
  • Chores

    • Standardized module system and imports across packages.
    • Updated TypeScript configs and added build/type-check scripts to improve build reliability.
    • Removed explicit package transpilation from the website configuration.

@linear
Copy link

linear bot commented Aug 26, 2025

@supabase
Copy link

supabase bot commented Aug 26, 2025

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 26, 2025

📝 Walkthrough

Walkthrough

Repo-wide shift from ESM to CommonJS across multiple packages, associated TypeScript config updates to emit builds, and script entry-point checks adjusted. Several Roam utilities switched to ES imports and centralized types. One prompt in hyde.ts was condensed with an added output constraint. Next.js website config removed transpilePackages.

Changes

Cohort / File(s) Summary
Roam utils: import/type source updates
apps/roam/src/utils/conceptConversion.ts, apps/roam/src/utils/supabaseContext.ts, apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts
Replace CommonJS requires with ES imports; source LocalConceptDataInput and context types/functions from @repo packages; no runtime logic changes.
Roam hyde prompt + import
apps/roam/src/utils/hyde.ts
Switch to ES import; reformat userPromptContent and add directive “Only return the text of the hypothetical node.”; signatures unchanged.
Website Next config
apps/website/next.config.ts
Remove transpilePackages (["@repo/database","@repo/utils","@repo/ui"]).
Database ESM→CJS config shift
packages/database/package.json, packages/database/tsconfig.json, packages/database/cucumber.json
Remove "type":"module"; enable emit and esModuleInterop; switch Cucumber from loader/import to requireModule/require; adjust scripts (add tsc pre-step, use .mts for env generation).
Database scripts entry/dirname changes
packages/database/scripts/build.ts, .../scripts/deploy.ts, .../scripts/lint.ts, packages/database/src/dbDotEnv.ts
Replace import.meta.url usage with __filename/__dirname; adjust main-guard checks; minor formatting; add runtime console.log of dirname in dbDotEnv.ts.
ESLint config package module type
packages/eslint-config/package.json
Remove "type":"module".
UI package build enablement
packages/ui/package.json, packages/ui/tsconfig.json
Remove "type":"module"; add "build":"tsc"; set outDir:"dist".
Utils package build enablement
packages/utils/package.json, packages/utils/tsconfig.json
Remove "type":"module"; add "build" and "check-types" scripts; enable emit with rootDir "." and outDir "dist".

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (10)
apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts (4)

48-52: Safer URL construction to prevent double slashes and missing protocol

Concatenating strings can yield //embeddings... or miss a slash depending on nextApiRoot(). Using URL is more robust.

Apply this minimal change:

-    const response = await fetch(nextApiRoot() + "/embeddings/openai/small", {
+    const response = await fetch(
+      new URL("/embeddings/openai/small", nextApiRoot()).toString(),
+      {
         method: "POST",
         headers: { "Content-Type": "application/json" },
         body: JSON.stringify({ input: batch }),
-    });
+      }
+    );

Optional follow-up: add a simple retry with exponential backoff for transient 429/5xx responses.

// place near top-level
async function fetchWithRetry(input: RequestInfo, init: RequestInit, max = 3) {
  let attempt = 0, lastErr: unknown;
  while (attempt++ < max) {
    try {
      const res = await fetch(input, init);
      if (res.ok) return res;
      // Retry on throttling and 5xx
      if (res.status === 429 || (res.status >= 500 && res.status < 600)) {
        await new Promise(r => setTimeout(r, 250 * 2 ** (attempt - 1)));
      } else {
        return res; // non-retryable
      }
    } catch (e) {
      lastErr = e;
      await new Promise(r => setTimeout(r, 250 * 2 ** (attempt - 1)));
    }
  }
  if (lastErr) throw lastErr;
  // Final attempt
  return fetch(input, init);
}

Then replace the fetch(...) call accordingly.


128-131: Early return hides actionable errors when missing Supabase context

The function logs and returns when userId is missing. Upstream callers won’t know it silently aborted.

Consider either:

  • Throwing a typed error (preferred), or
  • Returning a discriminated union { ok: false, error: 'NoSupabaseContext' } and documenting it.

This keeps failure handling explicit.


151-156: Mismatch case should fail loudly (throw) to avoid partial ingestion

A mismatch between nodes and embeddings indicates a data integrity issue. Logging and returning can leave the system in an inconsistent or confusing state.

Throw an error here and let the caller decide whether to retry or abort the whole ingestion batch.


5-7: Replace local any aliases with exported database types

To strengthen type safety and catch mismatches at compile time, import the actual types from @repo/database instead of using any aliases. We’ve located the canonical definitions:

  • LocalContentDataInput is exported from @repo/database/inputTypes
  • DGSupabaseClient is exported from @repo/database/lib/client
  • Json is exported from @repo/database/dbTypes

In apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts, replace the local aliases at the top of the file:

- type LocalContentDataInput = any;
- type DGSupabaseClient    = any;
- type Json                 = any;
+ import type { LocalContentDataInput } from '@repo/database/inputTypes';
+ import type { DGSupabaseClient }      from '@repo/database/lib/client';
+ import type { Json }                  from '@repo/database/dbTypes';

This will ensure that any structural changes to your database types are caught by the compiler rather than at runtime.

packages/database/scripts/deploy.ts (2)

75-75: Prefer Node’s canonical CJS entry-point guard

__filename === process.argv[1] can fail with symlinks or when invoked through wrappers. The conventional CJS guard is more robust.

Apply:

-if (__filename === process.argv[1]) main();
+if (require.main === module) main();

16-27: Make the “on main and pristine” check resilient to ahead/behind decorations

The exact comparison to "## main...origin/main" breaks when Git adds [ahead N], [behind N], or additional status hints. This can mistakenly skip or proceed with deployments.

Refactor to:

  • Determine branch via git rev-parse --abbrev-ref HEAD and compare to "main".
  • Ensure a clean tree via git status --porcelain being empty.

I can propose a minimal diff if you want this hardened in this PR.

packages/database/package.json (1)

14-22: Dev/build/genenv flow looks good—consider an explicit env-generation step

The repository’s tsconfig.json in packages/database already excludes the supabase directory, so TypeScript won’t traverse serverless files during builds.

  • LGTM on using tsx scripts/createEnv.mts (ESM exception).
  • The current build script (tsc && tsx scripts/build.ts && npm run genenv -- local) still writes environment artifacts as part of a full build. To prevent accidental file mutations in CI or downstream workspace builds, consider:
    • Extracting env generation into a dedicated npm target (e.g., "build:env": "npm run genenv -- local").
    • Optionally invoking that target in a postbuild hook gated by a CI-only environment variable.
packages/database/scripts/lint.ts (1)

6-8: Path base is correctly switched to __filename/__dirname for CJS

This removes the import.meta.url dependency and matches the repo-wide CommonJS target. One nit: for consistency with other Node built-ins in this file (node:child_process, node:fs), consider importing from node:path rather than path.

apps/roam/src/utils/supabaseContext.ts (1)

9-16: Type-only imports + centralizing db types: LGTM; minor consistency nit

Great move using import type for Enums and DGSupabaseClient, and pulling runtime fns from a single module. One nit: you define const platform: Platform = "Roam" but still pass string literals later—prefer the variable for consistency and fewer typos.

Apply:

-      const userId = await fetchOrCreatePlatformAccount({
-        platform: "Roam",
+      const userId = await fetchOrCreatePlatformAccount({
+        platform,
         accountLocalId,
         name: personName,
         email: personEmail,
         spaceId,
         password: spacePassword,
       });
-      _contextCache = {
-        platform: "Roam",
+      _contextCache = {
+        platform,
         spaceId,
         userId,
         spacePassword,
       };
apps/roam/src/utils/hyde.ts (1)

96-101: Tighten output-shaping in prompt; trim response

The added constraint helps. Make it even stricter to avoid quotes/fences leaking into downstream embedding/search, and trim the returned text.

Update the prompt:

-Only return the text of the hypothetical node.
+Only return the text of the hypothetical node, with no surrounding quotes, code fences, or commentary. Do not prefix or suffix anything.

Additionally, trim the LLM response (outside this hunk):

-    return await response.text();
+    return (await response.text()).trim();

Consider a safe timeout fallback—AbortSignal.timeout isn’t supported in all browsers/Roam environments:

// near the fetch call
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), API_CONFIG.LLM.TIMEOUT_MS);
try {
  response = await fetch(API_CONFIG.LLM.URL, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(requestBody),
    signal: controller.signal,
  });
} finally {
  clearTimeout(timer);
}

Please verify whether AbortSignal.timeout exists in your target runtime; if yes, keep it. If not, use the fallback shown above.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2f8f435 and 2884b73.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (17)
  • apps/roam/src/utils/conceptConversion.ts (1 hunks)
  • apps/roam/src/utils/hyde.ts (2 hunks)
  • apps/roam/src/utils/supabaseContext.ts (1 hunks)
  • apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts (1 hunks)
  • apps/website/next.config.ts (0 hunks)
  • packages/database/cucumber.json (1 hunks)
  • packages/database/package.json (1 hunks)
  • packages/database/scripts/build.ts (2 hunks)
  • packages/database/scripts/deploy.ts (1 hunks)
  • packages/database/scripts/lint.ts (2 hunks)
  • packages/database/src/dbDotEnv.ts (1 hunks)
  • packages/database/tsconfig.json (1 hunks)
  • packages/eslint-config/package.json (0 hunks)
  • packages/ui/package.json (1 hunks)
  • packages/ui/tsconfig.json (1 hunks)
  • packages/utils/package.json (1 hunks)
  • packages/utils/tsconfig.json (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/eslint-config/package.json
  • apps/website/next.config.ts
🧰 Additional context used
🧠 Learnings (11)
📚 Learning: 2025-06-22T10:40:52.752Z
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:18-31
Timestamp: 2025-06-22T10:40:52.752Z
Learning: In apps/roam/src/utils/getAllDiscourseNodesSince.ts, the user confirmed that querying for `?title` with `:node/title` and mapping it to the `text` field in the DiscourseGraphContent type is the correct implementation for retrieving discourse node content from Roam Research, despite it appearing to query page titles rather than block text content.

Applied to files:

  • apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts
  • apps/roam/src/utils/hyde.ts
  • apps/roam/src/utils/supabaseContext.ts
📚 Learning: 2025-06-22T10:40:21.679Z
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:15-16
Timestamp: 2025-06-22T10:40:21.679Z
Learning: In the getAllDiscourseNodesSince function in apps/roam/src/utils/getAllDiscourseNodesSince.ts, date validation is performed before the function is called, so additional date validation within the function is not needed.

Applied to files:

  • apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts
📚 Learning: 2025-06-25T18:11:58.352Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: apps/website/eslint.config.mjs:6-13
Timestamp: 2025-06-25T18:11:58.352Z
Learning: In TypeScript ESLint parser options, `parserOptions.project: true` is a valid boolean value that has been supported since version 5.52.0. When set to `true`, it automatically finds the nearest `tsconfig.json` file for each source file being linted, eliminating the need to specify explicit paths like `"./tsconfig.json"`. This is especially useful for monorepos and projects with multiple TypeScript configurations.

Applied to files:

  • packages/utils/tsconfig.json
📚 Learning: 2025-06-25T18:03:52.669Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.

Applied to files:

  • packages/database/package.json
  • packages/database/scripts/build.ts
📚 Learning: 2025-07-22T01:50:20.253Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-22T01:50:20.253Z
Learning: In packages/database/scripts/create_env.ts, the Vercel CLI integration uses both vercel/sdk for deployment queries and vercel CLI for environment variable pulling, with support for different variants (local, branch, production, all) and proper team/project configuration with discourse-graphs defaults.

Applied to files:

  • packages/database/package.json
📚 Learning: 2025-05-22T23:48:45.450Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/scripts/deploy.ts:0-0
Timestamp: 2025-05-22T23:48:45.450Z
Learning: The database deployment script in packages/database/scripts/deploy.ts requires that the branch is 'main' and pristine (no uncommitted or unpushed changes) before allowing deployment to proceed.

Applied to files:

  • packages/database/scripts/deploy.ts
📚 Learning: 2025-06-17T23:37:45.289Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `type` serves as the unique identifier field, not a type classification field. The interface has no `uid` or `id` field, making `node.type` the correct field to use for UID-related operations.

Applied to files:

  • apps/roam/src/utils/conceptConversion.ts
📚 Learning: 2025-06-17T23:37:45.289Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `node.type` serves as the UID field rather than having a conventional `node.uid` field. This is an unusual naming convention where the type field actually contains the unique identifier.

Applied to files:

  • apps/roam/src/utils/conceptConversion.ts
📚 Learning: 2025-07-21T14:22:20.752Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Applied to files:

  • apps/roam/src/utils/supabaseContext.ts
  • packages/database/scripts/build.ts
📚 Learning: 2025-05-30T14:49:24.016Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Applied to files:

  • apps/roam/src/utils/supabaseContext.ts
📚 Learning: 2025-07-13T16:47:14.352Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.

Applied to files:

  • packages/database/scripts/build.ts
🔇 Additional comments (6)
apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts (1)

4-4: Named export confirmed; no change required

The function nextApiRoot is declared as a named export in packages/utils/src/execContext.ts (line 3), and all existing imports use named syntax. There is no default export for nextApiRoot, so the current import

import { nextApiRoot } from "@repo/utils/execContext";

is correct and poses no risk of runtime breakage. You can safely ignore the suggestion to switch to a default import.

Likely an incorrect or invalid review comment.

packages/database/scripts/lint.ts (1)

69-69: Entry-point guard works under tsx/Node for CJS

if (__filename === process.argv[1]) is a reliable direct-execution check after the CJS migration. LGTM.

apps/roam/src/utils/hyde.ts (1)

6-6: Import migration to ES module is correct

Switching nextApiRoot to an ES import from @repo/utils/execContext matches the repo-wide CommonJS/ESM consolidation. No functional changes.

apps/roam/src/utils/conceptConversion.ts (1)

6-6: Centralizing LocalConceptDataInput type import: LGTM

Importing the shared type from @repo/database/inputTypes reduces duplication and keeps schema coupling in one place. The functions using it remain type-safe, and usage of node.type as UID aligns with prior decisions in this codebase.

packages/database/scripts/build.ts (2)

17-20: Write file restructuring: LGTM

Multiline writeFileSync with a header improves readability; behavior stays identical.


6-6: Confirmed CJS context for build script; no changes needed

  • packages/database/package.json has no "type" field (defaults to CommonJS)
  • The build command (tsc && tsx scripts/build.ts …) runs under that CJS context, so __filename will be defined and dirname(__filename) safe

@maparent maparent force-pushed the eng-785-use-commonjs-in-whole-project branch from 2884b73 to c73ec8c Compare August 27, 2025 02:24
@maparent
Copy link
Collaborator Author

maparent commented Aug 27, 2025

@mdroidian ok, this is functional. cucumber works. build, dev and check-types succeed locally.
What fails in deployment: tsc of packages is done with no-emit, so tsc of apps fails to find the declarations. Will give a look on how to fix that tomorrow morning, but otherwise it's ready for review.

@maparent maparent requested a review from mdroidian August 27, 2025 02:29
@maparent
Copy link
Collaborator Author

ok check-types was easy to solve, now stumped by deploy issue. Works locally (even after wiping all dist folders.)

@maparent
Copy link
Collaborator Author

Ok, did fail locally after wiping dist after all. Not sure what I did wrong the first time. So... does deploy not come after a build?

@mdroidian
Copy link
Contributor

Error: Cannot find module '/home/runner/work/discourse-graph/discourse-graph/node_modules/@repo/database/dist/src/dbDotEnv.js'

FYI, This is still being imported via require. Is that the issue?

const { envContents } = require("@repo/database/dbDotEnv");

Search for https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm to find all the other require references.

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

"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

@maparent
Copy link
Collaborator Author

Error: Cannot find module '/home/runner/work/discourse-graph/discourse-graph/node_modules/@repo/database/dist/src/dbDotEnv.js'

FYI, This is still being imported via require. Is that the issue?

No, but it did ultimately point to the issue.

I asked if roam was built before deploy, and it is, through compile. But compile now uses dbDotEnv, and that is only built when the database is built.
I can think of three ways to fix this:

  1. quick and dirty, already pushed: build the database before calling deploy.
  2. Detect in scripts/compile that dbDotEnv is missing, and build it at need. (And then yes we'd use require.) This cross-build breaks encapsulation a bit, imho.
  3. another option: Recode dbDotEnv as js directly, so we don't have to build it.

2 and 3 are more complex, I want your feedback on whether it's worth doing.

I went to import, and then back to require so I could give a better error message when the database is not built.

@maparent maparent requested a review from mdroidian August 27, 2025 13:55
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

  1. quick and dirty, already pushed: build the database before calling deploy.

If deploy always requires this, then I think we could achieve this via turbo.json with something like "dependsOn": ["@repo/database#build"], It would then be in a single place.

But I'll leave that up to you.

@maparent maparent force-pushed the eng-785-use-commonjs-in-whole-project branch from f65b855 to dac8623 Compare August 27, 2025 22:41
@maparent maparent merged commit 35a2d55 into main Aug 27, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 27, 2025
@maparent maparent deleted the eng-785-use-commonjs-in-whole-project branch August 27, 2025 23:19
@maparent
Copy link
Collaborator Author

I got your latest comment by mail but do not see it here? Solved in #801.

Copy link
Contributor

I think npm i actually solved it for me

@maparent
Copy link
Collaborator Author

maparent commented Aug 28, 2025

Process to reproduce the issue :

  1. rm -rf projects/*/dist apps/*/dist
  2. turbo dev
    Process to avoid the issue: intercalate
    turbo build -F @repo/database
    Reason: roam expects to use dbDotEnv in its compiled form.
    Solution: Probably make dbDotEnv into a js file? (cf ENG-799)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants