From 5a09a2eb5a9e22e14ef5494bdd7920848f746c61 Mon Sep 17 00:00:00 2001 From: FENG/XIAODONG Date: Thu, 27 Jul 2023 22:24:24 +0800 Subject: [PATCH 1/4] feat(idux): add new components (#665) --- src/core/resolvers/idux.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/resolvers/idux.ts b/src/core/resolvers/idux.ts index f9cd036e..bff2034c 100644 --- a/src/core/resolvers/idux.ts +++ b/src/core/resolvers/idux.ts @@ -3,6 +3,11 @@ import { kebabCase } from '../utils' const specialComponents: Record = { CdkVirtualScroll: 'scroll', + CdkClickOutside: 'click-outside', + CdkDraggable: 'drag-drop', + CdkResizable: 'resize', + CdkResizableHandle: 'resize', + CdkResizeObserver: 'resize', IxAutoComplete: 'auto-complete', IxBackTop: 'back-top', IxDatePicker: 'date-picker', @@ -14,6 +19,8 @@ const specialComponents: Record = { IxTreeSelect: 'tree-select', IxTimePicker: 'time-picker', IxTimeRangePicker: 'time-picker', + IxLoadingBar: 'loading-bar', + IxLoadingBarProvider: 'loading-bar', } export interface IduxResolverOptions { From 4db550cd53dfe68f9b48355451fa893a055b9f72 Mon Sep 17 00:00:00 2001 From: Cherry7 <79909910+CCherry07@users.noreply.github.com> Date: Fri, 28 Jul 2023 01:01:16 +0800 Subject: [PATCH 2/4] chore: support antdv4 new components (#658) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 内小子 --- src/core/resolvers/antdv.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/resolvers/antdv.ts b/src/core/resolvers/antdv.ts index 35c38865..16f64d37 100644 --- a/src/core/resolvers/antdv.ts +++ b/src/core/resolvers/antdv.ts @@ -164,6 +164,10 @@ const matchComponents: IMatcher[] = [ pattern: /^Qrcode/, styleDir: 'qrcode', }, + { + pattern: /^Space/, + styleDir: 'space', + }, ] export interface AntDesignVueResolverOptions { @@ -246,7 +250,7 @@ function getSideEffects(compName: string, options: AntDesignVueResolverOptions): return `${packageName}/${lib}/${styleDir}/style/css` } } -const primitiveNames = ['Affix', 'Anchor', 'AnchorLink', 'AutoComplete', 'AutoCompleteOptGroup', 'AutoCompleteOption', 'Alert', 'Avatar', 'AvatarGroup', 'BackTop', 'Badge', 'BadgeRibbon', 'Breadcrumb', 'BreadcrumbItem', 'BreadcrumbSeparator', 'Button', 'ButtonGroup', 'Calendar', 'Card', 'CardGrid', 'CardMeta', 'Collapse', 'CollapsePanel', 'Carousel', 'Cascader', 'Checkbox', 'CheckboxGroup', 'Col', 'Comment', 'ConfigProvider', 'DatePicker', 'MonthPicker', 'WeekPicker', 'RangePicker', 'QuarterPicker', 'Descriptions', 'DescriptionsItem', 'Divider', 'Dropdown', 'DropdownButton', 'Drawer', 'Empty', 'Form', 'FormItem', 'FormItemRest', 'Grid', 'Input', 'InputGroup', 'InputPassword', 'InputSearch', 'Textarea', 'Image', 'ImagePreviewGroup', 'InputNumber', 'Layout', 'LayoutHeader', 'LayoutSider', 'LayoutFooter', 'LayoutContent', 'List', 'ListItem', 'ListItemMeta', 'Menu', 'MenuDivider', 'MenuItem', 'MenuItemGroup', 'SubMenu', 'Mentions', 'MentionsOption', 'Modal', 'Statistic', 'StatisticCountdown', 'PageHeader', 'Pagination', 'Popconfirm', 'Popover', 'Progress', 'Radio', 'RadioButton', 'RadioGroup', 'Rate', 'Result', 'Row', 'Select', 'SelectOptGroup', 'SelectOption', 'Skeleton', 'SkeletonButton', 'SkeletonAvatar', 'SkeletonInput', 'SkeletonImage', 'Slider', 'Space', 'Spin', 'Steps', 'Step', 'Switch', 'Table', 'TableColumn', 'TableColumnGroup', 'TableSummary', 'TableSummaryRow', 'TableSummaryCell', 'Transfer', 'Tree', 'TreeNode', 'DirectoryTree', 'TreeSelect', 'TreeSelectNode', 'Tabs', 'TabPane', 'Tag', 'CheckableTag', 'TimePicker', 'TimeRangePicker', 'Timeline', 'TimelineItem', 'Tooltip', 'Typography', 'TypographyLink', 'TypographyParagraph', 'TypographyText', 'TypographyTitle', 'Upload', 'UploadDragger', 'LocaleProvider', 'FloatButton', 'FloatButtonGroup', 'Qrcode', 'Watermark', 'Segmented', 'Tour'] +const primitiveNames = ['Affix', 'Anchor', 'AnchorLink', 'AutoComplete', 'AutoCompleteOptGroup', 'AutoCompleteOption', 'Alert', 'Avatar', 'AvatarGroup', 'BackTop', 'Badge', 'BadgeRibbon', 'Breadcrumb', 'BreadcrumbItem', 'BreadcrumbSeparator', 'Button', 'ButtonGroup', 'Calendar', 'Card', 'CardGrid', 'CardMeta', 'Collapse', 'CollapsePanel', 'Carousel', 'Cascader', 'Checkbox', 'CheckboxGroup', 'Col', 'Comment', 'ConfigProvider', 'DatePicker', 'MonthPicker', 'WeekPicker', 'RangePicker', 'QuarterPicker', 'Descriptions', 'DescriptionsItem', 'Divider', 'Dropdown', 'DropdownButton', 'Drawer', 'Empty', 'Form', 'FormItem', 'FormItemRest', 'Grid', 'Input', 'InputGroup', 'InputPassword', 'InputSearch', 'Textarea', 'Image', 'ImagePreviewGroup', 'InputNumber', 'Layout', 'LayoutHeader', 'LayoutSider', 'LayoutFooter', 'LayoutContent', 'List', 'ListItem', 'ListItemMeta', 'Menu', 'MenuDivider', 'MenuItem', 'MenuItemGroup', 'SubMenu', 'Mentions', 'MentionsOption', 'Modal', 'Statistic', 'StatisticCountdown', 'PageHeader', 'Pagination', 'Popconfirm', 'Popover', 'Progress', 'Radio', 'RadioButton', 'RadioGroup', 'Rate', 'Result', 'Row', 'Select', 'SelectOptGroup', 'SelectOption', 'Skeleton', 'SkeletonButton', 'SkeletonAvatar', 'SkeletonInput', 'SkeletonImage', 'Slider', 'Space', 'Spin', 'Steps', 'Step', 'Switch', 'Table', 'TableColumn', 'TableColumnGroup', 'TableSummary', 'TableSummaryRow', 'TableSummaryCell', 'Transfer', 'Tree', 'TreeNode', 'DirectoryTree', 'TreeSelect', 'TreeSelectNode', 'Tabs', 'TabPane', 'Tag', 'CheckableTag', 'TimePicker', 'TimeRangePicker', 'Timeline', 'TimelineItem', 'Tooltip', 'Typography', 'TypographyLink', 'TypographyParagraph', 'TypographyText', 'TypographyTitle', 'Upload', 'UploadDragger', 'LocaleProvider', 'FloatButton', 'FloatButtonGroup', 'Qrcode', 'Watermark', 'Segmented', 'Tour', 'SpaceCompact', 'StyleProvider'] const prefix = 'A' let antdvNames: Set @@ -263,6 +267,8 @@ function isAntdv(compName: string): boolean { function getImportName(compName: string): string { if (compName === 'Qrcode') return 'QRCode' + else if (compName === 'SpaceCompact') + return 'Compact' return compName } From 7c9169841dd83f54a4034a1d3a34c044f468ef4a Mon Sep 17 00:00:00 2001 From: lishaobos Date: Mon, 7 Aug 2023 18:40:15 +0800 Subject: [PATCH 3/4] fix: tsx component type declaration --- src/core/declaration.ts | 12 +++++--- test/__snapshots__/dts.test.ts.snap | 48 ++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/core/declaration.ts b/src/core/declaration.ts index fa6241c4..9dc9a9ed 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -114,11 +114,9 @@ export function getDeclaration(ctx: Context, filepath: string, originalImports?: directive: stringifyDeclarationImports({ ...originalImports?.directive, ...imports.directive }), } - const head = ctx.options.version === 2.7 - ? `export {} + const head = `export {} -declare module 'vue' {` - : `export {} +import { GlobalComponents } from 'vue' declare module 'vue' {` @@ -142,6 +140,12 @@ ${head}` }` } code += '\n}\n' + if (Object.keys(declarations.component).length > 0) { + code += ` +declare global { + ${declarations.component.map(d => d.replace(/(.+):/, 'const $1:')).join('\n ')} +}` + } return code } diff --git a/test/__snapshots__/dts.test.ts.snap b/test/__snapshots__/dts.test.ts.snap index ea2af4da..e3db46a4 100644 --- a/test/__snapshots__/dts.test.ts.snap +++ b/test/__snapshots__/dts.test.ts.snap @@ -8,6 +8,8 @@ exports[`dts > components only 1`] = ` // Read more: https://github.com/vuejs/core/pull/3399 export {} +import { GlobalComponents } from 'vue' + declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] @@ -15,7 +17,12 @@ declare module 'vue' { TestComp: typeof import('test/component/TestComp')['default'] } } -" + +declare global { + const RouterLink: typeof import('vue-router')['RouterLink'] + const RouterView: typeof import('vue-router')['RouterView'] + const TestComp: typeof import('test/component/TestComp')['default'] +}" `; exports[`dts > directive only 1`] = ` @@ -26,6 +33,8 @@ exports[`dts > directive only 1`] = ` // Read more: https://github.com/vuejs/core/pull/3399 export {} +import { GlobalComponents } from 'vue' + declare module 'vue' { export interface ComponentCustomProperties { vLoading: typeof import('test/directive/Loading')['default'] @@ -42,6 +51,8 @@ exports[`dts > getDeclaration 1`] = ` // Read more: https://github.com/vuejs/core/pull/3399 export {} +import { GlobalComponents } from 'vue' + declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] @@ -52,7 +63,12 @@ declare module 'vue' { vLoading: typeof import('test/directive/Loading')['default'] } } -" + +declare global { + const RouterLink: typeof import('vue-router')['RouterLink'] + const RouterView: typeof import('vue-router')['RouterView'] + const TestComp: typeof import('test/component/TestComp')['default'] +}" `; exports[`dts > parseDeclaration - has icon component like 1`] = ` @@ -100,6 +116,8 @@ exports[`dts > vue 2.7 components only 1`] = ` // Read more: https://github.com/vuejs/core/pull/3399 export {} +import { GlobalComponents } from 'vue' + declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] @@ -107,7 +125,12 @@ declare module 'vue' { TestComp: typeof import('test/component/TestComp')['default'] } } -" + +declare global { + const RouterLink: typeof import('vue-router')['RouterLink'] + const RouterView: typeof import('vue-router')['RouterView'] + const TestComp: typeof import('test/component/TestComp')['default'] +}" `; exports[`dts > writeDeclaration - keep unused 1`] = ` @@ -118,6 +141,8 @@ exports[`dts > writeDeclaration - keep unused 1`] = ` // Read more: https://github.com/vuejs/core/pull/3399 export {} +import { GlobalComponents } from 'vue' + declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] @@ -131,7 +156,13 @@ declare module 'vue' { vSome: typeof import('test/directive/Some')['default'] } } -" + +declare global { + const RouterLink: typeof import('vue-router')['RouterLink'] + const RouterView: typeof import('vue-router')['RouterView'] + const SomeComp: typeof import('test/component/SomeComp')['default'] + const TestComp: typeof import('test/component/TestComp')['default'] +}" `; exports[`dts > writeDeclaration 1`] = ` @@ -142,6 +173,8 @@ exports[`dts > writeDeclaration 1`] = ` // Read more: https://github.com/vuejs/core/pull/3399 export {} +import { GlobalComponents } from 'vue' + declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] @@ -152,5 +185,10 @@ declare module 'vue' { vLoading: typeof import('test/directive/Loading')['default'] } } -" + +declare global { + const RouterLink: typeof import('vue-router')['RouterLink'] + const RouterView: typeof import('vue-router')['RouterView'] + const TestComp: typeof import('test/component/TestComp')['default'] +}" `; From d7190dae030b380a484b7cc68b03a631f035bb24 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 20 Oct 2025 08:05:09 +0900 Subject: [PATCH 4/4] feat: introduce flag for it --- README.md | 4 + src/core/declaration.ts | 17 ++-- src/core/options.ts | 1 + src/types.ts | 9 ++ test/__snapshots__/dts.test.ts.snap | 148 ++++++++++++---------------- test/dts.test.ts | 16 +++ 6 files changed, 106 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index f3b867f8..c19ef3bd 100644 --- a/README.md +++ b/README.md @@ -423,6 +423,10 @@ Components({ // default: `true` if package typescript is installed dts: false, + // generate dts with TSX support + // default: `true` if `@vitejs/plugin-vue-jsx` is installed + dtsTsx: false, + // Allow subdirectories as namespace prefix for components. directoryAsNamespace: false, diff --git a/src/core/declaration.ts b/src/core/declaration.ts index 6b6b07d8..1bbf2168 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -116,14 +116,14 @@ export function getDeclaration(ctx: Context, filepath: string, originalImports?: let code = `/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 +${ctx.options.dtsTsx ? `import { GlobalComponents } from 'vue'\n` : ''} export {} -import { GlobalComponents } from 'vue' - /* prettier-ignore */ declare module 'vue' {` @@ -140,11 +140,16 @@ declare module 'vue' {` }` } code += '\n}\n' - if (Object.keys(declarations.component).length > 0) { - code += ` + + // for TSX support + if (ctx.options.dtsTsx) { + if (Object.keys(declarations.component).length > 0) { + code += ` +// For TSX support declare global { ${declarations.component.map(d => d.replace(/(.+):/, 'const $1:')).join('\n ')} }` + } } return code } diff --git a/src/core/options.ts b/src/core/options.ts index b55c06a8..68edc1a5 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -10,6 +10,7 @@ export const defaultOptions: Omit, 'include' | 'exclude' | 'ex extensions: 'vue', deep: true, dts: isPackageExists('typescript'), + dtsTsx: isPackageExists('@vitejs/plugin-vue-jsx'), directoryAsNamespace: false, collapseSamePrefixes: false, diff --git a/src/types.ts b/src/types.ts index 3f1cb578..0e274110 100644 --- a/src/types.ts +++ b/src/types.ts @@ -176,6 +176,14 @@ export interface Options { */ dts?: boolean | string + /** + * Generate TypeScript declaration for global components + * For TSX support + * + * @default true if `@vitejs/plugin-vue-jsx` is installed + */ + dtsTsx?: boolean + /** * Do not emit warning on component overriding * @@ -243,6 +251,7 @@ export type ResolvedOptions = Omit< globs: string[] globsExclude: string[] dts: string | false + dtsTsx: boolean root: string } diff --git a/test/__snapshots__/dts.test.ts.snap b/test/__snapshots__/dts.test.ts.snap index 2c2619d9..3b13882f 100644 --- a/test/__snapshots__/dts.test.ts.snap +++ b/test/__snapshots__/dts.test.ts.snap @@ -3,13 +3,13 @@ exports[`dts > components only 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -19,24 +19,19 @@ declare module 'vue' { TestComp: typeof import('test/component/TestComp')['default'] } } - -declare global { - const RouterLink: typeof import('vue-router')['RouterLink'] - const RouterView: typeof import('vue-router')['RouterView'] - const TestComp: typeof import('test/component/TestComp')['default'] -}" +" `; exports[`dts > directive only 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -50,13 +45,13 @@ declare module 'vue' { exports[`dts > generate components with prefix 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -83,38 +78,19 @@ declare module 'vue' { vLoading: typeof import('test/directive/Loading')['default'] } } - -declare global { - const CustomPrefixAvatar: typeof import('./examples/vite-vue3/src/components/global/avatar.vue')['default'] - const CustomPrefixBook: typeof import('./examples/vite-vue3/src/components/book/index.vue')['default'] - const CustomPrefixButton: typeof import('./examples/vite-vue3/src/components/ui/button.vue')['default'] - const CustomPrefixCheckbox: typeof import('./examples/vite-vue3/src/components/ui/nested/checkbox.vue')['default'] - const CustomPrefixCollapseFolderAndComponentFromRoot: typeof import('./examples/vite-vue3/src/components/collapse/collapseFolder/CollapseFolderAndComponentFromRoot.vue')['default'] - const CustomPrefixComponentA: typeof import('./examples/vite-vue3/src/components/ComponentA.vue')['default'] - const CustomPrefixComponentAsync: typeof import('./examples/vite-vue3/src/components/ComponentAsync.vue')['default'] - const CustomPrefixComponentB: typeof import('./examples/vite-vue3/src/components/ComponentB.vue')['default'] - const CustomPrefixComponentC: typeof import('./examples/vite-vue3/src/components/component-c.vue')['default'] - const CustomPrefixComponentD: typeof import('./examples/vite-vue3/src/components/ComponentD.vue')['default'] - const CustomPrefixFolderAndComponentPartially: typeof import('./examples/vite-vue3/src/components/collapse/collapseFolder/FolderAndComponentPartially.vue')['default'] - const CustomPrefixKebabCaseCollapseFile: typeof import('./examples/vite-vue3/src/components/kebab-case/kebab-case-collapse/KebabCaseCollapseFile.vue')['default'] - const CustomPrefixKebabCaseFile: typeof import('./examples/vite-vue3/src/components/kebab-case/KebabCaseFile.vue')['default'] - const CustomPrefixRecursive: typeof import('./examples/vite-vue3/src/components/Recursive.vue')['default'] - const RouterLink: typeof import('vue-router')['RouterLink'] - const RouterView: typeof import('vue-router')['RouterView'] - const TestComp: typeof import('test/component/TestComp')['default'] -}" +" `; exports[`dts > getDeclaration 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -127,12 +103,7 @@ declare module 'vue' { vLoading: typeof import('test/directive/Loading')['default'] } } - -declare global { - const RouterLink: typeof import('vue-router')['RouterLink'] - const RouterView: typeof import('vue-router')['RouterView'] - const TestComp: typeof import('test/component/TestComp')['default'] -}" +" `; exports[`dts > parseDeclaration - has icon component like 1`] = ` @@ -172,17 +143,18 @@ exports[`dts > parseDeclaration 1`] = ` } `; -exports[`dts > vue 2.7 components only 1`] = ` +exports[`dts > tsx 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} - +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 import { GlobalComponents } from 'vue' +export {} + /* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { @@ -190,8 +162,12 @@ declare module 'vue' { RouterView: typeof import('vue-router')['RouterView'] TestComp: typeof import('test/component/TestComp')['default'] } + export interface GlobalDirectives { + vLoading: typeof import('test/directive/Loading')['default'] + } } +// For TSX support declare global { const RouterLink: typeof import('vue-router')['RouterLink'] const RouterView: typeof import('vue-router')['RouterView'] @@ -199,16 +175,38 @@ declare global { }" `; -exports[`dts > writeDeclaration - append 1`] = ` +exports[`dts > vue 2.7 components only 1`] = ` "/* eslint-disable */ // @ts-nocheck +// biome-ignore lint: disable +// oxlint-disable +// ------ // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 + +export {} + +/* prettier-ignore */ +declare module 'vue' { + export interface GlobalComponents { + RouterLink: typeof import('vue-router')['RouterLink'] + RouterView: typeof import('vue-router')['RouterView'] + TestComp: typeof import('test/component/TestComp')['default'] + } +} +" +`; + +exports[`dts > writeDeclaration - append 1`] = ` +"/* eslint-disable */ +// @ts-nocheck // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -224,25 +222,19 @@ declare module 'vue' { vSome: typeof import('test/directive/Some')['default'] } } - -declare global { - const RouterLink: typeof import('vue-router')['RouterLink'] - const RouterView: typeof import('vue-router')['RouterView'] - const SomeComp: typeof import('test/component/SomeComp')['default'] - const TestComp: typeof import('test/component/TestComp')['default'] -}" +" `; exports[`dts > writeDeclaration - overwrite 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -255,24 +247,19 @@ declare module 'vue' { vLoading: typeof import('test/directive/Loading')['default'] } } - -declare global { - const RouterLink: typeof import('vue-router')['RouterLink'] - const RouterView: typeof import('vue-router')['RouterView'] - const TestComp: typeof import('test/component/TestComp')['default'] -}" +" `; exports[`dts > writeDeclaration 1`] = ` "/* eslint-disable */ // @ts-nocheck -// Generated by unplugin-vue-components -// Read more: https://github.com/vuejs/core/pull/3399 // biome-ignore lint: disable // oxlint-disable -export {} +// ------ +// Generated by unplugin-vue-components +// Read more: https://github.com/vuejs/core/pull/3399 -import { GlobalComponents } from 'vue' +export {} /* prettier-ignore */ declare module 'vue' { @@ -285,10 +272,5 @@ declare module 'vue' { vLoading: typeof import('test/directive/Loading')['default'] } } - -declare global { - const RouterLink: typeof import('vue-router')['RouterLink'] - const RouterView: typeof import('vue-router')['RouterView'] - const TestComp: typeof import('test/component/TestComp')['default'] -}" +" `; diff --git a/test/dts.test.ts b/test/dts.test.ts index 35f0e064..0a5267a1 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -32,6 +32,22 @@ const _directive_loading = _resolveDirective("loading")` expect(declarations).toMatchSnapshot() }) + it('tsx', async () => { + const ctx = new Context({ + resolvers: resolver, + directives: true, + dts: true, + dtsTsx: true, + }) + const code = ` +const _component_test_comp = _resolveComponent("test-comp") +const _directive_loading = _resolveDirective("loading")` + await ctx.transform(code, '') + + const declarations = getDeclaration(ctx, 'test.d.ts') + expect(declarations).toMatchSnapshot() + }) + it('writeDeclaration', async () => { const filepath = path.resolve(__dirname, 'tmp/dts-test.d.ts') const ctx = new Context({