Skip to content

Commit

Permalink
chore: keep code
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 1, 2024
1 parent 006e0a5 commit f5e4ebf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/vitest/src/node/pools/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
},
async fetch(id, transformMode) {
const result = await project.vitenode.fetchResult(id, transformMode)
const code = result.code
if (result.externalize)
return result
if (!result.code && 'id' in result)
if ('id' in result)
return { id: result.id as string }

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

const dir = join(project.tmpDir, transformMode)
Expand All @@ -45,10 +46,8 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
await mkdir(dir, { recursive: true })
created.add(dir)
}
const code = result.code
promises.set(tmp, writeFile(tmp, code, 'utf-8').finally(() => promises.delete(tmp)))
await promises.get(tmp)
result.code = undefined
Object.assign(result, { id: tmp })
return { id: tmp }
},
Expand Down
4 changes: 2 additions & 2 deletions packages/web-worker/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from 'node:fs/promises'
import { readFileSync } from 'node:fs'
import type { WorkerGlobalState } from 'vitest'
import ponyfillStructuredClone from '@ungap/structured-clone'
import createDebug from 'debug'
Expand Down Expand Up @@ -69,7 +69,7 @@ export function getRunnerOptions(): any {
async fetchModule(id: string) {
const result = await rpc.fetch(id, 'web')
if (result.id && !result.externalize) {
const code = await readFile(result.id, 'utf-8')
const code = readFileSync(result.id, 'utf-8')
return { code }
}
return result
Expand Down

0 comments on commit f5e4ebf

Please sign in to comment.