@@ -30,8 +30,9 @@ export async function bundleDts(
30
30
format : NormalizedFormat ,
31
31
pkg ?: PackageJson ,
32
32
) : Promise < void > {
33
- typeAsserts < IsolatedDeclOptions > ( options . dts )
34
- typeAsserts < BundleDtsOptions > ( options . bundleDts )
33
+ const { dts, bundleDts } = options
34
+ typeAsserts < IsolatedDeclOptions > ( dts )
35
+ typeAsserts < BundleDtsOptions > ( bundleDts )
35
36
36
37
const ext = jsExtension . replace ( 'j' , 't' )
37
38
const dtsOutDir = path . resolve ( options . outDir , getTempDtsDir ( format ) )
@@ -41,6 +42,7 @@ export async function bundleDts(
41
42
path . resolve ( dtsOutDir , `${ key } .d.${ ext } ` ) ,
42
43
] ) ,
43
44
)
45
+
44
46
const build = await rollup ( {
45
47
input : dtsEntry ,
46
48
external : options . external ,
@@ -51,10 +53,13 @@ export async function bundleDts(
51
53
} ,
52
54
plugins : [
53
55
ExternalPlugin ( options , pkg ) as any ,
54
- options . bundleDts . resolve && ResolveDtsPlugin ( ) ,
56
+ bundleDts . resolve &&
57
+ ResolveDtsPlugin (
58
+ bundleDts . resolve !== true ? bundleDts . resolve : undefined ,
59
+ ) ,
55
60
DtsPlugin ( {
56
61
compilerOptions : {
57
- ...options . bundleDts . compilerOptions ,
62
+ ...bundleDts . compilerOptions ,
58
63
declaration : true ,
59
64
noEmit : false ,
60
65
emitDeclarationOnly : true ,
@@ -70,7 +75,7 @@ export async function bundleDts(
70
75
} )
71
76
72
77
let outDir = options . outDir
73
- const extraOutdir = options . dts . extraOutdir
78
+ const extraOutdir = dts . extraOutdir
74
79
if ( extraOutdir ) {
75
80
outDir = path . resolve ( outDir , extraOutdir )
76
81
}
@@ -84,7 +89,7 @@ export async function bundleDts(
84
89
}
85
90
86
91
let resolver : ResolverFactory | undefined
87
- export function ResolveDtsPlugin ( ) : Plugin {
92
+ export function ResolveDtsPlugin ( resolveOnly ?: Array < string | RegExp > ) : Plugin {
88
93
return {
89
94
name : 'resolve-dts' ,
90
95
buildStart ( ) {
@@ -99,6 +104,17 @@ export function ResolveDtsPlugin(): Plugin {
99
104
if ( id [ 0 ] === '.' || path . isAbsolute ( id ) ) return
100
105
if ( / \0 / . test ( id ) ) return
101
106
107
+ if ( resolveOnly ) {
108
+ const shouldResolve = resolveOnly . some ( ( value ) => {
109
+ if ( typeof value === 'string' ) return value === id
110
+ return value . test ( id )
111
+ } )
112
+ if ( ! shouldResolve ) {
113
+ debug ( 'skipped by matching resolveOnly: %s' , id )
114
+ return
115
+ }
116
+ }
117
+
102
118
const directory = importer ? path . dirname ( importer ) : process . cwd ( )
103
119
debug ( 'Resolving:' , id , 'from:' , directory )
104
120
const { path : resolved } = await resolver ! . async ( directory , id )
0 commit comments