Skip to content

Commit

Permalink
fix: hash the name of the file when caching (#5654)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored May 2, 2024
1 parent f5faf42 commit c9e68ce
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/vitest/src/node/pools/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createHash } from 'node:crypto'
import { mkdir, writeFile } from 'node:fs/promises'
import type { RawSourceMap } from 'vite-node'
import { join } from 'pathe'
Expand Down Expand Up @@ -30,14 +31,15 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
const code = result.code
if (result.externalize)
return result
if ('id' in result)
if ('id' in result && typeof result.id === 'string')
return { id: result.id as string }

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

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

0 comments on commit c9e68ce

Please sign in to comment.