From b0a5e5b59ea856e80c3114f694267b0802632082 Mon Sep 17 00:00:00 2001 From: waset Date: Tue, 3 Sep 2024 16:16:24 +0800 Subject: [PATCH] feat: use runtime functional options --- src/core/declaration.ts | 35 ++++++++++++++++++++++++----------- src/core/options.ts | 2 ++ src/types.ts | 5 +++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/core/declaration.ts b/src/core/declaration.ts index 2d96dc78..c286197b 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -114,28 +114,41 @@ export function getDeclaration(ctx: Context, filepath: string, originalImports?: directive: stringifyDeclarationImports({ ...originalImports?.directive, ...imports.directive }), } - let code = `/* eslint-disable */ -// @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 -export {} - -/* prettier-ignore */ -declare module 'vue' {` - + let items = '' if (Object.keys(declarations.component).length > 0) { - code += ` + items += ` export interface GlobalComponents { ${declarations.component.join('\n ')} }` } + if (Object.keys(declarations.directive).length > 0) { - code += ` + items += ` export interface ComponentCustomProperties { ${declarations.directive.join('\n ')} }` } + + let code = `/* eslint-disable */ +// @ts-nocheck +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 +export {} + +/* prettier-ignore */ +declare module 'vue' {` + if (items) + code += items code += '\n}\n' + + if (ctx.options.runtime) + code += ` +/* prettier-ignore */ +declare module '@vue/runtime-core' {` + if (items) + code += items + code += '\n}\n' + return code } diff --git a/src/core/options.ts b/src/core/options.ts index 4b44e914..356232a1 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -19,6 +19,8 @@ export const defaultOptions: Omit, 'include' | 'exclude' | 'ex importPathTransform: v => v, allowOverrides: false, + + runtime: false, } function normalizeResolvers(resolvers: (ComponentResolver | ComponentResolver[])[]): ComponentResolverObject[] { diff --git a/src/types.ts b/src/types.ts index 967d9486..9d7f2b8e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -181,6 +181,11 @@ export interface Options { * Vue version of project. It will detect automatically if not specified. */ version?: 2 | 2.7 | 3 + + /** + * Whether runtime is needed + */ + runtime?: boolean } export type ResolvedOptions = Omit<