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:
Alessio Gravili
2024-12-17 12:49:29 -07:00
committed by GitHub
parent 70666a0f7b
commit f5c13deb24
39 changed files with 183 additions and 703 deletions

View File

@@ -10,7 +10,12 @@ const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export const createTestHooks = async (testSuiteName = '_community') => {
const tsConfigPath = path.resolve(getNextRootDir().rootDir, './tsconfig.json')
const rootDir = getNextRootDir().rootDir
const tsConfigBasePath = path.resolve(rootDir, './tsconfig.base.json')
const tsConfigPath = existsSync(tsConfigBasePath)
? tsConfigBasePath
: path.resolve(rootDir, './tsconfig.json')
const tsConfigContent = await readFile(tsConfigPath, 'utf8')
const tsConfig = parse(tsConfigContent)
@@ -20,7 +25,7 @@ export const createTestHooks = async (testSuiteName = '_community') => {
*/
beforeTest: async () => {
// Delete entire .next cache folder
const nextCache = path.resolve(getNextRootDir().rootDir, './.next')
const nextCache = path.resolve(rootDir, './.next')
if (existsSync(nextCache)) {
await rm(nextCache, { recursive: true })
}