vite-plugin-dts 2.2.0 → 2.3.0

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 CHANGED
@@ -91,7 +91,7 @@ If your project doesn't use type diagnostic tools, you can set `skipDiagnostics:
91
91
 
92
92
  This is usually caused by using the `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.
93
93
 
94
- 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.
94
+ Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue). You should remove the `defineComponent` which in `script` and export a native object directly.
95
95
 
96
96
  ### Type errors that are unable to infer types from packages in `node_modules`
97
97
 
package/README.zh-CN.md CHANGED
@@ -1,325 +1,325 @@
1
- <h1 align="center">vite-plugin-dts</h1>
2
-
3
- <p align="center">
4
- 一款用于在 <a href="https://cn.vitejs.dev/guide/build.html#library-mode">库模式</a> 中从 <code>.ts(x)</code> 或 <code>.vue</code> 源文件生成类型文件(<code>*.d.ts</code>)的 vite 插件。
5
- </p>
6
-
7
- <p align="center">
8
- <a href="https://www.npmjs.com/package/vite-plugin-dts">
9
- <img src="https://img.shields.io/npm/v/vite-plugin-dts?color=orange&label=" alt="version" />
10
- </a>
11
- </p>
12
-
13
- <p align="center">
14
- <strong>中文</strong> | <a href="./README.md">English</a>
15
- </p>
16
-
17
- <p align="center"><strong>注意:</strong>从 1.7.0 开始 <code>skipDiagnostics</code> 选项默认为 <code>false</code>。</p>
18
-
19
- <br />
20
-
21
- ## 安装
22
-
23
- ```sh
24
- pnpm add vite-plugin-dts -D
25
- ```
26
-
27
- ## 使用
28
-
29
- 在 `vite.config.ts`:
30
-
31
- ```ts
32
- import { resolve } from 'path'
33
- import { defineConfig } from 'vite'
34
- import dts from 'vite-plugin-dts'
35
-
36
- export default defineConfig({
37
- build: {
38
- lib: {
39
- entry: resolve(__dirname, 'src/index.ts'),
40
- name: 'MyLib',
41
- formats: ['es'],
42
- fileName: 'my-lib'
43
- }
44
- },
45
- plugins: [dts()]
46
- })
47
- ```
48
-
49
- 在你的组件中:
50
-
51
- ```vue
52
- <template>
53
- <div></div>
54
- </template>
55
-
56
- <script lang="ts">
57
- // 使用 defineComponent 来进行类型推断
58
- import { defineComponent } from 'vue'
59
-
60
- export default defineComponent({
61
- name: 'Component'
62
- })
63
- </script>
64
- ```
65
-
66
- ```vue
67
- <script setup lang="ts">
68
- // 尽管没有直接使用 props,你仍需要接收 defineProps 的返回值
69
- const props = defineProps<{
70
- color: 'blue' | 'red'
71
- }>()
72
- </script>
73
-
74
- <template>
75
- <div>{{ color }}</div>
76
- </template>
77
- ```
78
-
79
- ## 常见问题
80
-
81
- 此处将收录一些常见的问题并提供一些解决方案。
82
-
83
- ### 打包后出现类型文件缺失 (`1.7.0` 之前)
84
-
85
- 默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
86
-
87
- 如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
88
-
89
- ### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
90
-
91
- 这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
92
-
93
- 这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
94
-
95
- ### 打包时出现了无法从 `node_modules` 的包中推断类型的错误
96
-
97
- 这是 TypeScript 通过软链接 (pnpm) 读取 `node_modules` 中过的类型时会出现的一个已知的问题,可以参考这个 [issue](https://github.com/microsoft/TypeScript/issues/42873),目前已有的一个解决方案,在你的 `tsconfig.json` 中添加 `baseUrl` 以及在 `paths` 添加这些包的路径:
98
-
99
- ```json
100
- {
101
- "compilerOptions": {
102
- "baseUrl": ".",
103
- "paths": {
104
- "third-lib": ["node_modules/third-lib"]
105
- }
106
- }
107
- }
108
- ```
109
-
110
- ## 选项
111
-
112
- ```ts
113
- import type { ts, Diagnostic } from 'ts-morph'
114
- import type { LogLevel } from 'vite'
115
-
116
- interface TransformWriteFile {
117
- filePath?: string
118
- content?: string
119
- }
120
-
121
- export interface PluginOptions {
122
- /**
123
- * 执行的根目录
124
- *
125
- * 默认基于 vite 配置的 'root' 选项
126
- */
127
- root?: string
128
-
129
- /**
130
- * 声明文件的输出目录
131
- *
132
- * 可以指定一个数组来输出到多个目录中
133
- *
134
- * 默认基于 vite 配置的 'build.outDir' 选项
135
- */
136
- outputDir?: string | string[]
137
-
138
- /**
139
- * 用于手动设置入口文件的根路径
140
- *
141
- * 在计算每个文件的输出路径时将基于该路径
142
- *
143
- * 默认为所有文件的最小公共路径
144
- */
145
- entryRoot?: string
146
-
147
- /**
148
- * 提供给 ts-morph Project 初始化的 compilerOptions 选项
149
- *
150
- * @default null
151
- */
152
- compilerOptions?: ts.CompilerOptions | null
153
-
154
- /**
155
- * 提供给 ts-morph Project 初始化的 tsconfig.json 路径
156
- *
157
- * 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
158
- *
159
- * @default 'tsconfig.json'
160
- */
161
- tsConfigFilePath?: string
162
-
163
- /**
164
- * 设置在转换别名时哪些路径需要排除
165
- *
166
- * 如果为正则,会直接使用 test 和原始路径进行比较
167
- *
168
- * @default []
169
- */
170
- aliasesExclude?: (string | RegExp)[]
171
-
172
- /**
173
- * 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
174
- *
175
- * @default false
176
- */
177
- cleanVueFileName?: boolean
178
-
179
- /**
180
- * 是否将动态引入转换为静态
181
- *
182
- * 当开启打包类型文件时强制为 true
183
- *
184
- * 例如将 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
185
- *
186
- * @default false
187
- */
188
- staticImport?: boolean
189
-
190
- /**
191
- * 手动设置包含路径的 glob
192
- *
193
- * 默认基于 tsconfig.json 的 'include' 选项
194
- */
195
- include?: string | string[]
196
-
197
- /**
198
- * 手动设置排除路径的 glob
199
- *
200
- * 默认基于 tsconfig.json 的 'exclude' 选线,未设置时为 'node_module/**'
201
- */
202
- exclude?: string | string[]
203
-
204
- /**
205
- * 如果文件内容仅包含 'export {}' 则跳过生成
206
- *
207
- * @default true
208
- */
209
- clearPureImport?: boolean
210
-
211
- /**
212
- * 是否生成类型声明入口
213
- *
214
- * 当为 true 时会基于 package.json 的 types 字段生成,或者 `${outputDir}/index.d.ts`
215
- *
216
- * 当开启打包类型文件时强制为 true
217
- *
218
- * @default false
219
- */
220
- insertTypesEntry?: boolean
221
-
222
- /**
223
- * 设置是否在发出类型文件后将其打包
224
- *
225
- * 基于 `@microsoft/api-extractor`,由于这开启了一个新的进程,将会消耗一些时间
226
- *
227
- * @default false
228
- */
229
- rollupTypes?: boolean
230
-
231
- /**
232
- * 是否将源码里的 .d.ts 文件复制到 outputDir
233
- *
234
- * @default false
235
- * @remarks 在 2.0 之前它默认为 true
236
- */
237
- copyDtsFiles?: boolean
238
-
239
- /**
240
- * 出现类型诊断信息时不生成类型文件
241
- *
242
- * @default false
243
- */
244
- noEmitOnError?: boolean
245
-
246
- /**
247
- * 是否跳过类型诊断
248
- *
249
- * 跳过类型诊断意味着出现错误时不会中断打包进程的执行
250
- *
251
- * 但对于出现错误的源文件,将无法生成相应的类型文件
252
- *
253
- * @default false
254
- * @remarks 在 1.7 之前它默认为 true
255
- */
256
- skipDiagnostics?: boolean
257
-
258
- /**
259
- * 定制 typescript 的 lib 文件夹路径
260
- *
261
- * 应传入一个 root 的相对路径或一个绝对路径
262
- *
263
- * @default undefined
264
- */
265
- libFolderPath?: string
266
-
267
- /**
268
- * 指定插件的输出等级
269
- *
270
- * 默认基于 vite 配置的 'logLevel' 选项
271
- */
272
- logLevel?: LogLevel
273
-
274
- /**
275
- * 获取诊断信息后的钩子
276
- *
277
- * 可以根据参数 length 来判断有误类型错误
278
- *
279
- * @default () => {}
280
- */
281
- afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
282
-
283
- /**
284
- * 类型声明文件被写入前的钩子
285
- *
286
- * 可以在钩子里转换文件路径和文件内容
287
- *
288
- * 当返回 false 时会跳过该文件
289
- *
290
- * @default () => {}
291
- */
292
- beforeWriteFile?: (filePath: string, content: string) => void | false | TransformWriteFile
293
-
294
- /**
295
- * 构建后回调钩子
296
- *
297
- * 将会在所有类型文件被写入后调用
298
- *
299
- * @default () => {}
300
- */
301
- afterBuild?: () => void | Promise<void>
302
- }
303
- ```
304
-
305
- ## 贡献者
306
-
307
- 感谢他们的所做的一切贡献!
308
-
309
- <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
310
- <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" />
311
- </a>
312
-
313
- ## 示例
314
-
315
- 克隆项目然后执行下列命令:
316
-
317
- ```sh
318
- pnpm run test:ts
319
- ```
320
-
321
- 然后检查 `examples/ts/types` 目录。
322
-
323
- ## 授权
324
-
325
- MIT 授权。
1
+ <h1 align="center">vite-plugin-dts</h1>
2
+
3
+ <p align="center">
4
+ 一款用于在 <a href="https://cn.vitejs.dev/guide/build.html#library-mode">库模式</a> 中从 <code>.ts(x)</code> 或 <code>.vue</code> 源文件生成类型文件(<code>*.d.ts</code>)的 vite 插件。
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/vite-plugin-dts">
9
+ <img src="https://img.shields.io/npm/v/vite-plugin-dts?color=orange&label=" alt="version" />
10
+ </a>
11
+ </p>
12
+
13
+ <p align="center">
14
+ <strong>中文</strong> | <a href="./README.md">English</a>
15
+ </p>
16
+
17
+ <p align="center"><strong>注意:</strong>从 1.7.0 开始 <code>skipDiagnostics</code> 选项默认为 <code>false</code>。</p>
18
+
19
+ <br />
20
+
21
+ ## 安装
22
+
23
+ ```sh
24
+ pnpm add vite-plugin-dts -D
25
+ ```
26
+
27
+ ## 使用
28
+
29
+ 在 `vite.config.ts`:
30
+
31
+ ```ts
32
+ import { resolve } from 'path'
33
+ import { defineConfig } from 'vite'
34
+ import dts from 'vite-plugin-dts'
35
+
36
+ export default defineConfig({
37
+ build: {
38
+ lib: {
39
+ entry: resolve(__dirname, 'src/index.ts'),
40
+ name: 'MyLib',
41
+ formats: ['es'],
42
+ fileName: 'my-lib'
43
+ }
44
+ },
45
+ plugins: [dts()]
46
+ })
47
+ ```
48
+
49
+ 在你的组件中:
50
+
51
+ ```vue
52
+ <template>
53
+ <div></div>
54
+ </template>
55
+
56
+ <script lang="ts">
57
+ // 使用 defineComponent 来进行类型推断
58
+ import { defineComponent } from 'vue'
59
+
60
+ export default defineComponent({
61
+ name: 'Component'
62
+ })
63
+ </script>
64
+ ```
65
+
66
+ ```vue
67
+ <script setup lang="ts">
68
+ // 尽管没有直接使用 props,你仍需要接收 defineProps 的返回值
69
+ const props = defineProps<{
70
+ color: 'blue' | 'red'
71
+ }>()
72
+ </script>
73
+
74
+ <template>
75
+ <div>{{ color }}</div>
76
+ </template>
77
+ ```
78
+
79
+ ## 常见问题
80
+
81
+ 此处将收录一些常见的问题并提供一些解决方案。
82
+
83
+ ### 打包后出现类型文件缺失 (`1.7.0` 之前)
84
+
85
+ 默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
86
+
87
+ 如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
88
+
89
+ ### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
90
+
91
+ 这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
92
+
93
+ 这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
94
+
95
+ ### 打包时出现了无法从 `node_modules` 的包中推断类型的错误
96
+
97
+ 这是 TypeScript 通过软链接 (pnpm) 读取 `node_modules` 中过的类型时会出现的一个已知的问题,可以参考这个 [issue](https://github.com/microsoft/TypeScript/issues/42873),目前已有的一个解决方案,在你的 `tsconfig.json` 中添加 `baseUrl` 以及在 `paths` 添加这些包的路径:
98
+
99
+ ```json
100
+ {
101
+ "compilerOptions": {
102
+ "baseUrl": ".",
103
+ "paths": {
104
+ "third-lib": ["node_modules/third-lib"]
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ ## 选项
111
+
112
+ ```ts
113
+ import type { ts, Diagnostic } from 'ts-morph'
114
+ import type { LogLevel } from 'vite'
115
+
116
+ interface TransformWriteFile {
117
+ filePath?: string
118
+ content?: string
119
+ }
120
+
121
+ export interface PluginOptions {
122
+ /**
123
+ * 执行的根目录
124
+ *
125
+ * 默认基于 vite 配置的 'root' 选项
126
+ */
127
+ root?: string
128
+
129
+ /**
130
+ * 声明文件的输出目录
131
+ *
132
+ * 可以指定一个数组来输出到多个目录中
133
+ *
134
+ * 默认基于 vite 配置的 'build.outDir' 选项
135
+ */
136
+ outputDir?: string | string[]
137
+
138
+ /**
139
+ * 用于手动设置入口文件的根路径
140
+ *
141
+ * 在计算每个文件的输出路径时将基于该路径
142
+ *
143
+ * 默认为所有文件的最小公共路径
144
+ */
145
+ entryRoot?: string
146
+
147
+ /**
148
+ * 提供给 ts-morph Project 初始化的 compilerOptions 选项
149
+ *
150
+ * @default null
151
+ */
152
+ compilerOptions?: ts.CompilerOptions | null
153
+
154
+ /**
155
+ * 提供给 ts-morph Project 初始化的 tsconfig.json 路径
156
+ *
157
+ * 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
158
+ *
159
+ * @default 'tsconfig.json'
160
+ */
161
+ tsConfigFilePath?: string
162
+
163
+ /**
164
+ * 设置在转换别名时哪些路径需要排除
165
+ *
166
+ * 如果为正则,会直接使用 test 和原始路径进行比较
167
+ *
168
+ * @default []
169
+ */
170
+ aliasesExclude?: (string | RegExp)[]
171
+
172
+ /**
173
+ * 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
174
+ *
175
+ * @default false
176
+ */
177
+ cleanVueFileName?: boolean
178
+
179
+ /**
180
+ * 是否将动态引入转换为静态
181
+ *
182
+ * 当开启打包类型文件时强制为 true
183
+ *
184
+ * 例如将 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
185
+ *
186
+ * @default false
187
+ */
188
+ staticImport?: boolean
189
+
190
+ /**
191
+ * 手动设置包含路径的 glob
192
+ *
193
+ * 默认基于 tsconfig.json 的 'include' 选项
194
+ */
195
+ include?: string | string[]
196
+
197
+ /**
198
+ * 手动设置排除路径的 glob
199
+ *
200
+ * 默认基于 tsconfig.json 的 'exclude' 选线,未设置时为 'node_module/**'
201
+ */
202
+ exclude?: string | string[]
203
+
204
+ /**
205
+ * 如果文件内容仅包含 'export {}' 则跳过生成
206
+ *
207
+ * @default true
208
+ */
209
+ clearPureImport?: boolean
210
+
211
+ /**
212
+ * 是否生成类型声明入口
213
+ *
214
+ * 当为 true 时会基于 package.json 的 types 字段生成,或者 `${outputDir}/index.d.ts`
215
+ *
216
+ * 当开启打包类型文件时强制为 true
217
+ *
218
+ * @default false
219
+ */
220
+ insertTypesEntry?: boolean
221
+
222
+ /**
223
+ * 设置是否在发出类型文件后将其打包
224
+ *
225
+ * 基于 `@microsoft/api-extractor`,由于这开启了一个新的进程,将会消耗一些时间
226
+ *
227
+ * @default false
228
+ */
229
+ rollupTypes?: boolean
230
+
231
+ /**
232
+ * 是否将源码里的 .d.ts 文件复制到 outputDir
233
+ *
234
+ * @default false
235
+ * @remarks 在 2.0 之前它默认为 true
236
+ */
237
+ copyDtsFiles?: boolean
238
+
239
+ /**
240
+ * 出现类型诊断信息时不生成类型文件
241
+ *
242
+ * @default false
243
+ */
244
+ noEmitOnError?: boolean
245
+
246
+ /**
247
+ * 是否跳过类型诊断
248
+ *
249
+ * 跳过类型诊断意味着出现错误时不会中断打包进程的执行
250
+ *
251
+ * 但对于出现错误的源文件,将无法生成相应的类型文件
252
+ *
253
+ * @default false
254
+ * @remarks 在 1.7 之前它默认为 true
255
+ */
256
+ skipDiagnostics?: boolean
257
+
258
+ /**
259
+ * 定制 typescript 的 lib 文件夹路径
260
+ *
261
+ * 应传入一个 root 的相对路径或一个绝对路径
262
+ *
263
+ * @default undefined
264
+ */
265
+ libFolderPath?: string
266
+
267
+ /**
268
+ * 指定插件的输出等级
269
+ *
270
+ * 默认基于 vite 配置的 'logLevel' 选项
271
+ */
272
+ logLevel?: LogLevel
273
+
274
+ /**
275
+ * 获取诊断信息后的钩子
276
+ *
277
+ * 可以根据参数 length 来判断有误类型错误
278
+ *
279
+ * @default () => {}
280
+ */
281
+ afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
282
+
283
+ /**
284
+ * 类型声明文件被写入前的钩子
285
+ *
286
+ * 可以在钩子里转换文件路径和文件内容
287
+ *
288
+ * 当返回 false 时会跳过该文件
289
+ *
290
+ * @default () => {}
291
+ */
292
+ beforeWriteFile?: (filePath: string, content: string) => void | false | TransformWriteFile
293
+
294
+ /**
295
+ * 构建后回调钩子
296
+ *
297
+ * 将会在所有类型文件被写入后调用
298
+ *
299
+ * @default () => {}
300
+ */
301
+ afterBuild?: () => void | Promise<void>
302
+ }
303
+ ```
304
+
305
+ ## 贡献者
306
+
307
+ 感谢他们的所做的一切贡献!
308
+
309
+ <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
310
+ <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" />
311
+ </a>
312
+
313
+ ## 示例
314
+
315
+ 克隆项目然后执行下列命令:
316
+
317
+ ```sh
318
+ pnpm run test:ts
319
+ ```
320
+
321
+ 然后检查 `examples/ts/types` 目录。
322
+
323
+ ## 授权
324
+
325
+ MIT 授权。
package/dist/index.cjs CHANGED
@@ -8,9 +8,9 @@ const glob = require('fast-glob');
8
8
  const debug = require('debug');
9
9
  const tsMorph = require('ts-morph');
10
10
  const vite = require('vite');
11
- const typescript = require('typescript');
12
11
  const pluginutils = require('@rollup/pluginutils');
13
12
  const node_fs = require('node:fs');
13
+ const typescript = require('typescript');
14
14
  const node_module = require('node:module');
15
15
  const parser = require('@babel/parser');
16
16
  const MagicString = require('magic-string');
@@ -143,6 +143,25 @@ function removeDirIfEmpty(dir) {
143
143
  }
144
144
  return onlyHasDir;
145
145
  }
146
+ function getTsConfig(tsConfigPath, readFileSync) {
147
+ const tsConfig = {
148
+ compilerOptions: {},
149
+ ...typescript.readConfigFile(tsConfigPath, readFileSync).config ?? {}
150
+ };
151
+ if (tsConfig.extends) {
152
+ ensureArray(tsConfig.extends).forEach((configPath) => {
153
+ const config = getTsConfig(ensureAbsolute(configPath, node_path.dirname(tsConfigPath)), readFileSync);
154
+ Object.assign(tsConfig.compilerOptions, config.compilerOptions);
155
+ if (!tsConfig.include) {
156
+ tsConfig.include = config.include;
157
+ }
158
+ if (!tsConfig.exclude) {
159
+ tsConfig.exclude = config.exclude;
160
+ }
161
+ });
162
+ }
163
+ return tsConfig;
164
+ }
146
165
 
147
166
  const globSuffixRE = /^((?:.*\.[^.]+)|(?:\*+))$/;
148
167
  function normalizeGlob(path) {
@@ -243,7 +262,7 @@ function transferSetupPosition(content) {
243
262
  }
244
263
 
245
264
  const noScriptContent = "import { defineComponent } from 'vue'\nexport default defineComponent({})";
246
- const _require = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
265
+ const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
247
266
  let index = 1;
248
267
  let compileRoot = null;
249
268
  let compiler;
@@ -757,20 +776,7 @@ ${kolorist.cyan(
757
776
  libFolderPath
758
777
  });
759
778
  allowJs = project.getCompilerOptions().allowJs ?? false;
760
- const tsConfig = { compilerOptions: {} };
761
- const readFile = project.getFileSystem().readFileSync;
762
- let currentConfigPath = tsConfigPath;
763
- while (currentConfigPath) {
764
- const currentConfig = typescript.readConfigFile(currentConfigPath, readFile).config ?? {};
765
- Object.assign(tsConfig.compilerOptions, currentConfig.compilerOptions || {});
766
- if (!tsConfig.include) {
767
- tsConfig.include = currentConfig.include;
768
- }
769
- if (!tsConfig.exclude) {
770
- tsConfig.exclude = currentConfig.exclude;
771
- }
772
- currentConfigPath = currentConfig.extends && ensureAbsolute(currentConfig.extends, node_path.dirname(currentConfigPath));
773
- }
779
+ const tsConfig = getTsConfig(tsConfigPath, project.getFileSystem().readFileSync);
774
780
  include = ensureArray(options.include ?? tsConfig.include ?? "**/*").map(normalizeGlob);
775
781
  exclude = ensureArray(options.exclude ?? tsConfig.exclude ?? "node_modules/**").map(
776
782
  normalizeGlob
package/dist/index.mjs CHANGED
@@ -13,9 +13,9 @@ import glob from 'fast-glob';
13
13
  import debug from 'debug';
14
14
  import { Project } from 'ts-morph';
15
15
  import { normalizePath, createLogger } from 'vite';
16
- import typescript from 'typescript';
17
16
  import { createFilter } from '@rollup/pluginutils';
18
17
  import { existsSync, readdirSync, lstatSync, rmdirSync } from 'node:fs';
18
+ import typescript from 'typescript';
19
19
  import { createRequire } from 'node:module';
20
20
  import { parse } from '@babel/parser';
21
21
  import MagicString from 'magic-string';
@@ -148,6 +148,25 @@ function removeDirIfEmpty(dir) {
148
148
  }
149
149
  return onlyHasDir;
150
150
  }
151
+ function getTsConfig(tsConfigPath, readFileSync) {
152
+ const tsConfig = {
153
+ compilerOptions: {},
154
+ ...typescript.readConfigFile(tsConfigPath, readFileSync).config ?? {}
155
+ };
156
+ if (tsConfig.extends) {
157
+ ensureArray(tsConfig.extends).forEach((configPath) => {
158
+ const config = getTsConfig(ensureAbsolute(configPath, dirname(tsConfigPath)), readFileSync);
159
+ Object.assign(tsConfig.compilerOptions, config.compilerOptions);
160
+ if (!tsConfig.include) {
161
+ tsConfig.include = config.include;
162
+ }
163
+ if (!tsConfig.exclude) {
164
+ tsConfig.exclude = config.exclude;
165
+ }
166
+ });
167
+ }
168
+ return tsConfig;
169
+ }
151
170
 
152
171
  const globSuffixRE = /^((?:.*\.[^.]+)|(?:\*+))$/;
153
172
  function normalizeGlob(path) {
@@ -762,20 +781,7 @@ ${cyan(
762
781
  libFolderPath
763
782
  });
764
783
  allowJs = project.getCompilerOptions().allowJs ?? false;
765
- const tsConfig = { compilerOptions: {} };
766
- const readFile = project.getFileSystem().readFileSync;
767
- let currentConfigPath = tsConfigPath;
768
- while (currentConfigPath) {
769
- const currentConfig = typescript.readConfigFile(currentConfigPath, readFile).config ?? {};
770
- Object.assign(tsConfig.compilerOptions, currentConfig.compilerOptions || {});
771
- if (!tsConfig.include) {
772
- tsConfig.include = currentConfig.include;
773
- }
774
- if (!tsConfig.exclude) {
775
- tsConfig.exclude = currentConfig.exclude;
776
- }
777
- currentConfigPath = currentConfig.extends && ensureAbsolute(currentConfig.extends, dirname(currentConfigPath));
778
- }
784
+ const tsConfig = getTsConfig(tsConfigPath, project.getFileSystem().readFileSync);
779
785
  include = ensureArray(options.include ?? tsConfig.include ?? "**/*").map(normalizeGlob);
780
786
  exclude = ensureArray(options.exclude ?? tsConfig.exclude ?? "node_modules/**").map(
781
787
  normalizeGlob
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",
@@ -54,54 +54,54 @@
54
54
  "typescript"
55
55
  ],
56
56
  "dependencies": {
57
- "@babel/parser": "^7.20.15",
58
- "@microsoft/api-extractor": "^7.33.5",
57
+ "@babel/parser": "^7.21.4",
58
+ "@microsoft/api-extractor": "^7.34.4",
59
59
  "@rollup/pluginutils": "^5.0.2",
60
- "@rushstack/node-core-library": "^3.53.2",
60
+ "@rushstack/node-core-library": "^3.55.2",
61
61
  "debug": "^4.3.4",
62
62
  "fast-glob": "^3.2.12",
63
63
  "fs-extra": "^10.1.0",
64
- "kolorist": "^1.6.0",
64
+ "kolorist": "^1.7.0",
65
65
  "magic-string": "^0.29.0",
66
- "ts-morph": "17.0.1"
66
+ "ts-morph": "18.0.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@babel/types": "^7.20.7",
70
- "@commitlint/cli": "^17.1.2",
71
- "@commitlint/config-conventional": "^17.1.0",
69
+ "@babel/types": "^7.21.4",
70
+ "@commitlint/cli": "^17.6.1",
71
+ "@commitlint/config-conventional": "^17.6.1",
72
72
  "@types/debug": "^4.1.7",
73
73
  "@types/fs-extra": "^9.0.13",
74
74
  "@types/minimist": "^1.2.2",
75
- "@types/node": "^18.11.7",
76
- "@types/prompts": "^2.4.1",
75
+ "@types/node": "^18.15.11",
76
+ "@types/prompts": "^2.4.4",
77
77
  "@types/semver": "^7.3.13",
78
- "@typescript-eslint/eslint-plugin": "^5.41.0",
79
- "@typescript-eslint/parser": "^5.41.0",
78
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
79
+ "@typescript-eslint/parser": "^5.58.0",
80
80
  "@vue/eslint-config-standard": "^8.0.1",
81
81
  "@vue/eslint-config-typescript": "^11.0.2",
82
82
  "conventional-changelog-cli": "^2.2.2",
83
83
  "cross-env": "^7.0.3",
84
- "eslint": "^8.26.0",
85
- "eslint-plugin-import": "^2.26.0",
84
+ "eslint": "^8.38.0",
85
+ "eslint-plugin-import": "^2.27.5",
86
86
  "eslint-plugin-node": "^11.1.0",
87
87
  "eslint-plugin-promise": "^6.1.1",
88
- "eslint-plugin-vue": "^9.6.0",
88
+ "eslint-plugin-vue": "^9.10.0",
89
89
  "execa": "^6.1.0",
90
- "husky": "^8.0.1",
90
+ "husky": "^8.0.3",
91
91
  "is-ci": "^3.0.1",
92
- "lint-staged": "^13.0.3",
93
- "minimist": "^1.2.7",
92
+ "lint-staged": "^13.2.1",
93
+ "minimist": "^1.2.8",
94
94
  "pinst": "^3.0.0",
95
- "prettier": "^2.7.1",
95
+ "prettier": "^2.8.7",
96
96
  "pretty-quick": "^3.1.3",
97
97
  "prompts": "^2.4.2",
98
98
  "rimraf": "^3.0.2",
99
- "semver": "^7.3.8",
100
- "tsx": "^3.11.0",
101
- "typescript": "4.8.4",
99
+ "semver": "^7.4.0",
100
+ "tsx": "^3.12.6",
101
+ "typescript": "^5.0.4",
102
102
  "unbuild": "^0.9.4",
103
- "vite": "^3.2.1",
104
- "vitest": "^0.24.3",
103
+ "vite": "^3.2.5",
104
+ "vitest": "^0.24.5",
105
105
  "vue": "3.2.41"
106
106
  },
107
107
  "peerDependencies": {