Compare commits

...

4 Commits

Author SHA1 Message Date
Aiden Cline 699563e31f Merge branch 'dev' into snapshot-node-shim-stuff 2026-04-12 19:58:14 -05:00
Aiden Cline 4721b31d35 Merge branch 'dev' into snapshot-node-shim-stuff 2026-04-11 17:14:41 -05:00
Aiden Cline 8bce02e567 Merge branch 'dev' into snapshot-node-shim-stuff 2026-04-10 19:55:48 -05:00
Aiden Cline c3dc5a3466 wip: node shim signals 2026-04-10 16:32:16 -05:00
+20 -7
View File
@@ -6,20 +6,33 @@ const path = require("path")
const os = require("os") const os = require("os")
function run(target) { function run(target) {
const result = childProcess.spawnSync(target, process.argv.slice(2), { const child = childProcess.spawn(target, process.argv.slice(2), {
stdio: "inherit", stdio: "inherit",
}) })
if (result.error) { child.on("error", (err) => {
console.error(result.error.message) console.error(err.message)
process.exit(1) process.exit(1)
})
const forward = (sig) => {
if (!child.killed) {
try { child.kill(sig) } catch {}
}
} }
const code = typeof result.status === "number" ? result.status : 0 ;["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
process.exit(code) process.on(sig, () => forward(sig))
})
child.on("exit", (code, signal) => {
if (signal) {
process.kill(process.pid, signal)
return
}
process.exit(typeof code === "number" ? code : 1)
})
} }
const envPath = process.env.OPENCODE_BIN_PATH const envPath = process.env.OPENCODE_BIN_PATH
if (envPath) { if (envPath) {
run(envPath) return run(envPath)
} }
const scriptPath = fs.realpathSync(__filename) const scriptPath = fs.realpathSync(__filename)
@@ -28,7 +41,7 @@ const scriptDir = path.dirname(scriptPath)
// //
const cached = path.join(scriptDir, ".opencode") const cached = path.join(scriptDir, ".opencode")
if (fs.existsSync(cached)) { if (fs.existsSync(cached)) {
run(cached) return run(cached)
} }
const platformMap = { const platformMap = {