@visulima/vis 4.1.18 → 4.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/bin.js +1 -1
  3. package/dist/binx.js +1 -1
  4. package/dist/packem_chunks/catalog.js +42 -44
  5. package/dist/packem_chunks/cli-exec.js +1 -1
  6. package/dist/packem_chunks/cli-main.js +142 -146
  7. package/dist/packem_chunks/fix.js +1 -1
  8. package/dist/packem_chunks/handler10.js +1 -1
  9. package/dist/packem_chunks/handler13.js +1 -1
  10. package/dist/packem_chunks/handler15.js +1 -1
  11. package/dist/packem_chunks/handler19.js +1 -1
  12. package/dist/packem_chunks/handler2.js +1 -1
  13. package/dist/packem_chunks/handler21.js +1 -1
  14. package/dist/packem_chunks/handler24.js +1 -1
  15. package/dist/packem_chunks/handler28.js +1 -1
  16. package/dist/packem_chunks/handler3.js +1 -1
  17. package/dist/packem_chunks/handler5.js +1 -1
  18. package/dist/packem_chunks/handler59.js +1 -1
  19. package/dist/packem_chunks/handler6.js +1 -1
  20. package/dist/packem_chunks/handler60.js +1 -1
  21. package/dist/packem_chunks/handler66.js +1 -1
  22. package/dist/packem_chunks/handler67.js +10 -10
  23. package/dist/packem_chunks/handler70.js +1 -1
  24. package/dist/packem_chunks/handler72.js +1 -1
  25. package/dist/packem_chunks/handler73.js +1 -1
  26. package/dist/packem_chunks/handler75.js +1 -1
  27. package/dist/packem_chunks/handler78.js +1 -1
  28. package/dist/packem_chunks/heal.js +1 -1
  29. package/dist/packem_chunks/help-command.js +1 -1
  30. package/dist/packem_chunks/index5.js +2 -2
  31. package/dist/packem_chunks/keys-refresh.js +1 -1
  32. package/dist/packem_chunks/verify-lockfile.js +1 -1
  33. package/dist/packem_shared/Table-kgZ-Cd21-DdNsp69H.js +9 -0
  34. package/dist/packem_shared/{affected-selection-CsLSvm80.js → affected-selection-Bt4qkPUb.js} +1 -1
  35. package/dist/packem_shared/{ai-fix-CyUx_ZAB.js → ai-fix-BHyx1F1j.js} +1 -1
  36. package/dist/packem_shared/{bin-I6B0n2r_.js → bin-Bq3tJmvE.js} +1 -1
  37. package/dist/packem_shared/{failure-log-DE_MJCzB.js → failure-log-3R522Vb5.js} +1 -1
  38. package/dist/packem_shared/formatBytes-BHAzNIrn-XohRrPdt.js +4 -0
  39. package/dist/packem_shared/{index-CIIKPX4H.js → index-Czrll7SU.js} +1 -1
  40. package/dist/packem_shared/{index-RyhUpZw7.js → index-Vm90Te96.js} +1 -1
  41. package/dist/packem_shared/{lifecycle-DW8KRF5d.js → lifecycle-CAIJbxIa.js} +1 -1
  42. package/dist/packem_shared/{package-version-BouRuXiK.js → package-version-DFlytdgJ.js} +1 -1
  43. package/dist/packem_shared/{packument-CHdDsn0O.js → packument-DyuhH1Gz.js} +1 -1
  44. package/dist/packem_shared/{project-name-filter-CwcQT14j.js → project-name-filter-CC5FF49q.js} +1 -1
  45. package/dist/packem_shared/{provenance-w-NIPtim.js → provenance-BH80RHXx.js} +1 -1
  46. package/dist/packem_shared/{registry-keys-_IKDLSbu.js → registry-keys-BWHRFWbb.js} +1 -1
  47. package/dist/packem_shared/{resolve-explicit-CsTmALmE.js → resolve-explicit-DuJ3mbzt.js} +1 -1
  48. package/dist/packem_shared/{s1ngularity-BRk_GMUj.js → s1ngularity-BJ5j2vbJ.js} +1 -1
  49. package/dist/packem_shared/{signatures-ijwqxAtF.js → signatures-BP042BlB.js} +1 -1
  50. package/dist/packem_shared/{vis-update-app-DNeU8RBQ.js → vis-update-app-CR21zyht.js} +1 -1
  51. package/dist/packem_shared/{vis-user-error-CnMuoAGo.js → vis-user-error-qqqhLoF6.js} +12 -12
  52. package/index.js +52 -52
  53. package/package.json +11 -11
  54. package/dist/packem_shared/Table-DyORjLji-CC9cYgCG.js +0 -11
  55. package/dist/packem_shared/formatBytes-BHAzNIrn-Bkk_uRS-.js +0 -4
@@ -1,7 +1,7 @@
1
- import{a as nt,e as st,l as At,z as O}from"../packem_shared/index-DHD8wb6Z.js";import{L as Et}from"../packem_shared/index-BisalDCf.js";import{p as bt}from"./cli-main.js";import{X as xt,O as Ct,H as S,q as L,M as W,r as E,F as N,t as G,Q as V,Y as jt,U as K,u as kt,W as D,v as J,C as Y,w as Lt,G as Wt,P as Ut,x as St,y as Tt,z as Ot,Z as Pt,A as _t,B as It,E as Rt,I as zt,J as Nt,K as vt,L as Ft,N as Mt,V as Bt}from"../packem_shared/formatBytes-BHAzNIrn-Bkk_uRS-.js";import{P as I,L as qt}from"./catalog.js";const Qt=(t,e)=>typeof t!="string"||t===""?"":t[0].toLowerCase()+t.slice(1),Gt=new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))","g"),Vt=t=>{if(typeof t!="string")throw new TypeError(`The "value" argument must be of type string. Received ${typeof t}`);return t.replaceAll(Gt,"")},v=new I(1e3),Kt=/[.*+?^${}()|[\]\\]/g,Dt=t=>{const e=t.join("");if(v.has(e)){const r=v.get(e);return r.lastIndex=0,r}const s=t.map(r=>r.replaceAll(Kt,String.raw`\$&`)).join("|"),n=new RegExp(s,"g");return v.set(e,n),n},Jt=t=>{const e=[];let s=0,n;for(L.lastIndex=0;(n=L.exec(t))!==null;)n.index>s&&e.push(t.slice(s,n.index)),e.push(n[0]),s=L.lastIndex;return s<t.length&&e.push(t.slice(s)),e.filter(Boolean)},Yt=/[ČŠŽĐ]/i,rt=new Uint8Array(128),ot=new Uint8Array(128),it=new Uint8Array(128);for(let t=0;t<128;t++)rt[t]=t>=65&&t<=90?1:0,ot[t]=t>=97&&t<=122?1:0,it[t]=t>=48&&t<=57?1:0;const F=t=>rt[t],X=t=>ot[t],M=t=>it[t],j=(t,e,s,n,r)=>{if(t.length===0)return[];let o=!1;const a=Object.values(e);for(const u of a)if(u(t[0])){o=!0;break}if(!o&&!s)return[t];const l=[...t],h=[];let i=l[0],p="other";const d=Object.entries(e);for(const u of d){const[f,g]=u;if(g(l[0])){p=f;break}}let c=s&&n?l[0]===l[0].toLocaleUpperCase(n):!1;for(let u=1;u<l.length;u++){const f=l[u];let g="other";for(const w of d){const[$,A]=w;if(A(f)){g=$;break}}const y=s&&n?f===f.toLocaleUpperCase(n):!1;let m=!1;r?m=r(p,g,c,y,f,u,l):(p!==g&&p!=="other"&&g!=="other"&&(m=!0),s&&g!=="other"&&!c&&y&&(m=!0)),m?(h.push(i),i=f):i+=f,p=g,s&&(c=y)}return i&&i.length>0&&h.push(i),h.length>0?h:[t]},Xt=(t,e,s,n)=>{if(s.size===0)return e;for(const r of s)if(t.startsWith(r,e))return n.push(r),e+r.length;return e},lt=(t,e=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let s=0;const n=[],r=t.length;for(let o=1;o<r;o++){const a=Xt(t,s,e,n);if(a!==s){s=a,o=s-1;continue}const l=t.codePointAt(o-1),h=t.codePointAt(o),i=l&&l<128&&F(l),p=h&&h<128&&F(h),d=l&&l<128&&X(l),c=l&&l<128&&M(l),u=h&&h<128&&M(h);if(d&&p){n.push(t.slice(s,o)),s=o;continue}if(c&&!u||!c&&u){n.push(t.slice(s,o)),s=o;continue}if(u&&!c){let f=!1,g=!1;if(o+1<r){const y=t.codePointAt(o+1);f=y&&y<128&&F(y),g=y&&y<128&&M(y)}if(!g&&f){n.push(t.slice(s,o),t.slice(o,o+1)),s=o+1;continue}}if(o+1<r){const f=t.codePointAt(o+1),g=f&&f<128&&X(f);if(i&&p&&g){const y=t.slice(s,o+1);e.has(y)||(n.push(t.slice(s,o)),s=o)}}}return s<r&&n.push(t.slice(s)),n.filter(o=>o!=="")},at=(t,e,s)=>{if(t.length===0)return[];const n=t===t.toLocaleUpperCase(e);if(e.startsWith("de")){if(!n&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(e))return[t];const i=[...t],p=i.length,d=[];let c=i[0],u=i[0]===i[0].toLocaleUpperCase(e),f=u,g=u?0:-1;for(let y=1;y<p;y++){const m=i[y],w=m===m.toLocaleUpperCase(e);if(w===u)c+=m;else if(w)c&&c.length>0&&(d.push(c),c=m),f=!0,g=y;else{if(f&&y-g>1){const $=i[y-1],A=c.slice(0,-1);A&&A.length>0&&d.push(A),c=$+m}else c+=m;f=!1,g=-1}u=w}return c&&c.length>0&&d.push(c),d}if(e.startsWith("uk")||e.startsWith("ru")||e.startsWith("bg")||e.startsWith("sr")||e.startsWith("mk")||e.startsWith("be")){if(!W.test(t)&&!E.test(t))return[t];const i=[...t],p=i.length,d=[];let c=i[0];const u=i[0];let f;W.test(u)?f=1:E.test(u)?f=2:f=0;let g=u===u.toLocaleUpperCase(e);for(let m=1;m<p;m++){const w=i[m];let $;W.test(w)?$=1:E.test(w)?$=2:$=0;const A=w===w.toLocaleUpperCase(e);f!==$&&(f===1||f===2)&&($===1||$===2)||$===f&&!g&&A?(d.push(c),c=w):c+=w,f=$,g=A}c&&c.length>0&&d.push(c);const y=[];for(let m=0;m<d.length;m++)m<d.length-1&&d[m].length===1&&E.test(d[m])&&W.test(d[m+1][0])?(y.push(d[m]+d[m+1]),m+=1):y.push(d[m]);return y}if(e.startsWith("el")){if(!N.test(t)&&!E.test(t))return[t];const i=[];G.lastIndex=0;let p;for(;(p=G.exec(t))!==null;)i.push(p[0]);i.length===0&&i.push(t);const d=[];if(i.length===1){const c=i[0];if(!c||!N.test(c[0])||c.length===1)return[c??t]}for(const c of i){if(!c)continue;if(!N.test(c[0])||c.length===1){d.push(c);continue}const u=c.length;let f=c[0],g=c[0]===c[0].toLocaleUpperCase(e);for(let y=1;y<u;y++){const m=c[y],w=m===m.toLocaleUpperCase(e);!g&&w?(d.push(f),f=m):f+=m,g=w}f&&d.push(f)}return d}if(e.startsWith("ja")||e.startsWith("ko")){const i=e.startsWith("ja"),p=i?{hiragana:c=>kt.test(c),kanji:c=>K.test(c),katakana:c=>jt.test(c),latin:c=>E.test(c)}:{hangul:c=>D.test(c),latin:c=>E.test(c)},d=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(i){const c=j(t,p,!1,e,(f,g)=>f==="hiragana"&&g==="katakana"||f==="katakana"&&g==="hiragana"||f==="hiragana"&&g==="latin"||f==="katakana"&&g==="latin"||f==="kanji"&&g==="latin"||f==="latin"&&(g==="hiragana"||g==="katakana"||g==="kanji")),u=[];for(const f of c){const g=f;g.length===1&&d.has(g)&&u.length>0?u[u.length-1]=u.at(-1)+g:u.push(g)}return u.length>0?u:[t]}return j(t,p,!1,e,(c,u)=>c==="hangul"&&u==="latin"||c==="latin"&&u==="hangul")}if(e.startsWith("sl")){const i=[...t],p=i.length,d=[];let c=i[0],u=i[0]===i[0].toLocaleUpperCase(e);for(let f=1;f<p;f++){const g=i[f],y=g===g.toLocaleUpperCase(e),m=Yt.test(g),w=f<p-1&&i[f+1]===i[f+1].toLocaleUpperCase(e);!u&&y||m&&w?(d.push(c),c=g,m&&w&&(d.push(c),c="")):c+=g,u=y}return c&&c.length>0&&d.push(c),d}if(e.startsWith("zh"))return j(t,{han:i=>K.test(i),latin:i=>E.test(i)},!1,e);if(["ar","fa","he","ur"].includes(e.split("-")[0])){const i=p=>J.test(p)||Y.test(p);return j(t,{latin:p=>E.test(p),rtl:p=>i(p)},!1,e)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(e.split("-")[0])){const i=p=>Lt.test(p)||Wt.test(p)||Ut.test(p)||St.test(p)||Tt.test(p)||Ot.test(p)||Pt.test(p)||_t.test(p)||It.test(p)||Rt.test(p)||zt.test(p)||Nt.test(p)||vt.test(p)||Ft.test(p)||Mt.test(p)||Bt.test(p);return j(t,{indic:p=>i(p),latin:p=>E.test(p)},!1,e)}if(["be","bg","ru","sr","uk"].includes(e))return j(t,{cyrillic:i=>W.test(i),latin:i=>E.test(i)},!0,e);if(["ar","fa","he"].includes(e))return j(t,{latin:i=>E.test(i),rtl:i=>J.test(i)||Y.test(i)},!1,e);if(e.startsWith("ko"))return j(t,{hangul:i=>D.test(i),latin:i=>E.test(i)},!1,e);if(e.startsWith("uz")){if(!W.test(t)&&!E.test(t))return[t];const i=[...t],p=i.length,d=[];let c=i[0],u=i[0]===i[0].toLocaleUpperCase(e);for(let f=1;f<p;f++){const g=i[f],y=g===g.toLocaleUpperCase(e);if(V.test(g)||V.test(i[f-1])){c+=g;continue}!u&&y?(d.push(c),c=g):c+=g,u=y}return c&&c.length>0&&d.push(c),d}const r=[...t],o=r.length,a=[];let l=r[0],h=r[0]===r[0].toLocaleUpperCase(e);for(const i of s)if(t.startsWith(i)){a.push(i),l=r[i.length],h=l===l.toLocaleUpperCase(e);break}for(let i=1;i<o;i++){const p=r[i],d=p===p.toLocaleUpperCase(e);let c=0;for(const u of s)if(t.startsWith(u,i)){a.push(l,u),c=u.length,l="";const f=u.at(-1);f&&(h=f===f.toLocaleUpperCase(e));break}if(c>0){i+=c-1;continue}!h&&d?(a.push(l),l=p):l+=p,h=d}return l&&a.push(l),a},Zt=(t,e,s)=>{const n=[],r=S.test(t)?t.split(S).filter(Boolean):[t];for(const o of r){const a=o;if(S.test(a))n.push(a);else{L.lastIndex=0;const l=L.test(a)?Jt(a).filter(Boolean):[a];for(const h of l)if(L.lastIndex=0,L.test(h))n.push(h);else if(e){const i=e.toLowerCase().split("-")[0];n.push(...at(h,i,s))}else n.push(...lt(h,s))}}return n},R=(t,e={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:s=!1,handleEmoji:n=!1,knownAcronyms:r=[],locale:o,normalize:a=!1,separators:l,stripAnsi:h=!1,stripEmoji:i=!1}=e,p=new Set([...r].toSorted((m,w)=>w.length-m.length));let d=t;h&&(d=Vt(d)),i&&(d=xt(d));let c;Array.isArray(l)?c=Dt(l):l instanceof RegExp?c=l:c=Ct;const u=[];let f=d;const g=c.flags.includes("g")?c:new RegExp(c.source,`${c.flags}g`);for(;f.length>0;){const m=g.exec(f);if(!m){f===".."?u.push(".."):f==="."?u.push("."):f.length>0&&u.push(f);break}const w=m.index,$=m[0],A=$.length,T=f.slice(0,w),$t=f.slice(w+A);if($.startsWith("../"))u.push(".."),f=f.slice(w+3);else if($.startsWith("./"))u.push("."),f=f.slice(w+2);else if(w===0&&$==="..")u.push(".."),f=f.slice(2);else if(w===0&&$===".")u.push("."),f=f.slice(1);else{T.length>0&&u.push(T);let x=0;for(;(x=$.indexOf("../",x))!==-1;)u.push(".."),x+=3;for(x=0;(x=$.indexOf("./",x))!==-1;)(x===0||$[x-1]!==".")&&u.push("."),x+=2;let C=$t;for(;C.startsWith("../");)u.push(".."),C=C.slice(3);for(;C.startsWith("./");)u.push("."),C=C.slice(2);if(C===".."){u.push("..");break}else if(C==="."){u.push(".");break}else f=C}g.lastIndex=0}if(u.length===0){const m=d.split(c).filter(Boolean);u.push(...m)}let y=[];for(const m of u)s||n?y.push(...Zt(m,o,p)):o?y.push(...at(m,o,p)):y.push(...lt(m,p));return a&&(y=y.map(m=>p.has(m)?m:o&&m===m.toLocaleUpperCase(o)?m[0]+m.slice(1).toLocaleLowerCase(o):m.toUpperCase()===m&&!p.has(m)?m.slice(0,1)+m.slice(1).toLowerCase():m)),y},q=(t,e)=>typeof t!="string"||t===""?"":(e?.locale?t[0].toLocaleUpperCase(e.locale):t[0].toUpperCase())+t.slice(1),Ht=(t,e)=>`${t}::${e?.joiner??""}::${e?.locale??""}::${e?.knownAcronyms?.join(",")??""}::${e?.normalize?"true":"false"}::${e?.stripAnsi?"true":"false"}::${e?.stripEmoji?"true":"false"}::${e?.handleAnsi?"true":"false"}::${e?.handleEmoji?"true":"false"}`,z=(t,e)=>{const{length:s}=t;if(s===0)return"";if(s===1)return t[0];const n=[];let r="",o="";for(let a=0;a<s;a++){const l=t[a];if(S.test(l)){r?(n.push(r+o+l),r="",o=""):(n.length>0&&n.push(e),r=l);continue}r?(o&&(o+=e),o+=l):(n.length>0&&n.push(e),n.push(l))}return n.join("")},te=/(?<![a-zß])SS(?![a-z])/g,ee=t=>t.replaceAll(te,"ß"),ne=(t,e)=>{if(typeof t!="string"||!t)return"";let s=!0;return z(R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(r=>{const o=r,a=o.toLowerCase();return s?(s=!1,Qt(a)):q(a,e)}),"")},se=new I(1e3),Q=(t,e)=>{if(typeof t!="string")return"";const s=e?.cache??!1,n=e?.cacheStore??se;let r;if(s&&(r=Ht(t,e)),s&&r&&n.has(r))return n.get(r);const o=R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(l=>{if(e?.handleAnsi&&S.test(l))return l;if(e?.toUpperCase)return e.locale?l.toLocaleUpperCase(e.locale):l.toUpperCase();const h=e?.locale?.startsWith("de")?ee(l):l;return e?.locale?h.toLocaleLowerCase(e.locale):h.toLowerCase()}),a=z(o,e?.joiner??"-");return s&&r&&n.set(r,a),a},re=new I(1e3),oe=(t,e)=>Q(t,{cacheStore:re,...e,joiner:"_",toUpperCase:!0}),ie=(t,e)=>typeof t!="string"||!t?"":z(R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(n=>q(n.toLowerCase(),{locale:e?.locale})),""),le=new I(1e3),ae=(t,e)=>Q(t,{cacheStore:le,...e,joiner:"_"}),ce=(t,e)=>typeof t!="string"?"":z(R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(n=>q(n,{locale:e?.locale})),"-"),b=t=>t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?String(t):JSON.stringify(t),Z={camel_case:t=>ne(b(t)),kebab_case:t=>Q(b(t)),lower_case:t=>b(t).toLowerCase(),pascal_case:t=>ie(b(t)),path_join:(t,...e)=>{const s=[b(t),...e.map(n=>b(n))];return st(...s)},path_relative:(t,e)=>nt(b(e),b(t)),snake_case:t=>ae(b(t)),upper_case:t=>b(t).toUpperCase(),upper_kebab_case:t=>ce(b(t)),upper_snake_case:t=>oe(b(t))},ct=(t,e,s=[])=>{const n=Z[t];if(!n)throw new Error(`Unknown filter "${t}". Known filters: ${Object.keys(Z).sort().join(", ")}.`);return n(e,...s)},ft=t=>{const e=[];let s=0,n=0,r,o=-1;for(const a of t){if(o+=1,r){a===r&&(r=void 0);continue}if(a==='"'||a==="'"){r=a;continue}a==="("?s+=1:a===")"?s-=1:a===","&&s===0&&(e.push(t.slice(n,o)),n=o+1)}return e.push(t.slice(n)),e},fe=t=>{if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1)},ue=/\[([^\]]+)\]/g,pe=t=>{const e=t.trim(),s=e.indexOf("(");if(s===-1)return{args:[],name:e};if(!e.endsWith(")"))throw new Error(`Filter call "${t}" missing closing ")"`);const n=e.slice(0,s).trim(),r=e.slice(s+1,-1).trim();return r===""?{args:[],name:n}:{args:ft(r).map(a=>{const l=a.trim();return fe(l)??l}),name:n}},he=t=>{const e=t.split("|").map(r=>r.trim()),s=e[0]??"";if(!s)throw new Error(`Empty variable name in expression "${t}"`);return{filters:e.slice(1).map(r=>pe(r)),name:s}},de=t=>t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?String(t):JSON.stringify(t),me=(t,e)=>{const s=t.replaceAll(ue,(n,r)=>{const{filters:o,name:a}=he(r);if(!Object.hasOwn(e,a))throw new Error(`Variable "${a}" used in filename "${t}" but not defined`);let l=e[a];for(const h of o)l=ct(h.name,l,h.args);return de(l)});return ut(s)},ut=t=>t.split("/").map(e=>e.endsWith(".tera")||e.endsWith(".twig")?e.slice(0,-5):e).join("/"),ge=t=>t.endsWith(".raw")?t.slice(0,-4):t,ye=t=>{const e=t.split("/");return(e.at(-1)??"").startsWith("_")?!0:e.slice(0,-1).includes("partials")},k="---",we=(t,e)=>{if(!t.startsWith(`${k}
1
+ import{a as nt,e as st,l as At,z as O}from"../packem_shared/index-DHD8wb6Z.js";import{L as Et}from"../packem_shared/index-BisalDCf.js";import{p as bt}from"./cli-main.js";import{q as xt,L as Ct,T as S,R as L,B as W,U as E,O as N,K as Q,Z as V,W as jt,r as K,t as kt,F as D,u as Y,x as J,H as Lt,w as Wt,M as Ut,C as St,P as Tt,v as Ot,y as Pt,Y as _t,z as It,J as Rt,A as zt,V as Nt,E as vt,G as Ft,I as Mt,N as Bt}from"../packem_shared/formatBytes-BHAzNIrn-XohRrPdt.js";import{P as I,L as qt}from"./catalog.js";const Gt=(t,e)=>typeof t!="string"||t===""?"":t[0].toLowerCase()+t.slice(1),Qt=new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))","g"),Vt=t=>{if(typeof t!="string")throw new TypeError(`The "value" argument must be of type string. Received ${typeof t}`);return t.replaceAll(Qt,"")},v=new I(1e3),Kt=/[.*+?^${}()|[\]\\]/g,Dt=t=>{const e=t.join("");if(v.has(e)){const r=v.get(e);return r.lastIndex=0,r}const s=t.map(r=>r.replaceAll(Kt,String.raw`\$&`)).join("|"),n=new RegExp(s,"g");return v.set(e,n),n},Yt=t=>{const e=[];let s=0,n;for(L.lastIndex=0;(n=L.exec(t))!==null;)n.index>s&&e.push(t.slice(s,n.index)),e.push(n[0]),s=L.lastIndex;return s<t.length&&e.push(t.slice(s)),e.filter(Boolean)},Jt=/[ČŠŽĐ]/i,rt=new Uint8Array(128),ot=new Uint8Array(128),it=new Uint8Array(128);for(let t=0;t<128;t++)rt[t]=t>=65&&t<=90?1:0,ot[t]=t>=97&&t<=122?1:0,it[t]=t>=48&&t<=57?1:0;const F=t=>rt[t],Z=t=>ot[t],M=t=>it[t],j=(t,e,s,n,r)=>{if(t.length===0)return[];let o=!1;const a=Object.values(e);for(const u of a)if(u(t[0])){o=!0;break}if(!o&&!s)return[t];const l=[...t],h=[];let i=l[0],p="other";const d=Object.entries(e);for(const u of d){const[f,g]=u;if(g(l[0])){p=f;break}}let c=s&&n?l[0]===l[0].toLocaleUpperCase(n):!1;for(let u=1;u<l.length;u++){const f=l[u];let g="other";for(const w of d){const[$,A]=w;if(A(f)){g=$;break}}const y=s&&n?f===f.toLocaleUpperCase(n):!1;let m=!1;r?m=r(p,g,c,y,f,u,l):(p!==g&&p!=="other"&&g!=="other"&&(m=!0),s&&g!=="other"&&!c&&y&&(m=!0)),m?(h.push(i),i=f):i+=f,p=g,s&&(c=y)}return i&&i.length>0&&h.push(i),h.length>0?h:[t]},Zt=(t,e,s,n)=>{if(s.size===0)return e;for(const r of s)if(t.startsWith(r,e))return n.push(r),e+r.length;return e},lt=(t,e=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let s=0;const n=[],r=t.length;for(let o=1;o<r;o++){const a=Zt(t,s,e,n);if(a!==s){s=a,o=s-1;continue}const l=t.codePointAt(o-1),h=t.codePointAt(o),i=l&&l<128&&F(l),p=h&&h<128&&F(h),d=l&&l<128&&Z(l),c=l&&l<128&&M(l),u=h&&h<128&&M(h);if(d&&p){n.push(t.slice(s,o)),s=o;continue}if(c&&!u||!c&&u){n.push(t.slice(s,o)),s=o;continue}if(u&&!c){let f=!1,g=!1;if(o+1<r){const y=t.codePointAt(o+1);f=y&&y<128&&F(y),g=y&&y<128&&M(y)}if(!g&&f){n.push(t.slice(s,o),t.slice(o,o+1)),s=o+1;continue}}if(o+1<r){const f=t.codePointAt(o+1),g=f&&f<128&&Z(f);if(i&&p&&g){const y=t.slice(s,o+1);e.has(y)||(n.push(t.slice(s,o)),s=o)}}}return s<r&&n.push(t.slice(s)),n.filter(o=>o!=="")},at=(t,e,s)=>{if(t.length===0)return[];const n=t===t.toLocaleUpperCase(e);if(e.startsWith("de")){if(!n&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(e))return[t];const i=[...t],p=i.length,d=[];let c=i[0],u=i[0]===i[0].toLocaleUpperCase(e),f=u,g=u?0:-1;for(let y=1;y<p;y++){const m=i[y],w=m===m.toLocaleUpperCase(e);if(w===u)c+=m;else if(w)c&&c.length>0&&(d.push(c),c=m),f=!0,g=y;else{if(f&&y-g>1){const $=i[y-1],A=c.slice(0,-1);A&&A.length>0&&d.push(A),c=$+m}else c+=m;f=!1,g=-1}u=w}return c&&c.length>0&&d.push(c),d}if(e.startsWith("uk")||e.startsWith("ru")||e.startsWith("bg")||e.startsWith("sr")||e.startsWith("mk")||e.startsWith("be")){if(!W.test(t)&&!E.test(t))return[t];const i=[...t],p=i.length,d=[];let c=i[0];const u=i[0];let f;W.test(u)?f=1:E.test(u)?f=2:f=0;let g=u===u.toLocaleUpperCase(e);for(let m=1;m<p;m++){const w=i[m];let $;W.test(w)?$=1:E.test(w)?$=2:$=0;const A=w===w.toLocaleUpperCase(e);f!==$&&(f===1||f===2)&&($===1||$===2)||$===f&&!g&&A?(d.push(c),c=w):c+=w,f=$,g=A}c&&c.length>0&&d.push(c);const y=[];for(let m=0;m<d.length;m++)m<d.length-1&&d[m].length===1&&E.test(d[m])&&W.test(d[m+1][0])?(y.push(d[m]+d[m+1]),m+=1):y.push(d[m]);return y}if(e.startsWith("el")){if(!N.test(t)&&!E.test(t))return[t];const i=[];Q.lastIndex=0;let p;for(;(p=Q.exec(t))!==null;)i.push(p[0]);i.length===0&&i.push(t);const d=[];if(i.length===1){const c=i[0];if(!c||!N.test(c[0])||c.length===1)return[c??t]}for(const c of i){if(!c)continue;if(!N.test(c[0])||c.length===1){d.push(c);continue}const u=c.length;let f=c[0],g=c[0]===c[0].toLocaleUpperCase(e);for(let y=1;y<u;y++){const m=c[y],w=m===m.toLocaleUpperCase(e);!g&&w?(d.push(f),f=m):f+=m,g=w}f&&d.push(f)}return d}if(e.startsWith("ja")||e.startsWith("ko")){const i=e.startsWith("ja"),p=i?{hiragana:c=>kt.test(c),kanji:c=>K.test(c),katakana:c=>jt.test(c),latin:c=>E.test(c)}:{hangul:c=>D.test(c),latin:c=>E.test(c)},d=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(i){const c=j(t,p,!1,e,(f,g)=>f==="hiragana"&&g==="katakana"||f==="katakana"&&g==="hiragana"||f==="hiragana"&&g==="latin"||f==="katakana"&&g==="latin"||f==="kanji"&&g==="latin"||f==="latin"&&(g==="hiragana"||g==="katakana"||g==="kanji")),u=[];for(const f of c){const g=f;g.length===1&&d.has(g)&&u.length>0?u[u.length-1]=u.at(-1)+g:u.push(g)}return u.length>0?u:[t]}return j(t,p,!1,e,(c,u)=>c==="hangul"&&u==="latin"||c==="latin"&&u==="hangul")}if(e.startsWith("sl")){const i=[...t],p=i.length,d=[];let c=i[0],u=i[0]===i[0].toLocaleUpperCase(e);for(let f=1;f<p;f++){const g=i[f],y=g===g.toLocaleUpperCase(e),m=Jt.test(g),w=f<p-1&&i[f+1]===i[f+1].toLocaleUpperCase(e);!u&&y||m&&w?(d.push(c),c=g,m&&w&&(d.push(c),c="")):c+=g,u=y}return c&&c.length>0&&d.push(c),d}if(e.startsWith("zh"))return j(t,{han:i=>K.test(i),latin:i=>E.test(i)},!1,e);if(["ar","fa","he","ur"].includes(e.split("-")[0])){const i=p=>Y.test(p)||J.test(p);return j(t,{latin:p=>E.test(p),rtl:p=>i(p)},!1,e)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(e.split("-")[0])){const i=p=>Lt.test(p)||Wt.test(p)||Ut.test(p)||St.test(p)||Tt.test(p)||Ot.test(p)||Pt.test(p)||_t.test(p)||It.test(p)||Rt.test(p)||zt.test(p)||Nt.test(p)||vt.test(p)||Ft.test(p)||Mt.test(p)||Bt.test(p);return j(t,{indic:p=>i(p),latin:p=>E.test(p)},!1,e)}if(["be","bg","ru","sr","uk"].includes(e))return j(t,{cyrillic:i=>W.test(i),latin:i=>E.test(i)},!0,e);if(["ar","fa","he"].includes(e))return j(t,{latin:i=>E.test(i),rtl:i=>Y.test(i)||J.test(i)},!1,e);if(e.startsWith("ko"))return j(t,{hangul:i=>D.test(i),latin:i=>E.test(i)},!1,e);if(e.startsWith("uz")){if(!W.test(t)&&!E.test(t))return[t];const i=[...t],p=i.length,d=[];let c=i[0],u=i[0]===i[0].toLocaleUpperCase(e);for(let f=1;f<p;f++){const g=i[f],y=g===g.toLocaleUpperCase(e);if(V.test(g)||V.test(i[f-1])){c+=g;continue}!u&&y?(d.push(c),c=g):c+=g,u=y}return c&&c.length>0&&d.push(c),d}const r=[...t],o=r.length,a=[];let l=r[0],h=r[0]===r[0].toLocaleUpperCase(e);for(const i of s)if(t.startsWith(i)){a.push(i),l=r[i.length],h=l===l.toLocaleUpperCase(e);break}for(let i=1;i<o;i++){const p=r[i],d=p===p.toLocaleUpperCase(e);let c=0;for(const u of s)if(t.startsWith(u,i)){a.push(l,u),c=u.length,l="";const f=u.at(-1);f&&(h=f===f.toLocaleUpperCase(e));break}if(c>0){i+=c-1;continue}!h&&d?(a.push(l),l=p):l+=p,h=d}return l&&a.push(l),a},Ht=(t,e,s)=>{const n=[],r=S.test(t)?t.split(S).filter(Boolean):[t];for(const o of r){const a=o;if(S.test(a))n.push(a);else{L.lastIndex=0;const l=L.test(a)?Yt(a).filter(Boolean):[a];for(const h of l)if(L.lastIndex=0,L.test(h))n.push(h);else if(e){const i=e.toLowerCase().split("-")[0];n.push(...at(h,i,s))}else n.push(...lt(h,s))}}return n},R=(t,e={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:s=!1,handleEmoji:n=!1,knownAcronyms:r=[],locale:o,normalize:a=!1,separators:l,stripAnsi:h=!1,stripEmoji:i=!1}=e,p=new Set([...r].toSorted((m,w)=>w.length-m.length));let d=t;h&&(d=Vt(d)),i&&(d=xt(d));let c;Array.isArray(l)?c=Dt(l):l instanceof RegExp?c=l:c=Ct;const u=[];let f=d;const g=c.flags.includes("g")?c:new RegExp(c.source,`${c.flags}g`);for(;f.length>0;){const m=g.exec(f);if(!m){f===".."?u.push(".."):f==="."?u.push("."):f.length>0&&u.push(f);break}const w=m.index,$=m[0],A=$.length,T=f.slice(0,w),$t=f.slice(w+A);if($.startsWith("../"))u.push(".."),f=f.slice(w+3);else if($.startsWith("./"))u.push("."),f=f.slice(w+2);else if(w===0&&$==="..")u.push(".."),f=f.slice(2);else if(w===0&&$===".")u.push("."),f=f.slice(1);else{T.length>0&&u.push(T);let x=0;for(;(x=$.indexOf("../",x))!==-1;)u.push(".."),x+=3;for(x=0;(x=$.indexOf("./",x))!==-1;)(x===0||$[x-1]!==".")&&u.push("."),x+=2;let C=$t;for(;C.startsWith("../");)u.push(".."),C=C.slice(3);for(;C.startsWith("./");)u.push("."),C=C.slice(2);if(C===".."){u.push("..");break}else if(C==="."){u.push(".");break}else f=C}g.lastIndex=0}if(u.length===0){const m=d.split(c).filter(Boolean);u.push(...m)}let y=[];for(const m of u)s||n?y.push(...Ht(m,o,p)):o?y.push(...at(m,o,p)):y.push(...lt(m,p));return a&&(y=y.map(m=>p.has(m)?m:o&&m===m.toLocaleUpperCase(o)?m[0]+m.slice(1).toLocaleLowerCase(o):m.toUpperCase()===m&&!p.has(m)?m.slice(0,1)+m.slice(1).toLowerCase():m)),y},q=(t,e)=>typeof t!="string"||t===""?"":(e?.locale?t[0].toLocaleUpperCase(e.locale):t[0].toUpperCase())+t.slice(1),Xt=(t,e)=>`${t}::${e?.joiner??""}::${e?.locale??""}::${e?.knownAcronyms?.join(",")??""}::${e?.normalize?"true":"false"}::${e?.stripAnsi?"true":"false"}::${e?.stripEmoji?"true":"false"}::${e?.handleAnsi?"true":"false"}::${e?.handleEmoji?"true":"false"}`,z=(t,e)=>{const{length:s}=t;if(s===0)return"";if(s===1)return t[0];const n=[];let r="",o="";for(let a=0;a<s;a++){const l=t[a];if(S.test(l)){r?(n.push(r+o+l),r="",o=""):(n.length>0&&n.push(e),r=l);continue}r?(o&&(o+=e),o+=l):(n.length>0&&n.push(e),n.push(l))}return n.join("")},te=/(?<![a-zß])SS(?![a-z])/g,ee=t=>t.replaceAll(te,"ß"),ne=(t,e)=>{if(typeof t!="string"||!t)return"";let s=!0;return z(R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(r=>{const o=r,a=o.toLowerCase();return s?(s=!1,Gt(a)):q(a,e)}),"")},se=new I(1e3),G=(t,e)=>{if(typeof t!="string")return"";const s=e?.cache??!1,n=e?.cacheStore??se;let r;if(s&&(r=Xt(t,e)),s&&r&&n.has(r))return n.get(r);const o=R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(l=>{if(e?.handleAnsi&&S.test(l))return l;if(e?.toUpperCase)return e.locale?l.toLocaleUpperCase(e.locale):l.toUpperCase();const h=e?.locale?.startsWith("de")?ee(l):l;return e?.locale?h.toLocaleLowerCase(e.locale):h.toLowerCase()}),a=z(o,e?.joiner??"-");return s&&r&&n.set(r,a),a},re=new I(1e3),oe=(t,e)=>G(t,{cacheStore:re,...e,joiner:"_",toUpperCase:!0}),ie=(t,e)=>typeof t!="string"||!t?"":z(R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(n=>q(n.toLowerCase(),{locale:e?.locale})),""),le=new I(1e3),ae=(t,e)=>G(t,{cacheStore:le,...e,joiner:"_"}),ce=(t,e)=>typeof t!="string"?"":z(R(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(n=>q(n,{locale:e?.locale})),"-"),b=t=>t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?String(t):JSON.stringify(t),H={camel_case:t=>ne(b(t)),kebab_case:t=>G(b(t)),lower_case:t=>b(t).toLowerCase(),pascal_case:t=>ie(b(t)),path_join:(t,...e)=>{const s=[b(t),...e.map(n=>b(n))];return st(...s)},path_relative:(t,e)=>nt(b(e),b(t)),snake_case:t=>ae(b(t)),upper_case:t=>b(t).toUpperCase(),upper_kebab_case:t=>ce(b(t)),upper_snake_case:t=>oe(b(t))},ct=(t,e,s=[])=>{const n=H[t];if(!n)throw new Error(`Unknown filter "${t}". Known filters: ${Object.keys(H).sort().join(", ")}.`);return n(e,...s)},ft=t=>{const e=[];let s=0,n=0,r,o=-1;for(const a of t){if(o+=1,r){a===r&&(r=void 0);continue}if(a==='"'||a==="'"){r=a;continue}a==="("?s+=1:a===")"?s-=1:a===","&&s===0&&(e.push(t.slice(n,o)),n=o+1)}return e.push(t.slice(n)),e},fe=t=>{if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1)},ue=/\[([^\]]+)\]/g,pe=t=>{const e=t.trim(),s=e.indexOf("(");if(s===-1)return{args:[],name:e};if(!e.endsWith(")"))throw new Error(`Filter call "${t}" missing closing ")"`);const n=e.slice(0,s).trim(),r=e.slice(s+1,-1).trim();return r===""?{args:[],name:n}:{args:ft(r).map(a=>{const l=a.trim();return fe(l)??l}),name:n}},he=t=>{const e=t.split("|").map(r=>r.trim()),s=e[0]??"";if(!s)throw new Error(`Empty variable name in expression "${t}"`);return{filters:e.slice(1).map(r=>pe(r)),name:s}},de=t=>t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?String(t):JSON.stringify(t),me=(t,e)=>{const s=t.replaceAll(ue,(n,r)=>{const{filters:o,name:a}=he(r);if(!Object.hasOwn(e,a))throw new Error(`Variable "${a}" used in filename "${t}" but not defined`);let l=e[a];for(const h of o)l=ct(h.name,l,h.args);return de(l)});return ut(s)},ut=t=>t.split("/").map(e=>e.endsWith(".tera")||e.endsWith(".twig")?e.slice(0,-5):e).join("/"),ge=t=>t.endsWith(".raw")?t.slice(0,-4):t,ye=t=>{const e=t.split("/");return(e.at(-1)??"").startsWith("_")?!0:e.slice(0,-1).includes("partials")},k="---",we=(t,e)=>{if(!t.startsWith(`${k}
2
2
  `)&&!t.startsWith(`${k}\r
