1- import fs from 'node:fs'
21import crypto from 'node:crypto'
3- import { findUp } from 'find-up'
42import { resolve } from 'pathe'
5- import { loadConfigFromFile } from 'vite'
6- import { configFiles } from '../../constants'
7- import type { CliOptions } from '../cli/cli-api'
83import { slash } from '../../utils'
94import { FilesStatsCache } from './files'
105import { ResultsCache } from './results'
@@ -27,34 +22,4 @@ export class VitestCache {
2722 ? resolve ( root , baseDir , crypto . createHash ( 'md5' ) . update ( projectName , 'utf-8' ) . digest ( 'hex' ) )
2823 : resolve ( root , baseDir )
2924 }
30-
31- static async clearCache ( options : CliOptions ) {
32- const root = resolve ( options . root || process . cwd ( ) )
33-
34- const configPath = options . config === false
35- ? false
36- : options . config
37- ? resolve ( root , options . config )
38- : await findUp ( configFiles , { cwd : root } as any )
39-
40- const config = configPath
41- ? ( await loadConfigFromFile ( { command : 'serve' , mode : 'test' } , configPath ) ) ?. config
42- : undefined
43-
44- const cache = config ?. test ?. cache
45- const projectName = config ?. test ?. name
46-
47- if ( cache === false )
48- throw new Error ( 'Cache is disabled' )
49-
50- const cachePath = VitestCache . resolveCacheDir ( root , cache ?. dir , projectName )
51-
52- let cleared = false
53-
54- if ( fs . existsSync ( cachePath ) ) {
55- fs . rmSync ( cachePath , { recursive : true , force : true } )
56- cleared = true
57- }
58- return { dir : cachePath , cleared }
59- }
6025}
0 commit comments