vite-plugin-dts 2.0.2 → 2.2.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
@@ -83,19 +83,19 @@ Here are some FAQ's and solutions.
83
83
 
84
84
  ### Missing some declaration files after build (before `1.7.0`)
85
85
 
86
- 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).
86
+ By default, the `skipDiagnostics` option is set to `true` which means 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).
87
87
 
88
- 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.
88
+ 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
89
 
90
- ### Take type error when using both `script` and `setup-script` in vue component
90
+ ### Type error when using both `script` and `setup-script` in Vue component
91
91
 
92
- 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.
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/example/components/BothScripts.vue). You should remove the `defineComponent` which in `script` and export a native object directly.
95
95
 
96
- ### Take errors that unable to infer types from packages which under `node_modules`
96
+ ### Type errors that are unable to infer types from packages in `node_modules`
97
97
 
98
- This is a exist issue when TypeScript inferring types from packages which under `node_modules` through soft links (pnpm), you can refer to this [issue](https://github.com/microsoft/TypeScript/issues/42873). Currently has a workaround that add `baseUrl` to your `tsconfig.json` and specify the `paths` for these packages:
98
+ This is an existing issue when TypeScript infers types from packages located in `node_modules` through soft links (pnpm). Please refer to [this TypeScript issue](https://github.com/microsoft/TypeScript/issues/42873). The current workaround is to add `baseUrl` to your `tsconfig.json` and specify the `paths` for these packages:
99
99
 
100
100
  ```json
101
101
  {
@@ -123,25 +123,25 @@ export interface PluginOptions {
123
123
  /**
124
124
  * Depends on the root directory
125
125
  *
126
- * By Default it base on 'root' option of your vite config
126
+ * Defaults to 'root' property in your vite config
127
127
  */
128
128
  root?: string
129
129
 
130
130
  /**
131
131
  * Declaration files output directory
132
132
  *
133
- * Can be specified a array to output to multiple directories
133
+ * Supports arrays to output to multiple directories
134
134
  *
135
- * By Default it base on 'build.outDir' option of your vite config
135
+ * Defaults to 'build.outDir' property in your vite config
136
136
  */
137
137
  outputDir?: string | string[]
138
138
 
139
139
  /**
140
- * Manually set the root path of the entry files
140
+ * Manually sets the root path of entry files
141
141
  *
142
- * The output path of each file will be calculated base on it
142
+ * The output path of each file will be calculated based on it
143
143
  *
144
- * By Default it is the smallest public path for all files
144
+ * Defaults to the shortest public path for all files
145
145
  */
146
146
  entryRoot?: string
147
147
 
@@ -155,7 +155,7 @@ export interface PluginOptions {
155
155
  /**
156
156
  * Project init tsconfig.json file path by ts-morph
157
157
  *
158
- * Plugin also resolve include and exclude files from tsconfig.json
158
+ * Plugin also resolves include and exclude files from tsconfig.json
159
159
  *
160
160
  * @default 'tsconfig.json'
161
161
  */
@@ -164,21 +164,21 @@ export interface PluginOptions {
164
164
  /**
165
165
  * Set which paths should exclude when transform aliases
166
166
  *
167
- * If it's regexp, it will test the original import path directly
167
+ * If a regular expression, it will test the original import path directly
168
168
  *
169
169
  * @default []
170
170
  */
171
171
  aliasesExclude?: (string | RegExp)[]
172
172
 
173
173
  /**
174
- * Whether transform file name '.vue.d.ts' to '.d.ts'
174
+ * Whether tp transform file name '.vue.d.ts' to '.d.ts'
175
175
  *
176
176
  * @default false
177
177
  */
178
178
  cleanVueFileName?: boolean
179
179
 
180
180
  /**
181
- * Whether transform dynamic import to static
181
+ * Whether to transform dynamic imports to static
182
182
  *
183
183
  * Force true when `rollupTypes` is effective
184
184
  *
@@ -189,16 +189,16 @@ export interface PluginOptions {
189
189
  staticImport?: boolean
190
190
 
191
191
  /**
192
- * Manual set include glob
192
+ * Specify a glob of files to include
193
193
  *
194
- * By Default it base on 'include' option of the tsconfig.json
194
+ * Defaults to 'include' property of the tsconfig.json
195
195
  */
196
196
  include?: string | string[]
197
197
 
198
198
  /**
199
- * Manual set exclude glob
199
+ * Specify a glob of files to exclude
200
200
  *
201
- * By Default it base on 'exclude' option of the tsconfig.json, be 'node_module/**' when empty
201
+ * Defaults to 'exclude' property of tsconfig.json and 'node_module/**' when empty
202
202
  */
203
203
  exclude?: string | string[]
204
204
 
@@ -210,11 +210,11 @@ export interface PluginOptions {
210
210
  clearPureImport?: boolean
211
211
 
212
212
  /**
213
- * Whether generate types entry file
213
+ * Whether to generate types entry file
214
214
  *
215
- * When true will from package.json types field if exists or `${outputDir}/index.d.ts`
215
+ * When set to true, will add package.json `types` property to `${outputDir}/index.d.ts`
216
216
  *
217
- * Force true when `rollupTypes` is effective
217
+ * Force true when `rollupTypes` is set
218
218
  *
219
219
  * @default false
220
220
  */
@@ -230,36 +230,36 @@ export interface PluginOptions {
230
230
  rollupTypes?: boolean
231
231
 
232
232
  /**
233
- * Whether copy .d.ts source files into outputDir
233
+ * Whether to copy .d.ts source files to outputDir
234
234
  *
235
235
  * @default false
236
- * @remarks Before 2.0 it defaults to true
236
+ * @remarks Prior to 2.0, the default was true
237
237
  */
238
238
  copyDtsFiles?: boolean
239
239
 
240
240
  /**
241
- * Whether emit nothing when has any diagnostic
241
+ * Whether to emit nothing when there is a diagnostic
242
242
  *
243
243
  * @default false
244
244
  */
245
245
  noEmitOnError?: boolean
246
246
 
247
247
  /**
248
- * Whether skip typescript diagnostics
248
+ * Whether to skip Typescript diagnostics
249
249
  *
250
- * Skip type diagnostics means that type errors will not interrupt the build process
250
+ * Skip type diagnostics means type errors will not interrupt the build process
251
251
  *
252
- * But for the source files with type errors will not be emitted
252
+ * But source files with type errors will not be emitted
253
253
  *
254
254
  * @default false
255
- * @remarks Before 1.7 it defaults to true
255
+ * @remarks Before 1.7, default was true
256
256
  */
257
257
  skipDiagnostics?: boolean
258
258
 
259
259
  /**
260
- * Customize typescript lib folder path
260
+ * Customize Typescript lib folder path
261
261
  *
262
- * Should pass a relative path to root or a absolute path
262
+ * Relative path to root or an absolute path
263
263
  *
264
264
  * @default undefined
265
265
  */
@@ -268,7 +268,7 @@ export interface PluginOptions {
268
268
  /**
269
269
  * Specify the log level of plugin
270
270
  *
271
- * By Default it base on 'logLevel' option of your vite config
271
+ * Defaults to base 'logLevel' property of your vite config
272
272
  */
273
273
  logLevel?: LogLevel
274
274
 
@@ -305,7 +305,7 @@ export interface PluginOptions {
305
305
 
306
306
  ## Contributors
307
307
 
308
- Thanks for all their contributions!
308
+ Thanks for all the contributions!
309
309
 
310
310
  <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
311
311
  <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" />
package/dist/index.cjs CHANGED
@@ -507,7 +507,8 @@ function rollupDeclarationFiles({
507
507
  outputDir,
508
508
  entryPath,
509
509
  fileName,
510
- libFolder
510
+ libFolder,
511
+ bundledPackages
511
512
  }) {
512
513
  const configObjectFullPath = node_path.resolve(root, "api-extractor.json");
513
514
  const packageJsonLookup = new nodeCoreLibrary.PackageJsonLookup();
@@ -519,6 +520,7 @@ function rollupDeclarationFiles({
519
520
  configObject: {
520
521
  projectFolder: root,
521
522
  mainEntryPointFilePath: entryPath,
523
+ bundledPackages,
522
524
  compiler: {
523
525
  overrideTsconfig: {
524
526
  $schema: "http://json.schemastore.org/tsconfig",
@@ -587,6 +589,7 @@ function rollupDeclarationFiles({
587
589
 
588
590
  const noneExport = "export {};\n";
589
591
  const vueRE = /\.vue$/;
592
+ const svelteRE = /\.svelte$/;
590
593
  const tsRE = /\.(m|c)?tsx?$/;
591
594
  const jsRE = /\.(m|c)?jsx?$/;
592
595
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -611,6 +614,7 @@ function dtsPlugin(options = {}) {
611
614
  clearPureImport = true,
612
615
  insertTypesEntry = false,
613
616
  rollupTypes = false,
617
+ bundledPackages = [],
614
618
  noEmitOnError = false,
615
619
  skipDiagnostics = false,
616
620
  copyDtsFiles = false,
@@ -666,6 +670,9 @@ ${kolorist.cyan(
666
670
  }
667
671
  } else if (!id.includes(".vue?vue") && (tsRE.test(id) || allowJs && jsRE.test(id))) {
668
672
  project.createSourceFile(id, await fs.readFile(id, "utf-8"), { overwrite: true });
673
+ } else if (svelteRE.test(id)) {
674
+ const content = "export { SvelteComponentTyped as default } from 'svelte/internal';";
675
+ project.createSourceFile(`${id}.ts`, content, { overwrite: true });
669
676
  }
670
677
  }
671
678
  return {
@@ -701,7 +708,7 @@ ${kolorist.cyan(
701
708
  `
702
709
  ${kolorist.cyan(
703
710
  "[vite:dts]"
704
- )} You building not a library that may not need to generate declaration files.
711
+ )} You are building a library that may not need to generate declaration files.
705
712
  `
706
713
  )
707
714
  );
@@ -726,7 +733,7 @@ ${kolorist.cyan(
726
733
  `
