chore: reduce atoms bundle size prisma types#24001
Conversation
WalkthroughThis 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 Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
There was a problem hiding this comment.
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 claritySlightly 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 misleadingUpdate the header to the actual file path to prevent confusion for future readers.
Suggested:
// packages/platform/atoms/prisma-types/index.tspackages/platform/atoms/vite.config.ts (1)
82-84: Mirror these aliases in tsconfig pathsKeep 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.
📒 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 useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/platform/atoms/prisma-types/index.tspackages/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.tspackages/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.tspackages/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 internalsNo 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/runtimeor@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/atomsSearched 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 occurrenceString.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
There was a problem hiding this comment.
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.
📒 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 useinclude, always useselect
Ensure thecredential.keyfield 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 importsExternalizing 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 tsxTo 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.
E2E results are ready! |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
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)