vite-plugin-dts 2.3.0 → 3.0.0-beta.2

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
@@ -1,7 +1,7 @@
1
1
  <h1 align="center">vite-plugin-dts</h1>
2
2
 
3
3
  <p align="center">
4
- A vite plugin that generates declaration files (<code>*.d.ts</code>) from <code>.ts(x)</code> or <code>.vue</code> source files when using vite in <a href="https://vitejs.dev/guide/build.html#library-mode">library mode</a>.
4
+ A Vite plugin that generates declaration files (<code>*.d.ts</code>) from <code>.ts(x)</code> or <code>.vue</code> source files when using Vite in <a href="https://vitejs.dev/guide/build.html#library-mode">library mode</a>.
5
5
  </p>
6
6
 
7
7
  <p align="center">
@@ -10,13 +10,7 @@
10
10
  </a>
11
11
  </p>
12
12
 
13
- <p align="center">
14
- <strong>English</strong> | <a href="./README.zh-CN.md">中文</a>
15
- </p>
16
-
17
- <p align="center"><strong>Notice: </strong><code>skipDiagnostics</code> option default to <code>false</code> since 1.7.0.</p>
18
-
19
- <br />
13
+ **English** | [中文](./README.zh-CN.md)
20
14
 
21
15
  ## Install
22
16
 
@@ -87,7 +81,7 @@ By default, the `skipDiagnostics` option is set to `true` which means type diagn
87
81
 
88
82
  If your project doesn't use type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on diagnostic and logging features of this plugin. It will help you check the type errors during build and log error information to the terminal.
89
83
 
90
- ### Type error when using both `script` and `setup-script` in Vue component
84
+ ### Type error when using both `script` and `setup-script` in Vue component (before `3.0.0`)
91
85
 
92
86
  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
87
 
@@ -111,7 +105,7 @@ This is an existing issue when TypeScript infers types from packages located in
111
105
  ## Options
112
106
 
