@@ -5,12 +5,12 @@ import { pathToFileURL } from 'node:url'
55import { underline } from 'ansis'
66import Debug from 'debug'
77import { loadConfig } from 'unconfig'
8+ import { resolveClean } from './features/clean'
89import { resolveEntry } from './features/entry'
9- import { fsExists } from './utils/fs '
10+ import { resolveTsconfig } from './features/tsconfig '
1011import { resolveComma , toArray } from './utils/general'
1112import { logger } from './utils/logger'
1213import { normalizeFormat , readPackageJson } from './utils/package'
13- import { findTsconfig } from './utils/tsconfig'
1414import type { TsdownHooks } from './features/hooks'
1515import type { OutExtensionFactory } from './features/output'
1616import type { ReportOptions } from './features/report'
@@ -139,7 +139,11 @@ export interface Options {
139139
140140 /// addons
141141 /**
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.
143147 */
144148 dts ?: boolean | DtsOptions
145149
@@ -242,7 +246,7 @@ export async function resolveOptions(options: Options): Promise<{
242246 platform = 'node' ,
243247 outDir = 'dist' ,
244248 sourcemap = false ,
245- dts = false ,
249+ dts,
246250 unused = false ,
247251 watch = false ,
248252 shims = false ,
@@ -258,44 +262,17 @@ export async function resolveOptions(options: Options): Promise<{
258262
259263 outDir = path . resolve ( outDir )
260264 entry = await resolveEntry ( entry , cwd )
265+ clean = resolveClean ( clean , outDir )
266+
267+ const pkg = await readPackageJson ( cwd )
261268
262- if ( clean === true ) {
263- clean = [ outDir ]
264- } else if ( ! clean ) {
265- clean = [ ]
269+ if ( dts == null ) {
270+ dts = ! ! ( pkg ?. types || pkg ?. typings )
266271 }
267272
273+ tsconfig = await resolveTsconfig ( tsconfig , cwd )
268274 if ( publint === true ) publint = { }
269275
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-
299276 if ( fromVite ) {
300277 const viteUserConfig = await loadViteConfig (
301278 fromVite === true ? 'vite' : fromVite ,
@@ -323,8 +300,6 @@ export async function resolveOptions(options: Options): Promise<{
323300 }
324301 }
325302
326- const pkg = await readPackageJson ( cwd )
327-
328303 const config : ResolvedOptions = {
329304 ...subOptions ,
330305 entry,
0 commit comments