3
3
  `))return{body:t};const s=t.indexOf(`
4
4
  ${k}`,k.length);if(s===-1)return{body:t};let n=s+1+k.length;t[n]==="\r"&&(n+=1),t[n]===`
5
5
  `&&(n+=1);const r=t.startsWith(`${k}\r
6
6
  `)?k.length+2:k.length+1,o=t.slice(r,s).replaceAll("\r","");let a;try{a=e(o)}catch(l){const h=l instanceof Error?l.message:String(l);throw new Error(`Failed to parse frontmatter YAML: ${h}`,{cause:l})}if(a==null)return{body:t.slice(n)};if(typeof a!="object"||Array.isArray(a))throw new TypeError(`Frontmatter must be a YAML mapping, got ${Array.isArray(a)?"array":typeof a}`);return{body:t.slice(n),frontmatter:a}},$e=/\{\{-?(.+?)-?\}\}|\{%-?(.+?)-?%\}/gs,pt=t=>{const e=[];let s=0,n=1;const r=o=>{for(const a of o)a===`
7
- `&&(n+=1)};for(const o of t.matchAll($e)){const a=o.index??0;if(a>s){const i=t.slice(s,a);e.push({line:n,type:"text",value:i}),r(i)}const l=n,h=o[0];h.startsWith("{{")?e.push({line:l,type:"expr",value:(o[1]??"").trim()}):e.push({line:l,type:"stmt",value:(o[2]??"").trim()}),r(h),s=a+h.length}if(s<t.length){const o=t.slice(s);e.push({line:n,type:"text",value:o})}return e},Ae=new Set(["block","endblock","endfilter","endmacro","extends","filter","import","macro","set"]),ht=(t,e)=>{let s=0;const n=(o,a)=>{throw new Error(`${e}:${o}: ${a}`)},r=o=>{const a=[];for(;s<t.length;){const l=t[s];if(l.type==="text"){a.push({type:"text",value:l.value}),s+=1;continue}if(l.type==="expr"){a.push({expression:l.value,line:l.line,type:"expr"}),s+=1;continue}const h=l.value.split(/\s+/)[0]??"";if(o.includes(h))return a;if(Ae.has(h)&&n(l.line,`Tera feature "{% ${h} %}" is not supported. Supported: if/else/endif, for/endfor, include. Rewrite the template to avoid macros, set, extends, block, and import.`),h==="if"){s+=1;const i=l.value.slice(2).trim(),p=r(["else","endif"]);let d;s<t.length&&t[s].type==="stmt"&&t[s].value.split(/\s+/)[0]==="else"&&(s+=1,d=r(["endif"])),(s>=t.length||t[s].type!=="stmt"||t[s].value.split(/\s+/)[0]!=="endif")&&n(l.line,"Unterminated {% if %} — missing {% endif %}"),s+=1,a.push({alternate:d,condition:i,consequent:p,line:l.line,type:"if"});continue}if(h==="for"){s+=1;const i=l.value.slice(3).trim(),p=i.indexOf(" in ");p===-1&&n(l.line,"Malformed {% for %} — expected `for <name> in <collection>`");const d=i.slice(0,p).trim(),c=i.slice(p+4).trim();(!d||!c)&&n(l.line,"Malformed {% for %} — missing binding or collection");const u=r(["endfor"]);(s>=t.length||t[s].type!=="stmt"||t[s].value.split(/\s+/)[0]!=="endfor")&&n(l.line,"Unterminated {% for %} — missing {% endfor %}"),s+=1,a.push({binding:d,body:u,collection:c,line:l.line,type:"for"});continue}if(h==="include"){s+=1;const i=l.value.slice(7).trim(),p=dt(i);p===void 0&&n(l.line,"Malformed {% include %} — expected a quoted partial name"),a.push({line:l.line,name:p,type:"include"});continue}n(l.line,`Unknown tag "{% ${h} %}". Supported: if, for, include.`)}return a};return r([])},dt=t=>{if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1)},Ee=t=>t==null?"":typeof t=="boolean"||typeof t=="number"?String(t):typeof t=="string"?t:JSON.stringify(t),be=t=>t==null||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:!0,mt=(t,e,s,n,r=!0)=>{const o=t.split(".");if(r&&o.length>0&&!Object.hasOwn(e,o[0]))throw new Error(`${n}:${s}: Variable "${t}" is not defined`);let a=e;for(const l of o){if(a==null)return;if(typeof a!="object")throw new TypeError(`${n}:${s}: Cannot read "${l}" on non-object value`);a=a[l]}return a},xe=t=>{const e=[];let s=0,n=0,r;for(let o=0;o<t.length;o+=1){const a=t[o];if(r){a===r&&(r=void 0);continue}if(a==='"'||a==="'"){r=a;continue}a==="("?s+=1:a===")"?s-=1:a==="|"&&s===0&&(e.push(t.slice(n,o)),n=o+1)}return e.push(t.slice(n)),e},Ce=t=>{const e=t.trim(),s=e.indexOf("(");if(s===-1)return{args:[],name:e};if(!e.endsWith(")"))throw new Error(`Filter call "${t}" missing closing ")"`);const n=e.slice(0,s).trim(),r=e.slice(s+1,-1).trim();return r?{args:ft(r).map(o=>o.trim()),name:n}:{args:[],name:n}},_=(t,e,s,n,r=!0)=>{const o=t.trim();if(o==="true")return!0;if(o==="false")return!1;if(o==="null"||o==="none")return null;const a=dt(o);return a!==void 0?a:/^-?\d+(?:\.\d+)?$/.test(o)?Number(o):mt(o,e,s,n,r)},gt=(t,e,s,n,r=!0)=>{const o=xe(t),a=o[0].trim();let l=_(a,e,s,n,r);for(let h=1;h<o.length;h+=1){const i=o[h].trim(),{args:p,name:d}=Ce(i),c=p.map(u=>_(u,e,s,n,r));try{l=ct(d,l,c)}catch(u){const f=u instanceof Error?u.message:String(u);throw new Error(`${n}:${s}: ${f}`,{cause:u})}}return l},yt=(t,e)=>{let s,n=0;for(let r=0;r<=t.length-e.length;r+=1){const o=t[r];if(s){o===s&&(s=void 0);continue}if(o==='"'||o==="'"){s=o;continue}if(o==="("){n+=1;continue}if(o===")"){n-=1;continue}if(n===0&&t.slice(r,r+e.length)===e)return r}return-1},H=(t,e)=>{const s=[];let n=0,r=0;for(;r<=t.length-e.length;){const o=yt(t.slice(r),e);if(o===-1)break;s.push(t.slice(n,r+o)),r+=o+e.length,n=r}return s.push(t.slice(n)),s},U=(t,e,s,n)=>{const r=t.trim();if(r==="")return!1;if(r.startsWith("(")&&r.endsWith(")")&&je(r)===r.length-1)return U(r.slice(1,-1),e,s,n);const o=H(r," or ");if(o.length>1)return o.some(l=>U(l,e,s,n));const a=H(r," and ");if(a.length>1)return a.every(l=>U(l,e,s,n));if(r.startsWith("not "))return!U(r.slice(4),e,s,n);for(const l of["==","!="]){const h=yt(r,l);if(h!==-1){const i=_(r.slice(0,h),e,n,s,!1),p=_(r.slice(h+l.length),e,n,s,!1),d=i===p;return l==="=="?d:!d}}return be(gt(r,e,n,s,!1))},je=t=>{if(t[0]!=="(")return-1;let e=0,s,n=-1;for(const r of t){if(n+=1,s){r===s&&(s=void 0);continue}if(r==='"'||r==="'"){s=r;continue}if(r==="(")e+=1;else if(r===")"&&(e-=1,e===0))return n}return-1},P=(t,e)=>{let s="";for(const n of t){if(n.type==="text"){s+=n.value;continue}if(n.type==="expr"){s+=Ee(gt(n.expression,e.scope,n.line,e.filename));continue}if(n.type==="if"){const r=U(n.condition,e.scope,e.filename,n.line)?n.consequent:n.alternate??[];s+=P(r,e);continue}if(n.type==="for"){const r=mt(n.collection,e.scope,n.line,e.filename,!1);if(r==null)continue;if(!Array.isArray(r))throw new TypeError(`${e.filename}:${n.line}: {% for %} expected an array, got ${typeof r}`);for(const o of r){const a={...e.scope,[n.binding]:o};s+=P(n.body,{...e,scope:a})}continue}if(n.type==="include"){const r=e.partials?.get(n.name);if(!r)throw new Error(`${e.filename}:${n.line}: Partial "${n.name}" not found. Available: ${[...e.partials?.keys()??[]].join(", ")||"(none)"}`);const o=e.includeStack??new Set;if(o.has(n.name)){const a=[...o,n.name].join(" → ");throw new Error(`${e.filename}:${n.line}: Circular partial include detected: ${a}`)}o.add(n.name);try{s+=P(r,{...e,filename:`<partial:${n.name}>`,includeStack:o})}finally{o.delete(n.name)}}}return s},ke=(t,e)=>ht(pt(t),e),B=(t,e)=>P(ht(pt(t),e.filename),e),tt="template.yml",Le=".raw",We=new Set([".cjs",".css",".env",".gitattributes",".gitignore",".graphql",".html",".ini",".js",".json",".json5",".jsonc",".jsx",".lock",".md",".mdx",".mjs",".prettierrc",".raw",".rs",".scss",".sh",".sql",".svg",".tera",".toml",".ts",".tsx",".twig",".txt",".vue",".xml",".yaml",".yml"]),Ue=new Set(["Brewfile","CHANGELOG","CODEOWNERS","CONTRIBUTING","COPYING","Dockerfile","Gemfile","LICENCE","LICENSE","Makefile","NOTICE","Procfile","Rakefile","README","VERSION"]),Se=t=>{const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")),s=e===-1?t:t.slice(e+1),n=s.lastIndexOf(".");return n===-1||n===0?"":s.slice(n).toLowerCase()},wt=t=>{const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return e===-1?t:t.slice(e+1)},Te=t=>{const e=Se(t);if(e!=="")return We.has(e);const s=wt(t);return Ue.has(s)},Oe=t=>{const e={default:t.default,internal:t.internal,order:t.order,prompt:t.prompt,required:t.required};switch(t.type){case"array":return{...e,type:"array"};case"boolean":return{...e,default:typeof e.default=="boolean"?e.default:void 0,type:"boolean"};case"enum":return{...e,multiple:t.multiple,type:"enum",values:t.values??[]};case"number":return{...e,type:"number"};case"string":return{...e,type:"string"};default:throw new Error(`Unsupported variable type "${String(t.type)}"`)}},Pe=t=>t.replaceAll("\\","/").replace(/^\.\//,"").replaceAll(/\/+/g,"/"),_e=(t,e,s)=>{const n=e.split("/").filter(Boolean);if(n.length===0)throw new Error("Empty destination path for value");let r=t;for(let o=0;o<n.length-1;o+=1){const a=n[o],l=r[a];if(l===void 0){const h={};r[a]=h,r=h}else if(typeof l=="object"&&!Buffer.isBuffer(l))r=l;else throw new TypeError(`Path conflict: "${n.slice(0,o+1).join("/")}" is both a file and a directory`)}r[n.at(-1)]=s},et=(t,e,s)=>{if(typeof t!="string")return Ie(t);const n=t.includes("{{")||t.includes("{%")?B(t,{filename:`${s}#frontmatter`,scope:e}):t;return U(n,e,`${s}#frontmatter`,1)},Ie=t=>t==null||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="string"?t!=="false"&&t!=="0":!0,Be=(t,e)=>{const s=st(t,tt),n=At(s);if(!n||typeof n!="object")throw new Error(`${s}: must contain a YAML mapping`);const r={};if(n.variables)for(const[h,i]of Object.entries(n.variables))r[h]=Oe(i);const o=new Map,a=[];for(const h of qt(t,{includeDirs:!1,includeSymlinks:!1})){if(h.path===s)continue;const i=nt(t,h.path).replaceAll("\\","/");if(i===tt)continue;if(ye(i)){const c=O(h.path),u=ke(c,i);for(const f of Re(i))o.has(f)&&o.get(f)!==u&&bt.warn(`partial name "${f}" is declared by multiple files — last one wins. Use distinct names or fully-qualified includes.`),o.set(f,u);continue}if(i.endsWith(Le)){const c=O(h.path);a.push({binary:null,isRaw:!0,rawText:c,relativePath:i});continue}if(Te(i)){const c=O(h.path);a.push({binary:null,isRaw:!1,rawText:c,relativePath:i});continue}const d=O(h.path,{buffer:!0});a.push({binary:d,isRaw:!1,rawText:null,relativePath:i})}const l=h=>{const i={...h.builtins,...h.options},p={},d={};for(const u of a){const f=u.relativePath;let g,y,m=!1;if(u.binary)g=u.binary;else if(u.isRaw)g=u.rawText??"";else{const $=u.rawText??"",A=we($,T=>Et(T));if(A.frontmatter){if(A.frontmatter.skip!==void 0&&et(A.frontmatter.skip,i,f)||A.frontmatter.if!==void 0&&!et(A.frontmatter.if,i,f))continue;typeof A.frontmatter.to=="string"&&(y=B(A.frontmatter.to,{filename:`${f}#frontmatter.to`,partials:o,scope:i})),A.frontmatter.force===!0&&(m=!0)}g=B(A.body,{filename:f,partials:o,scope:i})}const w=Pe(y??me(ge(f),i));_e(p,w,g),m&&(d[w]={force:!0})}const c={files:p};return Object.keys(d).length>0&&(c.filesMeta=d),c};return{about:{description:n.description??`Moon-format template at ${t}`,name:n.title??e},destination:n.destination,options:r,produce:l}},Re=t=>{const e=ut(t),s=wt(e),n=new Set([s,e]);if(s.startsWith("_")){n.add(s.replace(/^_+/,""));const r=e.slice(0,e.length-s.length);n.add(`${r}${s.replace(/^_+/,"")}`)}return[...n]};export{Be as loadMoonTemplate};
7
+ `&&(n+=1)};for(const o of t.matchAll($e)){const a=o.index??0;if(a>s){const i=t.slice(s,a);e.push({line:n,type:"text",value:i}),r(i)}const l=n,h=o[0];h.startsWith("{{")?e.push({line:l,type:"expr",value:(o[1]??"").trim()}):e.push({line:l,type:"stmt",value:(o[2]??"").trim()}),r(h),s=a+h.length}if(s<t.length){const o=t.slice(s);e.push({line:n,type:"text",value:o})}return e},Ae=new Set(["block","endblock","endfilter","endmacro","extends","filter","import","macro","set"]),ht=(t,e)=>{let s=0;const n=(o,a)=>{throw new Error(`${e}:${o}: ${a}`)},r=o=>{const a=[];for(;s<t.length;){const l=t[s];if(l.type==="text"){a.push({type:"text",value:l.value}),s+=1;continue}if(l.type==="expr"){a.push({expression:l.value,line:l.line,type:"expr"}),s+=1;continue}const h=l.value.split(/\s+/)[0]??"";if(o.includes(h))return a;if(Ae.has(h)&&n(l.line,`Tera feature "{% ${h} %}" is not supported. Supported: if/else/endif, for/endfor, include. Rewrite the template to avoid macros, set, extends, block, and import.`),h==="if"){s+=1;const i=l.value.slice(2).trim(),p=r(["else","endif"]);let d;s<t.length&&t[s].type==="stmt"&&t[s].value.split(/\s+/)[0]==="else"&&(s+=1,d=r(["endif"])),(s>=t.length||t[s].type!=="stmt"||t[s].value.split(/\s+/)[0]!=="endif")&&n(l.line,"Unterminated {% if %} — missing {% endif %}"),s+=1,a.push({alternate:d,condition:i,consequent:p,line:l.line,type:"if"});continue}if(h==="for"){s+=1;const i=l.value.slice(3).trim(),p=i.indexOf(" in ");p===-1&&n(l.line,"Malformed {% for %} — expected `for <name> in <collection>`");const d=i.slice(0,p).trim(),c=i.slice(p+4).trim();(!d||!c)&&n(l.line,"Malformed {% for %} — missing binding or collection");const u=r(["endfor"]);(s>=t.length||t[s].type!=="stmt"||t[s].value.split(/\s+/)[0]!=="endfor")&&n(l.line,"Unterminated {% for %} — missing {% endfor %}"),s+=1,a.push({binding:d,body:u,collection:c,line:l.line,type:"for"});continue}if(h==="include"){s+=1;const i=l.value.slice(7).trim(),p=dt(i);p===void 0&&n(l.line,"Malformed {% include %} — expected a quoted partial name"),a.push({line:l.line,name:p,type:"include"});continue}n(l.line,`Unknown tag "{% ${h} %}". Supported: if, for, include.`)}return a};return r([])},dt=t=>{if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1)},Ee=t=>t==null?"":typeof t=="boolean"||typeof t=="number"?String(t):typeof t=="string"?t:JSON.stringify(t),be=t=>t==null||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:!0,mt=(t,e,s,n,r=!0)=>{const o=t.split(".");if(r&&o.length>0&&!Object.hasOwn(e,o[0]))throw new Error(`${n}:${s}: Variable "${t}" is not defined`);let a=e;for(const l of o){if(a==null)return;if(typeof a!="object")throw new TypeError(`${n}:${s}: Cannot read "${l}" on non-object value`);a=a[l]}return a},xe=t=>{const e=[];let s=0,n=0,r;for(let o=0;o<t.length;o+=1){const a=t[o];if(r){a===r&&(r=void 0);continue}if(a==='"'||a==="'"){r=a;continue}a==="("?s+=1:a===")"?s-=1:a==="|"&&s===0&&(e.push(t.slice(n,o)),n=o+1)}return e.push(t.slice(n)),e},Ce=t=>{const e=t.trim(),s=e.indexOf("(");if(s===-1)return{args:[],name:e};if(!e.endsWith(")"))throw new Error(`Filter call "${t}" missing closing ")"`);const n=e.slice(0,s).trim(),r=e.slice(s+1,-1).trim();return r?{args:ft(r).map(o=>o.trim()),name:n}:{args:[],name:n}},_=(t,e,s,n,r=!0)=>{const o=t.trim();if(o==="true")return!0;if(o==="false")return!1;if(o==="null"||o==="none")return null;const a=dt(o);return a!==void 0?a:/^-?\d+(?:\.\d+)?$/.test(o)?Number(o):mt(o,e,s,n,r)},gt=(t,e,s,n,r=!0)=>{const o=xe(t),a=o[0].trim();let l=_(a,e,s,n,r);for(let h=1;h<o.length;h+=1){const i=o[h].trim(),{args:p,name:d}=Ce(i),c=p.map(u=>_(u,e,s,n,r));try{l=ct(d,l,c)}catch(u){const f=u instanceof Error?u.message:String(u);throw new Error(`${n}:${s}: ${f}`,{cause:u})}}return l},yt=(t,e)=>{let s,n=0;for(let r=0;r<=t.length-e.length;r+=1){const o=t[r];if(s){o===s&&(s=void 0);continue}if(o==='"'||o==="'"){s=o;continue}if(o==="("){n+=1;continue}if(o===")"){n-=1;continue}if(n===0&&t.slice(r,r+e.length)===e)return r}return-1},X=(t,e)=>{const s=[];let n=0,r=0;for(;r<=t.length-e.length;){const o=yt(t.slice(r),e);if(o===-1)break;s.push(t.slice(n,r+o)),r+=o+e.length,n=r}return s.push(t.slice(n)),s},U=(t,e,s,n)=>{const r=t.trim();if(r==="")return!1;if(r.startsWith("(")&&r.endsWith(")")&&je(r)===r.length-1)return U(r.slice(1,-1),e,s,n);const o=X(r," or ");if(o.length>1)return o.some(l=>U(l,e,s,n));const a=X(r," and ");if(a.length>1)return a.every(l=>U(l,e,s,n));if(r.startsWith("not "))return!U(r.slice(4),e,s,n);for(const l of["==","!="]){const h=yt(r,l);if(h!==-1){const i=_(r.slice(0,h),e,n,s,!1),p=_(r.slice(h+l.length),e,n,s,!1),d=i===p;return l==="=="?d:!d}}return be(gt(r,e,n,s,!1))},je=t=>{if(t[0]!=="(")return-1;let e=0,s,n=-1;for(const r of t){if(n+=1,s){r===s&&(s=void 0);continue}if(r==='"'||r==="'"){s=r;continue}if(r==="(")e+=1;else if(r===")"&&(e-=1,e===0))return n}return-1},P=(t,e)=>{let s="";for(const n of t){if(n.type==="text"){s+=n.value;continue}if(n.type==="expr"){s+=Ee(gt(n.expression,e.scope,n.line,e.filename));continue}if(n.type==="if"){const r=U(n.condition,e.scope,e.filename,n.line)?n.consequent:n.alternate??[];s+=P(r,e);continue}if(n.type==="for"){const r=mt(n.collection,e.scope,n.line,e.filename,!1);if(r==null)continue;if(!Array.isArray(r))throw new TypeError(`${e.filename}:${n.line}: {% for %} expected an array, got ${typeof r}`);for(const o of r){const a={...e.scope,[n.binding]:o};s+=P(n.body,{...e,scope:a})}continue}if(n.type==="include"){const r=e.partials?.get(n.name);if(!r)throw new Error(`${e.filename}:${n.line}: Partial "${n.name}" not found. Available: ${[...e.partials?.keys()??[]].join(", ")||"(none)"}`);const o=e.includeStack??new Set;if(o.has(n.name)){const a=[...o,n.name].join(" → ");throw new Error(`${e.filename}:${n.line}: Circular partial include detected: ${a}`)}o.add(n.name);try{s+=P(r,{...e,filename:`<partial:${n.name}>`,includeStack:o})}finally{o.delete(n.name)}}}return s},ke=(t,e)=>ht(pt(t),e),B=(t,e)=>P(ht(pt(t),e.filename),e),tt="template.yml",Le=".raw",We=new Set([".cjs",".css",".env",".gitattributes",".gitignore",".graphql",".html",".ini",".js",".json",".json5",".jsonc",".jsx",".lock",".md",".mdx",".mjs",".prettierrc",".raw",".rs",".scss",".sh",".sql",".svg",".tera",".toml",".ts",".tsx",".twig",".txt",".vue",".xml",".yaml",".yml"]),Ue=new Set(["Brewfile","CHANGELOG","CODEOWNERS","CONTRIBUTING","COPYING","Dockerfile","Gemfile","LICENCE","LICENSE","Makefile","NOTICE","Procfile","Rakefile","README","VERSION"]),Se=t=>{const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")),s=e===-1?t:t.slice(e+1),n=s.lastIndexOf(".");return n===-1||n===0?"":s.slice(n).toLowerCase()},wt=t=>{const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return e===-1?t:t.slice(e+1)},Te=t=>{const e=Se(t);if(e!=="")return We.has(e);const s=wt(t);return Ue.has(s)},Oe=t=>{const e={default:t.default,internal:t.internal,order:t.order,prompt:t.prompt,required:t.required};switch(t.type){case"array":return{...e,type:"array"};case"boolean":return{...e,default:typeof e.default=="boolean"?e.default:void 0,type:"boolean"};case"enum":return{...e,multiple:t.multiple,type:"enum",values:t.values??[]};case"number":return{...e,type:"number"};case"string":return{...e,type:"string"};default:throw new Error(`Unsupported variable type "${String(t.type)}"`)}},Pe=t=>t.replaceAll("\\","/").replace(/^\.\//,"").replaceAll(/\/+/g,"/"),_e=(t,e,s)=>{const n=e.split("/").filter(Boolean);if(n.length===0)throw new Error("Empty destination path for value");let r=t;for(let o=0;o<n.length-1;o+=1){const a=n[o],l=r[a];if(l===void 0){const h={};r[a]=h,r=h}else if(typeof l=="object"&&!Buffer.isBuffer(l))r=l;else throw new TypeError(`Path conflict: "${n.slice(0,o+1).join("/")}" is both a file and a directory`)}r[n.at(-1)]=s},et=(t,e,s)=>{if(typeof t!="string")return Ie(t);const n=t.includes("{{")||t.includes("{%")?B(t,{filename:`${s}#frontmatter`,scope:e}):t;return U(n,e,`${s}#frontmatter`,1)},Ie=t=>t==null||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="string"?t!=="false"&&t!=="0":!0,Be=(t,e)=>{const s=st(t,tt),n=At(s);if(!n||typeof n!="object")throw new Error(`${s}: must contain a YAML mapping`);const r={};if(n.variables)for(const[h,i]of Object.entries(n.variables))r[h]=Oe(i);const o=new Map,a=[];for(const h of qt(t,{includeDirs:!1,includeSymlinks:!1})){if(h.path===s)continue;const i=nt(t,h.path).replaceAll("\\","/");if(i===tt)continue;if(ye(i)){const c=O(h.path),u=ke(c,i);for(const f of Re(i))o.has(f)&&o.get(f)!==u&&bt.warn(`partial name "${f}" is declared by multiple files — last one wins. Use distinct names or fully-qualified includes.`),o.set(f,u);continue}if(i.endsWith(Le)){const c=O(h.path);a.push({binary:null,isRaw:!0,rawText:c,relativePath:i});continue}if(Te(i)){const c=O(h.path);a.push({binary:null,isRaw:!1,rawText:c,relativePath:i});continue}const d=O(h.path,{buffer:!0});a.push({binary:d,isRaw:!1,rawText:null,relativePath:i})}const l=h=>{const i={...h.builtins,...h.options},p={},d={};for(const u of a){const f=u.relativePath;let g,y,m=!1;if(u.binary)g=u.binary;else if(u.isRaw)g=u.rawText??"";else{const $=u.rawText??"",A=we($,T=>Et(T));if(A.frontmatter){if(A.frontmatter.skip!==void 0&&et(A.frontmatter.skip,i,f)||A.frontmatter.if!==void 0&&!et(A.frontmatter.if,i,f))continue;typeof A.frontmatter.to=="string"&&(y=B(A.frontmatter.to,{filename:`${f}#frontmatter.to`,partials:o,scope:i})),A.frontmatter.force===!0&&(m=!0)}g=B(A.body,{filename:f,partials:o,scope:i})}const w=Pe(y??me(ge(f),i));_e(p,w,g),m&&(d[w]={force:!0})}const c={files:p};return Object.keys(d).length>0&&(c.filesMeta=d),c};return{about:{description:n.description??`Moon-format template at ${t}`,name:n.title??e},destination:n.destination,options:r,produce:l}},Re=t=>{const e=ut(t),s=wt(e),n=new Set([s,e]);if(s.startsWith("_")){n.add(s.replace(/^_+/,""));const r=e.slice(0,e.length-s.length);n.add(`${r}${s.replace(/^_+/,"")}`)}return[...n]};export{Be as loadMoonTemplate};
@@ -1,4 +1,4 @@
1
- import{p as s}from"./cli-main.js";import{c as a,f as c}from"../packem_shared/registry-keys-_IKDLSbu.js";const f=async({options:r})=>{if(r.clear){const t=a();if(r.json){process.stdout.write(`${JSON.stringify({cleared:t,refetched:!1},void 0,2)}
1
+ import{p as s}from"./cli-main.js";import{c as a,f as c}from"../packem_shared/registry-keys-BWHRFWbb.js";const f=async({options:r})=>{if(r.clear){const t=a();if(r.json){process.stdout.write(`${JSON.stringify({cleared:t,refetched:!1},void 0,2)}
2
2
  `);return}s.success(t?"Cleared cached npm signing keys.":"No cached npm signing keys to clear.");return}const e=await c({forceRefresh:!0});if(e===void 0){if(r.json){process.stdout.write(`${JSON.stringify({cleared:!1,error:"fetch-failed",refetched:!1},void 0,2)}
3
3
  `),process.exitCode=1;return}s.error("Failed to fetch npm signing keys (network error and no cached keys available)."),process.exitCode=1;return}if(r.json){process.stdout.write(`${JSON.stringify({cleared:!1,fromCache:e.fromCache,keyCount:e.keys.length,refetched:!e.fromCache,stale:e.stale??!1},void 0,2)}
4
4
  `);return}if(e.fromCache&&e.stale===!0){s.warn(`Network fetch failed — falling back to expired cache (${String(e.keys.length)} keys).`);return}s.success(`Refreshed npm signing keys (${String(e.keys.length)} keys).`)};export{f as default};
@@ -1,2 +1,2 @@
1
- import{p}from"./cli-main.js";import{d as b}from"../packem_shared/pm-runner-d93_73O6.js";import{r as m,l as w,L as v}from"../packem_shared/dependency-scan-DBH2Qo4I.js";import{z as S,e as g}from"../packem_shared/index-DHD8wb6Z.js";import{S as $}from"../packem_shared/lockfile-DhHAaHN5.js";import{e as x}from"../packem_shared/index-CIIKPX4H.js";import{y as C}from"../packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js";const E=e=>{const o=e.trim();return o===""?!1:/^(?:git\+|git:\/\/|git@|ssh:\/\/)/i.test(o)||/^(?:github|gitlab|bitbucket|gist):/i.test(o)||/^[\w.-]+\/[\w.-]+(?:#.+)?$/.test(o)&&!o.includes("@")?!0:/^https?:\/\//i.test(o)},M=(e,o)=>{for(const i of o)if(i===e||i.endsWith("*")&&e.startsWith(i.slice(0,-1)))return!0;return!1},L=(e,o,i={})=>{const t=m(e,o);if(!t)return[];let s;try{s=S(g(e,t.file))}catch{return[]}const n=$(s,t.type);if(n.length===0)return[];const r=i.allow??[],l=[],f=new Set;for(const c of n){const a=`${c.name}@${c.version}`;for(const d of[c.dependencies,c.optionalDependencies])if(d){for(const[u,h]of Object.entries(d))if(!M(u,r))for(const k of h){if(!E(k))continue;const y=`${a}->${u}@${k}`;f.has(y)||(f.add(y),l.push({declaredBy:a,packageName:u,source:k}))}}}return l.sort((c,a)=>c.packageName.localeCompare(a.packageName)||c.declaredBy.localeCompare(a.declaredBy))},D=new Set(["firstSeen","publisherChange"]),I=e=>e.severity==="block"&&e.acceptedRisk===void 0,N=e=>{const o=e.security?.policies?.firstSeen?.minutes,i=typeof o=="number"&&o>0,t=e.security?.policies?.publisherChange?.mode==="no-downgrade",s=e.security?.blockExoticSubdeps===!0;return i||t||s},O=async e=>{const{offline:o=!1,packageManager:i,visConfig:t,workspaceRoot:s}=e,n=Date.now();if(!N(t))return{decisions:[],durationMs:Date.now()-n,entryCount:0,exoticViolations:[],lockfileMissing:!1,status:"skipped"};const r=m(s,i);if(!r||!C(g(s,r.file)))return{decisions:[],durationMs:Date.now()-n,entryCount:0,exoticViolations:[],lockfileMissing:!0,status:"fail"};const l=w(s,i,{includeDev:!0}),f=l.length,c=await x({offline:o,packageManager:i,packages:l,workspaceRoot:s},"install",{enabledPolicies:new Set(D),visConfig:t}),a=t.security?.blockExoticSubdeps===!0?L(s,i,{allow:t.security.exoticSubdepsAllow}):[],d=c.some(u=>I(u))||a.length>0;return{decisions:c,durationMs:Date.now()-n,entryCount:f,exoticViolations:a,lockfileMissing:!1,status:d?"fail":"pass"}},P=e=>e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`,V=e=>{if(e.status==="skipped")return["– Lockfile supply-chain verification skipped (no firstSeen / publisherChange / blockExoticSubdeps policy configured)"];if(e.lockfileMissing)return["✗ Lockfile supply-chain verification failed — no lockfile found, the resolved closure cannot be attested"];const o=`(${String(e.entryCount)} ${e.entryCount===1?"entry":"entries"}, ${P(e.durationMs)})`;if(e.status==="pass")return[`✓ Lockfile passes supply-chain policies ${o}`];const i=[`✗ Lockfile failed supply-chain policy check ${o}`];for(const t of e.decisions)t.severity==="block"&&t.acceptedRisk===void 0&&i.push(` [${t.policy}] ${t.reason}`);for(const t of e.exoticViolations)i.push(` [blockExoticSubdeps] ${t.packageName} pulled from exotic source by ${t.declaredBy}: ${t.source}`);return i},z=async({options:e,visConfig:o,workspaceRoot:i})=>{const t=i??process.cwd(),s=b(t);if(!v[s.name]){p.warn(`Package manager '${s.name}' has no lockfile vis can verify.`);return}const n=await O({offline:!!e.offline,packageManager:s.name,visConfig:o??{},workspaceRoot:t});if(e.json){process.stdout.write(`${JSON.stringify(n,void 0,2)}
1
+ import{p}from"./cli-main.js";import{d as b}from"../packem_shared/pm-runner-d93_73O6.js";import{r as m,l as w,L as v}from"../packem_shared/dependency-scan-DBH2Qo4I.js";import{z as S,e as g}from"../packem_shared/index-DHD8wb6Z.js";import{S as $}from"../packem_shared/lockfile-DhHAaHN5.js";import{e as x}from"../packem_shared/index-Czrll7SU.js";import{y as C}from"../packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js";const E=e=>{const o=e.trim();return o===""?!1:/^(?:git\+|git:\/\/|git@|ssh:\/\/)/i.test(o)||/^(?:github|gitlab|bitbucket|gist):/i.test(o)||/^[\w.-]+\/[\w.-]+(?:#.+)?$/.test(o)&&!o.includes("@")?!0:/^https?:\/\//i.test(o)},M=(e,o)=>{for(const i of o)if(i===e||i.endsWith("*")&&e.startsWith(i.slice(0,-1)))return!0;return!1},L=(e,o,i={})=>{const t=m(e,o);if(!t)return[];let s;try{s=S(g(e,t.file))}catch{return[]}const n=$(s,t.type);if(n.length===0)return[];const r=i.allow??[],l=[],f=new Set;for(const c of n){const a=`${c.name}@${c.version}`;for(const d of[c.dependencies,c.optionalDependencies])if(d){for(const[u,h]of Object.entries(d))if(!M(u,r))for(const k of h){if(!E(k))continue;const y=`${a}->${u}@${k}`;f.has(y)||(f.add(y),l.push({declaredBy:a,packageName:u,source:k}))}}}return l.sort((c,a)=>c.packageName.localeCompare(a.packageName)||c.declaredBy.localeCompare(a.declaredBy))},D=new Set(["firstSeen","publisherChange"]),I=e=>e.severity==="block"&&e.acceptedRisk===void 0,N=e=>{const o=e.security?.policies?.firstSeen?.minutes,i=typeof o=="number"&&o>0,t=e.security?.policies?.publisherChange?.mode==="no-downgrade",s=e.security?.blockExoticSubdeps===!0;return i||t||s},O=async e=>{const{offline:o=!1,packageManager:i,visConfig:t,workspaceRoot:s}=e,n=Date.now();if(!N(t))return{decisions:[],durationMs:Date.now()-n,entryCount:0,exoticViolations:[],lockfileMissing:!1,status:"skipped"};const r=m(s,i);if(!r||!C(g(s,r.file)))return{decisions:[],durationMs:Date.now()-n,entryCount:0,exoticViolations:[],lockfileMissing:!0,status:"fail"};const l=w(s,i,{includeDev:!0}),f=l.length,c=await x({offline:o,packageManager:i,packages:l,workspaceRoot:s},"install",{enabledPolicies:new Set(D),visConfig:t}),a=t.security?.blockExoticSubdeps===!0?L(s,i,{allow:t.security.exoticSubdepsAllow}):[],d=c.some(u=>I(u))||a.length>0;return{decisions:c,durationMs:Date.now()-n,entryCount:f,exoticViolations:a,lockfileMissing:!1,status:d?"fail":"pass"}},P=e=>e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`,V=e=>{if(e.status==="skipped")return["– Lockfile supply-chain verification skipped (no firstSeen / publisherChange / blockExoticSubdeps policy configured)"];if(e.lockfileMissing)return["✗ Lockfile supply-chain verification failed — no lockfile found, the resolved closure cannot be attested"];const o=`(${String(e.entryCount)} ${e.entryCount===1?"entry":"entries"}, ${P(e.durationMs)})`;if(e.status==="pass")return[`✓ Lockfile passes supply-chain policies ${o}`];const i=[`✗ Lockfile failed supply-chain policy check ${o}`];for(const t of e.decisions)t.severity==="block"&&t.acceptedRisk===void 0&&i.push(` [${t.policy}] ${t.reason}`);for(const t of e.exoticViolations)i.push(` [blockExoticSubdeps] ${t.packageName} pulled from exotic source by ${t.declaredBy}: ${t.source}`);return i},z=async({options:e,visConfig:o,workspaceRoot:i})=>{const t=i??process.cwd(),s=b(t);if(!v[s.name]){p.warn(`Package manager '${s.name}' has no lockfile vis can verify.`);return}const n=await O({offline:!!e.offline,packageManager:s.name,visConfig:o??{},workspaceRoot:t});if(e.json){process.stdout.write(`${JSON.stringify(n,void 0,2)}
2
2
  `),n.status==="fail"&&(process.exitCode=1);return}const[r,...l]=V(n);if(n.status==="skipped"){p.info(r);return}if(n.status==="pass"){p.success(r);return}p.error(r);for(const f of l)p.error(f);process.exitCode=1};export{z as default};
@@ -0,0 +1,9 @@
1
+ import{createRequire as ei}from"node:module";let oi;const ni=t=>(oi??=ei(import.meta.url))(t),D=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ri=t=>{if(typeof D<"u"&&D.versions&&D.versions.node){const[i,e]=D.versions.node.split(".").map(Number);if(i>22||i===22&&e>=3||i===20&&e>=16)return D.getBuiltinModule(t)}return ni(t)},{createRequire:si}=ri("node:module");let hi;const ci=t=>(hi??=si(import.meta.url))(t),V=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:T,wt=t=>{if(typeof V<"u"&&V.versions&&V.versions.node){const[i,e]=V.versions.node.split(".").map(Number);if(i>22||i===22&&e>=3||i===20&&e>=16)return V.getBuiltinModule(t)}return ci(t)},T=V,{execFileSync:ai}=wt("node:child_process"),Y=wt("node:fs"),li=wt("node:tty"),di=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],ui=12288,fi=65510,mi=[12288,12288,65281,65376,65504,65510],wi=8361,pi=65518,gi=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],bi=32,yi=10630,xi=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],Wi=4352,Bi=262141,_t=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141],K=(t,i)=>{let e=0,o=Math.floor(t.length/2)-1;for(;e<=o;){const s=Math.floor((e+o)/2),h=s*2;if(i<t[h])o=s-1;else if(i>t[h+1])e=s+1;else return!0}return!1},bt=19968,[vi,Ri]=Ci(_t);function Ci(t){let i=t[0],e=t[1];for(let o=0;o<t.length;o+=2){const s=t[o],h=t[o+1];if(bt>=s&&bt<=h)return[s,h];h-s>e-i&&(i=s,e=h)}return[i,e]}const Si=t=>t<161||t>1114109?!1:K(di,t),Ai=t=>t<ui||t>fi?!1:K(mi,t),Ii=t=>t<wi||t>pi?!1:K(gi,t),Mi=t=>t<bi||t>yi?!1:K(xi,t),ki=t=>t>=vi&&t<=Ri?!0:t<Wi||t>Bi?!1:K(_t,t);function ji(t){return Si(t)?"ambiguous":Ai(t)?"fullwidth":Ii(t)?"halfwidth":Mi(t)?"narrow":ki(t)?"wide":"neutral"}function Ei(t){if(!Number.isSafeInteger(t))throw new TypeError(`Expected a code point, got \`${typeof t}\`.`)}function Ht(t){return Ei(t),ji(t)}const $t=String.raw,yt=$t`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,Ni=()=>new RegExp($t`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${yt}(?:\u200D${yt})*`,"gu"),J=new Set(["\x1B","›"]),pt="\x07",q="]8;;",Li=/[\u200B\uFEFF\u2060-\u2064]/g,ht=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\)|\][^\u0007\u001B]{0,1000}(?:\u0007|\u001B\\))/g,xt=/\u001B\[[\d;]*m[^\u001B]*(?:\u001B\[[\d;]*m|$)/g,Wt=/\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)[^\u001B]*\u001B\]8;;(?:\u0007|\u001B\\)/g,Z=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,Ji=Ni(),Bt=new Map,Fi=t=>[t.ambiguousIsNarrow?1:0,t.control,t.fullWidth,t.regular,t.wide].join("|"),Ti=t=>{const i=Fi(t.width);let e=Bt.get(i);return e||(e=new Map,Bt.set(i,e)),e},X=new RegExp(ht.source,"y"),dt=new RegExp(Ji.source,"uy"),Q=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,Pt=t=>t>=32&&t<=126?"latin":t===8203||t===8204||t===8205||t===8288?"zero":t<=31||t>=127&&t<=159?"control":t>=160&&t<=255||t>=9472&&t<=9599?"latin":t>=4352&&t<=4607||t>=11904&&t<=40959||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65519&&!(t>=65377&&t<=65439)||t>=12352&&t<=12543?"wide":t===8230?"latin":"other",Oi=(t,i)=>{const e=Ti(i),o=Math.floor(t/65536),s=t%65536;let h=e.get(o);if(h||(h=new Map,e.set(o,h)),h.has(s))return h.get(s);let n;switch(Pt(t)){case"control":{n=i.width.control;break}case"latin":{n=i.width.regular;break}case"wide":{n=i.width.wide;break}case"zero":{n=0;break}default:switch(Ht(t)){case"ambiguous":{n=i.width.ambiguousIsNarrow?i.width.regular:i.width.wide;break}case"fullwidth":{n=i.width.fullWidth;break}case"wide":{n=i.width.wide;break}default:n=i.width.regular}}return h.set(s,n),n},_i=t=>t>=768&&t<=879||t>=6832&&t<=6911||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65056&&t<=65071||t>=917760&&t<=917999||t>=65024&&t<=65039||t>=3633&&t<=3642||t>=3655&&t<=3662||t>=3761&&t<=3769||t>=3771&&t<=3772||t>=3784&&t<=3789||t>=2304&&t<=2307||t>=2362&&t<=2383||t>=2385&&t<=2391||t>=2402&&t<=2403||t>=2433&&t<=2435||t>=2492&&t<=2500||t>=2509&&t<=2509||t>=2561&&t<=2563||t>=2620&&t<=2637||t>=1611&&t<=1631||t>=1648&&t<=1648||t>=1750&&t<=1773||t>=2276&&t<=2302||t>=1425&&t<=1469||t>=1471&&t<=1471||t>=1473&&t<=1474||t>=1476&&t<=1477||t>=1479&&t<=1479||t>=3893&&t<=3893||t>=3895&&t<=3895||t>=3897&&t<=3897||t>=3953&&t<=3966||t>=3968&&t<=3972||t>=3974&&t<=3975?!0:t>=768&&t<=777||t>=803&&t<=803,z=(t,i={})=>{if(!t||t.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const e={truncation:{countAnsiEscapeCodes:i.countAnsiEscapeCodes??!1,ellipsis:i.ellipsis??"",ellipsisWidth:i.ellipsisWidth??(i.ellipsis?z(i.ellipsis,{...i,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:i.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:i.ambiguousIsNarrow??!1,ansi:i.ansiWidth??0,control:i.controlWidth??0,emoji:i.emojiWidth??2,fullWidth:i.fullWidth??2,halfWidth:i.halfWidth??1,regular:i.regularWidth??1,tab:i.tabWidth??8,wide:i.wideWidth??2}},o=Math.max(0,e.truncation.limit-e.truncation.ellipsisWidth),{length:s}=t,h=s>1e4;let n=0,r=0,c=s,a=!1;const d=t.includes("\x1B")||t.includes("›");for(;n<s;){if(d&&(t[n]==="\x1B"||t[n]==="›")){if(t.startsWith("\x1B]8;;",n)){const g="\x1B]8;;\x07",u=g.length,b=t.indexOf("\x07",n+5);if(b!==-1){const W=t.indexOf(g,b+1);if(W!==-1){const y=W+u,x=t.slice(b+1,W).replace(ht,""),R=z(x,{ambiguousIsNarrow:e.width.ambiguousIsNarrow,ansiWidth:e.width.ansi,controlWidth:e.width.control,countAnsiEscapeCodes:!1,ellipsis:e.truncation.ellipsis,ellipsisWidth:e.truncation.ellipsisWidth,emojiWidth:e.width.emoji,fullWidth:e.width.fullWidth,halfWidth:e.width.halfWidth,limit:Math.max(0,o-r),regularWidth:e.width.regular,tabWidth:e.width.tab,wideWidth:e.width.wide}),S=R.width;if(R.truncated)a=!0,c=Math.min(c,n);else if(r+S>o&&(c=Math.min(c,n),a=!0,r+S>e.truncation.limit))break;if(r+=S,n=y,a&&r>=e.truncation.limit)break;continue}}}if(X.lastIndex=n,X.test(t)){const g=X.lastIndex-n,u=e.truncation.countAnsiEscapeCodes?g:e.width.ansi;if(r+u>o&&(c=Math.min(c,n),r+u>e.truncation.limit)){a=!0;break}r+=u,n=X.lastIndex;continue}}const f=t.codePointAt(n);if(f===8203||f===65279||f>=8288&&f<=8292){n+=1;continue}if(f===9){if(r+e.width.tab>o&&(c=Math.min(c,n),r+e.width.tab>e.truncation.limit)){a=!0;break}r+=e.width.tab,n+=1;continue}if(Q.lastIndex=n,Q.test(t)){const g=(Q.lastIndex-n)*e.width.regular;if(r+g>o){const u=e.width.regular>0?Math.floor((o-r)/e.width.regular):0;if(c=Math.min(c,n+u),r+g>e.truncation.limit){a=!0;break}}r+=g,n=Q.lastIndex;continue}if((f<=31||f>=127&&f<=159)&&(Z.lastIndex=n,Z.test(t))){const g=(Z.lastIndex-n)*e.width.control;if(r+g>o){const u=e.width.control>0?Math.floor((o-r)/e.width.control):0;if(c=Math.min(c,n+u),r+g>e.truncation.limit){a=!0;break}}r+=g,n=Z.lastIndex;continue}if(dt.lastIndex=n,dt.test(t)){if(r+e.width.emoji>o&&(c=Math.min(c,n),r+e.width.emoji>e.truncation.limit)){a=!0;break}r+=e.width.emoji,n=dt.lastIndex;continue}const w=t.codePointAt(n)??0;if(_i(w)){n+=w>65535?2:1;continue}let p;if(h)p=Oi(w,e);else switch(Pt(w)){case"control":{p=e.width.control;break}case"latin":{p=e.width.regular;break}case"wide":{p=e.width.wide;break}case"zero":{p=0;break}default:switch(Ht(w)){case"ambiguous":{p=e.width.ambiguousIsNarrow?e.width.regular:e.width.wide;break}case"fullwidth":{p=e.width.fullWidth;break}case"wide":{p=e.width.wide;break}default:p=e.width.regular}}if(r+p>o&&(c=Math.min(c,n),r+p>e.truncation.limit)){a=!0;break}r+=p,n+=w>65535?2:1}let l=r,m=!1;return a&&e.truncation.limit>=e.truncation.ellipsisWidth&&(l=e.truncation.limit,m=!0),{ellipsed:m,index:a?c:s,truncated:a,width:l}},k=(t,i={})=>z(t,{...i,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width;class Hi{capacity;cache;constructor(i){this.capacity=i,this.cache=new Map}get(i){if(!this.cache.has(i))return;const e=this.cache.get(i);return this.cache.delete(i),this.cache.set(i,e),e}has(i){return this.cache.has(i)}set(i,e){if(this.cache.has(i))this.cache.delete(i);else if(this.cache.size>=this.capacity){const o=this.cache.keys().next().value;o!==void 0&&this.cache.delete(o)}this.cache.set(i,e)}delete(i){this.cache.delete(i)}clear(){this.cache.clear()}size(){return this.cache.size}}const $i=/^(?:\u001B\[|\u009B)([\d:;]*)m$/,Gt=new Map([[1,22],[2,22],[3,23],[4,24],[5,25],[6,25],[7,27],[8,28],[9,29],[21,24],[53,55]]),Pi=new Set(Gt.values()),Vt=t=>{const i=t.split(";"),e=[];for(let o=0;o<i.length;o+=1){const s=i[o];if(s.includes(":")){e.push([s]);continue}const h=s===""?0:Number.parseInt(s,10);if(h===38||h===48||h===58){const n=i[o+1];let r=0;n==="5"?r=2:n==="2"?r=4:n?.includes(":")&&(r=1),e.push(i.slice(o,o+1+r)),o+=r;continue}e.push([s])}return e},qt=t=>{const i=t[0],e=i.indexOf(":"),o=e===-1?i:i.slice(0,e);return o===""?0:Number.parseInt(o,10)},zt=t=>t===38||t>=30&&t<=37||t>=90&&t<=97,Ut=t=>t===48||t>=40&&t<=47||t>=100&&t<=107,Dt=t=>{const i=Vt(t);if(i.length!==1)return;const e=qt(i[0]);return zt(e)?"foreground":Ut(e)?"background":void 0};class Gi{activeForeground=void 0;activeBackground=void 0;activeUnderlineColor=void 0;activeAttributes=new Map;processEscape(i){const e=$i.exec(i);if(e)for(const o of Vt(e[1])){const s=qt(o);switch(s){case 0:{this.resetAll();break}case 39:{this.activeForeground=void 0;break}case 49:{this.activeBackground=void 0;break}case 59:{this.activeUnderlineColor=void 0;break}default:this.applyParameter(s,`\x1B[${o.join(";")}m`)}}}getStartEscapesForAllActiveAttributes(){return[this.activeBackground,this.activeForeground,this.activeUnderlineColor,...this.activeAttributes.values()].filter(Boolean).join("")}getEndEscapesForAllActiveAttributes(){const i=[...this.activeAttributes.keys()].toReversed().map(e=>`\x1B[${String(e)}m`);return this.activeUnderlineColor&&i.push("\x1B[59m"),this.activeForeground&&i.push("\x1B[39m"),this.activeBackground&&i.push("\x1B[49m"),i.join("")}resetAll(){this.activeForeground=void 0,this.activeBackground=void 0,this.activeUnderlineColor=void 0,this.activeAttributes.clear()}applyParameter(i,e){if(!((i===38||i===48||i===58)&&!e.includes(";")&&!e.includes(":")))if(zt(i))this.activeForeground=e;else if(Ut(i))this.activeBackground=e;else if(i===58)this.activeUnderlineColor=e;else if(Pi.has(i))this.activeAttributes.delete(i);else{const o=Gt.get(i);o!==void 0&&this.activeAttributes.set(o,e)}}}const vt=new Hi(100),Vi=new Intl.Segmenter("en",{granularity:"grapheme"}),qi=/^[\u0000-\u007F]*$/,zi=new Set(["0","22","23","24","27","28","29","39","49"]),Ui=new Set(["1","3","4","7","8","9"]),Rt=new Map([["22","1"],["23","3"],["24","4"],["27","7"],["28","8"],["29","9"]]),tt=t=>Dt(t)==="foreground",it=t=>Dt(t)==="background",Di=[{close:"\x1B[22m",open:"\x1B[1m"},{close:"\x1B[23m",open:"\x1B[3m"},{close:"\x1B[24m",open:"\x1B[4m"},{close:"\x1B[27m",open:"\x1B[7m"},{close:"\x1B[28m",open:"\x1B[8m"},{close:"\x1B[29m",open:"\x1B[9m"}],Ct=(t,i)=>{let e=-1;for(const o of i){const s=t.indexOf(o);s!==-1&&(e===-1||s<e)&&(e=s)}return e},Yi=(t,i)=>{if(!t.includes("\x1B"))return[{after:"",before:"",content:t,visibleLength:k(t,i.width)}];const e=`${JSON.stringify(i.width??void 0)}\0${t}`,o=vt.get(e);if(o)return o;const s=[],h=[];let n=0,r;for(ht.lastIndex=0;(r=ht.exec(t))!==null;){const l=r[0];s.push(t.slice(n,r.index)),h.push(l),n=r.index+l.length}n<t.length&&s.push(t.slice(n));const c=[];for(const l of h){if(l==="\x1B[0m"||l==="\x1B]8;;\x07"){c.push(l);continue}if(l.startsWith("\x1B[")&&l.endsWith("m")){const m=l.slice(2,-1);if(zi.has(m)){c.push(l);continue}}}const a=new Set,d=[];for(const[l,m]of s.entries()){if(l>0&&h[l-1]){const p=h[l-1];if(p==="\x1B[0m")a.clear();else if(p==="\x1B]8;;\x07"){for(const g of a)if(g.startsWith("\x1B]8;;")&&!g.endsWith("\x1B]8;;\x07")){a.delete(g);break}}else if(p.startsWith("\x1B[")&&p.endsWith("m")){const g=p.slice(2,-1);if(g==="39"){for(const u of a)if(u.startsWith("\x1B[")&&u.endsWith("m")){const b=u.slice(2,-1);if(tt(b)){a.delete(u);break}}}else if(g==="49"){for(const u of a)if(u.startsWith("\x1B[")&&u.endsWith("m")){const b=u.slice(2,-1);if(it(b)){a.delete(u);break}}}else if(Rt.has(g)){const u=Rt.get(g);for(const b of a)if(b===`\x1B[${u}m`){a.delete(b);break}}else{if(tt(g)){for(const u of a)if(u.startsWith("\x1B[")&&u.endsWith("m")){const b=u.slice(2,-1);if(tt(b)){a.delete(u);break}}}else if(it(g)){for(const u of a)if(u.startsWith("\x1B[")&&u.endsWith("m")){const b=u.slice(2,-1);if(it(b)){a.delete(u);break}}}else if(Ui.has(g)){const u=`\x1B[${g}m`;a.has(u)&&a.delete(u)}a.add(p)}}else if(p.startsWith("\x1B]8;;")&&!p.endsWith("\x1B]8;;\x07")){for(const g of a)if(g.startsWith("\x1B]8;;")&&!g.endsWith("\x1B]8;;\x07")){a.delete(g);break}a.add(p)}}if(m==="")continue;let f="";if(a.size>0)if(c.includes("\x1B[0m"))f="\x1B[0m";else{const p=[];let g=!1;for(const y of a)if(y.startsWith("\x1B]8;;")&&!y.endsWith("\x1B]8;;\x07")){g=!0;break}g&&c.includes("\x1B]8;;\x07")&&p.push("\x1B]8;;\x07");let u=!1,b=!1;for(const y of a)if(y.startsWith("\x1B[")&&y.endsWith("m")){const x=y.slice(2,-1);tt(x)?u=!0:it(x)&&(b=!0)}if(u&&b){const y=Ct(t,["\x1B[3","\x1B[9","\x1B[38;"]),x=Ct(t,["\x1B[4","\x1B[10","\x1B[48;"]);y>=0&&x>=0?y>x?p.push("\x1B[39m","\x1B[49m"):p.push("\x1B[49m","\x1B[39m"):p.push("\x1B[39m","\x1B[49m")}else u&&p.push("\x1B[39m"),b&&p.push("\x1B[49m");u&&b&&t.includes("\x1B[39m")&&t.includes("\x1B[49m")&&(t.indexOf("\x1B[39m")<t.indexOf("\x1B[49m")?(p.length-=2,p.push("\x1B[39m","\x1B[49m")):t.indexOf("\x1B[49m")<t.indexOf("\x1B[39m")&&(p.length-=2,p.push("\x1B[49m","\x1B[39m")));const W=Di.filter(y=>a.has(y.open)).map(y=>({position:t.indexOf(y.open),style:y})).filter(y=>y.position>=0).toSorted((y,x)=>x.position-y.position);for(const y of W){const x=y;c.includes(x.style.close)&&p.push(x.style.close)}f=p.join("")}const w=[...a].join("");d.push({after:f,before:w,content:m,visibleLength:k(m,i.width)})}return vt.set(e,d),d},St=(t,i,e,o)=>{const s=[...o.segmenter.segment(t)],h=[];let n=0,r=!1;for(const c of s){const a=k(c.segment,o.width),d=n,l=n+a;if(!r)if(d<i){n=l;continue}else r=!0;if(d>=e||l>e)break;h.push(c.segment),n=l}return h.join("")},F=(t,i=0,e=Number.MAX_SAFE_INTEGER,o={})=>{const s={segmenter:Vi,...o};if(i>=e||t==="")return"";const h=k(t,s.width);if(i===0&&e>=h)return t;if(i<0||e<0)throw new RangeError("Negative indices aren't supported");if(!t.includes("\x1B"))return qi.test(t)?t.slice(i,e):St(t,i,e,s);if(xt.lastIndex=0,Wt.lastIndex=0,!xt.test(t)&&!Wt.test(t))return t;const n=Yi(t,s);if(n.length===0)return"";let r=0;const c=[];for(const[l,m]of n.entries()){const f=r,w=r+m.visibleLength;if(w>i&&f<e){const p=Math.max(0,i-f),g=Math.min(m.visibleLength,e-f);c.push({end:g,index:l,segment:m,start:p})}r=w}if(c.length===0)return"";const a=[],d=c[0].segment;a.push(d.before);for(let l=0;l<c.length;l++){const{end:m,segment:f,start:w}=c[l];if(w===0&&m===f.visibleLength?a.push(f.content):a.push(St(f.content,w,m,s)),l<c.length-1){const p=c[l+1].segment,g=f.after,u=p.before;g!==u&&(g||u)&&a.push(g,u)}}return a.push(c.at(-1).segment.after),a.join("")},At="…",Ki=3,et=(t,i,e=!1)=>{if(t.charAt(i)===" ")return i;const o=e?1:-1,s=Math.min(Ki,e?t.length-i:i);for(let h=1;h<=s;h++){const n=i+h*o;if(t.charAt(n)===" ")return n}return i},ot=(t,i,e)=>z(t,{...e,ellipsis:"",ellipsisWidth:0,limit:i}).index,nt=(t,i,e)=>k(t.slice(0,i),e),It=(t,i,e={})=>{if(typeof t!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof t}`);if(typeof i!="number")throw new TypeError(`Expected \`limit\` to be a number, got ${typeof i}`);if(t===""||i<=0)return"";const o=t.normalize("NFC"),{ellipsis:s=At,position:h="end",preferTruncationOnSpace:n=!1}=e;let r=e.ellipsisWidth??(s===At?1:void 0);r??=z(s,{...e.width,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width;const{width:c}=z(o,{...e.width,ellipsis:s,ellipsisWidth:r});if(c<=i)return o;switch(h){case"end":{if(n){const a=i-r,d=ot(o,a,e.width),l=et(o,d),m=nt(o,l,e.width);return F(o,0,m,{width:e.width})+s}return F(o,0,i-r,{width:e.width})+s}case"middle":{const a=Math.floor(i/2),d=Math.max(0,i-r),l=Math.min(a,d),m=Math.max(0,d-l);if(n){const f=ot(o,l,e.width),w=et(o,f),p=nt(o,w,e.width),g=c-m,u=ot(o,g,e.width),b=et(o,u,!0),W=nt(o,b,e.width);return F(o,0,p,{width:e.width})+s+F(o,W,c,{width:e.width}).trim()}return F(o,0,l,{width:e.width})+s+F(o,c-m,c,{width:e.width})}case"start":{if(n){const a=c-i+r,d=ot(o,a,e.width),l=et(o,d,!0),m=nt(o,l,e.width);return s+F(o,m,c,{width:e.width}).trim()}return s+F(o,c-i+r,c,{width:e.width})}default:throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${h}'`)}},Mt=/(?:\u{1B}\[|\u{9B})[\u{30}-\u{3F}]*[\u{20}-\u{2F}]*[\u{40}-\u{7E}]/uy,lt=(t,i)=>{if(J.has(t[i])){if(t.startsWith(q,i+1)){const e=t.indexOf(pt,i);return e===-1?void 0:t.slice(i,e+1)}return Mt.lastIndex=i,Mt.exec(t)?.[0]}},Zi=(t,i)=>{if(!J.has(t[i]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const e=!0,o=t.slice(i+1,i+1+q.length).join("")===q;return{isInsideEscape:e,isInsideLinkEscape:o}},Xi=t=>{let i=0;for(let e=0;e<t.length;e+=1)t.codePointAt(e)>65535&&(e+=1),i+=1;return i},Qi=(t,i={})=>{let e="",o=!1,s=0,h="",n="",r=!1;const c=[...t],a=[];for(let d=0,l=0;d<c.length;d+=1)a.push(l),l+=c[d].length;for(let d=0;d<c.length;d++){const l=c[d];if(l&&J.has(l)){if(e){const g=i.getWidth?.(e)??0,u={isEscapeSequence:!1,isGrapheme:!0,text:e,width:g};if(r&&(u.isHyperlink=!0,u.hyperlinkUrl=n),i.onSegment?.(u)===!1)return;e=""}o=!0,s=d,h=l;const w=Zi(c,d),{isInsideLinkEscape:p}=w;if(p){let g=d+1;for(n="";g<c.length;){const b=c[g];if(b===pt)break;n+=b,g+=1}n=n.slice(4);const u={hyperlinkUrl:n,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(i.onSegment?.(u)===!1)return;d=g,r=!0,o=!1,h="";continue}if(d+1<c.length&&c[d+1]==="\\"&&r){const g={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(i.onSegment?.(g)===!1)return;r=!1,n="",d+=1,o=!1,h="";continue}}if(o){const w=lt(t,a[s]);o=!1,w===void 0?(h=c.slice(s).join(""),d=c.length):(h=w,d=s+Xi(w)-1);const p={isEscapeSequence:!0,isGrapheme:!1,text:h,width:0};if(i.onSegment?.(p)===!1)return;h="";continue}e+=l;const m=i.getWidth?.(e)??0,f={isEscapeSequence:!1,isGrapheme:!0,text:e,width:m};if(r&&(f.isHyperlink=!0,f.hyperlinkUrl=n),i.onSegment?.(f)===!1)return;e=""}if(e){const d=i.getWidth?.(e)??0,l={isEscapeSequence:!1,isGrapheme:!0,text:e,width:d};r&&(l.isHyperlink=!0,l.hyperlinkUrl=n),i.onSegment?.(l)}if(h){const d={isEscapeSequence:!0,isGrapheme:!1,text:h,width:0};i.onSegment?.(d)}},kt=t=>`${J.values().next().value}${q}${t}${pt}`,te=(t,i,e)=>{let o=e,s=0;for(;s<t.length;){if(!J.has(t[s])){s+=1;continue}const h=lt(t,s);if(h===void 0){s+=1;continue}if(t.startsWith(q,s+1)){const n=h.slice(1+q.length,-1);o=n.length===0?void 0:n}else i.processEscape(h);s+=h.length}return o},ie=t=>{if(t.length===0)return"";if(t.length===1)return t[0];const i=new Gi,e=t.length-1;let o="",s;for(const[h,n]of t.entries())h>0&&(o+=i.getStartEscapesForAllActiveAttributes(),s!==void 0&&(o+=kt(s))),o+=n,s=te(n,i,s),h<e&&(s!==void 0&&(o+=kt("")),o+=i.getEndEscapesForAllActiveAttributes(),o+=`
2
+ `);return o},ee=/(?=\s)|(?<=\s)/,oe=new Intl.Segmenter("en",{granularity:"grapheme"}),ne=/[^\u0000-\u02FF]/,gt=/^\s+$/,jt=new Map,re=t=>{const i=jt.get(t);if(i!==void 0)return i;const e=k(t);return jt.set(t,e),e},se=t=>{if(!ne.test(t))return[t];const i=[];let e="";for(const{segment:o}of oe.segment(t)){if(k(o)>1){e!==""&&(i.push(e),e=""),i.push(o);continue}e+=o}return e!==""&&i.push(e),i},Et=t=>t.split(ee).flatMap(i=>i===""||gt.test(i)?[i]:se(i)),Nt="x",he=t=>{let i="",e=0;for(;e<t.length;){const o=J.has(t[e])?lt(t,e):void 0;if(o===void 0){if(J.has(t[e]))return i+Nt.repeat(t.length-e);i+=t[e],e+=1;continue}i+=Nt.repeat(o.length),e+=o.length}return i},Yt=t=>{if(![...J].some(o=>t.includes(o)))return Et(t);const i=[];let e=0;for(const o of Et(he(t)))i.push(t.slice(e,e+o.length)),e+=o.length;return i},_=t=>{const i=t.split(" ");let e=i.length;for(;e>0&&k(i[e-1])===0;)e--;return e===i.length?t:i.slice(0,e).join(" ")+i.slice(e).join("")},Kt=(t,i,e)=>{if(t.length===0)return[""];if(i<=0)return[t];const o=[];let s="",h=0,n=0;for(;n<t.length;){const r=t.codePointAt(n),c=String.fromCodePoint(r),a=c.length;if(J.has(c)){const m=lt(t,n);if(m===void 0){s+=t.slice(n);break}s+=m,n+=m.length;continue}const d=re(c),l=c===" ";if(d===0){s+=c,n+=a;continue}if(h+d>i&&(s&&o.push(s),s="",h=0,l&&e)){for(;n<t.length&&t[n]===" ";)n+=1;continue}if(s+=c,h+=d,h===i&&n+a<t.length&&(o.push(s),s="",h=0,n+a<t.length&&t[n+a]===" "&&e)){for(n+=a;n<t.length&&t[n]===" ";)n+=1;continue}n+=a}return s&&o.push(s),e?o.map(r=>_(r)):o},ce=(t,i,e)=>{if(t.length===0)return[];const o=e?t.trim():t;if(o.length===0)return[];const s=[];let h="",n=0;return Qi(o,{getWidth:k,onSegment:r=>{const c=r.text??"";if(r.isEscapeSequence)h+=c;else{const a=c===" ";if(r.width===0)return h+=c,!0;if(n+r.width>i&&(h&&s.push(h),h="",n=0,a))return e||s.push(c),!0;h+=c,n+=r.width}return!0}}),h&&s.push(h),e?s.map(r=>_(r)):s},ae=(t,i,e)=>{if(t.length===0)return[];const o=e?t.trim():t;if(o.length===0)return[];const s=Yt(o),h=[];let n="",r=0,c=0;for(;c<s.length;){const a=s[c],d=gt.test(a),l=k(a);if(a.length===0){c+=1;continue}if(e&&d&&r===0){c+=1;continue}if(r+l>i&&r>0){e?h.push(_(n)):h.push(n),n="",r=0;continue}n+=a,r+=l,c+=1}return n&&(e?h.push(_(n)):h.push(n)),h},le=(t,i,e)=>{if(t.length===0)return[];const o=e?t.trim():t;if(o.length===0)return[];const s=Yt(o),h=[];let n="",r=0,c=0;for(;c<s.length;){const a=s[c],d=gt.test(a),l=k(a);if(a.length===0){c+=1;continue}if(e&&d&&r===0){c+=1;continue}if(l>i){n&&h.push(e?_(n):n);const m=Kt(a,i,e);if(m.length>0){for(let f=0;f<m.length-1;f+=1)h.push(m[f]);n=m.at(-1),r=k(n)}else n="",r=0;c+=1;continue}if(r+l>i&&r>0&&(h.push(e?_(n):n),n="",r=0,e&&d)){c+=1;continue}n+=a,r+=l,c+=1}return n&&h.push(e?_(n):n),h},rt={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},de=(t,i={})=>{const{removeZeroWidthCharacters:e=!0,trim:o=!0,width:s=80,wrapMode:h=rt.PRESERVE_WORDS}=i;if(o&&t.trim()==="")return"";let n=t.normalize("NFC").replaceAll(`\r
3
+ `,`
4
+ `);return e&&(n=n.replaceAll(Li,"")),n.split(`
5
+ `).map(r=>{if(o&&r.trim()==="")return"";let c;switch(h){case rt.BREAK_AT_CHARACTERS:{c=ce(r,s,o);break}case rt.BREAK_WORDS:{c=le(r,s,o);break}case rt.STRICT_WIDTH:{c=Kt(r,s,o);break}default:c=ae(r,s,o)}return ie(c)}).join(`
6
+ `)},Zt=80,Xt=24,ft=(t,i,{shell:e,env:o}={})=>ai(t,i,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:500,shell:e,env:o}).trim(),st=(t,i)=>({columns:Number.parseInt(t,10),rows:Number.parseInt(i,10)}),Qt=(t,i)=>{const{columns:e,rows:o}=st(t,i);if(!(Number.isNaN(e)||Number.isNaN(o))&&!(e===Zt&&o===Xt))return{columns:e,rows:o}},ue=()=>{if(T.platform!=="linux")return!0;try{const t=Y.readFileSync("/proc/self/stat","utf8"),i=t.lastIndexOf(") ");if(i===-1)return!1;const e=t.slice(i+2).trim().split(/\s+/),o=Number.parseInt(e[2],10),s=Number.parseInt(e[5],10);return Number.isNaN(o)||Number.isNaN(s)||s<=0?!1:o===s}catch{return!1}};function fe(){const{env:t,stdout:i,stderr:e}=T;if(i?.columns&&i?.rows)return st(i.columns,i.rows);if(e?.columns&&e?.rows)return st(e.columns,e.rows);if(t.COLUMNS&&t.LINES)return st(t.COLUMNS,t.LINES);const o={columns:Zt,rows:Xt};return T.platform==="win32"?ut()??o:T.platform==="darwin"?Lt()??ut()??o:Lt()??ut()??me()??o}const Lt=()=>{try{const t=T.platform==="darwin"?Y.constants.O_EVTONLY|Y.constants.O_NONBLOCK:Y.constants.O_NONBLOCK,{columns:i,rows:e}=li.WriteStream(Y.openSync("/dev/tty",t));return{columns:i,rows:e}}catch{}},ut=()=>{try{const t=ft("tput",["cols"],{env:{TERM:"dumb",...T.env}}),i=ft("tput",["lines"],{env:{TERM:"dumb",...T.env}});if(t&&i)return Qt(t,i)}catch{}},me=()=>{try{if(!ue())return;const t=ft("resize",["-u"]).match(/\d+/g);if(t.length===2)return Qt(t[0],t[1])}catch{}},P=(t,i)=>{switch(i){case"bottom":return{body:t.bottomBody,join:t.bottomJoin,left:t.bottomLeft,right:t.bottomRight};case"middle":return{body:t.joinBody,join:t.joinJoin,left:t.joinLeft,right:t.joinRight};case"top":return{body:t.topBody,join:t.topJoin,left:t.topLeft,right:t.topRight};default:throw new Error(`Invalid borderType: ${String(i)}`)}},we=t=>({join:t.bodyJoin,left:t.bodyLeft,right:t.bodyRight}),ct=(t,i,e,o=1)=>{let s=0;for(let h=0;h<e;h+=1)s+=t[i+h]??0;return e>1&&(s+=(e-1)*o),s},mt=(t,i,e,o)=>{let s=i;for(;s>0&&t[s-1]?.[e]===o;)s-=1;let h=i;for(;h<t.length-1&&t[h+1]?.[e]===o;)h+=1;let n;const r=h-s+1;if(r===1)n=!0;else switch(o.vAlign){case"bottom":{n=i===h;break}case"middle":{const c=s+Math.floor(r/2);n=i===c;break}case"top":{n=i===s;break}default:n=i===s}return{firstRow:s,lastRow:h,showContent:n}},pe=(t,i,e,o,s)=>{if(t.length===0)return[];const h=e.showBorders?e.border?.bodyJoin.width??0:0,n=e.showBorders&&(e.border?.joinBody.width??0)>0;let r=t.length-1;for(let d=0;d<t.length;d+=1){const l=t[d];if(l){for(const[m,f]of l.entries())if(f&&s(t,d,m,f)===d){const w=mt(t,d,m,f);r=Math.max(r,w.lastRow)}}}const c=Array.from({length:r+1}).fill(1);for(let d=0;d<t.length;d+=1){const l=t[d];if(l)for(let m=0;m<e.columns;m+=1){const f=l[m];if(f&&s(t,d,m,f)===d&&(f.rowSpan??1)===1){const w=f.colSpan??1,p=ct(i,m,w,h),g=o(f,p).length;c[d]=Math.max(c[d]??1,g)}}}const a=Array.from({length:c.length}).fill(!1);if(e.fixedRowHeights)for(let d=0;d<c.length;d+=1){let l;e.fixedRowHeights[d]!==void 0?l=e.fixedRowHeights[d]:e.fixedRowHeights.length===1&&e.fixedRowHeights[0]!==void 0&&(l=e.fixedRowHeights[0]),l!==void 0&&(c[d]=Math.max(1,l),a[d]=!0)}for(let d=0;d<t.length;d+=1){const l=t[d];if(l)for(let m=0;m<e.columns;m+=1){const f=l[m];if(f&&s(t,d,m,f)===d&&(f.rowSpan??1)>1){const w=f.colSpan??1,p=ct(i,m,w,h),g=o(f,p),u=n?g.length-1:g.length,b=mt(t,d,m,f),{firstRow:W,lastRow:y}=b;let x=0,R=0;for(let v=W;v<=y&&v<c.length;v+=1)x+=c[v]??1,a[v]||(R+=1);const S=u-x;if(S>0)if(R>0){const v=Math.ceil(S/R);let B=0;for(let A=W;A<=y&&A<c.length;A+=1)if(!a[A]){const M=Math.min(v,S-B);if(c[A]=(c[A]??1)+M,B+=M,B>=S)break}}else(e.onWarn??(v=>{console.warn(v)}))(`[calculateRowHeights] Content of spanning cell exceeds fixed height allocated. Cell: ${JSON.stringify(f.content)}, Required: ${String(u)}, Allocated: ${String(x)} (fixed).`)}}}return c},G=(t,i,e,o)=>{let s=i;for(;s>0&&t[s-1]?.[e]===o;)s-=1;return s},Jt=t=>{if(typeof t=="string")return{content:t};if(typeof t=="number"||typeof t=="bigint"||typeof t=="boolean")return{content:String(t)};if(t==null)return{content:"",isEmpty:!0};if(typeof t=="object"&&"content"in t){let{content:i}=t,e=!1;if(typeof i=="number"||typeof i=="bigint"||typeof i=="boolean")i=String(i);else if(i==null)i="",e=!0;else if(typeof i!="string")throw new TypeError(`Invalid item type in grid cell: expected string, number, null, undefined, or GridItem object, but received ${JSON.stringify(t)} (type: ${typeof t})`);return e?{...t,content:i,isEmpty:!0}:{...t,content:i}}throw new TypeError(`Invalid item type in grid cell: expected string, number, null, undefined, or GridItem object, but received ${JSON.stringify(t)} (type: ${typeof t})`)},ge=(t,i,e,o,s)=>{const h=k(t),n=" ".repeat(Math.max(0,o)),r=" ".repeat(Math.max(0,s));if(h===0)return n+" ".repeat(Math.max(0,i))+r;const c=Math.max(0,i-h);switch(e){case"center":{const a=Math.floor(c/2),d=c-a;return n+" ".repeat(a)+t+" ".repeat(d)+r}case"right":return n+" ".repeat(c)+t+r;default:return n+t+" ".repeat(c)+r}},Ft=/\r?\n/,Tt=/\s+/;let Ot;const be=()=>(Ot??=fe().columns,Ot),C=(t,i)=>!t||!i?t:typeof i=="function"?i(t):i.open+t+i.close;class at{#t;#e=[];#o;#r=new WeakMap;#n=new WeakMap;#i=new WeakMap;#s(i){const e=this.#i.get(i);if(e)return e;const o=String(i.content??"").split(Ft);let s=0;for(const n of o)s=Math.max(s,k(n));const h={lines:o,maxLineWidth:s};return this.#i.set(i,h),h}#h(i){const e=this.#t.onWarn;if(e){e(i);return}console.warn(i)}static createGridLayout(){return[]}static calculateImplicitRowCount(i,e){let o=0;for(const s of i)o+=(s.colSpan??1)*(s.rowSpan??1);return Math.max(1,Math.ceil(o/e))}constructor(i){const e={autoColumns:1,autoFlow:"row",autoRows:1,balancedWidths:!1,gap:0,paddingLeft:1,paddingRight:1,rows:0,showBorders:i.border!==void 0,truncate:!1,truncateOverflow:!0,wordWrap:!1};let o;Array.isArray(i.fixedRowHeights)?o=i.fixedRowHeights:typeof i.fixedRowHeights=="number"&&(o=[i.fixedRowHeights]),this.#t={...e,...i,columns:i.columns,fixedRowHeights:o,showBorders:i.border!==void 0||(i.showBorders??!1)};const{terminalWidth:s}=this.#t;this.#o=s??be(),this.#t.maxWidth&&(this.#t.maxWidth=Math.min(this.#t.maxWidth,this.#o))}addItem(i){const e=Jt(i);return this.#c(e),this.#e.push(e),this}#c(i){i.width!==void 0&&this.#h("@visulima/tabular: GridItem.width is ignored by Grid (it is only consumed by Table). Use fixedColumnWidths or maxWidth to constrain Grid column widths.")}addItems(i){for(const e of i){const o=Jt(e);this.#c(o),this.#e.push(o)}return this}setColumns(i){return this.#t.columns=i,this}setRows(i){return this.#t.rows=i,this}setBorder(i){return this.#t.border=i,this}setShowBorders(i){return this.#t.showBorders=i,this}setMaxWidth(i){return this.#t.maxWidth=i,this}toString(){const i=at.createGridLayout();if(this.#r=new WeakMap,this.#n=new WeakMap,this.#i=new WeakMap,this.placeItems(i),i.length===0||i[0]?.length===0)return"";let e=this.calculateColumnWidths(i);const o=this.calculateTotalGridWidth(e),s=typeof this.#t.maxWidth=="number"&&this.#t.maxWidth>0?Math.min(this.#t.maxWidth,this.#o):this.#o;return o>s&&(e=this.adjustColumnWidthsForTerminal(e,o)),this.renderGrid(i,e)}placeItems(i){let e=0,o=0;const s=this.#t.rows>0?this.#t.rows:Number.POSITIVE_INFINITY,h=this.#t.rows>0?this.#t.rows:at.calculateImplicitRowCount(this.#e,Math.max(1,this.#t.columns));for(let n=0;n<this.#e.length;n+=1){const r=this.#e[n];if(r.isEmpty&&!(r.rowSpan&&r.rowSpan>1)&&!(r.colSpan&&r.colSpan>1)){this.#t.autoFlow==="row"?(o+=1,o>=this.#t.columns&&(o=0,e+=1)):(e+=1,e>=h&&(e=0,o+=1));continue}const c=r.colSpan??1,a=r.rowSpan??1;let d=!1,l=e,m=o,f=0;const w=((this.#t.autoFlow==="column"?Math.max(i.length,h):i.length)+a+5)*this.#t.columns,p=c<=this.#t.columns;for(;p&&!d&&l<s&&f<w;){for(f+=1;l+a>i.length;)i.push(Array.from({length:this.#t.columns}).fill(void 0));if(this.canPlaceItem(i,l,m,c,a))this.placeItem(i,l,m,r),d=!0,this.#t.autoFlow==="row"?(o=m+c,e=l,o>=this.#t.columns&&(o=0,e+=1)):(e=l+a,o=m,e>=h&&(e=0,o+=1));else if(this.#t.autoFlow==="row")m+=1,m>=this.#t.columns&&(m=0,l+=1);else if(l+=1,l>=h&&(l=0,m+=1,m>=this.#t.columns))break}d||(this.#h(`@visulima/tabular: Could not find position for item: ${JSON.stringify(r)} after ${String(f)} attempts. Grid might be too small or layout impossible.`),this.#t.autoFlow==="row"?(o+=1,o>=this.#t.columns&&(o=0,e+=1)):(e+=1,e>=h&&(e=0,o+=1)))}if(this.#t.rows>0){if(i.length>0)for(;i.length<this.#t.rows;)i.push(Array.from({length:this.#t.columns}).fill(void 0))}else for(;i.length>0&&i.at(-1)?.every(n=>n===void 0);)i.pop()}canPlaceItem(i,e,o,s,h,n=!1){if(o+s>this.#t.columns)return!1;for(let r=e;r<e+h;r+=1)if(r<i.length){if(!i[r])return this.#h(`Grid layout unexpectedly missing row ${String(r)} during canPlaceItem check.`),!1;for(let c=o;c<o+s;c+=1)if(i[r]?.[c]!==void 0)return!1}else if(!n)return!1;return!0}computeWrappedContentWidth(i,e,o,s){let h=i;if(s){if(h>20){let n=0;for(const r of e){const c=r.split(Tt);for(const a of c)n=Math.max(n,Math.min(k(a),o))}h=Math.min(h,Math.max(n+4,12))}}else{let n=0;for(const r of e){const c=r.split(Tt);for(const a of c)n=Math.max(n,Math.min(k(a),o))}h=Math.min(h,Math.max(n+12,20))}return h}placeItem(i,e,o,s){const h=s.rowSpan??1,n=s.colSpan??1;for(let r=e;r<e+h;r+=1){for(;r>=i.length;)i.push(Array.from({length:this.#t.columns}).fill(void 0));for(let c=o;c<o+n;c+=1)c<this.#t.columns&&(i[r]||(this.#h(`Logic error: Row ${String(r)} not found in placeItem despite check.`),i[r]=Array.from({length:this.#t.columns}).fill(void 0)),i[r][c]=s)}}calculateTotalGridWidth(i){let e=0;const o=this.#t.showBorders?this.#t.border:void 0;o&&(e+=o.bodyLeft.width,e+=o.bodyRight.width);const s=i.length,h=this.#t.showBorders?o?.bodyJoin.width??0:0,n=this.#t.gap;for(let r=0;r<s;r+=1)e+=i[r]??0,r<s-1&&(e+=n,e+=h);return e}adjustColumnWidthsForTerminal(i,e){const o=typeof this.#t.maxWidth=="number"&&this.#t.maxWidth>0?Math.min(this.#t.maxWidth??0,this.#o):this.#o;if(e<=o)return i;let s=0;const h=i.length,n=this.#t.showBorders?this.#t.border:void 0;if(n&&(s+=n.bodyLeft.width,s+=n.bodyRight.width),h>1){s+=(h-1)*this.#t.gap;const m=n?.bodyJoin.width??0;s+=(h-1)*m}if(s>=o)return Array.from({length:h}).fill(1);const r=o-s,c=i.reduce((m,f)=>m+f,0);if(c===0){const m=Math.floor(r/h);return Array.from({length:h}).fill(m)}const a=i.map(m=>{const f=m/c;return Math.max(1,Math.floor(r*f))});let d=a.reduce((m,f)=>m+f,0)-r;for(;d>0;){let m=-1;for(let f=0;f<a.length;f+=1)(a[f]??0)>1&&(m===-1||(a[f]??0)>(a[m]??0))&&(m=f);if(m===-1)break;a[m]-=1,d-=1}let l=r-a.reduce((m,f)=>m+f,0);if(l>0){const m=a.map((f,w)=>{const p=c>0?(i[w]??0)/c:1/h;return{index:w,remainder:r*p%1}}).toSorted((f,w)=>w.remainder-f.remainder);for(const f of m){if(l<=0)break;const{index:w}=f;a[w]!==void 0&&(a[w]+=1,l-=1)}}return a}calculateBalancedColumnWidths(i){const e=this.calculateMinimumColumnWidthsWithGrowableInfo(i),o=e.widths,{growableColumns:s}=e,h=typeof this.#t.maxWidth=="number"&&this.#t.maxWidth>0?Math.min(this.#t.maxWidth,this.#o):this.#o,n=this.#t.showBorders?this.#t.border:void 0;let r=0;if(n&&(r+=n.bodyLeft.width,r+=n.bodyRight.width),this.#t.columns>1){r+=(this.#t.columns-1)*this.#t.gap;const d=n?.bodyJoin.width??0;r+=(this.#t.columns-1)*d}const c=Math.max(0,h-r);if(o.reduce((d,l)=>d+l,0)>0){const d=Math.floor(c/this.#t.columns),l=Array.from({length:this.#t.columns}).fill(d),m=d*this.#t.columns;let f=c-m;for(let u=0;u<l.length&&f>0;u+=1)l[u]=(l[u]??0)+1,f-=1;const w=[];let p=0;for(let u=0;u<this.#t.columns;u+=1){const b=l[u]??0,W=o[u]??0,y=Math.max(b,W);w.push(y),p+=y}if(p>c){const u=c/p,b=w.map(x=>Math.max(3,Math.floor(x*u))),W=b.reduce((x,R)=>x+R,0);let y=c-W;for(let x=0;x<b.length&&y>0;x+=1)b[x]=(b[x]??0)+1,y-=1;return b}let g=c-p;if(g>0){const u=s.length>0?s:w.map((b,W)=>W);for(;g>0&&u.length>0;)for(const b of u){if(g<=0)break;w[b]=(w[b]??0)+1,g-=1}}return w}const a=Math.floor(c/this.#t.columns);return Array.from({length:this.#t.columns}).fill(a)}calculateMinimumColumnWidthsWithGrowableInfo(i){const e=Array.from({length:this.#t.columns}).fill(0),o=[],s=this.#t.paddingLeft+this.#t.paddingRight,h=this.#t.gap+(this.#t.showBorders?this.#t.border?.bodyJoin.width??0:0);for(let n=0;n<this.#t.columns;n+=1)for(let r=0;r<i.length;r+=1){const c=i[r]?.[n];if(!c||G(i,r,n,c)!==r||n>0&&i[r]?.[n-1]===c)continue;const a=c.colSpan??1,d=c.maxWidth??Number.POSITIVE_INFINITY,{lines:l,maxLineWidth:m}=this.#s(c),f=this.#t.wordWrap&&c.wordWrap!==!1;let w=Math.min(m,d);w=this.computeWrappedContentWidth(w,l,d,f),a===1&&(e[n]=Math.max(e[n]??0,w+s),f&&!o.includes(n)&&o.push(n))}for(let n=0;n<i.length;n+=1)for(let r=0;r<this.#t.columns;r+=1){const c=i[n]?.[r];if(!c||G(i,n,r,c)!==n||r>0&&i[n]?.[r-1]===c)continue;const a=c.colSpan??1;if(a>1){const d=c.maxWidth??Number.POSITIVE_INFINITY,{lines:l,maxLineWidth:m}=this.#s(c),f=this.#t.wordWrap&&c.wordWrap!==!1;let w=Math.min(m,d);w=this.computeWrappedContentWidth(w,l,d,f);const p=(a-1)*h,g=w+s+p;let u=0;for(let W=r;W<r+a;W+=1)u+=e[W]??0;const b=u+p;if(g>b){const W=g-b,y=Math.floor(W/a);let x=0;for(let R=0;R<a&&r+R<this.#t.columns;R+=1){const S=Math.min(y,W-x);if(e[r+R]=(e[r+R]??0)+S,x+=S,x>=W)break}}}}return{growableColumns:o,widths:e}}calculateColumnWidths(i){if(this.#t.fixedColumnWidths&&this.#t.fixedColumnWidths.length===this.#t.columns){const h=this.#t.fixedColumnWidths;if(!h.some(n=>n===void 0||!Number.isFinite(n)))return[...h];if(this.#t.balancedWidths){const n=Array.from({length:h.length}).fill(0),r=typeof this.#t.maxWidth=="number"&&this.#t.maxWidth>0?Math.min(this.#t.maxWidth,this.#o):this.#o,c=this.calculateTotalGridWidth(Array.from({length:n.length}).fill(0)),a=Math.max(0,r-c);let d=0;const l=[];for(const[w,p]of h.entries())typeof p=="number"&&Number.isFinite(p)?(n[w]=p,d+=p):l.push(w);let m=Math.max(0,a-d);const f=l.length>0?Math.floor(m/l.length):0;for(const w of l)n[w]=f;m-=f*l.length;for(const w of l){if(m<=0)break;n[w]+=1,m-=1}return n}}if(this.#t.balancedWidths)return this.calculateBalancedColumnWidths(i);const e=Array.from({length:this.#t.columns}).fill(0),o=this.#t.paddingLeft+this.#t.paddingRight,s=this.#t.gap+(this.#t.showBorders?this.#t.border?.bodyJoin.width??0:0);for(let h=0;h<this.#t.columns;h+=1)for(let n=0;n<i.length;n+=1){const r=i[n]?.[h];if(!r||G(i,n,h,r)!==n||h>0&&i[n]?.[h-1]===r)continue;const c=r.colSpan??1,a=r.maxWidth??Number.POSITIVE_INFINITY,{maxLineWidth:d}=this.#s(r),l=Math.min(d,a);c===1&&(e[h]=Math.max(e[h]??0,l+o))}for(let h=0;h<i.length;h+=1)for(let n=0;n<this.#t.columns;n+=1){const r=i[h]?.[n];if(!r||G(i,h,n,r)!==h||n>0&&i[h]?.[n-1]===r)continue;const c=r.colSpan??1;if(c>1){const a=r.maxWidth??Number.POSITIVE_INFINITY,{lines:d,maxLineWidth:l}=this.#s(r),m=this.#t.wordWrap&&r.wordWrap!==!1;let f=Math.min(l,a);f=this.computeWrappedContentWidth(f,d,a,m);let w=0;for(let b=n;b<n+c;b+=1)w+=e[b]??0;const p=c>1?(c-1)*s:0,g=f+o+p,u=w+p;if(g>u){const b=g-u,W=Math.floor(b/c);let y=0;for(let x=0;x<c&&n+x<this.#t.columns;x+=1){const R=Math.min(W,b-y);if(e[n+x]=(e[n+x]??0)+R,y+=R,y>=b)break}}}}if(this.#t.fixedColumnWidths&&this.#t.fixedColumnWidths.length===this.#t.columns)for(const[h,n]of this.#t.fixedColumnWidths.entries())typeof n=="number"&&Number.isFinite(n)&&(e[h]=n);if(this.#t.maxWidth){const h=this.calculateTotalGridWidth(e);if(h>this.#t.maxWidth)return this.adjustColumnWidthsForTerminal(e,h)}return e}renderVisualRowContent(i,e,o,s,h){const n=i[e];if(!n)return"";const r=this.#t.borderColor??this.#t.foregroundColor??void 0,c=[],a=this.#t.showBorders&&this.#t.border?we(this.#t.border):void 0,d=a&&a.left.width>0?a.left.char:"",l=a&&a.right.width>0?a.right.char:"",m=a&&a.join.width>0?a.join.char:"",f=" ".repeat(this.#t.gap);d&&c.push(C(C(d,r),this.#t.backgroundColor));let w=0;for(;w<this.#t.columns;){const p=n[w]??void 0;let g=1,u;if(p){const b=p.colSpan??1;g=b;const W=G(i,e,w,p),y=this.#t.showBorders?this.#t.border?.bodyJoin.width??0:0,x=ct(s,w,b,y),R=this.alignCellContent(p,x),S=R.length,v=this.getCachedCellVerticalPosition(i,e,w,p);v.firstRow!==W&&this.#h(`Mismatch between findFirstOccurrenceRow (${String(W)}) and determineCellVerticalPosition (${String(v.firstRow)})`);const B=h.slice(W,v.lastRow+1).reduce((I,j)=>I+j,0),A=v.lastRow-v.firstRow+1;let M=o,L=0;const H=this.#t.showBorders&&(this.#t.border?.joinBody.width??0)>0;for(let I=W;I<e;I+=1)I<h.length&&(M+=h[I]??1),H&&I<v.lastRow&&(L+=1);M+=L;const O=p.vAlign??"top";let E;switch(O){case"bottom":{let I=o;for(let N=W;N<e;N+=1)I+=h[N]??1;const j=B-S;E=I>=j?I-j:-1;break}case"middle":{const I=Math.round((B-S)/2);let j=o;for(let N=W;N<e;N+=1)j+=h[N]??1;E=j>=I&&j<I+S?j-I:-1;break}case"top":{E=M;break}default:E=M}const U=E>=0&&E<S;if(u=" ".repeat(Math.max(0,x)),U){let I=!1;O==="middle"&&A%2===0&&E===0&&(I=!0),I||(u=R[E]??u)}p.colSpan&&p.colSpan>1&&(u+=f.repeat(p.colSpan)),p.foregroundColor?u=C(u,p.foregroundColor):this.#t.foregroundColor&&(u=C(u,this.#t.foregroundColor)),p.backgroundColor?u=C(u,p.backgroundColor):this.#t.backgroundColor&&(u=C(u,this.#t.backgroundColor))}else{const b=this.#t.paddingLeft+this.#t.paddingRight,W=Math.max(0,(s[w]??0)-b),y=" ".repeat(this.#t.paddingLeft+W+this.#t.paddingRight);u=C(C(o===0?y:" ".repeat(y.length),this.#t.foregroundColor),this.#t.backgroundColor)}c.push(u),w+g<this.#t.columns&&(c.push(f),this.#t.showBorders&&m&&c.push(C(C(m,r),this.#t.backgroundColor)),this.#t.gap>0&&c.push(f)),w+=g}return l&&c.push(C(C(l,r),this.#t.backgroundColor)),c.join("")}alignCellContent(i,e){const o=this.#r.get(i);if(o?.has(e))return o.get(e);const{paddingLeft:s,paddingRight:h}=this.#t,n=s+h,r=e-n;if(r<=0){const l=[" ".repeat(n+this.#t.gap)];return o?o.set(e,l):this.#r.set(i,new Map([[e,l]])),l}let c;const a=String(i.content??"");if(c=a.includes(`
7
+ `)||a.includes("\r")?a.split(Ft):[a],this.#t.wordWrap&&i.wordWrap!==!1){const l=typeof this.#t.wordWrap=="object"?this.#t.wordWrap:{},m=typeof i.wordWrap=="object"?i.wordWrap:l;c=de(a,{...m,width:r}).split(`
8
+ `)}if(this.#t.truncate&&i.truncate!==!1){const l=typeof this.#t.truncate=="object"?this.#t.truncate:{},m=typeof i.truncate=="object"?i.truncate:l;c=c.map(f=>It(f,r,m))}else this.#t.truncateOverflow&&(c=c.map(l=>k(l)>r?It(l,r,{}):l));const d=c.map(l=>ge(l,r,i.hAlign??"left",s,h));return o?o.set(e,d):this.#r.set(i,new Map([[e,d]])),d}renderHorizontalBorder(i,e,o,s,h,n=-1){if(!this.#t.showBorders||!this.#t.border)return"";const r=this.#t.border,c=P(r,h),a=c.body.char,d=c.body.width,l=r.bodyJoin.char;if(h!=="middle"&&d===0)return"";let m=c.left.char,f=c.right.char;if(h==="middle"&&n!==-1){const u=i[o]?.[0]??void 0,b=i[n]?.[0]??void 0;u&&b&&u===b&&(m=l);const W=this.#t.columns-1,y=i[o]?.[W]??void 0,x=i[n]?.[W]??void 0;y&&x&&y===x&&(f=l)}const w=[],p=" ".repeat(this.#t.gap);m&&w.push(C(C(m,this.#t.borderColor),this.#t.backgroundColor));let g;for(let u=0;u<this.#t.columns;u+=1){const b=i[o]?.[u]??void 0,W=h==="middle"&&n!==-1?i[n]?.[u]??void 0:void 0;let y,x=!1;if(b&&(u===0||i[o]?.[u-1]!==b)&&(y=b,x=!0),b&&!x)continue;if(!b){const v=s[u]??0;if(g=d>0?a.repeat(v):" ".repeat(v),w.push(C(C(g,this.#t.borderColor),this.#t.backgroundColor)),u<this.#t.columns-1){const B=this.determineJoinChar(h,i,o,n,u,u+1);w.push(p),B.width>0&&w.push(C(C(B.char,this.#t.borderColor),this.#t.backgroundColor))}continue}const R=y?.colSpan??1;if(h==="middle"&&h==="middle"&&W&&b===W&&y){const v=y.vAlign==="middle",{firstRow:B,lastRow:A}=this.getCachedCellVerticalPosition(i,o,u,y),M=A-B+1,L=M%2===0,H=B+Math.ceil(M/2)-1,O=r.bodyJoin.width,E=ct(s,u,R,O),U=this.alignCellContent(y,E),I=U.length;if(v&&L&&o===H)g=C(U[0]??"",this.#t.borderColor);else{let j=0;for(let $=B;$<=o;$+=1)j+=e[$]??1,$<o&&(j+=1);const N=j;if(N>=0&&N<I)g=C(U[N]??"",this.#t.foregroundColor);else{const $=s.slice(u,u+R).reduce((ti,ii)=>ti+ii,0)+(R-1)*(this.#t.gap+this.#t.border.bodyJoin.width);g=C(" ".repeat($),this.#t.borderColor)}}w.push(C(g,this.#t.backgroundColor))}else{const v=[];for(let B=u;B<u+R;B+=1){const A=s[B]??0,M=d>0?a:" ";if(v.push(M.repeat(A+this.#t.gap)),B<u+R-1){const L=this.determineJoinChar(h,i,o,n,B,B+1);L.width>0&&v.push(L.char)}}g=v.join(""),w.push(C(C(g,this.#t.borderColor),this.#t.backgroundColor))}const S=u+R-1;if(S<this.#t.columns-1){const v=this.determineJoinChar(h,i,o,n,S,S+1);v.width>0&&w.push(C(C(v.char,this.#t.borderColor),this.#t.backgroundColor))}u+=R-1}return f&&w.push(C(C(f,this.#t.borderColor),this.#t.backgroundColor)),w.join("")}determineJoinChar(i,e,o,s,h,n=-1){if(!this.#t.showBorders||!this.#t.border)return{char:" ",width:this.#t.gap};const r=this.#t.border;if(i!=="middle"){const x=P(r,i),R=e[o]?.[h]??void 0,S=n===-1?h+1:n,v=e[o]?.[S]??void 0,B=R!==void 0&&v!==void 0&&R===v?x.body:x.join,{char:A,width:M}=B;return{char:A,width:M>0?M:this.#t.gap}}if(s===-1||n===-1)return{char:" ",width:this.#t.gap};const c=r.bodyJoin,a=e[o]?.[h]??void 0,d=e[s]?.[h]??void 0,l=e[o]?.[n]??void 0,m=e[s]?.[n]??void 0,f=a!==void 0&&d!==void 0&&a===d,w=l!==void 0&&m!==void 0&&l===m,p=a!==void 0&&l!==void 0&&a===l,g=d!==void 0&&m!==void 0&&d===m;let u;const b=P(r,"middle");f&&w?u=p?{char:" ",width:c.width}:c:f?u=r.joinLeft:w?u=r.joinRight:p&&g?u=b.body:p?u=r.topJoin:g?u=r.bottomJoin:u=r.joinJoin;const{char:W,width:y}=u;return{char:W,width:y>0?y:this.#t.gap}}renderGrid(i,e){if(i.length===0)return"";const o=[],s=pe(i,e,this.#t,this.alignCellContent.bind(this),G),h=this.#t.showBorders&&this.#t.border?P(this.#t.border,"top"):void 0;h&&h.body.width>0&&o.push(this.renderHorizontalBorder(i,s,0,e,"top"));for(let r=0;r<i.length;r+=1){const c=s[r]??1;for(let d=0;d<c;d+=1)o.push(this.renderVisualRowContent(i,r,d,e,s));const a=this.#t.showBorders&&this.#t.border?P(this.#t.border,"middle"):void 0;if(r<i.length-1&&a&&a.body.width>0){const d=i[r],l=i[r+1];let m=!1;if(d&&l)for(let f=0;f<this.#t.columns;f+=1){const w=d[f],p=l[f];if(w!==p){m=!0;break}}m&&o.push(this.renderHorizontalBorder(i,s,r,e,"middle",r+1))}}const n=this.#t.showBorders&&this.#t.border?P(this.#t.border,"bottom"):void 0;return n&&n.body.width>0&&o.push(this.renderHorizontalBorder(i,s,i.length-1,e,"bottom")),o.join(`
9
+ `)}getCachedCellVerticalPosition(i,e,o,s){const h=this.#n.get(s);if(h)return h;const n=mt(i,e,o,s);return this.#n.set(s,n),n}}const ye={bodyJoin:{char:"│",width:1},bodyLeft:{char:"│",width:1},bodyRight:{char:"│",width:1},bottomBody:{char:"─",width:1},bottomJoin:{char:"┴",width:1},bottomLeft:{char:"└",width:1},bottomRight:{char:"┘",width:1},joinBody:{char:"─",width:1},joinJoin:{char:"┼",width:1},joinLeft:{char:"├",width:1},joinRight:{char:"┤",width:1},topBody:{char:"─",width:1},topJoin:{char:"┬",width:1},topLeft:{char:"┌",width:1},topRight:{char:"┐",width:1}},Ce={bodyJoin:{char:" ",width:1},bodyLeft:{char:" ",width:1},bodyRight:{char:" ",width:1},bottomBody:{char:"-",width:1},bottomJoin:{char:"-",width:1},bottomLeft:{char:"-",width:1},bottomRight:{char:"-",width:1},joinBody:{char:"-",width:1},joinJoin:{char:"-",width:1},joinLeft:{char:"-",width:1},joinRight:{char:"-",width:1},topBody:{char:"-",width:1},topJoin:{char:"-",width:1},topLeft:{char:"-",width:1},topRight:{char:"-",width:1}},Se={bodyJoin:{char:"║",width:1},bodyLeft:{char:"║",width:1},bodyRight:{char:"║",width:1},bottomBody:{char:"═",width:1},bottomJoin:{char:"╩",width:1},bottomLeft:{char:"╚",width:1},bottomRight:{char:"╝",width:1},joinBody:{char:"═",width:1},joinJoin:{char:"╬",width:1},joinLeft:{char:"╠",width:1},joinRight:{char:"╣",width:1},topBody:{char:"═",width:1},topJoin:{char:"╦",width:1},topLeft:{char:"╔",width:1},topRight:{char:"╗",width:1}},Ae={bodyJoin:{char:"│",width:1},bodyLeft:{char:"│",width:1},bodyRight:{char:"│",width:1},bottomBody:{char:"─",width:1},bottomJoin:{char:"┴",width:1},bottomLeft:{char:"╰",width:1},bottomRight:{char:"╯",width:1},joinBody:{char:"─",width:1},joinJoin:{char:"┼",width:1},joinLeft:{char:"├",width:1},joinRight:{char:"┤",width:1},topBody:{char:"─",width:1},topJoin:{char:"┬",width:1},topLeft:{char:"╭",width:1},topRight:{char:"╮",width:1}},Ie={bodyJoin:{char:"┊",width:1},bodyLeft:{char:"┊",width:1},bodyRight:{char:"┊",width:1},bottomBody:{char:"┈",width:1},bottomJoin:{char:"┴",width:1},bottomLeft:{char:"└",width:1},bottomRight:{char:"┘",width:1},joinBody:{char:"┈",width:1},joinJoin:{char:"┼",width:1},joinLeft:{char:"├",width:1},joinRight:{char:"┤",width:1},topBody:{char:"┈",width:1},topJoin:{char:"┬",width:1},topLeft:{char:"┌",width:1},topRight:{char:"┐",width:1}},Me={bodyJoin:{char:"|",width:1},bodyLeft:{char:"|",width:1},bodyRight:{char:"|",width:1},bottomBody:{char:"-",width:1},bottomJoin:{char:"|",width:1},bottomLeft:{char:"|",width:1},bottomRight:{char:"|",width:1},joinBody:{char:"-",width:1},joinJoin:{char:"|",width:1},joinLeft:{char:"|",width:1},joinRight:{char:"|",width:1},topBody:{char:"-",width:1},topJoin:{char:"|",width:1},topLeft:{char:"|",width:1},topRight:{char:"|",width:1}},ke={bodyJoin:{char:"|",width:1},bodyLeft:{char:"|",width:1},bodyRight:{char:"|",width:1},bottomBody:{char:"-",width:1},bottomJoin:{char:"+",width:1},bottomLeft:{char:"+",width:1},bottomRight:{char:"+",width:1},joinBody:{char:"-",width:1},joinJoin:{char:"+",width:1},joinLeft:{char:"+",width:1},joinRight:{char:"+",width:1},topBody:{char:"-",width:1},topJoin:{char:"+",width:1},topLeft:{char:"+",width:1},topRight:{char:"+",width:1}},je={bodyJoin:{char:"",width:0},bodyLeft:{char:"",width:0},bodyRight:{char:"",width:0},bottomBody:{char:"",width:0},bottomJoin:{char:"",width:0},bottomLeft:{char:"",width:0},bottomRight:{char:"",width:0},joinBody:{char:"",width:0},joinJoin:{char:"",width:0},joinLeft:{char:"",width:0},joinRight:{char:"",width:0},topBody:{char:"",width:0},topJoin:{char:"",width:0},topLeft:{char:"",width:0},topRight:{char:"",width:0}},Ee={bodyJoin:{char:"█",width:1},bodyLeft:{char:"█",width:1},bodyRight:{char:"█",width:1},bottomBody:{char:"█",width:1},bottomJoin:{char:"█",width:1},bottomLeft:{char:"█",width:1},bottomRight:{char:"█",width:1},joinBody:{char:"█",width:1},joinJoin:{char:"█",width:1},joinLeft:{char:"█",width:1},joinRight:{char:"█",width:1},topBody:{char:"█",width:1},topJoin:{char:"█",width:1},topLeft:{char:"█",width:1},topRight:{char:"█",width:1}},Ne={bodyJoin:{char:"┃",width:1},bodyLeft:{char:"┃",width:1},bodyRight:{char:"┃",width:1},bottomBody:{char:"━",width:1},bottomJoin:{char:"┻",width:1},bottomLeft:{char:"┗",width:1},bottomRight:{char:"┛",width:1},joinBody:{char:"━",width:1},joinJoin:{char:"╋",width:1},joinLeft:{char:"┣",width:1},joinRight:{char:"┫",width:1},topBody:{char:"━",width:1},topJoin:{char:"┳",width:1},topLeft:{char:"┏",width:1},topRight:{char:"┓",width:1}},xe=t=>t.reduce((i,e)=>{if(e===null)return i+1;if(typeof e=="object"&&!Array.isArray(e)){const o=typeof e.colSpan=="number"?e.colSpan:1;return i+(o<=0?1:o)}return i+1},0),We=/[\u0000-\u001F\u007F-\u009F]/gu,Be=t=>t.replaceAll(We,"");class ve{#t;#e=[];#o=[];#r=[];#n=!0;#i=void 0;#s(i){const e=this.#t.onWarn;if(e){e(i);return}console.warn(i)}constructor(i={}){this.#t={...i,showFooter:i.showFooter??!0,showHeader:i.showHeader??!0,style:{border:ye,paddingLeft:1,paddingRight:1,...i.style}}}setHeaders(i){return i.length>0&&!Array.isArray(i[0])?this.#o=[i]:this.#o=i.map(e=>Array.isArray(e)?e:[e]),this.#n=!0,this.#i=void 0,this}setFooter(i){return i.length>0&&!Array.isArray(i[0])?this.#r=[i]:this.#r=i.map(e=>Array.isArray(e)?e:[e]),this.#n=!0,this.#i=void 0,this}addRow(i){if(!Array.isArray(i))throw new TypeError("Row must be an array");return this.#e.push(i),this.#n=!0,this.#i=void 0,this}addRows(...i){for(const e of i)this.addRow(e);return this.#n=!0,this.#i=void 0,this}getRows(){return this.#e.map(i=>[...i])}get rowCount(){return this.#e.length}removeRow(i){if(!Number.isInteger(i)||i<0||i>=this.#e.length)throw new RangeError(`Row index ${String(i)} is out of bounds (0..${String(this.#e.length-1)})`);return this.#e.splice(i,1),this.#n=!0,this.#i=void 0,this}clear(){return this.#e.length=0,this.#n=!0,this.#i=void 0,this}toString(){if(!this.#n&&this.#i!==void 0)return this.#i;const i=this.#t.showHeader?this.#o:[],e=this.#t.showFooter?this.#r:[],o=[...i,...this.#e,...e];if(o.length===0)return this.#i="",this.#n=!1,"";let s=0;for(const f of o){const w=f;Array.isArray(w)?s=Math.max(s,xe(w)):this.#s(`Unexpected non-array element found while calculating columns: ${JSON.stringify(w)}`)}if(s===0)return this.#i="",this.#n=!1,"";let h;Array.isArray(this.#t.columnWidths)?h=this.#t.columnWidths.length>=s?this.#t.columnWidths.slice(0,s):[...this.#t.columnWidths,...Array.from({length:s-this.#t.columnWidths.length}).fill(void 0)]:typeof this.#t.columnWidths=="number"&&(h=Array.from({length:s}).fill(this.#t.columnWidths));let n;const r=o.length;if(Array.isArray(this.#t.rowHeights)?n=this.#t.rowHeights:typeof this.#t.rowHeights=="number"&&(n=Array.from({length:r}).fill(this.#t.rowHeights)),h||o.some(f=>Array.isArray(f)&&f.some(w=>typeof w=="object"&&w!==null&&!Array.isArray(w)&&w.width!==void 0))&&(h=Array.from({length:s}).fill(void 0)),h&&Array.isArray(h)){const f=[...h];for(const w of o){const p=w;let g=0;for(const u of p){let b={};if(typeof u=="object"&&u!==null&&!Array.isArray(u)){const{content:W,href:y,...x}=u;b=x}b.width!==void 0?f[g]=b.width:b.maxWidth!==void 0&&f[g]!==void 0&&(f[g]=Math.min(f[g],b.maxWidth)),g+=b.colSpan??1}}h=f}const c={autoFlow:"row",backgroundColor:this.#t.style?.backgroundColor,balancedWidths:this.#t.balancedWidths??!1,border:this.#t.style?.border,borderColor:this.#t.style?.borderColor,columns:s,fixedColumnWidths:h,fixedRowHeights:n,foregroundColor:this.#t.style?.foregroundColor,gap:this.#t.gap??0,maxWidth:this.#t.maxWidth,onWarn:this.#t.onWarn,paddingLeft:this.#t.style?.paddingLeft,paddingRight:this.#t.style?.paddingRight,terminalWidth:this.#t.terminalWidth,truncate:this.#t.truncate??(h?.every(f=>typeof f=="number")||this.#t.maxWidth!==void 0&&!this.#t.balancedWidths),truncateOverflow:this.#t.truncateOverflow??!0,wordWrap:this.#t.wordWrap??!1},a=new at(c),d=[];if(this.#t.columnDefaults)for(const[f,w]of this.#t.columnDefaults.entries())w&&(d[f]={...w});if(this.#t.colAligns)for(const[f,w]of this.#t.colAligns.entries())w!==void 0&&(d[f]={...d[f],hAlign:d[f]?.hAlign??w});const l=d.length>0,m=[];for(const[f,w]of o.entries()){const p=w;if(!Array.isArray(p)){this.#s(`Skipping non-array row while creating GridItems: ${JSON.stringify(p)}`);continue}const g=this.#t.showHeader?this.#o.length:0,u=this.#e.length,b=this.#t.showHeader&&f<g,W=this.#t.showFooter&&f>=g+u,y=b&&p.length===1&&s>1,x=W&&p.length===1&&s>1;let R=0;for(const S of p){let v=S,B={};if(typeof v=="object"&&v!==null&&!Array.isArray(v)){const{content:H,href:O,...E}=v;v=O?`\x1B]8;;${Be(O)}\x1B\\${String(H)}\x1B]8;;\x1B\\`:H,B=E}const A=l?d[R]:void 0;A&&(B={...B,hAlign:B.hAlign??A.hAlign,maxWidth:B.maxWidth??A.maxWidth,truncate:B.truncate??A.truncate,vAlign:B.vAlign??A.vAlign,wordWrap:B.wordWrap??A.wordWrap}),R+=B.colSpan??1,y&&(B.colSpan=s),x&&(B.colSpan=s);const M=this.#t.transformTabToSpace&&typeof v=="string"?v.replaceAll(" "," ".repeat(this.#t.transformTabToSpace)):v,{maxWidth:L}=B;m.push({backgroundColor:B.backgroundColor,colSpan:B.colSpan,content:M,foregroundColor:B.foregroundColor,hAlign:B.hAlign,maxWidth:L,rowSpan:B.rowSpan,truncate:B.truncate??(L===void 0?void 0:!0),vAlign:B.vAlign,wordWrap:B.wordWrap})}}return a.addItems(m),this.#i=a.toString(),this.#n=!1,this.#i}}const Le=t=>new ve(t);export{Le as N,Ne as R,je as a,Me as c,Ie as d,Ce as h,Ae as i,ve as k,Se as o,ke as r,ye as t,Ee as w};
@@ -1 +1 @@
1
- import{createRequire as C}from"node:module";import{getAffectedProjects as S}from"@visulima/task-runner";import{i as W}from"./index-BjdW45xX.js";import{V as j}from"./vis-user-error-CnMuoAGo.js";import{r as A}from"./affected-shas-Dd0P7fGD.js";let T;const $=e=>(T??=C(import.meta.url))(e),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=e=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[t,s]=f.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return f.getBuiltinModule(e)}return $(e)},{spawnSync:I}=R("node:child_process"),v=new Set(["deep","direct","none"]),B=e=>{const t=[],s=e.split("\0");for(let n=0;n<s.length;n++){const o=s[n];if(!o||o.length<4)continue;const p=o.slice(0,2),d=o.slice(3);if(d&&t.push(d),p.includes("R")||p.includes("C")){n+=1;const c=s[n];c&&t.push(c)}}return t},P=e=>{const t=I("git",["status","--porcelain","-z"],{cwd:e,encoding:"utf8"});return t.error||t.status!==0||typeof t.stdout!="string"?[]:B(t.stdout)},D=async(e,t,s={})=>{const n=e.downstream??"deep",o=e.upstream??"none";if(!v.has(n))throw new j(`Invalid --downstream value: "${n}". Must be "none", "direct", or "deep".`);if(!v.has(o))throw new j(`Invalid --upstream value: "${o}". Must be "none", "direct", or "deep".`);const{projectGraph:p,projects:d,workspaceRoot:c}=t,u=[];let{base:m}=e,{head:r}=e;if(!m||!r){const l=A({defaultBase:s.defaultBase,workspaceRoot:c});m=m||l.base,r=r||l.head,u.push(`Resolved affected refs from ${l.provider} (${l.notes.join("; ")})`)}const k=s.runningInCi??W,h=r==="HEAD"||r==="",b=e.uncommitted??(!k&&h);let a=[];if(b)if(h){const g=(s.readWorkingTreeChanges??P)(c),y=Object.values(d).map(i=>i.root?.replace(/\/$/,"")).filter(i=>!!i&&i!==".");a=g.filter(i=>y.some(_=>i===_||i.startsWith(`${_}/`)));const w=g.length-a.length;a.length>0&&u.push(`including ${a.length} uncommitted working-tree file(s)`),w>0&&u.push(`ignoring ${w} uncommitted path(s) outside any project (untracked scratch would otherwise mark every project affected)`)}else u.push(`ignoring --uncommitted: --head=${r} pins the comparison to a commit, not the working tree`);return{...await S({additionalChangedFiles:a,base:m,downstream:n,head:r,projectGraph:p,projects:d,upstream:o,workspaceRoot:c}),notes:u,uncommittedFileCount:a.length}};export{D as s};
1
+ import{createRequire as C}from"node:module";import{getAffectedProjects as S}from"@visulima/task-runner";import{i as W}from"./index-BjdW45xX.js";import{V as j}from"./vis-user-error-qqqhLoF6.js";import{r as A}from"./affected-shas-Dd0P7fGD.js";let T;const $=e=>(T??=C(import.meta.url))(e),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=e=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[t,s]=f.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return f.getBuiltinModule(e)}return $(e)},{spawnSync:I}=R("node:child_process"),v=new Set(["deep","direct","none"]),B=e=>{const t=[],s=e.split("\0");for(let n=0;n<s.length;n++){const o=s[n];if(!o||o.length<4)continue;const p=o.slice(0,2),d=o.slice(3);if(d&&t.push(d),p.includes("R")||p.includes("C")){n+=1;const c=s[n];c&&t.push(c)}}return t},P=e=>{const t=I("git",["status","--porcelain","-z"],{cwd:e,encoding:"utf8"});return t.error||t.status!==0||typeof t.stdout!="string"?[]:B(t.stdout)},D=async(e,t,s={})=>{const n=e.downstream??"deep",o=e.upstream??"none";if(!v.has(n))throw new j(`Invalid --downstream value: "${n}". Must be "none", "direct", or "deep".`);if(!v.has(o))throw new j(`Invalid --upstream value: "${o}". Must be "none", "direct", or "deep".`);const{projectGraph:p,projects:d,workspaceRoot:c}=t,u=[];let{base:m}=e,{head:r}=e;if(!m||!r){const l=A({defaultBase:s.defaultBase,workspaceRoot:c});m=m||l.base,r=r||l.head,u.push(`Resolved affected refs from ${l.provider} (${l.notes.join("; ")})`)}const k=s.runningInCi??W,h=r==="HEAD"||r==="",b=e.uncommitted??(!k&&h);let a=[];if(b)if(h){const g=(s.readWorkingTreeChanges??P)(c),y=Object.values(d).map(i=>i.root?.replace(/\/$/,"")).filter(i=>!!i&&i!==".");a=g.filter(i=>y.some(_=>i===_||i.startsWith(`${_}/`)));const w=g.length-a.length;a.length>0&&u.push(`including ${a.length} uncommitted working-tree file(s)`),w>0&&u.push(`ignoring ${w} uncommitted path(s) outside any project (untracked scratch would otherwise mark every project affected)`)}else u.push(`ignoring --uncommitted: --head=${r} pins the comparison to a commit, not the working tree`);return{...await S({additionalChangedFiles:a,base:m,downstream:n,head:r,projectGraph:p,projects:d,upstream:o,workspaceRoot:c}),notes:u,uncommittedFileCount:a.length}};export{D as s};
@@ -1,4 +1,4 @@
1
- import{createRequire as T}from"node:module";import{readLastRunSummary as _}from"@visulima/task-runner";import{a as $}from"./failure-log-DE_MJCzB.js";import{n as v,o as P,q as D,f as j,s as E,t as N,u as A}from"../packem_chunks/cli-main.js";import{c as R}from"./formatBytes-BHAzNIrn-Bkk_uRS-.js";import{v as x,U as y,e as B,a as H}from"./index-DHD8wb6Z.js";import{a as q,b as C,e as U}from"./ai-analysis-DSQQDFU9.js";let I;const F=e=>(I??=T(import.meta.url))(e),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,O=e=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[t,n]=h.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return h.getBuiltinModule(e)}return F(e)},{readFile:L,writeFile:M}=O("node:fs/promises"),k=32*1024,W=(e,t)=>{if(e.length<=t)return e;const n=e.slice(-t),o=e.length-n.length;return`[…${String(o)} bytes truncated from head…]
1
+ import{createRequire as T}from"node:module";import{readLastRunSummary as _}from"@visulima/task-runner";import{a as $}from"./failure-log-3R522Vb5.js";import{n as v,o as P,q as D,f as j,s as E,t as N,u as A}from"../packem_chunks/cli-main.js";import{c as R}from"./formatBytes-BHAzNIrn-XohRrPdt.js";import{v as x,U as y,e as B,a as H}from"./index-DHD8wb6Z.js";import{a as q,b as C,e as U}from"./ai-analysis-DSQQDFU9.js";let I;const F=e=>(I??=T(import.meta.url))(e),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,O=e=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[t,n]=h.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return h.getBuiltinModule(e)}return F(e)},{readFile:L,writeFile:M}=O("node:fs/promises"),k=32*1024,W=(e,t)=>{if(e.length<=t)return e;const n=e.slice(-t),o=e.length-n.length;return`[…${String(o)} bytes truncated from head…]
2
2
  ${n}`},J=async(e,t)=>t===void 0?_(e,{dataDirectory:R(e)}):j(e,t),pe=async(e,t,n={})=>{const o=n.terminalOutputLimit??k,[r,i]=await Promise.all([$(e,t),J(e,n.runId)]),s=i?v(i,t):void 0;if(!r&&!s)return;let a,c;if(i&&s){const u=await P(e,i.id),f=u?v(u,t):void 0;a=D(s.hashDetails,f?.hashDetails),c=u?.id}const d=r?.terminalOutput??"";return{command:r?.command??void 0,cwd:r?.cwd??void 0,dependencies:s?.dependencies??[],duration:s?.duration,exitCode:r?.exitCode??s?.exitCode,hash:s?.hash??r?.hash,hashDetails:s?.hashDetails,hashDiff:a,previousRunId:c,project:s?.target.project,runId:i?.id??r?.runId,status:r?.status??(s?K(s):void 0),target:s?.target.target,taskId:t,terminalOutput:W(d,o),terminalOutputCaptured:!!r,timestamp:r?.timestamp??s?.endTime??s?.startTime}},K=e=>{if(e.exitCode!==void 0&&e.exitCode!==0)return"failure";switch(e.cacheStatus){case"HIT":return"local-cache";case"REMOTE_HIT":return"remote-cache";case"SKIPPED":return"skipped";default:return e.exitCode===0?"success":void 0}},Y=3600*1e3,w=80,V=new Set(["high","low","medium"]),X=()=>`You are an expert software engineer helping fix a failing build/test/lint task.
3
3
 
4
4
  You will be given:
@@ -1 +1 @@
1
- import{createRequire as v}from"node:module";import{t as T}from"./compile-cache-DoMHRsRZ.js";import{l as w,i as R,a as j,b as M,c as m,g as S}from"./package-version-BouRuXiK.js";import{i as $}from"./index-BjdW45xX.js";let _;const x=s=>(_??=v(import.meta.url))(s),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,b=s=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[e,o]=t.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return t.getBuiltinModule(s)}return x(s)},{createRequire:y}=b("node:module");let N;const O=s=>(N??=y(import.meta.url))(s),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=s=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[e,o]=r.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return r.getBuiltinModule(s)}return O(s)},{execFileSync:C}=f("node:child_process"),{totalmem:I}=f("node:os"),q=/--max-old-space-size=(\d+)/,z=/--max-semi-space-size=(\d+)/,E=s=>Math.floor(I()/1024/1024*s),P=s=>s<=512?4:s<=1024?8:s<=2048?16:s<=4096?32:s<=8192?64:Math.floor(Math.log2(s))*8,d=(s,e)=>{for(const o of e){const n=s.exec(o);if(n)return Number.parseInt(n[1],10)}},B=s=>{const o=[...w()],n=[...R()],a=d(q,o),p=d(z,o);if(a!==void 0&&p!==void 0)return;const l=a??E(.75),g=p??P(l),c=[];if(a===void 0&&c.push(`--max-old-space-size=${String(l)}`),p===void 0&&c.push(`--max-semi-space-size=${String(g)}`),c.length!==0)try{C(j(),[...c,...o,...n.slice(1)],{env:M(),stdio:"inherit"}),m(0)}catch(h){const u=h.status;m(typeof u=="number"?u:1)}},V=()=>{process.env.VIS_VERSION=S()},H=s=>{!process.stdout.isTTY||$||process.env.TERM==="dumb"||process.stdout.write(`\x1B]0;${s}\x07`)},L=new Set(["","--help","--version","-h","-v","completion","dlx","exec","x"]),i=process.argv[2]??"";!L.has(i)&&!process.argv.includes("--help")&&!process.argv.includes("-h")&&B();process.argv.includes("--no-color")&&(process.env.NO_COLOR="1",process.env.FORCE_COLOR="0");V();T();(async()=>{if(i==="__pm-shim"){const{dispatchShim:e}=await import("../packem_chunks/dispatch.js");e(process.argv[3]??"",process.argv.slice(4));return}if(i==="x"){const{runLeanX:e}=await import("../packem_chunks/lean.js");await e(process.argv.slice(3));return}if(i==="exec"||i==="dlx"){const{runExecCli:e}=await import("../packem_chunks/cli-exec.js");await e();return}const{runCli:s}=await import("../packem_chunks/cli-main.js").then(e=>e.ax);await s()})();export{H as s};
1
+ import{createRequire as v}from"node:module";import{t as T}from"./compile-cache-DoMHRsRZ.js";import{l as w,i as R,a as j,b as M,c as m,g as S}from"./package-version-DFlytdgJ.js";import{i as $}from"./index-BjdW45xX.js";let _;const x=s=>(_??=v(import.meta.url))(s),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,b=s=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[e,o]=t.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return t.getBuiltinModule(s)}return x(s)},{createRequire:y}=b("node:module");let N;const O=s=>(N??=y(import.meta.url))(s),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=s=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[e,o]=r.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return r.getBuiltinModule(s)}return O(s)},{execFileSync:C}=f("node:child_process"),{totalmem:I}=f("node:os"),q=/--max-old-space-size=(\d+)/,z=/--max-semi-space-size=(\d+)/,E=s=>Math.floor(I()/1024/1024*s),P=s=>s<=512?4:s<=1024?8:s<=2048?16:s<=4096?32:s<=8192?64:Math.floor(Math.log2(s))*8,d=(s,e)=>{for(const o of e){const n=s.exec(o);if(n)return Number.parseInt(n[1],10)}},B=s=>{const o=[...w()],n=[...R()],a=d(q,o),p=d(z,o);if(a!==void 0&&p!==void 0)return;const l=a??E(.75),g=p??P(l),c=[];if(a===void 0&&c.push(`--max-old-space-size=${String(l)}`),p===void 0&&c.push(`--max-semi-space-size=${String(g)}`),c.length!==0)try{C(j(),[...c,...o,...n.slice(1)],{env:M(),stdio:"inherit"}),m(0)}catch(h){const u=h.status;m(typeof u=="number"?u:1)}},V=()=>{process.env.VIS_VERSION=S()},H=s=>{!process.stdout.isTTY||$||process.env.TERM==="dumb"||process.stdout.write(`\x1B]0;${s}\x07`)},L=new Set(["","--help","--version","-h","-v","completion","dlx","exec","x"]),i=process.argv[2]??"";!L.has(i)&&!process.argv.includes("--help")&&!process.argv.includes("-h")&&B();process.argv.includes("--no-color")&&(process.env.NO_COLOR="1",process.env.FORCE_COLOR="0");V();T();(async()=>{if(i==="__pm-shim"){const{dispatchShim:e}=await import("../packem_chunks/dispatch.js");e(process.argv[3]??"",process.argv.slice(4));return}if(i==="x"){const{runLeanX:e}=await import("../packem_chunks/lean.js");await e(process.argv.slice(3));return}if(i==="exec"||i==="dlx"){const{runExecCli:e}=await import("../packem_chunks/cli-exec.js");await e();return}const{runCli:s}=await import("../packem_chunks/cli-main.js").then(e=>e.ax);await s()})();export{H as s};
@@ -1,2 +1,2 @@
1
- import{createRequire as p}from"node:module";import{e as j}from"./index-DHD8wb6Z.js";import{a as F}from"./formatBytes-BHAzNIrn-Bkk_uRS-.js";let h;const m=t=>(h??=p(import.meta.url))(t),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,c=t=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[e,r]=s.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return s.getBuiltinModule(t)}return m(t)},{mkdirSync:f,writeFileSync:y,readdirSync:g}=c("node:fs"),{readFile:_}=c("node:fs/promises"),i=t=>F(t),a=(t,e)=>j(i(t),`${encodeURIComponent(e)}.json`);class R{#e;#t;constructor(e,r){this.#e=e,this.#t=r}printTaskTerminalOutput(e,r,o){if(r!=="failure")return;const n=i(this.#e);try{f(n,{recursive:!0})}catch{return}const u=e.overrides.command,d=e.projectRoot,l={command:u,cwd:d,exitCode:void 0,hash:e.hash,runId:this.#t,status:r,taskId:e.id,terminalOutput:o,timestamp:new Date().toISOString()};try{y(a(this.#e,e.id),`${JSON.stringify(l,void 0,2)}
1
+ import{createRequire as p}from"node:module";import{e as j}from"./index-DHD8wb6Z.js";import{a as F}from"./formatBytes-BHAzNIrn-XohRrPdt.js";let h;const m=t=>(h??=p(import.meta.url))(t),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,c=t=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[e,r]=s.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return s.getBuiltinModule(t)}return m(t)},{mkdirSync:f,writeFileSync:y,readdirSync:g}=c("node:fs"),{readFile:_}=c("node:fs/promises"),i=t=>F(t),a=(t,e)=>j(i(t),`${encodeURIComponent(e)}.json`);class R{#e;#t;constructor(e,r){this.#e=e,this.#t=r}printTaskTerminalOutput(e,r,o){if(r!=="failure")return;const n=i(this.#e);try{f(n,{recursive:!0})}catch{return}const u=e.overrides.command,d=e.projectRoot,l={command:u,cwd:d,exitCode:void 0,hash:e.hash,runId:this.#t,status:r,taskId:e.id,terminalOutput:o,timestamp:new Date().toISOString()};try{y(a(this.#e,e.id),`${JSON.stringify(l,void 0,2)}
2
2
  `,"utf8")}catch{}}}const S=async(t,e)=>{const r=a(t,e);try{const o=await _(r,"utf8");return JSON.parse(o)}catch{return}},w=t=>{const e=i(t);let r;try{r=g(e)}catch{return[]}const o=[];for(const n of r)if(n.endsWith(".json"))try{o.push(decodeURIComponent(n.slice(0,-5)))}catch{}return o};export{R as F,S as a,w as l};
@@ -0,0 +1,4 @@
1
+ import{createRequire as st}from"node:module";import{e as f}from"./index-DHD8wb6Z.js";import{y as G}from"./isAccessibleSync-DYKTrrvc-CSnBISfV.js";import{p as ht}from"./readJsonSync-CbryXYxN-B2aSeDpC.js";import{h as dt}from"./writeFileSync-DJoHk3Ks-CgQ-VNNT.js";let nt;const ot=t=>(nt??=st(import.meta.url))(t),x=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=t=>{if(typeof x<"u"&&x.versions&&x.versions.node){const[s,e]=x.versions.node.split(".").map(Number);if(s>22||s===22&&e>=3||s===20&&e>=16)return x.getBuiltinModule(t)}return ot(t)},{existsSync:it,readdirSync:z,statSync:rt,rmSync:Y,writeFileSync:at}=R("node:fs"),{spawn:F}=R("node:child_process"),{createHash:ct}=R("node:crypto"),{homedir:lt,platform:ut}=R("node:os"),pt=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],ft=12288,gt=65510,mt=[12288,12288,65281,65376,65504,65510],wt=8361,bt=65518,yt=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],St=32,Et=10630,xt=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],$t=4352,Mt=262141,V=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141],$=(t,s)=>{let e=0,n=Math.floor(t.length/2)-1;for(;e<=n;){const r=Math.floor((e+n)/2),c=r*2;if(s<t[c])n=r-1;else if(s>t[c+1])e=r+1;else return!0}return!1},D=19968,[Bt,kt]=vt(V);function vt(t){let s=t[0],e=t[1];for(let n=0;n<t.length;n+=2){const r=t[n],c=t[n+1];if(D>=r&&D<=c)return[r,c];c-r>e-s&&(s=r,e=c)}return[s,e]}const Tt=t=>t<161||t>1114109?!1:$(pt,t),It=t=>t<ft||t>gt?!1:$(mt,t),Rt=t=>t<wt||t>bt?!1:$(yt,t),Wt=t=>t<St||t>Et?!1:$(xt,t),_t=t=>t>=Bt&&t<=kt?!0:t<$t||t>Mt?!1:$(V,t);function Ct(t){return Tt(t)?"ambiguous":It(t)?"fullwidth":Rt(t)?"halfwidth":Wt(t)?"narrow":_t(t)?"wide":"neutral"}function Nt(t){if(!Number.isSafeInteger(t))throw new TypeError(`Expected a code point, got \`${typeof t}\`.`)}function Z(t){return Nt(t),Ct(t)}const H=String.raw,j=H`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,At=()=>new RegExp(H`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${j}(?:\u200D${j})*`,"gu"),he=new Set(["\x1B","›"]),de="\x07",pe="]8;;",fe=/[\u200B\uFEFF\u2060-\u2064]/g,U=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\)|\][^\u0007\u001B]{0,1000}(?:\u0007|\u001B\\))/g,ge=/\u001B\[[\d;]*m[^\u001B]*(?:\u001B\[[\d;]*m|$)/g,me=/\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)[^\u001B]*\u001B\]8;;(?:\u0007|\u001B\\)/g,v=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,q=At(),we=/[-_./\s]+/g,be=/(\u001B\[[0-9;]*[a-z])/i,ye=new RegExp("\\p{Script=Arabic}","u"),Se=new RegExp("\\p{Script=Bengali}","u"),Ee=new RegExp("\\p{Script=Cyrillic}","u"),xe=new RegExp("\\p{Script=Devanagari}","u"),$e=new RegExp("\\p{Script=Ethiopic}","u"),Me=new RegExp("\\p{Script=Greek}","u"),Be=new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+","gu"),ke=new RegExp("\\p{Script=Gujarati}","u"),ve=new RegExp("\\p{Script=Gurmukhi}","u"),Te=new RegExp("\\p{Script=Hangul}","u"),Ie=new RegExp("\\p{Script=Hebrew}","u"),Re=new RegExp("\\p{Script=Hiragana}","u"),We=new RegExp("\\p{Script=Han}","u"),_e=new RegExp("\\p{Script=Kannada}","u"),Ce=new RegExp("\\p{Script=Katakana}","u"),Ne=new RegExp("\\p{Script=Khmer}","u"),Ae=new RegExp("\\p{Script=Lao}","u"),Fe=new RegExp("\\p{Script=Latin}","u"),De=new RegExp("\\p{Script=Malayalam}","u"),je=new RegExp("\\p{Script=Myanmar}","u"),Oe=new RegExp("\\p{Script=Oriya}","u"),Pe=new RegExp("\\p{Script=Sinhala}","u"),Ke=new RegExp("\\p{Script=Tamil}","u"),Le=new RegExp("\\p{Script=Telugu}","u"),ze=new RegExp("\\p{Script=Thai}","u"),Ye=new RegExp("\\p{Script=Tibetan}","u"),Ge=/[\u02BB\u02BC\u0027]/u,Ve=t=>t.replace(q,""),O=new Map,Ft=t=>[t.ambiguousIsNarrow?1:0,t.control,t.fullWidth,t.regular,t.wide].join("|"),Dt=t=>{const s=Ft(t.width);let e=O.get(s);return e||(e=new Map,O.set(s,e)),e},T=new RegExp(U.source,"y"),_=new RegExp(q.source,"uy"),I=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,J=t=>t>=32&&t<=126?"latin":t===8203||t===8204||t===8205||t===8288?"zero":t<=31||t>=127&&t<=159?"control":t>=160&&t<=255||t>=9472&&t<=9599?"latin":t>=4352&&t<=4607||t>=11904&&t<=40959||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65519&&!(t>=65377&&t<=65439)||t>=12352&&t<=12543?"wide":t===8230?"latin":"other",jt=(t,s)=>{const e=Dt(s),n=Math.floor(t/65536),r=t%65536;let c=e.get(n);if(c||(c=new Map,e.set(n,c)),c.has(r))return c.get(r);let o;switch(J(t)){case"control":{o=s.width.control;break}case"latin":{o=s.width.regular;break}case"wide":{o=s.width.wide;break}case"zero":{o=0;break}default:switch(Z(t)){case"ambiguous":{o=s.width.ambiguousIsNarrow?s.width.regular:s.width.wide;break}case"fullwidth":{o=s.width.fullWidth;break}case"wide":{o=s.width.wide;break}default:o=s.width.regular}}return c.set(r,o),o},Ot=t=>t>=768&&t<=879||t>=6832&&t<=6911||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65056&&t<=65071||t>=917760&&t<=917999||t>=65024&&t<=65039||t>=3633&&t<=3642||t>=3655&&t<=3662||t>=3761&&t<=3769||t>=3771&&t<=3772||t>=3784&&t<=3789||t>=2304&&t<=2307||t>=2362&&t<=2383||t>=2385&&t<=2391||t>=2402&&t<=2403||t>=2433&&t<=2435||t>=2492&&t<=2500||t>=2509&&t<=2509||t>=2561&&t<=2563||t>=2620&&t<=2637||t>=1611&&t<=1631||t>=1648&&t<=1648||t>=1750&&t<=1773||t>=2276&&t<=2302||t>=1425&&t<=1469||t>=1471&&t<=1471||t>=1473&&t<=1474||t>=1476&&t<=1477||t>=1479&&t<=1479||t>=3893&&t<=3893||t>=3895&&t<=3895||t>=3897&&t<=3897||t>=3953&&t<=3966||t>=3968&&t<=3972||t>=3974&&t<=3975?!0:t>=768&&t<=777||t>=803&&t<=803,C=(t,s={})=>{if(!t||t.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const e={truncation:{countAnsiEscapeCodes:s.countAnsiEscapeCodes??!1,ellipsis:s.ellipsis??"",ellipsisWidth:s.ellipsisWidth??(s.ellipsis?C(s.ellipsis,{...s,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:s.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:s.ambiguousIsNarrow??!1,ansi:s.ansiWidth??0,control:s.controlWidth??0,emoji:s.emojiWidth??2,fullWidth:s.fullWidth??2,halfWidth:s.halfWidth??1,regular:s.regularWidth??1,tab:s.tabWidth??8,wide:s.wideWidth??2}},n=Math.max(0,e.truncation.limit-e.truncation.ellipsisWidth),{length:r}=t,c=r>1e4;let o=0,i=0,a=r,l=!1;const p=t.includes("\x1B")||t.includes("›");for(;o<r;){if(p&&(t[o]==="\x1B"||t[o]==="›")){if(t.startsWith("\x1B]8;;",o)){const d="\x1B]8;;\x07",w=d.length,y=t.indexOf("\x07",o+5);if(y!==-1){const S=t.indexOf(d,y+1);if(S!==-1){const B=S+w,W=t.slice(y+1,S).replace(U,""),k=C(W,{ambiguousIsNarrow:e.width.ambiguousIsNarrow,ansiWidth:e.width.ansi,controlWidth:e.width.control,countAnsiEscapeCodes:!1,ellipsis:e.truncation.ellipsis,ellipsisWidth:e.truncation.ellipsisWidth,emojiWidth:e.width.emoji,fullWidth:e.width.fullWidth,halfWidth:e.width.halfWidth,limit:Math.max(0,n-i),regularWidth:e.width.regular,tabWidth:e.width.tab,wideWidth:e.width.wide}),E=k.width;if(k.truncated)l=!0,a=Math.min(a,o);else if(i+E>n&&(a=Math.min(a,o),l=!0,i+E>e.truncation.limit))break;if(i+=E,o=B,l&&i>=e.truncation.limit)break;continue}}}if(T.lastIndex=o,T.test(t)){const d=T.lastIndex-o,w=e.truncation.countAnsiEscapeCodes?d:e.width.ansi;if(i+w>n&&(a=Math.min(a,o),i+w>e.truncation.limit)){l=!0;break}i+=w,o=T.lastIndex;continue}}const u=t.codePointAt(o);if(u===8203||u===65279||u>=8288&&u<=8292){o+=1;continue}if(u===9){if(i+e.width.tab>n&&(a=Math.min(a,o),i+e.width.tab>e.truncation.limit)){l=!0;break}i+=e.width.tab,o+=1;continue}if(I.lastIndex=o,I.test(t)){const d=(I.lastIndex-o)*e.width.regular;if(i+d>n){const w=e.width.regular>0?Math.floor((n-i)/e.width.regular):0;if(a=Math.min(a,o+w),i+d>e.truncation.limit){l=!0;break}}i+=d,o=I.lastIndex;continue}if((u<=31||u>=127&&u<=159)&&(v.lastIndex=o,v.test(t))){const d=(v.lastIndex-o)*e.width.control;if(i+d>n){const w=e.width.control>0?Math.floor((n-i)/e.width.control):0;if(a=Math.min(a,o+w),i+d>e.truncation.limit){l=!0;break}}i+=d,o=v.lastIndex;continue}if(_.lastIndex=o,_.test(t)){if(i+e.width.emoji>n&&(a=Math.min(a,o),i+e.width.emoji>e.truncation.limit)){l=!0;break}i+=e.width.emoji,o=_.lastIndex;continue}const m=t.codePointAt(o)??0;if(Ot(m)){o+=m>65535?2:1;continue}let h;if(c)h=jt(m,e);else switch(J(m)){case"control":{h=e.width.control;break}case"latin":{h=e.width.regular;break}case"wide":{h=e.width.wide;break}case"zero":{h=0;break}default:switch(Z(m)){case"ambiguous":{h=e.width.ambiguousIsNarrow?e.width.regular:e.width.wide;break}case"fullwidth":{h=e.width.fullWidth;break}case"wide":{h=e.width.wide;break}default:h=e.width.regular}}if(i+h>n&&(a=Math.min(a,o),i+h>e.truncation.limit)){l=!0;break}i+=h,o+=m>65535?2:1}let g=i,b=!1;return l&&e.truncation.limit>=e.truncation.ellipsisWidth&&(g=e.truncation.limit,b=!0),{ellipsed:b,index:l?a:r,truncated:l,width:g}},Ze=(t,s={})=>C(t,{...s,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,N=()=>f(lt(),".vis"),Pt=()=>f(N(),"cache"),He=()=>f(N(),"state"),Kt=t=>ct("sha256").update(t).digest("hex").slice(0,12),Ue=t=>f(N(),"workspaces",Kt(t)),Lt=".vis",A=t=>f(t,Lt),qe="node_modules/.cache/vis",Je=t=>f(A(t),"runs"),Xe=t=>f(A(t),"last-summary.json"),Qe=t=>f(A(t),"last-failures"),ts=t=>{const s=ut()==="win32";for(const e of[".task-runner",".task-runner-cache"]){const n=f(t,e);if(it(n))try{const r=s?F("cmd.exe",["/c","rmdir","/s","/q",n],{detached:!0,stdio:"ignore"}):F("rm",["-rf",n],{detached:!0,stdio:"ignore"});r.on("error",()=>{}),r.unref()}catch{}}},zt="https://api.socket.dev/v0/purl?alerts=true",M=()=>f(Pt(),"socket-security"),Yt=3600*1e3,X=.4,P=100,Gt=t=>typeof t=="object"&&t!==null&&"id"in t&&"type"in t&&"name"in t&&"version"in t&&"alerts"in t&&"score"in t&&t.type==="npm",Vt=()=>{dt(M())},Q=(t,s)=>`${encodeURIComponent(t)}@${encodeURIComponent(s)}`,Zt=(t,s)=>{const e=Q(t,s),n=f(M(),`${e}.json`);try{const r=ht(n);if(Date.now()-r.createdAt>r.ttlMs){Y(n,{force:!0});return}return r.report}catch{return}},Ht=(t,s,e,n)=>{const r=Q(t,s),c={createdAt:Date.now(),report:e,ttlMs:n};at(f(M(),`${r}.json`),JSON.stringify(c),"utf8")},Ut=t=>{const s=[t.license,t.maintenance,t.quality,t.supplyChain,t.vulnerability];return Number((s.reduce((e,n)=>e+n,0)/s.length).toFixed(2))},qt=async(t,s={})=>{const{apiToken:e,cacheTtlMs:n=Yt,timeoutMs:r=15e3}=s,c=new Map;if(t.length===0||!e)return c;const o=[];for(const l of t){const p=Zt(l.name,l.version);p?c.set(`${l.name}@${l.version}`,p):o.push(l)}if(o.length===0)return c;const i=`Basic ${Buffer.from(`${e}:`).toString("base64")}`;Vt();const a=[];for(let l=0;l<o.length;l+=P)a.push(o.slice(l,l+P));for(const l of a){const p=l.map(u=>({purl:`pkg:npm/${u.name}@${u.version}`})),g=new AbortController,b=setTimeout(()=>{g.abort()},r);try{const u=await fetch(zt,{body:JSON.stringify({components:p}),headers:{Authorization:i,"Content-Type":"application/json","User-Agent":"@visulima/vis"},method:"POST",signal:g.signal});if(!u.ok)continue;const m=await u.text();Jt(m,l,c,n)}catch{}finally{clearTimeout(b)}}return c},Jt=(t,s,e,n)=>{const r=new Map;for(const o of s)r.set(`${o.name}@${o.version}`,o);const c=t.split(`}
2
+ `);for(const o of c){const i=o.trim();if(i)try{const a=JSON.parse(i.endsWith("}")?i:`${i}}`),p=`${a.namespace?`${a.namespace}/`:""}${a.name}`,g=`${p}@${a.version}`;if(!r.has(g))continue;const b=a.score.overall??Ut(a.score),u={alerts:a.alerts,author:a.author,id:a.id,license:a.license,name:a.name,score:{...a.score,overall:b},size:a.size,type:"npm",version:a.version};a.namespace&&(u.namespace=a.namespace),Gt(u)&&(e.set(g,u),Ht(p,a.version,u,n))}catch{}}},Xt=t=>t.namespace?`${t.namespace}/${t.name}`:t.name,es=t=>t>=.8?"excellent":t>=.6?"good":t>=.4?"fair":t>=.2?"poor":"critical",ss=t=>t>=.6?"green":t>=.4?"yellow":"red",ns=t=>{const s=Xt(t),e=`score: ${String(Math.round(t.score.overall*100))}%`,n=t.alerts.length,r=n>0?`${String(n)} alert${n===1?"":"s"}`:"no alerts";return`${s}@${t.version} (${e}, ${r})`},os=(t,s=X)=>{if(t.size===0)return"";let e=0,n=0,r=0,c=0,o=0,i=0;for(const l of t.values()){for(const p of l.alerts)switch(e++,p.severity){case"critical":{n++;break}case"high":{r++;break}case"medium":{c++;break}default:o++}l.score.overall<s&&i++}const a=[`Socket.dev: scanned ${String(t.size)} package${t.size===1?"":"s"}`];if(e>0){const l=[];n>0&&l.push(`${String(n)} critical`),r>0&&l.push(`${String(r)} high`),c>0&&l.push(`${String(c)} medium`),o>0&&l.push(`${String(o)} low`),a.push(` Alerts: ${String(e)} total (${l.join(", ")})`)}else a.push(" No security alerts found.");if(i>0){const l=Math.round(s*100);a.push(` ${String(i)} package${i===1?"":"s"} with low security score (<${String(l)}%)`)}return a.join(`
3
+ `)},Qt=()=>{const t=M();if(!G(t))return 0;const s=z(t).filter(e=>e.endsWith(".json"));for(const e of s)Y(f(t,e),{force:!0});return s.length},te=()=>{const t=M();if(!G(t))return{entries:0,newestEntry:void 0,oldestEntry:void 0,totalSizeBytes:0};const s=z(t).filter(c=>c.endsWith(".json"));let e=0,n,r;for(const c of s){const o=rt(f(t,c));e+=o.size;const{mtimeMs:i}=o;(n===void 0||i<n)&&(n=i),(r===void 0||i>r)&&(r=i)}return{entries:s.length,newestEntry:r,oldestEntry:n,totalSizeBytes:e}},ee=(t,s)=>t?.enabled?{apiToken:t.apiToken??process.env.VIS_SOCKET_TOKEN,cacheTtlMs:t.cacheTtlMs,minimumScore:s??X,timeoutMs:t.timeoutMs}:void 0,is=(t,s,e,n)=>{if(!e)return;const r=Date.now(),c=i=>{if(i.expiresAt){const a=Date.parse(i.expiresAt);if(!Number.isNaN(a)&&a<r)return!1}return!(n&&i.policies&&!i.policies.includes(n))},o=`${t}@${s}`;if(e[o]&&c(e[o]))return e[o];if(e[t]&&c(e[t]))return e[t];for(const[i,a]of Object.entries(e))if(i.endsWith("*")&&t.startsWith(i.slice(0,-1))&&c(a))return a},rs=(t,s,e,n)=>[" // Add to security.acceptedRisks in vis.config.ts:",` ${`"${t}"`}: {`,` reason: "${n}",`,` acceptedAt: "${new Date().toISOString()}",`,` acceptedScore: ${String(e)},`,' policies: ["score"],'," },"].join(`
4
+ `),as=(t,s={})=>{const e=ee(t,s.minimumScore);if(e)return{clearCache:Qt,displayName:"Socket.dev",fetchReports:n=>qt(n,e),getCacheStats:te,id:"socket"}},cs=t=>{if(t===void 0)return!1;const s=t.trim().toLowerCase();return s!==""&&s!=="0"&&s!=="false"&&s!=="no"},tt={iec:[{long:"Bytes",short:"B"},{long:"Kibibytes",short:"KiB"},{long:"Mebibytes",short:"MiB"},{long:"Gibibytes",short:"GiB"},{long:"Tebibytes",short:"TiB"},{long:"Pebibytes",short:"PiB"},{long:"Exbibytes",short:"EiB"},{long:"Zebibytes",short:"ZiB"},{long:"Yobibytes",short:"YiB"}],iec_octet:[{long:"Octets",short:"o"},{long:"Kibioctets",short:"Kio"},{long:"Mebioctets",short:"Mio"},{long:"Gibioctets",short:"Gio"},{long:"Tebioctets",short:"Tio"},{long:"Pebioctets",short:"Pio"},{long:"Exbioctets",short:"Eio"},{long:"Zebioctets",short:"Zio"},{long:"Yobioctets",short:"Yio"}],metric:[{long:"Bytes",short:"Bytes"},{long:"Kilobytes",short:"KB"},{long:"Megabytes",short:"MB"},{long:"Gigabytes",short:"GB"},{long:"Terabytes",short:"TB"},{long:"Petabytes",short:"PB"},{long:"Exabytes",short:"EB"},{long:"Zettabytes",short:"ZB"},{long:"Yottabytes",short:"YB"}],metric_octet:[{long:"Octets",short:"o"},{long:"Kilo-octets",short:"ko"},{long:"Mega-octets",short:"Mo"},{long:"Giga-octets",short:"Go"},{long:"Tera-octets",short:"To"},{long:"Peta-octets",short:"Po"},{long:"Exa-octets",short:"Eo"},{long:"Zetta-octets",short:"Zo"},{long:"Yotta-octets",short:"Yo"}]},se=[{long:"bits",short:"bit"},{long:"Kilobits",short:"kbit"},{long:"Megabits",short:"Mbit"},{long:"Gigabits",short:"Gbit"},{long:"Terabits",short:"Tbit"},{long:"Petabits",short:"Pbit"},{long:"Exabits",short:"Ebit"},{long:"Zettabits",short:"Zbit"},{long:"Yottabits",short:"Ybit"}],K=new Map,L=(t,s)=>{const e=`${t}\0${JSON.stringify(s)}`;let n=K.get(e);return n===void 0&&(n=new Intl.NumberFormat(t,s),K.set(e,n)),n},ne=t=>{switch(t){case 2:return 1024;case 10:return 1e3;default:throw new Error("Unsupported base.")}},oe=(t,s,e)=>({maximumFractionDigits:t,minimumFractionDigits:t,...s,...e}),ie=(t,s,e,n)=>{if(t===void 0)return-1;const r=s.findIndex(c=>c.short===t);return r===-1&&n?tt[e].findIndex(c=>c.short===t):r},ls=(t,s)=>{if(typeof t!="number"||!Number.isFinite(t))throw new TypeError("Bytesize is not a number.");const{base:e,bits:n,decimals:r,locale:c,long:o,signed:i,unit:a,units:l,...p}={base:2,bits:!1,decimals:0,locale:"en-US",long:!1,signed:!1,units:"metric",...s},g=ne(e),b=n?t*8:t,u=Math.abs(b),m=s?.space??!0?" ":"",h=n?se:tt[l],d=ie(a,h,l,n),w=r<0?void 0:r,y=i?{signDisplay:"exceptZero"}:{};if(b===0){const E=d===-1?0:Math.min(d,h.length-1),et=h[E][o?"long":"short"];return L(c,{...y,...p}).format(0)+m+et}const S=Math.max(0,Math.min(Math.floor(Math.log(u)/Math.log(g)),h.length-1)),B=d===-1?S:d,W=h[B][o?"long":"short"],k=b/g**B;return L(c,oe(w,y,p)).format(k)+m+W};export{ls as $,Ae as A,Ee as B,ve as C,X as D,je as E,Te as F,$e as G,xe as H,Ne as I,ze as J,Be as K,we as L,ke as M,Oe as N,Me as O,_e as P,ts as Q,q as R,ge as S,be as T,Fe as U,Ye as V,Ce as W,me as X,De as Y,Ge as Z,U as _,Qe as a,C as a0,It as a1,_t as a2,fe as a3,he as a4,pe as a5,de as a6,as as a7,os as a8,qe as a9,te as aa,Qt as ab,Xe as ac,N as b,A as c,Je as d,Xt as e,is as f,Pt as g,ns as h,es as i,rs as j,cs as k,He as l,Ut as m,qt as n,Ze as o,Ue as p,Ve as q,We as r,ss as s,Re as t,Ie as u,Ke as v,Se as w,ye as x,Le as y,Pe as z};
@@ -1 +1 @@
1
- import{m as k,D as S,f as L}from"./provenance-w-NIPtim.js";import{g as $}from"./packument-CHdDsn0O.js";import{f}from"./formatBytes-BHAzNIrn-Bkk_uRS-.js";import{a as E}from"./build-scripts-pdVmqXRm.js";import{n as h}from"./license-DvlYdo6T.js";import{v as A,U as P,z as x}from"./index-DHD8wb6Z.js";import{S as O}from"./lockfile-DhHAaHN5.js";import{L as b}from"./dependency-scan-DBH2Qo4I.js";const C=2,m=4,y={CRITICAL:0,HIGH:1,LOW:3,MODERATE:C,UNKNOWN:m},ae=(s,e)=>{const n=y[(s.vulnerability.severity??"UNKNOWN").toUpperCase()]??m,t=y[(e.vulnerability.severity??"UNKNOWN").toUpperCase()]??m;return n-t||s.packageName.localeCompare(e.packageName)||s.packageVersion.localeCompare(e.packageVersion)},M=(s,e)=>{const n=y[e.toUpperCase()]??C;return(y[s.toUpperCase()]??m)<=n},R=["firstSeen","installScripts","license","malware","publisherChange","score","unexpectedDeps","vulnerability"],w=6e4,D=(s,e,n)=>{for(const t of n)if(t===s||t===`${s}@${e}`||t.endsWith("*")&&s.startsWith(t.slice(0,-1)))return!0;return!1},W=async(s,e)=>{const n=e.security?.policies?.firstSeen;if(n?.minutes===void 0||n.minutes<=0)return[];const{minutes:t}=n,r=n.exclude??[],a=e.security?.acceptedRisks,c=t*w,o=Date.now();return(await k(s.packages,S,async l=>{if(D(l.name,l.version,r))return;const p=await $(l.name,{workspaceRoot:s.workspaceRoot});if(p===void 0)return;const u=p.time?.[l.version];if(u===void 0)return;const d=Date.parse(u);if(Number.isNaN(d))return;const v=o-d;if(v>=c)return;const g=Math.max(0,Math.floor(v/w));return{acceptedRisk:f(l.name,l.version,a,"firstSeen"),data:{ageMinutes:g,minimumMinutes:t,publishedAt:u},packageName:l.name,policy:"firstSeen",reason:`${l.name}@${l.version} was published ${String(g)} min ago — below the ${String(t)} min firstSeen cooldown.`,severity:"block",version:l.version}})).filter(l=>l!==void 0)},U=(s,e)=>{const n=e.security?.policies?.installScripts;if(!n)return[];const t=n.allow??{},r=n.strict===!0;if(!r&&Object.keys(t).length===0)return[];const a=E(s.workspaceRoot,t,{pinVersions:e.security?.pinVersions===!0});if(a.unapproved.length===0)return[];const c=e.security?.acceptedRisks,o=r?"block":"warn";return a.unapproved.map(i=>({acceptedRisk:f(i.name,i.version??"*",c,"installScripts"),data:{hooks:i.hooks},packageName:i.name,policy:"installScripts",reason:`${i.name}${i.version?`@${i.version}`:""} declares unapproved build script(s): ${i.hooks.join(", ")}`,severity:o,version:i.version??"*"}))},_=new Set(["AND","OR"]),I=s=>{const e=s.replaceAll("("," ").replaceAll(")"," ").split(/\s+/).map(r=>r.trim()).filter(r=>r.length>0),n=[];let t=!1;for(const r of e){const a=r.toUpperCase();if(t){t=!1;continue}if(a==="WITH"){t=!0;continue}if(_.has(a))continue;const c=r.endsWith("+"),o=c?r.slice(0,-1):r,i=h(o)??o;n.push(i),c&&n.push(`${i}-or-later`)}return n},T=s=>{if(typeof s.license=="string"){const e=s.license.trim();return e.length>0?e:void 0}if(s.license&&typeof s.license=="object"&&typeof s.license.type=="string"){const e=s.license.type.trim();if(e.length>0)return e}if(Array.isArray(s.licenses)&&s.licenses.length>0){const e=s.licenses.map(n=>n&&typeof n.type=="string"?n.type.trim():"").filter(n=>n.length>0);if(e.length>0)return e.length===1?e[0]:`(${e.join(" OR ")})`}},V=(s,e)=>{if(e.length===0)return;const n=new Set(e.map(t=>h(t)??t).map(t=>t.toLowerCase()));for(const t of s)if(n.has(t.toLowerCase()))return t},F=(s,e)=>{if(e.length===0)return;const n=new Set(e.map(t=>h(t)??t).map(t=>t.toLowerCase()));for(const t of s)if(!n.has(t.toLowerCase()))return t},j=(s,e)=>{const n=e.security?.policies?.license;if(!n)return[];const t=n.allow??[],r=n.deny??[];if(t.length===0&&r.length===0)return[];const a=e.security?.acceptedRisks,c=[];for(const o of s.packages){const i=s.manifestData?.get(`${o.name}@${o.version}`),l=i?T(i):void 0;if(!l){t.length>0&&c.push({acceptedRisk:f(o.name,o.version,a,"license"),data:{declaredLicense:null},packageName:o.name,policy:"license",reason:`${o.name}@${o.version} declares no license; allow-list mode requires one of: ${t.join(", ")}`,severity:"block",version:o.version});continue}const p=I(l),u=V(p,r);if(u){c.push({acceptedRisk:f(o.name,o.version,a,"license"),data:{declaredLicense:l,deniedLicense:u},packageName:o.name,policy:"license",reason:`${o.name}@${o.version} uses denied license '${u}' (declared: ${l})`,severity:"block",version:o.version});continue}const d=F(p,t);d&&c.push({acceptedRisk:f(o.name,o.version,a,"license"),data:{allowList:t,declaredLicense:l,unallowedLicense:d},packageName:o.name,policy:"license",reason:`${o.name}@${o.version} uses license '${d}' which is not on the allow-list (declared: ${l})`,severity:"block",version:o.version})}return c},K=6e4,z=(s,e,n)=>{for(const t of n)if(t===s||t===`${s}@${e}`||t.endsWith("*")&&s.startsWith(t.slice(0,-1)))return!0;return!1},B=async(s,e)=>{const n=e.security?.policies?.publisherChange;if(n?.mode!=="no-downgrade")return[];const t=n.exclude??[],r=typeof n.ignoreAfter=="number"?n.ignoreAfter*K:void 0,a=e.security?.acceptedRisks,c=Date.now();return(await k(s.packages,S,async i=>{if(z(i.name,i.version,t))return;const l=await $(i.name,{workspaceRoot:s.workspaceRoot});if(l===void 0)return;if(r!==void 0){const d=l.time?.[i.version],v=d===void 0?Number.NaN:Date.parse(d);if(!Number.isNaN(v)&&c-v>r)return}if(l.versions[i.version]?.dist?.attestations?.provenance!==void 0)return;const u=L(l,i.version);if(u!==void 0)return{acceptedRisk:f(i.name,i.version,a,"publisherChange"),data:{priorVersionWithProvenance:u},packageName:i.name,policy:"publisherChange",reason:`${i.name}@${i.version} dropped the provenance attestation that ${i.name}@${u} carried — publisher trust downgrade.`,severity:"block",version:i.version}})).filter(i=>i!==void 0)},Y=s=>{for(const e of Object.values(b))for(const n of[e.file,...e.aliases??[]])if(s===n||s.endsWith(`/${n}`)||s.endsWith(`.${n}`))return e.type},H=(s,e,n)=>{const t=A(e)?e:P(s,e);let r;try{r=x(t)}catch{return}const a=Y(t)??b[n]?.type;if(!a)return;const c=O(r,a);if(c.length===0)return;const o=new Set;for(const i of c)o.add(`${i.name}@${i.version}`);return o},q=(s,e)=>{for(const n of e)if(n===s||n.endsWith("*")&&s.startsWith(n.slice(0,-1)))return!0;return!1},G=(s,e)=>{const n=e.security?.policies?.unexpectedDeps;if(!n)return[];const t=n.allow??[],r=n.baselineLockfile;if(t.length===0&&!r)return[];const a=r?H(s.workspaceRoot,r,s.packageManager):void 0,c=e.security?.acceptedRisks,o=[];for(const i of s.packages){const l=t.length===0||q(i.name,t),p=a?a.has(`${i.name}@${i.version}`):!0;if(l&&p)continue;const u=[],d={};l||(u.push(`not on allow-list (${t.length} entr${t.length===1?"y":"ies"})`),d.allowList=t),!p&&a&&(u.push(`not present in baseline lockfile (${r})`),d.baselineLockfile=r),o.push({acceptedRisk:f(i.name,i.version,c,"unexpectedDeps"),data:d,packageName:i.name,policy:"unexpectedDeps",reason:`${i.name}@${i.version} is unexpected: ${u.join("; ")}`,severity:"block",version:i.version})}return o},X=(s,e)=>{if(!s.osvFindings||s.osvFindings.size===0)return[];const t=e.security?.policies?.vulnerability?.failOn,r=e.security?.acceptedRisks,a=[];for(const c of s.packages){const o=s.osvFindings.get(c.name);if(!(!o||o.length===0))for(const i of o){const l=t?M(i.severity,t)?"block":"warn":"info";a.push({acceptedRisk:f(c.name,c.version,r,"vulnerability"),data:{advisoryId:i.id,aliases:i.aliases??[],cvssScore:i.cvssScore,fixedVersions:i.fixedVersions,severity:i.severity,summary:i.summary},packageName:c.name,policy:"vulnerability",reason:`${i.severity} ${i.id} affects ${c.name}@${c.version}: ${i.summary}`,severity:l,version:c.version})}}return a},N=[{evaluate:X,isConfigured:s=>s.security?.policies?.vulnerability!==void 0,name:"vulnerability",offlineSupported:!0,surfaces:["audit","doctor"]},{evaluate:j,isConfigured:s=>{const e=s.security?.policies?.license;return!!(e&&(e.allow&&e.allow.length>0||e.deny&&e.deny.length>0))},name:"license",offlineSupported:!0,surfaces:["audit","doctor","install"]},{evaluate:U,isConfigured:s=>{const e=s.security?.policies?.installScripts;return!!(e&&(e.allow&&Object.keys(e.allow).length>0||e.strict===!0))},name:"installScripts",offlineSupported:!0,surfaces:["audit","doctor","install"]},{evaluate:G,isConfigured:s=>{const e=s.security?.policies?.unexpectedDeps;return!!(e&&(e.allow&&e.allow.length>0||typeof e.baselineLockfile=="string"))},name:"unexpectedDeps",offlineSupported:!0,surfaces:["audit","doctor","install"]},{evaluate:W,isConfigured:s=>{const e=s.security?.policies?.firstSeen?.minutes;return typeof e=="number"&&e>0},name:"firstSeen",offlineSupported:!1,surfaces:["audit","doctor","install"]},{evaluate:B,isConfigured:s=>s.security?.policies?.publisherChange?.mode==="no-downgrade",name:"publisherChange",offlineSupported:!1,surfaces:["audit","doctor","install"]}],J=(s,e,n)=>N.filter(t=>t.surfaces.includes(s)?n!==void 0?n.has(t.name):t.isConfigured(e):!1),ce=async(s,e,n)=>{const t=J(e,n.visConfig,n.enabledPolicies),r=[];for(const a of t){if(s.offline&&!a.offlineSupported){r.push({packageName:"*",policy:a.name,reason:`policy.${a.name} skipped: requires network (--offline)`,severity:"info",version:"*"});continue}try{const c=await a.evaluate(s,n.visConfig);r.push(...c)}catch(c){const o=c instanceof Error?c.message:String(c);r.push({packageName:"*",policy:a.name,reason:`policy.${a.name} failed: ${o}`,severity:"info",version:"*"})}}return r},Q=(()=>{const s=new Map;for(const e of R)s.set(e.toLowerCase(),e);return s})(),le=()=>N.map(s=>s.name),ue=(s,e)=>{if(s===void 0)return;const n=s.trim().toLowerCase();if(n===""||n==="none")return new Set;if(n==="all")return new Set(R);const t=new Set;for(const r of s.split(",").map(a=>a.trim()).filter(a=>a.length>0)){const a=r.replace(/^_+/,"").replaceAll(/_+([a-z])/g,(o,i)=>i.toUpperCase()),c=Q.get(a.toLowerCase());c===void 0?e?.(r):t.add(c)}return t};export{ae as c,ce as e,le as g,ue as p,M as s};
1
+ import{m as k,D as S,f as L}from"./provenance-BH80RHXx.js";import{g as $}from"./packument-DyuhH1Gz.js";import{f}from"./formatBytes-BHAzNIrn-XohRrPdt.js";import{a as E}from"./build-scripts-pdVmqXRm.js";import{n as h}from"./license-DvlYdo6T.js";import{v as A,U as P,z as x}from"./index-DHD8wb6Z.js";import{S as O}from"./lockfile-DhHAaHN5.js";import{L as b}from"./dependency-scan-DBH2Qo4I.js";const C=2,m=4,y={CRITICAL:0,HIGH:1,LOW:3,MODERATE:C,UNKNOWN:m},ae=(s,e)=>{const n=y[(s.vulnerability.severity??"UNKNOWN").toUpperCase()]??m,t=y[(e.vulnerability.severity??"UNKNOWN").toUpperCase()]??m;return n-t||s.packageName.localeCompare(e.packageName)||s.packageVersion.localeCompare(e.packageVersion)},M=(s,e)=>{const n=y[e.toUpperCase()]??C;return(y[s.toUpperCase()]??m)<=n},R=["firstSeen","installScripts","license","malware","publisherChange","score","unexpectedDeps","vulnerability"],w=6e4,D=(s,e,n)=>{for(const t of n)if(t===s||t===`${s}@${e}`||t.endsWith("*")&&s.startsWith(t.slice(0,-1)))return!0;return!1},W=async(s,e)=>{const n=e.security?.policies?.firstSeen;if(n?.minutes===void 0||n.minutes<=0)return[];const{minutes:t}=n,r=n.exclude??[],a=e.security?.acceptedRisks,c=t*w,o=Date.now();return(await k(s.packages,S,async l=>{if(D(l.name,l.version,r))return;const p=await $(l.name,{workspaceRoot:s.workspaceRoot});if(p===void 0)return;const u=p.time?.[l.version];if(u===void 0)return;const d=Date.parse(u);if(Number.isNaN(d))return;const v=o-d;if(v>=c)return;const g=Math.max(0,Math.floor(v/w));return{acceptedRisk:f(l.name,l.version,a,"firstSeen"),data:{ageMinutes:g,minimumMinutes:t,publishedAt:u},packageName:l.name,policy:"firstSeen",reason:`${l.name}@${l.version} was published ${String(g)} min ago — below the ${String(t)} min firstSeen cooldown.`,severity:"block",version:l.version}})).filter(l=>l!==void 0)},U=(s,e)=>{const n=e.security?.policies?.installScripts;if(!n)return[];const t=n.allow??{},r=n.strict===!0;if(!r&&Object.keys(t).length===0)return[];const a=E(s.workspaceRoot,t,{pinVersions:e.security?.pinVersions===!0});if(a.unapproved.length===0)return[];const c=e.security?.acceptedRisks,o=r?"block":"warn";return a.unapproved.map(i=>({acceptedRisk:f(i.name,i.version??"*",c,"installScripts"),data:{hooks:i.hooks},packageName:i.name,policy:"installScripts",reason:`${i.name}${i.version?`@${i.version}`:""} declares unapproved build script(s): ${i.hooks.join(", ")}`,severity:o,version:i.version??"*"}))},_=new Set(["AND","OR"]),I=s=>{const e=s.replaceAll("("," ").replaceAll(")"," ").split(/\s+/).map(r=>r.trim()).filter(r=>r.length>0),n=[];let t=!1;for(const r of e){const a=r.toUpperCase();if(t){t=!1;continue}if(a==="WITH"){t=!0;continue}if(_.has(a))continue;const c=r.endsWith("+"),o=c?r.slice(0,-1):r,i=h(o)??o;n.push(i),c&&n.push(`${i}-or-later`)}return n},T=s=>{if(typeof s.license=="string"){const e=s.license.trim();return e.length>0?e:void 0}if(s.license&&typeof s.license=="object"&&typeof s.license.type=="string"){const e=s.license.type.trim();if(e.length>0)return e}if(Array.isArray(s.licenses)&&s.licenses.length>0){const e=s.licenses.map(n=>n&&typeof n.type=="string"?n.type.trim():"").filter(n=>n.length>0);if(e.length>0)return e.length===1?e[0]:`(${e.join(" OR ")})`}},V=(s,e)=>{if(e.length===0)return;const n=new Set(e.map(t=>h(t)??t).map(t=>t.toLowerCase()));for(const t of s)if(n.has(t.toLowerCase()))return t},F=(s,e)=>{if(e.length===0)return;const n=new Set(e.map(t=>h(t)??t).map(t=>t.toLowerCase()));for(const t of s)if(!n.has(t.toLowerCase()))return t},j=(s,e)=>{const n=e.security?.policies?.license;if(!n)return[];const t=n.allow??[],r=n.deny??[];if(t.length===0&&r.length===0)return[];const a=e.security?.acceptedRisks,c=[];for(const o of s.packages){const i=s.manifestData?.get(`${o.name}@${o.version}`),l=i?T(i):void 0;if(!l){t.length>0&&c.push({acceptedRisk:f(o.name,o.version,a,"license"),data:{declaredLicense:null},packageName:o.name,policy:"license",reason:`${o.name}@${o.version} declares no license; allow-list mode requires one of: ${t.join(", ")}`,severity:"block",version:o.version});continue}const p=I(l),u=V(p,r);if(u){c.push({acceptedRisk:f(o.name,o.version,a,"license"),data:{declaredLicense:l,deniedLicense:u},packageName:o.name,policy:"license",reason:`${o.name}@${o.version} uses denied license '${u}' (declared: ${l})`,severity:"block",version:o.version});continue}const d=F(p,t);d&&c.push({acceptedRisk:f(o.name,o.version,a,"license"),data:{allowList:t,declaredLicense:l,unallowedLicense:d},packageName:o.name,policy:"license",reason:`${o.name}@${o.version} uses license '${d}' which is not on the allow-list (declared: ${l})`,severity:"block",version:o.version})}return c},K=6e4,z=(s,e,n)=>{for(const t of n)if(t===s||t===`${s}@${e}`||t.endsWith("*")&&s.startsWith(t.slice(0,-1)))return!0;return!1},B=async(s,e)=>{const n=e.security?.policies?.publisherChange;if(n?.mode!=="no-downgrade")return[];const t=n.exclude??[],r=typeof n.ignoreAfter=="number"?n.ignoreAfter*K:void 0,a=e.security?.acceptedRisks,c=Date.now();return(await k(s.packages,S,async i=>{if(z(i.name,i.version,t))return;const l=await $(i.name,{workspaceRoot:s.workspaceRoot});if(l===void 0)return;if(r!==void 0){const d=l.time?.[i.version],v=d===void 0?Number.NaN:Date.parse(d);if(!Number.isNaN(v)&&c-v>r)return}if(l.versions[i.version]?.dist?.attestations?.provenance!==void 0)return;const u=L(l,i.version);if(u!==void 0)return{acceptedRisk:f(i.name,i.version,a,"publisherChange"),data:{priorVersionWithProvenance:u},packageName:i.name,policy:"publisherChange",reason:`${i.name}@${i.version} dropped the provenance attestation that ${i.name}@${u} carried — publisher trust downgrade.`,severity:"block",version:i.version}})).filter(i=>i!==void 0)},Y=s=>{for(const e of Object.values(b))for(const n of[e.file,...e.aliases??[]])if(s===n||s.endsWith(`/${n}`)||s.endsWith(`.${n}`))return e.type},H=(s,e,n)=>{const t=A(e)?e:P(s,e);let r;try{r=x(t)}catch{return}const a=Y(t)??b[n]?.type;if(!a)return;const c=O(r,a);if(c.length===0)return;const o=new Set;for(const i of c)o.add(`${i.name}@${i.version}`);return o},q=(s,e)=>{for(const n of e)if(n===s||n.endsWith("*")&&s.startsWith(n.slice(0,-1)))return!0;return!1},G=(s,e)=>{const n=e.security?.policies?.unexpectedDeps;if(!n)return[];const t=n.allow??[],r=n.baselineLockfile;if(t.length===0&&!r)return[];const a=r?H(s.workspaceRoot,r,s.packageManager):void 0,c=e.security?.acceptedRisks,o=[];for(const i of s.packages){const l=t.length===0||q(i.name,t),p=a?a.has(`${i.name}@${i.version}`):!0;if(l&&p)continue;const u=[],d={};l||(u.push(`not on allow-list (${t.length} entr${t.length===1?"y":"ies"})`),d.allowList=t),!p&&a&&(u.push(`not present in baseline lockfile (${r})`),d.baselineLockfile=r),o.push({acceptedRisk:f(i.name,i.version,c,"unexpectedDeps"),data:d,packageName:i.name,policy:"unexpectedDeps",reason:`${i.name}@${i.version} is unexpected: ${u.join("; ")}`,severity:"block",version:i.version})}return o},X=(s,e)=>{if(!s.osvFindings||s.osvFindings.size===0)return[];const t=e.security?.policies?.vulnerability?.failOn,r=e.security?.acceptedRisks,a=[];for(const c of s.packages){const o=s.osvFindings.get(c.name);if(!(!o||o.length===0))for(const i of o){const l=t?M(i.severity,t)?"block":"warn":"info";a.push({acceptedRisk:f(c.name,c.version,r,"vulnerability"),data:{advisoryId:i.id,aliases:i.aliases??[],cvssScore:i.cvssScore,fixedVersions:i.fixedVersions,severity:i.severity,summary:i.summary},packageName:c.name,policy:"vulnerability",reason:`${i.severity} ${i.id} affects ${c.name}@${c.version}: ${i.summary}`,severity:l,version:c.version})}}return a},N=[{evaluate:X,isConfigured:s=>s.security?.policies?.vulnerability!==void 0,name:"vulnerability",offlineSupported:!0,surfaces:["audit","doctor"]},{evaluate:j,isConfigured:s=>{const e=s.security?.policies?.license;return!!(e&&(e.allow&&e.allow.length>0||e.deny&&e.deny.length>0))},name:"license",offlineSupported:!0,surfaces:["audit","doctor","install"]},{evaluate:U,isConfigured:s=>{const e=s.security?.policies?.installScripts;return!!(e&&(e.allow&&Object.keys(e.allow).length>0||e.strict===!0))},name:"installScripts",offlineSupported:!0,surfaces:["audit","doctor","install"]},{evaluate:G,isConfigured:s=>{const e=s.security?.policies?.unexpectedDeps;return!!(e&&(e.allow&&e.allow.length>0||typeof e.baselineLockfile=="string"))},name:"unexpectedDeps",offlineSupported:!0,surfaces:["audit","doctor","install"]},{evaluate:W,isConfigured:s=>{const e=s.security?.policies?.firstSeen?.minutes;return typeof e=="number"&&e>0},name:"firstSeen",offlineSupported:!1,surfaces:["audit","doctor","install"]},{evaluate:B,isConfigured:s=>s.security?.policies?.publisherChange?.mode==="no-downgrade",name:"publisherChange",offlineSupported:!1,surfaces:["audit","doctor","install"]}],J=(s,e,n)=>N.filter(t=>t.surfaces.includes(s)?n!==void 0?n.has(t.name):t.isConfigured(e):!1),ce=async(s,e,n)=>{const t=J(e,n.visConfig,n.enabledPolicies),r=[];for(const a of t){if(s.offline&&!a.offlineSupported){r.push({packageName:"*",policy:a.name,reason:`policy.${a.name} skipped: requires network (--offline)`,severity:"info",version:"*"});continue}try{const c=await a.evaluate(s,n.visConfig);r.push(...c)}catch(c){const o=c instanceof Error?c.message:String(c);r.push({packageName:"*",policy:a.name,reason:`policy.${a.name} failed: ${o}`,severity:"info",version:"*"})}}return r},Q=(()=>{const s=new Map;for(const e of R)s.set(e.toLowerCase(),e);return s})(),le=()=>N.map(s=>s.name),ue=(s,e)=>{if(s===void 0)return;const n=s.trim().toLowerCase();if(n===""||n==="none")return new Set;if(n==="all")return new Set(R);const t=new Set;for(const r of s.split(",").map(a=>a.trim()).filter(a=>a.length>0)){const a=r.replace(/^_+/,"").replaceAll(/_+([a-z])/g,(o,i)=>i.toUpperCase()),c=Q.get(a.toLowerCase());c===void 0?e?.(r):t.add(c)}return t};export{ae as c,ce as e,le as g,ue as p,M as s};
@@ -1 +1 @@
1
- import{b as e}from"./vis-user-error-CnMuoAGo.js";const o={filter:{alias:"F",description:"Filter packages by name pattern",multiple:!0,type:String},parallel:{defaultValue:!1,description:"Run concurrently without topological ordering",type:Boolean},recursive:{alias:"r",defaultValue:!1,description:"Run in every workspace package",type:Boolean},reverse:{defaultValue:!1,description:"Reverse topological execution order",type:Boolean},"shell-mode":{alias:"c",defaultValue:!1,description:"Execute within shell environment",type:Boolean},"workspace-root":{alias:"w",defaultValue:!1,description:"Run on workspace root only",type:Boolean}},l=e({argument:{description:"Command to execute followed by arguments",name:"command",type:String},description:"Execute a local node_modules/.bin command (no remote fallback)",examples:[["vis exec eslint .","Run local eslint"],["vis exec tsc --noEmit","Run local TypeScript check"],["vis exec -r -- eslint .","Run in all workspace packages"],["vis exec -c 'echo $PATH'","Shell mode"]],group:"Run & Execute",loader:()=>import("../packem_chunks/handler.js"),name:"exec",options:o});export{l as e};
1
+ import{b as e}from"./vis-user-error-qqqhLoF6.js";const o={filter:{alias:"F",description:"Filter packages by name pattern",multiple:!0,type:String},parallel:{defaultValue:!1,description:"Run concurrently without topological ordering",type:Boolean},recursive:{alias:"r",defaultValue:!1,description:"Run in every workspace package",type:Boolean},reverse:{defaultValue:!1,description:"Reverse topological execution order",type:Boolean},"shell-mode":{alias:"c",defaultValue:!1,description:"Execute within shell environment",type:Boolean},"workspace-root":{alias:"w",defaultValue:!1,description:"Run on workspace root only",type:Boolean}},l=e({argument:{description:"Command to execute followed by arguments",name:"command",type:String},description:"Execute a local node_modules/.bin command (no remote fallback)",examples:[["vis exec eslint .","Run local eslint"],["vis exec tsc --noEmit","Run local TypeScript check"],["vis exec -r -- eslint .","Run in all workspace packages"],["vis exec -c 'echo $PATH'","Shell mode"]],group:"Run & Execute",loader:()=>import("../packem_chunks/handler.js"),name:"exec",options:o});export{l as e};
@@ -1,2 +1,2 @@
1
- import{createRequire as K}from"node:module";import{n as E,o as z,C as S,f as X,e as h}from"./index-DHD8wb6Z.js";import{p as rt}from"./formatBytes-BHAzNIrn-Bkk_uRS-.js";import{N as it}from"./readJsonSync-CbryXYxN-B2aSeDpC.js";import{r as D}from"./writeFileSync-DJoHk3Ks-CgQ-VNNT.js";import{withEnhancedPath as lt}from"@visulima/task-runner";let V;const U=t=>(V??=K(import.meta.url))(t),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=t=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[e,o]=f.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return f.getBuiltinModule(t)}return U(t)},{Socket:Y}=l("node:net"),{randomBytes:J}=l("node:crypto"),{readdir:Q,rm:b,unlink:$,open:Z,readFile:tt,stat:et,writeFile:ot,rename:st}=l("node:fs/promises"),{createRequire:M}=l("node:module"),{spawn:nt}=l("node:child_process"),{openSync:ct,closeSync:at}=l("node:fs");let ht;const dt=t=>(ht??=M(import.meta.url))(t),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ft=t=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[e,o]=u.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return u.getBuiltinModule(t)}return dt(t)},{lstat:A,mkdir:ut}=ft("node:fs/promises"),pt=async t=>{E(t);try{const e=await A(t);if(!e.isDirectory())throw new Error(`Ensure path exists, expected 'dir', got '${String(D(e))}'`);return}catch(e){if(e.code!=="ENOENT")throw e}try{await ut(t,{recursive:!0})}catch(e){if(e.code!=="EEXIST")throw e;const o=await A(t);if(!o.isDirectory())throw new Error(`Ensure path exists, expected 'dir', got '${String(D(o))}'`,{cause:e})}};let wt;const yt=t=>(wt??=M(import.meta.url))(t),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,kt=t=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[e,o]=p.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return p.getBuiltinModule(t)}return yt(t)},{access:mt}=kt("node:fs/promises");async function _t(t,e=z){E(t),t=S(t);try{return await mt(t,e),!0}catch{return!1}}let gt;const vt=t=>(gt??=M(import.meta.url))(t),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,x=t=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[e,o]=w.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return w.getBuiltinModule(t)}return vt(t)},{readFile:bt}=x("node:fs/promises"),{unzip:Tt,brotliDecompress:Et}=x("node:zlib"),St={brotli:Et,gzip:Tt,none:(t,e)=>{e(null,t)}},Mt=async(t,e)=>{E(t),t=S(t);const{buffer:o,compression:s,encoding:r,flag:i}=e??{};let n;try{n=await bt(t,i?{flag:i}:{})}catch(c){throw X(c,t)}return await new Promise((c,g)=>{St[s??"none"](n,(k,m)=>{k?g(k):c(o?m:m.toString(r??"utf8"))})})};async function C(t,e,o){const s=await Mt(t,{buffer:!0,encoding:void 0});let r=new TextDecoder().decode(s);const{beforeParse:i,color:n}={};return typeof i=="function"&&(r=i(r)),it(r,e,S(t),{color:n})}const Ht=3e4,N=100;class Rt extends Error{constructor(e,o){super(e),this.elapsedMs=o,this.name="ServiceReadinessError"}elapsedMs}const Pt=async t=>{const e=t.host??"127.0.0.1",{port:o}=t,s=t.timeoutMs??Ht,r=Date.now();for(;Date.now()-r<s;){if(await $t(e,o))return;await Dt(N)}throw new Rt(`Timed out waiting for ${e}:${String(o)} to accept TCP connections (${String(s)}ms)`,Date.now()-r)},$t=(t,e)=>new Promise(o=>{const s=new Y,r=i=>{s.removeAllListeners(),s.destroy(),o(i)};s.once("connect",()=>{r(!0)}),s.once("error",()=>{r(!1)}),s.setTimeout(N,()=>{r(!1)});try{s.connect(e,t)}catch{r(!1)}}),Dt=t=>new Promise(e=>{setTimeout(e,t)}),At=async(t,e)=>{const o=t.readiness??(t.port===void 0?void 0:{tcp:{port:t.port}});o&&await Pt({host:o.tcp.host,port:o.tcp.port,timeoutMs:e?.timeoutMs??o.tcp.timeoutMs})},H=384,L=5e3,Lt=50,Ot=3e4,d=async t=>{const e=h(rt(t),"services");try{await pt(e)}catch(o){throw o.code==="ENOTDIR"?new Error(`Service registry path ${e} exists but is not a directory. Remove it or move the conflicting file before running \`vis service\`.`,{cause:o}):o}return e},R=t=>t.replaceAll("/","_").replaceAll(":","__"),P=(t,e)=>h(t,`${R(e)}.json`),It=(t,e)=>h(t,`${R(e)}.lock`),_=async(t,e)=>{const o=await d(t),s=P(o,e);if(await _t(s))try{return await C(s)}catch{return}},xt=async t=>{const e=await d(t);let o;try{o=await Q(e)}catch{return[]}const s=[];for(const r of o)if(r.endsWith(".json"))try{const i=await C(h(e,r));s.push(i)}catch{}return s},Ct=async(t,e)=>{const o=await d(t),s=P(o,e.id),r=h(o,`.${J(8).toString("hex")}.tmp`);await ot(r,`${JSON.stringify(e,void 0,2)}
1
+ import{createRequire as K}from"node:module";import{n as E,o as z,C as S,f as X,e as h}from"./index-DHD8wb6Z.js";import{p as rt}from"./formatBytes-BHAzNIrn-XohRrPdt.js";import{N as it}from"./readJsonSync-CbryXYxN-B2aSeDpC.js";import{r as D}from"./writeFileSync-DJoHk3Ks-CgQ-VNNT.js";import{withEnhancedPath as lt}from"@visulima/task-runner";let V;const U=t=>(V??=K(import.meta.url))(t),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=t=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[e,o]=f.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return f.getBuiltinModule(t)}return U(t)},{Socket:Y}=l("node:net"),{randomBytes:J}=l("node:crypto"),{readdir:Q,rm:b,unlink:$,open:Z,readFile:tt,stat:et,writeFile:ot,rename:st}=l("node:fs/promises"),{createRequire:M}=l("node:module"),{spawn:nt}=l("node:child_process"),{openSync:ct,closeSync:at}=l("node:fs");let ht;const dt=t=>(ht??=M(import.meta.url))(t),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ft=t=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[e,o]=u.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return u.getBuiltinModule(t)}return dt(t)},{lstat:A,mkdir:ut}=ft("node:fs/promises"),pt=async t=>{E(t);try{const e=await A(t);if(!e.isDirectory())throw new Error(`Ensure path exists, expected 'dir', got '${String(D(e))}'`);return}catch(e){if(e.code!=="ENOENT")throw e}try{await ut(t,{recursive:!0})}catch(e){if(e.code!=="EEXIST")throw e;const o=await A(t);if(!o.isDirectory())throw new Error(`Ensure path exists, expected 'dir', got '${String(D(o))}'`,{cause:e})}};let wt;const yt=t=>(wt??=M(import.meta.url))(t),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,kt=t=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[e,o]=p.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return p.getBuiltinModule(t)}return yt(t)},{access:mt}=kt("node:fs/promises");async function _t(t,e=z){E(t),t=S(t);try{return await mt(t,e),!0}catch{return!1}}let gt;const vt=t=>(gt??=M(import.meta.url))(t),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,x=t=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[e,o]=w.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return w.getBuiltinModule(t)}return vt(t)},{readFile:bt}=x("node:fs/promises"),{unzip:Tt,brotliDecompress:Et}=x("node:zlib"),St={brotli:Et,gzip:Tt,none:(t,e)=>{e(null,t)}},Mt=async(t,e)=>{E(t),t=S(t);const{buffer:o,compression:s,encoding:r,flag:i}=e??{};let n;try{n=await bt(t,i?{flag:i}:{})}catch(c){throw X(c,t)}return await new Promise((c,g)=>{St[s??"none"](n,(k,m)=>{k?g(k):c(o?m:m.toString(r??"utf8"))})})};async function C(t,e,o){const s=await Mt(t,{buffer:!0,encoding:void 0});let r=new TextDecoder().decode(s);const{beforeParse:i,color:n}={};return typeof i=="function"&&(r=i(r)),it(r,e,S(t),{color:n})}const Ht=3e4,N=100;class Rt extends Error{constructor(e,o){super(e),this.elapsedMs=o,this.name="ServiceReadinessError"}elapsedMs}const Pt=async t=>{const e=t.host??"127.0.0.1",{port:o}=t,s=t.timeoutMs??Ht,r=Date.now();for(;Date.now()-r<s;){if(await $t(e,o))return;await Dt(N)}throw new Rt(`Timed out waiting for ${e}:${String(o)} to accept TCP connections (${String(s)}ms)`,Date.now()-r)},$t=(t,e)=>new Promise(o=>{const s=new Y,r=i=>{s.removeAllListeners(),s.destroy(),o(i)};s.once("connect",()=>{r(!0)}),s.once("error",()=>{r(!1)}),s.setTimeout(N,()=>{r(!1)});try{s.connect(e,t)}catch{r(!1)}}),Dt=t=>new Promise(e=>{setTimeout(e,t)}),At=async(t,e)=>{const o=t.readiness??(t.port===void 0?void 0:{tcp:{port:t.port}});o&&await Pt({host:o.tcp.host,port:o.tcp.port,timeoutMs:e?.timeoutMs??o.tcp.timeoutMs})},H=384,L=5e3,Lt=50,Ot=3e4,d=async t=>{const e=h(rt(t),"services");try{await pt(e)}catch(o){throw o.code==="ENOTDIR"?new Error(`Service registry path ${e} exists but is not a directory. Remove it or move the conflicting file before running \`vis service\`.`,{cause:o}):o}return e},R=t=>t.replaceAll("/","_").replaceAll(":","__"),P=(t,e)=>h(t,`${R(e)}.json`),It=(t,e)=>h(t,`${R(e)}.lock`),_=async(t,e)=>{const o=await d(t),s=P(o,e);if(await _t(s))try{return await C(s)}catch{return}},xt=async t=>{const e=await d(t);let o;try{o=await Q(e)}catch{return[]}const s=[];for(const r of o)if(r.endsWith(".json"))try{const i=await C(h(e,r));s.push(i)}catch{}return s},Ct=async(t,e)=>{const o=await d(t),s=P(o,e.id),r=h(o,`.${J(8).toString("hex")}.tmp`);await ot(r,`${JSON.stringify(e,void 0,2)}
2
2
  `,{mode:H});try{await Wt(r,s)}catch(i){throw await b(r,{force:!0}).catch(()=>{}),i}},Nt=new Set(["EACCES","EBUSY","EPERM"]),Ft=8,jt=20,Wt=async(t,e)=>{let o=0;for(;;)try{await st(t,e);return}catch(s){const{code:r}=s;if(!(r!==void 0&&Nt.has(r))||o>=Ft)throw s;const n=jt*2**o;await new Promise(c=>{setTimeout(c,n)}),o+=1}},y=async(t,e,o)=>{const s=await d(t),r=o??await _(t,e);await b(P(s,e),{force:!0}),r&&await b(r.logFile,{force:!0}).catch(()=>{})},a=t=>{try{return process.kill(t,0),!0}catch{return!1}},se=async t=>{const e=await xt(t),o=[],s=[];for(const r of e){if(a(r.pid)){s.push(r);continue}const i=await _(t,r.id);if(i&&i.pid!==r.pid){s.push(i);continue}await y(t,r.id,r).catch(()=>{}),o.push(r.id)}return{pruned:o,surviving:s}},Bt=t=>new Promise(e=>{setTimeout(e,t)}),Gt=async t=>{try{const e=await Z(t,"wx",H);try{await e.writeFile(String(process.pid))}finally{await e.close().catch(()=>{})}return!0}catch(e){if(e.code==="EEXIST")return!1;throw e}},qt=async t=>{let e;try{const o=await tt(t,"utf8"),s=Number.parseInt(o.trim(),10);e=Number.isFinite(s)?s:void 0}catch{return!0}if(e!==void 0&&!a(e))return!0;try{const o=await et(t);return Date.now()-o.mtimeMs>Ot}catch{return!0}},F=async(t,e,o)=>{const s=await d(t),r=It(s,e),i=Date.now();for(;!await Gt(r);){if(await qt(r)){await $(r).catch(()=>{});continue}if(Date.now()-i>=L)throw new Error(`Could not acquire service lock for ${e} within ${String(L)}ms — another \`vis service\` invocation appears to be holding it.`);await Bt(Lt)}try{return await o()}finally{await $(r).catch(()=>{})}};function T(t,e={},o){for(const s in t){const r=t[s],i=o?`${o}:${s}`:s;typeof r=="object"&&r!==null?T(r,e,i):typeof r=="function"&&(e[i]=r)}return e}const j=(()=>{if(console.createTask)return console.createTask;const t={run:e=>e()};return()=>t})();function W(t,e,o,s){for(let r=o;r<t.length;r+=1)try{const i=s?s.run(()=>t[r](...e)):t[r](...e);if(i&&typeof i.then=="function")return Promise.resolve(i).then(()=>W(t,e,r+1,s))}catch(i){return Promise.reject(i)}}function Kt(t,e,o){if(t.length>0)return W(t,e,0,j(o))}function Vt(t,e,o){if(t.length>0){const s=j(o);return Promise.all(t.map(r=>s.run(()=>r(...e))))}}function v(t,e){for(const o of[...t])o(e)}var Ut=class{_hooks;_before;_after;_deprecatedHooks;_deprecatedMessages;constructor(){this._hooks={},this._before=void 0,this._after=void 0,this._deprecatedMessages=void 0,this._deprecatedHooks={},this.hook=this.hook.bind(this),this.callHook=this.callHook.bind(this),this.callHookWith=this.callHookWith.bind(this)}hook(t,e,o={}){if(!t||typeof e!="function")return()=>{};const s=t;let r;for(;this._deprecatedHooks[t];)r=this._deprecatedHooks[t],t=r.to;if(r&&!o.allowDeprecated){let i=r.message;i||(i=`${s} hook has been deprecated`+(r.to?`, please use ${r.to}`:"")),this._deprecatedMessages||(this._deprecatedMessages=new Set),this._deprecatedMessages.has(i)||(console.warn(i),this._deprecatedMessages.add(i))}if(!e.name)try{Object.defineProperty(e,"name",{get:()=>"_"+t.replace(/\W+/g,"_")+"_hook_cb",configurable:!0})}catch{}return this._hooks[t]=this._hooks[t]||[],this._hooks[t].push(e),()=>{e&&(this.removeHook(t,e),e=void 0)}}hookOnce(t,e){let o,s=(...r)=>(typeof o=="function"&&o(),o=void 0,s=void 0,e(...r));return o=this.hook(t,s),o}removeHook(t,e){const o=this._hooks[t];if(o){const s=o.indexOf(e);s!==-1&&o.splice(s,1),o.length===0&&(this._hooks[t]=void 0)}}clearHook(t){this._hooks[t]=void 0}deprecateHook(t,e){this._deprecatedHooks[t]=typeof e=="string"?{to:e}:e;const o=this._hooks[t]||[];this._hooks[t]=void 0;for(const s of o)this.hook(t,s)}deprecateHooks(t){for(const e in t)this.deprecateHook(e,t[e])}addHooks(t){const e=T(t),o=Object.keys(e).map(s=>this.hook(s,e[s]));return()=>{for(const s of o)s();o.length=0}}removeHooks(t){const e=T(t);for(const o in e)this.removeHook(o,e[o])}removeAllHooks(){this._hooks={}}callHook(t,...e){return this.callHookWith(Kt,t,e)}callHookParallel(t,...e){return this.callHookWith(Vt,t,e)}callHookWith(t,e,o){const s=this._before||this._after?{name:e,args:o,context:{}}:void 0;this._before&&v(this._before,s);const r=t(this._hooks[e]?[...this._hooks[e]]:[],o,e);return r instanceof Promise?r.finally(()=>{this._after&&s&&v(this._after,s)}):(this._after&&s&&v(this._after,s),r)}beforeEach(t){return this._before=this._before||[],this._before.push(t),()=>{if(this._before!==void 0){const e=this._before.indexOf(t);e!==-1&&this._before.splice(e,1)}}}afterEach(t){return this._after=this._after||[],this._after.push(t),()=>{if(this._after!==void 0){const e=this._after.indexOf(t);e!==-1&&this._after.splice(e,1)}}}};function zt(){return new Ut}const re=()=>zt(),ie=async(t,e)=>{if(!(!e||e.length===0))for(const o of e){if(o.hooks)for(const[s,r]of Object.entries(o.hooks)){const i=Array.isArray(r)?r:[r];for(const n of i)t.hook(s,n)}o.setup&&await o.setup(t)}};class ne{#o;#e;#s=new Map;constructor(e,o){this.#o=e,this.#e=o}startTasks(e){for(const o of e)this.#s.set(o.id,o),this.#t("task:before",o)}endTasks(e){for(const o of e)this.#s.delete(o.task.id),this.#t("task:after",o.task,o),o.status==="failure"?this.#t("task:failure",o.task,o):Xt(o.status)&&this.#t("task:cacheHit",o.task,o)}printCacheMiss(e,o){this.#t("task:cacheMiss",e,o)}onTaskStdout(e,o){this.#t("task:stdout",e,o)}onTaskStderr(e,o){this.#t("task:stderr",e,o)}#t(e,...o){Promise.resolve(this.#o.callHook(e,...o)).catch(s=>{if(this.#e)try{this.#e(e,s)}catch{}})}}const Xt=t=>t==="local-cache"||t==="local-cache-kept-existing"||t==="remote-cache",O=process.platform==="win32",Yt=async t=>{const{command:e,cwd:o,env:s,logFile:r}=t,i=ct(r,"a",H);let n;const c=O?"cmd":"/bin/sh",g=O?["/d","/s","/c",e]:["-c",e];try{n=nt(c,g,{cwd:o,detached:!0,env:lt({...process.env,...s},o),stdio:["ignore",i,i],windowsHide:!0})}finally{at(i)}if(n.pid===void 0&&await new Promise((k,m)=>{n.once("spawn",()=>{k()}),n.once("error",q=>{m(q)})}),n.pid===void 0)throw new Error(`Failed to spawn detached process for command: ${e}`);return n.unref(),{pid:n.pid}},B=5e3,ce=async t=>F(t.workspaceRoot,t.id,async()=>{const e=await _(t.workspaceRoot,t.id);if(e&&a(e.pid))throw new Error(`Service ${t.id} is already running (pid ${String(e.pid)})`);e&&await y(t.workspaceRoot,t.id,e);const o=await d(t.workspaceRoot),s=R(t.id),r=h(o,`${s}.log`),{pid:i}=await Yt({command:t.command,cwd:t.cwd,env:t.env,logFile:r}),n={command:t.command,config:t.config,cwd:t.cwd,env:t.config.env??{},id:t.id,logFile:r,pid:i,slug:s,startedAt:new Date().toISOString(),visVersion:process.env.VIS_VERSION??"0.0.0"};if(await Ct(t.workspaceRoot,n),t.skipReadiness!==!0)try{await At(t.config,{timeoutMs:t.readinessTimeoutMs})}catch(c){throw await G(i,t.config.killGracePeriodMs??B).catch(()=>{}),await y(t.workspaceRoot,t.id,n).catch(()=>{}),c}return{entry:n}}),ae=async t=>F(t.workspaceRoot,t.id,async()=>{const e=await _(t.workspaceRoot,t.id);if(!e)return{stopped:!1};if(!a(e.pid))return await y(t.workspaceRoot,t.id,e),{stopped:!1};const o=t.graceMs??e.config.killGracePeriodMs??B;return await G(e.pid,o),await y(t.workspaceRoot,t.id,e),{stopped:!0}}),G=async(t,e)=>{I(t,"SIGTERM");const o=Date.now();for(;Date.now()-o<e;){if(!a(t))return;await new Promise(s=>{setTimeout(s,100)})}a(t)&&I(t,"SIGKILL")},I=(t,e)=>{try{process.platform==="win32"?process.kill(t,e):process.kill(-t,e)}catch(o){if(o.code==="ESRCH")return;throw o}};export{ne as H,Rt as S,ce as a,At as b,xt as c,re as d,ie as e,y as f,_t as g,a as i,se as p,_ as r,ae as s};