Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Sep 1, 2025

https://linear.app/discourse-graphs/issue/ENG-815/treat-dbdotenv-like-a-normal-ts-file-rather-than-separate-js-and-dts

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.ts; cucumber can use it by reference.
Then dbDotEnv can then be a .mts module. We then have to require it everywhere.
Ensure stepdef and scripts are type-checked, now that they're not compiled.

Summary by CodeRabbit

  • New Features
    • No user-facing changes.
  • Refactor
    • Standardized how environment utilities are loaded across apps for consistency and reliability.
    • Added explicit typings to environment utilities to improve type safety.
  • Chores
    • Updated package exports to use built artifacts for more predictable builds.
    • Switched type-checking to a dedicated lint configuration and streamlined compiler includes to source files.
    • Introduced a separate TypeScript config for lint/type emission across scripts and features.

Impact: Stability and build consistency improvements with no changes to user workflows.

@linear
Copy link

linear bot commented Sep 1, 2025

ENG-815 DbDotenv.d.ts

@supabase
Copy link

supabase bot commented Sep 1, 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

maparent commented Sep 1, 2025

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 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 Sep 1, 2025

📝 Walkthrough

Walkthrough

Standardizes consumers to use CommonJS require for @repo/database/dbDotEnv, updates @repo/database export map to dist-built artifacts, adds explicit TypeScript types in dbDotEnv source, narrows tsconfig includes, introduces a lint tsconfig for declaration emit, adjusts internal scripts to import dbDotEnv locally, and removes legacy types file.

Changes

Cohort / File(s) Summary
Switch consumers to CommonJS require for dbDotEnv
apps/roam/scripts/compile.ts, apps/roam/scripts/deploy.ts, apps/website/app/utils/supabase/middleware.ts, apps/website/app/utils/supabase/server.ts, apps/website/next.config.ts
Replace ES module imports with require(...) for envContents/config; in compile.ts, remove local try/catch around require so load errors bubble to existing top-level error handling.
Database package export map and scripts
packages/database/package.json
Point ./dbDotEnv export to ./dist/src/* for import/require/default and types (.d.mts), replacing non-dist paths; update check-types script to use tsc -p tsconfig_lint.json.
Type annotations in dbDotEnv source
packages/database/src/dbDotEnv.mts
Add exported Variant type; add explicit return types for getVariant, envFilePath, envContents, and config; cast return for getVariant. No runtime logic changes.
Internal scripts use local dbDotEnv
packages/database/scripts/build.ts, packages/database/scripts/dev.ts
Change imports of getVariant from package alias to relative ../src/dbDotEnv.mts.
TS config scope adjustments
packages/database/tsconfig.json, packages/database/tsconfig_lint.json
Narrow main tsconfig include to ./src/**/*; add new tsconfig_lint.json extending base config, emitting declarations from src/scripts/features, excluding supabase.
Step definitions import style
packages/database/features/step-definitions/stepdefs.ts
Replace ES module named imports of getVariant/config with CommonJS require(...).
Remove legacy types entry
packages/database/types/dbDotEnv.d.ts
Delete previously committed type declarations; types now come from dist via export map.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs


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 or @coderabbit 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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/database/src/dbDotEnv.mts (1)

13-19: Potential infinite loop if “database” segment isn’t found (bundled paths, atypical installs). Throw instead of looping to root.

When the file is bundled (e.g., .next/server/chunks), the path may never include “database”, causing dirname(dir) to stabilize at root and loop forever.

Apply:

-const findRoot = () => {
-  let dir = fileURLToPath(import.meta.url);
-  while (basename(dir) !== "database") {
-    dir = dirname(dir);
-  }
-  return dir;
-};
+const findRoot = () => {
+  let dir = dirname(fileURLToPath(import.meta.url));
+  // Walk up until we hit the package root folder named "database".
+  while (basename(dir) !== "database") {
+    const parent = dirname(dir);
+    if (parent === dir) {
+      throw new Error(
+        `dbDotEnv: could not locate "database" package root from ${fileURLToPath(
+          import.meta.url,
+        )}`,
+      );
+    }
+    dir = parent;
+  }
+  return dir;
+};
packages/database/package.json (1)

33-35: Stale typesVersions entry for ./dbDotEnv

