From 826f82a6da36fd4585b610b0126725b5ca1d2760 Mon Sep 17 00:00:00 2001 From: Samuel Burkhard Date: Fri, 14 Jul 2023 16:32:59 +0200 Subject: [PATCH] fix(cli): add aliases to monorepo paths to tsconfig includes (#21997) Co-authored-by: Daniel Roe --- packages/nuxi/src/utils/prepare.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/prepare.ts b/packages/nuxi/src/utils/prepare.ts index 5d9de151ce..10bcb42a28 100644 --- a/packages/nuxi/src/utils/prepare.ts +++ b/packages/nuxi/src/utils/prepare.ts @@ -3,11 +3,14 @@ import { isAbsolute, join, relative, resolve } from 'pathe' import type { Nuxt, TSReference } from '@nuxt/schema' import { defu } from 'defu' import type { TSConfig } from 'pkg-types' +import { withTrailingSlash } from 'ufo' import { getModulePaths, getNearestPackage } from './cjs' export const writeTypes = async (nuxt: Nuxt) => { const modulePaths = getModulePaths(nuxt.options.modulesDir) + const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir) + const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, { compilerOptions: { forceConsistentCasingInFileNames: true, @@ -31,7 +34,7 @@ export const writeTypes = async (nuxt: Nuxt) => { join(relative(nuxt.options.buildDir, nuxt.options.rootDir), '**/*'), ...nuxt.options.srcDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.srcDir), '**/*')] : [], ...nuxt.options._layers.map(layer => layer.config.srcDir ?? layer.cwd) - .filter(srcOrCwd => !srcOrCwd.startsWith(nuxt.options.rootDir) || srcOrCwd.includes('node_modules')) + .filter(srcOrCwd => !srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd.includes('node_modules')) .map(srcOrCwd => join(relative(nuxt.options.buildDir, srcOrCwd), '**/*')), ...nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), '**/*')] : [] ], @@ -52,6 +55,7 @@ export const writeTypes = async (nuxt: Nuxt) => { const basePath = tsConfig.compilerOptions!.baseUrl ? resolve(nuxt.options.buildDir, tsConfig.compilerOptions!.baseUrl) : nuxt.options.buildDir tsConfig.compilerOptions = tsConfig.compilerOptions || {} + tsConfig.include = tsConfig.include || [] for (const alias in aliases) { if (excludedAlias.some(re => re.test(alias))) { @@ -63,8 +67,17 @@ export const writeTypes = async (nuxt: Nuxt) => { if (stats?.isDirectory()) { tsConfig.compilerOptions.paths[alias] = [absolutePath] tsConfig.compilerOptions.paths[`${alias}/*`] = [`${absolutePath}/*`] + + if (!absolutePath.startsWith(rootDirWithSlash)) { + tsConfig.include.push(absolutePath) + tsConfig.include.push(`${absolutePath}/*`) + } } else { tsConfig.compilerOptions.paths[alias] = [absolutePath.replace(/(?<=\w)\.\w+$/g, '')] /* remove extension */ + + if (!absolutePath.startsWith(rootDirWithSlash)) { + tsConfig.include.push(absolutePath.replace(/(?<=\w)\.\w+$/g, '')) + } } }