From 0561c9a414ed6a87672541b756d74afa7b88ba7b Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Fri, 16 Feb 2024 15:23:24 +0900 Subject: [PATCH] refactor: simplify check --- packages/vitest/src/node/plugins/utils.ts | 30 ++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/vitest/src/node/plugins/utils.ts b/packages/vitest/src/node/plugins/utils.ts index cb4495c890e8..183daafe5e46 100644 --- a/packages/vitest/src/node/plugins/utils.ts +++ b/packages/vitest/src/node/plugins/utils.ts @@ -1,4 +1,4 @@ -import { searchForWorkspaceRoot, version as viteVersion } from 'vite' +import { searchForWorkspaceRoot } from 'vite' import type { DepOptimizationOptions, ResolvedConfig, UserConfig as ViteConfig } from 'vite' import { dirname } from 'pathe' import type { DepsOptimizationOptions, InlineConfig } from '../../types' @@ -8,18 +8,15 @@ import { rootDir } from '../../paths' export function resolveOptimizerConfig(_testOptions: DepsOptimizationOptions | undefined, viteOptions: DepOptimizationOptions | undefined, testConfig: InlineConfig) { const testOptions = _testOptions || {} const newConfig: { cacheDir?: string; optimizeDeps: DepOptimizationOptions } = {} as any - const [major, minor, fix] = viteVersion.split('.').map(Number) - const allowed = major >= 5 || (major === 4 && minor >= 4) || (major === 4 && minor === 3 && fix >= 2) - if (!allowed && testOptions?.enabled === true) - console.warn(`Vitest: "deps.optimizer" is only available in Vite >= 4.3.2, current Vite version: ${viteVersion}`) - else - // disabled by default - testOptions.enabled ??= false - if (!allowed || testOptions?.enabled !== true) { + // disabled by default + testOptions.enabled ??= false + if (testOptions?.enabled !== true) { newConfig.cacheDir = undefined newConfig.optimizeDeps = { - // experimental in Vite >2.9.2, entries remains to help with older versions - disabled: true, + // noDiscovery available since vite@4.3.3 + // https://github.com/vitejs/vite/discussions/13814 + noDiscovery: true, + include: [], entries: [], } } @@ -44,23 +41,12 @@ export function resolveOptimizerConfig(_testOptions: DepsOptimizationOptions | u ...viteOptions, ...testOptions, noDiscovery: true, - disabled: false, entries: [], exclude, include, } } - // `optimizeDeps.disabled` is deprecated since v5.1.0-beta.1 - // https://github.com/vitejs/vite/pull/15184 - if (major >= 5 && minor >= 1) { - if (newConfig.optimizeDeps.disabled) { - newConfig.optimizeDeps.noDiscovery = true - newConfig.optimizeDeps.include = [] - } - delete newConfig.optimizeDeps.disabled - } - return newConfig }