Files
orca/config/scripts/build-cli.mjs
T
Blue DaydreamingandNeil 51d25013f1 fix(typecheck): report Bun version probe timeouts (#33762)
When the pinned Bun binary is installed but its version probe times out,
required typecheck callers (repo typecheck, CLI build, E2E and mobile
typecheck) now report the timeout with the executable path and budget
instead of claiming Bun is missing. Each caller suggests its own compiler
fallback. Optional Bun consumers keep returning null and falling back.

Fixes #33707

Co-authored-by: Neil <neil@stably.ai>
2026-10-28 07:18:52 -07:00

90 lines
2.6 KiB
JavaScript

import { availableParallelism } from 'node:os'
import { createRequire } from 'node:module'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { runProcess } from '@orca/process-host'
import { describeProcessFailure } from './process-failure-message.mjs'
import { isDirectInvocation } from './script-entry-detection.mjs'
import { supportsTsrs } from './tsrs-typecheck-compiler.mjs'
import {
resolveProjectCompiler,
resolveTypecheckBunExecutable,
runTypecheckProjects,
selectTypecheckCompiler
} from './run-typecheck-projects-in-parallel.mjs'
const ROOT = fileURLToPath(new URL('../..', import.meta.url))
const CONFIG = 'config/tsconfig.build.cli.json'
export async function buildCli({
root = ROOT,
outDir = 'out',
check = runTypecheckProjects,
execute = runProcess,
compiler = process.env.ORCA_CLI_BUILD_COMPILER ?? 'bun',
resolveBunExecutable = resolveTypecheckBunExecutable
} = {}) {
if (compiler !== 'bun' && compiler !== 'tsrs') {
throw new Error(`Invalid ORCA_CLI_BUILD_COMPILER: ${compiler}`)
}
const emitArguments = [
'-p',
CONFIG,
'--outDir',
outDir,
'--composite',
'false',
'--incremental',
'false'
]
if (compiler === 'tsrs') {
const manifest = createRequire(join(root, 'package.json')).resolve('tsrs/package.json')
const result = await execute({
program: process.execPath,
args: [join(dirname(manifest), 'bin', 'tsrs'), ...emitArguments, '--noEmitOnError'],
cwd: root,
stdio: 'inherit',
timeoutMs: null
})
if (result.code !== 0) {
throw new Error(`CLI compilation failed: ${describeProcessFailure(result)}`)
}
return
}
const selection = selectTypecheckCompiler('bun', {
root,
resolveBunExecutable,
fallbackHint: supportsTsrs() ? 'set ORCA_CLI_BUILD_COMPILER=tsrs' : null
})
const failures = await check({
...selection,
root,
projects: [{ config: CONFIG, heapGib: 2 }],
bunThreads: availableParallelism()
})
if (failures.length > 0) {
throw failures[0]
}
// Bun has checked this exact project; retain TypeScript's emitter without checking it twice.
const result = await execute({
program: process.execPath,
args: [resolveProjectCompiler(CONFIG, root), ...emitArguments, '--noCheck'],
cwd: root,
stdio: 'inherit',
timeoutMs: null
})
if (result.code !== 0) {
throw new Error(`CLI emission failed: ${describeProcessFailure(result)}`)
}
}
if (isDirectInvocation(import.meta.url, process.argv[1])) {
try {
await buildCli()
} catch (error) {
console.error(error.message)
process.exitCode = 1
}
}