Skip to content

Commit 76fb75d

Browse files
authored
fix!: remove deprecated workspace option in favor of projects (#8218)
1 parent 20d4d9e commit 76fb75d

File tree

18 files changed

+175
-356
lines changed

18 files changed

+175
-356
lines changed

docs/.vitepress/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export default ({ mode }: { mode: string }) => {
7070
customIcon: {
7171
'CLI': 'vscode-icons:file-type-shell',
7272
'vitest.shims': 'vscode-icons:file-type-vitest',
73-
'vitest.workspace': 'vscode-icons:file-type-vitest',
7473
'vitest.config': 'vscode-icons:file-type-vitest',
7574
'.spec.ts': 'vscode-icons:file-type-testts',
7675
'.test.ts': 'vscode-icons:file-type-testts',

docs/config/index.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,20 +2362,6 @@ Relevant only when using with `shouldAdvanceTime: true`. increment mocked time b
23622362

23632363
Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. When disabled, it can lead to potentially unexpected behavior if timers existed prior to starting fake timers session.
23642364

2365-
### workspace<NonProjectOption /> {#workspace}
2366-
2367-
::: danger DEPRECATED
2368-
This options is deprecated and will be removed in the next major. Please, use [`projects`](#projects) instead.
2369-
:::
2370-
2371-
- **Type:** `string | TestProjectConfiguration[]`
2372-
- **CLI:** `--workspace=./file.js`
2373-
- **Default:** `vitest.{workspace,projects}.{js,ts,json}` close to the config file or root
2374-
2375-
Path to a [workspace](/guide/projects) config file relative to [root](#root).
2376-
2377-
Since Vitest 3, you can also define the workspace array in the root config. If the `workspace` is defined in the config manually, Vitest will ignore the `vitest.workspace` file in the root.
2378-
23792365
### projects<NonProjectOption /> {#projects}
23802366

23812367
- **Type:** `TestProjectConfiguration[]`

docs/guide/cli-generated.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,6 @@ High and low watermarks for functions in the format of `<high>,<low>`
272272

273273
Override Vite mode (default: `test` or `benchmark`)
274274

275-
### workspace
276-
277-
- **CLI:** `--workspace <path>`
278-
- **Config:** [workspace](/config/#workspace)
279-
280-
[deprecated] Path to a workspace configuration file
281-
282275
### isolate
283276

284277
- **CLI:** `--isolate`

docs/guide/migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Vitest 4.0 removes some deprecated APIs, including:
122122

123123
- `poolMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
124124
- `environmentMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
125+
- `workspace` config option. Use [`projects`](/guide/projects) instead.
125126

126127
## Migrating from Jest {#jest}
127128

packages/vitest/src/constants.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ export const extraInlineDeps: RegExp[] = [
1414

1515
export const CONFIG_NAMES: string[] = ['vitest.config', 'vite.config']
1616

17-
const WORKSPACES_NAMES = ['vitest.workspace', 'vitest.projects']
18-
1917
export const CONFIG_EXTENSIONS: string[] = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs']
2018

2119
export const configFiles: string[] = CONFIG_NAMES.flatMap(name =>
2220
CONFIG_EXTENSIONS.map(ext => name + ext),
2321
)
2422

25-
const WORKSPACES_EXTENSIONS = [...CONFIG_EXTENSIONS, '.json']
26-
27-
export const workspacesFiles: string[] = WORKSPACES_NAMES.flatMap(name =>
28-
WORKSPACES_EXTENSIONS.map(ext => name + ext),
29-
)
30-
3123
export const globalApis: string[] = [
3224
// suite
3325
'suite',

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,6 @@ export const cliOptionsConfig: VitestCLIOptions = {
334334
description: 'Override Vite mode (default: `test` or `benchmark`)',
335335
argument: '<name>',
336336
},
337-
workspace: {
338-
description: '[deprecated] Path to a workspace configuration file',
339-
argument: '<path>',
340-
normalize: true,
341-
},
342337
isolate: {
343338
description:
344339
'Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`)',

packages/vitest/src/node/config/resolveConfig.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
defaultInspectPort,
2222
defaultPort,
2323
extraInlineDeps,
24-
workspacesFiles,
2524
} from '../../constants'
2625
import { benchmarkConfigDefaults, configDefaults } from '../../defaults'
2726
import { isCI, stdProvider } from '../../utils/env'
@@ -387,7 +386,6 @@ export function resolveConfig(
387386
// Configs
388387
resolved.config && slash(resolved.config),
389388
...configFiles,
390-
...workspacesFiles,
391389

392390
// Vite internal
393391
'**\/virtual:*',
@@ -598,14 +596,6 @@ export function resolveConfig(
598596
}
599597
}
600598

601-
if (typeof resolved.workspace === 'string') {
602-
// if passed down from the CLI and it's relative, resolve relative to CWD
603-
resolved.workspace
604-
= typeof options.workspace === 'string' && options.workspace[0] === '.'
605-
? resolve(process.cwd(), options.workspace)
606-
: resolvePath(resolved.workspace, resolved.root)
607-
}
608-
609599
if (!builtinPools.includes(resolved.pool as BuiltinPool)) {
610600
resolved.pool = resolvePath(resolved.pool, resolved.root)
611601
}

packages/vitest/src/node/core.ts

Lines changed: 10 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ import type { ResolvedConfig, TestProjectConfiguration, UserConfig, VitestRunMod
1111
import type { CoverageProvider } from './types/coverage'
1212
import type { Reporter } from './types/reporter'
1313
import type { TestRunResult } from './types/tests'
14-
import { promises as fs } from 'node:fs'
1514
import { getTasks, hasFailed } from '@vitest/runner/utils'
1615
import { SnapshotManager } from '@vitest/snapshot/manager'
1716
import { noop, toArray } from '@vitest/utils'
18-
import { dirname, join, normalize, relative, resolve } from 'pathe'
17+
import { normalize, relative } from 'pathe'
1918
import { ViteNodeRunner } from 'vite-node/client'
2019
import { ViteNodeServer } from 'vite-node/server'
2120
import { version } from '../../package.json' with { type: 'json' }
2221
import { WebSocketReporter } from '../api/setup'
23-
import { defaultBrowserPort, workspacesFiles as workspaceFiles } from '../constants'
22+
import { defaultBrowserPort } from '../constants'
2423
import { distDir } from '../paths'
2524
import { wildcardPatternToRegExp } from '../utils/base'
2625
import { convertTasksToEvents } from '../utils/tasks'
@@ -90,11 +89,6 @@ export class Vitest {
9089
/** @internal */ closingPromise?: Promise<void>
9190
/** @internal */ isCancelling = false
9291
/** @internal */ coreWorkspaceProject: TestProject | undefined
93-
/**
94-
* @internal
95-
* @deprecated
96-
*/
97-
resolvedProjects: TestProject[] = []
9892
/** @internal */ _browserLastPort = defaultBrowserPort
9993
/** @internal */ _browserSessions = new BrowserSessions()
10094
/** @internal */ _cliOptions: CliOptions = {}
@@ -114,7 +108,6 @@ export class Vitest {
114108
private _state?: StateManager
115109
private _cache?: VitestCache
116110
private _snapshot?: SnapshotManager
117-
private _workspaceConfigPath?: string
118111

119112
constructor(
120113
public readonly mode: VitestRunMode,
@@ -208,8 +201,6 @@ export class Vitest {
208201
this.pool = undefined
209202
this.closingPromise = undefined
210203
this.projects = []
211-
this.resolvedProjects = []
212-
this._workspaceConfigPath = undefined
213204
this.coverageProvider = undefined
214205
this.runningPromise = undefined
215206
this.coreWorkspaceProject = undefined
@@ -261,7 +252,6 @@ export class Vitest {
261252
file = normalize(file)
262253
const isConfig = file === server.config.configFile
263254
|| this.projects.some(p => p.vite.config.configFile === file)
264-
|| file === this._workspaceConfigPath
265255
if (isConfig) {
266256
await Promise.all(this._onRestartListeners.map(fn => fn('config')))
267257
this.report('onServerRestart', 'config')
@@ -278,7 +268,6 @@ export class Vitest {
278268
catch { }
279269

280270
const projects = await this.resolveProjects(this._cliOptions)
281-
this.resolvedProjects = projects
282271
this.projects = projects
283272

284273
await Promise.all(projects.flatMap((project) => {
@@ -404,38 +393,10 @@ export class Vitest {
404393
return this.runner.executeId(moduleId)
405394
}
406395

407-
private async resolveWorkspaceConfigPath(): Promise<string | undefined> {
408-
if (typeof this.config.workspace === 'string') {
409-
return this.config.workspace
410-
}
411-
412-
const configDir = this.vite.config.configFile
413-
? dirname(this.vite.config.configFile)
414-
: this.config.root
415-
416-
const rootFiles = await fs.readdir(configDir)
417-
418-
const workspaceConfigName = workspaceFiles.find((configFile) => {
419-
return rootFiles.includes(configFile)
420-
})
421-
422-
if (!workspaceConfigName) {
423-
return undefined
424-
}
425-
426-
return join(configDir, workspaceConfigName)
427-
}
428-
429396
private async resolveProjects(cliOptions: UserConfig): Promise<TestProject[]> {
430397
const names = new Set<string>()
431398

432399
if (this.config.projects) {
433-
if (typeof this.config.workspace !== 'undefined') {
434-
this.logger.warn(
435-
'Both `test.projects` and `test.workspace` are defined. Ignoring the `test.workspace` option.',
436-
)
437-
}
438-
439400
return resolveProjects(
440401
this,
441402
cliOptions,
@@ -445,57 +406,17 @@ export class Vitest {
445406
)
446407
}
447408

448-
if (Array.isArray(this.config.workspace)) {
449-
this.logger.deprecate(
450-
'The `test.workspace` option is deprecated and will be removed in the next major. To hide this warning, rename `test.workspace` option to `test.projects`.',
451-
)
452-
return resolveProjects(
453-
this,
454-
cliOptions,
455-
undefined,
456-
this.config.workspace,
457-
names,
458-
)
459-
}
460-
461-
const workspaceConfigPath = await this.resolveWorkspaceConfigPath()
462-
463-
this._workspaceConfigPath = workspaceConfigPath
464-
465-
// user doesn't have a workspace config, return default project
466-
if (!workspaceConfigPath) {
467-
// user can filter projects with --project flag, `getDefaultTestProject`
468-
// returns the project only if it matches the filter
469-
const project = getDefaultTestProject(this)
470-
if (!project) {
471-
return []
472-
}
473-
return resolveBrowserProjects(this, new Set([project.name]), [project])
409+
if ('workspace' in this.config) {
410+
throw new Error('The `test.workspace` option was removed in Vitest 4. Please, migrate to `test.projects` instead. See https://vitest.dev/guide/projects for examples.')
474411
}
475412

476-
const configFile = this.vite.config.configFile
477-
? resolve(this.vite.config.root, this.vite.config.configFile)
478-
: 'the root config file'
479-
480-
this.logger.deprecate(
481-
`The workspace file is deprecated and will be removed in the next major. Please, use the \`test.projects\` field in ${configFile} instead.`,
482-
)
483-
484-
const workspaceModule = await this.import<{
485-
default: TestProjectConfiguration[]
486-
}>(workspaceConfigPath)
487-
488-
if (!workspaceModule.default || !Array.isArray(workspaceModule.default)) {
489-
throw new TypeError(`Workspace config file "${workspaceConfigPath}" must export a default array of project paths.`)
413+
// user can filter projects with --project flag, `getDefaultTestProject`
414+
// returns the project only if it matches the filter
415+
const project = getDefaultTestProject(this)
416+
if (!project) {
417+
return []
490418
}
491-
492-
return resolveProjects(
493-
this,
494-
cliOptions,
495-
workspaceConfigPath,
496-
workspaceModule.default,
497-
names,
498-
)
419+
return resolveBrowserProjects(this, new Set([project.name]), [project])
499420
}
500421

501422
/**

packages/vitest/src/node/projects/resolveProjects.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { GlobOptions } from 'tinyglobby'
22
import type { Vitest } from '../core'
3-
import type { BrowserInstanceOption, ResolvedConfig, TestProjectConfiguration, UserConfig, UserWorkspaceConfig } from '../types/config'
3+
import type {
4+
BrowserInstanceOption,
5+
ResolvedConfig,
6+
TestProjectConfiguration,
7+
UserConfig,
8+
UserWorkspaceConfig,
9+
} from '../types/config'
410
import { existsSync, promises as fs } from 'node:fs'
511
import os from 'node:os'
612
import { limitConcurrency } from '@vitest/runner/utils'

packages/vitest/src/node/types/config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,6 @@ export interface InlineConfig {
377377
*/
378378
projects?: TestProjectConfiguration[]
379379

380-
/**
381-
* Path to a workspace configuration file
382-
* @deprecated use `projects` instead
383-
*/
384-
workspace?: string | TestProjectConfiguration[]
385-
386380
/**
387381
* Update snapshot
388382
*
@@ -1110,7 +1104,6 @@ type NonProjectOptions =
11101104
| 'maxWorkers'
11111105
| 'minWorkers'
11121106
| 'fileParallelism'
1113-
| 'workspace'
11141107
| 'watchTriggerPatterns'
11151108

11161109
export type ProjectConfig = Omit<

0 commit comments

Comments
 (0)