Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(minor): allow tsup config function to be asynchronous (#627)
* Allow tsup config function to be asynchronous

* update types

Co-authored-by: EGOIST <hi@egoist.sh>
  • Loading branch information
louisgv and EGOIST committed May 25, 2022
1 parent c67e03d commit ad2629a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/index.ts
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs'
import { Worker } from 'worker_threads'
import type { Buildable, MarkRequired } from 'ts-essentials'
import { removeFiles, debouncePromise, slash } from './utils'
import { removeFiles, debouncePromise, slash, MaybePromise } from './utils'
import { loadTsupConfig } from './load'
import glob from 'globby'
import { loadTsConfig } from 'bundle-require'
Expand Down Expand Up @@ -39,7 +39,7 @@ export const defineConfig = (
| ((
/** The options derived from CLI flags */
overrideOptions: Options
) => Options | Options[])
) => MaybePromise<Options | Options[]>)
) => options

const killProcess = ({
Expand Down Expand Up @@ -126,7 +126,9 @@ export async function build(_options: Options) {
_options.config === false ? {} : await loadTsupConfig(process.cwd())

const configData =
typeof config.data === 'function' ? config.data(_options) : config.data
typeof config.data === 'function'
? await config.data(_options)
: config.data

await Promise.all(
[...(Array.isArray(configData) ? configData : [configData])].map(
Expand Down
3 changes: 1 addition & 2 deletions src/plugin.ts
Expand Up @@ -4,6 +4,7 @@ import { SourceMapConsumer, SourceMapGenerator, RawSourceMap } from 'source-map'
import { Format, NormalizedOptions } from '.'
import { outputFile } from './fs'
import { Logger } from './log'
import { MaybePromise } from './utils'

export type ChunkInfo = {
type: 'chunk'
Expand All @@ -22,8 +23,6 @@ export type AssetInfo = {
contents: Uint8Array
}

type MaybePromise<T> = T | Promise<T>

export type RenderChunk = (
this: PluginContext,
code: string,
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Expand Up @@ -3,6 +3,8 @@ import glob from 'globby'
import resolveFrom from 'resolve-from'
import strip from 'strip-json-comments'

export type MaybePromise<T> = T | Promise<T>

export type External =
| string
| RegExp
Expand Down

0 comments on commit ad2629a

Please sign in to comment.