vite-plugin-dts 3.1.0 → 3.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
@@ -8,6 +8,9 @@
8
8
  <a href="https://www.npmjs.com/package/vite-plugin-dts">
9
9
  <img src="https://img.shields.io/npm/v/vite-plugin-dts?color=orange&label=" alt="version" />
10
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>
11
14
  </p>
12
15
 
13
16
  **English** | [中文](./README.zh-CN.md)
@@ -40,34 +43,7 @@ export default defineConfig({
40
43
  })
41
44
  ```
42
45
 
43
- In your component:
44
-
45
- ```vue
46
- <template>
47
- <div></div>
48
- </template>
49
-
50
- <script lang="ts">
51
- // using defineComponent for inferring types
52
- import { defineComponent } from 'vue'
53
-
54
- export default defineComponent({
55
- name: 'Component'
56
- })
57
- </script>
58
- ```
59
-
60
- ```vue
61
- <script setup lang="ts">
62
- defineProps<{
63
- color: 'blue' | 'red'
64
- }>()
65
- </script>
66
-
67
- <template>
68
- <div>{{ color }}</div>
69
- </template>
70
- ```
46
+ Starting with `3.0.0`, you can use this plugin with Rollup.
71
47
 
72
48
  ## FAQ
73
49
 
@@ -75,19 +51,19 @@ Here are some FAQ's and solutions.
75
51
 
76
52
  ### Missing some declaration files after build (before `1.7.0`)
77
53
 
78
- 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).
54
+ By default, the `skipDiagnostics` option is set to `true` which means type diagnostics will be skipped during the build process (some projects may have diagnostic tools such as `vue-tsc`). Files with type errors which interrupt the build process will not be emitted (declaration files won't be generated).
79
55
 
80
- 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.
56
+ 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. Type errors during build will be logged to the terminal.
81
57
 
82
58
  ### Type error when using both `script` and `setup-script` in Vue component (before `3.0.0`)
83
59
 
84
- 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.
60
+ 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`. This results in a type error.
85
61
 
86
- 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.
62
+ Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue). You should remove the `defineComponent` in `script` and export a native object directly.
87
63
 
88
64
  ### Type errors that are unable to infer types from packages in `node_modules`
89
65
 