113
107
  ```ts
114
- import type { ts, Diagnostic } from 'ts-morph'
108
+ import type ts from 'typescript'
115
109
  import type { LogLevel } from 'vite'
116
110
 
117
111
  interface TransformWriteFile {
@@ -121,107 +115,105 @@ interface TransformWriteFile {
121
115
 
122
116
  export interface PluginOptions {
123
117
  /**
124
- * Depends on the root directory
118
+ * Specify root directory
125
119
  *
126
- * Defaults to 'root' property in your vite config
120
+ * By Default it base on 'root' of your Vite config, or `process.cwd()` if using Rollup
127
121
  */
128
122
  root?: string
129
123
 
130
124
  /**
131
- * Declaration files output directory
125
+ * Specify declaration files output directory
132
126
  *
133
- * Supports arrays to output to multiple directories
127
+ * Can be specified a array to output to multiple directories
134
128
  *
135
- * Defaults to 'build.outDir' property in your vite config
129
+ * By Default it base on 'build.outDir' of your Vite config, or `outDir` of tsconfig.json if using Rollup
136
130
  */
137
- outputDir?: string | string[]
131
+ outDir?: string | string[]
138
132
 
139
133
  /**
140
- * Manually sets the root path of entry files
134
+ * Manually set the root path of the entry files, useful in monorepo
141
135
  *
142
- * The output path of each file will be calculated based on it
136
+ * The output path of each file will be calculated base on it
143
137
  *
144
- * Defaults to the shortest public path for all files
138
+ * By Default it is the smallest public path for all files
145
139
  */
146
140
  entryRoot?: string
147
141
 
148
142
  /**
149
- * Project init compilerOptions using by ts-morph
143
+ * Specify a CompilerOptions to override
150
144
  *
151
145
  * @default null
152
146
  */
153
147
  compilerOptions?: ts.CompilerOptions | null
154
148
 
155
149
  /**
156
- * Project init tsconfig.json file path by ts-morph
150
+ * Specify tsconfig.json path
157
151
  *
158
- * Plugin also resolves include and exclude files from tsconfig.json
152
+ * Plugin also resolve include and exclude files from tsconfig.json
159
153
  *
160
- * @default 'tsconfig.json'
154
+ * By default plugin will find config form root if not specify
161
155
  */
162
- tsConfigFilePath?: string
156
+ tsconfigPath?: string
163
157
 
164
158
  /**
165
159
  * Set which paths should exclude when transform aliases
166
160
  *
167
- * If a regular expression, it will test the original import path directly
168
- *
169
161
  * @default []
170
162
  */
171
163
  aliasesExclude?: (string | RegExp)[]
172
164
 
173
165
  /**
174
- * Whether tp transform file name '.vue.d.ts' to '.d.ts'
166
+ * Whether transform file name '.vue.d.ts' to '.d.ts'
175
167
  *
176
168
  * @default false
177
169
  */
178
170
  cleanVueFileName?: boolean
179
171
 
180
172
  /**
181
- * Whether to transform dynamic imports to static
173
+ * Whether transform dynamic import to static
182
174
  *
183
- * Force true when `rollupTypes` is effective
175
+ * Force `true` when `rollupTypes` is effective
184
176
  *
185
- * eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
177
+ * eg. `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`
186
178
  *
187
179
  * @default false
188
180
  */
189
181
  staticImport?: boolean
190
182
 
191
183
  /**
192
- * Specify a glob of files to include
184
+ * Manual set include glob
193
185
  *
194
- * Defaults to 'include' property of the tsconfig.json
186
+ * By Default it base on 'include' option of the tsconfig.json
195
187
  */
196
188
  include?: string | string[]
197
189
 
198
190
  /**
199
- * Specify a glob of files to exclude
191
+ * Manual set exclude glob
200
192
  *
201
- * Defaults to 'exclude' property of tsconfig.json and 'node_module/**' when empty
193
+ * By Default it base on 'exclude' option of the tsconfig.json, be 'node_module/**' when empty
202
194
  */
203
195
  exclude?: string | string[]
204
196
 
205
197
  /**
206
- * Do not emit if content of file only includes 'export {}'
198
+ * Whether remove those `import 'xxx'`
207
199
  *
208
200
  * @default true
209
201
  */
210
202
  clearPureImport?: boolean
211
203
 
212
204
  /**
213
- * Whether to generate types entry file
205
+ * Whether generate types entry file
214
206
  *
215
- * When set to true, will add package.json `types` property to `${outputDir}/index.d.ts`
207
+ * When `true` will from package.json types field if exists or `${outDir}/index.d.ts`
216
208
  *
217
- * Force true when `rollupTypes` is set
209
+ * Force `true` when `rollupTypes` is effective
218
210
  *
219
211
  * @default false
220
212
  */
221
213
  insertTypesEntry?: boolean
222
214
 
223
215
  /**
224
- * Set to rollup declaration files after emit
216
+ * Set whether rollup declaration files after emit
225
217
  *
226
218
  * Power by `@microsoft/api-extractor`, it will start a new program which takes some time
227
219
  *
@@ -230,70 +222,50 @@ export interface PluginOptions {
230
222
  rollupTypes?: boolean
231
223
 
232
224
  /**
233
- * Whether to copy .d.ts source files to outputDir
234
- *
235
- * @default false
236
- * @remarks Prior to 2.0, the default was true
237
- */
238
- copyDtsFiles?: boolean
239
-
240
- /**
241
- * Whether to emit nothing when there is a diagnostic
225
+ * Bundled packages for `@microsoft/api-extractor`
242
226
  *
243
- * @default false
227
+ * @default []
228
+ * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
244
229
  */
245
- noEmitOnError?: boolean
230
+ bundledPackages?: string[]
246
231
 
247
232
  /**
248
- * Whether to skip Typescript diagnostics
249
- *
250
- * Skip type diagnostics means type errors will not interrupt the build process
251
- *
252
- * But source files with type errors will not be emitted
233
+ * Whether copy .d.ts source files into `outDir`
253
234
  *
254
235
  * @default false
255
- * @remarks Before 1.7, default was true
236
+ * @remarks Before 2.0 it defaults to true
256
237
  */
257
- skipDiagnostics?: boolean
258
-
259
- /**
260
- * Customize Typescript lib folder path
261
- *
262
- * Relative path to root or an absolute path
263
- *
264
- * @default undefined
265
- */
266
- libFolderPath?: string
238
+ copyDtsFiles?: boolean
267
239
 
268
240
  /**
269
241
  * Specify the log level of plugin
270
242
  *
271
- * Defaults to base 'logLevel' property of your vite config
243
+ * By Default it base on 'logLevel' option of your Vite config
272
244
  */
273
245
  logLevel?: LogLevel
274
246
 
275
247
  /**
276
- * After emit diagnostic hook
248
+ * Hook after diagnostic emitted
277
249
  *
278
250
  * According to the length to judge whether there is any type error
279
251
  *
280
252
  * @default () => {}
281
253
  */
282
- afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
254
+ afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => void | Promise<void>
283
255
 
284
256
  /**
285
- * Before declaration file be writed hook
257
+ * Hook before each declaration file is written
286
258
  *
287
- * You can transform declaration file-path and content through it
259
+ * You can transform declaration file's path and content through it
288
260
  *
289
- * The file will be skipped when return exact false
261
+ * The file will be skipped when return exact `false`
290
262
  *
291
263
  * @default () => {}
292
264
  */
293
265
  beforeWriteFile?: (filePath: string, content: string) => void | false | TransformWriteFile
294
266
 
295
267
  /**
296
- * After build hook
268
+ * Hook after built
297
269
  *
298
270
  * It wil be called after all declaration files are written
299
271
  *
@@ -321,6 +293,10 @@ pnpm run test:ts
321
293
 
322
294
  Then check `examples/ts/types`.
323
295
 
296
+ Also Vue and React cases under `examples`.
297
+
298
+ A real project using this plugin: [Vexip UI](https://github.com/vexip-ui/vexip-ui).
299
+
324
300
  ## License
325
301
 
326
302
  MIT License.