Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tsup config function to be asynchronous #627

Merged
merged 2 commits into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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