From 752cfa6bf98a826e8f49a590c8b0e70c9007ebfc Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Thu, 25 Sep 2025 05:36:16 +0300 Subject: [PATCH] chore: reduce atoms bundle size prisma types (#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 --- .changeset/ninety-colts-search.md | 5 +++ packages/platform/atoms/kysely-types/index.ts | 2 ++ packages/platform/atoms/package.json | 2 +- packages/platform/atoms/prisma-types/index.ts | 9 +++++ packages/platform/atoms/tsconfig.json | 6 +++- packages/platform/atoms/vite.config.ts | 36 +++++++++++++++---- 6 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 .changeset/ninety-colts-search.md create mode 100644 packages/platform/atoms/kysely-types/index.ts create mode 100644 packages/platform/atoms/prisma-types/index.ts diff --git a/.changeset/ninety-colts-search.md b/.changeset/ninety-colts-search.md new file mode 100644 index 0000000000..111894b687 --- /dev/null +++ b/.changeset/ninety-colts-search.md @@ -0,0 +1,5 @@ +--- +"@calcom/atoms": minor +--- + +Reduced bundle size by removing unnecessary types diff --git a/packages/platform/atoms/kysely-types/index.ts b/packages/platform/atoms/kysely-types/index.ts new file mode 100644 index 0000000000..9fe826d115 --- /dev/null +++ b/packages/platform/atoms/kysely-types/index.ts @@ -0,0 +1,2 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +export type ColumnType = SelectType; diff --git a/packages/platform/atoms/package.json b/packages/platform/atoms/package.json index 6c05117534..b186b9a734 100644 --- a/packages/platform/atoms/package.json +++ b/packages/platform/atoms/package.json @@ -7,7 +7,7 @@ "version": "1.9.0", "scripts": { "dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch", - "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", + "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", "publish-npm": "yarn build && npm publish --access public", "test": "jest", "dev-on": "node scripts/dev-on.js", diff --git a/packages/platform/atoms/prisma-types/index.ts b/packages/platform/atoms/prisma-types/index.ts new file mode 100644 index 0000000000..b064ddbb85 --- /dev/null +++ b/packages/platform/atoms/prisma-types/index.ts @@ -0,0 +1,9 @@ +// src/prisma-types.ts + +// These types are derived from Prisma's internal types +// to ensure type safety without importing the full client. +export type JsonValue = string | number | boolean | JsonObject | JsonArray | null; + +export type JsonObject = { [key: string]: JsonValue }; + +export type JsonArray = Array; diff --git a/packages/platform/atoms/tsconfig.json b/packages/platform/atoms/tsconfig.json index 40d91f9f05..f7cc9faa79 100644 --- a/packages/platform/atoms/tsconfig.json +++ b/packages/platform/atoms/tsconfig.json @@ -56,7 +56,11 @@ "../../features/shell", "../../features/components", "../../features/form-builder", - "../../features/data-table" + "../../features/data-table", + "../../kysely/types.ts", + "./prisma-types/index.ts", + "./kysely-types/index.ts", + "../../lib/intervalLimits/intervalLimitSchema.ts" ], "exclude": [ "dist", diff --git a/packages/platform/atoms/vite.config.ts b/packages/platform/atoms/vite.config.ts index 975682e09d..4cbf2b5376 100644 --- a/packages/platform/atoms/vite.config.ts +++ b/packages/platform/atoms/vite.config.ts @@ -19,7 +19,23 @@ export default defineConfig(({ mode }) => { "@calcom/platform-utils", ], }, - plugins: [react(), dts({ insertTypesEntry: true })], + plugins: [ + react(), + 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 }; + }, + }), + ], define: { "process.env.NEXT_PUBLIC_WEBAPP_URL": `"${webAppUrl}"`, }, @@ -34,7 +50,16 @@ export default defineConfig(({ mode }) => { formats: ["es"], }, rollupOptions: { - external: ["react", "fs", "path", "os", "react/jsx-runtime", "react-dom", "react-dom/client"], + external: [ + "react", + "fs", + "path", + "os", + "react/jsx-runtime", + "react-dom", + "react-dom/client", + "@prisma/client", + ], output: { format: "esm", globals: { @@ -54,10 +79,9 @@ export default defineConfig(({ mode }) => { "@calcom/lib/hooks/useLocale": path.resolve(__dirname, "./lib/useLocale"), "@radix-ui/react-tooltip": path.resolve(__dirname, "./src/components/ui/tooltip.tsx"), "@radix-ui/react-dialog": path.resolve(__dirname, "./src/components/ui/dialog.tsx"), - ".prisma/client": path.resolve(__dirname, "../../prisma-client"), - "@prisma/client": path.resolve(__dirname, "../../prisma-client"), - "@calcom/prisma/client": path.resolve(__dirname, "../../prisma-client"), - "@calcom/prisma": path.resolve(__dirname, "../../prisma"), + "@calcom/prisma/client/runtime/library": resolve("./prisma-types/index.ts"), + "@calcom/prisma/client": path.resolve(__dirname, "../../kysely/types.ts"), + kysely: path.resolve(__dirname, "./kysely-types/index.ts"), "@calcom/dayjs": path.resolve(__dirname, "../../dayjs"), "@calcom/platform-constants": path.resolve(__dirname, "../constants/index.ts"), "@calcom/platform-types": path.resolve(__dirname, "../types/index.ts"),