@depup/vite-plugin-dts 4.5.4-depup.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-present qmhc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @depup/vite-plugin-dts
2
+
3
+ > Dependency-bumped version of [vite-plugin-dts](https://www.npmjs.com/package/vite-plugin-dts)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/vite-plugin-dts
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [vite-plugin-dts](https://www.npmjs.com/package/vite-plugin-dts) @ 4.5.4 |
17
+ | Processed | 2026-03-22 |
18
+ | Smoke test | failed |
19
+ | Deps updated | 7 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | @microsoft/api-extractor | ^7.50.1 | ^7.57.7 |
26
+ | @rollup/pluginutils | ^5.1.4 | ^5.3.0 |
27
+ | @volar/typescript | ^2.4.11 | ^2.4.28 |
28
+ | @vue/language-core | 2.2.0 | ^3.2.6 |
29
+ | debug | ^4.4.0 | ^4.4.3 |
30
+ | local-pkg | ^1.0.0 | ^1.1.2 |
31
+ | magic-string | ^0.30.17 | ^0.30.21 |
32
+
33
+ ---
34
+
35
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/vite-plugin-dts
36
+
37
+ License inherited from the original package.
@@ -0,0 +1,417 @@
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
+ <a href="https://github.com/qmhc/vite-plugin-dts/blob/main/LICENSE">
12
+ <img src="https://img.shields.io/npm/l/vite-plugin-dts" alt="license" />
13
+ </a>
14
+ </p>
15
+
16
+ **中文** | [English](./README.md)
17
+
18
+ ## 安装
19
+
20
+ ```sh
21
+ pnpm i vite-plugin-dts -D
22
+ ```
23
+
24
+ ## 使用
25
+
26
+ 在 `vite.config.ts`:
27
+
28
+ ```ts
29
+ import { resolve } from 'path'
30
+ import { defineConfig } from 'vite'
31
+ import dts from 'vite-plugin-dts'
32
+
33
+ export default defineConfig({
34
+ build: {
35
+ lib: {
36
+ entry: resolve(__dirname, 'src/index.ts'),
37
+ name: 'MyLib',
38
+ formats: ['es'],
39
+ fileName: 'my-lib'
40
+ }
41
+ },
42
+ plugins: [dts()]
43
+ })
44
+ ```
45
+
46
+ 默认情况,生成的类型文件会跟随源文件的结构。
47
+
48
+ 如果你希望将所有的类型合并到一个文件中,只需指定 `rollupTypes: true`:
49
+
50
+ ```ts
51
+ {
52
+ plugins: [dts({ rollupTypes: true })]
53
+ }
54
+ ```
55
+
56
+ 如果你从 Vite 官方模板开始,你应该指定 `tsconfigPath`:
57
+
58
+ ```ts
59
+ {
60
+ plugins: [dts({ tsconfigPath: './tsconfig.app.json' })]
61
+ }
62
+ ```
63
+
64
+ 从 `3.0.0` 开始,你可以在 Rollup 中使用该插件。
65
+
66
+ ## 常见问题
67
+
68
+ 此处将收录一些常见的问题并提供一些解决方案。
69
+
70
+ ### 打包时出现了无法从 `node_modules` 的包中推断类型的错误
71
+
72
+ 这是 TypeScript 通过软链接 (pnpm) 读取 `node_modules` 中过的类型时会出现的一个已知的问题,可以参考这个 [issue](https://github.com/microsoft/TypeScript/issues/42873),目前已有的一个解决方案,在你的 `tsconfig.json` 中添加 `baseUrl` 以及在 `paths` 添加这些包的路径:
73
+
74
+ ```json
75
+ {
76
+ "compilerOptions": {
77
+ "baseUrl": ".",
78
+ "paths": {
79
+ "third-lib": ["node_modules/third-lib"]
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ ### 在 `rollupTypes: true` 时出现 `Internal Error`
86
+
87
+ 参考这个 [issue](https://github.com/microsoft/rushstack/issues/3875),这是由于 `@microsoft/api-extractor` 或者是 TypeScript 解析器的一些限制导致的。
88
+
89
+ 主要原因在于 `tsconfig.json` 中指定了 `baseUrl` 并且在引入时直接使用非标准路径。
90
+
91
+ 例如:指定了 `baseUrl: 'src'` 并且在 `<root>/src/index.ts` 中引入 `<root>/src/components/index.ts` 时使用了 `import 'components'` 而不是 `import './components'`。
92
+
93
+ 目前想要正常打包,需要规避上述情况,或使用别名代替(配合 `paths` 属性)。
94
+
95
+ ### 打包时出现找不到模块的错误
96
+
97
+ 这很有可能是因为在你的默认 `tsconfig.json` 中未有正确配置 `include` 导致的。
98
+
99
+ 由于一些局限性,插件依赖最上层的 `tsconfig.json` 来解析需要包含的文件,所以你需要在最上层的 `tsconfig.json` 中指定正确的 `include`,或者通过插件的 `tsconfigPath` 选项指定一个包含了正确 `include` 的配置文件路径,例如在 Vite 初始模板中它是 `tsconfig.app.json`。
100
+
101
+ 可以参考这个 [评论](https://github.com/qmhc/vite-plugin-dts/issues/343#issuecomment-2198111439).
102
+
103
+ <details>
104
+ <summary>过时的</summary>
105
+
106
+ ### 打包后出现类型文件缺失 (`1.7.0` 之前)
107
+
108
+ 默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。
109
+
110
+ 如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
111
+
112
+ ### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误(`3.0.0` 之前)
113
+
114
+ 这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
115
+
116
+ 这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。
117
+
118
+ </details>
119
+
120
+ ## 选项
121
+
122
+ ```ts
123
+ import type ts from 'typescript'
124
+ import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
125
+ import type { LogLevel } from 'vite'
126
+
127
+ type MaybePromise<T> = T | Promise<T>
128
+
129
+ export type RollupConfig = Omit<
130
+ IExtractorConfigPrepareOptions['configObject'],
131
+ | 'projectFolder'
132
+ | 'mainEntryPointFilePath'
133
+ | 'compiler'
134
+ | 'dtsRollup'
135
+ >
136
+
137
+ export interface Resolver {
138
+ /**
139
+ * 解析器的名称
140
+ *
141
+ * 靠后的同名解析器将会覆盖靠前的
142
+ */
143
+ name: string,
144
+ /**
145
+ * 判断解析器是否支持该文件
146
+ */
147
+ supports: (id: string) => void | boolean,
148
+ /**
149
+ * 将源文件转换为类型文件
150
+ *
151
+ * 注意,返回的文件的路径应该基于 `outDir`,或者相对于 `root`
152
+ */
153
+ transform: (payload: {
154
+ id: string,
155
+ code: string,
156
+ root: string,
157
+ outDir: string,
158
+ host: ts.CompilerHost,
159
+ program: ts.Program,
160
+ }) => MaybePromise<{ path: string, content: string }[]>
161
+ }
162
+
163
+ export interface PluginOptions {
164
+ /**
165
+ * 指定根目录
166
+ *
167
+ * 默认为 Vite 配置的 'root',使用 Rollup 为 `process.cwd()`
168
+ */
169
+ root?: string,
170
+
171
+ /**
172
+ * 指定输出目录
173
+ *
174
+ * 可以指定一个数组来输出到多个目录中
175
+ *
176
+ * 默认为 Vite 配置的 'build.outDir',使用 Rollup 时为 tsconfig.json 的 `outDir`
177
+ */
178
+ outDir?: string | string[],
179
+
180
+ /**
181
+ * 用于手动设置入口文件的根路径(通常用在 monorepo)
182
+ *
183
+ * 在计算每个文件的输出路径时将基于该路径
184
+ *
185
+ * 默认为所有源文件的最小公共路径
186
+ */
187
+ entryRoot?: string,
188
+
189
+ /**
190
+ * 限制类型文件生成在 `outDir` 内
191
+ *
192
+ * 如果为 `true`,生成在 `outDir` 外的文件将被忽略
193
+ *
194
+ * @default true
195
+ */
196
+ strictOutput?: boolean,
197
+
198
+ /**
199
+ * 覆写 CompilerOptions
200
+ *
201
+ * @default null
202
+ */
203
+ compilerOptions?: ts.CompilerOptions | null,
204
+
205
+ /**
206
+ * 指定 tsconfig.json 的路径
207
+ *
208
+ * 插件会解析 tsconfig.json 的 include 和 exclude 选项
209
+ *
210
+ * 未指定时插件默认从根目录开始寻找配置文件
211
+ */
212
+ tsconfigPath?: string,
213
+
214
+ /**
215
+ * 指定自定义的解析器
216
+ *
217
+ * @default []
218
+ */
219
+ resolvers?: Resolver[],
220
+
221
+ /**
222
+ * 解析 tsconfig.json 的 `paths` 作为别名
223
+ *
224
+ * 注意,这些别名仅用在类型文件中使用
225
+ *
226
+ * @default true
227
+ * @remarks 只使用每个路径的第一个替换
228
+ */
229
+ pathsToAliases?: boolean,
230
+
231
+ /**
232
+ * 设置在转换别名时哪些路径需要排除
233
+ *
234
+ * @default []
235
+ */
236
+ aliasesExclude?: (string | RegExp)[],
237
+
238
+ /**
239
+ * 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
240
+ *
241
+ * 如果转换后出现重名,将会回退到原来的名字。
242
+ *
243
+ * @default false
244
+ */
245
+ cleanVueFileName?: boolean,
246
+
247
+ /**
248
+ * 是否将动态引入转换为静态(例如:`import('vue').DefineComponent` 转换为 `import { DefineComponent } from 'vue'`)
249
+ *
250
+ * 开启 `rollupTypes` 时强制为 `true`
251
+ *
252
+ * @default false
253
+ */
254
+ staticImport?: boolean,
255
+
256
+ /**
257
+ * 手动设置包含路径的 glob(相对于 root)
258
+ *
259
+ * 默认基于 tsconfig.json 的 `include` 选项(相对于 tsconfig.json 所在目录)
260
+ */
261
+ include?: string | string[],
262
+
263
+ /**
264
+ * 手动设置排除路径的 glob
265
+ *
266
+ * 默认基于 tsconfig.json 的 `exclude` 选线,未设置时为 `'node_modules/**'`
267
+ */
268
+ exclude?: string | string[],
269
+
270
+ /**
271
+ * 是否移除 `import 'xxx'`
272
+ *
273
+ * @default true
274
+ */
275
+ clearPureImport?: boolean,
276
+
277
+ /**
278
+ * 是否生成类型入口文件
279
+ *
280
+ * 当为 `true` 时会基于 package.json 的 `types` 字段生成,或者 `${outDir}/index.d.ts`
281
+ *
282
+ * 当开启 `rollupTypes` 时强制为 `true`
283
+ *
284
+ * @default false
285
+ */
286
+ insertTypesEntry?: boolean,
287
+
288
+ /**
289
+ * 设置是否将发出的类型文件打包进单个文件
290
+ *
291
+ * 基于 `@microsoft/api-extractor`,过程将会消耗一些时间
292
+ *
293
+ * @default false
294
+ */
295
+ rollupTypes?: boolean,
296
+
297
+ /**
298
+ * 设置 `@microsoft/api-extractor` 的 `bundledPackages` 选项
299
+ *
300
+ * @default []
301
+ * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
302
+ */
303
+ bundledPackages?: string[],
304
+
305
+ /**
306
+ * 覆写 `@microsoft/api-extractor` 的配置
307
+ *
308
+ * @default null
309
+ * @see https://api-extractor.com/pages/setup/configure_api_report/
310
+ */
311
+ rollupConfig?: RollupConfig,
312
+
313
+ /**
314
+ * 覆写 `@microsoft/api-extractor` 的调用选项
315
+ *
316
+ * @default null
317
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
318
+ */
319
+ rollupOptions?: IExtractorInvokeOptions,
320
+
321
+ /**
322
+ * 是否将源码里的 .d.ts 文件复制到 `outDir`
323
+ *
324
+ * @default false
325
+ * @remarks 在 2.0 之前它默认为 `true`
326
+ */
327
+ copyDtsFiles?: boolean,
328
+
329
+ /**
330
+ * 是否只生成类型文件
331
+ *
332
+ * 当为 `true` 时会强制删除所有 Vite(Rollup)的原始产物
333
+ *
334
+ * @default false
335
+ */
336
+ declarationOnly?: boolean,
337
+
338
+ /**
339
+ * 指定插件的输出等级
340
+ *
341
+ * 默认基于 Vite 配置的 'logLevel' 选项
342
+ */
343
+ logLevel?: LogLevel,
344
+
345
+ /**
346
+ * 获取诊断信息后的钩子
347
+ *
348
+ * 可以根据 `diagnostics.length` 来判断有误类型错误
349
+ *
350
+ * @default () => {}
351
+ */
352
+ afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>,
353
+
354
+ /**
355
+ * 类型声明文件被写入前的钩子
356
+ *
357
+ * 可以在钩子里转换文件路径和文件内容
358
+ *
359
+ * 当返回 `false` 或 `Promise<false>` 时会跳过该文件
360
+ *
361
+ * @default () => {}
362
+ */
363
+ beforeWriteFile?: (
364
+ filePath: string,
365
+ content: string
366
+ ) => MaybePromise<
367
+ | void
368
+ | false
369
+ | {
370
+ filePath?: string,
371
+ content?: string
372
+ }
373
+ >,
374
+
375
+ /**
376
+ * 类型文件被打包进单个文件后的钩子
377
+ *
378
+ * @default () => {}
379
+ */
380
+ afterRollup?: (result: ExtractorResult) => MaybePromise<void>,
381
+
382
+ /**
383
+ * 在所有类型文件被写入后的钩子
384
+ *
385
+ * 它会接收一个记录了那些最终被写入的文件的映射(path -> content)
386
+ *
387
+ * @default () => {}
388
+ */
389
+ afterBuild?: (emittedFiles: Map<string, string>) => MaybePromise<void>
390
+ }
391
+ ```
392
+
393
+ ## 贡献者
394
+
395
+ 感谢他们的所做的一切贡献!
396
+
397
+ <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
398
+ <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" alt="contributors" />
399
+ </a>
400
+
401
+ ## 示例
402
+
403
+ 克隆项目然后执行下列命令:
404
+
405
+ ```sh
406
+ pnpm run test:ts
407
+ ```
408
+
409
+ 然后检查 `examples/ts/types` 目录。
410
+
411
+ `examples` 目录下同样有 Vue 和 React 的案例。
412
+
413
+ 一个使用该插件的真实项目:[Vexip UI](https://github.com/vexip-ui/vexip-ui)。
414
+
415
+ ## 授权
416
+
417
+ MIT 授权。
package/changes.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "bumped": {
3
+ "@microsoft/api-extractor": {
4
+ "from": "^7.50.1",
5
+ "to": "^7.57.7"
6
+ },
7
+ "@rollup/pluginutils": {
8
+ "from": "^5.1.4",
9
+ "to": "^5.3.0"
10
+ },
11
+ "@volar/typescript": {
12
+ "from": "^2.4.11",
13
+ "to": "^2.4.28"
14
+ },
15
+ "@vue/language-core": {
16
+ "from": "2.2.0",
17
+ "to": "^3.2.6"
18
+ },
19
+ "debug": {
20
+ "from": "^4.4.0",
21
+ "to": "^4.4.3"
22
+ },
23
+ "local-pkg": {
24
+ "from": "^1.0.0",
25
+ "to": "^1.1.2"
26
+ },
27
+ "magic-string": {
28
+ "from": "^0.30.17",
29
+ "to": "^0.30.21"
30
+ }
31
+ },
32
+ "timestamp": "2026-03-22T00:41:17.731Z",
33
+ "totalUpdated": 7
34
+ }