Skip to content

Commit 7ab9a00

Browse files
committed
feat: allow passing auto import options
1 parent bbc9d1d commit 7ab9a00

File tree

7 files changed

+121
-7
lines changed

7 files changed

+121
-7
lines changed

packages/cli/auto-imports.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Generated by 'unplugin-auto-import'
22
// We suggest you to commit this file into source control
33
declare global {
4+
const afterAll: typeof import('vitest')['afterAll']
5+
const afterEach: typeof import('vitest')['afterEach']
6+
const assert: typeof import('vitest')['assert']
7+
const beforeAll: typeof import('vitest')['beforeAll']
8+
const beforeEach: typeof import('vitest')['beforeEach']
9+
const chai: typeof import('vitest')['chai']
410
const computed: typeof import('vue-termui')['computed']
511
const createApp: typeof import('vue-termui')['createApp']
612
const customRef: typeof import('vue-termui')['customRef']
713
const defineAsyncComponent: typeof import('vue-termui')['defineAsyncComponent']
814
const defineComponent: typeof import('vue-termui')['defineComponent']
15+
const describe: typeof import('vitest')['describe']
916
const effectScope: typeof import('vue-termui')['effectScope']
1017
const EffectScope: typeof import('vue-termui')['EffectScope']
18+
const expect: typeof import('vitest')['expect']
1119
const getCurrentInstance: typeof import('vue-termui')['getCurrentInstance']
1220
const getCurrentScope: typeof import('vue-termui')['getCurrentScope']
1321
const h: typeof import('vue-termui')['h']
@@ -18,6 +26,7 @@ declare global {
1826
const isMouseDataEvent: typeof import('vue-termui')['isMouseDataEvent']
1927
const isReadonly: typeof import('vue-termui')['isReadonly']
2028
const isRef: typeof import('vue-termui')['isRef']
29+
const it: typeof import('vitest')['it']
2130
const markRaw: typeof import('vue-termui')['markRaw']
2231
const MouseEventType: typeof import('vue-termui')['MouseEventType']
2332
const nextTick: typeof import('vue-termui')['nextTick']
@@ -45,6 +54,8 @@ declare global {
4554
const shallowReactive: typeof import('vue-termui')['shallowReactive']
4655
const shallowReadonly: typeof import('vue-termui')['shallowReadonly']
4756
const shallowRef: typeof import('vue-termui')['shallowRef']
57+
const suite: typeof import('vitest')['suite']
58+
const test: typeof import('vitest')['test']
4859
const toRaw: typeof import('vue-termui')['toRaw']
4960
const toRef: typeof import('vue-termui')['toRef']
5061
const toRefs: typeof import('vue-termui')['toRefs']
@@ -56,6 +67,8 @@ declare global {
5667
const useRootNode: typeof import('vue-termui')['useRootNode']
5768
const useSlots: typeof import('vue-termui')['useSlots']
5869
const useTimeout: typeof import('vue-termui')['useTimeout']
70+
const vi: typeof import('vitest')['vi']
71+
const vitest: typeof import('vitest')['vitest']
5972
const watch: typeof import('vue-termui')['watch']
6073
const watchEffect: typeof import('vue-termui')['watchEffect']
6174
}

packages/cli/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export default defineConfig({
1515
},
1616
},
1717

18-
plugins: [VueTermui()],
18+
plugins: [VueTermui({ autoImportOptions: { imports: ['vitest'] } })],
1919
})

packages/core/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"include": [
2222
"../../auto-imports.d.ts",
23+
"./auto-imports.d.ts",
2324
"src/**/*.ts",
2425
"src/**/*.d.ts",
2526
"src/**/*.vue"

packages/domino/auto-imports.d.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,69 @@ declare global {
77
const beforeAll: typeof import('vitest')['beforeAll']
88
const beforeEach: typeof import('vitest')['beforeEach']
99
const chai: typeof import('vitest')['chai']
10+
const computed: typeof import('vue-termui')['computed']
11+
const createApp: typeof import('vue-termui')['createApp']
12+
const customRef: typeof import('vue-termui')['customRef']
13+
const defineAsyncComponent: typeof import('vue-termui')['defineAsyncComponent']
14+
const defineComponent: typeof import('vue-termui')['defineComponent']
1015
const describe: typeof import('vitest')['describe']
16+
const effectScope: typeof import('vue-termui')['effectScope']
17+
const EffectScope: typeof import('vue-termui')['EffectScope']
1118
const expect: typeof import('vitest')['expect']
19+
const getCurrentInstance: typeof import('vue-termui')['getCurrentInstance']
20+
const getCurrentScope: typeof import('vue-termui')['getCurrentScope']
21+
const h: typeof import('vue-termui')['h']
22+
const inject: typeof import('vue-termui')['inject']
23+
const inputDataToString: typeof import('vue-termui')['inputDataToString']
24+
const isInputDataEvent: typeof import('vue-termui')['isInputDataEvent']
25+
const isKeyDataEvent: typeof import('vue-termui')['isKeyDataEvent']
26+
const isMouseDataEvent: typeof import('vue-termui')['isMouseDataEvent']
27+
const isReadonly: typeof import('vue-termui')['isReadonly']
28+
const isRef: typeof import('vue-termui')['isRef']
1229
const it: typeof import('vitest')['it']
30+
const markRaw: typeof import('vue-termui')['markRaw']
31+
const MouseEventType: typeof import('vue-termui')['MouseEventType']
32+
const nextTick: typeof import('vue-termui')['nextTick']
33+
const onActivated: typeof import('vue-termui')['onActivated']
34+
const onBeforeMount: typeof import('vue-termui')['onBeforeMount']
35+
const onBeforeUnmount: typeof import('vue-termui')['onBeforeUnmount']
36+
const onBeforeUpdate: typeof import('vue-termui')['onBeforeUpdate']
37+
const onDeactivated: typeof import('vue-termui')['onDeactivated']
38+
const onErrorCaptured: typeof import('vue-termui')['onErrorCaptured']
39+
const onInputData: typeof import('vue-termui')['onInputData']
40+
const onKeyData: typeof import('vue-termui')['onKeyData']
41+
const onMounted: typeof import('vue-termui')['onMounted']
42+
const onMouseData: typeof import('vue-termui')['onMouseData']
43+
const onRenderTracked: typeof import('vue-termui')['onRenderTracked']
44+
const onRenderTriggered: typeof import('vue-termui')['onRenderTriggered']
45+
const onScopeDispose: typeof import('vue-termui')['onScopeDispose']
46+
const onServerPrefetch: typeof import('vue-termui')['onServerPrefetch']
47+
const onUnmounted: typeof import('vue-termui')['onUnmounted']
48+
const onUpdated: typeof import('vue-termui')['onUpdated']
49+
const provide: typeof import('vue-termui')['provide']
50+
const reactive: typeof import('vue-termui')['reactive']
51+
const readonly: typeof import('vue-termui')['readonly']
52+
const ref: typeof import('vue-termui')['ref']
53+
const resolveComponent: typeof import('vue-termui')['resolveComponent']
54+
const shallowReactive: typeof import('vue-termui')['shallowReactive']
55+
const shallowReadonly: typeof import('vue-termui')['shallowReadonly']
56+
const shallowRef: typeof import('vue-termui')['shallowRef']
1357
const suite: typeof import('vitest')['suite']
1458
const test: typeof import('vitest')['test']
59+
const toRaw: typeof import('vue-termui')['toRaw']
60+
const toRef: typeof import('vue-termui')['toRef']
61+
const toRefs: typeof import('vue-termui')['toRefs']
62+
const triggerRef: typeof import('vue-termui')['triggerRef']
63+
const unref: typeof import('vue-termui')['unref']
64+
const useAttrs: typeof import('vue-termui')['useAttrs']
65+
const useInterval: typeof import('vue-termui')['useInterval']
66+
const useLog: typeof import('vue-termui')['useLog']
67+
const useRootNode: typeof import('vue-termui')['useRootNode']
68+
const useSlots: typeof import('vue-termui')['useSlots']
69+
const useTimeout: typeof import('vue-termui')['useTimeout']
1570
const vi: typeof import('vitest')['vi']
1671
const vitest: typeof import('vitest')['vitest']
72+
const watch: typeof import('vue-termui')['watch']
73+
const watchEffect: typeof import('vue-termui')['watchEffect']
1774
}
1875
export {}

packages/domino/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"src/**/*.d.ts",
1515
"src/**/*.tsx",
1616
"src/**/*.vue",
17-
"./*.d.ts"
17+
"./auto-imports.d.ts",
18+
"./components.d.ts"
1819
]
1920
}

