diff --git a/packages/payload/src/fields/baseFields/baseIDField.ts b/packages/payload/src/fields/baseFields/baseIDField.ts index 5b488efcd..200e68aea 100644 --- a/packages/payload/src/fields/baseFields/baseIDField.ts +++ b/packages/payload/src/fields/baseFields/baseIDField.ts @@ -2,8 +2,7 @@ import ObjectIdImport from 'bson-objectid' import type { TextField } from '../config/types.js' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport export const baseIDField: TextField = { name: 'id', diff --git a/packages/payload/src/fields/validations.ts b/packages/payload/src/fields/validations.ts index 7dc86df95..ea27ceca9 100644 --- a/packages/payload/src/fields/validations.ts +++ b/packages/payload/src/fields/validations.ts @@ -1,8 +1,7 @@ import Ajv from 'ajv' import ObjectIdImport from 'bson-objectid' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport import type { TFunction } from '@payloadcms/translations' import type { JSONSchema4 } from 'json-schema' diff --git a/packages/payload/src/queues/errors/handleTaskError.ts b/packages/payload/src/queues/errors/handleTaskError.ts index 3366b0a15..194ecc245 100644 --- a/packages/payload/src/queues/errors/handleTaskError.ts +++ b/packages/payload/src/queues/errors/handleTaskError.ts @@ -9,8 +9,7 @@ import { getCurrentDate } from '../utilities/getCurrentDate.js' import { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js' import { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport export async function handleTaskError({ error, diff --git a/packages/payload/src/queues/operations/runJobs/runJob/getRunTaskFunction.ts b/packages/payload/src/queues/operations/runJobs/runJob/getRunTaskFunction.ts index aa9f17156..023d05290 100644 --- a/packages/payload/src/queues/operations/runJobs/runJob/getRunTaskFunction.ts +++ b/packages/payload/src/queues/operations/runJobs/runJob/getRunTaskFunction.ts @@ -23,8 +23,7 @@ import { TaskError } from '../../../errors/index.js' import { getCurrentDate } from '../../../utilities/getCurrentDate.js' import { getTaskHandlerFromConfig } from './importHandlerPath.js' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport export type TaskParent = { taskID: string diff --git a/packages/payload/src/utilities/isValidID.ts b/packages/payload/src/utilities/isValidID.ts index 82e67bf52..dc63767bc 100644 --- a/packages/payload/src/utilities/isValidID.ts +++ b/packages/payload/src/utilities/isValidID.ts @@ -1,7 +1,6 @@ import ObjectIdImport from 'bson-objectid' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport export const isValidID = ( value: number | string, diff --git a/packages/ui/src/elements/CodeEditor/CodeEditor.tsx b/packages/ui/src/elements/CodeEditor/CodeEditor.tsx index 82e975132..825dda5a4 100644 --- a/packages/ui/src/elements/CodeEditor/CodeEditor.tsx +++ b/packages/ui/src/elements/CodeEditor/CodeEditor.tsx @@ -8,7 +8,7 @@ import { useTheme } from '../../providers/Theme/index.js' import { ShimmerEffect } from '../ShimmerEffect/index.js' import './index.scss' -const Editor = (EditorImport.default || EditorImport) as unknown as typeof EditorImport.default +const Editor = 'default' in EditorImport ? EditorImport.default : EditorImport const baseClass = 'code-editor' diff --git a/packages/ui/src/elements/DatePicker/DatePicker.tsx b/packages/ui/src/elements/DatePicker/DatePicker.tsx index c8c182b69..a57a4471e 100644 --- a/packages/ui/src/elements/DatePicker/DatePicker.tsx +++ b/packages/ui/src/elements/DatePicker/DatePicker.tsx @@ -3,8 +3,10 @@ import type { DatePickerProps } from 'react-datepicker' import React from 'react' import ReactDatePickerDefaultImport, { registerLocale, setDefaultLocale } from 'react-datepicker' -const ReactDatePicker = (ReactDatePickerDefaultImport.default || - ReactDatePickerDefaultImport) as unknown as typeof ReactDatePickerDefaultImport.default +const ReactDatePicker = + 'default' in ReactDatePickerDefaultImport + ? ReactDatePickerDefaultImport.default + : ReactDatePickerDefaultImport import type { Props } from './types.js' diff --git a/packages/ui/src/elements/Link/index.tsx b/packages/ui/src/elements/Link/index.tsx index 5ab5f9d13..8d7f95b30 100644 --- a/packages/ui/src/elements/Link/index.tsx +++ b/packages/ui/src/elements/Link/index.tsx @@ -6,8 +6,7 @@ import React from 'react' import { useRouteTransition } from '../../providers/RouteTransition/index.js' import { formatUrl } from './formatUrl.js' -const NextLink = (NextLinkImport.default || - NextLinkImport) as unknown as typeof NextLinkImport.default +const NextLink = 'default' in NextLinkImport ? NextLinkImport.default : NextLinkImport // Copied from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/link.tsx#L180-L191 function isModifiedEvent(event: React.MouseEvent): boolean { diff --git a/packages/ui/src/fields/Join/index.tsx b/packages/ui/src/fields/Join/index.tsx index 81f07dfc2..0cf240ca2 100644 --- a/packages/ui/src/fields/Join/index.tsx +++ b/packages/ui/src/fields/Join/index.tsx @@ -24,8 +24,7 @@ import { FieldError } from '../FieldError/index.js' import { FieldLabel } from '../FieldLabel/index.js' import { fieldBaseClass } from '../index.js' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport /** * Recursively builds the default data for joined collection diff --git a/packages/ui/src/forms/Form/fieldReducer.ts b/packages/ui/src/forms/Form/fieldReducer.ts index 3dfadf09f..f2aaef573 100644 --- a/packages/ui/src/forms/Form/fieldReducer.ts +++ b/packages/ui/src/forms/Form/fieldReducer.ts @@ -10,8 +10,7 @@ import type { FieldAction } from './types.js' import { mergeServerFormState } from './mergeServerFormState.js' import { flattenRows, separateRows } from './rows.js' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport /** * Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object. diff --git a/packages/ui/src/forms/fieldSchemasToFormState/addFieldStatePromise.ts b/packages/ui/src/forms/fieldSchemasToFormState/addFieldStatePromise.ts index caceed53f..fe19d6fe6 100644 --- a/packages/ui/src/forms/fieldSchemasToFormState/addFieldStatePromise.ts +++ b/packages/ui/src/forms/fieldSchemasToFormState/addFieldStatePromise.ts @@ -37,8 +37,7 @@ import { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js' import { isRowCollapsed } from './isRowCollapsed.js' import { iterateFields } from './iterateFields.js' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport export type AddFieldStatePromiseArgs = { addErrorPathToParent: (fieldPath: string) => void diff --git a/packages/ui/src/utilities/copyDataFromLocale.ts b/packages/ui/src/utilities/copyDataFromLocale.ts index 8404fdeb8..7898774f1 100644 --- a/packages/ui/src/utilities/copyDataFromLocale.ts +++ b/packages/ui/src/utilities/copyDataFromLocale.ts @@ -11,8 +11,7 @@ import { } from 'payload' import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from 'payload/shared' -const ObjectId = (ObjectIdImport.default || - ObjectIdImport) as unknown as typeof ObjectIdImport.default +const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport export type CopyDataFromLocaleArgs = { collectionSlug?: CollectionSlug diff --git a/test/helpers/bootAdminPanel.mjs b/test/helpers/bootAdminPanel.mjs index ed0ae1ca4..8cac83ed9 100644 --- a/test/helpers/bootAdminPanel.mjs +++ b/test/helpers/bootAdminPanel.mjs @@ -2,7 +2,7 @@ import { createServer } from 'http' import next from 'next' import { parse } from 'url' -const actualNext = next.default || next +const actualNext = 'default' in next ? next.default : next export const bootAdminPanel = async ({ port = 3000, appDir }) => { const serverURL = `http://localhost:${port}` const app = actualNext({ diff --git a/test/live-preview/app/live-preview/_components/Button/index.tsx b/test/live-preview/app/live-preview/_components/Button/index.tsx index 241e9bd3f..d70b42cac 100644 --- a/test/live-preview/app/live-preview/_components/Button/index.tsx +++ b/test/live-preview/app/live-preview/_components/Button/index.tsx @@ -7,7 +7,7 @@ import React from 'react' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export type Props = { appearance?: 'default' | 'none' | 'primary' | 'secondary' diff --git a/test/live-preview/app/live-preview/_components/Card/index.tsx b/test/live-preview/app/live-preview/_components/Card/index.tsx index b4ee0787b..44309b863 100644 --- a/test/live-preview/app/live-preview/_components/Card/index.tsx +++ b/test/live-preview/app/live-preview/_components/Card/index.tsx @@ -6,7 +6,7 @@ import type { Post } from '../../../../payload-types.js' import { Media } from '../Media/index.js' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export const Card: React.FC<{ alignItems?: 'center' diff --git a/test/live-preview/app/live-preview/_components/Footer/index.tsx b/test/live-preview/app/live-preview/_components/Footer/index.tsx index 426c049f6..6cdc00eff 100644 --- a/test/live-preview/app/live-preview/_components/Footer/index.tsx +++ b/test/live-preview/app/live-preview/_components/Footer/index.tsx @@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js' import { CMSLink } from '../Link/index.js' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export async function Footer() { const footer = await getFooter() diff --git a/test/live-preview/app/live-preview/_components/Header/index.tsx b/test/live-preview/app/live-preview/_components/Header/index.tsx index 46e771960..2dbfc3323 100644 --- a/test/live-preview/app/live-preview/_components/Header/index.tsx +++ b/test/live-preview/app/live-preview/_components/Header/index.tsx @@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js' import classes from './index.module.scss' import { HeaderNav } from './Nav/index.js' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export async function Header() { const header = await getHeader() diff --git a/test/live-preview/app/live-preview/_components/Link/index.tsx b/test/live-preview/app/live-preview/_components/Link/index.tsx index d5d273133..061f61103 100644 --- a/test/live-preview/app/live-preview/_components/Link/index.tsx +++ b/test/live-preview/app/live-preview/_components/Link/index.tsx @@ -6,7 +6,7 @@ import type { Props as ButtonProps } from '../Button/index.js' import { Button } from '../Button/index.js' -const NextLink = (NextLinkImport.default || NextLinkImport) as typeof NextLinkImport.default +const NextLink = 'default' in NextLinkImport ? NextLinkImport.default : NextLinkImport type CMSLinkType = { appearance?: ButtonProps['appearance'] diff --git a/test/live-preview/app/live-preview/_components/Media/Image/index.tsx b/test/live-preview/app/live-preview/_components/Media/Image/index.tsx index 495aac0e8..c8ad982a3 100644 --- a/test/live-preview/app/live-preview/_components/Media/Image/index.tsx +++ b/test/live-preview/app/live-preview/_components/Media/Image/index.tsx @@ -13,8 +13,8 @@ import classes from './index.module.scss' const { breakpoints } = cssVariables -const NextImage = (NextImageWithDefault.default || - NextImageWithDefault) as typeof NextImageWithDefault.default +const NextImage = + 'default' in NextImageWithDefault ? NextImageWithDefault.default : NextImageWithDefault export const Image: React.FC = (props) => { const { diff --git a/test/live-preview/app/live-preview/_heros/PostHero/index.tsx b/test/live-preview/app/live-preview/_heros/PostHero/index.tsx index 7cf19c4f5..a83201119 100644 --- a/test/live-preview/app/live-preview/_heros/PostHero/index.tsx +++ b/test/live-preview/app/live-preview/_heros/PostHero/index.tsx @@ -10,7 +10,7 @@ import RichText from '../../_components/RichText/index.js' import { formatDateTime } from '../../_utilities/formatDateTime.js' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export const PostHero: React.FC<{ post: Post diff --git a/test/live-preview/prod/app/live-preview/_components/Button/index.tsx b/test/live-preview/prod/app/live-preview/_components/Button/index.tsx index 241e9bd3f..d70b42cac 100644 --- a/test/live-preview/prod/app/live-preview/_components/Button/index.tsx +++ b/test/live-preview/prod/app/live-preview/_components/Button/index.tsx @@ -7,7 +7,7 @@ import React from 'react' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export type Props = { appearance?: 'default' | 'none' | 'primary' | 'secondary' diff --git a/test/live-preview/prod/app/live-preview/_components/Card/index.tsx b/test/live-preview/prod/app/live-preview/_components/Card/index.tsx index 5cdc765f8..a613fbbd5 100644 --- a/test/live-preview/prod/app/live-preview/_components/Card/index.tsx +++ b/test/live-preview/prod/app/live-preview/_components/Card/index.tsx @@ -6,7 +6,7 @@ import type { Post } from '../../../../../payload-types.js' import { Media } from '../Media/index.js' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export const Card: React.FC<{ alignItems?: 'center' diff --git a/test/live-preview/prod/app/live-preview/_components/Footer/index.tsx b/test/live-preview/prod/app/live-preview/_components/Footer/index.tsx index 426c049f6..6cdc00eff 100644 --- a/test/live-preview/prod/app/live-preview/_components/Footer/index.tsx +++ b/test/live-preview/prod/app/live-preview/_components/Footer/index.tsx @@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js' import { CMSLink } from '../Link/index.js' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export async function Footer() { const footer = await getFooter() diff --git a/test/live-preview/prod/app/live-preview/_components/Header/index.tsx b/test/live-preview/prod/app/live-preview/_components/Header/index.tsx index 46e771960..2dbfc3323 100644 --- a/test/live-preview/prod/app/live-preview/_components/Header/index.tsx +++ b/test/live-preview/prod/app/live-preview/_components/Header/index.tsx @@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js' import classes from './index.module.scss' import { HeaderNav } from './Nav/index.js' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export async function Header() { const header = await getHeader() diff --git a/test/live-preview/prod/app/live-preview/_components/Link/index.tsx b/test/live-preview/prod/app/live-preview/_components/Link/index.tsx index 5b60e5a65..c02a9a9f0 100644 --- a/test/live-preview/prod/app/live-preview/_components/Link/index.tsx +++ b/test/live-preview/prod/app/live-preview/_components/Link/index.tsx @@ -6,7 +6,7 @@ import type { Props as ButtonProps } from '../Button/index.js' import { Button } from '../Button/index.js' -const NextLink = (NextLinkImport.default || NextLinkImport) as typeof NextLinkImport.default +const NextLink = 'default' in NextLinkImport ? NextLinkImport.default : NextLinkImport type CMSLinkType = { appearance?: ButtonProps['appearance'] diff --git a/test/live-preview/prod/app/live-preview/_components/Media/Image/index.tsx b/test/live-preview/prod/app/live-preview/_components/Media/Image/index.tsx index 495aac0e8..c8ad982a3 100644 --- a/test/live-preview/prod/app/live-preview/_components/Media/Image/index.tsx +++ b/test/live-preview/prod/app/live-preview/_components/Media/Image/index.tsx @@ -13,8 +13,8 @@ import classes from './index.module.scss' const { breakpoints } = cssVariables -const NextImage = (NextImageWithDefault.default || - NextImageWithDefault) as typeof NextImageWithDefault.default +const NextImage = + 'default' in NextImageWithDefault ? NextImageWithDefault.default : NextImageWithDefault export const Image: React.FC = (props) => { const { diff --git a/test/live-preview/prod/app/live-preview/_heros/PostHero/index.tsx b/test/live-preview/prod/app/live-preview/_heros/PostHero/index.tsx index 67cb767b8..93407a3e5 100644 --- a/test/live-preview/prod/app/live-preview/_heros/PostHero/index.tsx +++ b/test/live-preview/prod/app/live-preview/_heros/PostHero/index.tsx @@ -10,7 +10,7 @@ import RichText from '../../_components/RichText/index.js' import { formatDateTime } from '../../_utilities/formatDateTime.js' import classes from './index.module.scss' -const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default +const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault export const PostHero: React.FC<{ post: Post