Skip to content

Commit 4b8a4a2

Browse files
committed
refactor(component-meta): use type-helpers as a peer dependency
1 parent e619ade commit 4b8a4a2

File tree

3 files changed

+7
-36
lines changed

3 files changed

+7
-36
lines changed

packages/component-meta/lib/base.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createLanguageServiceHost, resolveFileLanguageId, type TypeScriptProjec
22
import * as vue from '@vue/language-core';
33
import { posix as path } from 'path-browserify';
44
import type * as ts from 'typescript';
5-
import { code as typeHelpersCode } from 'vue-component-type-helpers';
65

76
import type {
87
ComponentMeta,
@@ -224,7 +223,9 @@ export function baseCreate(
224223

225224
function getMetaScriptContent(fileName: string) {
226225
let code = `
226+
import type { ComponentType, ComponentProps, ComponentEmit, ComponentSlots, ComponentExposed } from 'vue-component-type-helpers';
227227
import * as Components from '${fileName.slice(0, -'.meta.ts'.length)}';
228+
228229
export default {} as { [K in keyof typeof Components]: ComponentMeta<typeof Components[K]>; };
229230
230231
interface ComponentMeta<T> {
@@ -233,9 +234,7 @@ interface ComponentMeta<T> {
233234
emit: ComponentEmit<T>;
234235
slots: ComponentSlots<T>;
235236
exposed: ComponentExposed<T>;
236-
};
237-
238-
${typeHelpersCode}
237+
}
239238
`.trim();
240239
return code;
241240
}

packages/component-meta/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"dependencies": {
1616
"@volar/typescript": "2.4.14",
1717
"@vue/language-core": "3.0.0-alpha.10",
18-
"path-browserify": "^1.0.1",
19-
"vue-component-type-helpers": "3.0.0-alpha.10"
18+
"path-browserify": "^1.0.1"
2019
},
2120
"peerDependencies": {
22-
"typescript": "*"
21+
"typescript": "*",
22+
"vue-component-type-helpers": "3.0.0-alpha.10"
2323
},
2424
"devDependencies": {
2525
"@types/node": "^22.10.4",

packages/component-type-helpers/index.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,12 @@ export type ComponentSlots<T> =
1313
T extends (props: any, ctx: { slots: infer S; attrs: any; emit: any; }, ...args: any) => any ? NonNullable<S> :
1414
{};
1515

16-
export type ComponentEmit<T> =
17-
T extends new (...args: any) => { $emit: infer E; } ? NonNullable<E> :
18-
{};
19-
20-
export type ComponentExposed<T> =
21-
T extends new (...args: any) => infer E ? E :
22-
T extends (props: any, ctx: any, expose: (exposed: infer E) => any, ...args: any) => any ? NonNullable<E> :
23-
{};
24-
25-
export const code = `
26-
export type ComponentType<T> =
27-
T extends new (...args: any) => {} ? 1 :
28-
T extends (...args: any) => any ? 2 :
29-
0;
30-
31-
export type ComponentProps<T> =
32-
T extends new (...args: any) => { $props: infer P; } ? NonNullable<P> :
33-
T extends (props: infer P, ...args: any) => any ? P :
34-
{};
35-
36-
export type ComponentSlots<T> =
37-
T extends new (...args: any) => { $slots: infer S; } ? NonNullable<S> :
38-
T extends (props: any, ctx: { slots: infer S; attrs: any; emit: any; }, ...args: any) => any ? NonNullable<S> :
39-
{};
40-
4116
export type ComponentEmit<T> =
4217
T extends new (...args: any) => { $emit: infer E; } ? NonNullable<E> :
4318
T extends (props: any, ctx: { slots: any; attrs: any; emit: infer E; }, ...args: any) => any ? NonNullable<E> :
4419
{};
4520

4621
export type ComponentExposed<T> =
4722
T extends new (...args: any) => infer E ? E :
48-
T extends (props: any, ctx: { expose(exposed: infer E): any; }, ...args: any) => any ? NonNullable<E> :
23+
T extends (props: any, ctx: any, expose: (exposed: infer E) => any, ...args: any) => any ? NonNullable<E> :
4924
{};
50-
`.trim();
51-
52-
export default code;

0 commit comments

Comments
 (0)