90
- 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:
66
+ This is an existing [TypeScript issue](https://github.com/microsoft/TypeScript/issues/42873) where TypeScript infers types from packages located in `node_modules` through soft links (pnpm). A workaround is to add `baseUrl` to your `tsconfig.json` and specify the `paths` for these packages:
91
67
 
92
68
  ```json
93
69
  {
@@ -116,16 +92,19 @@ export interface Resolver {
116
92
  */
117
93
  name: string,
118
94
  /**
119
- * Determine whether the resolve supports the file
95
+ * Determine whether the resolver supports the file
120
96
  */
121
97
  supports: (id: string) => void | boolean,
122
98
  /**
123
- * Transform the source file to declaration files
99
+ * Transform source to declaration files
100
+ *
101
+ * Note that the path of the returns should base on `outDir`, or relative path to `root`
124
102
  */
125
103
  transform: (payload: {
126
104
  id: string,
127
105
  code: string,
128
106
  root: string,
107
+ outDir: string,
129
108
  host: ts.CompilerHost,
130
109
  program: ts.Program,
131
110
  service: ts.LanguageService
@@ -136,39 +115,39 @@ export interface PluginOptions {
136
115
  /**
137
116
  * Specify root directory
138
117
  *
139
- * By Default it base on 'root' of your Vite config, or `process.cwd()` if using Rollup
118
+ * Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
140
119
  */
141
120
  root?: string,
142
121
 
143
122
  /**
144
- * Specify declaration files output directory
123
+ * Output directory for declaration files
145
124
  *
146
- * Can be specified a array to output to multiple directories
125
+ * Can be an array to output to multiple directories
147
126
  *
148
- * By Default it base on 'build.outDir' of your Vite config, or `outDir` of tsconfig.json if using Rollup
127
+ * Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
149
128
  */
150
129
  outDir?: string | string[],
151
130
 
152
131
  /**
153
- * Manually set the root path of the entry files, useful in monorepo
132
+ * Override root path of entry files (useful in monorepos)
154
133
  *
155
- * The output path of each file will be calculated base on it
134
+ * The output path of each file will be calculated based on the value provided
156
135
  *
157
- * By Default it is the smallest public path for all files
136
+ * The default is the smallest public path for all source files
158
137
  */
159
138
  entryRoot?: string,
160
139
 
161
140
  /**
162
- * Strictly restrict declaration files output inside `outDir`
141
+ * Restrict declaration files output to `outDir`
163
142
  *
164
- * Because if `entryRoot` is specified, declaration files maybe outside `outDir`
143
+ * If true, generated declaration files outside `outDir` will be ignored
165
144
  *
166
145
  * @default true
167
146
  */
168
147
  strictOutput?: boolean,
169
148
 
170
149
  /**
171
- * Specify a CompilerOptions to override
150
+ * Override compilerOptions
172
151
  *
173
152
  * @default null
174
153
  */
@@ -177,9 +156,9 @@ export interface PluginOptions {
177
156
  /**
178
157
  * Specify tsconfig.json path
179
158
  *
180
- * Plugin also resolve include and exclude files from tsconfig.json
159
+ * Plugin resolves `include` and `exclude` globs from tsconfig.json
181
160
  *
182
- * By default plugin will find config form root if not specify
161
+ * If not specified, plugin will find config file from root
183
162
  */
184
163
  tsconfigPath?: string,
185
164
 
@@ -191,68 +170,74 @@ export interface PluginOptions {
191
170
  resolvers?: Resolver[],
192
171
 
193
172
  /**
194
- * Set which paths should exclude when transform aliases
173
+ * Parsing `paths` of tsconfig.json to aliases
174
+ *
175
+ * Note that these aliases only use for declaration files
195
176
  *
196
- * If it's regexp, it will test the original import path directly
177
+ * @default true
178
+ * @remarks Only use first replacement of each path
179
+ */
180
+ pathsToAliases?: boolean,
181
+
182
+ /**
183
+ * Set which paths should be excluded when transforming aliases
197
184
  *
198
185
  * @default []
199
186
  */
200
187
  aliasesExclude?: (string | RegExp)[],
201
188
 
202
189
  /**
203
- * Whether transform file name '.vue.d.ts' to '.d.ts'
190
+ * Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
204
191
  *
205
192
  * @default false
206
193
  */
207
194
  cleanVueFileName?: boolean,
208
195
 
209
196
  /**
210
- * Whether transform dynamic import to static
197
+ * Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
211
198
  *
212
- * Force `true` when `rollupTypes` is effective
213
- *
214
- * eg. `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`
199
+ * Value is forced to `true` when `rollupTypes` is `true`
215
200
  *
216
201
  * @default false
217
202
  */
218
203
  staticImport?: boolean,
219
204
 
220
205
  /**
221
- * Manual set include glob
206
+ * Override `include` glob
222
207
  *
223
- * By Default it base on `include` option of the tsconfig.json
208
+ * Defaults to `include` property of tsconfig.json
224
209
  */
225
210
  include?: string | string[],
226
211
 
227
212
  /**
228
- * Manual set exclude glob
213
+ * Override `exclude` glob
229
214
  *
230
- * By Default it base on `exclude` option of the tsconfig.json, be `'node_module/**'` when empty
215
+ * Defaults to `exclude` property of tsconfig.json or `'node_module/**'` if not supplied.
231
216
  */
232
217
  exclude?: string | string[],
233
218
 
234
219
  /**
235
- * Whether remove those `import 'xxx'`
220
+ * Whether to remove `import 'xxx'`
236
221
  *
237
222
  * @default true
238
223
  */
239
224
  clearPureImport?: boolean,
240
225
 
241
226
  /**
242
- * Whether generate types entry file
227
+ * Whether to generate types entry file(s)
243
228
  *
244
- * When `true` will from package.json types field if exists or `${outDir}/index.d.ts`
229
+ * When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
245
230
  *
246
- * Force `true` when `rollupTypes` is effective
231
+ * Value is forced to `true` when `rollupTypes` is `true`
247
232
  *
248
233
  * @default false
249
234
  */
250
235
  insertTypesEntry?: boolean,
251
236
 
252
237
  /**
253
- * Set whether rollup declaration files after emit
238
+ * Rollup type declaration files after emitting them
254
239
  *
255
- * Power by `@microsoft/api-extractor`, it will start a new program which takes some time
240
+ * Powered by `@microsoft/api-extractor` - time-intensive operation
256
241
  *
257
242
  * @default false
258
243
  */
@@ -267,35 +252,35 @@ export interface PluginOptions {
267
252
  bundledPackages?: string[],
268
253
 
269
254
  /**
270
- * Whether copy .d.ts source files into `outDir`
255
+ * Whether to copy .d.ts source files to `outDir`
271
256
  *
272
257
  * @default false
273
- * @remarks Before 2.0 it defaults to true
258
+ * @remarks Before 2.0, the default was `true`
274
259
  */
275
260
  copyDtsFiles?: boolean,
276
261
 
277
262
  /**
278
- * Specify the log level of plugin
263
+ * Logging level for this plugin
279
264
  *
280
- * By Default it base on 'logLevel' option of your Vite config
265
+ * Defaults to the 'logLevel' property of your Vite config
281
266
  */
282
267
  logLevel?: LogLevel,
283
268
 
284
269
  /**
285
- * Hook after diagnostic emitted
270
+ * Hook called after diagnostic is emitted
286
271
  *
287
- * According to the length to judge whether there is any type error
272
+ * According to the `diagnostics.length`, you can judge whether there is any type error
288
273
  *
289
274
  * @default () => {}
290
275
  */
291
276
  afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>,
292
277
 
293
278
  /**
294
- * Hook before each declaration file is written
279
+ * Hook called prior to writing each declaration file
295
280
  *
296
- * You can transform declaration file's path and content through it
281
+ * This allows you to transform the path or content
297
282
  *
298
- * The file will be skipped when return exact `false`
283
+ * The file will be skipped when the return value `false`
299
284
  *
300
285
  * @default () => {}
301
286
  */
@@ -311,9 +296,7 @@ export interface PluginOptions {
311
296
  },
312
297
 
313
298
  /**
314
- * Hook after built
315
- *
316
- * It wil be called after all declaration files are written
299
+ * Hook called after all declaration files are written
317
300
  *
318
301
  * @default () => {}
319
302
  */
package/README.zh-CN.md CHANGED
@@ -8,6 +8,9 @@
8
8
  <a href="https://www.npmjs.com/package/vite-plugin-dts">
9
9
  <img src="https://img.shields.io/npm/v/vite-plugin-dts?color=orange&label=" alt="version" />
10
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>
11
14
  </p>
12
15
 
13
16
  **中文** | [English](./README.md)
@@ -40,34 +43,7 @@ export default defineConfig({
40
43
  })
41
44
  ```
42
45
 
43
- 在你的组件中:
44
-
45
- ```vue
46
- <template>
47
- <div></div>
48
- </template>
49
-
50
- <script lang="ts">
51
- // 使用 defineComponent 来进行类型推断
52
- import { defineComponent } from 'vue'
53
-
54
- export default defineComponent({
55
- name: 'Component'
56
- })
57
- </script>
58
- ```
59
-
60
- ```vue
61
- <script setup lang="ts">
62
- defineProps<{
63
- color: 'blue' | 'red'
64
- }>()
65
- </script>
66
-
67
- <template>
68
- <div>{{ color }}</div>
69
- </template>
70
- ```
46
+ 从 `3.0.0` 开始,你可以在 Rollup 中使用该插件。
71
47
 
72
48
  ## 常见问题
73
49
 
@@ -116,16 +92,19 @@ export interface Resolver {
116
92
  */
117
93
  name: string,
118
94
  /**
119
- * 决定是否要解析文件
95
+ * 判断解析器是否支持该文件
120
96
  */
121
97
  supports: (id: string) => void | boolean,
122
98
  /**
123
99
  * 将源文件转换为类型文件
100
+ *
101
+ * 注意,返回的文件的路径应该基于 `outDir`,或者相对于 `root`
124
102
  */
125
103
  transform: (payload: {
126
104
  id: string,
127
105
  code: string,
128
106
  root: string,
107
+ outDir: string,
129
108
  host: ts.CompilerHost,
130
109
  program: ts.Program,
131
110
  service: ts.LanguageService
@@ -136,7 +115,7 @@ export interface PluginOptions {
136
115
  /**
137
116
  * 指定根目录
138
117
  *
139
- * 默认基于 Vite 配置的 'root',使用 Rollup 时基于 `process.cwd()`
118
+ * 默认为 Vite 配置的 'root',使用 Rollup `process.cwd()`
140
119
  */
141
120
  root?: string,
142
121
 
@@ -145,30 +124,30 @@ export interface PluginOptions {
145
124
  *
146
125
  * 可以指定一个数组来输出到多个目录中
147
126
  *
148
- * 默认基于 Vite 配置的 'build.outDir',使用 Rollup 时基于 tsconfig.json 的 `outDir`
127
+ * 默认为 Vite 配置的 'build.outDir',使用 Rollup 时为 tsconfig.json 的 `outDir`
149
128
  */
150
129
  outDir?: string | string[],
151
130
 
152
131
  /**
153
- * 用于手动设置入口文件的根路径,通常用在 monorepo
132
+ * 用于手动设置入口文件的根路径(通常用在 monorepo
154
133
  *
155
134
  * 在计算每个文件的输出路径时将基于该路径
156
135
  *
157
- * 默认为所有文件的最小公共路径
136
+ * 默认为所有源文件的最小公共路径
158
137
  */
159
138
  entryRoot?: string,
160
139
 
161
140
  /**
162
- * 严格限制类型文件生产在 `outDir` 内
141
+ * 限制类型文件生成在 `outDir` 内
163
142
  *
164
- * 由于当指定了 `entryRoot` 时,类型文件有可能位于 `outDir` 之外
143
+ * 如果为 `true`,生成在 `outDir` 外的文件将被忽略
165
144
  *
166
145
  * @default true
167
146
  */
168
147
  strictOutput?: boolean,
169
148
 
170
149
  /**
171
- * 指定一个用于覆写的 CompilerOptions
150
+ * 覆写 CompilerOptions
172
151
  *
173
152
  * @default null
174
153
  */
@@ -177,9 +156,9 @@ export interface PluginOptions {
177
156
  /**
178
157
  * 指定 tsconfig.json 的路径
179
158
  *
180
- * 插件也会解析 tsconfig.json 的 include 和 exclude 选项
159
+ * 插件会解析 tsconfig.json 的 include 和 exclude 选项
181
160
  *
182
- * 未指定时插件默认从根目录寻找配置
161
+ * 未指定时插件默认从根目录开始寻找配置文件
183
162
  */
184
163
  tsconfigPath?: string,
185
164
 
@@ -190,6 +169,16 @@ export interface PluginOptions {
190
169
  */
191
170
  resolvers?: Resolver[],
192
171
 
172
+ /**
173
+ * 解析 tsconfig.json 的 `paths` 作为别名
174
+ *
175
+ * 注意,这些别名仅用在类型文件中使用
176
+ *
177
+ * @default true
178
+ * @remarks 只使用每个路径的第一个替换
179
+ */
180
+ pathsToAliases?: boolean,
181
+
193
182
  /**
194
183
  * 设置在转换别名时哪些路径需要排除
195
184
  *
@@ -205,12 +194,10 @@ export interface PluginOptions {
205
194
  cleanVueFileName?: boolean,
206
195
 
207
196
  /**
208
- * 是否将动态引入转换为静态
197
+ * 是否将动态引入转换为静态(例如:`import('vue').DefineComponent` 转换为 `import { DefineComponent } from 'vue'`)
209
198
  *
210
199
  * 开启 `rollupTypes` 时强制为 `true`
211
200
  *
212
- * 例如将 `import('vue').DefineComponent` 转换为 `import { DefineComponent } from 'vue'`
213
- *
214
201
  * @default false
215
202
  */
216
203
  staticImport?: boolean,
@@ -230,18 +217,18 @@ export interface PluginOptions {
230
217
  exclude?: string | string[],
231
218
 
232
219
  /**
233
- * 是否移除那些 `import 'xxx'`
220
+ * 是否移除 `import 'xxx'`
234
221
  *
235
222
  * @default true
236
223
  */
237
224
  clearPureImport?: boolean,
238
225
 
239
226
  /**
240
- * 是否生成类型声明入口
227
+ * 是否生成类型入口文件
241
228
  *
242
- * 当为 `true` 时会基于 package.json 的 types 字段生成,或者 `${outDir}/index.d.ts`
229
+ * 当为 `true` 时会基于 package.json 的 `types` 字段生成,或者 `${outDir}/index.d.ts`
243
230
  *
244
- * 当开启打包类型文件时强制为 `true`
231
+ * 当开启 `rollupTypes` 时强制为 `true`
245
232
  *
246
233
  * @default false
247
234
  */
@@ -250,7 +237,7 @@ export interface PluginOptions {
250
237
  /**
251
238
  * 设置是否在发出类型文件后将其打包
252
239
  *
253
- * 基于 `@microsoft/api-extractor`,由于这开启了一个新的进程,将会消耗一些时间
240
+ * 基于 `@microsoft/api-extractor`,过程将会消耗一些时间
254
241
  *
255
242
  * @default false
256
243
  */
@@ -268,7 +255,7 @@ export interface PluginOptions {
268
255
  * 是否将源码里的 .d.ts 文件复制到 `outDir`
269
256
  *
270
257
  * @default false
271
- * @remarks 在 2.0 之前它默认为 true
258
+ * @remarks 在 2.0 之前它默认为 `true`
272
259
  */
273
260
  copyDtsFiles?: boolean,
274
261
 
@@ -282,7 +269,7 @@ export interface PluginOptions {
282
269
  /**
283
270
  * 获取诊断信息后的钩子
284
271
  *
285
- * 可以根据参数 length 来判断有误类型错误
272
+ * 可以根据 `diagnostics.length` 来判断有误类型错误
286
273
  *
287
274
  * @default () => {}
288
275
  */
@@ -309,9 +296,7 @@ export interface PluginOptions {
309
296
  },
310
297
 
311
298
  /**
312
- * 构建后回调钩子
313
- *
314
- * 将会在所有类型文件被写入后调用
299
+ * 在所有类型文件被写入后调用的钩子
315
300
  *
316
301
  * @default () => {}
317
302
  */
package/dist/index.cjs CHANGED
@@ -114,6 +114,30 @@ function rollupDeclarationFiles({
114
114
  );
115
115
  }
116
116
 
117
+ const jsonRE = /\.json$/;
118
+ function JsonResolver() {
119
+ return {
120
+ name: "json",
121
+ supports(id) {
122
+ return jsonRE.test(id);
123
+ },
124
+ transform({ id, root, program }) {
125
+ const sourceFile = program.getSourceFile(id);
126
+ if (!sourceFile)
127
+ return [];
128
+ return [
129
+ {
130
+ path: node_path.relative(root, `${id}.d.ts`),
131
+ content: `declare const _default: ${sourceFile.text};
132
+
133
+ export default _default;
134
+ `
135
+ }
136
+ ];
137
+ }
138
+ };
139
+ }
140
+
117
141
  const svelteRE = /\.svelte$/;
118
142
  function SvelteResolver() {
119
143
  return {
@@ -121,17 +145,46 @@ function SvelteResolver() {
121
145
  supports(id) {
122
146
  return svelteRE.test(id);
123
147
  },
124
- transform({ id }) {
148
+ transform({ id, root }) {
125
149
  return [
126
150
  {
127
- path: `${id}.d.ts`,
128
- content: "export { SvelteComponentTyped as default } from 'svelte';"
151
+ path: node_path.relative(root, `${id}.d.ts`),
152
+ content: "export { SvelteComponentTyped as default } from 'svelte';\n"
129
153
  }
130
154
  ];
131
155
  }
132
156
  };
133
157
  }
134
158
 
159
+ const vueRE = /\.vue$/;
160
+ function VueResolver() {
161
+ return {
162
+ name: "vue",
163
+ supports(id) {
164
+ return vueRE.test(id);
165
+ },
166
+ transform({ id, program, service }) {
167
+ const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
168
+ if (!sourceFile)
169
+ return [];
170
+ return service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
171
+ return {
172
+ path: file.name,
173
+ content: file.text
174
+ };
175
+ });
176
+ }
177
+ };
178
+ }
179
+
180
+ function parseResolvers(resolvers) {
181
+ const nameMap = /* @__PURE__ */ new Map();
182
+ for (const resolver of resolvers) {
183
+ resolver.name && nameMap.set(resolver.name, resolver);
184
+ }
185
+ return Array.from(nameMap.values());
186
+ }
187
+
135
188
  const windowsSlashRE = /\\+/g;
136
189
  function slash(p) {
137
190
  return p.replace(windowsSlashRE, "/");
@@ -232,38 +285,6 @@ function removeDirIfEmpty(dir) {
232
285
  return onlyHasDir;
233
286
  }
234
287
 
235
- const vueRE = /\.vue$/;
236
- function VueResolver() {
237
- return {
238
- name: "vue",
239
- supports(id) {
240
- return vueRE.test(id);
241
- },
242
- transform({ id, root, program, service }) {
243
- let sourceFile = program.getSourceFile(id);
244
- if (!sourceFile && vueRE.test(id)) {
245
- sourceFile = program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
246
- }
247
- if (!sourceFile)
248
- return [];
249
- return service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
250
- return {
251
- path: resolve(root, file.name),
252
- content: file.text
253
- };
254
- });
255
- }
256
- };
257
- }
258
-
259
- function parseResolvers(resolvers) {
260
- const nameMap = /* @__PURE__ */ new Map();
261
- for (const resolver of resolvers) {
262
- resolver.name && nameMap.set(resolver.name, resolver);
263
- }
264
- return Array.from(nameMap.values());
265
- }
266
-
267
288
  const globSuffixRE = /^((?:.*\.[^.]+)|(?:\*+))$/;
268
289
  function normalizeGlob(path) {
269
290
  if (/[\\/]$/.test(path)) {
@@ -396,6 +417,7 @@ function dtsPlugin(options = {}) {
396
417
  insertTypesEntry = false,
397
418
  rollupTypes = false,
398
419
  bundledPackages = [],
420
+ pathsToAliases = true,
399
421
  aliasesExclude = [],
400
422
  copyDtsFiles = false,
401
423
  strictOutput = true,
@@ -422,7 +444,12 @@ function dtsPlugin(options = {}) {
422
444
  let filter;
423
445
  let bundled = false;
424
446
  let timeRecord = 0;
425
- const resolvers = parseResolvers([VueResolver(), SvelteResolver(), ...options.resolvers || []]);
447
+ const resolvers = parseResolvers([
448
+ JsonResolver(),
449
+ VueResolver(),
450
+ SvelteResolver(),
451
+ ...options.resolvers || []
452
+ ]);
426
453
  const rootFiles = /* @__PURE__ */ new Set();
427
454
  const outputFiles = /* @__PURE__ */ new Map();
428
455
  return {
@@ -441,7 +468,7 @@ function dtsPlugin(options = {}) {
441
468
  if (aliasesExclude.length > 0) {
442
469
  aliases = aliases.filter(
443
470
  ({ find }) => !aliasesExclude.some(
444
- (alias) => alias && (isRegExp(find) ? find.toString() === alias.toString() : isRegExp(alias) ? find.match(alias)?.[0] : find === alias)
471
+ (aliasExclude) => aliasExclude && (isRegExp(find) ? find.toString() === aliasExclude.toString() : isRegExp(aliasExclude) ? find.match(aliasExclude)?.[0] : find === aliasExclude)
445
472
  )
446
473
  );
447
474
  }
@@ -497,6 +524,7 @@ ${kolorist.cyan(
497
524
  entries = { ...input };
498
525
  }
499
526
  logger = logger || console;
527
+ aliases = aliases || [];
500
528
  libName = "_default";
501
529
  indexName = defaultIndex;
502
530
  bundleDebug("parse options");
@@ -519,12 +547,28 @@ ${kolorist.cyan(
519
547
  if (!outDirs) {
520
548
  outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
521
549
  }
550
+ const { baseUrl, paths } = compilerOptions;
551
+ if (pathsToAliases && baseUrl && paths) {
552
+ const basePath = ensureAbsolute(baseUrl, configPath ? node_path.dirname(configPath) : root);
553
+ const existsFinds = new Set(
554
+ aliases.map((alias) => alias.find).filter((find) => typeof find === "string")
555
+ );
556
+ for (const [findWithAsterisk, replacements] of Object.entries(paths)) {
557
+ const find = findWithAsterisk.replace("/*", "");
558
+ if (!replacements.length || existsFinds.has(find))
559
+ continue;
560
+ aliases.push({
561
+ find,
562
+ replacement: ensureAbsolute(replacements[0].replace("/*", ""), basePath)
563
+ });
564
+ }
565
+ }
522
566
  include = ensureArray(options.include ?? content?.raw.include ?? "**/*").map(normalizeGlob);
523
567
  exclude = ensureArray(options.exclude ?? content?.raw.exclude ?? "node_modules/**").map(
524
568
  normalizeGlob
525
569
  );
526
570
  filter = pluginutils.createFilter(include, exclude, { resolve: root });
527
- const rootNames = Object.values(entries).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
571
+ const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
528
572
  host = ts__default.createCompilerHost(compilerOptions, true);
529
573
  program = vueTsc.createProgram({ host, rootNames, options: compilerOptions });
530
574
  libName = libName || "_default";
@@ -560,6 +604,7 @@ ${kolorist.cyan(
560
604
  return;
561
605
  }
562
606
  const startTime = Date.now();
607
+ const outDir = outDirs[0];
563
608
  const service = program.__vue.languageService;
564
609
  rootFiles.delete(id);
565
610
  if (resolver) {
@@ -567,18 +612,25 @@ ${kolorist.cyan(
567
612
  id,
568
613
  code,
569
614
  root: publicRoot,
615
+ outDir,
570
616
  host,
571
617
  program,
572
618
  service
573
619
  });
574
620
  for (const { path, content } of result) {
575
- outputFiles.set(ensureAbsolute(path, publicRoot), content);
621
+ outputFiles.set(
622
+ resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(path, outDir))),
623
+ content
624
+ );
576
625
  }
577
626
  } else {
578
627
  const sourceFile = program.getSourceFile(id);
579
628
  if (sourceFile) {
580
629
  for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
581
- outputFiles.set(resolve(publicRoot, outputFile.name), outputFile.text);
630
+ outputFiles.set(
631
+ resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(outputFile.name, outDir))),
632
+ outputFile.text
633
+ );
582
634
  }
583
635
  }
584
636
  }
@@ -633,7 +685,10 @@ ${logPrefix} Start generate declaration files...`));
633
685
  }
634
686
  if (rootFiles.has(sourceFile.fileName)) {
635
687
  for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
636
- outputFiles.set(resolve(publicRoot, outputFile.name), outputFile.text);
688
+ outputFiles.set(
689
+ resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(outputFile.name, outDir))),
690
+ outputFile.text
691
+ );
637
692
  }
638
693
  rootFiles.delete(sourceFile.fileName);
639
694
  }
package/dist/index.d.ts CHANGED
@@ -11,16 +11,19 @@ interface Resolver {
11
11
  */
12
12
  name: string;
13
13
  /**
14
- * Determine whether the resolve supports the file
14
+ * Determine whether the resolver supports the file
15
15
  */
16
16
  supports: (id: string) => void | boolean;
17
17
  /**
18
- * Transform the source file to declaration files
18
+ * Transform source to declaration files
19
+ *
20
+ * Note that the path of the returns should base on `outDir`, or relative path to `root`
19
21
  */
20
22
  transform: (payload: {
21
23
  id: string;
22
24
  code: string;
23
25
  root: string;
26
+ outDir: string;
24
27
  host: ts.CompilerHost;
25
28
  program: ts.Program;
26
29
  service: ts.LanguageService;
@@ -33,35 +36,35 @@ interface PluginOptions {
33
36
  /**
34
37
  * Specify root directory
35
38
  *
36
- * By Default it base on 'root' of your Vite config, or `process.cwd()` if using Rollup
39
+ * Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
37
40
  */
38
41
  root?: string;
39
42
  /**
40
- * Specify declaration files output directory
43
+ * Output directory for declaration files
41
44
  *
42
- * Can be specified a array to output to multiple directories
45
+ * Can be an array to output to multiple directories
43
46
  *
44
- * By Default it base on 'build.outDir' of your Vite config, or `outDir` of tsconfig.json if using Rollup
47
+ * Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
45
48
  */
46
49
  outDir?: string | string[];
47
50
  /**
48
- * Manually set the root path of the entry files, useful in monorepo
51
+ * Override root path of entry files (useful in monorepos)
49
52
  *
50
- * The output path of each file will be calculated base on it
53
+ * The output path of each file will be calculated based on the value provided
51
54
  *
52
- * By Default it is the smallest public path for all files
55
+ * The default is the smallest public path for all source files
53
56
  */
54
57
  entryRoot?: string;
55
58
  /**
56
- * Strictly restrict declaration files output inside `outDir`
59
+ * Restrict declaration files output to `outDir`
57
60
  *
58
- * Because if `entryRoot` is specified, declaration files maybe outside `outDir`
61
+ * If true, generated declaration files outside `outDir` will be ignored
59
62
  *
60
63
  * @default true
61
64
  */
62
65
  strictOutput?: boolean;
63
66
  /**
64
- * Specify a CompilerOptions to override
67
+ * Override compilerOptions
65
68
  *
66
69
  * @default null
67
70
  */
@@ -69,9 +72,9 @@ interface PluginOptions {
69
72
  /**
70
73
  * Specify tsconfig.json path
71
74
  *
72
- * Plugin also resolve include and exclude files from tsconfig.json
75
+ * Plugin resolves `include` and `exclude` globs from tsconfig.json
73
76
  *
74
- * By default plugin will find config form root if not specify
77
+ * If not specified, plugin will find config file from root
75
78
  */
76
79
  tsconfigPath?: string;
77
80
  /**
@@ -81,61 +84,66 @@ interface PluginOptions {
81
84
  */
82
85
  resolvers?: Resolver[];
83
86
  /**
84
- * Set which paths should exclude when transform aliases
87
+ * Parsing `paths` of tsconfig.json to aliases
85
88
  *
86
- * If it's regexp, it will test the original import path directly
89
+ * Note that these aliases only use for declaration files
90
+ *
91
+ * @default true
92
+ * @remarks Only use first replacement of each path
93
+ */
94
+ pathsToAliases?: boolean;
95
+ /**
96
+ * Set which paths should be excluded when transforming aliases
87
97
  *
88
98
  * @default []
89
99
  */
90
100
  aliasesExclude?: (string | RegExp)[];
91
101
  /**
92
- * Whether transform file name '.vue.d.ts' to '.d.ts'
102
+ * Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
93
103
  *
94
104
  * @default false
95
105
  */
96
106
  cleanVueFileName?: boolean;
97
107
  /**
98
- * Whether transform dynamic import to static
99
- *
100
- * Force `true` when `rollupTypes` is effective
108
+ * Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
101
109
  *
102
- * eg. `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`
110
+ * Value is forced to `true` when `rollupTypes` is `true`
103
111
  *
104
112
  * @default false
105
113
  */
106
114
  staticImport?: boolean;
107
115
  /**
108
- * Manual set include glob
116
+ * Override `include` glob
109
117
  *
110
- * By Default it base on `include` option of the tsconfig.json
118
+ * Defaults to `include` property of tsconfig.json
111
119
  */
112
120
  include?: string | string[];
113
121
  /**
114
- * Manual set exclude glob
122
+ * Override `exclude` glob
115
123
  *
116
- * By Default it base on `exclude` option of the tsconfig.json, be `'node_module/**'` when empty
124
+ * Defaults to `exclude` property of tsconfig.json or `'node_module/**'` if not supplied.
117
125
  */
118
126
  exclude?: string | string[];
119
127
  /**
120
- * Whether remove those `import 'xxx'`
128
+ * Whether to remove `import 'xxx'`
121
129
  *
122
130
  * @default true
123
131
  */
124
132
  clearPureImport?: boolean;
125
133
  /**
126
- * Whether generate types entry file
134
+ * Whether to generate types entry file(s)
127
135
  *
128
- * When `true` will from package.json types field if exists or `` `${outDir}/index.d.ts` ``
136
+ * When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
129
137
  *
130
- * Force `true` when `rollupTypes` is effective
138
+ * Value is forced to `true` when `rollupTypes` is `true`
131
139
  *
132
140
  * @default false
133
141
  */
134
142
  insertTypesEntry?: boolean;
135
143
  /**
136
- * Set whether rollup declaration files after emit
144
+ * Rollup type declaration files after emitting them
137
145
  *
138
- * Power by `@microsoft/api-extractor`, it will start a new program which takes some time
146
+ * Powered by `@microsoft/api-extractor` - time-intensive operation
139
147
  *
140
148
  * @default false
141
149
  */
@@ -148,32 +156,32 @@ interface PluginOptions {
148
156
  */
149
157
  bundledPackages?: string[];
150
158
  /**
151
- * Whether copy .d.ts source files into `outDir`
159
+ * Whether to copy .d.ts source files to `outDir`
152
160
  *
153
161
  * @default false
154
- * @remarks Before 2.0 it defaults to true
162
+ * @remarks Before 2.0, the default was `true`
155
163
  */
156
164
  copyDtsFiles?: boolean;
157
165
  /**
158
- * Specify the log level of plugin
166
+ * Logging level for this plugin
159
167
  *
160
- * By Default it base on 'logLevel' option of your Vite config
168
+ * Defaults to the 'logLevel' property of your Vite config
161
169
  */
162
170
  logLevel?: LogLevel;
163
171
  /**
164
- * Hook after diagnostic emitted
172
+ * Hook called after diagnostic is emitted
165
173
  *
166
- * According to the length to judge whether there is any type error
174
+ * According to the `diagnostics.length`, you can judge whether there is any type error
167
175
  *
168
176
  * @default () => {}
169
177
  */
170
178
  afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
171
179
  /**
172
- * Hook before each declaration file is written
180
+ * Hook called prior to writing each declaration file
173
181
  *
174
- * You can transform declaration file's path and content through it
182
+ * This allows you to transform the path or content
175
183
  *
176
- * The file will be skipped when return exact `false`
184
+ * The file will be skipped when the return value `false`
177
185
  *
178
186
  * @default () => {}
179
187
  */
@@ -182,9 +190,7 @@ interface PluginOptions {
182
190
  content?: string;
183
191
  };
184
192
  /**
185
- * Hook after built
186
- *
187
- * It wil be called after all declaration files are written
193
+ * Hook called after all declaration files are written
188
194
  *
189
195
  * @default () => {}
190
196
  */
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import __cjs_mod__ from 'module';
5
5
  const __filename = __cjs_url__.fileURLToPath(import.meta.url);
6
6
  const __dirname = __cjs_path__.dirname(__filename);
7
7
  const require = __cjs_mod__.createRequire(import.meta.url);
8
- import { resolve as resolve$1, posix, isAbsolute, dirname, normalize, sep, relative, basename } from 'node:path';
8
+ import { resolve as resolve$1, relative, posix, isAbsolute, dirname, normalize, sep, basename } from 'node:path';
9
9
  import { existsSync, readdirSync, lstatSync, rmdirSync } from 'node:fs';
10
10
  import { readFile, mkdir, writeFile, unlink } from 'node:fs/promises';
11
11
  import { cpus } from 'node:os';
@@ -114,6 +114,30 @@ function rollupDeclarationFiles({
114
114
  );
115
115
  }
116
116
 
117
+ const jsonRE = /\.json$/;
118
+ function JsonResolver() {
119
+ return {
120
+ name: "json",
121
+ supports(id) {
122
+ return jsonRE.test(id);
123
+ },
124
+ transform({ id, root, program }) {
125
+ const sourceFile = program.getSourceFile(id);
126
+ if (!sourceFile)
127
+ return [];
128
+ return [
129
+ {
130
+ path: relative(root, `${id}.d.ts`),
131
+ content: `declare const _default: ${sourceFile.text};
132
+
133
+ export default _default;
134
+ `
135
+ }
136
+ ];
137
+ }
138
+ };
139
+ }
140
+
117
141
  const svelteRE = /\.svelte$/;
118
142
  function SvelteResolver() {
119
143
  return {
@@ -121,17 +145,46 @@ function SvelteResolver() {
121
145
  supports(id) {
122
146
  return svelteRE.test(id);
123
147
  },
124
- transform({ id }) {
148
+ transform({ id, root }) {
125
149
  return [
126
150
  {
127
- path: `${id}.d.ts`,
128
- content: "export { SvelteComponentTyped as default } from 'svelte';"
151
+ path: relative(root, `${id}.d.ts`),
152
+ content: "export { SvelteComponentTyped as default } from 'svelte';\n"
129
153
  }
130
154
  ];
131
155
  }
132
156
  };
133
157
  }
134
158
 
159
+ const vueRE = /\.vue$/;
160
+ function VueResolver() {
161
+ return {
162
+ name: "vue",
163
+ supports(id) {
164
+ return vueRE.test(id);
165
+ },
166
+ transform({ id, program, service }) {
167
+ const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
168
+ if (!sourceFile)
169
+ return [];
170
+ return service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
171
+ return {
172
+ path: file.name,
173
+ content: file.text
174
+ };
175
+ });
176
+ }
177
+ };
178
+ }
179
+
180
+ function parseResolvers(resolvers) {
181
+ const nameMap = /* @__PURE__ */ new Map();
182
+ for (const resolver of resolvers) {
183
+ resolver.name && nameMap.set(resolver.name, resolver);
184
+ }
185
+ return Array.from(nameMap.values());
186
+ }
187
+
135
188
  const windowsSlashRE = /\\+/g;
136
189
  function slash(p) {
137
190
  return p.replace(windowsSlashRE, "/");
@@ -232,38 +285,6 @@ function removeDirIfEmpty(dir) {
232
285
  return onlyHasDir;
233
286
  }
234
287
 
235
- const vueRE = /\.vue$/;
236
- function VueResolver() {
237
- return {
238
- name: "vue",
239
- supports(id) {
240
- return vueRE.test(id);
241
- },
242
- transform({ id, root, program, service }) {
243
- let sourceFile = program.getSourceFile(id);
244
- if (!sourceFile && vueRE.test(id)) {
245
- sourceFile = program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
246
- }
247
- if (!sourceFile)
248
- return [];
249
- return service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
250
- return {
251
- path: resolve(root, file.name),
252
- content: file.text
253
- };
254
- });
255
- }
256
- };
257
- }
258
-
259
- function parseResolvers(resolvers) {
260
- const nameMap = /* @__PURE__ */ new Map();
261
- for (const resolver of resolvers) {
262
- resolver.name && nameMap.set(resolver.name, resolver);
263
- }
264
- return Array.from(nameMap.values());
265
- }
266
-
267
288
  const globSuffixRE = /^((?:.*\.[^.]+)|(?:\*+))$/;
268
289
  function normalizeGlob(path) {
269
290
  if (/[\\/]$/.test(path)) {
@@ -396,6 +417,7 @@ function dtsPlugin(options = {}) {
396
417
  insertTypesEntry = false,
397
418
  rollupTypes = false,
398
419
  bundledPackages = [],
420
+ pathsToAliases = true,
399
421
  aliasesExclude = [],
400
422
  copyDtsFiles = false,
401
423
  strictOutput = true,
@@ -422,7 +444,12 @@ function dtsPlugin(options = {}) {
422
444
  let filter;
423
445
  let bundled = false;
424
446
  let timeRecord = 0;
425
- const resolvers = parseResolvers([VueResolver(), SvelteResolver(), ...options.resolvers || []]);
447
+ const resolvers = parseResolvers([
448
+ JsonResolver(),
449
+ VueResolver(),
450
+ SvelteResolver(),
451
+ ...options.resolvers || []
452
+ ]);
426
453
  const rootFiles = /* @__PURE__ */ new Set();
427
454
  const outputFiles = /* @__PURE__ */ new Map();
428
455
  return {
@@ -441,7 +468,7 @@ function dtsPlugin(options = {}) {
441
468
  if (aliasesExclude.length > 0) {
442
469
  aliases = aliases.filter(
443
470
  ({ find }) => !aliasesExclude.some(
444
- (alias) => alias && (isRegExp(find) ? find.toString() === alias.toString() : isRegExp(alias) ? find.match(alias)?.[0] : find === alias)
471
+ (aliasExclude) => aliasExclude && (isRegExp(find) ? find.toString() === aliasExclude.toString() : isRegExp(aliasExclude) ? find.match(aliasExclude)?.[0] : find === aliasExclude)
445
472
  )
446
473
  );
447
474
  }
@@ -497,6 +524,7 @@ ${cyan(
497
524
  entries = { ...input };
498
525
  }
499
526
  logger = logger || console;
527
+ aliases = aliases || [];
500
528
  libName = "_default";
501
529
  indexName = defaultIndex;
502
530
  bundleDebug("parse options");
@@ -519,12 +547,28 @@ ${cyan(
519
547
  if (!outDirs) {
520
548
  outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
521
549
  }
550
+ const { baseUrl, paths } = compilerOptions;
551
+ if (pathsToAliases && baseUrl && paths) {
552
+ const basePath = ensureAbsolute(baseUrl, configPath ? dirname(configPath) : root);
553
+ const existsFinds = new Set(
554
+ aliases.map((alias) => alias.find).filter((find) => typeof find === "string")
555
+ );
556
+ for (const [findWithAsterisk, replacements] of Object.entries(paths)) {
557
+ const find = findWithAsterisk.replace("/*", "");
558
+ if (!replacements.length || existsFinds.has(find))
559
+ continue;
560
+ aliases.push({
561
+ find,
562
+ replacement: ensureAbsolute(replacements[0].replace("/*", ""), basePath)
563
+ });
564
+ }
565
+ }
522
566
  include = ensureArray(options.include ?? content?.raw.include ?? "**/*").map(normalizeGlob);
523
567
  exclude = ensureArray(options.exclude ?? content?.raw.exclude ?? "node_modules/**").map(
524
568
  normalizeGlob
525
569
  );
526
570
  filter = createFilter(include, exclude, { resolve: root });
527
- const rootNames = Object.values(entries).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
571
+ const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
528
572
  host = ts.createCompilerHost(compilerOptions, true);
529
573
  program = createProgram({ host, rootNames, options: compilerOptions });
530
574
  libName = libName || "_default";
@@ -560,6 +604,7 @@ ${cyan(
560
604
  return;
561
605
  }
562
606
  const startTime = Date.now();
607
+ const outDir = outDirs[0];
563
608
  const service = program.__vue.languageService;
564
609
  rootFiles.delete(id);
565
610
  if (resolver) {
@@ -567,18 +612,25 @@ ${cyan(
567
612
  id,
568
613
  code,
569
614
  root: publicRoot,
615
+ outDir,
570
616
  host,
571
617
  program,
572
618
  service
573
619
  });
574
620
  for (const { path, content } of result) {
575
- outputFiles.set(ensureAbsolute(path, publicRoot), content);
621
+ outputFiles.set(
622
+ resolve(publicRoot, relative(outDir, ensureAbsolute(path, outDir))),
623
+ content
624
+ );
576
625
  }
577
626
  } else {
578
627
  const sourceFile = program.getSourceFile(id);
579
628
  if (sourceFile) {
580
629
  for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
581
- outputFiles.set(resolve(publicRoot, outputFile.name), outputFile.text);
630
+ outputFiles.set(
631
+ resolve(publicRoot, relative(outDir, ensureAbsolute(outputFile.name, outDir))),
632
+ outputFile.text
633
+ );
582
634
  }
583
635
  }
584
636
  }
@@ -633,7 +685,10 @@ ${logPrefix} Start generate declaration files...`));
633
685
  }
634
686
  if (rootFiles.has(sourceFile.fileName)) {
635
687
  for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
636
- outputFiles.set(resolve(publicRoot, outputFile.name), outputFile.text);
688
+ outputFiles.set(
689
+ resolve(publicRoot, relative(outDir, ensureAbsolute(outputFile.name, outDir))),
690
+ outputFile.text
691
+ );
637
692
  }
638
693
  rootFiles.delete(sourceFile.fileName);
639
694
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",
@@ -77,7 +77,6 @@
77
77
  "@vue/eslint-config-standard": "^8.0.1",
78
78
  "@vue/eslint-config-typescript": "^11.0.3",
79
79
  "conventional-changelog-cli": "^3.0.0",
80
- "cross-env": "^7.0.3",
81
80
  "eslint": "^8.43.0",
82
81
  "execa": "^7.1.1",
83
82
  "husky": "^8.0.3",