Skip to content

Commit 59c6e8b

Browse files
authored
feat(dts): support using output.distPath as dts emit path (#1269)
1 parent fc3d34c commit 59c6e8b

File tree

8 files changed

+15
-10
lines changed

8 files changed

+15
-10
lines changed

packages/plugin-dts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The output directory of declaration files. The default value follows the priorit
8989

9090
1. The `distPath` value of the plugin options.
9191
2. The `declarationDir` value in the `tsconfig.json` file.
92-
3. The [output.distPath.root](https://rsbuild.rs/config/output/dist-path) value of Rsbuild configuration.
92+
3. The [output.distPath](https://rsbuild.rs/config/output/dist-path) or [output.distPath.root](https://rsbuild.rs/config/output/dist-path) value of Rsbuild configuration.
9393

9494
```js
9595
pluginDts({

packages/plugin-dts/src/dts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
187187
throw Error(
188188
`Please set "declarationDir": "${dtsEmitPath}" in ${color.underline(
189189
tsconfigPath,
190-
)} to keep it same as "dts.distPath" or "output.distPath.root" field in lib config.`,
190+
)} to keep it same as "dts.distPath" or "output.distPath" field in lib config.`,
191191
);
192192
}
193193
}

packages/plugin-dts/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
144144
const { options: rawCompilerOptions } = tsConfigResult;
145145
const { declarationDir, outDir, composite, incremental } =
146146
rawCompilerOptions;
147+
const distPathRoot =
148+
typeof config.output?.distPath === 'string'
149+
? config.output?.distPath
150+
: config.output?.distPath.root;
151+
147152
const dtsEmitPath = getDtsEmitPath(
148153
options.distPath,
149154
declarationDir,
150-
config.output?.distPath?.root,
155+
distPathRoot,
151156
);
152157

153158
// check whether declarationDir or outDir is outside from current project

packages/plugin-dts/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,14 @@ export async function cleanTsBuildInfoFile(
655655
}
656656
}
657657

658-
// the priority of dtsEmitPath is dts.distPath > declarationDir > output.distPath.root
658+
// the priority of dtsEmitPath is dts.distPath > declarationDir > output.distPath > output.distPath.root
659659
// outDir is not considered since in multiple formats, the dts files may not in the same directory as the js files
660660
export function getDtsEmitPath(
661661
pathFromPlugin: string | undefined,
662662
declarationDir: string | undefined,
663-
distPath: string,
663+
distPathRoot: string,
664664
): string {
665-
return pathFromPlugin ?? declarationDir ?? distPath;
665+
return pathFromPlugin ?? declarationDir ?? distPathRoot;
666666
}
667667

668668
export function warnIfOutside(

website/docs/en/config/lib/dts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ The default value follows the priority below:
136136

137137
1. The `dts.distPath` value in the current lib configuration.
138138
2. The `declarationDir` value in the `tsconfig.json` file.
139-
3. The [output.distPath.root](/config/rsbuild/output#outputdistpath) value in the current lib configuration.
139+
3. The [output.distPath](/config/rsbuild/output#outputdistpath) or [output.distPath.root](/config/rsbuild/output#outputdistpath) value in the current lib configuration.
140140

141141
#### Example
142142

website/docs/en/guide/advanced/dts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ The priority from highest to lowest of final output directory of declaration fil
149149

150150
- The configuration option [dts.distPath](/config/lib/dts#dtsdistpath)
151151
- The configuration option `declarationDir` in `tsconfig.json`
152-
- The configuration option [output.distPath.root](/config/rsbuild/output#outputdistpath)
152+
- The configuration option [output.distPath](/config/rsbuild/output#outputdistpath) or [output.distPath.root](/config/rsbuild/output#outputdistpath)
153153

154154
## Related configuration of declaration files
155155

website/docs/zh/config/lib/dts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default {
136136

137137
1. 当前 lib 配置中的 `dts.distPath` 值。
138138
2. `tsconfig.json` 文件中的 `declarationDir` 值。
139-
3. 当前 lib 配置中的 [output.distPath.root](/config/rsbuild/output#outputdistpath) 值。
139+
3. 当前 lib 配置中的 [output.distPath](/config/rsbuild/output#outputdistpath) 值或 [output.distPath.root](/config/rsbuild/output#outputdistpath) 值。
140140

141141
#### 示例
142142

website/docs/zh/guide/advanced/dts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) 或 [t
152152

153153
- [dts.distPath](/config/lib/dts#dtsdistpath) 配置项
154154
- `tsconfig.json` 中的 `declarationDir` 配置项
155-
- [output.distPath.root](/config/rsbuild/output#outputdistpath) 配置项
155+
- [output.distPath](/config/rsbuild/output#outputdistpath)[output.distPath.root](/config/rsbuild/output#outputdistpath) 配置项
156156

157157
## 类型声明文件的相关配置
158158

0 commit comments

Comments
 (0)