const e=[];e.push(`SIGHUP`,`SIGINT`,`SIGTERM`),process.platform!==`win32`&&e.push(`SIGALRM`,`SIGABRT`,`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),process.platform===`linux`&&e.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`);const t=e=>!!e&&typeof e==`object`&&typeof e.removeListener==`function`&&typeof e.emit==`function`&&typeof e.reallyExit==`function`&&typeof e.listeners==`function`&&typeof e.kill==`function`&&typeof e.pid==`number`&&typeof e.on==`function`,n=Symbol.for(`signal-exit emitter`),r=globalThis,i=Object.defineProperty.bind(Object);var a=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(r[n])return r[n];i(r,n,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,t){this.listeners[e].push(t)}removeListener(e,t){let n=this.listeners[e],r=n.indexOf(t);r!==-1&&(r===0&&n.length===1?n.length=0:n.splice(r,1))}emit(e,t,n){if(this.emitted[e])return!1;this.emitted[e]=!0;let r=!1;for(let i of this.listeners[e])r=i(t,n)===!0||r;return e===`exit`&&(r=this.emit(`afterExit`,t,n)||r),r}},o=class{};const s=e=>({onExit(t,n){return e.onExit(t,n)},load(){return e.load()},unload(){return e.unload()}});var c=class extends o{onExit(){return()=>{}}load(){}unload(){}},l=class extends o{#e=u.platform===`win32`?`SIGINT`:`SIGHUP`;#t=new a;#n;#r;#i;#a={};#o=!1;constructor(t){super(),this.#n=t,this.#a={};for(let n of e)this.#a[n]=()=>{let e=this.#n.listeners(n),{count:r}=this.#t,i=t;if(typeof i.__signal_exit_emitter__==`object`&&typeof i.__signal_exit_emitter__.count==`number`&&(r+=i.__signal_exit_emitter__.count),e.length===r){this.unload();let e=this.#t.emit(`exit`,null,n),r=n===`SIGHUP`?this.#e:n;e||t.kill(t.pid,r)}};this.#i=t.reallyExit,this.#r=t.emit}onExit(e,n){if(!t(this.#n))return()=>{};this.#o===!1&&this.load();let r=n?.alwaysLast?`afterExit`:`exit`;return this.#t.on(r,e),()=>{this.#t.removeListener(r,e),this.#t.listeners.exit.length===0&&this.#t.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#o){this.#o=!0,this.#t.count+=1;for(let t of e)try{let e=this.#a[t];e&&this.#n.on(t,e)}catch{}this.#n.emit=(e,...t)=>this.#c(e,...t),this.#n.reallyExit=e=>this.#s(e)}}unload(){this.#o&&(this.#o=!1,e.forEach(e=>{let t=this.#a[e];if(!t)throw Error(`Listener not defined for signal: `+e);try{this.#n.removeListener(e,t)}catch{}}),this.#n.emit=this.#r,this.#n.reallyExit=this.#i,--this.#t.count)}#s(e){return t(this.#n)?(this.#n.exitCode=e||0,this.#t.emit(`exit`,this.#n.exitCode,null),this.#i.call(this.#n,this.#n.exitCode)):0}#c(e,...n){let r=this.#r;if(e===`exit`&&t(this.#n)){typeof n[0]==`number`&&(this.#n.exitCode=n[0]);let t=r.call(this.#n,e,...n);return this.#t.emit(`exit`,this.#n.exitCode,null),t}else return r.call(this.#n,e,...n)}};const u=globalThis.process,{onExit:d,load:f,unload:p}=s(t(u)?new l(u):new c);export{d as t};
//# sourceMappingURL=mjs-5RaNlSCX.js.map