Skip to content

Commit

Permalink
fix: port the latest defineConfig type from vite
Browse files Browse the repository at this point in the history
Ported from vitejs/vite#13792

Fully fixes issues like vuejs/create-vue#317
and vuejs/create-vue#313

For an easy reproduction, please refer to https://github.com/sodatea/viteste-define-config-bug-repro

I didn't include a test in this PR because:

1. The reproduction is a bit complicated, it only fails on the very
latest Vite versions, but updating Vite would mess up the lockfile.
2. By not updating the dependencies, we can make sure that this fix is
compatible with older versions of Vite, too.
  • Loading branch information
haoqunjiang committed Jul 24, 2023
1 parent 8693449 commit 8bbf161
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/vitest/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ export { configDefaults, defaultInclude, defaultExclude, coverageConfigDefaults
export { mergeConfig } from 'vite'

export type { ConfigEnv, ViteUserConfig as UserConfig }
export type UserConfigFnObject = (env: ConfigEnv) => ViteUserConfig
export type UserConfigFnPromise = (env: ConfigEnv) => Promise<ViteUserConfig>
export type UserConfigFn = (env: ConfigEnv) => ViteUserConfig | Promise<ViteUserConfig>
export type UserConfigExport = ViteUserConfig | Promise<ViteUserConfig> | UserConfigFn
export type UserConfigExport = ViteUserConfig | Promise<ViteUserConfig> | UserConfigFnObject | UserConfigFnPromise | UserConfigFn

export type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>
export type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn

export function defineConfig(config: UserConfigExport) {
export function defineConfig(config: ViteUserConfig): ViteUserConfig
export function defineConfig(config: Promise<ViteUserConfig>): Promise<ViteUserConfig>
export function defineConfig(config: UserConfigExport): UserConfigExport
export function defineConfig(config: UserConfigExport): UserConfigExport {
return config
}

Expand Down

0 comments on commit 8bbf161

Please sign in to comment.