mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(kit): resolve module tsconfig paths relative to dirs (#23860)
This commit is contained in:
parent
d6c196afad
commit
803c4fe147
@ -42,7 +42,7 @@ export async function installModule (moduleToInstall: string | NuxtModule, inlin
|
||||
|
||||
// --- Internal ---
|
||||
|
||||
function getDirectory (p: string) {
|
||||
export function getDirectory (p: string) {
|
||||
try {
|
||||
// we need to target directories instead of module file paths themselves
|
||||
// /home/user/project/node_modules/module/index.js -> /home/user/project/node_modules/module
|
||||
|
@ -8,6 +8,7 @@ import type { TSConfig } from 'pkg-types'
|
||||
import { readPackageJSON } from 'pkg-types'
|
||||
|
||||
import { tryResolveModule } from './internal/esm'
|
||||
import { getDirectory } from './module/install'
|
||||
import { tryUseNuxt, useNuxt } from './context'
|
||||
import { getModulePaths } from './internal/cjs'
|
||||
import { resolveNuxtModule } from './resolve'
|
||||
@ -110,14 +111,14 @@ export async function updateTemplates (options?: { filter?: (template: ResolvedN
|
||||
return await tryUseNuxt()?.hooks.callHook('builder:generateApp', options)
|
||||
}
|
||||
export async function writeTypes (nuxt: Nuxt) {
|
||||
const modulePaths = getModulePaths(nuxt.options.modulesDir)
|
||||
const nodeModulePaths = getModulePaths(nuxt.options.modulesDir)
|
||||
|
||||
const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir)
|
||||
|
||||
const modules = await resolveNuxtModule(rootDirWithSlash,
|
||||
const modulePaths = await resolveNuxtModule(rootDirWithSlash,
|
||||
nuxt.options._installedModules
|
||||
.filter(m => m.entryPath)
|
||||
.map(m => m.entryPath)
|
||||
.map(m => getDirectory(m.entryPath))
|
||||
)
|
||||
|
||||
const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, {
|
||||
@ -150,11 +151,11 @@ export async function writeTypes (nuxt: Nuxt) {
|
||||
.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), '**/*')] : [],
|
||||
...modules.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime'))
|
||||
...modulePaths.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime'))
|
||||
],
|
||||
exclude: [
|
||||
...nuxt.options.modulesDir.map(m => relativeWithDot(nuxt.options.buildDir, m)),
|
||||
...modules.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime/server')),
|
||||
...modulePaths.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime/server')),
|
||||
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
||||
relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, 'dist'))
|
||||
]
|
||||
@ -215,7 +216,7 @@ export async function writeTypes (nuxt: Nuxt) {
|
||||
...nuxt.options._modules
|
||||
]
|
||||
.filter(f => typeof f === 'string')
|
||||
.map(async id => ({ types: (await readPackageJSON(id, { url: modulePaths }).catch(() => null))?.name || id })))
|
||||
.map(async id => ({ types: (await readPackageJSON(id, { url: nodeModulePaths }).catch(() => null))?.name || id })))
|
||||
|
||||
if (nuxt.options.experimental?.reactivityTransform) {
|
||||
references.push({ types: 'vue/macros-global' })
|
||||
|
Loading…
Reference in New Issue
Block a user