Skip to content

Commit

Permalink
feat: support named entry in api mode (#391)
Browse files Browse the repository at this point in the history
* feat: support named entry in api mode

* fix: check input existence
  • Loading branch information
tmkx authored Sep 24, 2021
1 parent f7cae28 commit eceda2f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { log, setSilent } from './log'
export type Format = 'cjs' | 'esm' | 'iife'

export type Options = {
entryPoints?: string[]
entryPoints?: BuildOptions['entryPoints']
/**
* Output different formats to differen folder instead of using different extensions
*/
Expand Down Expand Up @@ -346,17 +346,27 @@ const normalizeOptions = async (
setSilent(options.silent)

const input = options.entryPoints
if (input) {
options.entryPoints = await glob(input)
} else {

if (!input || Object.keys(input).length === 0) {
throw new PrettyError(`No input files, try "tsup <your-file>" instead`)
}

// Ensure entry exists
if (!options.entryPoints || options.entryPoints.length === 0) {
throw new PrettyError(`Cannot find ${input}`)
if (Array.isArray(input)) {
options.entryPoints = await glob(input)
// Ensure entry exists
if (!options.entryPoints || options.entryPoints.length === 0) {
throw new PrettyError(`Cannot find ${input}`)
} else {
log('CLI', 'info', `Building entry: ${options.entryPoints.join(', ')}`)
}
} else {
log('CLI', 'info', `Building entry: ${options.entryPoints.join(', ')}`)
Object.keys(input).forEach(alias => {
const filename = input[alias]!;
if (!fs.existsSync(filename)) {
throw new PrettyError(`Cannot find ${alias}: ${filename}`)
}
})
log('CLI', 'info', `Building entry: ${JSON.stringify(input)}`)
}

options.outDir = options.outDir || 'dist'
Expand Down

1 comment on commit eceda2f

@vercel
Copy link

@vercel vercel bot commented on eceda2f Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.