( logger: Logger, entry: UserConfig['entry'], cwd: string, color: Ansis, nameLabel?: string, root?: string, )
| 9 | import type { Ansis } from 'ansis' |
| 10 | |
| 11 | export async function resolveEntry( |
| 12 | logger: Logger, |
| 13 | entry: UserConfig['entry'], |
| 14 | cwd: string, |
| 15 | color: Ansis, |
| 16 | nameLabel?: string, |
| 17 | root?: string, |
| 18 | ): Promise<[entry: Record<string, string>, root: string]> { |
| 19 | if (!entry || Object.keys(entry).length === 0) { |
| 20 | const defaultEntry = path.resolve(cwd, 'src/index.ts') |
| 21 | |
| 22 | if (await fsExists(defaultEntry)) { |
| 23 | entry = { index: defaultEntry } |
| 24 | } else { |
| 25 | throw new Error( |
| 26 | `${nameLabel} No input files, try "tsdown <your-file>" or create src/index.ts`, |
| 27 | ) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | const [entryMap, computedRoot] = await toObjectEntry(entry, cwd, root) |
| 32 | const entries = Object.values(entryMap) |
| 33 | if (entries.length === 0) { |
| 34 | throw new Error(`${nameLabel} Cannot find entry: ${JSON.stringify(entry)}`) |
| 35 | } |
| 36 | logger.info( |
| 37 | nameLabel, |
| 38 | `entry: ${color(entries.map((entry) => (path.isAbsolute(entry) ? path.relative(cwd, entry) : entry)).join(', '))}`, |
| 39 | ) |
| 40 | return [entryMap, computedRoot] |
| 41 | } |
| 42 | |
| 43 | export function toObjectEntry( |
| 44 | entry: TsdownInputOption, |
no test coverage detected
searching dependent graphs…