Skip to content

Commit 024689f

Browse files
committed
feat: add processor option to specify program processor
fix #436 BREAKING CHANGE: The plugin will no longer heuristically detect Vue dependencies to determine whether to use @vue/language-core for creating the program. You now need to explicitly specify the processor option to tell the plugin which method to use for program creation.
1 parent 8ce589a commit 024689f

File tree

15 files changed

+96
-47
lines changed

15 files changed

+96
-47
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,18 @@ If you start with official Vite template, you should specify the `tsconfigPath`:
245245
}
246246
```
247247

248-
One more, if you are using it in a **Vue project**, you need to install `@vue/language-core` as a peer dependency for the plugin:
248+
One more, if you are using it in a **Vue project**, you need to install `@vue/language-core` as a peer dependency, and specify `processor` to `'vue'` for the plugin:
249249

250250
```sh
251251
pnpm i -D @vue/language-core
252252
```
253253

254+
```ts
255+
{
256+
plugins: [dts({ processor: 'vue' })]
257+
}
258+
```
259+
254260
## FAQ
255261

256262
Here are some FAQ's and solutions.
@@ -341,10 +347,17 @@ export interface Resolver {
341347
}
342348

343349
export interface PluginOptions {
350+
/**
351+
* Specify which (program) process you prefer.
352+
*
353+
* @default 'ts'
354+
*/
355+
processor?: 'vue' | 'ts',
356+
344357
/**
345358
* Specify root directory.
346359
*
347-
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup.
360+
* The default is to use the root provided by the scaffold; if none is provided, it defaults to `process.cwd()`.
348361
*/
349362
root?: string,
350363

README.zh-CN.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,18 @@ pnpm i -D @microsoft/api-extractor
245245
}
246246
```
247247

248-
还有一点,如果你正在一个 **Vue 项目** 中使用它,你需要安装 `@vue/language-core` 作为一个必要依赖:
248+
还有一点,如果你正在一个 **Vue 项目** 中使用它,你需要安装 `@vue/language-core` 作为一个必要依赖,并修改 `processor``'vue'`
249249

250250
```sh
251251
pnpm i -D @vue/language-core
252252
```
253253

254+
```ts
255+
{
256+
plugins: [dts({ processor: 'vue' })]
257+
}
258+
```
259+
254260
## 常见问题
255261

256262
此处将收录一些常见的问题并提供一些解决方案。
@@ -358,10 +364,17 @@ export interface Resolver {
358364
}
359365

360366
export interface PluginOptions {
367+
/**
368+
* 指定使用哪种处理程序
369+
*
370+
* @default 'ts'
371+
*/
372+
processor?: 'vue' | 'ts',
373+
361374
/**
362375
* 指定根目录
363376
*
364-
* 默认为 Vite 配置的 'root',使用 Rollup 为 `process.cwd()`
377+
* 默认使用脚手架提供的根目录,如果没提供则为 `process.cwd()`
365378
*/
366379
root?: string,
367380

examples/vue-rolldown/rolldown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default defineConfig({
2626
],
2727
plugins: [
2828
dts({
29+
processor: 'vue',
2930
outDirs: ['dist', 'types'],
3031
// include: ['src/index.ts'],
3132
exclude: ['src/ignore'],

examples/vue-rspack/rspack.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default defineConfig({
7373
mode: 'production',
7474
plugins: [
7575
dts({
76+
processor: 'vue',
7677
outDirs: ['dist', 'types'],
7778
// include: ['src/index.ts'],
7879
exclude: ['src/ignore'],

examples/vue-vite/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default defineConfig({
3434
plugins: [
3535
// @ts-ignore
3636
dts({
37+
processor: 'vue',
3738
copyDtsFiles: true,
3839
outDirs: [
3940
'dist',

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@commitlint/cli": "^19.8.0",
3333
"@commitlint/types": "^19.8.0",
3434
"@eslint/js": "^9.31.0",
35+
"@microsoft/api-extractor": "^7.52.9",
3536
"@rspack/core": "^1.3.9",
3637
"@types/debug": "^4.1.12",
3738
"@types/minimist": "^1.2.5",
@@ -42,6 +43,7 @@
4243
"@vexip-ui/eslint-config": "^1.2.1",
4344
"@vexip-ui/prettier-config": "^1.0.0",
4445
"@vexip-ui/scripts": "^1.4.1",
46+
"@vue/language-core": "^3.0.4",
4547
"conventional-changelog-cli": "^5.0.0",
4648
"eslint": "^9.31.0",
4749
"execa": "^9.5.2",

packages/unplugin-dts/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@
128128
"magic-string": "^0.30.17",
129129
"unplugin": "^2.3.2"
130130
},
131-
"devDependencies": {
132-
"@microsoft/api-extractor": "^7.52.5",
133-
"@vue/language-core": "~3.0.1"
134-
},
135131
"peerDependencies": {
136132
"@microsoft/api-extractor": ">=7",
137133
"@rspack/core": "^1",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type ts from 'typescript'
2+
3+
export interface ProgramProcessor {
4+
createParsedCommandLine: (_ts: typeof ts, host: ts.ParseConfigHost, configPath: string) => ts.ParsedCommandLine,
5+
createProgram: typeof ts.createProgram
6+
}
7+
8+
export async function loadProgramProcessor(type: 'vue' | 'ts' = 'ts'): Promise<ProgramProcessor> {
9+
if (type === 'vue') {
10+
return await import('./vue')
11+
}
12+
13+
return await import('./ts')
14+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)