Skip to content

Commit

Permalink
Techdebt/bundle size experiments (#7894)
Browse files Browse the repository at this point in the history
* Checking package size effects when we remove zod from middleware

* Remove 'crypto' from client code

* Revert "Checking package size effects when we remove zod from middleware"

This reverts commit ecc2038.

* Adding lodash to dynamicImports + consistent imports

* Remove the locales from the global Dayjs object
  • Loading branch information
emrysal authored Mar 23, 2023
1 parent e4893c2 commit 46f0b55
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion apps/web/components/NavTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AdminRequired } from "components/ui/AdminRequired";
import noop from "lodash/noop";
import { noop } from "lodash";
import type { LinkProps } from "next/link";
import Link from "next/link";
import { useRouter } from "next/router";
Expand Down
2 changes: 2 additions & 0 deletions apps/web/components/booking/BookingListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useState } from "react";
import type { EventLocationType } from "@calcom/app-store/locations";
import { getEventLocationType } from "@calcom/app-store/locations";
import dayjs from "@calcom/dayjs";
// TODO: Use browser locale, implement Intl in Dayjs maybe?
import "@calcom/dayjs/locales";
import ViewRecordingsDialog from "@calcom/features/ee/video/ViewRecordingsDialog";
import classNames from "@calcom/lib/classNames";
import { formatTime } from "@calcom/lib/date-fns";
Expand Down
3 changes: 3 additions & 0 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const nextConfig = {
skipDefaultConversion: true,
preventFullImport: true,
},
lodash: {
transform: "lodash/{{member}}",
},
// TODO: We need to have all components in `@calcom/ui/components` in order to use this
// "@calcom/ui": {
// transform: "@calcom/ui/components/{{member}}",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/auth/forgot-password/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ResetPasswordRequest } from "@prisma/client";
import debounce from "lodash/debounce";
import { debounce } from "lodash";
import type { GetServerSidePropsContext } from "next";
import { getCsrfToken } from "next-auth/react";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/auth/forgot-password/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debounce from "lodash/debounce";
import { debounce } from "lodash";
import type { GetServerSidePropsContext } from "next";
import { getCsrfToken } from "next-auth/react";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
Expand Down
8 changes: 1 addition & 7 deletions apps/web/pages/settings/my-account/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { IdentityProvider } from "@prisma/client";
import crypto from "crypto";
import { signOut } from "next-auth/react";
import type { BaseSyntheticEvent } from "react";
import { useRef, useState } from "react";
Expand Down Expand Up @@ -332,11 +331,6 @@ const ProfileForm = ({
bio: z.string(),
});

const emailMd5 = crypto
.createHash("md5")
.update(defaultValues.email || "example@example.com")
.digest("hex");

