import{spawn as e}from"node:child_process";async function t(t,n){let r=[...t.baseArgs];t.yoloArgs&&r.push(...t.yoloArgs),n?.args&&r.push(...n.args);let i={...process.env,...t.envVars,...n?.env},a=e(t.executable,r,{cwd:n?.cwd??process.cwd(),env:i,stdio:`inherit`,detached:!1}),o=`${t.executable} ${r.join(` `)}`;return new Promise((e,t)=>{a.on(`error`,e=>{t(Error(`Failed to spawn process: ${e.message}`))}),a.on(`spawn`,()=>{e({pid:a.pid,command:o})}),a.on(`exit`,e=>{e!==0&&e!==null&&t(Error(`Process exited with code ${e}`))})})}async function n(t){return new Promise(n=>{let r=e(process.platform===`win32`?`where`:`which`,[t],{stdio:`ignore`});r.on(`error`,()=>n(!1)),r.on(`exit`,e=>n(e===0))})}async function r(t,n=[`--version`]){return new Promise((r,i)=>{let a=``,o=e(t,n,{stdio:[`ignore`,`pipe`,`pipe`]});o.stdout?.on(`data`,e=>{a+=e.toString()}),o.stderr?.on(`data`,e=>{a+=e.toString()}),o.on(`error`,e=>{i(Error(`Failed to get version: ${e.message}`))}),o.on(`exit`,e=>{e===0?r(a.trim()):i(Error(`Failed to get version`))})})}async function i(t,n,r={}){let{cwd:i=process.cwd(),env:a={},silent:o=!1,throwOnError:s=!0}=r;return new Promise((r,c)=>{let l=``,u=``,d=e(t,n,{cwd:i,env:{...process.env,...a},stdio:o?[`ignore`,`pipe`,`pipe`]:[`inherit`,`pipe`,`pipe`]});d.stdout?.on(`data`,e=>{l+=e.toString(),o||process.stdout.write(e)}),d.stderr?.on(`data`,e=>{u+=e.toString(),o||process.stderr.write(e)}),d.on(`error`,e=>{let t={stdout:l.trim(),stderr:e.message,exitCode:1,success:!1};s?c(t):r(t)}),d.on(`exit`,e=>{let t=e??1,n={stdout:l.trim(),stderr:u.trim(),exitCode:t,success:t===0};s&&!n.success?c(n):r(n)})})}export{t as i,r as n,i as r,n as t};