packages/domino/vite.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ export default defineConfig({
1818
},
1919

2020
plugins: [
21-
AutoImport({ imports: ['vitest'], dts: true }),
2221
//
23-
VueTermui(),
22+
VueTermui({
23+
autoImportOptions: {
24+
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
25+
imports: ['vitest'],
26+
dts: true,
27+
},
28+
}),
2429
],
2530

2631
test: {

packages/vite-plugin-vue-termui/src/index.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,49 @@ import * as MyModule from 'vue-termui'
66

77
type ModuleExports = keyof typeof MyModule
88

9-
export default function VueTermui(): Plugin[] {
9+
type AutoImportOptions = Parameters<typeof AutoImport>[0]
10+
11+
export interface VueTermuiOptios {
12+
autoImportOptions?: AutoImportOptions
13+
}
14+
15+
/**
16+
* Typesafe alternative to Array.isArray
17+
* https://github.com/microsoft/TypeScript/pull/48228
18+
*/
19+
export const isArray: (arg: ArrayLike<any> | any) => arg is ReadonlyArray<any> =
20+
Array.isArray
21+
22+
function optionAsArray<T>(
23+
value: T | undefined | null
24+
): Extract<T, readonly any[]> {
25+
const v = isArray(value)
26+
? (value as Extract<T, readonly any[]>)
27+
: value != null
28+
? [value as Exclude<T, readonly any[]>]
29+
: []
30+
31+
// @ts-expect-error: just easier...
32+
return v
33+
}
34+
35+
export default function VueTermui({
36+
autoImportOptions = {},
37+
}: VueTermuiOptios = {}): Plugin[] {
1038
return [
1139
AutoImport({
1240
dts: true,
13-
include: [/\.[tj]sx$/, /\.vue$/, /\.vue\?vue/],
14-
imports: [{ 'vue-termui': VueTuiExports }],
41+
...autoImportOptions,
42+
include: [
43+
...optionAsArray(autoImportOptions.include),
44+
/\.[tj]sx?$/,
45+
/\.vue$/,
46+
/\.vue\?vue/,
47+
],
48+
imports: [
49+
...optionAsArray(autoImportOptions.imports),
50+
{ 'vue-termui': VueTuiExports },
51+
],
1552
}),
1653

1754
Components({

0 commit comments

Comments
 (0)