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

fix(vitest): improve defineProject and defineWorkspace types #6198

Merged
merged 2 commits into from
Jul 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guide/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Workspace projects don't support all configuration properties. For better type s

:::code-group
```ts [packages/a/vitest.config.ts] twoslash
// @errors: 2769
import { defineProject } from 'vitest/config'

export default defineProject({
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build]
publish = "docs/.vitepress/dist"
command = "pnpm ci:docs"
ignore = "git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- docs/ package.json pnpm-lock.yaml"
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF docs/ package.json pnpm-lock.yaml"

[build.environment]
NODE_VERSION = "20"
Expand Down
16 changes: 13 additions & 3 deletions packages/vitest/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@ export function defineConfig(config: UserConfigExport): UserConfigExport {
return config
}

export function defineProject<T extends UserProjectConfigExport>(config: T): T {
export function defineProject(config: UserWorkspaceConfig): UserWorkspaceConfig
export function defineProject(config: Promise<UserWorkspaceConfig>): Promise<UserWorkspaceConfig>
export function defineProject(config: UserProjectConfigFn): UserProjectConfigFn
export function defineProject(config: UserProjectConfigExport): UserProjectConfigExport
export function defineProject(config: UserProjectConfigExport): UserProjectConfigExport {
return config
}

type Workspace = string | (UserProjectConfigExport & { extends?: string })
type WorkspaceProjectConfiguration = string | (UserProjectConfigExport & {
/**
* Relative path to the extendable config. All other options will be merged with this config.
* @example '../vite.config.ts'
*/
extends?: string
})

export function defineWorkspace(config: Workspace[]): Workspace[] {
export function defineWorkspace(config: WorkspaceProjectConfiguration[]): WorkspaceProjectConfiguration[] {
return config
}