Skip to content

Commit 1a8b433

Browse files
authored
fix: fix fetch cache multiple writes (#7546)
1 parent 358cccf commit 1a8b433

File tree

1 file changed

+6
-5
lines changed
  • packages/vitest/src/node/pools

1 file changed

+6
-5
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { RawSourceMap } from 'vite-node'
22
import type { RuntimeRPC } from '../../types/rpc'
33
import type { TestProject } from '../project'
44
import type { ResolveSnapshotPathHandlerContext } from '../types/config'
5-
import { mkdir, writeFile } from 'node:fs/promises'
5+
import { mkdirSync } from 'node:fs'
6+
import { writeFile } from 'node:fs/promises'
67
import { join } from 'pathe'
78
import { hash } from '../hash'
89

@@ -54,14 +55,14 @@ export function createMethodsRPC(project: TestProject, options: MethodsOptions =
5455
const dir = join(project.tmpDir, transformMode)
5556
const name = hash('sha1', id, 'hex')
5657
const tmp = join(dir, name)
58+
if (!created.has(dir)) {
59+
mkdirSync(dir, { recursive: true })
60+
created.add(dir)
61+
}
5762
if (promises.has(tmp)) {
5863
await promises.get(tmp)
5964
return { id: tmp }
6065
}
61-
if (!created.has(dir)) {
62-
await mkdir(dir, { recursive: true })
63-
created.add(dir)
64-
}
6566
promises.set(
6667
tmp,
6768
writeFile(tmp, code, 'utf-8').finally(() => promises.delete(tmp)),

0 commit comments

Comments
 (0)