vite-plugin-dts 2.1.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
@@ -1,326 +1,326 @@
1
- <h1 align="center">vite-plugin-dts</h1>
2
-
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>.
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>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 />
20
-
21
- ## Install
22
-
23
- ```sh
24
- pnpm add vite-plugin-dts -D
25
- ```
26
-
27
- ## Usage
28
-
29
- In `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
- In your component:
50
-
51
- ```vue
52
- <template>
53
- <div></div>
54
- </template>
55
-
56
- <script lang="ts">
57
- // using defineComponent for inferring types
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
- // Need to access the defineProps returned value to
69
- // infer types although you never use the props directly
70
- const props = defineProps<{
71
- color: 'blue' | 'red'
72
- }>()
73
- </script>
74
-
75
- <template>
76
- <div>{{ color }}</div>
77
- </template>
78
- ```
79
-
80
- ## FAQ
81
-
82
- Here are some FAQ's and solutions.
83
-
84
- ### Missing some declaration files after build (before `1.7.0`)
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).
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.
89
-
90
- ### Take type error when using both `script` and `setup-script` in vue component
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.
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.
95
-
96
- ### Take errors that unable to infer types from packages which under `node_modules`
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:
99
-
100
- ```json
101
- {
102
- "compilerOptions": {
103
- "baseUrl": ".",
104
- "paths": {
105
- "third-lib": ["node_modules/third-lib"]
106
- }
107
- }
108
- }
109
- ```
110
-
111
- ## Options
112
-
113
- ```ts
114
- import type { ts, Diagnostic } from 'ts-morph'
115
- import type { LogLevel } from 'vite'
116
-
117
- interface TransformWriteFile {
118
- filePath?: string
119
- content?: string
120
- }
121
-
122
- export interface PluginOptions {
123
- /**
124
- * Depends on the root directory
125
- *
126
- * By Default it base on 'root' option of your vite config
127
- */
128
- root?: string
129
-
130
- /**
131
- * Declaration files output directory
132
- *
133
- * Can be specified a array to output to multiple directories
134
- *
135
- * By Default it base on 'build.outDir' option of your vite config
136
- */
137
- outputDir?: string | string[]
138
-
139
- /**
140
- * Manually set the root path of the entry files
141
- *
142
- * The output path of each file will be calculated base on it
143
- *
144
- * By Default it is the smallest public path for all files
145
- */
146
- entryRoot?: string
147
-
148
- /**
149
- * Project init compilerOptions using by ts-morph
150
- *
151
- * @default null
152
- */
153
- compilerOptions?: ts.CompilerOptions | null
154
-
155
- /**
156
- * Project init tsconfig.json file path by ts-morph
157
- *
158
- * Plugin also resolve include and exclude files from tsconfig.json
159
- *
160
- * @default 'tsconfig.json'
161
- */
162
- tsConfigFilePath?: string
163
-
164
- /**
165
- * Set which paths should exclude when transform aliases
166
- *
167
- * If it's regexp, it will test the original import path directly
168
- *
169
- * @default []
170
- */
171
- aliasesExclude?: (string | RegExp)[]
172
-
173
- /**
174
- * Whether transform file name '.vue.d.ts' to '.d.ts'
175
- *
176
- * @default false
177
- */
178
- cleanVueFileName?: boolean
179
-
180
- /**
181
- * Whether transform dynamic import to static
182
- *
183
- * Force true when `rollupTypes` is effective
184
- *
185
- * eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
186
- *
187
- * @default false
188
- */
189
- staticImport?: boolean
190
-
191
- /**
192
- * Manual set include glob
193
- *
194
- * By Default it base on 'include' option of the tsconfig.json
195
- */
196
- include?: string | string[]
197
-
198
- /**
199
- * Manual set exclude glob
200
- *
201
- * By Default it base on 'exclude' option of the tsconfig.json, be 'node_module/**' when empty
202
- */
203
- exclude?: string | string[]
204
-
205
- /**
206
- * Do not emit if content of file only includes 'export {}'
207
- *
208
- * @default true
209
- */
210
- clearPureImport?: boolean
211
-
212
- /**
213
- * Whether generate types entry file
214
- *
215
- * When true will from package.json types field if exists or `${outputDir}/index.d.ts`
216
- *
217
- * Force true when `rollupTypes` is effective
218
- *
219
- * @default false
220
- */
221
- insertTypesEntry?: boolean
222
-
223
- /**
224
- * Set to rollup declaration files after emit
225
- *
226
- * Power by `@microsoft/api-extractor`, it will start a new program which takes some time
227
- *
228
- * @default false
229
- */
230
- rollupTypes?: boolean
231
-
232
- /**
233
- * Whether copy .d.ts source files into outputDir
234
- *
235
- * @default false
236
- * @remarks Before 2.0 it defaults to true
237
- */
238
- copyDtsFiles?: boolean
239
-
240
- /**
241
- * Whether emit nothing when has any diagnostic
242
- *
243
- * @default false
244
- */
245
- noEmitOnError?: boolean
246
-
247
- /**
248
- * Whether skip typescript diagnostics
249
- *
250
- * Skip type diagnostics means that type errors will not interrupt the build process
251
- *
252
- * But for the source files with type errors will not be emitted
253
- *
254
- * @default false
255
- * @remarks Before 1.7 it defaults to true
256
- */
257
- skipDiagnostics?: boolean
258
-
259
- /**
260
- * Customize typescript lib folder path
261
- *
262
- * Should pass a relative path to root or a absolute path
263
- *
264
- * @default undefined
265
- */
266
- libFolderPath?: string
267
-
268
- /**
269
- * Specify the log level of plugin
270
- *
271
- * By Default it base on 'logLevel' option of your vite config
272
- */
273
- logLevel?: LogLevel
274
-
275
- /**
276
- * After emit diagnostic hook
277
- *
278
- * According to the length to judge whether there is any type error
279
- *
280
- * @default () => {}
281
- */
282
- afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
283
-
284
- /**
285
- * Before declaration file be writed hook
286
- *
287
- * You can transform declaration file-path and content through it
288
- *
289
- * The file will be skipped when return exact false
290
- *
291
- * @default () => {}
292
- */
293
- beforeWriteFile?: (filePath: string, content: string) => void | false | TransformWriteFile
294
-
295
- /**
296
- * After build hook
297
- *
298
- * It wil be called after all declaration files are written
299
- *
300
- * @default () => {}
301
- */
302
- afterBuild?: () => void | Promise<void>
303
- }
304
- ```
305
-
306
- ## Contributors
307
-
308
- Thanks for all their contributions!
309
-
310
- <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
311
- <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" />
312
- </a>
313
-
314
- ## Example
315
-
316
- Clone and run the following script:
317
-
318
- ```sh
319
- pnpm run test:ts
320
- ```
321
-
322
- Then check `examples/ts/types`.
323
-
324
- ## License
325
-
326
- MIT License.
1
+ <h1 align="center">vite-plugin-dts</h1>
2
+
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>.
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>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 />
20
+
21
+ ## Install
22
+
23
+ ```sh
24
+ pnpm add vite-plugin-dts -D
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ In `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
+ In your component:
50
+
51
+ ```vue
52
+ <template>
53
+ <div></div>
54
+ </template>
55
+
56
+ <script lang="ts">
57
+ // using defineComponent for inferring types
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
+ // Need to access the defineProps returned value to
69
+ // infer types although you never use the props directly
70
+ const props = defineProps<{
71
+ color: 'blue' | 'red'
72
+ }>()
73
+ </script>
74
+
75
+ <template>
76
+ <div>{{ color }}</div>
77
+ </template>
78
+ ```
79
+
80
+ ## FAQ
81
+
82
+ Here are some FAQ's and solutions.
83
+
84
+ ### Missing some declaration files after build (before `1.7.0`)
85
+
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
+
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
+
90
+ ### Type error when using both `script` and `setup-script` in Vue component
91
+
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
+
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
+
96
+ ### Type errors that are unable to infer types from packages in `node_modules`
97
+
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
+
100
+ ```json
101
+ {
102
+ "compilerOptions": {
103
+ "baseUrl": ".",
104
+ "paths": {
105
+ "third-lib": ["node_modules/third-lib"]
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ ## Options
112
+
113
+ ```ts
114
+ import type { ts, Diagnostic } from 'ts-morph'
115
+ import type { LogLevel } from 'vite'
116
+
117
+ interface TransformWriteFile {
118
+ filePath?: string
119
+ content?: string
120
+ }
121
+
122
+ export interface PluginOptions {
123
+ /**
124
+ * Depends on the root directory
125
+ *
126
+ * Defaults to 'root' property in your vite config
127
+ */
128
+ root?: string
129
+
130
+ /**
131
+ * Declaration files output directory
132
+ *
133
+ * Supports arrays to output to multiple directories
134
+ *
135
+ * Defaults to 'build.outDir' property in your vite config
136
+ */
137
+ outputDir?: string | string[]
138
+
139
+ /**
140
+ * Manually sets the root path of entry files
141
+ *
142
+ * The output path of each file will be calculated based on it
143
+ *
144
+ * Defaults to the shortest public path for all files
145
+ */
146
+ entryRoot?: string
147
+
148
+ /**
149
+ * Project init compilerOptions using by ts-morph
150
+ *
151
+ * @default null
152
+ */
153
+ compilerOptions?: ts.CompilerOptions | null
154
+
155
+ /**
156
+ * Project init tsconfig.json file path by ts-morph
157
+ *
158
+ * Plugin also resolves include and exclude files from tsconfig.json
159
+ *
160
+ * @default 'tsconfig.json'
161
+ */
162
+ tsConfigFilePath?: string
163
+
164
+ /**
165
+ * Set which paths should exclude when transform aliases
166
+ *
167
+ * If a regular expression, it will test the original import path directly
168
+ *
169
+ * @default []
170
+ */
171
+ aliasesExclude?: (string | RegExp)[]
172
+
173
+ /**
174
+ * Whether tp transform file name '.vue.d.ts' to '.d.ts'
175
+ *
176
+ * @default false
177
+ */
178
+ cleanVueFileName?: boolean
179
+
180
+ /**
181
+ * Whether to transform dynamic imports to static
182
+ *
183
+ * Force true when `rollupTypes` is effective
184
+ *
185
+ * eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
186
+ *
187
+ * @default false
188
+ */
189
+ staticImport?: boolean
190
+
191
+ /**
192
+ * Specify a glob of files to include
193
+ *
194
+ * Defaults to 'include' property of the tsconfig.json
195
+ */
196
+ include?: string | string[]
197
+
198
+ /**
199
+ * Specify a glob of files to exclude
200
+ *
201
+ * Defaults to 'exclude' property of tsconfig.json and 'node_module/**' when empty
202
+ */
203
+ exclude?: string | string[]
204
+
205
+ /**
206
+ * Do not emit if content of file only includes 'export {}'
207
+ *
208
+ * @default true
209
+ */
210
+ clearPureImport?: boolean
211
+
212
+ /**
213
+ * Whether to generate types entry file
214
+ *
215
+ * When set to true, will add package.json `types` property to `${outputDir}/index.d.ts`
216
+ *
217
+ * Force true when `rollupTypes` is set
218
+ *
219
+ * @default false
220
+ */
221
+ insertTypesEntry?: boolean
222
+
223
+ /**
224
+ * Set to rollup declaration files after emit
225
+ *
226
+ * Power by `@microsoft/api-extractor`, it will start a new program which takes some time
227
+ *
228
+ * @default false
229
+ */
230
+ rollupTypes?: boolean
231
+
232
+ /**
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
242
+ *
243
+ * @default false
244
+ */
245
+ noEmitOnError?: boolean
246
+
247
+ /**
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
253
+ *
254
+ * @default false
255
+ * @remarks Before 1.7, default was true
256
+ */
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
267
+
268
+ /**
269
+ * Specify the log level of plugin
270
+ *
271
+ * Defaults to base 'logLevel' property of your vite config
272
+ */
273
+ logLevel?: LogLevel
274
+
275
+ /**
276
+ * After emit diagnostic hook
277
+ *
278
+ * According to the length to judge whether there is any type error
279
+ *
280
+ * @default () => {}
281
+ */
282
+ afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
283
+
284
+ /**
285
+ * Before declaration file be writed hook
286
+ *
287
+ * You can transform declaration file-path and content through it
288
+ *
289
+ * The file will be skipped when return exact false
290
+ *
291
+ * @default () => {}
292
+ */
293
+ beforeWriteFile?: (filePath: string, content: string) => void | false | TransformWriteFile
294
+
295
+ /**
296
+ * After build hook
297
+ *
298
+ * It wil be called after all declaration files are written
299
+ *
300
+ * @default () => {}
301
+ */
302
+ afterBuild?: () => void | Promise<void>
303
+ }
304
+ ```
305
+
306
+ ## Contributors
307
+
308
+ Thanks for all the contributions!
309
+
310
+ <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
311
+ <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" />
312
+ </a>
313
+
314
+ ## Example
315
+
316
+ Clone and run the following script:
317
+
318
+ ```sh
319
+ pnpm run test:ts
320
+ ```
321
+
322
+ Then check `examples/ts/types`.
323
+
324
+ ## License
325
+
326
+ MIT License.
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;
@@ -589,6 +608,7 @@ function rollupDeclarationFiles({
589
608
 
590
609
  const noneExport = "export {};\n";
591
610
  const vueRE = /\.vue$/;
611
+ const svelteRE = /\.svelte$/;
592
612
  const tsRE = /\.(m|c)?tsx?$/;
593
613
  const jsRE = /\.(m|c)?jsx?$/;
594
614
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -669,6 +689,9 @@ ${kolorist.cyan(
669
689
  }
670
690
  } else if (!id.includes(".vue?vue") && (tsRE.test(id) || allowJs && jsRE.test(id))) {
671
691
  project.createSourceFile(id, await fs.readFile(id, "utf-8"), { overwrite: true });
692
+ } else if (svelteRE.test(id)) {
693
+ const content = "export { SvelteComponentTyped as default } from 'svelte/internal';";
694
+ project.createSourceFile(`${id}.ts`, content, { overwrite: true });
672
695
  }
673
696
  }
674
697
  return {
@@ -704,7 +727,7 @@ ${kolorist.cyan(
704
727
  `
705
728
  ${kolorist.cyan(
706
729
  "[vite:dts]"
707
- )} You building not a library that may not need to generate declaration files.
730
+ )} You are building a library that may not need to generate declaration files.
708
731
  `
709
732
  )
710
733
  );
@@ -729,7 +752,7 @@ ${kolorist.cyan(
729
752
  `
730
753
  ${kolorist.cyan(
731
754
  "[vite:dts]"
732
- )} Can not resolve declaration directory, please check your vite config and plugin options.
755
+ )} Can not resolve declaration directory. Please check your vite config and plugin options.
733
756
  `
734
757
  )
735
758
  );
@@ -753,20 +776,7 @@ ${kolorist.cyan(
753
776
  libFolderPath
754
777
  });
755
778
  allowJs = project.getCompilerOptions().allowJs ?? false;
756
- const tsConfig = { compilerOptions: {} };
757
- const readFile = project.getFileSystem().readFileSync;
758
- let currentConfigPath = tsConfigPath;
759
- while (currentConfigPath) {
760
- const currentConfig = typescript.readConfigFile(currentConfigPath, readFile).config ?? {};
761
- Object.assign(tsConfig.compilerOptions, currentConfig.compilerOptions || {});
762
- if (!tsConfig.include) {
763
- tsConfig.include = currentConfig.include;
764
- }
765
- if (!tsConfig.exclude) {
766
- tsConfig.exclude = currentConfig.exclude;
767
- }
768
- currentConfigPath = currentConfig.extends && ensureAbsolute(currentConfig.extends, node_path.dirname(currentConfigPath));
769
- }
779
+ const tsConfig = getTsConfig(tsConfigPath, project.getFileSystem().readFileSync);
770
780
  include = ensureArray(options.include ?? tsConfig.include ?? "**/*").map(normalizeGlob);
771
781
  exclude = ensureArray(options.exclude ?? tsConfig.exclude ?? "node_modules/**").map(
772
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) {
@@ -594,6 +613,7 @@ function rollupDeclarationFiles({
594
613
 
595
614
  const noneExport = "export {};\n";
596
615
  const vueRE = /\.vue$/;
616
+ const svelteRE = /\.svelte$/;
597
617
  const tsRE = /\.(m|c)?tsx?$/;
598
618
  const jsRE = /\.(m|c)?jsx?$/;
599
619
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -674,6 +694,9 @@ ${cyan(
674
694
  }
675
695
  } else if (!id.includes(".vue?vue") && (tsRE.test(id) || allowJs && jsRE.test(id))) {
676
696
  project.createSourceFile(id, await fs.readFile(id, "utf-8"), { overwrite: true });
697
+ } else if (svelteRE.test(id)) {
698
+ const content = "export { SvelteComponentTyped as default } from 'svelte/internal';";
699
+ project.createSourceFile(`${id}.ts`, content, { overwrite: true });
677
700
  }
678
701
  }
679
702
  return {
@@ -709,7 +732,7 @@ ${cyan(
709
732
  `
710
733
  ${cyan(
711
734
  "[vite:dts]"
712
- )} You building not a library that may not need to generate declaration files.
735
+ )} You are building a library that may not need to generate declaration files.
713
736
  `
714
737
  )
715
738
  );
@@ -734,7 +757,7 @@ ${cyan(
734
757
  `
735
758
  ${cyan(
736
759
  "[vite:dts]"
737
- )} Can not resolve declaration directory, please check your vite config and plugin options.
760
+ )} Can not resolve declaration directory. Please check your vite config and plugin options.
738
761
  `
739
762
  )
740
763
  );
@@ -758,20 +781,7 @@ ${cyan(
758
781
  libFolderPath
759
782
  });
760
783
  allowJs = project.getCompilerOptions().allowJs ?? false;
761
- const tsConfig = { compilerOptions: {} };
762
- const readFile = project.getFileSystem().readFileSync;
763
- let currentConfigPath = tsConfigPath;
764
- while (currentConfigPath) {
765
- const currentConfig = typescript.readConfigFile(currentConfigPath, readFile).config ?? {};
766
- Object.assign(tsConfig.compilerOptions, currentConfig.compilerOptions || {});
767
- if (!tsConfig.include) {
768
- tsConfig.include = currentConfig.include;
769
- }
770
- if (!tsConfig.exclude) {
771
- tsConfig.exclude = currentConfig.exclude;
772
- }
773
- currentConfigPath = currentConfig.extends && ensureAbsolute(currentConfig.extends, dirname(currentConfigPath));
774
- }
784
+ const tsConfig = getTsConfig(tsConfigPath, project.getFileSystem().readFileSync);
775
785
  include = ensureArray(options.include ?? tsConfig.include ?? "**/*").map(normalizeGlob);
776
786
  exclude = ensureArray(options.exclude ?? tsConfig.exclude ?? "node_modules/**").map(
777
787
  normalizeGlob
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "2.1.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": {