mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(kit): do not use module: preserve
unelss ts v5.4 is installed
This commit is contained in:
parent
0d84300218
commit
b08dfc98be
@ -5,6 +5,7 @@ import type { Nuxt, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate, TSRefe
|
||||
import { withTrailingSlash } from 'ufo'
|
||||
import { defu } from 'defu'
|
||||
import type { TSConfig } from 'pkg-types'
|
||||
import { gte } from 'semver'
|
||||
import { readPackageJSON } from 'pkg-types'
|
||||
|
||||
import { tryResolveModule } from './internal/esm'
|
||||
@ -122,6 +123,12 @@ export async function _generateTypes (nuxt: Nuxt) {
|
||||
.map(m => getDirectory(m.entryPath)),
|
||||
)
|
||||
|
||||
const isV4 = nuxt.options.future?.compatibilityVersion === 4
|
||||
|
||||
const hasTypescriptVersionWithModulePreserve = await readPackageJSON('typescript', { url: nuxt.options.modulesDir })
|
||||
.then(r => r?.version && gte(r.version, '5.4.0'))
|
||||
.catch(() => isV4)
|
||||
|
||||
// https://www.totaltypescript.com/tsconfig-cheat-sheet
|
||||
const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, {
|
||||
compilerOptions: {
|
||||
@ -136,11 +143,11 @@ export async function _generateTypes (nuxt: Nuxt) {
|
||||
verbatimModuleSyntax: true,
|
||||
/* Strictness */
|
||||
strict: nuxt.options.typescript?.strict ?? true,
|
||||
noUncheckedIndexedAccess: nuxt.options.future?.compatibilityVersion === 4,
|
||||
noUncheckedIndexedAccess: isV4,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
noImplicitOverride: true,
|
||||
/* If NOT transpiling with TypeScript: */
|
||||
module: 'preserve',
|
||||
module: hasTypescriptVersionWithModulePreserve ? 'preserve' : 'es2022',
|
||||
noEmit: true,
|
||||
/* If your code runs in the DOM: */
|
||||
lib: [
|
||||
|
Loading…
Reference in New Issue
Block a user