727
734
  ${kolorist.cyan(
728
735
  "[vite:dts]"
729
- )} Can not resolve declaration directory, please check your vite config and plugin options.
736
+ )} Can not resolve declaration directory. Please check your vite config and plugin options.
730
737
  `
731
738
  )
732
739
  );
@@ -954,7 +961,8 @@ export default ${libName}
954
961
  outputDir,
955
962
  entryPath: path,
956
963
  fileName: node_path.basename(path),
957
- libFolder: libFolderPath
964
+ libFolder: libFolderPath,
965
+ bundledPackages
958
966
  });
959
967
  emittedFiles.delete(path);
960
968
  rollupFiles.add(path);
@@ -966,7 +974,8 @@ export default ${libName}
966
974
  outputDir,
967
975
  entryPath: typesPath,
968
976
  fileName: node_path.basename(typesPath),
969
- libFolder: libFolderPath
977
+ libFolder: libFolderPath,
978
+ bundledPackages
970
979
  });
971
980
  emittedFiles.delete(typesPath);
972
981
  rollupFiles.add(typesPath);
package/dist/index.d.ts CHANGED
@@ -103,6 +103,14 @@ interface PluginOptions {
103
103
  * @default false
104
104
  */
105
105
  rollupTypes?: boolean;
106
+ /**
107
+ * Bundled packages for rollup types
108
+ *
109
+ * See https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
110
+ *
111
+ * @default []
112
+ */
113
+ bundledPackages?: string[];
106
114
  /**
107
115
  * Whether copy .d.ts source files into outputDir
108
116
  *
package/dist/index.mjs CHANGED
@@ -512,7 +512,8 @@ function rollupDeclarationFiles({
512
512
  outputDir,
513
513
  entryPath,
514
514
  fileName,
515
- libFolder
515
+ libFolder,
516
+ bundledPackages
516
517
  }) {
517
518
  const configObjectFullPath = resolve$1(root, "api-extractor.json");
518
519
  const packageJsonLookup = new PackageJsonLookup();
@@ -524,6 +525,7 @@ function rollupDeclarationFiles({
524
525
  configObject: {
525
526
  projectFolder: root,
526
527
  mainEntryPointFilePath: entryPath,
528
+ bundledPackages,
527
529
  compiler: {
528
530
  overrideTsconfig: {
529
531
  $schema: "http://json.schemastore.org/tsconfig",
@@ -592,6 +594,7 @@ function rollupDeclarationFiles({
592
594
 
593
595
  const noneExport = "export {};\n";
594
596
  const vueRE = /\.vue$/;
597
+ const svelteRE = /\.svelte$/;
595
598
  const tsRE = /\.(m|c)?tsx?$/;
596
599
  const jsRE = /\.(m|c)?jsx?$/;
597
600
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -616,6 +619,7 @@ function dtsPlugin(options = {}) {
616
619
  clearPureImport = true,
617
620
  insertTypesEntry = false,
618
621
  rollupTypes = false,
622
+ bundledPackages = [],
619
623
  noEmitOnError = false,
620
624
  skipDiagnostics = false,
621
625
  copyDtsFiles = false,
@@ -671,6 +675,9 @@ ${cyan(
671
675
  }
672
676
  } else if (!id.includes(".vue?vue") && (tsRE.test(id) || allowJs && jsRE.test(id))) {
673
677
  project.createSourceFile(id, await fs.readFile(id, "utf-8"), { overwrite: true });
678
+ } else if (svelteRE.test(id)) {
679
+ const content = "export { SvelteComponentTyped as default } from 'svelte/internal';";
680
+ project.createSourceFile(`${id}.ts`, content, { overwrite: true });
674
681
  }
675
682
  }
676
683
  return {
@@ -706,7 +713,7 @@ ${cyan(
706
713
  `
