Skip to content

Commit ad2629a

Browse files
louisgvEGOIST
andcommitted
feat(minor): allow tsup config function to be asynchronous (#627)
* Allow tsup config function to be asynchronous * update types Co-authored-by: EGOIST <[email protected]>
1 parent c67e03d commit ad2629a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path'
22
import fs from 'fs'
33
import { Worker } from 'worker_threads'
44
import type { Buildable, MarkRequired } from 'ts-essentials'
5-
import { removeFiles, debouncePromise, slash } from './utils'
5+
import { removeFiles, debouncePromise, slash, MaybePromise } from './utils'
66
import { loadTsupConfig } from './load'
77
import glob from 'globby'
88
import { loadTsConfig } from 'bundle-require'
@@ -39,7 +39,7 @@ export const defineConfig = (
3939
| ((
4040
/** The options derived from CLI flags */
4141
overrideOptions: Options
42-
) => Options | Options[])
42+
) => MaybePromise<Options | Options[]>)
4343
) => options
4444

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

128128
const configData =
129-
typeof config.data === 'function' ? config.data(_options) : config.data
129+
typeof config.data === 'function'
130+
? await config.data(_options)
131+
: config.data
130132

131133
await Promise.all(
132134
[...(Array.isArray(configData) ? configData : [configData])].map(

src/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SourceMapConsumer, SourceMapGenerator, RawSourceMap } from 'source-map'
44
import { Format, NormalizedOptions } from '.'
55
import { outputFile } from './fs'
66
import { Logger } from './log'
7+
import { MaybePromise } from './utils'
78

89
export type ChunkInfo = {
910
type: 'chunk'
@@ -22,8 +23,6 @@ export type AssetInfo = {
2223
contents: Uint8Array
2324
}
2425

25-
type MaybePromise<T> = T | Promise<T>
26-
2726
export type RenderChunk = (
2827
this: PluginContext,
2928
code: string,

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import glob from 'globby'
33
import resolveFrom from 'resolve-from'
44
import strip from 'strip-json-comments'
55

6+
export type MaybePromise<T> = T | Promise<T>
7+
68
export type External =
79
| string
810
| RegExp

0 commit comments

Comments
 (0)