From c9e68ced74e18e887466edcc6d5f2a608ef0d901 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 2 May 2024 10:44:00 +0200 Subject: [PATCH] fix: hash the name of the file when caching (#5654) --- packages/vitest/src/node/pools/rpc.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/node/pools/rpc.ts b/packages/vitest/src/node/pools/rpc.ts index 538ab2b5a94b..5d041b0ee8fd 100644 --- a/packages/vitest/src/node/pools/rpc.ts +++ b/packages/vitest/src/node/pools/rpc.ts @@ -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' @@ -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 }