@@ -5,12 +5,12 @@ import { pathToFileURL } from 'node:url'
5
5
import { underline } from 'ansis'
6
6
import Debug from 'debug'
7
7
import { loadConfig } from 'unconfig'
8
+ import { resolveClean } from './features/clean'
8
9
import { resolveEntry } from './features/entry'
9
- import { fsExists } from './utils/fs '
10
+ import { resolveTsconfig } from './features/tsconfig '
10
11
import { resolveComma , toArray } from './utils/general'
11
12
import { logger } from './utils/logger'
12
13
import { normalizeFormat , readPackageJson } from './utils/package'
13
- import { findTsconfig } from './utils/tsconfig'
14
14
import type { TsdownHooks } from './features/hooks'
15
15
import type { OutExtensionFactory } from './features/output'
16
16
import type { ReportOptions } from './features/report'
@@ -139,7 +139,11 @@ export interface Options {
139
139
140
140
/// addons
141
141
/**
142
- * Emit declaration files
142
+ * Emit TypeScript declaration files (.d.ts).
143
+ *
144
+ * By default, this feature is auto-detected based on the presence of the `types` field in the `package.json` file.
145
+ * - If the `types` field is present in `package.json`, declaration file emission is enabled.
146
+ * - If the `types` field is absent, declaration file emission is disabled by default.
143
147
*/
144
148
dts ?: boolean | DtsOptions
145
149
@@ -242,7 +246,7 @@ export async function resolveOptions(options: Options): Promise<{
242
246
platform = 'node' ,
243
247
outDir = 'dist' ,
244
248
sourcemap = false ,
245
- dts = false ,
249
+ dts,
246
250
unused = false ,
247
251
watch = false ,
248
252
shims = false ,
@@ -258,44 +262,17 @@ export async function resolveOptions(options: Options): Promise<{
258
262
259
263
outDir = path . resolve ( outDir )
260
264
entry = await resolveEntry ( entry , cwd )
265
+ clean = resolveClean ( clean , outDir )
266
+
267
+ const pkg = await readPackageJson ( cwd )
261
268
262
- if ( clean === true ) {
263
- clean = [ outDir ]
264
- } else if ( ! clean ) {
265
- clean = [ ]
269
+ if ( dts == null ) {
270
+ dts = ! ! ( pkg ?. types || pkg ?. typings )
266
271
}
267
272
273
+ tsconfig = await resolveTsconfig ( tsconfig , cwd )
268
274
if ( publint === true ) publint = { }
269
275
270
- if ( tsconfig !== false ) {
271
- if ( tsconfig === true || tsconfig == null ) {
272
- const isSet = tsconfig
273
- tsconfig = findTsconfig ( cwd )
274
- if ( isSet && ! tsconfig ) {
275
- logger . warn ( `No tsconfig found in \`${ cwd } \`` )
276
- }
277
- } else {
278
- const tsconfigPath = path . resolve ( cwd , tsconfig )
279
- if ( await fsExists ( tsconfigPath ) ) {
280
- tsconfig = tsconfigPath
281
- } else if ( tsconfig . includes ( '\\' ) || tsconfig . includes ( '/' ) ) {
282
- logger . warn ( `tsconfig \`${ tsconfig } \` doesn't exist` )
283
- tsconfig = false
284
- } else {
285
- tsconfig = findTsconfig ( cwd , tsconfig )
286
- if ( ! tsconfig ) {
287
- logger . warn ( `No \`${ tsconfig } \` found in \`${ cwd } \`` )
288
- }
289
- }
290
- }
291
-
292
- if ( tsconfig ) {
293
- logger . info (
294
- `Using tsconfig: ${ underline ( path . relative ( cwd , tsconfig ) ) } ` ,
295
- )
296
- }
297
- }
298
-
299
276
if ( fromVite ) {
300
277
const viteUserConfig = await loadViteConfig (
301
278
fromVite === true ? 'vite' : fromVite ,
@@ -323,8 +300,6 @@ export async function resolveOptions(options: Options): Promise<{
323
300
}
324
301
}
325
302
326
- const pkg = await readPackageJson ( cwd )
327
-
328
303
const config : ResolvedOptions = {
329
304
...subOptions ,
330
305
entry,
0 commit comments