Skip to content

Comments

chore: reduce atoms bundle size prisma types#24001

Merged
anikdhabal merged 6 commits intomainfrom
reduce-atoms-bundle-size-prisma-types
Sep 25, 2025
Merged

chore: reduce atoms bundle size prisma types#24001
anikdhabal merged 6 commits intomainfrom
reduce-atoms-bundle-size-prisma-types

Conversation

@ThyMinimalDev
Copy link
Contributor

@ThyMinimalDev ThyMinimalDev commented Sep 23, 2025

What does this PR do?

This change removes post-build copying of Prisma .d.ts files from the atoms build script. It introduces a new prisma-types module exporting JsonValue, JsonObject, and JsonArray. TypeScript config now includes Kysely types, the new prisma-types, and an interval limit schema. Vite config updates include aliasing Prisma client/runtime to local Kysely and prisma-types paths, adding @prisma/client to Rollup externals, and a dts beforeWriteFile hook to adjust a Kysely path in generated typings. Existing plugins remain unchanged.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • n/a - I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

@ThyMinimalDev ThyMinimalDev requested a review from a team September 23, 2025 11:24
@ThyMinimalDev ThyMinimalDev requested a review from a team as a code owner September 23, 2025 11:24
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

This change simplifies the atoms build script by removing post-build mkdir/cp steps that copied Prisma declaration files. It adds a prisma-types module exporting JsonValue/JsonObject/JsonArray and a kysely-types module exporting a ColumnType alias. tsconfig includes those new type files and an interval limit schema. Vite config updates add a dts beforeWriteFile hook to fix a kysely path, add @prisma/client to rollup externals, and rework aliases to point prisma-related imports to the new local prisma-types and kysely-types paths. A changeset for a minor atoms release was added.

Possibly related PRs

  • fix: Avoid using prisma types on client #23566: Also addresses Prisma types leaking into the client bundle by removing direct Prisma imports, related to this PR's introduction of lightweight prisma-type aliases and alias/build changes.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely and accurately reflects the primary change: reducing the atoms package bundle size by handling Prisma types differently, and the "chore:" prefix appropriately marks it as a non-functional change. It is short, related to the changeset, and clear enough for a reviewer to understand the main intent.
Description Check ✅ Passed The PR description directly describes the changes shown in the diff (removing post-build Prisma .d.ts copying, adding prisma-types, TS and Vite config updates, and the dts hook) and matches the stated objectives, so it is related to the changeset. The level of detail is adequate for this lenient check and gives useful context for reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch reduce-atoms-bundle-size-prisma-types

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@keithwillcode keithwillcode added core area: core, team members only foundation platform Anything related to our platform plan labels Sep 23, 2025
@dosubot dosubot bot added the 🧹 Improvements Improvements to existing features. Mostly UX/UI label Sep 23, 2025
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: 1

🧹 Nitpick comments (3)
packages/platform/atoms/prisma-types/index.ts (2)

5-9: Prefer JsonPrimitive + readonly shapes for better assignability and clarity

Slightly clearer and more flexible typing. Readonly avoids accidental mutation and widens assignability in consumers.

-export type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
-
-export type JsonObject = { [key: string]: JsonValue };
-
-export type JsonArray = Array<JsonValue>;
+export type JsonPrimitive = string | number | boolean | null;
+export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
+export type JsonObject = { readonly [key: string]: JsonValue };
+export type JsonArray = readonly JsonValue[];

1-4: Header path comment is misleading

Update the header to the actual file path to prevent confusion for future readers.

Suggested:

// packages/platform/atoms/prisma-types/index.ts
packages/platform/atoms/vite.config.ts (1)

82-84: Mirror these aliases in tsconfig paths

Keep TS and bundler resolution in sync to avoid dts path leakage. See my tsconfig comment for the exact paths entry.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 14b3344 and 58a0c16.

📒 Files selected for processing (4)
  • packages/platform/atoms/package.json (1 hunks)
  • packages/platform/atoms/prisma-types/index.ts (1 hunks)
  • packages/platform/atoms/tsconfig.json (1 hunks)
  • packages/platform/atoms/vite.config.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/platform/atoms/prisma-types/index.ts
  • packages/platform/atoms/vite.config.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/platform/atoms/prisma-types/index.ts
  • packages/platform/atoms/vite.config.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/platform/atoms/prisma-types/index.ts
  • packages/platform/atoms/vite.config.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: emrysal
PR: calcom/cal.com#23692
File: packages/lib/server/service/InsightsBookingBaseService.ts:16-16
Timestamp: 2025-09-09T03:29:43.025Z
Learning: In the Cal.com codebase, readonlyPrisma is still an instance of PrismaClient, making type changes from `typeof readonlyPrisma` to `PrismaClient` less critical since they are fundamentally compatible types.
📚 Learning: 2025-09-15T12:58:12.826Z
Learnt from: CR
PR: calcom/cal.com#0
File: AGENTS.md:0-0
Timestamp: 2025-09-15T12:58:12.826Z
Learning: Use `yarn build` to build all packages

Applied to files:

  • packages/platform/atoms/package.json
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (3)
packages/platform/atoms/package.json (1)

10-10: Verify generated types don't reference monorepo Prisma internals