const formMethods = useForm<FormValues>({
defaultValues,
resolver: zodResolver(profileFormSchema),
Expand All @@ -356,7 +350,7 @@ const ProfileForm = ({
name="avatar"
render={({ field: { value } }) => (
<>
<Avatar alt="" imageSrc={value} gravatarFallbackMd5={emailMd5} size="lg" />
<Avatar alt="" imageSrc={value} gravatarFallbackMd5="fallback" size="lg" />
<div className="ltr:ml-4 rtl:mr-4">
<ImageUploader
target="avatar"
Expand Down
2 changes: 1 addition & 1 deletion apps/web/playwright/lib/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import type { IncomingMessage, ServerResponse } from "http";
import { createServer } from "http";
import noop from "lodash/noop";
import { noop } from "lodash";

import { test } from "./fixtures";

Expand Down
12 changes: 6 additions & 6 deletions packages/core/CalendarManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SelectedCalendar } from "@prisma/client";
import _ from "lodash";
import { sortBy } from "lodash";
import * as process from "process";

import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
Expand Down Expand Up @@ -54,8 +54,8 @@ export const getConnectedCalendars = async (
};
}
const cals = await calendar.listCalendars();
const calendars = _(cals)
.map((cal) => {
const calendars = sortBy(
cals.map((cal) => {
if (cal.externalId === destinationCalendarExternalId) destinationCalendar = cal;
return {
...cal,
Expand All @@ -64,9 +64,9 @@ export const getConnectedCalendars = async (
isSelected: selectedCalendars.some((selected) => selected.externalId === cal.externalId),
credentialId,
};
})
.sortBy(["primary"])
.value();
}),
["primary"]
);
const primary = calendars.find((item) => item.primary) ?? calendars.find((cal) => cal !== undefined);
if (!primary) {
return {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/EventManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { DestinationCalendar, Booking } from "@prisma/client";
import { cloneDeep } from "lodash";
import merge from "lodash/merge";
import { cloneDeep, merge } from "lodash";
import { v5 as uuidv5 } from "uuid";
import type { z } from "zod";

Expand Down
25 changes: 0 additions & 25 deletions packages/dayjs/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
/* eslint-disable @calcom/eslint/deprecated-imports */
import dayjs from "dayjs";
import dayjsBusinessTime from "dayjs-business-days2";
import "dayjs/locale/ar";
import "dayjs/locale/bg";
import "dayjs/locale/cs";
import "dayjs/locale/de";
import "dayjs/locale/es";
import "dayjs/locale/es-mx";
import "dayjs/locale/fr";
import "dayjs/locale/he";
import "dayjs/locale/hu";
import "dayjs/locale/it";
import "dayjs/locale/ja";
import "dayjs/locale/ko";
import "dayjs/locale/nl";
import "dayjs/locale/pl";
import "dayjs/locale/pt";
import "dayjs/locale/pt-br";
import "dayjs/locale/ro";
import "dayjs/locale/ru";
import "dayjs/locale/sr";
import "dayjs/locale/sv";
import "dayjs/locale/tr";
import "dayjs/locale/uk";
import "dayjs/locale/vi";
import "dayjs/locale/zh-cn";
import "dayjs/locale/zh-tw";
import customParseFormat from "dayjs/plugin/customParseFormat";
import isBetween from "dayjs/plugin/isBetween";
import isToday from "dayjs/plugin/isToday";
Expand Down
25 changes: 25 additions & 0 deletions packages/dayjs/locales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "dayjs/locale/ar";
import "dayjs/locale/bg";
import "dayjs/locale/cs";
import "dayjs/locale/de";
import "dayjs/locale/es";
import "dayjs/locale/es-mx";
import "dayjs/locale/fr";
import "dayjs/locale/he";
import "dayjs/locale/hu";
import "dayjs/locale/it";
import "dayjs/locale/ja";
import "dayjs/locale/ko";
import "dayjs/locale/nl";
import "dayjs/locale/pl";
import "dayjs/locale/pt";
import "dayjs/locale/pt-br";
import "dayjs/locale/ro";
import "dayjs/locale/ru";
import "dayjs/locale/sr";
import "dayjs/locale/sv";
import "dayjs/locale/tr";
import "dayjs/locale/uk";
import "dayjs/locale/vi";
import "dayjs/locale/zh-cn";
import "dayjs/locale/zh-tw";
2 changes: 2 additions & 0 deletions packages/emails/src/components/WhenInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { TFunction } from "next-i18next";
import { RRule } from "rrule";

import dayjs from "@calcom/dayjs";
// TODO: Use browser locale, implement Intl in Dayjs maybe?
import "@calcom/dayjs/locales";
import { getEveryFreqFor } from "@calcom/lib/recurringStrings";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
Expand Down
2 changes: 1 addition & 1 deletion packages/features/ee/support/lib/intercom/useIntercom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import noop from "lodash/noop";
import { noop } from "lodash";
import { useIntercom as useIntercomLib } from "react-use-intercom";
import { z } from "zod";

Expand Down
4 changes: 2 additions & 2 deletions packages/trpc/server/routers/viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DestinationCalendar, Prisma } from "@prisma/client";
import { AppCategories, BookingStatus, IdentityProvider } from "@prisma/client";
import { cityMapping } from "city-timezones";
import _ from "lodash";
import { reverse } from "lodash";
import { authenticator } from "otplib";
import z from "zod";

Expand Down Expand Up @@ -755,7 +755,7 @@ const loggedInViewerRouter = router({
});
}
await Promise.all(
_.reverse(input.ids).map((id, position) => {
reverse(input.ids).map((id, position) => {
return prisma.eventType.update({
where: {
id,
Expand Down
5 changes: 2 additions & 3 deletions packages/trpc/server/routers/viewer/eventTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MembershipRole, PeriodType, Prisma, SchedulingType } from "@prisma/client";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
// REVIEW: From lint error
import _ from "lodash";
import { orderBy } from "lodash";
import type { NextApiResponse } from "next";
import { z } from "zod";

Expand Down Expand Up @@ -336,7 +335,7 @@ export const eventTypesRouter = router({
name: user.name,
image: user.avatar || undefined,
},
eventTypes: _.orderBy(mergedEventTypes, ["position", "id"], ["desc", "asc"]),
eventTypes: orderBy(mergedEventTypes, ["position", "id"], ["desc", "asc"]),
metadata: {
membershipCount: 1,
readOnly: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/head-seo/HeadSeo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import merge from "lodash/merge";
import { merge } from "lodash";
import type { NextSeoProps } from "next-seo";
import { NextSeo } from "next-seo";
import { useRouter } from "next/router";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/top-banner/TopBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { XIcon } from "@heroicons/react/solid";
import classNames from "classnames";
import noop from "lodash/noop";
import { noop } from "lodash";
import type { ReactNode } from "react";

import { FiAlertTriangle, FiInfo } from "../icon";
Expand Down

0 comments on commit 46f0b55

Please sign in to comment.