chore: fix dev:generate-types not working (#6284)
This commit is contained in:
@@ -6,22 +6,23 @@ import { setTestEnvPaths } from './helpers/setTestEnvPaths.js'
|
|||||||
|
|
||||||
const [testConfigDir] = process.argv.slice(2)
|
const [testConfigDir] = process.argv.slice(2)
|
||||||
|
|
||||||
|
import type { SanitizedConfig } from 'payload/types'
|
||||||
|
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
import { load } from './loader/load.js'
|
import { load } from './loader/load.js'
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
const loadConfig = async (configPath: string) => {
|
|
||||||
const configPromise = await load(configPath)
|
|
||||||
return configPromise.default
|
|
||||||
}
|
|
||||||
|
|
||||||
let testDir
|
let testDir
|
||||||
if (testConfigDir) {
|
if (testConfigDir) {
|
||||||
testDir = path.resolve(dirname, testConfigDir)
|
testDir = path.resolve(dirname, testConfigDir)
|
||||||
|
|
||||||
const config = await loadConfig(path.resolve(testDir, 'config.ts'))
|
console.log('Generating types for config:', path.resolve(testDir, 'config.ts'))
|
||||||
|
|
||||||
|
const config: SanitizedConfig = (await load(
|
||||||
|
path.resolve(testDir, 'config.ts'),
|
||||||
|
)) as unknown as SanitizedConfig
|
||||||
|
|
||||||
setTestEnvPaths(testDir)
|
setTestEnvPaths(testDir)
|
||||||
generateTypes(config)
|
generateTypes(config)
|
||||||
@@ -29,7 +30,14 @@ if (testConfigDir) {
|
|||||||
// Generate types for entire directory
|
// Generate types for entire directory
|
||||||
testDir = dirname
|
testDir = dirname
|
||||||
|
|
||||||
const config = await loadConfig(path.resolve(testDir, 'config.ts'))
|
console.log(
|
||||||
|
'No testConfigDir passed. Generating types for config:',
|
||||||
|
path.resolve(testDir, 'config.ts'),
|
||||||
|
)
|
||||||
|
|
||||||
|
const config: SanitizedConfig = (await load(
|
||||||
|
path.resolve(testDir, 'config.ts'),
|
||||||
|
)) as unknown as SanitizedConfig
|
||||||
|
|
||||||
fs.readdirSync(dirname, { withFileTypes: true })
|
fs.readdirSync(dirname, { withFileTypes: true })
|
||||||
.filter((f) => f.isDirectory())
|
.filter((f) => f.isDirectory())
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
const filename = fileURLToPath(import.meta.url)
|
||||||
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
export const load = async (filePath) => {
|
export const load = async (filePath) => {
|
||||||
const importConfigImport = await import(
|
const resolvedImportWithoutClientFilesPath = path.resolve(
|
||||||
'../../packages/payload/dist/utilities/importWithoutClientFiles.js'
|
dirname,
|
||||||
|
'../../packages/payload/dist/utilities/importWithoutClientFiles.js',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// First check if ../../packages/payload/dist/utilities/importWithoutClientFiles.js exist
|
||||||
|
// If it does not, throw a proper error
|
||||||
|
if (!fs.existsSync(resolvedImportWithoutClientFilesPath)) {
|
||||||
|
throw new Error(
|
||||||
|
'Looks like payload has not been built. Please run `pnpm build:core` in the monorepo root',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const importConfigImport = await import(resolvedImportWithoutClientFilesPath)
|
||||||
const importConfig = importConfigImport.importConfig
|
const importConfig = importConfigImport.importConfig
|
||||||
|
|
||||||
const result = await importConfig(filePath)
|
const result = await importConfig(filePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user