This still targets the removed src/dbDotEnv.d.ts. It will break type resolution for editors/older TS versions.

Apply this diff:

       "./dbDotEnv": [
-        "src/dbDotEnv.d.ts"
+        "dist/src/dbDotEnv.d.mts"
       ],
🧹 Nitpick comments (8)
packages/database/tsconfig.json (1)

3-9: Align rootDir with package exports

  • Change "rootDir" in packages/database/tsconfig.json from "." to "src".
  • Update the exports["./dbDotEnv"] paths in packages/database/package.json from ./dist/src/dbDotEnv.*./dist/dbDotEnv.* to match the new output location.
  • No changes needed for tsconfig_lint.json.
packages/database/src/dbDotEnv.mts (2)

21-36: Tighten typing for variant and simplify validation via Set to drop the cast.

Avoid casting by tracking variant as Variant | undefined and validating with a Set.

Apply:

-export const getVariant = (): Variant => {
+export const getVariant = (): Variant => {
   const processHasVars =
     !!process.env["SUPABASE_URL"] && !!process.env["SUPABASE_ANON_KEY"];
   const useDbArgPos = (process.argv || []).indexOf("--use-db");
-  let variant =
-    useDbArgPos > 0
-      ? process.argv[useDbArgPos + 1]
-      : process.env["SUPABASE_USE_DB"];
+  const allowed = new Set<Variant | undefined>([
+    "local",
+    "branch",
+    "production",
+    "none",
+    "implicit",
+    undefined,
+  ]);
+  let variant: Variant | undefined =
+    useDbArgPos > 0
+      ? (process.argv[useDbArgPos + 1] as Variant | undefined)
+      : (process.env["SUPABASE_USE_DB"] as Variant | undefined);
 
-  if (
-    ["local", "branch", "production", "none", "implicit", undefined].indexOf(
-      variant,
-    ) === -1
-  ) {
+  if (!allowed.has(variant)) {
     throw new Error("Invalid variant: " + variant);
   }
@@
   // avoid repeating warnings
   process.env["SUPABASE_USE_DB"] = variant;
-  return variant as Variant;
+  return variant;
 };

Also applies to: 38-61


63-83: Minor: clarify return shape and keys; consider narrowing to known keys for stronger typing.

If you want stricter typing at call sites, you can expose a dedicated Env map type and return that, while still allowing partials.

Example (no change required now):

export type SupabaseEnv = Partial<{
  SUPABASE_URL: string;
  SUPABASE_ANON_KEY: string;
  NEXT_API_ROOT: string;
}>;
export const envContents = (): SupabaseEnv => { /* ... */ };
packages/database/scripts/dev.ts (1)

3-3: Same resolution concern as build.ts: confirm ESM TS loader availability.

If environments vary, consider lazy dynamic import with a helpful error or a small shim that resolves either local src or the published package.

Example shim (optional):

// dbDotEnvShim.ts
export const getVariant = async () =>
  (await import("../src/dbDotEnv.mts")).getVariant;
apps/website/app/utils/supabase/server.ts (1)

4-4: Preserve types when using CommonJS require by annotating the shape.

Current require erases types; add a minimal annotation to keep type-checks downstream.

Apply:

-const { envContents } = require("@repo/database/dbDotEnv");
+const { envContents } = require("@repo/database/dbDotEnv") as {
+  envContents: () => Partial<Record<string, string>>;
+};
packages/database/tsconfig_lint.json (1)

1-19: Ensure declaration emit actually happens; consider clarifying config intent.

If base config doesn’t set "declaration": true, "emitDeclarationOnly": true won’t emit anything. Also, if this file is used for type-checking only, "noEmit": true might be preferable; if it’s for .d.ts generation, consider renaming to tsconfig.types.json for clarity.

If needed, add:

   "compilerOptions": {
     "baseUrl": ".",
     "rootDir": ".",
     "outDir": "dist",
     "module": "esnext",
     "moduleResolution": "bundler",
     "allowImportingTsExtensions": true,
+    "declaration": true,
     "emitDeclarationOnly": true
   },
apps/roam/scripts/compile.ts (1)

21-21: LGTM on require; add a guard to avoid embedding "undefined" strings into build.

Validate presence of required envs before esbuild.define, and prefer JSON.stringify for safety.

Add after const dbEnv = envContents();:

if (!dbEnv.SUPABASE_URL || !dbEnv.SUPABASE_ANON_KEY) {
  throw new Error("Missing SUPABASE_URL or SUPABASE_ANON_KEY for compile");
}

And adjust define:

define: {
  "process.env.SUPABASE_URL": JSON.stringify(dbEnv.SUPABASE_URL),
  "process.env.SUPABASE_ANON_KEY": JSON.stringify(dbEnv.SUPABASE_ANON_KEY),
  "process.env.NEXT_API_ROOT": JSON.stringify(dbEnv.NEXT_API_ROOT || ""),
  "window.__DISCOURSE_GRAPH_VERSION__": JSON.stringify(getVersion()),
  "window.__DISCOURSE_GRAPH_BUILD_DATE__": JSON.stringify(getBuildDate()),
},
packages/database/features/step-definitions/stepdefs.ts (1)

5-5: Keep type safety when switching to CommonJS require

require() erases types in TS. Cast the module to its declared type so getVariant/config remain typed.

Apply this diff:

-const { getVariant, config } = require("@repo/database/dbDotEnv");
+const { getVariant, config } =
+  require("@repo/database/dbDotEnv") as typeof import("@repo/database/dbDotEnv");
📜 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 94b1da7 and 8648408.

📒 Files selected for processing (13)
  • apps/roam/scripts/compile.ts (1 hunks)
  • apps/roam/scripts/deploy.ts (1 hunks)
  • apps/website/app/utils/supabase/middleware.ts (1 hunks)
  • apps/website/app/utils/supabase/server.ts (1 hunks)
  • apps/website/next.config.ts (1 hunks)
  • packages/database/features/step-definitions/stepdefs.ts (1 hunks)
  • packages/database/package.json (2 hunks)
  • packages/database/scripts/build.ts (1 hunks)
  • packages/database/scripts/dev.ts (1 hunks)
  • packages/database/src/dbDotEnv.mts (4 hunks)
  • packages/database/tsconfig.json (1 hunks)
  • packages/database/tsconfig_lint.json (1 hunks)
  • packages/database/types/dbDotEnv.d.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/database/types/dbDotEnv.d.ts
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-08-31T17:38:52.730Z
Learning: The dbDotEnv functionality in packages/database/src/dbDotEnv.js is designed for Node.js environments only and will not be used in browser contexts.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#400
File: packages/database/src/dbDotEnv.js:24-31
Timestamp: 2025-08-31T17:37:17.131Z
Learning: The "all" variant for SUPABASE_USE_DB should only be used in createEnv.mts and not in the dbDotEnv module. It was incorrectly added to dbDotEnv.d.ts but should be removed to maintain proper separation of concerns.
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.
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.
📚 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/tsconfig.json
  • packages/database/tsconfig_lint.json
  • packages/database/package.json
📚 Learning: 2025-08-31T17:37:17.131Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#400
File: packages/database/src/dbDotEnv.js:24-31
Timestamp: 2025-08-31T17:37:17.131Z
Learning: The "all" variant for SUPABASE_USE_DB should only be used in createEnv.mts and not in the dbDotEnv module. It was incorrectly added to dbDotEnv.d.ts but should be removed to maintain proper separation of concerns.

Applied to files:

  • apps/website/app/utils/supabase/server.ts
  • packages/database/features/step-definitions/stepdefs.ts
  • packages/database/scripts/build.ts
  • apps/website/app/utils/supabase/middleware.ts
  • apps/roam/scripts/compile.ts
  • packages/database/scripts/dev.ts
  • packages/database/package.json
  • packages/database/src/dbDotEnv.mts
📚 Learning: 2025-08-27T02:23:45.632Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#377
File: packages/ui/tsconfig.json:5-7
Timestamp: 2025-08-27T02:23:45.632Z
Learning: When reviewing TypeScript configuration changes, check if settings like "declaration" are inherited from base configs before suggesting to add them explicitly. Many monorepo packages extend base configurations that already include necessary compiler options.

Applied to files:

  • packages/database/tsconfig_lint.json
📚 Learning: 2025-07-19T22:34:08.725Z
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Prettier with the project's configuration

Applied to files:

  • packages/database/tsconfig_lint.json
📚 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/database/tsconfig_lint.json
📚 Learning: 2025-08-31T17:38:52.730Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-08-31T17:38:52.730Z
Learning: The dbDotEnv functionality in packages/database/src/dbDotEnv.js is designed for Node.js environments only and will not be used in browser contexts.

Applied to files:

  • apps/website/next.config.ts
  • packages/database/scripts/build.ts
  • apps/roam/scripts/compile.ts
  • apps/roam/scripts/deploy.ts
  • packages/database/scripts/dev.ts
  • packages/database/package.json
📚 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/scripts/build.ts
  • apps/roam/scripts/deploy.ts
  • packages/database/scripts/dev.ts
📚 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:

  • apps/roam/scripts/compile.ts
  • apps/roam/scripts/deploy.ts
🔇 Additional comments (7)
packages/database/src/dbDotEnv.mts (1)

6-11: Good: Variant excludes the “all” value per ENG-815 constraints.

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

4-4: Verify ESM support for .mts imports
Importing "../src/dbDotEnv.mts" requires an ESM-aware TS runner (e.g. ts-node --esm or tsx). CI/dev currently has no ts-node/tsx references—confirm your script-runner setup supports loading .mts files.

apps/website/app/utils/supabase/middleware.ts (1)

3-11: Ignore dbDotEnv import in middleware.ts: updateSession in apps/website/app/utils/supabase/middleware.ts isn’t referenced anywhere in the repo, so there’s no Edge-runtime use of this Node-only module.

Likely an incorrect or invalid review comment.

apps/roam/scripts/deploy.ts (1)

5-10: LGTM: CommonJS require for dbDotEnv in a Node script is appropriate.

config() gated by NODE_ENV !== "production" is sensible; no issues.

apps/website/next.config.ts (1)

2-5: LGTM—No remaining ES imports for dbDotEnv
Search for import … from '@repo/database/dbDotEnv' returned no matches; it’s safe to load the env only in next.config.ts.

packages/database/package.json (2)

50-50: Lint config covers non-src TS tsconfig_lint.json’s include array already lists "./scripts//*" and "./features/step-definitions//*", ensuring step definitions and scripts are type-checked.


13-16: Ensure require export targets a CJS file

Update packages/database/package.json so that the require export points to a CommonJS build, and confirm that the file exists (or add a CJS build step). For example:

     "./dbDotEnv": {
       "types":  "./dist/src/dbDotEnv.d.mts",
       "import": "./dist/src/dbDotEnv.mjs",
-      "require": "./dist/src/dbDotEnv.mjs",
+      "require": "./dist/src/dbDotEnv.cjs",
       "default": "./dist/src/dbDotEnv.mjs"
     },

Verify that packages/database/dist/src/dbDotEnv.cjs is produced (or add a wrapper/build config).

@maparent
Copy link
Collaborator Author

maparent commented Sep 1, 2025

@CodeRabbit good call on typesVersions. Making types explicit in each require is anti-dry, not going that way. I did find the as typof import syntax interesting, but does not work everywhere... may be worth investigating. Also thinking about the impact of the shim.

@maparent maparent requested a review from mdroidian September 1, 2025 19:08
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for any shim-related code or configuration
rg -n -C3 "shim" --type=ts --type=js --type=json

# Look for any type assertion patterns or typeof import usage
rg -n -C2 "as typeof" --type=ts

# Check the current dbDotEnv implementation to understand the context
cat packages/database/src/dbDotEnv.mts

# Look at the package.json exports to understand the current module setup
cat packages/database/package.json | jq '.exports'

Length of output: 9080


@maparent Thanks for the feedback! I'm glad the typesVersions suggestion resonated with you.

You're absolutely right about avoiding explicit types in each require - that would indeed be anti-DRY and create maintenance overhead. The current approach with inline types in the .mts file and proper package.json exports is much cleaner.

Regarding the as typeof import syntax - it's a fascinating TypeScript pattern that can provide type-only imports without runtime overhead:

// This gets the type without importing the module
const someFunction = null as any as typeof import('./module').someFunction;

However, you're correct that it has limitations:

  • Doesn't work with default exports in all contexts
  • Can break with certain bundler configurations
  • Requires the module to be resolvable at compile time
  • Less IDE-friendly for autocomplete and navigation

For your shim concerns - I see you have the React useSyncExternalStore shim in compile.ts. If you're thinking about module interop shims more broadly, the current approach with dual CJS/ESM exports should minimize compatibility issues. The .d.mts types file properly signals to TypeScript that this is an ES module while still supporting CommonJS requires.

The build pipeline changes look solid - moving type declarations to the built artifacts in dist/ creates a cleaner separation between source and distribution, which should reduce any potential shim-related confusion.


✏️ Learnings added
Learnt from: maparent
URL: https://github.com/DiscourseGraphs/discourse-graph/pull/407

Timestamp: 2025-09-01T19:09:07.021Z
Learning: User prefers to avoid making types explicit in each require statement due to anti-DRY concerns when working with module imports in TypeScript.

Learnt from: maparent
URL: https://github.com/DiscourseGraphs/discourse-graph/pull/407

Timestamp: 2025-09-01T19:09:07.021Z
Learning: User finds the `as typeof import` TypeScript syntax interesting but acknowledges it doesn't work everywhere and may be worth investigating for future use.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@maparent
Copy link
Collaborator Author

maparent commented Sep 1, 2025

As stated, this seems to work for me; curious how it'll work for you.

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.

After removing and all dist, running npm i (because package-lock.json it is off), both turbo check-types and turbo dev -F roam fail

image image

@mdroidian
Copy link
Contributor

Build is failing too

image

@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch from 11e2366 to 8a91312 Compare September 9, 2025 16:07
@maparent
Copy link
Collaborator Author

@mdroidian Ok. I tried re-running this, and @repo/database had an old typescript@4.1, imposed by vercel, which does not pick up on some settings.
Bizarrely, overriding typescript@5 has no impact.
I updated vercel and obtained typescript@4.9, which does run.
I think... given that this PR will have to be updated to pnpm shortly, I think we should sit on this, hopefully overrides will be more sensible.

@maparent maparent marked this pull request as draft September 10, 2025 00:49
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch from efd241b to 0dd939a Compare September 10, 2025 15:47
@maparent maparent changed the base branch from main to eng-757-experiment-with-pnpm September 10, 2025 15:48
@maparent
Copy link
Collaborator Author

Rebased on pnpm branch, should be good to go.

@maparent maparent marked this pull request as ready for review September 10, 2025 15:49
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch from 0dd939a to a7a656b Compare September 11, 2025 17:28
@maparent maparent force-pushed the eng-757-experiment-with-pnpm branch from 9239965 to 7023fbf Compare September 11, 2025 17:30
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch 2 times, most recently from 05686ea to 210a59b Compare September 11, 2025 17:33
@maparent maparent force-pushed the eng-757-experiment-with-pnpm branch from 7023fbf to 81e0a27 Compare September 11, 2025 20:11
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch from 210a59b to 78dcbc7 Compare September 11, 2025 20:13
@maparent maparent force-pushed the eng-757-experiment-with-pnpm branch from 81e0a27 to 8181a98 Compare September 12, 2025 00:01
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch from 78dcbc7 to f3c2a6b Compare September 12, 2025 00:21
"default": "./src/dbDotEnv.mjs"
"types": "./dist/src/dbDotEnv.d.mts",
"import": "./dist/src/dbDotEnv.mjs",
"require": "./dist/src/dbDotEnv.mjs",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line annoys me; according to coderabbit, I should create a cjs wrapper and use it here.
Removing the line (as I did in the original PR) breaks the build. So may look into wrapping, even though things do work as-is.

@maparent maparent marked this pull request as draft September 28, 2025 04:18
@mdroidian mdroidian force-pushed the eng-757-experiment-with-pnpm branch from 8181a98 to a6b59ba Compare September 28, 2025 22:12
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch 2 times, most recently from a19ccaf to 209587d Compare September 29, 2025 19:03
Base automatically changed from eng-757-experiment-with-pnpm to main September 30, 2025 23:05
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch 2 times, most recently from 01c3c4c to 1d358a8 Compare October 1, 2025 12:55
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.
@maparent maparent force-pushed the ENG-815-normalize-dbDotEnv branch from 1d358a8 to 70a3f50 Compare October 12, 2025 23:51
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: No status

Development

Successfully merging this pull request may close these issues.

3 participants