diff --git a/src/features/entry.ts b/src/features/entry.ts index 9f06bb574..33ef591b0 100644 --- a/src/features/entry.ts +++ b/src/features/entry.ts @@ -1,6 +1,6 @@ import path from 'node:path' import { glob } from 'tinyglobby' -import { lowestCommonAncestor } from '../utils/fs' +import { fsExists, lowestCommonAncestor } from '../utils/fs' import { generateColor, logger, prettyName } from '../utils/logger' import type { Options } from '../options' @@ -11,10 +11,15 @@ export async function resolveEntry( ): Promise> { const nameLabel = name ? `[${name}] ` : '' if (!entry || Object.keys(entry).length === 0) { - // TODO auto find entry - throw new Error( - `${nameLabel}No input files, try "tsdown " instead`, - ) + const defaultEntry = path.resolve(cwd, 'src/index.ts') + + if (await fsExists(defaultEntry)) { + entry = { index: defaultEntry } + } else { + throw new Error( + `${nameLabel}No input files, try "tsdown " or create src/index.ts`, + ) + } } const entryMap = await toObjectEntry(entry, cwd) diff --git a/src/options/types.ts b/src/options/types.ts index ed02a9276..2b7ce8dad 100644 --- a/src/options/types.ts +++ b/src/options/types.ts @@ -91,6 +91,9 @@ export interface ExportsOptions { */ export interface Options { /// build options + /** + * Defaults to `'src/index.ts'` if it exists. + */ entry?: InputOption external?: ExternalOption noExternal?: