@stacksjs/dtsx
Version:
A modern, fast .d.ts generation tool, powered by Bun.
4 lines (3 loc) • 1.38 kB
JavaScript
// @bun
import{kf as m}from"./chunk-736mzc3x.js";import{xf as h}from"./chunk-pwwfmfhh.js";var b=100,c=new Map,a=new Map,u=new Map,g=0;function y(e,n,t){let r={fileName:e,text:n};c.delete(e),c.set(e,{file:r,hash:t});while(c.size>b){let s=c.keys().next().value;if(s===void 0)break;c.delete(s)}return r}function C(e,n,t){return u.set(e,(u.get(e)??0)+1),y(e,n,t)}function S(e,n,t=h(n)){let r=c.get(e);if(r?.hash===t)return c.delete(e),c.set(e,r),r.file;return C(e,n,t)}async function x(e,n,t={}){let r=h(n);if(c.get(e)?.hash===r)return S(e,n,r);let o=`${e}\x00${String(r)}`,i=a.get(o);if(i)return i;let d=(u.get(e)??0)+1;u.set(e,d);let f=g,l;return l=Promise.resolve().then(async()=>{try{if(n.length>=(t.asyncThreshold??1e5))await new Promise((p)=>setTimeout(p,Math.max(0,t.yieldInterval??0)));if(f===g&&u.get(e)===d)return y(e,n,r);return{fileName:e,text:n}}finally{if(a.get(o)===l)a.delete(o)}}),a.set(o,l),l}async function A(e,n={}){let t=new Map,r=m(n.concurrency,4);for(let s=0;s<e.length;s+=r){let o=await Promise.all(e.slice(s,s+r).map(async(i)=>({path:i.filePath,file:await x(i.filePath,i.sourceCode,n)})));for(let i of o)t.set(i.path,i.file)}return t}function v(){g++,c.clear(),a.clear(),u.clear()}function M(){return c.size}function z(){return a.size}function k(e,n={}){return e.length>=(n.asyncThreshold??1e5)}
export{S as Oe,x as Pe,A as Qe,v as Re,M as Se,z as Te,k as Ue};