build: fix tsconfig monorepo setup (#10028)
Should fix messed up import suggestions and simplifies all tsconfigs through inheritance. One main issue was that packages were inheriting `baseURL: "."` from the root tsconfig. This caused incorrect import suggestions that start with "packages/...". This PR ensures that packages do not inherit this baseURL: "." property, while ensuring the root, non-inherited tsconfig still keeps it to get tests to work (the importMap needs it)
This commit is contained in:
@@ -11,15 +11,20 @@ import { parse, stringify } from 'comment-json'
|
||||
import path from 'path'
|
||||
import fs from 'fs/promises'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { existsSync } from 'fs'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const tsConfigPath = path.resolve(dirname, '../tsconfig.json')
|
||||
const tsConfigBasePath = path.resolve(dirname, '../tsconfig.base.json')
|
||||
const tsConfigPath = existsSync(tsConfigBasePath)
|
||||
? tsConfigBasePath
|
||||
: path.resolve(dirname, '../tsconfig.json')
|
||||
|
||||
|
||||
const tsConfigContent = await fs.readFile(tsConfigPath, 'utf8')
|
||||
const tsConfig = parse(tsConfigContent)
|
||||
|
||||
// @ts-expect-error
|
||||
tsConfig.compilerOptions.paths['@payload-config'] = ['./test/_community/config.ts']
|
||||
const output = stringify(tsConfig, null, 2) + `\n`
|
||||
await fs.writeFile(tsConfigPath, output)
|
||||
|
||||
Reference in New Issue
Block a user