Files
payload/test/buildConfigWithDefaults.ts
Alessio Gravili a81401cf77 feat: breaking: richtext adapter (#3311)
BREAKING: requires user to install @payloacms-richtext-slate and specify a `config.editor` property

* chore: move slate stuff into packages/richtext-slate

* chore: fieldTypes stuff

* chore: fix richtext-slate tsconfig

* chore: add clean:unix command

* chore: fix up things

* chore: undo subpath imports being hoisted up

* chore: fix incorrect imports

* chore: improve AdapterArguments type

* chore: remove unused richTextToHTML and stringifyRichText files

* fix: core-dev scss imports

* chore: fix publishConfig exports for richtext-slate

* chore: adjust joi schema for richtext field

* chore: various fixes

* chore: handle afterRead population in richText adapter

* chore: handle more after-read promise stuff

* chore: fix joi validation

* chore: add richtext adapter to tests

* chore: merge adapter props with field props

* chore: index.tsx => index.ts

* chore: rename `adapter` to `editor`

* chore: fix e2e tests not running due to importing a constant from a file (`Tabs`) which imports createSlate.

This fails because createSlate imports React components.

* chore: remove unnecessary import

* chore: improve various typings

* chore: improve typings for List view Cell components

* feat: richText adapter cell component

* chore: add missing types packages for packages/richtext-slate

* chore: add new adapter interface properties to joi schema

* chore: withMergedProps utility which replaces getSlateCellComponent and getSlateFieldComponent

* feat: added config.defaultEditor property which is now required. field.editor is no longer required and overrides config.defaultEditor

* docs: mention editor and defaultEditor property in the docs

* chore: fix incorrectly formatted JSX in docs files breaking mdx parser

* chore: fix various errors

* chore: auto-generated pointer files
2023-09-19 11:03:31 +02:00

97 lines
3.2 KiB
TypeScript

import path from 'path'
import type { Config, SanitizedConfig } from '../packages/payload/src/config/types'
// import { viteBundler } from '../packages/bundler-vite/src'
import { webpackBundler } from '../packages/bundler-webpack/src'
import { mongooseAdapter } from '../packages/db-mongodb/src/index'
import { postgresAdapter } from '../packages/db-postgres/src/index'
import { buildConfig as buildPayloadConfig } from '../packages/payload/src/config/build'
import { createSlate } from '../packages/richtext-slate/src'
const databaseAdapters = {
mongoose: mongooseAdapter({
url: 'mongodb://127.0.0.1/payloadtests',
}),
postgres: postgresAdapter({
client: {
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
},
}),
}
export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<SanitizedConfig> {
const [name] = process.argv.slice(2)
const config: Config = {
editor: createSlate({}),
telemetry: false,
rateLimit: {
window: 15 * 60 * 100, // 15min default,
max: 9999999999,
},
...testConfig,
db: databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongoose'],
}
config.admin = {
autoLogin:
process.env.PAYLOAD_PUBLIC_DISABLE_AUTO_LOGIN === 'true'
? false
: {
email: 'dev@payloadcms.com',
password: 'test',
},
...(config.admin || {}),
// bundler: viteBundler(),
bundler: webpackBundler(),
webpack: (webpackConfig) => {
const existingConfig =
typeof testConfig?.admin?.webpack === 'function'
? testConfig.admin.webpack(webpackConfig)
: webpackConfig
return {
...existingConfig,
entry: {
main: [
`webpack-hot-middleware/client?path=${
testConfig?.routes?.admin || '/admin'
}/__webpack_hmr`,
path.resolve(__dirname, '../packages/payload/src/admin'),
],
},
name,
cache: process.env.NODE_ENV === 'test' ? { type: 'memory' } : existingConfig.cache,
resolve: {
...existingConfig.resolve,
alias: {
...existingConfig.resolve?.alias,
[path.resolve(__dirname, '../packages/db-postgres/src/index')]: path.resolve(
__dirname,
'../packages/db-postgres/src/mock.js',
),
[path.resolve(__dirname, '../packages/db-mongodb/src/index')]: path.resolve(
__dirname,
'../packages/db-mongodb/src/mock.js',
),
[path.resolve(__dirname, '../packages/bundler-webpack/src/index')]: path.resolve(
__dirname,
'../packages/bundler-webpack/src/mocks/emptyModule.js',
),
'@payloadcms/db-mongodb': path.resolve(__dirname, '../packages/db-mongodb/src/mock'),
'@payloadcms/db-postgres': path.resolve(__dirname, '../packages/db-postgres/src/mock'),
react: path.resolve(__dirname, '../packages/payload/node_modules/react'),
},
},
}
},
}
if (process.env.PAYLOAD_DISABLE_ADMIN === 'true') {
if (typeof config.admin !== 'object') config.admin = {}
config.admin.disable = true
}
return buildPayloadConfig(config)
}