Repository navigation
feat(kit): easier way to define global tsConfig options - #35697
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/kit/src/template.ts (1)
437-505: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting the shared compiler options to reduce duplication.
The fallback
compilerOptionsmapped frombaseTsConfigare identical for bothnodeTsConfigandsharedTsConfig. Extracting them into a shared variable could reduce duplication and make it easier to maintain in the future.♻️ Proposed refactor
const tsConfig: TSConfig = defu(nuxt.options.typescript?.appTsConfig, baseTsConfig) + + const sharedFallbackCompilerOptions = { + /* Base options: */ + esModuleInterop: baseTsConfig.compilerOptions?.esModuleInterop, + skipLibCheck: baseTsConfig.compilerOptions?.skipLibCheck, + target: baseTsConfig.compilerOptions?.target, + allowJs: baseTsConfig.compilerOptions?.allowJs, + allowImportingTsExtensions: baseTsConfig.compilerOptions?.allowImportingTsExtensions, + resolveJsonModule: baseTsConfig.compilerOptions?.resolveJsonModule, + moduleDetection: baseTsConfig.compilerOptions?.moduleDetection, + isolatedModules: baseTsConfig.compilerOptions?.isolatedModules, + verbatimModuleSyntax: baseTsConfig.compilerOptions?.verbatimModuleSyntax, + allowArbitraryExtensions: baseTsConfig.compilerOptions?.allowArbitraryExtensions, + /* Strictness */ + strict: baseTsConfig.compilerOptions?.strict, + noUncheckedIndexedAccess: baseTsConfig.compilerOptions?.noUncheckedIndexedAccess, + forceConsistentCasingInFileNames: baseTsConfig.compilerOptions?.forceConsistentCasingInFileNames, + noImplicitOverride: baseTsConfig.compilerOptions?.noImplicitOverride, + /* If NOT transpiling with TypeScript: */ + module: baseTsConfig.compilerOptions?.module, + noEmit: true, + /* remove auto-scanning for types */ + types: [], + /* add paths object for filling-in later */ + paths: {}, + /* Possibly consider removing the following in future */ + moduleResolution: baseTsConfig.compilerOptions?.moduleResolution, + useDefineForClassFields: baseTsConfig.compilerOptions?.useDefineForClassFields, + noImplicitThis: baseTsConfig.compilerOptions?.noImplicitThis, + allowSyntheticDefaultImports: baseTsConfig.compilerOptions?.allowSyntheticDefaultImports, + } // This describes the environment where we load `nuxt.config.ts` (and modules) const nodeTsConfig: TSConfig = defu(nuxt.options.typescript?.nodeTsConfig, { compilerOptions: globalCompilerOptions }, { - compilerOptions: { - /* Base options: */ - esModuleInterop: baseTsConfig.compilerOptions?.esModuleInterop, - skipLibCheck: baseTsConfig.compilerOptions?.skipLibCheck, - target: baseTsConfig.compilerOptions?.target, - allowJs: baseTsConfig.compilerOptions?.allowJs, - allowImportingTsExtensions: baseTsConfig.compilerOptions?.allowImportingTsExtensions, - resolveJsonModule: baseTsConfig.compilerOptions?.resolveJsonModule, - moduleDetection: baseTsConfig.compilerOptions?.moduleDetection, - isolatedModules: baseTsConfig.compilerOptions?.isolatedModules, - verbatimModuleSyntax: baseTsConfig.compilerOptions?.verbatimModuleSyntax, - allowArbitraryExtensions: baseTsConfig.compilerOptions?.allowArbitraryExtensions, - /* Strictness */ - strict: baseTsConfig.compilerOptions?.strict, - noUncheckedIndexedAccess: baseTsConfig.compilerOptions?.noUncheckedIndexedAccess, - forceConsistentCasingInFileNames: baseTsConfig.compilerOptions?.forceConsistentCasingInFileNames, - noImplicitOverride: baseTsConfig.compilerOptions?.noImplicitOverride, - /* If NOT transpiling with TypeScript: */ - module: baseTsConfig.compilerOptions?.module, - noEmit: true, - /* remove auto-scanning for types */ - types: [], - /* add paths object for filling-in later */ - paths: {}, - /* Possibly consider removing the following in future */ - moduleResolution: baseTsConfig.compilerOptions?.moduleResolution, - useDefineForClassFields: baseTsConfig.compilerOptions?.useDefineForClassFields, - noImplicitThis: baseTsConfig.compilerOptions?.noImplicitThis, - allowSyntheticDefaultImports: baseTsConfig.compilerOptions?.allowSyntheticDefaultImports, - }, + compilerOptions: sharedFallbackCompilerOptions, include: [...nodeInclude], exclude: [...nodeExclude], } satisfies TSConfig) // This describes the environment where we load `nuxt.config.ts` (and modules) const sharedTsConfig: TSConfig = defu(nuxt.options.typescript?.sharedTsConfig, { compilerOptions: globalCompilerOptions }, { - compilerOptions: { - /* Base options: */ - esModuleInterop: baseTsConfig.compilerOptions?.esModuleInterop, - skipLibCheck: baseTsConfig.compilerOptions?.skipLibCheck, - target: baseTsConfig.compilerOptions?.target, - allowJs: baseTsConfig.compilerOptions?.allowJs, - allowImportingTsExtensions: baseTsConfig.compilerOptions?.allowImportingTsExtensions, - resolveJsonModule: baseTsConfig.compilerOptions?.resolveJsonModule, - moduleDetection: baseTsConfig.compilerOptions?.moduleDetection, - isolatedModules: baseTsConfig.compilerOptions?.isolatedModules, - verbatimModuleSyntax: baseTsConfig.compilerOptions?.verbatimModuleSyntax, - allowArbitraryExtensions: baseTsConfig.compilerOptions?.allowArbitraryExtensions, - /* Strictness */ - strict: baseTsConfig.compilerOptions?.strict, - noUncheckedIndexedAccess: baseTsConfig.compilerOptions?.noUncheckedIndexedAccess, - forceConsistentCasingInFileNames: baseTsConfig.compilerOptions?.forceConsistentCasingInFileNames, - noImplicitOverride: baseTsConfig.compilerOptions?.noImplicitOverride, - /* If NOT transpiling with TypeScript: */ - module: baseTsConfig.compilerOptions?.module, - noEmit: true, - /* remove auto-scanning for types */ - types: [], - /* add paths object for filling-in later */ - paths: {}, - /* Possibly consider removing the following in future */ - moduleResolution: baseTsConfig.compilerOptions?.moduleResolution, - useDefineForClassFields: baseTsConfig.compilerOptions?.useDefineForClassFields, - noImplicitThis: baseTsConfig.compilerOptions?.noImplicitThis, - allowSyntheticDefaultImports: baseTsConfig.compilerOptions?.allowSyntheticDefaultImports, - }, + compilerOptions: sharedFallbackCompilerOptions, include: [...sharedInclude], exclude: [...sharedExclude], } satisfies TSConfig)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/kit/src/template.ts` around lines 437 - 505, Extract the duplicated baseTsConfig-derived compiler options from the nodeTsConfig and sharedTsConfig definitions into one shared variable, then reuse it in both defu fallback configurations. Preserve each config’s distinct include and exclude settings while keeping the resulting compiler options unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/kit/src/template.ts`:
- Around line 437-505: Extract the duplicated baseTsConfig-derived compiler
options from the nodeTsConfig and sharedTsConfig definitions into one shared
variable, then reuse it in both defu fallback configurations. Preserve each
config’s distinct include and exclude settings while keeping the resulting
compiler options unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 52318f13-5a17-42f5-a269-c9255f9981a0
📒 Files selected for processing (10)
docs/2.directory-structure/3.tsconfig.mddocs/3.guide/4.modules/5.recipes-advanced.mddocs/4.api/6.nuxt-config.mdpackages/kit/src/template.tspackages/kit/test/generate-types.spec.tspackages/nitro-server/src/augments.tspackages/nitro-server/src/index.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/test/load-nuxt.test.tspackages/schema/src/types/schema.ts
Merging this PR will degrade performance by 10.38%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
typescript.tsConfig to all generated tsconfigs
|
sorry @cernymatej, I thought it might be safer to keep the portal in place |
typescript.tsConfig to all generated tsconfigstsConfig options
Co-authored-by: Daniel Roe <[email protected]>
Co-authored-by: Daniel Roe <[email protected]>
🔗 Linked issue
Resolves #33678
📚 Description
typescript.tsConfigis now a shared baseline for all four generated tsconfigs (app,server,node,shared), not justtsconfig.app.json. NewappTsConfigandserverTsConfigjoin the existingnodeTsConfig/sharedTsConfigfor per-context overrides.Precedence: context-specific > global
tsConfig> Nuxt/Nitro defaults. OnlycompilerOptionspropagate globally;include/excludestay per-context, andvueCompilerOptionsstays app-only.Per the comment in #33678,
typescript.serverTsConfigreplacesnitro.typescript.tsConfigin Nuxt config (v5-only, no compat sync). Modules can still set nuxt.options.nitro.typescript.tsConfig programmatically.Tests
Cover global propagation, per-context override precedence. Docs updated for the new options.