Skip to content

Commit 0b3ea30

Browse files
gaoachaosxzz
andauthored
feat: defaults entry to src/index.ts if exists (#266)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
1 parent 13ab98c commit 0b3ea30

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/features/entry.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22
import { glob } from 'tinyglobby'
3-
import { lowestCommonAncestor } from '../utils/fs'
3+
import { fsExists, lowestCommonAncestor } from '../utils/fs'
44
import { generateColor, logger, prettyName } from '../utils/logger'
55
import type { Options } from '../options'
66

@@ -11,10 +11,15 @@ export async function resolveEntry(
1111
): Promise<Record<string, string>> {
1212
const nameLabel = name ? `[${name}] ` : ''
1313
if (!entry || Object.keys(entry).length === 0) {
14-
// TODO auto find entry
15-
throw new Error(
16-
`${nameLabel}No input files, try "tsdown <your-file>" instead`,
17-
)
14+
const defaultEntry = path.resolve(cwd, 'src/index.ts')
15+
16+
if (await fsExists(defaultEntry)) {
17+
entry = { index: defaultEntry }
18+
} else {
19+
throw new Error(
20+
`${nameLabel}No input files, try "tsdown <your-file>" or create src/index.ts`,
21+
)
22+
}
1823
}
1924

2025
const entryMap = await toObjectEntry(entry, cwd)

src/options/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export interface ExportsOptions {
9191
*/
9292
export interface Options {
9393
/// build options
94+
/**
95+
* Defaults to `'src/index.ts'` if it exists.
96+
*/
9497
entry?: InputOption
9598
external?: ExternalOption
9699
noExternal?:

0 commit comments

Comments
 (0)