vite-plugin-dts 3.1.1 → 3.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
@@ -97,11 +97,14 @@ export interface Resolver {
97
97
  supports: (id: string) => void | boolean,
98
98
  /**
99
99
  * Transform source to declaration files
100
+ *
101
+ * Note that the path of the returns should base on `outDir`, or relative path to `root`
100
102
  */
101
103
  transform: (payload: {
102
104
  id: string,
103
105
  code: string,
104
106
  root: string,
107
+ outDir: string,
105
108
  host: ts.CompilerHost,
106
109
  program: ts.Program,
107
110
  service: ts.LanguageService
@@ -166,6 +169,16 @@ export interface PluginOptions {
166
169
  */
167
170
  resolvers?: Resolver[],
168
171
 
172
+ /**
173
+ * Parsing `paths` of tsconfig.json to aliases
174
+ *
175
+ * Note that these aliases only use for declaration files
176
+ *
177
+ * @default true
178
+ * @remarks Only use first replacement of each path
179
+ */
180
+ pathsToAliases?: boolean,
181
+
169
182
  /**
170
183
  * Set which paths should be excluded when transforming aliases
171
184
  *
@@ -267,20 +280,21 @@ export interface PluginOptions {
267
280
  *
268
281
  * This allows you to transform the path or content
269
282
  *
270
- * The file will be skipped when the return value `false`
283
+ * The file will be skipped when the return value `false` or `Promise<false>`
271
284
  *
272
285
  * @default () => {}
273
286
  */
274
287
  beforeWriteFile?: (
275
288
  filePath: string,
276
289
  content: string
277
- ) =>
278
- | void
279
- | false
280
- | {
281
- filePath?: string,
282
- content?: string
283
- },
290
+ ) => MaybePromise<
291
+ | void
292
+ | false
293
+ | {
294
+ filePath?: string,
295
+ content?: string
296
+ }
297
+ >,
284
298
 
285
299
  /**
286
300
  * Hook called after all declaration files are written
package/README.zh-CN.md CHANGED
@@ -97,11 +97,14 @@ export interface Resolver {
97
97
  supports: (id: string) => void | boolean,
98
98
  /**
99
99
  * 将源文件转换为类型文件
100
+ *
101
+ * 注意,返回的文件的路径应该基于 `outDir`,或者相对于 `root`
100
102
  */
101
103
  transform: (payload: {
102
104
  id: string,
103
105
  code: string,
104
106
  root: string,
107
+ outDir: string,
105
108
  host: ts.CompilerHost,
106
109
  program: ts.Program,
107
110
  service: ts.LanguageService
@@ -166,6 +169,16 @@ export interface PluginOptions {
166
169
  */
167
170
  resolvers?: Resolver[],
168
171
 
172
+ /**
173
+ * 解析 tsconfig.json 的 `paths` 作为别名
174
+ *
175
+ * 注意,这些别名仅用在类型文件中使用
176
+ *
177
+ * @default true
178
+ * @remarks 只使用每个路径的第一个替换
179
+ */
180
+ pathsToAliases?: boolean,
181
+
169
182
  /**
170
183
  * 设置在转换别名时哪些路径需要排除
171
184
  *
@@ -267,20 +280,21 @@ export interface PluginOptions {
267
280
  *
268
281
  * 可以在钩子里转换文件路径和文件内容
269
282
  *
270
- * 当返回 `false` 时会跳过该文件
283
+ * 当返回 `false` 或 `Promise<false>` 时会跳过该文件
271
284
  *
272
285
  * @default () => {}
273
286
  */
274
287
  beforeWriteFile?: (
275
288
  filePath: string,
276
289
  content: string
277
- ) =>
278
- | void
279
- | false
280
- | {
281
- filePath?: string,
282
- content?: string
283
- },
290
+ ) => MaybePromise<
291
+ | void
292
+ | false
293
+ | {
294
+ filePath?: string,
295
+ content?: string
296
+ }
297
+ >,
284
298
 
285
299
  /**
286
300
  * 在所有类型文件被写入后调用的钩子