1
1
import fs from 'node:fs'
2
+ import crypto from 'node:crypto'
2
3
import { findUp } from 'find-up'
3
4
import { resolve } from 'pathe'
4
5
import { loadConfigFromFile } from 'vite'
@@ -20,8 +21,11 @@ export class VitestCache {
20
21
return this . stats . getStats ( key )
21
22
}
22
23
23
- static resolveCacheDir ( root : string , dir : string | undefined ) {
24
- return resolve ( root , slash ( dir || 'node_modules/.vitest' ) )
24
+ static resolveCacheDir ( root : string , dir : string | undefined , projectName : string | undefined ) {
25
+ const baseDir = slash ( dir || 'node_modules/.vitest' )
26
+ return projectName
27
+ ? resolve ( root , baseDir , crypto . createHash ( 'md5' ) . update ( projectName , 'utf-8' ) . digest ( 'hex' ) )
28
+ : resolve ( root , baseDir )
25
29
}
26
30
27
31
static async clearCache ( options : CliOptions ) {
@@ -38,11 +42,12 @@ export class VitestCache {
38
42
: undefined
39
43
40
44
const cache = config ?. test ?. cache
45
+ const projectName = config ?. test ?. name
41
46
42
47
if ( cache === false )
43
48
throw new Error ( 'Cache is disabled' )
44
49
45
- const cachePath = VitestCache . resolveCacheDir ( root , cache ?. dir )
50
+ const cachePath = VitestCache . resolveCacheDir ( root , cache ?. dir , projectName )
46
51
47
52
let cleared = false
48
53
0 commit comments