Skip to content

Commit c9e68ce

Browse files
authored
fix: hash the name of the file when caching (#5654)
1 parent f5faf42 commit c9e68ce

File tree

1 file changed

+4
-2
lines changed
  • packages/vitest/src/node/pools

1 file changed

+4
-2
lines changed

packages/vitest/src/node/pools/rpc.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createHash } from 'node:crypto'
12
import { mkdir, writeFile } from 'node:fs/promises'
23
import type { RawSourceMap } from 'vite-node'
34
import { join } from 'pathe'
@@ -30,14 +31,15 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
3031
const code = result.code
3132
if (result.externalize)
3233
return result
33-
if ('id' in result)
34+
if ('id' in result && typeof result.id === 'string')
3435
return { id: result.id as string }
3536

3637
if (!code)
3738
throw new Error(`Failed to fetch module ${id}`)
3839

3940
const dir = join(project.tmpDir, transformMode)
40-
const tmp = join(dir, id.replace(/[/\\?%*:|"<>]/g, '_').replace('\0', '__x00__'))
41+
const name = createHash('sha1').update(id).digest('hex')
42+
const tmp = join(dir, name)
4143
if (promises.has(tmp)) {
4244
await promises.get(tmp)
4345
return { id: tmp }

0 commit comments

Comments
 (0)