Files
payloadcms/test/initDevAndTest.ts
Alessio Gravili ebd43c7763 feat: pre-compile ui and richtext-lexical with react compiler (#7688)
This noticeably improves performance in the admin panel, for example
when there are multiple richtext editors on one page (& likely
performance in other areas too, though I mainly tested rich text).

The babel plugin currently only optimizes files with a 'use client'
directive at the top - thus we have to make sure to add use client
wherever possible, even if it's imported by a parent client component.

There's one single component that broke when it was compiled using the
React compiler (it stopped being reactive and failed one of our admin
e2e tests):
150808f608
opting out of it completely fixed that issue

Fixes https://github.com/payloadcms/payload/issues/7366
2024-08-19 17:31:36 -04:00

78 lines
2.1 KiB
TypeScript

import fs from 'fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { type SanitizedConfig, generateImportMap } from 'payload'
import type { allDatabaseAdapters } from './getDatabaseAdapter.js'
import { getDatabaseAdapter } from './getDatabaseAdapter.js'
import { getNextRootDir } from './helpers/getNextRootDir.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const runImmediately = process.argv[2]
export async function initDevAndTest(
testSuiteArg: string,
writeDBAdapter: string,
skipGenImportMap: string,
): Promise<void> {
const importMapPath: string = path.resolve(
getNextRootDir(testSuiteArg).rootDir,
'./app/(payload)/admin/importMap.js',
)
try {
fs.writeFileSync(importMapPath, 'export const importMap = {}')
} catch (error) {
console.log('Error writing importMap.js', error)
}
if (writeDBAdapter === 'true') {
const dbAdapter: keyof typeof allDatabaseAdapters =
(process.env.PAYLOAD_DATABASE as keyof typeof allDatabaseAdapters) || 'mongodb'
// Generate databaseAdapter.ts
const databaseAdapter = getDatabaseAdapter(dbAdapter)
// Write to databaseAdapter.ts
fs.writeFileSync(
path.resolve(dirname, 'databaseAdapter.ts'),
`
// DO NOT MODIFY. This file is automatically generated in initDevAndTest.ts
${databaseAdapter}
`,
)
console.log('Wrote', dbAdapter, 'db adapter')
}
if (skipGenImportMap === 'true') {
console.log('Done')
return
}
// Generate importMap
const testDir = path.resolve(dirname, testSuiteArg)
const pathWithConfig = path.resolve(testDir, 'config.ts')
console.log('Generating import map for config:', pathWithConfig)
const config: SanitizedConfig = await (await import(pathWithConfig)).default
process.env.ROOT_DIR = getNextRootDir(testSuiteArg).rootDir
await generateImportMap(config, { log: true, force: true })
console.log('Done')
}
if (runImmediately === 'true') {
const testSuiteArg = process.argv[3]
const writeDBAdapter = process.argv[4]
const skipGenImportMap = process.argv[5]
void initDevAndTest(testSuiteArg, writeDBAdapter, skipGenImportMap)
}