Skip to content

Commit 80713ab

Browse files
authored
fix: increase maximumConfigs to 5 and add a link to documentation (#622)
1 parent e3ac56f commit 80713ab

File tree

5 files changed

+17
-40
lines changed

5 files changed

+17
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ These options are resolved relative to the [workspace file](https://code.visuals
9494
- `vitest.debugExclude`: Excludes files matching specified glob patterns from debugging. Default:
9595
`[\"<node_internals>/**\", \"**/node_modules/**\"]`
9696
- `vitest.debugOutFiles`: If source maps are enabled, these glob patterns specify the generated JavaScript files. If a pattern starts with `!` the files are excluded. If not specified, the generated code is expected in the same directory as its source. Default: `["${workspaceFolder}/**/*.(m|c|)js", "!**/node_modules/**"]`
97-
- `vitest.maximumConfigs`: The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file. Default: `3`
97+
- `vitest.maximumConfigs`: The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file. Default: `5`
9898
- `vitest.logLevel`: How verbose should the logger be in the "Output" channel. Default: `info`
9999
- `vitest.applyDiagnostic`: Show a squiggly line where the error was thrown. This also enables the error count in the File Tab. Default: `true`
100100
- `vitest.experimentalStaticAstCollect`: uses AST parses to collect tests instead of running files and collecting them at runtime. Default: `true`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"vitest.maximumConfigs": {
168168
"description": "The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file.",
169169
"type": "number",
170-
"default": 3,
170+
"default": 5,
171171
"scope": "window"
172172
},
173173
"vitest.debugExclude": {

src/api.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as vscode from 'vscode'
44
import { log } from './log'
55
import type { ExtensionWorkerEvents, SerializedTestSpecification, VitestRPC } from './api/rpc'
66
import type { VitestPackage } from './api/pkg'
7-
import { createVitestWorkspaceFile, noop, showVitestError } from './utils'
7+
import { showVitestError } from './utils'
88
import { createVitestTerminalProcess } from './api/terminal'
99
import { getConfig } from './config'
1010
import { createVitestProcess } from './api/child_process'
@@ -280,7 +280,7 @@ export async function resolveVitestAPI(workspaceConfigs: VitestPackage[], config
280280
return depthA - depthB
281281
})
282282

283-
const maximumConfigs = getConfig().maximumConfigs ?? 3
283+
const maximumConfigs = getConfig().maximumConfigs ?? 5
284284

285285
const workspaceRoots: string[] = apis
286286
.map(api => api.workspaceSource ? dirname(api.workspaceSource) : null)
@@ -345,27 +345,31 @@ function isCoveredByWorkspace(workspacesRoots: string[], currentConfig: string):
345345
}
346346

347347
function warnPerformanceConfigLimit(configsToResolve: VitestPackage[]) {
348-
const maximumConfigs = getConfig().maximumConfigs ?? 3
348+
const maximumConfigs = getConfig().maximumConfigs ?? 5
349349
const warningMessage = [
350-
'Vitest found multiple config files.',
350+
'Vitest found multiple projects.',
351351
`The extension will use only the first ${maximumConfigs} due to performance concerns.`,
352-
'Consider using a workspace configuration to group your configs or increase',
352+
'Consider using a projects configuration to group your configs or increase',
353353
'the limit via "vitest.maximumConfigs" option.',
354354
].join(' ')
355355

356356
const folders = Array.from(new Set(configsToResolve.map(c => c.folder)))
357-
const allConfigs = [...configsToResolve]
358-
// remove all but the first 3
357+
// remove all but the first 5
359358
const discardedConfigs = configsToResolve.splice(maximumConfigs)
360359

361360
if (folders.every(f => getConfig(f).disableWorkspaceWarning !== true)) {
362361
vscode.window.showWarningMessage(
363362
warningMessage,
364-
'Create vitest.workspace.js',
363+
'Documentation',
365364
'Disable notification',
366365
).then((result) => {
367-
if (result === 'Create vitest.workspace.js')
368-
createVitestWorkspaceFile(allConfigs).catch(noop)
366+
if (result === 'Documentation') {
367+
vscode.commands.executeCommand(
368+
'vscode.open',
369+
// /workspace redirects to /projects on the new version
370+
vscode.Uri.parse('https://vitest.dev/guide/workspace'),
371+
)
372+
}
369373

370374
if (result === 'Disable notification') {
371375
folders.forEach((folder) => {

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) {
8282
workspaceConfig: resolveConfigPath(workspaceConfig),
8383
rootConfig: resolveConfigPath(rootConfigFile),
8484
configSearchPatternExclude,
85-
maximumConfigs: get<number>('maximumConfigs', 3),
85+
maximumConfigs: get<number>('maximumConfigs', 5),
8686
nodeExecutable: resolveConfigPath(nodeExecutable),
8787
disableWorkspaceWarning: get<boolean>('disableWorkspaceWarning', false),
8888
debuggerPort: get<number>('debuggerPort') || undefined,

src/utils.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,6 @@ export function formatPkg(pkg: VitestPackage) {
1313
return `Vitest v${pkg.version} (${relative(dirname(pkg.cwd), pkg.id)})`
1414
}
1515

16-
export async function createVitestWorkspaceFile(vitest: VitestPackage[]) {
17-
const folders = new Set(vitest.map(x => x.folder))
18-
const encoder = new TextEncoder()
19-
const promises = [...folders].map(async (folder) => {
20-
const configFiles = vitest.filter(x => x.folder === folder).map(x => relative(folder.uri.fsPath, x.configFile!))
21-
const ext = configFiles.every(x => /\.m?ts$/.test(x)) ? 'ts' : 'js'
22-
const workspaceFileUri = vscode.Uri.joinPath(folder.uri, `vitest.workspace.${ext}`)
23-
24-
const workspaceContent = `
25-
import { defineWorkspace } from 'vitest/config'
26-
27-
export default defineWorkspace([
28-
${configFiles.map(file => `"./${file}"`).join(',\n ')}
29-
])
30-
`.trimStart()
31-
32-
await vscode.workspace.fs.writeFile(workspaceFileUri, encoder.encode(workspaceContent))
33-
return await vscode.workspace.openTextDocument(workspaceFileUri)
34-
})
35-
36-
const results = await Promise.all(promises)
37-
if (results[0])
38-
await vscode.window.showTextDocument(results[0])
39-
40-
await vscode.window.showInformationMessage('Created vitest.workspace.js. You might need to run \`npm i --save-dev vitest\` in the root folder to install Vitest.')
41-
}
42-
4316
function _showVitestError(message: string, error?: any) {
4417
if (error)
4518
log.error(error)

0 commit comments

Comments
 (0)