UNPKG

@stacksjs/dtsx

Version:

A modern, fast .d.ts generation tool, powered by Bun.

4 lines (3 loc) 1.8 kB
// @bun import{spawn as L}from"child_process";import{readFile as z,stat as A,writeFile as M}from"fs/promises";var q=typeof globalThis.Bun<"u",U=!q&&typeof process<"u"&&!!process.versions?.node,V=q?"bun":"node";class C{name;_size=-1;constructor(j){this.name=j}async exists(){try{return await A(this.name),!0}catch{return!1}}async text(){return z(this.name,"utf-8")}async arrayBuffer(){let j=await z(this.name);return j.buffer.slice(j.byteOffset,j.byteOffset+j.byteLength)}get size(){if(this._size===-1)return-1;return this._size}}class D{pid;stdout;stderr;stdin;exited;process;constructor(j){this.process=j,this.pid=j.pid??0,this.stdout=j.stdout,this.stderr=j.stderr,this.stdin=j.stdin,this.exited=new Promise((k)=>{j.on("exit",(y)=>{k(y??0)}),j.on("error",()=>{k(1)})})}kill(j){this.process.kill(j)}ref(){this.process.ref()}unref(){this.process.unref()}}function W(j){if(q)return globalThis.Bun.file(j);return new C(j)}async function P(j,k){if(q)return globalThis.Bun.write(j,k);let y=typeof k==="string"?k:k instanceof ArrayBuffer?Buffer.from(k):k;return await M(j,y),typeof k==="string"?Buffer.byteLength(k):k.byteLength}function X(j,k={}){if(q)return globalThis.Bun.spawn(j,k);let y=Array.isArray(j)?j:[j],[E,...I]=y,J={cwd:k.cwd,env:k.env,stdio:[k.stdin??"pipe",k.stdout??"pipe",k.stderr??"pipe"]},K=L(E,I,J);return new D(K)}async function Y(j){if(q)return globalThis.Bun.file(j).text();return z(j,"utf-8")}async function Z(j){if(q)return globalThis.Bun.file(j).exists();try{return await A(j),!0}catch{return!1}}async function $(j,k){await P(j,k)}function x(){if(q)return{name:"bun",version:globalThis.Bun.version,isBun:!0,isNode:!1};return{name:"node",version:process.versions.node,isBun:!1,isNode:!0}} export{q as Rc,U as Sc,V as Tc,W as Uc,P as Vc,X as Wc,Y as Xc,Z as Yc,$ as Zc,x as _c};