vite-plugin-dts 1.0.4 → 1.0.5
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 +5 -5
- package/README.zh-CN.md +184 -184
- package/dist/index.js +8 -8
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**English** | [中文](./README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
A vite plugin that
|
|
5
|
+
A vite plugin that generates declaration files (`*.d.ts`) from `.ts` or `.vue` source files when using vite in [library mode](https://vitejs.dev/guide/build.html#library-mode).
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -166,17 +166,17 @@ Then check `example/types`.
|
|
|
166
166
|
|
|
167
167
|
## FAQ
|
|
168
168
|
|
|
169
|
-
Here
|
|
169
|
+
Here are some FAQ's and solutions.
|
|
170
170
|
|
|
171
171
|
### Missing some declaration files after build
|
|
172
172
|
|
|
173
|
-
By default `skipDiagnostics` option is `true`, which means that type diagnostic will be skipped during the build process (some projects may have diagnostic
|
|
173
|
+
By default `skipDiagnostics` option is `true`, which means that type diagnostic will be skipped during the build process (some projects may have diagnostic tools such as `vue-tsc`). If there are some files with type errors which interrupt the build process, these files will not be emitted (declaration files won't be generated).
|
|
174
174
|
|
|
175
|
-
If your project
|
|
175
|
+
If your project doesn't use 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 check the type errors during build and log error information to the terminal.
|
|
176
176
|
|
|
177
177
|
### Take type error when using both `script` and `setup-script` in vue component
|
|
178
178
|
|
|
179
|
-
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
|
|
179
|
+
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 from `script` gets merged with the parameter object of `defineComponent` from `setup-script`. This is incompatible with parameters and types returned from `defineComponent`, which results in a type error.
|
|
180
180
|
|
|
181
181
|
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.
|
|
182
182
|
|
package/README.zh-CN.md
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
# vite-plugin-dts
|
|
2
|
-
|
|
3
|
-
**中文** | [English](./README.md)
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
// 用于手动设置入口文件的根路径
|
|
85
|
-
// 在计算每个文件的输出路径时将基于该路径
|
|
86
|
-
// 默认为所有文件的最小公共路径
|
|
87
|
-
entryRoot?: string
|
|
88
|
-
|
|
89
|
-
// 提供给 ts-morph Project 初始化的 compilerOptions 选项
|
|
90
|
-
// 默认值: null
|
|
91
|
-
compilerOptions?: ts.CompilerOptions | null
|
|
92
|
-
|
|
93
|
-
// 提供给 ts-morph Project 初始化的 tsconfig.json 路径
|
|
94
|
-
// 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
|
|
95
|
-
// 默认值: 'tsconfig.json'
|
|
96
|
-
tsConfigFilePath?: string
|
|
97
|
-
|
|
98
|
-
// 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
|
|
99
|
-
// 默认值: false
|
|
100
|
-
cleanVueFileName?: boolean
|
|
101
|
-
|
|
102
|
-
//是否将动态引入转换为静态
|
|
103
|
-
// eg. 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
|
|
104
|
-
// 默认值: false
|
|
105
|
-
staticImport?: boolean
|
|
106
|
-
|
|
107
|
-
// 手动设置包含路径的 glob
|
|
108
|
-
// 默认基于 tsconfig.json 的 include 选项
|
|
109
|
-
include?: string | string[]
|
|
110
|
-
|
|
111
|
-
// 手动设置排除路径的 glob
|
|
112
|
-
// 默认基于 tsconfig.json 的 exclude 选线,未设置时为 'node_module/**'
|
|
113
|
-
exclude?: string | string[]
|
|
114
|
-
|
|
115
|
-
// 是否生成类型声明入口
|
|
116
|
-
// 当为 true 时会基于 package.json 的 tpyes 字段生成,或者 `${outputDir}/index.d.ts`
|
|
117
|
-
// 默认值: false
|
|
118
|
-
insertTypesEntry?: boolean
|
|
119
|
-
|
|
120
|
-
// 是否将源码里的 .d.ts 文件复制到 outputDir
|
|
121
|
-
// 默认值: true
|
|
122
|
-
copyDtsFiles?: boolean
|
|
123
|
-
|
|
124
|
-
// 出现类型诊断信息时不生成类型文件
|
|
125
|
-
// 默认值: false
|
|
126
|
-
noEmitOnError?: boolean
|
|
127
|
-
|
|
128
|
-
// 是否跳过类型诊断
|
|
129
|
-
// 跳过类型诊断意味着出现错误时不会中断打包进程的执行
|
|
130
|
-
// 但对于出现错误的源文件,将无法生成相应的类型文件
|
|
131
|
-
// 默认值: true
|
|
132
|
-
skipDiagnostics?: boolean
|
|
133
|
-
|
|
134
|
-
// 是否打印类型诊断信息
|
|
135
|
-
// 当跳过类型诊断时该属性将不会生效
|
|
136
|
-
// 默认值: false
|
|
137
|
-
logDiagnostics?: boolean
|
|
138
|
-
|
|
139
|
-
// 获取诊断信息后的钩子
|
|
140
|
-
// 可以根据参数 length 来判断有误类型错误
|
|
141
|
-
// 默认值: () => {}
|
|
142
|
-
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
143
|
-
|
|
144
|
-
// 类型声明文件被写入前的钩子
|
|
145
|
-
// 可以在钩子里转换文件路径和文件内容
|
|
146
|
-
// 默认值: () => {}
|
|
147
|
-
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
148
|
-
|
|
149
|
-
// 构建后回调钩子
|
|
150
|
-
// 将会在所有类型文件被写入后调用
|
|
151
|
-
// 默认值: () => {}
|
|
152
|
-
afterBuild?: () => void | Promise<void>
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## 示例
|
|
157
|
-
|
|
158
|
-
克隆项目然后执行下列命令:
|
|
159
|
-
|
|
160
|
-
```sh
|
|
161
|
-
pnpm run test:e2e
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
然后检查 `example/types` 目录。
|
|
165
|
-
|
|
166
|
-
## 常见问题
|
|
167
|
-
|
|
168
|
-
此处将收录一些常见的问题并提供一些解决方案。
|
|
169
|
-
|
|
170
|
-
### 打包后出现类型文件缺失
|
|
171
|
-
|
|
172
|
-
默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
|
|
173
|
-
|
|
174
|
-
如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
|
|
175
|
-
|
|
176
|
-
### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
|
|
177
|
-
|
|
178
|
-
这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
|
|
179
|
-
|
|
180
|
-
这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
|
|
181
|
-
|
|
182
|
-
## 授权
|
|
183
|
-
|
|
184
|
-
MIT 授权。
|
|
1
|
+
# vite-plugin-dts
|
|
2
|
+
|
|
3
|
+
**中文** | [English](./README.md)
|
|
4
|
+
|
|
5
|
+
一款用于在 [库模式](https://cn.vitejs.dev/guide/build.html#library-mode) 中,从 `.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
|
+
// 用于手动设置入口文件的根路径
|
|
85
|
+
// 在计算每个文件的输出路径时将基于该路径
|
|
86
|
+
// 默认为所有文件的最小公共路径
|
|
87
|
+
entryRoot?: string
|
|
88
|
+
|
|
89
|
+
// 提供给 ts-morph Project 初始化的 compilerOptions 选项
|
|
90
|
+
// 默认值: null
|
|
91
|
+
compilerOptions?: ts.CompilerOptions | null
|
|
92
|
+
|
|
93
|
+
// 提供给 ts-morph Project 初始化的 tsconfig.json 路径
|
|
94
|
+
// 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
|
|
95
|
+
// 默认值: 'tsconfig.json'
|
|
96
|
+
tsConfigFilePath?: string
|
|
97
|
+
|
|
98
|
+
// 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
|
|
99
|
+
// 默认值: false
|
|
100
|
+
cleanVueFileName?: boolean
|
|
101
|
+
|
|
102
|
+
//是否将动态引入转换为静态
|
|
103
|
+
// eg. 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
|
|
104
|
+
// 默认值: false
|
|
105
|
+
staticImport?: boolean
|
|
106
|
+
|
|
107
|
+
// 手动设置包含路径的 glob
|
|
108
|
+
// 默认基于 tsconfig.json 的 include 选项
|
|
109
|
+
include?: string | string[]
|
|
110
|
+
|
|
111
|
+
// 手动设置排除路径的 glob
|
|
112
|
+
// 默认基于 tsconfig.json 的 exclude 选线,未设置时为 'node_module/**'
|
|
113
|
+
exclude?: string | string[]
|
|
114
|
+
|
|
115
|
+
// 是否生成类型声明入口
|
|
116
|
+
// 当为 true 时会基于 package.json 的 tpyes 字段生成,或者 `${outputDir}/index.d.ts`
|
|
117
|
+
// 默认值: false
|
|
118
|
+
insertTypesEntry?: boolean
|
|
119
|
+
|
|
120
|
+
// 是否将源码里的 .d.ts 文件复制到 outputDir
|
|
121
|
+
// 默认值: true
|
|
122
|
+
copyDtsFiles?: boolean
|
|
123
|
+
|
|
124
|
+
// 出现类型诊断信息时不生成类型文件
|
|
125
|
+
// 默认值: false
|
|
126
|
+
noEmitOnError?: boolean
|
|
127
|
+
|
|
128
|
+
// 是否跳过类型诊断
|
|
129
|
+
// 跳过类型诊断意味着出现错误时不会中断打包进程的执行
|
|
130
|
+
// 但对于出现错误的源文件,将无法生成相应的类型文件
|
|
131
|
+
// 默认值: true
|
|
132
|
+
skipDiagnostics?: boolean
|
|
133
|
+
|
|
134
|
+
// 是否打印类型诊断信息
|
|
135
|
+
// 当跳过类型诊断时该属性将不会生效
|
|
136
|
+
// 默认值: false
|
|
137
|
+
logDiagnostics?: boolean
|
|
138
|
+
|
|
139
|
+
// 获取诊断信息后的钩子
|
|
140
|
+
// 可以根据参数 length 来判断有误类型错误
|
|
141
|
+
// 默认值: () => {}
|
|
142
|
+
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
143
|
+
|
|
144
|
+
// 类型声明文件被写入前的钩子
|
|
145
|
+
// 可以在钩子里转换文件路径和文件内容
|
|
146
|
+
// 默认值: () => {}
|
|
147
|
+
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
148
|
+
|
|
149
|
+
// 构建后回调钩子
|
|
150
|
+
// 将会在所有类型文件被写入后调用
|
|
151
|
+
// 默认值: () => {}
|
|
152
|
+
afterBuild?: () => void | Promise<void>
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 示例
|
|
157
|
+
|
|
158
|
+
克隆项目然后执行下列命令:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
pnpm run test:e2e
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
然后检查 `example/types` 目录。
|
|
165
|
+
|
|
166
|
+
## 常见问题
|
|
167
|
+
|
|
168
|
+
此处将收录一些常见的问题并提供一些解决方案。
|
|
169
|
+
|
|
170
|
+
### 打包后出现类型文件缺失
|
|
171
|
+
|
|
172
|
+
默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
|
|
173
|
+
|
|
174
|
+
如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
|
|
175
|
+
|
|
176
|
+
### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
|
|
177
|
+
|
|
178
|
+
这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
|
|
179
|
+
|
|
180
|
+
这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
|
|
181
|
+
|
|
182
|
+
## 授权
|
|
183
|
+
|
|
184
|
+
MIT 授权。
|
package/dist/index.js
CHANGED
|
@@ -311,7 +311,7 @@ var noop = () => {
|
|
|
311
311
|
};
|
|
312
312
|
var bundleDebug = (0, import_debug.debug)("vite-plugin-dts:bundle");
|
|
313
313
|
function dtsPlugin(options = {}) {
|
|
314
|
-
var _a;
|
|
314
|
+
var _a, _b;
|
|
315
315
|
const {
|
|
316
316
|
tsConfigFilePath = "tsconfig.json",
|
|
317
317
|
cleanVueFileName = false,
|
|
@@ -328,7 +328,7 @@ function dtsPlugin(options = {}) {
|
|
|
328
328
|
} = options;
|
|
329
329
|
const compilerOptions = (_a = options.compilerOptions) != null ? _a : {};
|
|
330
330
|
let root;
|
|
331
|
-
let entryRoot;
|
|
331
|
+
let entryRoot = (_b = options.entryRoot) != null ? _b : "";
|
|
332
332
|
let aliases;
|
|
333
333
|
let entries;
|
|
334
334
|
let logger;
|
|
@@ -357,7 +357,7 @@ function dtsPlugin(options = {}) {
|
|
|
357
357
|
}
|
|
358
358
|
},
|
|
359
359
|
configResolved(config) {
|
|
360
|
-
var _a2,
|
|
360
|
+
var _a2, _b2;
|
|
361
361
|
if (isBundle)
|
|
362
362
|
return;
|
|
363
363
|
logger = config.logger;
|
|
@@ -390,7 +390,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
390
390
|
tsConfigFilePath: tsConfigPath,
|
|
391
391
|
skipAddingFilesFromTsConfig: true
|
|
392
392
|
});
|
|
393
|
-
allowJs = (
|
|
393
|
+
allowJs = (_b2 = project.getCompilerOptions().allowJs) != null ? _b2 : false;
|
|
394
394
|
},
|
|
395
395
|
buildStart(inputOptions) {
|
|
396
396
|
if (insertTypesEntry) {
|
|
@@ -423,7 +423,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
423
423
|
}
|
|
424
424
|
},
|
|
425
425
|
async closeBundle() {
|
|
426
|
-
var _a2,
|
|
426
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
427
427
|
if (!outputDir || !project || isBundle)
|
|
428
428
|
return;
|
|
429
429
|
logger.info(import_chalk.default.green(`
|
|
@@ -433,7 +433,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
433
433
|
sourceDtsFiles.clear();
|
|
434
434
|
const startTime = Date.now();
|
|
435
435
|
const tsConfig = (_a2 = (0, import_typescript.readConfigFile)(tsConfigPath, project.getFileSystem().readFileSync).config) != null ? _a2 : {};
|
|
436
|
-
const include = (_c = (
|
|
436
|
+
const include = (_c = (_b2 = options.include) != null ? _b2 : tsConfig.include) != null ? _c : "**/*";
|
|
437
437
|
const exclude = (_d = options.exclude) != null ? _d : tsConfig.exclude;
|
|
438
438
|
bundleDebug("read config");
|
|
439
439
|
const includedFileSet = /* @__PURE__ */ new Set();
|
|
@@ -489,7 +489,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
489
489
|
entryRoot = ensureAbsolute(entryRoot, root);
|
|
490
490
|
bundleDebug("emit");
|
|
491
491
|
await runParallel(import_os.default.cpus().length, outputFiles, async (outputFile) => {
|
|
492
|
-
var _a3,
|
|
492
|
+
var _a3, _b3;
|
|
493
493
|
let filePath = outputFile.path;
|
|
494
494
|
let content = outputFile.content;
|
|
495
495
|
const isMapFile = filePath.endsWith(".map");
|
|
@@ -506,7 +506,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Start generate declaration files...`)
|
|
|
506
506
|
const result = beforeWriteFile(filePath, content);
|
|
507
507
|
if (result && isNativeObj(result)) {
|
|
508
508
|
filePath = (_a3 = result.filePath) != null ? _a3 : filePath;
|
|
509
|
-
content = (
|
|
509
|
+
content = (_b3 = result.content) != null ? _b3 : content;
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
await import_fs_extra.default.mkdir((0, import_path3.dirname)(filePath), { recursive: true });
|
package/dist/index.mjs
CHANGED
|
@@ -290,7 +290,7 @@ var noop = () => {
|
|
|
290
290
|
};
|
|
291
291
|
var bundleDebug = debug("vite-plugin-dts:bundle");
|
|
292
292
|
function dtsPlugin(options = {}) {
|
|
293
|
-
var _a;
|
|
293
|
+
var _a, _b;
|
|
294
294
|
const {
|
|
295
295
|
tsConfigFilePath = "tsconfig.json",
|
|
296
296
|
cleanVueFileName = false,
|
|
@@ -307,7 +307,7 @@ function dtsPlugin(options = {}) {
|
|
|
307
307
|
} = options;
|
|
308
308
|
const compilerOptions = (_a = options.compilerOptions) != null ? _a : {};
|
|
309
309
|
let root;
|
|
310
|
-
let entryRoot;
|
|
310
|
+
let entryRoot = (_b = options.entryRoot) != null ? _b : "";
|
|
311
311
|
let aliases;
|
|
312
312
|
let entries;
|
|
313
313
|
let logger;
|
|
@@ -336,7 +336,7 @@ function dtsPlugin(options = {}) {
|
|
|
336
336
|
}
|
|
337
337
|
},
|
|
338
338
|
configResolved(config) {
|
|
339
|
-
var _a2,
|
|
339
|
+
var _a2, _b2;
|
|
340
340
|
if (isBundle)
|
|
341
341
|
return;
|
|
342
342
|
logger = config.logger;
|
|
@@ -369,7 +369,7 @@ ${chalk.cyan("[vite:dts]")} Can not resolve declaration directory, please check
|
|
|
369
369
|
tsConfigFilePath: tsConfigPath,
|
|
370
370
|
skipAddingFilesFromTsConfig: true
|
|
371
371
|
});
|
|
372
|
-
allowJs = (
|
|
372
|
+
allowJs = (_b2 = project.getCompilerOptions().allowJs) != null ? _b2 : false;
|
|
373
373
|
},
|
|
374
374
|
buildStart(inputOptions) {
|
|
375
375
|
if (insertTypesEntry) {
|
|
@@ -402,7 +402,7 @@ ${chalk.cyan("[vite:dts]")} Can not resolve declaration directory, please check
|
|
|
402
402
|
}
|
|
403
403
|
},
|
|
404
404
|
async closeBundle() {
|
|
405
|
-
var _a2,
|
|
405
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
406
406
|
if (!outputDir || !project || isBundle)
|
|
407
407
|
return;
|
|
408
408
|
logger.info(chalk.green(`
|
|
@@ -412,7 +412,7 @@ ${chalk.cyan("[vite:dts]")} Start generate declaration files...`));
|
|
|
412
412
|
sourceDtsFiles.clear();
|
|
413
413
|
const startTime = Date.now();
|
|
414
414
|
const tsConfig = (_a2 = readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config) != null ? _a2 : {};
|
|
415
|
-
const include = (_c = (
|
|
415
|
+
const include = (_c = (_b2 = options.include) != null ? _b2 : tsConfig.include) != null ? _c : "**/*";
|
|
416
416
|
const exclude = (_d = options.exclude) != null ? _d : tsConfig.exclude;
|
|
417
417
|
bundleDebug("read config");
|
|
418
418
|
const includedFileSet = /* @__PURE__ */ new Set();
|
|
@@ -468,7 +468,7 @@ ${chalk.cyan("[vite:dts]")} Start generate declaration files...`));
|
|
|
468
468
|
entryRoot = ensureAbsolute(entryRoot, root);
|
|
469
469
|
bundleDebug("emit");
|
|
470
470
|
await runParallel(os.cpus().length, outputFiles, async (outputFile) => {
|
|
471
|
-
var _a3,
|
|
471
|
+
var _a3, _b3;
|
|
472
472
|
let filePath = outputFile.path;
|
|
473
473
|
let content = outputFile.content;
|
|
474
474
|
const isMapFile = filePath.endsWith(".map");
|
|
@@ -485,7 +485,7 @@ ${chalk.cyan("[vite:dts]")} Start generate declaration files...`));
|
|
|
485
485
|
const result = beforeWriteFile(filePath, content);
|
|
486
486
|
if (result && isNativeObj(result)) {
|
|
487
487
|
filePath = (_a3 = result.filePath) != null ? _a3 : filePath;
|
|
488
|
-
content = (
|
|
488
|
+
content = (_b3 = result.content) != null ? _b3 : content;
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
await fs.mkdir(dirname3(filePath), { recursive: true });
|
package/package.json
CHANGED