File tree Expand file tree Collapse file tree 3 files changed +59
-2
lines changed
Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Original file line number Diff line number Diff line change 88 cleanDtsFiles ,
99 cleanTsBuildInfoFile ,
1010 clearTempDeclarationDir ,
11+ getDtsEmitPath ,
1112 loadTsconfig ,
1213 processSourceEntry ,
1314 warnIfOutside ,
@@ -115,8 +116,11 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
115116 rawCompilerOptions ;
116117 // the priority of dtsEmitPath is dts.distPath > declarationDir > output.distPath.root
117118 // outDir is not considered since in multiple formats, the dts files may not in the same directory as the js files
118- const dtsEmitPath =
119- options . distPath ?? declarationDir ?? config . output ?. distPath ?. root ;
119+ const dtsEmitPath = getDtsEmitPath (
120+ options . distPath ,
121+ declarationDir ,
122+ config . output ?. distPath ?. root ,
123+ ) ;
120124
121125 // check whether declarationDir or outDir is outside from current project
122126 warnIfOutside ( cwd , declarationDir , 'declarationDir' ) ;
Original file line number Diff line number Diff line change @@ -506,6 +506,14 @@ export async function cleanTsBuildInfoFile(
506506 }
507507}
508508
509+ export function getDtsEmitPath (
510+ pathFromPlugin : string | undefined ,
511+ declarationDir : string | undefined ,
512+ distPath : string ,
513+ ) : string {
514+ return pathFromPlugin ?? declarationDir ?? distPath ;
515+ }
516+
509517export function warnIfOutside (
510518 cwd : string ,
511519 dir : string | undefined ,
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+ import type { PluginDtsOptions } from '../src/index' ;
3+ import { getDtsEmitPath } from '../src/utils' ;
4+
5+ describe ( 'getDtsEmitPath' , ( ) => {
6+ const baseConfig = {
7+ output : {
8+ distPath : {
9+ root : '/dist-config' ,
10+ } ,
11+ } ,
12+ } ;
13+ const declarationDir = '/dist-declarationDir' ;
14+
15+ it ( 'should return options.distPath with the highest priority' , ( ) => {
16+ const options : PluginDtsOptions = {
17+ distPath : '/dist-options' ,
18+ } ;
19+ const result = getDtsEmitPath (
20+ options . distPath ,
21+ declarationDir ,
22+ baseConfig . output . distPath . root ,
23+ ) ;
24+ expect ( result ) . toBe ( '/dist-options' ) ;
25+ } ) ;
26+ it ( 'should return declarationDir when options.distPath is undefined' , ( ) => {
27+ const options : PluginDtsOptions = { } ;
28+ const result = getDtsEmitPath (
29+ options . distPath ,
30+ declarationDir ,
31+ baseConfig . output . distPath . root ,
32+ ) ;
33+ expect ( result ) . toBe ( '/dist-declarationDir' ) ;
34+ } ) ;
35+
36+ it ( 'should return config.output.distPath.root when both options.distPath and declarationDir are undefined' , ( ) => {
37+ const options : PluginDtsOptions = { } ;
38+ const result = getDtsEmitPath (
39+ options . distPath ,
40+ undefined ,
41+ baseConfig . output . distPath . root ,
42+ ) ;
43+ expect ( result ) . toBe ( '/dist-config' ) ;
44+ } ) ;
45+ } ) ;
You can’t perform that action at this time.
0 commit comments