Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hash the name of the file when caching #5654

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading