vite-plugin-dts 0.9.7 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -180
- package/README.zh-CN.md +179 -179
- package/dist/index.js +38 -12
- package/dist/index.mjs +38 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
# vite-plugin-dts
|
|
2
|
-
|
|
3
|
-
**English** | [中文](./README.zh-CN.md)
|
|
4
|
-
|
|
5
|
-
A vite plugin that generate `.d.ts` files from `.ts` or `.vue` source files for lib.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
pnpm add vite-plugin-dts -D
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
In `vite.config.ts`:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { resolve } from 'path'
|
|
19
|
-
import { defineConfig } from 'vite'
|
|
20
|
-
import dts from 'vite-plugin-dts'
|
|
21
|
-
|
|
22
|
-
export default defineConfig({
|
|
23
|
-
build: {
|
|
24
|
-
lib: {
|
|
25
|
-
entry: resolve(__dirname, 'src/index.ts'),
|
|
26
|
-
name: 'MyLib',
|
|
27
|
-
formats: ['es'],
|
|
28
|
-
fileName: 'my-lib'
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
plugins: [dts()]
|
|
32
|
-
})
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
In your component:
|
|
36
|
-
|
|
37
|
-
```vue
|
|
38
|
-
<template>
|
|
39
|
-
<div></div>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<script lang="ts">
|
|
43
|
-
// using defineComponent for inferring types
|
|
44
|
-
import { defineComponent } from 'vue'
|
|
45
|
-
|
|
46
|
-
export default defineComponent({
|
|
47
|
-
name: 'Component'
|
|
48
|
-
})
|
|
49
|
-
</script>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
```vue
|
|
53
|
-
<script setup lang="ts">
|
|
54
|
-
// Need to access the defineProps returned value to
|
|
55
|
-
// infer types although you never use the props directly
|
|
56
|
-
const props = defineProps<{
|
|
57
|
-
color: 'blue' | 'red'
|
|
58
|
-
}>()
|
|
59
|
-
</script>
|
|
60
|
-
|
|
61
|
-
<template>
|
|
62
|
-
<div>{{ color }}</div>
|
|
63
|
-
</template>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Options
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import type { ts, Diagnostic } from 'ts-morph'
|
|
70
|
-
|
|
71
|
-
interface TransformWriteFile {
|
|
72
|
-
filePath?: string
|
|
73
|
-
content?: string
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface PluginOptions {
|
|
77
|
-
// Depends on the root directory
|
|
78
|
-
// Defaults base on your vite config root options
|
|
79
|
-
root?: string
|
|
80
|
-
|
|
81
|
-
// Declaration files output directory
|
|
82
|
-
// Defaults base on your vite config output options
|
|
83
|
-
outputDir?: string
|
|
84
|
-
|
|
85
|
-
// Project init compilerOptions using by ts-morph
|
|
86
|
-
// Default: null
|
|
87
|
-
compilerOptions?: ts.CompilerOptions | null
|
|
88
|
-
|
|
89
|
-
// Project init tsconfig.json file path by ts-morph
|
|
90
|
-
// Plugin also resolve incldue and exclude files from tsconfig.json
|
|
91
|
-
// Default: 'tsconfig.json'
|
|
92
|
-
tsConfigFilePath?: string
|
|
93
|
-
|
|
94
|
-
// Whether transform file name '.vue.d.ts' to '.d.ts'
|
|
95
|
-
// Default: false
|
|
96
|
-
cleanVueFileName?: boolean
|
|
97
|
-
|
|
98
|
-
// Whether transform dynamic import to static
|
|
99
|
-
// eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
|
|
100
|
-
// Default: false
|
|
101
|
-
staticImport?: boolean
|
|
102
|
-
|
|
103
|
-
// Manual set include glob
|
|
104
|
-
// Defaults base on your tsconfig.json include option
|
|
105
|
-
include?: string | string[]
|
|
106
|
-
|
|
107
|
-
// Manual set exclude glob
|
|
108
|
-
// Defaults base on your tsconfig.json exclude option, be 'node_module/**' when empty
|
|
109
|
-
exclude?: string | string[]
|
|
110
|
-
|
|
111
|
-
// Whether generate types entry file
|
|
112
|
-
// When true will from package.json types field if exists or `${outputDir}/index.d.ts`
|
|
113
|
-
// Default: false
|
|
114
|
-
insertTypesEntry?: boolean
|
|
115
|
-
|
|
116
|
-
// Whether copy .d.ts source files into outputDir
|
|
117
|
-
// Default: true
|
|
118
|
-
copyDtsFiles?: boolean
|
|
119
|
-
|
|
120
|
-
// Whether emit nothing when has any diagnostic
|
|
121
|
-
// Default: false
|
|
122
|
-
noEmitOnError?: boolean
|
|
123
|
-
|
|
124
|
-
// Whether skip typescript diagnostics
|
|
125
|
-
// Skip type diagnostics means that type errors will not interrupt the build process
|
|
126
|
-
// But for the source files with type errors will not be emitted
|
|
127
|
-
// Default: true
|
|
128
|
-
skipDiagnostics?: boolean
|
|
129
|
-
|
|
130
|
-
// Whether log diagnostic informations
|
|
131
|
-
// Not effective when `skipDiagnostics` is true
|
|
132
|
-
// Default: false
|
|
133
|
-
logDiagnostics?: boolean
|
|
134
|
-
|
|
135
|
-
// After emit diagnostic hook
|
|
136
|
-
// According to the length to judge whether there is any type error
|
|
137
|
-
// Default: () => {}
|
|
138
|
-
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
139
|
-
|
|
140
|
-
// Before declaration file be writed hook
|
|
141
|
-
// You can transform declaration file-path and content through it
|
|
142
|
-
// Default: () => {}
|
|
143
|
-
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
144
|
-
|
|
145
|
-
// After build hook
|
|
146
|
-
// It wil be called after all declaration files are written
|
|
147
|
-
// Default: () => {}
|
|
148
|
-
afterBuild?: () => void | Promise<void>
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Example
|
|
153
|
-
|
|
154
|
-
Clone and run the following script:
|
|
155
|
-
|
|
156
|
-
```sh
|
|
157
|
-
pnpm run test:e2e
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Then check `example/types`.
|
|
161
|
-
|
|
162
|
-
## FAQ
|
|
163
|
-
|
|
164
|
-
Here will include some FAQ's and provide some solutions.
|
|
165
|
-
|
|
166
|
-
### Missing some declaration files after build
|
|
167
|
-
|
|
168
|
-
By default `skipDiagnostics` option is `true`, which means that type diagnostic will be skipped during the build process (some projects may have diagnostic tool such as `vue-tsc`). If there are some files with type errors which will interrupt the build process, these files will not be emitted (not generate declaration files).
|
|
169
|
-
|
|
170
|
-
If your project has not type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on the diagnostic and log features of this plugin. It will help you to check the type errors during build and log error information to the terminal.
|
|
171
|
-
|
|
172
|
-
### Take type error when using both `script` and `setup-script` in vue component
|
|
173
|
-
|
|
174
|
-
This is usually caused by using `defineComponent` function in both `script` and `setup-script`. When `vue/compiler-sfc` compiles these files, the default export result in `script` will be merged into the parameter object of `defineComponent` that in `setup-script`, but there is incompatible of `defineComponent` returned types and parameter types, then a type error is caused.
|
|
175
|
-
|
|
176
|
-
Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue), you should remove the `defineComponent` which in `script` and export a native object directly.
|
|
177
|
-
|
|
178
|
-
## License
|
|
179
|
-
|
|
180
|
-
MIT License.
|
|
1
|
+
# vite-plugin-dts
|
|
2
|
+
|
|
3
|
+
**English** | [中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A vite plugin that generate `.d.ts` files from `.ts` or `.vue` source files for lib.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add vite-plugin-dts -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
In `vite.config.ts`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { resolve } from 'path'
|
|
19
|
+
import { defineConfig } from 'vite'
|
|
20
|
+
import dts from 'vite-plugin-dts'
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
build: {
|
|
24
|
+
lib: {
|
|
25
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
26
|
+
name: 'MyLib',
|
|
27
|
+
formats: ['es'],
|
|
28
|
+
fileName: 'my-lib'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
plugins: [dts()]
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
In your component:
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<template>
|
|
39
|
+
<div></div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script lang="ts">
|
|
43
|
+
// using defineComponent for inferring types
|
|
44
|
+
import { defineComponent } from 'vue'
|
|
45
|
+
|
|
46
|
+
export default defineComponent({
|
|
47
|
+
name: 'Component'
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
// Need to access the defineProps returned value to
|
|
55
|
+
// infer types although you never use the props directly
|
|
56
|
+
const props = defineProps<{
|
|
57
|
+
color: 'blue' | 'red'
|
|
58
|
+
}>()
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<div>{{ color }}</div>
|
|
63
|
+
</template>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Options
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import type { ts, Diagnostic } from 'ts-morph'
|
|
70
|
+
|
|
71
|
+
interface TransformWriteFile {
|
|
72
|
+
filePath?: string
|
|
73
|
+
content?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PluginOptions {
|
|
77
|
+
// Depends on the root directory
|
|
78
|
+
// Defaults base on your vite config root options
|
|
79
|
+
root?: string
|
|
80
|
+
|
|
81
|
+
// Declaration files output directory
|
|
82
|
+
// Defaults base on your vite config output options
|
|
83
|
+
outputDir?: string
|
|
84
|
+
|
|
85
|
+
// Project init compilerOptions using by ts-morph
|
|
86
|
+
// Default: null
|
|
87
|
+
compilerOptions?: ts.CompilerOptions | null
|
|
88
|
+
|
|
89
|
+
// Project init tsconfig.json file path by ts-morph
|
|
90
|
+
// Plugin also resolve incldue and exclude files from tsconfig.json
|
|
91
|
+
// Default: 'tsconfig.json'
|
|
92
|
+
tsConfigFilePath?: string
|
|
93
|
+
|
|
94
|
+
// Whether transform file name '.vue.d.ts' to '.d.ts'
|
|
95
|
+
// Default: false
|
|
96
|
+
cleanVueFileName?: boolean
|
|
97
|
+
|
|
98
|
+
// Whether transform dynamic import to static
|
|
99
|
+
// eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
|
|
100
|
+
// Default: false
|
|
101
|
+
staticImport?: boolean
|
|
102
|
+
|
|
103
|
+
// Manual set include glob
|
|
104
|
+
// Defaults base on your tsconfig.json include option
|
|
105
|
+
include?: string | string[]
|
|
106
|
+
|
|
107
|
+
// Manual set exclude glob
|
|
108
|
+
// Defaults base on your tsconfig.json exclude option, be 'node_module/**' when empty
|
|
109
|
+
exclude?: string | string[]
|
|
110
|
+
|
|
111
|
+
// Whether generate types entry file
|
|
112
|
+
// When true will from package.json types field if exists or `${outputDir}/index.d.ts`
|
|
113
|
+
// Default: false
|
|
114
|
+
insertTypesEntry?: boolean
|
|
115
|
+
|
|
116
|
+
// Whether copy .d.ts source files into outputDir
|
|
117
|
+
// Default: true
|
|
118
|
+
copyDtsFiles?: boolean
|
|
119
|
+
|
|
120
|
+
// Whether emit nothing when has any diagnostic
|
|
121
|
+
// Default: false
|
|
122
|
+
noEmitOnError?: boolean
|
|
123
|
+
|
|
124
|
+
// Whether skip typescript diagnostics
|
|
125
|
+
// Skip type diagnostics means that type errors will not interrupt the build process
|
|
126
|
+
// But for the source files with type errors will not be emitted
|
|
127
|
+
// Default: true
|
|
128
|
+
skipDiagnostics?: boolean
|
|
129
|
+
|
|
130
|
+
// Whether log diagnostic informations
|
|
131
|
+
// Not effective when `skipDiagnostics` is true
|
|
132
|
+
// Default: false
|
|
133
|
+
logDiagnostics?: boolean
|
|
134
|
+
|
|
135
|
+
// After emit diagnostic hook
|
|
136
|
+
// According to the length to judge whether there is any type error
|
|
137
|
+
// Default: () => {}
|
|
138
|
+
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
139
|
+
|
|
140
|
+
// Before declaration file be writed hook
|
|
141
|
+
// You can transform declaration file-path and content through it
|
|
142
|
+
// Default: () => {}
|
|
143
|
+
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
144
|
+
|
|
145
|
+
// After build hook
|
|
146
|
+
// It wil be called after all declaration files are written
|
|
147
|
+
// Default: () => {}
|
|
148
|
+
afterBuild?: () => void | Promise<void>
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Example
|
|
153
|
+
|
|
154
|
+
Clone and run the following script:
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
pnpm run test:e2e
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Then check `example/types`.
|
|
161
|
+
|
|
162
|
+
## FAQ
|
|
163
|
+
|
|
164
|
+
Here will include some FAQ's and provide some solutions.
|
|
165
|
+
|
|
166
|
+
### Missing some declaration files after build
|
|
167
|
+
|
|
168
|
+
By default `skipDiagnostics` option is `true`, which means that type diagnostic will be skipped during the build process (some projects may have diagnostic tool such as `vue-tsc`). If there are some files with type errors which will interrupt the build process, these files will not be emitted (not generate declaration files).
|
|
169
|
+
|
|
170
|
+
If your project has not type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on the diagnostic and log features of this plugin. It will help you to check the type errors during build and log error information to the terminal.
|
|
171
|
+
|
|
172
|
+
### Take type error when using both `script` and `setup-script` in vue component
|
|
173
|
+
|
|
174
|
+
This is usually caused by using `defineComponent` function in both `script` and `setup-script`. When `vue/compiler-sfc` compiles these files, the default export result in `script` will be merged into the parameter object of `defineComponent` that in `setup-script`, but there is incompatible of `defineComponent` returned types and parameter types, then a type error is caused.
|
|
175
|
+
|
|
176
|
+
Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue), you should remove the `defineComponent` which in `script` and export a native object directly.
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT License.
|
package/README.zh-CN.md
CHANGED
|
@@ -1,179 +1,179 @@
|
|
|
1
|
-
# vite-plugin-dts
|
|
2
|
-
|
|
3
|
-
**中文** | [English](./README.md)
|
|
4
|
-
|
|
5
|
-
一款用于从 `.ts` 或 `.vue` 源文件生成 `.d.ts` 文件的 Vite 插件。
|
|
6
|
-
|
|
7
|
-
## 安装
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
pnpm add vite-plugin-dts -D
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## 使用
|
|
14
|
-
|
|
15
|
-
在 `vite.config.ts`:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { resolve } from 'path'
|
|
19
|
-
import { defineConfig } from 'vite'
|
|
20
|
-
import dts from 'vite-plugin-dts'
|
|
21
|
-
|
|
22
|
-
export default defineConfig({
|
|
23
|
-
build: {
|
|
24
|
-
lib: {
|
|
25
|
-
entry: resolve(__dirname, 'src/index.ts'),
|
|
26
|
-
name: 'MyLib',
|
|
27
|
-
formats: ['es'],
|
|
28
|
-
fileName: 'my-lib'
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
plugins: [dts()]
|
|
32
|
-
})
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
在你的组件中:
|
|
36
|
-
|
|
37
|
-
```vue
|
|
38
|
-
<template>
|
|
39
|
-
<div></div>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<script lang="ts">
|
|
43
|
-
// 使用 defineComponent 来进行类型推断
|
|
44
|
-
import { defineComponent } from 'vue'
|
|
45
|
-
|
|
46
|
-
export default defineComponent({
|
|
47
|
-
name: 'Component'
|
|
48
|
-
})
|
|
49
|
-
</script>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
```vue
|
|
53
|
-
<script setup lang="ts">
|
|
54
|
-
// 尽管没有直接使用 props,你仍需要接收 defineProps 的返回值
|
|
55
|
-
const props = defineProps<{
|
|
56
|
-
color: 'blue' | 'red'
|
|
57
|
-
}>()
|
|
58
|
-
</script>
|
|
59
|
-
|
|
60
|
-
<template>
|
|
61
|
-
<div>{{ color }}</div>
|
|
62
|
-
</template>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## 选项
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import type { ts, Diagnostic } from 'ts-morph'
|
|
69
|
-
|
|
70
|
-
interface TransformWriteFile {
|
|
71
|
-
filePath?: string
|
|
72
|
-
content?: string
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface PluginOptions {
|
|
76
|
-
// 执行的根目录
|
|
77
|
-
// 默认基于 vite 配置的 root 选项
|
|
78
|
-
root?: string
|
|
79
|
-
|
|
80
|
-
// 声明文件的输出目录
|
|
81
|
-
// 默认基于 vite 配置的输出目录
|
|
82
|
-
outputDir?: string
|
|
83
|
-
|
|
84
|
-
// 提供给 ts-morph Project 初始化的 compilerOptions 选项
|
|
85
|
-
// 默认值: null
|
|
86
|
-
compilerOptions?: ts.CompilerOptions | null
|
|
87
|
-
|
|
88
|
-
// 提供给 ts-morph Project 初始化的 tsconfig.json 路径
|
|
89
|
-
// 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
|
|
90
|
-
// 默认值: 'tsconfig.json'
|
|
91
|
-
tsConfigFilePath?: string
|
|
92
|
-
|
|
93
|
-
// 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
|
|
94
|
-
// 默认值: false
|
|
95
|
-
cleanVueFileName?: boolean
|
|
96
|
-
|
|
97
|
-
//是否将动态引入转换为静态
|
|
98
|
-
// eg. 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
|
|
99
|
-
// 默认值: false
|
|
100
|
-
staticImport?: boolean
|
|
101
|
-
|
|
102
|
-
// 手动设置包含路径的 glob
|
|
103
|
-
// 默认基于 tsconfig.json 的 include 选项
|
|
104
|
-
include?: string | string[]
|
|
105
|
-
|
|
106
|
-
// 手动设置排除路径的 glob
|
|
107
|
-
// 默认基于 tsconfig.json 的 exclude 选线,未设置时为 'node_module/**'
|
|
108
|
-
exclude?: string | string[]
|
|
109
|
-
|
|
110
|
-
// 是否生成类型声明入口
|
|
111
|
-
// 当为 true 时会基于 package.json 的 tpyes 字段生成,或者 `${outputDir}/index.d.ts`
|
|
112
|
-
// 默认值: false
|
|
113
|
-
insertTypesEntry?: boolean
|
|
114
|
-
|
|
115
|
-
// 是否将源码里的 .d.ts 文件复制到 outputDir
|
|
116
|
-
// 默认值: true
|
|
117
|
-
copyDtsFiles?: boolean
|
|
118
|
-
|
|
119
|
-
// 出现类型诊断信息时不生成类型文件
|
|
120
|
-
// 默认值: false
|
|
121
|
-
noEmitOnError?: boolean
|
|
122
|
-
|
|
123
|
-
// 是否跳过类型诊断
|
|
124
|
-
// 跳过类型诊断意味着出现错误时不会中断打包进程的执行
|
|
125
|
-
// 但对于出现错误的源文件,将无法生成相应的类型文件
|
|
126
|
-
// 默认值: true
|
|
127
|
-
skipDiagnostics?: boolean
|
|
128
|
-
|
|
129
|
-
// 是否打印类型诊断信息
|
|
130
|
-
// 当跳过类型诊断时该属性将不会生效
|
|
131
|
-
// 默认值: false
|
|
132
|
-
logDiagnostics?: boolean
|
|
133
|
-
|
|
134
|
-
// 获取诊断信息后的钩子
|
|
135
|
-
// 可以根据参数 length 来判断有误类型错误
|
|
136
|
-
// 默认值: () => {}
|
|
137
|
-
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
138
|
-
|
|
139
|
-
// 类型声明文件被写入前的钩子
|
|
140
|
-
// 可以在钩子里转换文件路径和文件内容
|
|
141
|
-
// 默认值: () => {}
|
|
142
|
-
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
143
|
-
|
|
144
|
-
// 构建后回调钩子
|
|
145
|
-
// 将会在所有类型文件被写入后调用
|
|
146
|
-
// 默认值: () => {}
|
|
147
|
-
afterBuild?: () => void | Promise<void>
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## 示例
|
|
152
|
-
|
|
153
|
-
克隆项目然后执行下列命令:
|
|
154
|
-
|
|
155
|
-
```sh
|
|
156
|
-
pnpm run test:e2e
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
然后检查 `example/types` 目录。
|
|
160
|
-
|
|
161
|
-
## 常见问题
|
|
162
|
-
|
|
163
|
-
此处将收录一些常见的问题并提供一些解决方案。
|
|
164
|
-
|
|
165
|
-
### 打包后出现类型文件缺失
|
|
166
|
-
|
|
167
|
-
默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
|
|
168
|
-
|
|
169
|
-
如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
|
|
170
|
-
|
|
171
|
-
### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
|
|
172
|
-
|
|
173
|
-
这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
|
|
174
|
-
|
|
175
|
-
这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
|
|
176
|
-
|
|
177
|
-
## 授权
|
|
178
|
-
|
|
179
|
-
MIT 授权。
|
|
1
|
+
# vite-plugin-dts
|
|
2
|
+
|
|
3
|
+
**中文** | [English](./README.md)
|
|
4
|
+
|
|
5
|
+
一款用于从 `.ts` 或 `.vue` 源文件生成 `.d.ts` 文件的 Vite 插件。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add vite-plugin-dts -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
在 `vite.config.ts`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { resolve } from 'path'
|
|
19
|
+
import { defineConfig } from 'vite'
|
|
20
|
+
import dts from 'vite-plugin-dts'
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
build: {
|
|
24
|
+
lib: {
|
|
25
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
26
|
+
name: 'MyLib',
|
|
27
|
+
formats: ['es'],
|
|
28
|
+
fileName: 'my-lib'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
plugins: [dts()]
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
在你的组件中:
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<template>
|
|
39
|
+
<div></div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script lang="ts">
|
|
43
|
+
// 使用 defineComponent 来进行类型推断
|
|
44
|
+
import { defineComponent } from 'vue'
|
|
45
|
+
|
|
46
|
+
export default defineComponent({
|
|
47
|
+
name: 'Component'
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
// 尽管没有直接使用 props,你仍需要接收 defineProps 的返回值
|
|
55
|
+
const props = defineProps<{
|
|
56
|
+
color: 'blue' | 'red'
|
|
57
|
+
}>()
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<div>{{ color }}</div>
|
|
62
|
+
</template>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 选项
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import type { ts, Diagnostic } from 'ts-morph'
|
|
69
|
+
|
|
70
|
+
interface TransformWriteFile {
|
|
71
|
+
filePath?: string
|
|
72
|
+
content?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface PluginOptions {
|
|
76
|
+
// 执行的根目录
|
|
77
|
+
// 默认基于 vite 配置的 root 选项
|
|
78
|
+
root?: string
|
|
79
|
+
|
|
80
|
+
// 声明文件的输出目录
|
|
81
|
+
// 默认基于 vite 配置的输出目录
|
|
82
|
+
outputDir?: string
|
|
83
|
+
|
|
84
|
+
// 提供给 ts-morph Project 初始化的 compilerOptions 选项
|
|
85
|
+
// 默认值: null
|
|
86
|
+
compilerOptions?: ts.CompilerOptions | null
|
|
87
|
+
|
|
88
|
+
// 提供给 ts-morph Project 初始化的 tsconfig.json 路径
|
|
89
|
+
// 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
|
|
90
|
+
// 默认值: 'tsconfig.json'
|
|
91
|
+
tsConfigFilePath?: string
|
|
92
|
+
|
|
93
|
+
// 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
|
|
94
|
+
// 默认值: false
|
|
95
|
+
cleanVueFileName?: boolean
|
|
96
|
+
|
|
97
|
+
//是否将动态引入转换为静态
|
|
98
|
+
// eg. 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
|
|
99
|
+
// 默认值: false
|
|
100
|
+
staticImport?: boolean
|
|
101
|
+
|
|
102
|
+
// 手动设置包含路径的 glob
|
|
103
|
+
// 默认基于 tsconfig.json 的 include 选项
|
|
104
|
+
include?: string | string[]
|
|
105
|
+
|
|
106
|
+
// 手动设置排除路径的 glob
|
|
107
|
+
// 默认基于 tsconfig.json 的 exclude 选线,未设置时为 'node_module/**'
|
|
108
|
+
exclude?: string | string[]
|
|
109
|
+
|
|
110
|
+
// 是否生成类型声明入口
|
|
111
|
+
// 当为 true 时会基于 package.json 的 tpyes 字段生成,或者 `${outputDir}/index.d.ts`
|
|
112
|
+
// 默认值: false
|
|
113
|
+
insertTypesEntry?: boolean
|
|
114
|
+
|
|
115
|
+
// 是否将源码里的 .d.ts 文件复制到 outputDir
|
|
116
|
+
// 默认值: true
|
|
117
|
+
copyDtsFiles?: boolean
|
|
118
|
+
|
|
119
|
+
// 出现类型诊断信息时不生成类型文件
|
|
120
|
+
// 默认值: false
|
|
121
|
+
noEmitOnError?: boolean
|
|
122
|
+
|
|
123
|
+
// 是否跳过类型诊断
|
|
124
|
+
// 跳过类型诊断意味着出现错误时不会中断打包进程的执行
|
|
125
|
+
// 但对于出现错误的源文件,将无法生成相应的类型文件
|
|
126
|
+
// 默认值: true
|
|
127
|
+
skipDiagnostics?: boolean
|
|
128
|
+
|
|
129
|
+
// 是否打印类型诊断信息
|
|
130
|
+
// 当跳过类型诊断时该属性将不会生效
|
|
131
|
+
// 默认值: false
|
|
132
|
+
logDiagnostics?: boolean
|
|
133
|
+
|
|
134
|
+
// 获取诊断信息后的钩子
|
|
135
|
+
// 可以根据参数 length 来判断有误类型错误
|
|
136
|
+
// 默认值: () => {}
|
|
137
|
+
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
138
|
+
|
|
139
|
+
// 类型声明文件被写入前的钩子
|
|
140
|
+
// 可以在钩子里转换文件路径和文件内容
|
|
141
|
+
// 默认值: () => {}
|
|
142
|
+
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
143
|
+
|
|
144
|
+
// 构建后回调钩子
|
|
145
|
+
// 将会在所有类型文件被写入后调用
|
|
146
|
+
// 默认值: () => {}
|
|
147
|
+
afterBuild?: () => void | Promise<void>
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 示例
|
|
152
|
+
|
|
153
|
+
克隆项目然后执行下列命令:
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
pnpm run test:e2e
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
然后检查 `example/types` 目录。
|
|
160
|
+
|
|
161
|
+
## 常见问题
|
|
162
|
+
|
|
163
|
+
此处将收录一些常见的问题并提供一些解决方案。
|
|
164
|
+
|
|
165
|
+
### 打包后出现类型文件缺失
|
|
166
|
+
|
|
167
|
+
默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
|
|
168
|
+
|
|
169
|
+
如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
|
|
170
|
+
|
|
171
|
+
### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
|
|
172
|
+
|
|
173
|
+
这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
|
|
174
|
+
|
|
175
|
+
这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
|
|
176
|
+
|
|
177
|
+
## 授权
|
|
178
|
+
|
|
179
|
+
MIT 授权。
|
package/dist/index.js
CHANGED
|
@@ -141214,21 +141214,36 @@ init_cjs_shims();
|
|
|
141214
141214
|
var exportDefaultRE = /export\s+default/;
|
|
141215
141215
|
var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
141216
141216
|
var index = 1;
|
|
141217
|
+
var compileRoot = null;
|
|
141217
141218
|
var compiler;
|
|
141218
141219
|
function requireCompiler() {
|
|
141219
141220
|
if (!compiler) {
|
|
141220
|
-
|
|
141221
|
-
|
|
141222
|
-
|
|
141221
|
+
if (compileRoot) {
|
|
141222
|
+
try {
|
|
141223
|
+
compiler = require(require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
|
|
141224
|
+
} catch (e) {
|
|
141225
|
+
}
|
|
141226
|
+
}
|
|
141227
|
+
if (!compiler) {
|
|
141223
141228
|
try {
|
|
141224
|
-
compiler =
|
|
141225
|
-
} catch (
|
|
141226
|
-
|
|
141229
|
+
compiler = require_compiler_sfc();
|
|
141230
|
+
} catch (e) {
|
|
141231
|
+
try {
|
|
141232
|
+
compiler = require("@vue/compiler-sfc");
|
|
141233
|
+
} catch (e2) {
|
|
141234
|
+
throw new Error("@vue/compiler-sfc is not present in the dependency tree.\n");
|
|
141235
|
+
}
|
|
141227
141236
|
}
|
|
141228
141237
|
}
|
|
141229
141238
|
}
|
|
141230
141239
|
return compiler;
|
|
141231
141240
|
}
|
|
141241
|
+
function setCompileRoot(root) {
|
|
141242
|
+
if (root && root !== compileRoot) {
|
|
141243
|
+
compileRoot = root;
|
|
141244
|
+
compiler = null;
|
|
141245
|
+
}
|
|
141246
|
+
}
|
|
141232
141247
|
function compileVueCode(code) {
|
|
141233
141248
|
const { parse, compileScript, rewriteDefault } = requireCompiler();
|
|
141234
141249
|
const { descriptor } = parse(code);
|
|
@@ -141263,6 +141278,7 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
141263
141278
|
|
|
141264
141279
|
// src/plugin.ts
|
|
141265
141280
|
var noneExport = "export {};\n";
|
|
141281
|
+
var virtualPrefix = "\0";
|
|
141266
141282
|
var vueRE = /\.vue$/;
|
|
141267
141283
|
var tsRE = /\.tsx?$/;
|
|
141268
141284
|
var jsRE = /\.jsx?$/;
|
|
@@ -141283,6 +141299,7 @@ function dtsPlugin(options = {}) {
|
|
|
141283
141299
|
noEmitOnError = false,
|
|
141284
141300
|
skipDiagnostics = true,
|
|
141285
141301
|
logDiagnostics = false,
|
|
141302
|
+
copyDtsFiles = true,
|
|
141286
141303
|
afterDiagnostic = noop,
|
|
141287
141304
|
beforeWriteFile = noop,
|
|
141288
141305
|
afterBuild = noop
|
|
@@ -141335,6 +141352,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
141335
141352
|
`));
|
|
141336
141353
|
return;
|
|
141337
141354
|
}
|
|
141355
|
+
setCompileRoot(root);
|
|
141338
141356
|
compilerOptions.rootDir || (compilerOptions.rootDir = root);
|
|
141339
141357
|
project = new import_ts_morph.Project({
|
|
141340
141358
|
compilerOptions: mergeObjects(compilerOptions, {
|
|
@@ -141357,6 +141375,9 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
141357
141375
|
}
|
|
141358
141376
|
},
|
|
141359
141377
|
transform(code, id) {
|
|
141378
|
+
if (id.startsWith(virtualPrefix)) {
|
|
141379
|
+
return null;
|
|
141380
|
+
}
|
|
141360
141381
|
if (vueRE.test(id)) {
|
|
141361
141382
|
const { content, ext } = compileVueCode(code);
|
|
141362
141383
|
if (content) {
|
|
@@ -141379,7 +141400,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
141379
141400
|
}
|
|
141380
141401
|
},
|
|
141381
141402
|
async closeBundle() {
|
|
141382
|
-
var _a2, _b, _c, _d, _e;
|
|
141403
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
141383
141404
|
if (!outputDir || !project || isBundle)
|
|
141384
141405
|
return;
|
|
141385
141406
|
logger.info(import_chalk.default.green(`
|
|
@@ -141389,8 +141410,8 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
141389
141410
|
sourceDtsFiles.clear();
|
|
141390
141411
|
const startTime = Date.now();
|
|
141391
141412
|
const tsConfig = (_a2 = (0, import_typescript.readConfigFile)(tsConfigPath, project.getFileSystem().readFileSync).config) != null ? _a2 : {};
|
|
141392
|
-
const include = (_b = options.include) != null ? _b : tsConfig.include;
|
|
141393
|
-
const exclude = (
|
|
141413
|
+
const include = (_c = (_b = options.include) != null ? _b : tsConfig.include) != null ? _c : "**/*";
|
|
141414
|
+
const exclude = (_d = options.exclude) != null ? _d : tsConfig.exclude;
|
|
141394
141415
|
bundleDebug("read config");
|
|
141395
141416
|
const includedFileSet = new Set();
|
|
141396
141417
|
if (include && include.length) {
|
|
@@ -141400,10 +141421,15 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
141400
141421
|
ignore: ensureArray(exclude != null ? exclude : ["node_modules/**"]).map(normalizeGlob)
|
|
141401
141422
|
});
|
|
141402
141423
|
files.forEach((file) => {
|
|
141403
|
-
includedFileSet.add(dtsRE.test(file) ? file : `${tjsRE.test(file) ? file.replace(tjsRE, "") : file}.d.ts`);
|
|
141404
141424
|
if (dtsRE.test(file)) {
|
|
141425
|
+
if (!copyDtsFiles) {
|
|
141426
|
+
return;
|
|
141427
|
+
}
|
|
141428
|
+
includedFileSet.add(file);
|
|
141405
141429
|
sourceDtsFiles.add(project.addSourceFileAtPath(file));
|
|
141430
|
+
return;
|
|
141406
141431
|
}
|
|
141432
|
+
includedFileSet.add(`${tjsRE.test(file) ? file.replace(tjsRE, "") : file}.d.ts`);
|
|
141407
141433
|
});
|
|
141408
141434
|
if (hasJsVue) {
|
|
141409
141435
|
if (!allowJs) {
|
|
@@ -141474,8 +141500,8 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
141474
141500
|
if (typeof beforeWriteFile === "function") {
|
|
141475
141501
|
const result = beforeWriteFile(typesPath, content);
|
|
141476
141502
|
if (result && isNativeObj(result)) {
|
|
141477
|
-
typesPath = (
|
|
141478
|
-
content = (
|
|
141503
|
+
typesPath = (_e = result.filePath) != null ? _e : typesPath;
|
|
141504
|
+
content = (_f = result.content) != null ? _f : content;
|
|
141479
141505
|
}
|
|
141480
141506
|
}
|
|
141481
141507
|
await import_fs_extra.default.writeFile(typesPath, content, "utf-8");
|
package/dist/index.mjs
CHANGED
|
@@ -141165,21 +141165,36 @@ function transferSetupPosition(content) {
|
|
|
141165
141165
|
var exportDefaultRE = /export\s+default/;
|
|
141166
141166
|
var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
141167
141167
|
var index = 1;
|
|
141168
|
+
var compileRoot = null;
|
|
141168
141169
|
var compiler;
|
|
141169
141170
|
function requireCompiler() {
|
|
141170
141171
|
if (!compiler) {
|
|
141171
|
-
|
|
141172
|
-
|
|
141173
|
-
|
|
141172
|
+
if (compileRoot) {
|
|
141173
|
+
try {
|
|
141174
|
+
compiler = __require(__require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
|
|
141175
|
+
} catch (e) {
|
|
141176
|
+
}
|
|
141177
|
+
}
|
|
141178
|
+
if (!compiler) {
|
|
141174
141179
|
try {
|
|
141175
|
-
compiler =
|
|
141176
|
-
} catch (
|
|
141177
|
-
|
|
141180
|
+
compiler = require_compiler_sfc();
|
|
141181
|
+
} catch (e) {
|
|
141182
|
+
try {
|
|
141183
|
+
compiler = __require("@vue/compiler-sfc");
|
|
141184
|
+
} catch (e2) {
|
|
141185
|
+
throw new Error("@vue/compiler-sfc is not present in the dependency tree.\n");
|
|
141186
|
+
}
|
|
141178
141187
|
}
|
|
141179
141188
|
}
|
|
141180
141189
|
}
|
|
141181
141190
|
return compiler;
|
|
141182
141191
|
}
|
|
141192
|
+
function setCompileRoot(root) {
|
|
141193
|
+
if (root && root !== compileRoot) {
|
|
141194
|
+
compileRoot = root;
|
|
141195
|
+
compiler = null;
|
|
141196
|
+
}
|
|
141197
|
+
}
|
|
141183
141198
|
function compileVueCode(code) {
|
|
141184
141199
|
const { parse, compileScript, rewriteDefault } = requireCompiler();
|
|
141185
141200
|
const { descriptor } = parse(code);
|
|
@@ -141214,6 +141229,7 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
141214
141229
|
|
|
141215
141230
|
// src/plugin.ts
|
|
141216
141231
|
var noneExport = "export {};\n";
|
|
141232
|
+
var virtualPrefix = "\0";
|
|
141217
141233
|
var vueRE = /\.vue$/;
|
|
141218
141234
|
var tsRE = /\.tsx?$/;
|
|
141219
141235
|
var jsRE = /\.jsx?$/;
|
|
@@ -141234,6 +141250,7 @@ function dtsPlugin(options = {}) {
|
|
|
141234
141250
|
noEmitOnError = false,
|
|
141235
141251
|
skipDiagnostics = true,
|
|
141236
141252
|
logDiagnostics = false,
|
|
141253
|
+
copyDtsFiles = true,
|
|
141237
141254
|
afterDiagnostic = noop,
|
|
141238
141255
|
beforeWriteFile = noop,
|
|
141239
141256
|
afterBuild = noop
|
|
@@ -141286,6 +141303,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
141286
141303
|
`));
|
|
141287
141304
|
return;
|
|
141288
141305
|
}
|
|
141306
|
+
setCompileRoot(root);
|
|
141289
141307
|
compilerOptions.rootDir || (compilerOptions.rootDir = root);
|
|
141290
141308
|
project = new Project({
|
|
141291
141309
|
compilerOptions: mergeObjects(compilerOptions, {
|
|
@@ -141308,6 +141326,9 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
141308
141326
|
}
|
|
141309
141327
|
},
|
|
141310
141328
|
transform(code, id) {
|
|
141329
|
+
if (id.startsWith(virtualPrefix)) {
|
|
141330
|
+
return null;
|
|
141331
|
+
}
|
|
141311
141332
|
if (vueRE.test(id)) {
|
|
141312
141333
|
const { content, ext } = compileVueCode(code);
|
|
141313
141334
|
if (content) {
|
|
@@ -141330,7 +141351,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
141330
141351
|
}
|
|
141331
141352
|
},
|
|
141332
141353
|
async closeBundle() {
|
|
141333
|
-
var _a2, _b, _c, _d, _e;
|
|
141354
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
141334
141355
|
if (!outputDir || !project || isBundle)
|
|
141335
141356
|
return;
|
|
141336
141357
|
logger.info(import_chalk.default.green(`
|
|
@@ -141340,8 +141361,8 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
141340
141361
|
sourceDtsFiles.clear();
|
|
141341
141362
|
const startTime = Date.now();
|
|
141342
141363
|
const tsConfig = (_a2 = (0, import_typescript.readConfigFile)(tsConfigPath, project.getFileSystem().readFileSync).config) != null ? _a2 : {};
|
|
141343
|
-
const include = (_b = options.include) != null ? _b : tsConfig.include;
|
|
141344
|
-
const exclude = (
|
|
141364
|
+
const include = (_c = (_b = options.include) != null ? _b : tsConfig.include) != null ? _c : "**/*";
|
|
141365
|
+
const exclude = (_d = options.exclude) != null ? _d : tsConfig.exclude;
|
|
141345
141366
|
bundleDebug("read config");
|
|
141346
141367
|
const includedFileSet = new Set();
|
|
141347
141368
|
if (include && include.length) {
|
|
@@ -141351,10 +141372,15 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
141351
141372
|
ignore: ensureArray(exclude != null ? exclude : ["node_modules/**"]).map(normalizeGlob)
|
|
141352
141373
|
});
|
|
141353
141374
|
files.forEach((file) => {
|
|
141354
|
-
includedFileSet.add(dtsRE.test(file) ? file : `${tjsRE.test(file) ? file.replace(tjsRE, "") : file}.d.ts`);
|
|
141355
141375
|
if (dtsRE.test(file)) {
|
|
141376
|
+
if (!copyDtsFiles) {
|
|
141377
|
+
return;
|
|
141378
|
+
}
|
|
141379
|
+
includedFileSet.add(file);
|
|
141356
141380
|
sourceDtsFiles.add(project.addSourceFileAtPath(file));
|
|
141381
|
+
return;
|
|
141357
141382
|
}
|
|
141383
|
+
includedFileSet.add(`${tjsRE.test(file) ? file.replace(tjsRE, "") : file}.d.ts`);
|
|
141358
141384
|
});
|
|
141359
141385
|
if (hasJsVue) {
|
|
141360
141386
|
if (!allowJs) {
|
|
@@ -141425,8 +141451,8 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
141425
141451
|
if (typeof beforeWriteFile === "function") {
|
|
141426
141452
|
const result = beforeWriteFile(typesPath, content);
|
|
141427
141453
|
if (result && isNativeObj(result)) {
|
|
141428
|
-
typesPath = (
|
|
141429
|
-
content = (
|
|
141454
|
+
typesPath = (_e = result.filePath) != null ? _e : typesPath;
|
|
141455
|
+
content = (_f = result.content) != null ? _f : content;
|
|
141430
141456
|
}
|
|
141431
141457
|
}
|
|
141432
141458
|
await fs.writeFile(typesPath, content, "utf-8");
|
package/package.json
CHANGED