707
714
  ${cyan(
708
715
  "[vite:dts]"
709
- )} You building not a library that may not need to generate declaration files.
716
+ )} You are building a library that may not need to generate declaration files.
710
717
  `
711
718
  )
712
719
  );
@@ -731,7 +738,7 @@ ${cyan(
731
738
  `
732
739
  ${cyan(
733
740
  "[vite:dts]"
734
- )} Can not resolve declaration directory, please check your vite config and plugin options.
741
+ )} Can not resolve declaration directory. Please check your vite config and plugin options.
735
742
  `
736
743
  )
737
744
  );
@@ -959,7 +966,8 @@ export default ${libName}
959
966
  outputDir,
960
967
  entryPath: path,
961
968
  fileName: basename(path),
962
- libFolder: libFolderPath
969
+ libFolder: libFolderPath,
970
+ bundledPackages
963
971
  });
964
972
  emittedFiles.delete(path);
965
973
  rollupFiles.add(path);
@@ -971,7 +979,8 @@ export default ${libName}
971
979
  outputDir,
972
980
  entryPath: typesPath,
973
981
  fileName: basename(typesPath),
974
- libFolder: libFolderPath
982
+ libFolder: libFolderPath,
983
+ bundledPackages
975
984
  });
976
985
  emittedFiles.delete(typesPath);
977
986
  rollupFiles.add(typesPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "2.0.2",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",