chore: safely accesses more dependencies

This commit is contained in:
James
2024-03-07 11:04:27 -05:00
parent 764c6f0086
commit 5431a84f37
7 changed files with 141 additions and 130 deletions

View File

@@ -5,7 +5,7 @@ import { getTranslation } from '@payloadcms/translations'
import { type MappedField, useConfig } from '@payloadcms/ui' import { type MappedField, useConfig } from '@payloadcms/ui'
import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/types' import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/types'
import React from 'react' import React from 'react'
import ReactDiffViewerDefault from 'react-diff-viewer-continued' import ReactDiffViewerImport from 'react-diff-viewer-continued'
import type { Props } from '../types.d.ts' import type { Props } from '../types.d.ts'
@@ -13,7 +13,8 @@ import Label from '../../Label/index.js'
import { diffStyles } from '../styles.js' import { diffStyles } from '../styles.js'
import './index.scss' import './index.scss'
const ReactDiffViewer = ReactDiffViewerDefault.default const ReactDiffViewer = (ReactDiffViewerImport.default ||
ReactDiffViewerImport) as unknown as typeof ReactDiffViewerImport.default
const baseClass = 'relationship-diff' const baseClass = 'relationship-diff'

View File

@@ -1,9 +1,11 @@
'use client' 'use client'
import React from 'react' import React from 'react'
import ReactDiffViewerDefault from 'react-diff-viewer-continued' import ReactDiffViewerImport from 'react-diff-viewer-continued'
const ReactDiffViewer = ReactDiffViewerDefault.default const ReactDiffViewer = (ReactDiffViewerImport.default ||
const DiffMethod = ReactDiffViewerDefault.DiffMethod ReactDiffViewerImport) as unknown as typeof ReactDiffViewerImport.default
const DiffMethod = ReactDiffViewerImport.DiffMethod
export const DiffViewer: React.FC<{ export const DiffViewer: React.FC<{
comparisonToRender: string comparisonToRender: string

View File

@@ -1,9 +1,11 @@
'use client' 'use client'
import React from 'react' import React from 'react'
import ReactDiffViewerDefault from 'react-diff-viewer-continued' import ReactDiffViewerImport from 'react-diff-viewer-continued'
const ReactDiffViewer = ReactDiffViewerDefault.default const ReactDiffViewer = (ReactDiffViewerImport.default ||
const DiffMethod = ReactDiffViewerDefault.DiffMethod ReactDiffViewerImport) as unknown as typeof ReactDiffViewerImport.default
const DiffMethod = ReactDiffViewerImport.DiffMethod
export const DiffViewer: React.FC<{ export const DiffViewer: React.FC<{
comparisonToRender: string comparisonToRender: string

View File

@@ -1,7 +1,11 @@
import pino from 'pino' import pinoImport from 'pino'
import PinoPretty from 'pino-pretty' import pinoPrettyImport from 'pino-pretty'
export type PayloadLogger = pino.Logger const pino = (pinoImport.default || pinoImport) as unknown as typeof pinoImport.default
const pinoPretty = (pinoPrettyImport.default ||
pinoPrettyImport) as unknown as typeof pinoPrettyImport.default
export type PayloadLogger = pinoImport.default.Logger
const prettyOptions = { const prettyOptions = {
colorize: true, colorize: true,
@@ -9,14 +13,14 @@ const prettyOptions = {
translateTime: 'SYS:HH:MM:ss', translateTime: 'SYS:HH:MM:ss',
} }
export const defaultLoggerOptions: pino.LoggerOptions = { export const defaultLoggerOptions: pinoImport.default.LoggerOptions = {
transport: { transport: {
options: prettyOptions, options: prettyOptions,
target: 'pino-pretty', target: 'pino-pretty',
}, },
} }
export const prettySyncLoggerDestination = PinoPretty.default({ export const prettySyncLoggerDestination = pinoPretty({
...prettyOptions, ...prettyOptions,
destination: 1, // stdout destination: 1, // stdout
sync: true, sync: true,
@@ -24,11 +28,11 @@ export const prettySyncLoggerDestination = PinoPretty.default({
const getLogger = ( const getLogger = (
name = 'payload', name = 'payload',
options?: pino.LoggerOptions, options?: pinoImport.default.LoggerOptions,
destination?: pino.DestinationStream, destination?: pinoImport.default.DestinationStream,
): PayloadLogger => { ): PayloadLogger => {
if (options) { if (options) {
return pino.default( return pino(
{ {
name: options?.name || name, name: options?.name || name,
enabled: process.env.DISABLE_LOGGING !== 'true', enabled: process.env.DISABLE_LOGGING !== 'true',
@@ -38,7 +42,7 @@ const getLogger = (
) )
} }
return pino.default(prettySyncLoggerDestination) return pino(prettySyncLoggerDestination)
} }
export default getLogger export default getLogger

View File

@@ -1,5 +1,5 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import Conf from 'conf' import ConfImport from 'conf'
import { randomBytes } from 'crypto' import { randomBytes } from 'crypto'
import findUp from 'find-up' import findUp from 'find-up'
import fs from 'fs' import fs from 'fs'
@@ -10,6 +10,8 @@ import type { ServerInitEvent } from './events/serverInit.js'
import { oneWayHash } from './oneWayHash.js' import { oneWayHash } from './oneWayHash.js'
const Conf = (ConfImport.default || ConfImport) as unknown as typeof ConfImport.default
export type BaseEvent = { export type BaseEvent = {
envID: string envID: string
nodeEnv: string nodeEnv: string
@@ -61,7 +63,7 @@ export const sendEvent = async ({ event, payload }: Args): Promise<void> => {
* generated from random data and completely anonymous. * generated from random data and completely anonymous.
*/ */
const getEnvID = (): string => { const getEnvID = (): string => {
const conf = new Conf.default() const conf = new Conf()
const ENV_ID = 'envID' const ENV_ID = 'envID'
const val = conf.get(ENV_ID) const val = conf.get(ENV_ID)

View File

@@ -1,4 +1,4 @@
import EditorDefault from '@monaco-editor/react' import EditorImport from '@monaco-editor/react'
import React from 'react' import React from 'react'
import type { Props } from './types.d.ts' import type { Props } from './types.d.ts'
@@ -7,7 +7,7 @@ import { useTheme } from '../../providers/Theme/index.js'
import { ShimmerEffect } from '../ShimmerEffect/index.js' import { ShimmerEffect } from '../ShimmerEffect/index.js'
import './index.scss' import './index.scss'
const Editor = EditorDefault.default const Editor = (EditorImport.default || EditorImport) as unknown as typeof EditorImport.default
const baseClass = 'code-editor' const baseClass = 'code-editor'

View File

@@ -6,30 +6,30 @@ import type { Config, SanitizedConfig } from '../packages/payload/src/config/typ
import { mongooseAdapter } from '../packages/db-mongodb/src/index.js' import { mongooseAdapter } from '../packages/db-mongodb/src/index.js'
import { postgresAdapter } from '../packages/db-postgres/src/index.js' import { postgresAdapter } from '../packages/db-postgres/src/index.js'
import { buildConfig as buildPayloadConfig } from '../packages/payload/src/config/build.js' import { buildConfig as buildPayloadConfig } from '../packages/payload/src/config/build.js'
import { // import {
AlignFeature, // AlignFeature,
BlockQuoteFeature, // BlockQuoteFeature,
BlocksFeature, // BlocksFeature,
BoldFeature, // BoldFeature,
CheckListFeature, // CheckListFeature,
HeadingFeature, // HeadingFeature,
IndentFeature, // IndentFeature,
InlineCodeFeature, // InlineCodeFeature,
ItalicFeature, // ItalicFeature,
LinkFeature, // LinkFeature,
OrderedListFeature, // OrderedListFeature,
ParagraphFeature, // ParagraphFeature,
RelationshipFeature, // RelationshipFeature,
StrikethroughFeature, // StrikethroughFeature,
SubscriptFeature, // SubscriptFeature,
SuperscriptFeature, // SuperscriptFeature,
TreeViewFeature, // TreeViewFeature,
UnderlineFeature, // UnderlineFeature,
UnorderedListFeature, // UnorderedListFeature,
UploadFeature, // UploadFeature,
lexicalEditor, // lexicalEditor,
} from '../packages/richtext-lexical/src' // } from '../packages/richtext-lexical/src'
// import { slateEditor } from '../packages/richtext-slate/src/index.js' import { slateEditor } from '../packages/richtext-slate/src/index.js'
// process.env.PAYLOAD_DATABASE = 'postgres' // process.env.PAYLOAD_DATABASE = 'postgres'
@@ -66,42 +66,9 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
const config: Config = { const config: Config = {
db: databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongoose'], db: databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongoose'],
secret: 'TEST_SECRET', secret: 'TEST_SECRET',
// editor: slateEditor({ editor: slateEditor({
// admin: { admin: {
// upload: { upload: {
// collections: {
// media: {
// fields: [
// {
// name: 'alt',
// type: 'text',
// },
// ],
// },
// },
// },
// },
// }),
editor: lexicalEditor({
features: [
ParagraphFeature(),
RelationshipFeature(),
LinkFeature({
fields: [
{
name: 'description',
type: 'text',
},
],
}),
CheckListFeature(),
UnorderedListFeature(),
OrderedListFeature(),
AlignFeature(),
BlockQuoteFeature(),
BoldFeature(),
ItalicFeature(),
UploadFeature({
collections: { collections: {
media: { media: {
fields: [ fields: [
@@ -112,56 +79,89 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
], ],
}, },
}, },
}), },
UnderlineFeature(), },
StrikethroughFeature(),
SubscriptFeature(),
SuperscriptFeature(),
InlineCodeFeature(),
TreeViewFeature(),
HeadingFeature(),
IndentFeature(),
BlocksFeature({
blocks: [
{
slug: 'myBlock',
fields: [
{
name: 'someText',
type: 'text',
},
{
name: 'someTextRequired',
type: 'text',
required: true,
},
{
name: 'radios',
type: 'radio',
options: [
{
label: 'Option 1',
value: 'option1',
},
{
label: 'Option 2',
value: 'option2',
},
{
label: 'Option 3',
value: 'option3',
},
],
validate: (value) => {
return value !== 'option2' ? true : 'Cannot be option2'
},
},
],
},
],
}),
],
}), }),
// editor: lexicalEditor({
// features: [
// ParagraphFeature(),
// RelationshipFeature(),
// LinkFeature({
// fields: [
// {
// name: 'description',
// type: 'text',
// },
// ],
// }),
// CheckListFeature(),
// UnorderedListFeature(),
// OrderedListFeature(),
// AlignFeature(),
// BlockQuoteFeature(),
// BoldFeature(),
// ItalicFeature(),
// UploadFeature({
// collections: {
// media: {
// fields: [
// {
// name: 'alt',
// type: 'text',
// },
// ],
// },
// },
// }),
// UnderlineFeature(),
// StrikethroughFeature(),
// SubscriptFeature(),
// SuperscriptFeature(),
// InlineCodeFeature(),
// TreeViewFeature(),
// HeadingFeature(),
// IndentFeature(),
// BlocksFeature({
// blocks: [
// {
// slug: 'myBlock',
// fields: [
// {
// name: 'someText',
// type: 'text',
// },
// {
// name: 'someTextRequired',
// type: 'text',
// required: true,
// },
// {
// name: 'radios',
// type: 'radio',
// options: [
// {
// label: 'Option 1',
// value: 'option1',
// },
// {
// label: 'Option 2',
// value: 'option2',
// },
// {
// label: 'Option 3',
// value: 'option3',
// },
// ],
// validate: (value) => {
// return value !== 'option2' ? true : 'Cannot be option2'
// },
// },
// ],
// },
// ],
// }),
// ],
// }),
sharp, sharp,
telemetry: false, telemetry: false,
...testConfig, ...testConfig,