Skip to content

Commit 752cfa6

Browse files
chore: reduce atoms bundle size prisma types (calcom#24001)
* chore: use kysely types instead of prisma types in atoms * fixup! chore: use kysely types instead of prisma types in atoms * fixup! Merge branch 'main' into reduce-atoms-bundle-size-prisma-types
1 parent f11c4dd commit 752cfa6

6 files changed

Lines changed: 52 additions & 8 deletions

File tree

.changeset/ninety-colts-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@calcom/atoms": minor
3+
---
4+
5+
Reduced bundle size by removing unnecessary types
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
export type ColumnType<SelectType, InsertType = SelectType, UpdateType = SelectType> = SelectType;

packages/platform/atoms/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"version": "1.9.0",
88
"scripts": {
99
"dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
10-
"build": "NODE_OPTIONS='--max_old_space_size=12288' rm -rf dist && yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify && mkdir ./dist/packages/prisma-client && cp -rf ../../prisma/client/*.d.ts ./dist/packages/prisma-client",
10+
"build": "NODE_OPTIONS='--max_old_space_size=12288' rm -rf dist && yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify",
1111
"publish-npm": "yarn build && npm publish --access public",
1212
"test": "jest",
1313
"dev-on": "node scripts/dev-on.js",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// src/prisma-types.ts
2+
3+
// These types are derived from Prisma's internal types
4+
// to ensure type safety without importing the full client.
5+
export type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
6+
7+
export type JsonObject = { [key: string]: JsonValue };
8+
9+
export type JsonArray = Array<JsonValue>;

packages/platform/atoms/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656
"../../features/shell",
5757
"../../features/components",
5858
"../../features/form-builder",
59-
"../../features/data-table"
59+
"../../features/data-table",
60+
"../../kysely/types.ts",
61+
"./prisma-types/index.ts",
62+
"./kysely-types/index.ts",
63+
"../../lib/intervalLimits/intervalLimitSchema.ts"
6064
],
6165
"exclude": [
6266
"dist",

packages/platform/atoms/vite.config.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,23 @@ export default defineConfig(({ mode }) => {
1919
"@calcom/platform-utils",
2020
],
2121
},
22-
plugins: [react(), dts({ insertTypesEntry: true })],
22+
plugins: [
23+
react(),
24+
dts({
25+
insertTypesEntry: true,
26+
beforeWriteFile: (filePath, content) => {
27+
// Check if the content includes the broken path from kysely
28+
if (content.includes(`kysely/types.ts').$Enums`)) {
29+
// Replace the broken path with the correct import
30+
return {
31+
filePath,
32+
content: content.replaceAll(`kysely/types.ts').$Enums`, `kysely/types.ts')`),
33+
};
34+
}
35+
return { filePath, content };
36+
},
37+
}),
38+
],
2339
define: {
2440
"process.env.NEXT_PUBLIC_WEBAPP_URL": `"${webAppUrl}"`,
2541
},
@@ -34,7 +50,16 @@ export default defineConfig(({ mode }) => {
3450
formats: ["es"],
3551
},
3652
rollupOptions: {
37-
external: ["react", "fs", "path", "os", "react/jsx-runtime", "react-dom", "react-dom/client"],
53+
external: [
54+
"react",
55+
"fs",
56+
"path",
57+
"os",
58+
"react/jsx-runtime",
59+
"react-dom",
60+
"react-dom/client",
61+
"@prisma/client",
62+
],
3863
output: {
3964
format: "esm",
4065
globals: {
@@ -54,10 +79,9 @@ export default defineConfig(({ mode }) => {
5479
"@calcom/lib/hooks/useLocale": path.resolve(__dirname, "./lib/useLocale"),
5580
"@radix-ui/react-tooltip": path.resolve(__dirname, "./src/components/ui/tooltip.tsx"),
5681
"@radix-ui/react-dialog": path.resolve(__dirname, "./src/components/ui/dialog.tsx"),
57-
".prisma/client": path.resolve(__dirname, "../../prisma-client"),
58-
"@prisma/client": path.resolve(__dirname, "../../prisma-client"),
59-
"@calcom/prisma/client": path.resolve(__dirname, "../../prisma-client"),
60-
"@calcom/prisma": path.resolve(__dirname, "../../prisma"),
82+
"@calcom/prisma/client/runtime/library": resolve("./prisma-types/index.ts"),
83+
"@calcom/prisma/client": path.resolve(__dirname, "../../kysely/types.ts"),
84+
kysely: path.resolve(__dirname, "./kysely-types/index.ts"),
6185
"@calcom/dayjs": path.resolve(__dirname, "../../dayjs"),
6286
"@calcom/platform-constants": path.resolve(__dirname, "../constants/index.ts"),
6387
"@calcom/platform-types": path.resolve(__dirname, "../types/index.ts"),

0 commit comments

Comments
 (0)