No packages/platform/atoms/dist/.d.ts found (build not run) — after running yarn workspace @calcom/atoms build, confirm packages/platform/atoms/dist/.d.ts contain no '../../' imports or references to @prisma/client/runtime or @calcom/prisma/client/runtime/library (example check: rg -n --glob 'packages/platform/atoms/dist/**/*.d.ts' -e '\.\./\.\./' -e '@prisma/client/runtime' -e '@calcom/prisma/client/runtime/library' || true).

packages/platform/atoms/vite.config.ts (2)

53-62: Externalized @prisma/client — no runtime imports found in packages/platform/atoms

Searched packages/platform/atoms for non-type imports, dynamic imports, and require calls referencing @prisma/client and found none; externalizing is safe here.


26-37: Use a global replace — current replace only fixes the first occurrence

String.prototype.replace with a string argument only replaces the first match; switch to a global regex (or replaceAll) so all generated occurrences are fixed.

-        beforeWriteFile: (filePath, content) => {
-          // Check if the content includes the broken path from kysely
-          if (content.includes(`kysely/types.ts').$Enums`)) {
-            // Replace the broken path with the correct import
-            return {
-              filePath,
-              content: content.replace(`kysely/types.ts').$Enums`, `kysely/types.ts')`),
-            };
-          }
-          return { filePath, content };
-        },
+        beforeWriteFile: (filePath, content) => {
+          // Fix broken Kysely path in generated d.ts
+          const pattern = /kysely\/types\.ts'\)\.\$Enums/g;
+          if (pattern.test(content)) {
+            return {
+              filePath,
+              content: content.replace(pattern, "kysely/types.ts')"),
+            };
+          }
+          return { filePath, content };
+        },

Sanity-check generated .d.ts for remaining ".$Enums" references after the change (example): rg -n --hidden -S '.$Enums' packages/platform/atoms/dist -C3

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

🧹 Nitpick comments (2)
packages/platform/atoms/vite.config.ts (2)

22-38: Make the dts patch robust (quote-agnostic) and safer.

Use a regex that preserves the original quote and only removes .$Enums. This avoids missing double-quoted cases and reduces false positives.

Apply this diff:

       dts({
         insertTypesEntry: true,
-        beforeWriteFile: (filePath, content) => {
-          // Check if the content includes the broken path from kysely
-          if (content.includes(`kysely/types.ts').$Enums`)) {
-            // Replace the broken path with the correct import
-            return {
-              filePath,
-              content: content.replaceAll(`kysely/types.ts').$Enums`, `kysely/types.ts')`),
-            };
-          }
-          return { filePath, content };
-        },
+        beforeWriteFile: (filePath, content) => {
+          // Remove trailing `.$Enums` on imports from kysely/types.ts while preserving original quote
+          const patched = content.replace(/kysely\/types\.ts(['"])\)\.\$Enums/g, "kysely/types.ts$1)");
+          return { filePath, content: patched };
+        },
       }),

82-84: Resolve aliases relative to this file for stability across CWDs.

Use __dirname-based absolute paths to avoid resolution drift.

Apply this diff:

-        "@calcom/prisma/client/runtime/library": resolve("./prisma-types/index.ts"),
+        "@calcom/prisma/client/runtime/library": path.resolve(__dirname, "./prisma-types/index.ts"),
         "@calcom/prisma/client": path.resolve(__dirname, "../../kysely/types.ts"),
         kysely: path.resolve(__dirname, "./kysely-types/index.ts"),
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 58a0c16 and cb2bc2c.

📒 Files selected for processing (4)
  • .changeset/ninety-colts-search.md (1 hunks)
  • packages/platform/atoms/kysely-types/index.ts (1 hunks)
  • packages/platform/atoms/tsconfig.json (1 hunks)
  • packages/platform/atoms/vite.config.ts (3 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/platform/atoms/kysely-types/index.ts
  • .changeset/ninety-colts-search.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/platform/atoms/tsconfig.json
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/platform/atoms/vite.config.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/platform/atoms/vite.config.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/platform/atoms/vite.config.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (1)
packages/platform/atoms/vite.config.ts (1)

53-62: LGTM to externalize @prisma/client — confirm no runtime value imports

Externalizing is safe only if every import from @prisma/client and @calcom/prisma/client in packages/platform/atoms is type-only; verify there are no value imports. Run locally and inspect matches:

rg -n -S -g 'packages/platform/atoms/' '@prisma/client' --type ts --type tsx
rg -n -S -g 'packages/platform/atoms/
' '@calcom/prisma/client' --type ts --type tsx

To narrow to potential non-type imports (inspect results manually):

rg -n -S -g 'packages/platform/atoms/' '@prisma/client' --type ts --type tsx | rg -v '^\simport\s+type' | rg -v '^\simport\s+.{\stype'
rg -n -S -g 'packages/platform/atoms/
' '@calcom/prisma/client' --type ts --type tsx | rg -v '^\simport\s+type' | rg -v '^\simport\s+.{\stype'

If any non-type imports appear, convert them to type-only imports or remove @prisma/client from the bundle externals.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 2025

E2E results are ready!

@vercel
Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 24, 2025 11:00am
cal-eu Ignored Ignored Sep 24, 2025 11:00am

@anikdhabal anikdhabal merged commit 752cfa6 into main Sep 25, 2025
40 checks passed
@anikdhabal anikdhabal deleted the reduce-atoms-bundle-size-prisma-types branch September 25, 2025 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only foundation 🧹 Improvements Improvements to existing features. Mostly UX/UI platform Anything related to our platform plan ready-for-e2e size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants