Skip to content

Commit

Permalink
fix: fix fetch cache multiple writes (#7546)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 24, 2025
1 parent 358cccf commit 1a8b433
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/vitest/src/node/pools/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { RawSourceMap } from 'vite-node'
import type { RuntimeRPC } from '../../types/rpc'
import type { TestProject } from '../project'
import type { ResolveSnapshotPathHandlerContext } from '../types/config'
import { mkdir, writeFile } from 'node:fs/promises'
import { mkdirSync } from 'node:fs'
import { writeFile } from 'node:fs/promises'
import { join } from 'pathe'
import { hash } from '../hash'

Expand Down Expand Up @@ -54,14 +55,14 @@ export function createMethodsRPC(project: TestProject, options: MethodsOptions =
const dir = join(project.tmpDir, transformMode)
const name = hash('sha1', id, 'hex')
const tmp = join(dir, name)
if (!created.has(dir)) {
mkdirSync(dir, { recursive: true })
created.add(dir)
}
if (promises.has(tmp)) {
await promises.get(tmp)
return { id: tmp }
}
if (!created.has(dir)) {
await mkdir(dir, { recursive: true })
created.add(dir)
}
promises.set(
tmp,
writeFile(tmp, code, 'utf-8').finally(() => promises.delete(tmp)),
Expand Down

0 comments on commit 1a8b433

Please sign in to comment.