Skip to content

Commit

Permalink
fix(vitest): remove viteConfig cacheDir override within the VitestOpt…
Browse files Browse the repository at this point in the history
…imizer plugin
  • Loading branch information
jacoberdman2147 committed Nov 13, 2024
1 parent 25fd725 commit 9f7c89d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
4 changes: 0 additions & 4 deletions packages/vitest/src/node/plugins/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ export function VitestOptimizer(): Plugin {
const webOptimizer = resolveOptimizerConfig(
testConfig.deps?.optimizer?.web,
viteConfig.optimizeDeps,
testConfig,
)
const ssrOptimizer = resolveOptimizerConfig(
testConfig.deps?.optimizer?.ssr,
viteConfig.ssr?.optimizeDeps,
testConfig,
)

viteConfig.cacheDir
= viteConfig.cacheDir || webOptimizer.cacheDir || ssrOptimizer.cacheDir
viteConfig.optimizeDeps = webOptimizer.optimizeDeps
viteConfig.ssr ??= {}
viteConfig.ssr.optimizeDeps = ssrOptimizer.optimizeDeps
Expand Down
12 changes: 2 additions & 10 deletions packages/vitest/src/node/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ import type {
ResolvedConfig,
UserConfig as ViteConfig,
} from 'vite'
import type { DepsOptimizationOptions, InlineConfig } from '../types/config'
import type { DepsOptimizationOptions } from '../types/config'
import { dirname } from 'pathe'
import { searchForWorkspaceRoot, version as viteVersion } from 'vite'
import { rootDir } from '../../paths'
import { VitestCache } from '../cache'

export function resolveOptimizerConfig(
_testOptions: DepsOptimizationOptions | undefined,
viteOptions: DepOptimizationOptions | undefined,
testConfig: InlineConfig,
) {
const testOptions = _testOptions || {}
const newConfig: { cacheDir?: string; optimizeDeps: DepOptimizationOptions }
const newConfig: { optimizeDeps: DepOptimizationOptions }
= {} as any
const [major, minor, fix] = viteVersion.split('.').map(Number)
const allowed
Expand All @@ -32,17 +30,13 @@ export function resolveOptimizerConfig(
testOptions.enabled ??= false
}
if (!allowed || testOptions?.enabled !== true) {
newConfig.cacheDir = undefined
newConfig.optimizeDeps = {
// experimental in Vite >2.9.2, entries remains to help with older versions
disabled: true,
entries: [],
}
}
else {
const root = testConfig.root ?? process.cwd()
const cacheDir
= testConfig.cache !== false ? testConfig.cache?.dir : undefined
const currentInclude = testOptions.include || viteOptions?.include || []
const exclude = [
'vitest',
Expand All @@ -60,8 +54,6 @@ export function resolveOptimizerConfig(
(n: string) => !exclude.includes(n),
)

newConfig.cacheDir
= cacheDir ?? VitestCache.resolveCacheDir(root, cacheDir, testConfig.name)
newConfig.optimizeDeps = {
...viteOptions,
...testOptions,
Expand Down

0 comments on commit 9f7c89d

Please sign in to comment.