From 3258cacc2893487f87e9ca42adce6e1bb1f13199 Mon Sep 17 00:00:00 2001 From: Andrea Basile <57828270+Evobaso-J@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:31:46 +0100 Subject: [PATCH] fix(schema): add `vueCompilerOptions` property to `tsConfig` (#25924) --- packages/schema/build.config.ts | 1 + packages/schema/package.json | 1 + packages/schema/src/config/typescript.ts | 2 +- packages/schema/src/types/hooks.ts | 7 ++++++- pnpm-lock.yaml | 3 +++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/schema/build.config.ts b/packages/schema/build.config.ts index 04a306a6c4..49c2520e6f 100644 --- a/packages/schema/build.config.ts +++ b/packages/schema/build.config.ts @@ -53,6 +53,7 @@ export default defineBuildConfig({ 'sass-loader', 'c12', 'unenv', + '@vue/language-core', // Implicit '@vue/compiler-core', '@vue/shared', diff --git a/packages/schema/package.json b/packages/schema/package.json index af8b508f11..119738a0a8 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -42,6 +42,7 @@ "@vitejs/plugin-vue": "5.0.4", "@vitejs/plugin-vue-jsx": "3.1.0", "@vue/compiler-core": "3.4.20", + "@vue/language-core": "^1.8.27", "c12": "1.9.0", "esbuild-loader": "4.0.3", "h3": "1.11.1", diff --git a/packages/schema/src/config/typescript.ts b/packages/schema/src/config/typescript.ts index e2ae05df6f..69e13d5094 100644 --- a/packages/schema/src/config/typescript.ts +++ b/packages/schema/src/config/typescript.ts @@ -43,7 +43,7 @@ export default defineUntypedSchema({ /** * You can extend generated `.nuxt/tsconfig.json` using this option. - * @type {typeof import('pkg-types')['TSConfig']} + * @type {0 extends 1 & VueCompilerOptions ? typeof import('pkg-types')['TSConfig'] : typeof import('pkg-types')['TSConfig'] & { vueCompilerOptions?: typeof import('@vue/language-core')['VueCompilerOptions']}} */ tsConfig: {}, diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 72d74aab67..51e06f82d9 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -9,6 +9,7 @@ import type { Compiler, Configuration, Stats } from 'webpack' import type { Nitro, NitroConfig } from 'nitropack' import type { Schema, SchemaDefinition } from 'untyped' import type { RouteLocationRaw } from 'vue-router' +import type { VueCompilerOptions } from '@vue/language-core' import type { NuxtCompatibility, NuxtCompatibilityIssues, ViteConfig } from '..' import type { Component, ComponentsOptions } from './components' import type { Nuxt, NuxtApp, ResolvedNuxtTemplate } from './nuxt' @@ -20,6 +21,10 @@ export type TSReference = { types: string } | { path: string } export type WatchEvent = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir' +// If the user does not have `@vue/language-core` installed, VueCompilerOptions will be typed as `any`, +// thus making the whole `VueTSConfig` type `any`. We only augment TSConfig if VueCompilerOptions is available. +export type VueTSConfig = 0 extends 1 & VueCompilerOptions ? TSConfig : TSConfig & { vueCompilerOptions?: VueCompilerOptions } + export type NuxtPage = { name?: string path: string @@ -282,7 +287,7 @@ export interface NuxtHooks { * @param options Objects containing `references`, `declarations`, `tsConfig` * @returns Promise */ - 'prepare:types': (options: { references: TSReference[], declarations: string[], tsConfig: TSConfig }) => HookResult + 'prepare:types': (options: { references: TSReference[], declarations: string[], tsConfig: VueTSConfig }) => HookResult /** * Called when the dev server is loading. * @param listenerServer The HTTP/HTTPS server object diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f95d103caf..4db50b5fb6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -493,6 +493,9 @@ importers: '@vue/compiler-core': specifier: 3.4.20 version: 3.4.20 + '@vue/language-core': + specifier: ^1.8.27 + version: 1.8.27(typescript@5.3.3) c12: specifier: 1.9.0 version: 1.9.0