mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
perf(test): bundle Zod once per isolated Vitest invocation (#32298)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { resolve } from 'node:path'
|
||||
import { runProcessSync } from '@orca/process-host'
|
||||
import { createVitestZodBundle } from './vitest-zod-bundle.mjs'
|
||||
import {
|
||||
checkBunVersion,
|
||||
probeBunVersion,
|
||||
@@ -18,7 +19,9 @@ if (bunCheck.message) {
|
||||
if (!bunCheck.ok) {
|
||||
process.exitCode = 1
|
||||
} else {
|
||||
let zodBundle
|
||||
try {
|
||||
zodBundle = createVitestZodBundle(root)
|
||||
const result = runProcessSync({
|
||||
program: pinnedBun ?? 'bun',
|
||||
args: ['--bun', resolve(root, 'node_modules/vitest/vitest.mjs'), ...process.argv.slice(2)],
|
||||
@@ -27,7 +30,8 @@ if (!bunCheck.ok) {
|
||||
...process.env,
|
||||
ORCA_BACKGROUND_LAUNCH: '1',
|
||||
ORCA_TEST_NODE_EXECUTABLE: process.execPath,
|
||||
ORCA_TEST_NODE_VERSION: process.versions.node
|
||||
ORCA_TEST_NODE_VERSION: process.versions.node,
|
||||
ORCA_UNIT_ZOD_BUNDLE: zodBundle.path
|
||||
},
|
||||
stdio: 'inherit',
|
||||
timeoutMs: null
|
||||
@@ -35,7 +39,13 @@ if (!bunCheck.ok) {
|
||||
|
||||
process.exitCode = result.code ?? 1
|
||||
} catch (error) {
|
||||
console.error('Could not start Vitest. Install the Bun version in config/.bun-version.', error)
|
||||
console.error('Could not prepare or start Vitest:', error)
|
||||
process.exitCode = 1
|
||||
} finally {
|
||||
try {
|
||||
zodBundle?.cleanup()
|
||||
} catch (error) {
|
||||
console.warn('Could not remove the temporary Vitest Zod bundle:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { buildSync } from 'esbuild'
|
||||
|
||||
export function createVitestZodBundle(root) {
|
||||
const temporary = join(root, '.tmp')
|
||||
mkdirSync(temporary, { recursive: true })
|
||||
const directory = mkdtempSync(join(temporary, 'vitest-zod-'))
|
||||
const path = join(directory, 'zod.mjs')
|
||||
const cleanup = () => rmSync(directory, { recursive: true, force: true, maxRetries: 3 })
|
||||
try {
|
||||
buildSync({
|
||||
absWorkingDir: root,
|
||||
entryPoints: [fileURLToPath(import.meta.resolve('zod'))],
|
||||
outfile: path,
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
target: 'node24',
|
||||
sourcemap: true
|
||||
})
|
||||
return { path, cleanup }
|
||||
} catch (error) {
|
||||
cleanup()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,9 @@ const transforms = {
|
||||
},
|
||||
resolve: {
|
||||
alias: [
|
||||
...(process.env.ORCA_UNIT_ZOD_BUNDLE
|
||||
? [{ find: /^zod$/, replacement: process.env.ORCA_UNIT_ZOD_BUNDLE }]
|
||||
: []),
|
||||
...createWorkspaceSourceResolver().aliases,
|
||||
{ find: '@renderer', replacement: resolve('src/renderer/src') },
|
||||
{ find: '@', replacement: resolve('src/renderer/src') },
|
||||
|
||||
Reference in New Issue
Block a user