-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6c4a6c
commit 898422b
Showing
7 changed files
with
75 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { builtinModules } from 'node:module' | ||
import { version as viteVersion } from 'vite' | ||
import type { DepOptimizationOptions } from 'vite' | ||
import type { DepsOptimizationOptions, InlineConfig } from '../../types' | ||
|
||
export function resolveOptimizerConfig(testOptionc: DepsOptimizationOptions | undefined, viteOptions: DepOptimizationOptions | undefined, testConfig: InlineConfig) { | ||
const newConfig: { cacheDir?: string; optimizeDeps: DepOptimizationOptions } = {} as any | ||
const [major, minor] = viteVersion.split('.').map(Number) | ||
const allowed = major >= 5 || (major === 4 && minor >= 3) | ||
if (!allowed && testOptionc?.enabled === true) | ||
console.warn(`Vitest: "deps.optimizer" is only available in Vite >= 4.3.0, current Vite version: ${viteVersion}`) | ||
if (!allowed || testOptionc?.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 cacheDir = testConfig.cache !== false ? testConfig.cache?.dir : null | ||
newConfig.cacheDir = cacheDir ?? 'node_modules/.vitest' | ||
newConfig.optimizeDeps = { | ||
...viteOptions, | ||
...testOptionc, | ||
noDiscovery: true, | ||
disabled: false, | ||
entries: [], | ||
exclude: ['vitest', ...builtinModules, ...(testOptionc.exclude || viteOptions?.exclude || [])], | ||
include: (testOptionc.include || viteOptions?.include || []).filter((n: string) => n !== 'vitest'), | ||
} | ||
} | ||
return newConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters