refactor: migrate Bun.spawn to Process utility with timeout and cleanup (#14448)

This commit is contained in:
Dax
2026-02-24 23:04:15 -05:00
committed by GitHub
parent da40ab7b3d
commit 814c1d398c
13 changed files with 203 additions and 114 deletions

View File

@@ -1,7 +1,8 @@
import { readableStreamToText } from "bun"
import { text } from "node:stream/consumers"
import { BunProc } from "../bun"
import { Instance } from "../project/instance"
import { Filesystem } from "../util/filesystem"
import { Process } from "../util/process"
import { Flag } from "@/flag/flag"
export interface Info {
@@ -213,12 +214,13 @@ export const rlang: Info = {
if (airPath == null) return false
try {
const proc = Bun.spawn(["air", "--help"], {
const proc = Process.spawn(["air", "--help"], {
stdout: "pipe",
stderr: "pipe",
})
await proc.exited
const output = await readableStreamToText(proc.stdout)
if (!proc.stdout) return false
const output = await text(proc.stdout)
// Check for "Air: An R language server and formatter"
const firstLine = output.split("\n")[0]
@@ -238,7 +240,7 @@ export const uvformat: Info = {
async enabled() {
if (await ruff.enabled()) return false
if (Bun.which("uv") !== null) {
const proc = Bun.spawn(["uv", "format", "--help"], { stderr: "pipe", stdout: "pipe" })
const proc = Process.spawn(["uv", "format", "--help"], { stderr: "pipe", stdout: "pipe" })
const code = await proc.exited
return code === 0
}

View File

@@ -8,6 +8,7 @@ import * as Formatter from "./formatter"
import { Config } from "../config/config"
import { mergeDeep } from "remeda"
import { Instance } from "../project/instance"
import { Process } from "../util/process"
export namespace Format {
const log = Log.create({ service: "format" })
@@ -110,13 +111,15 @@ export namespace Format {
for (const item of await getFormatter(ext)) {
log.info("running", { command: item.command })
try {
const proc = Bun.spawn({
cmd: item.command.map((x) => x.replace("$FILE", file)),
cwd: Instance.directory,
env: { ...process.env, ...item.environment },
stdout: "ignore",
stderr: "ignore",
})
const proc = Process.spawn(
item.command.map((x) => x.replace("$FILE", file)),
{
cwd: Instance.directory,
env: { ...process.env, ...item.environment },
stdout: "ignore",
stderr: "ignore",
},
)
const exit = await proc.exited
if (exit !== 0)
log.error("failed", {