mirror of
https://github.com/payloadcms/payload.git
synced 2026-09-14 20:07:19 +08:00
22 lines
705 B
JavaScript
22 lines
705 B
JavaScript
|
|
import fs from 'fs/promises'
|
||
|
|
import { existsSync } from 'fs'
|
||
|
|
import path from 'path'
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Replace the @payload-config path in tsconfig.base.json using string replacement
|
||
|
|
* to avoid reformatting the entire file.
|
||
|
|
*/
|
||
|
|
export async function replacePayloadConfigPath(rootDir, configPath) {
|
||
|
|
const tsConfigBasePath = path.resolve(rootDir, './tsconfig.base.json')
|
||
|
|
const tsConfigPath = existsSync(tsConfigBasePath)
|
||
|
|
? tsConfigBasePath
|
||
|
|
: path.resolve(rootDir, './tsconfig.json')
|
||
|
|
|
||
|
|
const content = await fs.readFile(tsConfigPath, 'utf8')
|
||
|
|
const updated = content.replace(
|
||
|
|
/("@payload-config":\s*\[\s*)"[^"]*"(\s*\])/,
|
||
|
|
`$1"${configPath}"$2`,
|
||
|
|
)
|
||
|
|
await fs.writeFile(tsConfigPath, updated)
|
||
|
|
}
|