Skip to content

Commit

Permalink
fix(vitest): improve defineProject and defineWorkspace types (#6198)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jul 23, 2024
1 parent 17a81f0 commit 8cd8272
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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
}

0 comments on commit 8cd8272

Please sign in to comment.