Skip to content

Commit

Permalink
fix: don't send map
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 1, 2024
1 parent a37287f commit 006e0a5
Show file tree
Hide file tree
Showing 3 changed files with 16 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
@@ -1,5 +1,4 @@
import { mkdir, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import type { RawSourceMap } from 'vite-node'
import { join } from 'pathe'
import type { RuntimeRPC } from '../../types'
Expand Down Expand Up @@ -31,13 +30,12 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
if (result.externalize)
return result
if (!result.code && 'id' in result)
return result
return { id: result.id as string }

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

const code = result.code
const dir = join(tmpdir(), project.id, transformMode)
const dir = join(project.tmpDir, transformMode)
const tmp = join(dir, id.replace(/[/\\?%*:|"<>]/g, '_').replace('\0', '__x00__'))
if (promises.has(tmp)) {
await promises.get(tmp)
Expand All @@ -47,6 +45,7 @@ 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
Expand Down
11 changes: 11 additions & 0 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { promises as fs } from 'node:fs'
import { rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import fg from 'fast-glob'
import mm from 'micromatch'
import { dirname, isAbsolute, join, relative, resolve, toNamespacedPath } from 'pathe'
Expand Down Expand Up @@ -79,6 +81,7 @@ export class WorkspaceProject {
testFilesList: string[] | null = null

public readonly id = nanoid()
public readonly tmpDir = join(tmpdir(), this.id)

private _globalSetups: GlobalSetupFile[] | undefined
private _provided: ProvidedContext = {} as any
Expand Down Expand Up @@ -404,11 +407,19 @@ export class WorkspaceProject {
this.server.close(),
this.typechecker?.stop(),
this.browser?.close(),
this.clearTmpDir(),
].filter(Boolean)).then(() => this._provided = {} as any)
}
return this.closingPromise
}

private async clearTmpDir() {
try {
await rm(this.tmpDir, { force: true, recursive: true })
}
catch {}
}

async initBrowserProvider() {
if (!this.isBrowserEnabled())
return
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/runtime/execute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vm from 'node:vm'
import { pathToFileURL } from 'node:url'
import { readFile } from 'node:fs/promises'
import { readFileSync } from 'node:fs'
import type { ModuleCacheMap } from 'vite-node/client'
import { DEFAULT_REQUEST_STUBS, ViteNodeRunner } from 'vite-node/client'
import { isInternalRequest, isNodeBuiltin, isPrimitive, toFilePath } from 'vite-node/utils'
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function startVitestExecutor(options: ContextExecutorOptions) {

const result = await rpc().fetch(id, getTransformMode())
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 006e0a5

Please sign in to comment.