Skip to content

Commit ab1cccd

Browse files
committedMar 10, 2025
fix: disable resolve dts dependency by default
1 parent 7c41227 commit ab1cccd

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed
 

‎src/features/dts.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { rollup, type Plugin } from 'rollup'
66
import DtsPlugin from 'rollup-plugin-dts'
77
import { fsExists, fsRemove } from '../utils/fs'
88
import { typeAsserts } from '../utils/general'
9-
import type { NormalizedFormat, ResolvedOptions } from '../options'
9+
import type {
10+
BundleDtsOptions,
11+
NormalizedFormat,
12+
ResolvedOptions,
13+
} from '../options'
1014
import { ExternalPlugin } from './external'
1115
import type { OutputExtension } from './output'
1216
import type { PackageJson } from 'pkg-types'
@@ -27,6 +31,7 @@ export async function bundleDts(
2731
pkg?: PackageJson,
2832
): Promise<void> {
2933
typeAsserts<IsolatedDeclOptions>(options.dts)
34+
typeAsserts<BundleDtsOptions>(options.bundleDts)
3035

3136
const ext = jsExtension.replace('j', 't')
3237
const dtsOutDir = path.resolve(options.outDir, getTempDtsDir(format))
@@ -46,9 +51,10 @@ export async function bundleDts(
4651
},
4752
plugins: [
4853
ExternalPlugin(options, pkg) as any,
49-
ResolveDtsPlugin(),
54+
options.bundleDts.resolve && ResolveDtsPlugin(),
5055
DtsPlugin({
5156
compilerOptions: {
57+
...options.bundleDts.compilerOptions,
5258
declaration: true,
5359
noEmit: false,
5460
emitDeclarationOnly: true,

‎src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ export async function buildSingle(
125125
? getTempDtsDir(format)
126126
: dts.extraOutdir,
127127
}),
128-
target &&
128+
!!target &&
129129
transformPlugin({
130130
target:
131131
target &&
132132
(typeof target === 'string' ? target : target.join(',')),
133133
}),
134134

135135
userPlugins,
136-
].filter((plugin) => !!plugin),
136+
],
137137
inject: {
138138
...(shims && getShimsInject(format, platform)),
139139
},

‎src/options.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ import type {
2121
ModuleFormat,
2222
OutputOptions,
2323
} from 'rolldown'
24+
import type { CompilerOptions } from 'typescript'
2425
import type { Options as IsolatedDeclOptions } from 'unplugin-isolated-decl'
2526
import type { Options as UnusedOptions } from 'unplugin-unused'
2627
import type { ConfigEnv, UserConfigExport as ViteUserConfigExport } from 'vite'
2728

2829
export type Sourcemap = boolean | 'inline' | 'hidden'
2930

31+
export interface BundleDtsOptions {
32+
resolve?: boolean
33+
compilerOptions?: CompilerOptions
34+
}
35+
3036
/**
3137
* Options for tsdown.
3238
*/
@@ -100,7 +106,7 @@ export interface Options {
100106
*/
101107
dts?: boolean | IsolatedDeclOptions
102108
/** @default true */
103-
bundleDts?: boolean
109+
bundleDts?: boolean | BundleDtsOptions
104110

105111
/**
106112
* Enable unused dependencies check with `unplugin-unused`
@@ -146,6 +152,7 @@ export type ResolvedOptions = Omit<
146152
format: NormalizedFormat[]
147153
clean: string[] | false
148154
dts: false | IsolatedDeclOptions
155+
bundleDts: false | BundleDtsOptions
149156
}
150157
>,
151158
'config' | 'fromVite'
@@ -188,6 +195,7 @@ export async function resolveOptions(options: Options): Promise<{
188195
entry = await resolveEntry(entry)
189196
if (clean === true) clean = []
190197
if (publint === true) publint = {}
198+
if (bundleDts === true) bundleDts = {}
191199

192200
if (fromVite) {
193201
const viteUserConfig = await loadViteConfig(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## index.d.mts
2+
3+
```mts
4+
interface GlobOptions {
5+
absolute?: boolean;
6+
cwd?: string;
7+
patterns?: string | string[];
8+
ignore?: string | string[];
9+
dot?: boolean;
10+
deep?: number;
11+
followSymbolicLinks?: boolean;
12+
caseSensitiveMatch?: boolean;
13+
expandDirectories?: boolean;
14+
onlyDirectories?: boolean;
15+
onlyFiles?: boolean;
16+
debug?: boolean;
17+
}
18+
19+
export type { GlobOptions };
20+
21+
```
22+
## index.mjs
23+
24+
```mjs
25+
26+
```

‎tests/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ test('fromVite', async (context) => {
171171
])
172172
})
173173

174-
test('inline dependency for dts', async (context) => {
174+
test('resolve dependency for dts', async (context) => {
175175
const files = {
176176
'index.ts': `export type { GlobOptions } from 'tinyglobby'`,
177177
}
178-
await testBuild(context, files, { dts: true })
178+
await testBuild(context, files, { dts: true, bundleDts: { resolve: true } })
179179
})

0 commit comments

Comments
 (0)
Please sign in to comment.