@visulima/vis 1.0.0-alpha.15 → 1.0.0-alpha.17

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 (101) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE.md +44 -233
  3. package/dist/bin.js +1 -1
  4. package/dist/config/index.d.ts +200 -94
  5. package/dist/config/index.js +1 -1
  6. package/dist/packem_chunks/bin.js +271 -271
  7. package/dist/packem_chunks/config.js +18 -0
  8. package/dist/packem_chunks/fix.js +1 -1
  9. package/dist/packem_chunks/handler.js +1 -1
  10. package/dist/packem_chunks/handler10.js +1 -1
  11. package/dist/packem_chunks/handler11.js +1 -1
  12. package/dist/packem_chunks/handler12.js +1 -1
  13. package/dist/packem_chunks/handler13.js +1 -1
  14. package/dist/packem_chunks/handler14.js +4 -4
  15. package/dist/packem_chunks/handler15.js +1 -1
  16. package/dist/packem_chunks/handler16.js +1 -1
  17. package/dist/packem_chunks/handler17.js +1 -1
  18. package/dist/packem_chunks/handler18.js +1 -1
  19. package/dist/packem_chunks/handler19.js +5 -5
  20. package/dist/packem_chunks/handler2.js +1 -1
  21. package/dist/packem_chunks/handler20.js +2 -1
  22. package/dist/packem_chunks/handler21.js +18 -1
  23. package/dist/packem_chunks/handler22.js +1 -5
  24. package/dist/packem_chunks/handler23.js +1 -1
  25. package/dist/packem_chunks/handler24.js +5 -3
  26. package/dist/packem_chunks/handler25.js +1 -1
  27. package/dist/packem_chunks/handler26.js +3 -1
  28. package/dist/packem_chunks/handler27.js +1 -7
  29. package/dist/packem_chunks/handler28.js +1 -23
  30. package/dist/packem_chunks/handler29.js +7 -3
  31. package/dist/packem_chunks/handler3.js +1 -1
  32. package/dist/packem_chunks/handler30.js +23 -18
  33. package/dist/packem_chunks/handler31.js +3 -1
  34. package/dist/packem_chunks/handler32.js +1 -2
  35. package/dist/packem_chunks/handler33.js +2 -25
  36. package/dist/packem_chunks/handler34.js +25 -2
  37. package/dist/packem_chunks/handler35.js +2 -2
  38. package/dist/packem_chunks/handler36.js +8 -8
  39. package/dist/packem_chunks/handler37.js +3 -3
  40. package/dist/packem_chunks/handler38.js +3 -3
  41. package/dist/packem_chunks/handler39.js +1 -1
  42. package/dist/packem_chunks/handler40.js +5 -5
  43. package/dist/packem_chunks/handler41.js +9 -9
  44. package/dist/packem_chunks/handler42.js +9 -9
  45. package/dist/packem_chunks/handler43.js +1 -1
  46. package/dist/packem_chunks/handler44.js +5 -5
  47. package/dist/packem_chunks/handler45.js +3 -3
  48. package/dist/packem_chunks/handler46.js +9 -9
  49. package/dist/packem_chunks/handler47.js +161 -36
  50. package/dist/packem_chunks/handler48.js +1 -1
  51. package/dist/packem_chunks/handler5.js +5 -5
  52. package/dist/packem_chunks/handler6.js +1 -1
  53. package/dist/packem_chunks/handler7.js +1 -1
  54. package/dist/packem_chunks/handler8.js +1 -1
  55. package/dist/packem_chunks/handler9.js +1 -1
  56. package/dist/packem_chunks/heal-accept.js +2 -2
  57. package/dist/packem_chunks/heal.js +1 -1
  58. package/dist/packem_chunks/help-command.js +16 -16
  59. package/dist/packem_chunks/index.js +1 -1
  60. package/dist/packem_chunks/loader.js +1 -1
  61. package/dist/packem_shared/{ai-analysis-CGVjqwdc.js → ai-analysis-C_GpXikx.js} +3 -3
  62. package/dist/packem_shared/ai-cache-DrCLD4gc.js +1 -0
  63. package/dist/packem_shared/ai-fix-CWOz12Om.js +43 -0
  64. package/dist/packem_shared/applyDefaults-DLY94gWA.js +1 -0
  65. package/dist/packem_shared/cache-directory-C_U1qsIw.js +1 -0
  66. package/dist/packem_shared/definePlugin-CWm4Dv_t.js +1 -0
  67. package/dist/packem_shared/dependency-scan-YdgNVvoz.js +2 -0
  68. package/dist/packem_shared/docker-B4i5yxtP.js +60 -0
  69. package/dist/packem_shared/failure-log-CSC6KfcO.js +2 -0
  70. package/dist/packem_shared/flakiness-Dzz-I3dB.js +1 -0
  71. package/dist/packem_shared/lifecycle-C7vfQmA3.js +2 -0
  72. package/dist/packem_shared/{lockfile-B7JJzxnL.js → lockfile-i-qvq_k8.js} +1 -1
  73. package/dist/packem_shared/otelPlugin-CJR2T_lk.js +1 -0
  74. package/dist/packem_shared/{readTomlSync-1fKo0R52-DAKNI1Me.js → readTomlSync-1fKo0R52-DtxWULlF.js} +1 -1
  75. package/dist/packem_shared/run-summary-utils-CJv75pla.js +1 -0
  76. package/dist/packem_shared/runtime-check-CBU6W8qG.js +1 -0
  77. package/dist/packem_shared/{selectors-Sem2CTYA.js → selectors-B2ISH581.js} +1 -1
  78. package/dist/packem_shared/toolchain-B7dckBQ1.js +5 -0
  79. package/dist/packem_shared/typosquats-B3A38-qx.js +1 -0
  80. package/dist/packem_shared/verify-WDStBFvK.js +1 -0
  81. package/dist/packem_shared/vis-update-app-D0uL3eO5.js +1 -0
  82. package/package.json +13 -13
  83. package/schemas/project.schema.json +12 -2
  84. package/schemas/vis-config.schema.json +248 -3
  85. package/dist/packem_chunks/applyDefaults.js +0 -2
  86. package/dist/packem_shared/ai-cache-BdPgSfg2.js +0 -1
  87. package/dist/packem_shared/ai-fix-iHtGLkJS.js +0 -43
  88. package/dist/packem_shared/cache-directory-DTfMSzT9.js +0 -1
  89. package/dist/packem_shared/dependency-scan-SQeRzrpJ.js +0 -2
  90. package/dist/packem_shared/docker-D5p9mRPU.js +0 -2
  91. package/dist/packem_shared/failure-log-CElcbnb9.js +0 -2
  92. package/dist/packem_shared/flakiness-C4t4_NoA.js +0 -1
  93. package/dist/packem_shared/otel-CO8UEfTa.js +0 -17
  94. package/dist/packem_shared/otelPlugin-DTynZDWh.js +0 -1
  95. package/dist/packem_shared/registry-D04iOQ5H.js +0 -2
  96. package/dist/packem_shared/run-summary-utils-BPraMTcm.js +0 -1
  97. package/dist/packem_shared/runtime-check-l4qFpo08.js +0 -1
  98. package/dist/packem_shared/toolchain-BhZNts--.js +0 -5
  99. package/dist/packem_shared/typosquats-Dr7VIL2B.js +0 -1
  100. package/dist/packem_shared/verify-C6NNOhTA.js +0 -1
  101. package/dist/packem_shared/vis-update-app-DGiMc5kb.js +0 -1
@@ -1,6 +1,6 @@
1
- var re=Object.defineProperty;var E=(e,r)=>re(e,"name",{value:r,configurable:!0});import{createRequire as te}from"node:module";import{C as se,i as G,M,$ as Q,z as V,Q as le}from"../packem_shared/otel-CO8UEfTa.js";import{Box as a,Text as c,ScrollView as ce,ScrollBar as ae,useApp as de,useWindowSize as ue,useInput as fe,render as he}from"@visulima/tui";import{aH as ge,aI as J,aJ as pe,aK as me,aL as we,aM as ye,p as k,s as xe}from"./bin.js";import be,{useSyncExternalStore as Se,useRef as F,useCallback as _}from"react";import{o as ke}from"../packem_shared/index-DH-5hsrC.js";import{sortPackageJsonStringWithOptions as Y}from"#native";import{jsxs as f,jsx as s,Fragment as ve}from"react/jsx-runtime";import{f as N}from"../packem_shared/utils-DrNg0XTR.js";const oe=te(import.meta.url),T=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ne=E(e=>{if(typeof T<"u"&&T.versions&&T.versions.node){const[r,t]=T.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return T.getBuiltinModule(e)}return oe(e)},"__cjs_getBuiltinModule"),{writeFileSync:ie}=ne("node:fs");var $e=Object.defineProperty,I=E((e,r)=>$e(e,"name",{value:r,configurable:!0}),"i$1");const q={error:0,rewritten:1,"would-rewrite":1,unchanged:2},Pe=I(e=>[...e].sort((r,t)=>q[r.status]-q[t.status]),"sortByStatusRank"),Ee=I((e,r)=>r==="all"?e:r==="errors"?e.filter(t=>t.status==="error"):r==="rewritten"?e.filter(t=>t.status==="rewritten"||t.status==="would-rewrite"):e.filter(t=>t.status==="unchanged"),"filterEntries");class Oe{static{E(this,"a")}static{I(this,"SortPackageJsonStore")}#e;#r=new Set;constructor(r){this.#e={entries:Pe(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=I(()=>this.#e,"getSnapshot");subscribe=I(r=>(this.#r.add(r),()=>{this.#r.delete(r)}),"subscribe");getFilteredEntries=I(()=>Ee(this.#e.entries,this.#e.filterType),"getFilteredEntries");#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const t=this.getFilteredEntries();this.#e.selectedIndex=t.length===0?-1:Math.max(0,Math.min(r,t.length-1)),this.#t()}selectStep(r){this.select(this.#e.selectedIndex+r)}setFilter(r){this.#e.filterType=r,this.#e.selectedIndex=0,this.#t()}setFocusedPanel(r){this.#e.focusedPanel=r,this.#t()}}var je=Object.defineProperty,Ce=E((e,r)=>je(e,"name",{value:r,configurable:!0}),"c$2");const Re=Ce(({checkMode:e,entry:r,focused:t,scrollRef:l})=>r?f(a,{borderColor:t?"white":"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,children:[s(a,{flexShrink:0,paddingTop:1,paddingX:2,children:s(c,{bold:!0,color:"white",children:r.relativePath})}),f(ce,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[s(c,{}),f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Status:"})}),r.status==="error"?s(c,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?s(c,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?s(c,{bold:!0,color:"yellow",children:"rewritten"}):s(c,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Path:"})}),s(c,{children:r.filePath})]}),r.error?f(ve,{children:[f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"red",children:"ERROR"}),f(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Step:"})}),s(c,{color:"yellow",children:r.error.step})]}),r.error.context&&f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Position:"})}),s(c,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),s(a,{marginTop:1,children:s(c,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"white",children:"SNIPPET"}),f(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const i=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return f(a,{children:[s(c,{color:n.isErrorLine?"red":"gray",children:i}),s(c,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&s(a,{children:s(c,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"white",children:"KEY DIFF"}),s(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?s(c,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(n=>{const i=n.toIndex-n.fromIndex,d=i<0?`↑ ${String(Math.abs(i))}`:`↓ ${String(i)}`,g=i<0?"green":"yellow";return f(a,{children:[s(a,{width:28,children:s(c,{wrap:"truncate",children:n.key})}),s(a,{width:10,children:f(c,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),s(c,{color:g,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&s(a,{marginTop:1,paddingLeft:2,children:s(c,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):s(a,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:s(c,{dimColor:!0,children:"No entry selected"})}),"SortDetailPanel");var Ie=Object.defineProperty,O=E((e,r)=>Ie(e,"name",{value:r,configurable:!0}),"i");const Te={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},Me={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},U={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},Fe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},Ne=[{count:O(e=>e.errors+e.rewrites+e.sorted,"count"),key:"all",label:"All",shortcut:"1"},{count:O(e=>e.rewrites,"count"),key:"rewritten",label:"Rewrites",shortcut:"2"},{count:O(e=>e.errors,"count"),key:"errors",label:"Errors",shortcut:"3"},{count:O(e=>e.sorted,"count"),key:"unchanged",label:"Sorted",shortcut:"4"}],Z=O(e=>{const r={errors:0,rewrites:0,sorted:0};for(const t of e)r[U[t.status]]++;return r},"computeGroupCounts"),De=O(({entry:e,isSelected:r})=>{const t=Te[e.status],l=Me[e.status];return f(a,{flexShrink:0,height:1,children:[s(c,{children:r?">":" "}),s(c,{children:" "}),s(c,{bold:!0,color:t,children:`[${l}]`.padEnd(10)}),s(c,{children:" "}),s(a,{flexGrow:1,children:s(c,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&s(c,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},"EntryRow"),Ae=O(({color:e,count:r,label:t})=>s(a,{flexShrink:0,height:1,children:s(c,{bold:!0,color:e,children:`${t} (${String(r)})`})}),"SectionHeader"),Le=O(({counts:e,entries:r,filterType:t,focused:l,selectedIndex:o,totalEntries:n,viewportHeight:i})=>{const d=l?"white":"gray",g=Z(r),b=(g.errors>0?1:0)+(g.rewrites>0?1:0)+(g.sorted>0?1:0),w=t==="all"&&b>1,p=[];let m;for(const[u,y]of r.entries()){const S=U[y.status];w&&S!==m&&(m!==void 0&&p.push({kind:"spacer"}),p.push({color:S==="errors"?"red":S==="rewrites"?"yellow":"green",count:g[S],kind:"header",label:Fe[S]}),m=S),p.push({entry:y,entryIndex:u,kind:"entry"})}const v=p.findIndex(u=>u.kind==="entry"&&u.entryIndex===o),$=v!==-1,P=p.length,h=Math.max(0,P-i);let C=0;$&&i>0&&(C=Math.min(h,Math.max(0,v-i+1)));const R=P>i&&i>0;return f(a,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[f(a,{flexShrink:0,gap:1,paddingX:1,children:[s(c,{bold:!0,inverse:!0,children:" VIS SORT "}),f(c,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),s(a,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:Ne.map(u=>{const y=t===u.key,S=u.count(e);return f(a,{children:[s(c,{dimColor:!y,children:"["}),s(c,{bold:y,color:y?"cyan":"gray",children:u.shortcut}),s(c,{dimColor:!y,children:"]"}),f(c,{color:y?"white":"gray",children:[" ",u.label]}),f(c,{dimColor:!0,children:[" ","(",S,")"]})]},u.key)})}),f(a,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[s(a,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:s(a,{flexDirection:"column",marginTop:-C,children:p.map((u,y)=>u.kind==="spacer"?s(a,{flexShrink:0,height:1},`s-${String(y)}`):u.kind==="header"?s(Ae,{color:u.color,count:u.count,label:u.label},`h-${u.label}`):s(De,{entry:u.entry,isSelected:u.entryIndex===o},u.entry.filePath))})}),R&&s(a,{flexShrink:0,marginLeft:1,marginRight:1,children:s(ae,{contentHeight:P,placement:"inset",scrollOffset:C,style:"block",viewportHeight:i})})]})]})},"SortListPanel");var Be=Object.defineProperty,Ge=E((e,r)=>Be(e,"name",{value:r,configurable:!0}),"T");const Je=100,H=10,_e=6,qe=1,z={1:"all",2:"rewritten",3:"errors",4:"unchanged"},He=Ge(({checkMode:e,store:r})=>{const{exit:t}=de(),{columns:l,rows:o}=ue(),n=Se(r.subscribe,r.getSnapshot),i=F(null),d=r.getFilteredEntries(),g=d[n.selectedIndex]??null,b=Z(n.entries),w=l>=Je,p=Math.max(0,o-qe),m=w?p:Math.floor(p/2),v=Math.max(0,m-_e),$=_(()=>{t()},[t]),P=F(0),h=F(void 0),C=F(!1),R=_((u,y)=>{P.current+=y,h.current=u,!C.current&&(C.current=!0,queueMicrotask(()=>{C.current=!1;const S=P.current,B=h.current;P.current=0,h.current=void 0,!(S===0||B===void 0)&&(B==="list"?r.selectStep(Math.sign(S)):i.current?.scrollBy(Math.sign(S)))}))},[r]);return fe((u,y)=>{if(u==="q"||y.escape){$();return}if(z[u]){r.setFilter(z[u]);return}if(y.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?y.upArrow||u==="k"?R("list",-1):(y.downArrow||u==="j")&&R("list",1):n.focusedPanel==="detail"&&(y.upArrow||u==="k"?R("detail",-1):(y.downArrow||u==="j")&&R("detail",1))}),o<H?s(a,{alignItems:"center",justifyContent:"center",children:f(c,{color:"yellow",children:["Terminal too small. Resize to at least",H," ","rows."]})}):f(a,{flexDirection:"column",height:o,width:l,children:[f(a,{flexDirection:w?"row":"column",flexGrow:1,children:[s(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:s(Le,{counts:b,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:v})}),s(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:s(Re,{checkMode:e,entry:g,focused:n.focusedPanel==="detail",scrollRef:i})})]}),s(a,{flexShrink:0,paddingX:1,children:s(c,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},"VisSortPackageJsonApp");var ze=Object.defineProperty,j=E((e,r)=>ze(e,"name",{value:r,configurable:!0}),"c$1");const W=["types","node-addons","node","import","require","default"],We=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Xe=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,D=j(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isPlainObject"),L=j(e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(t=>L(t));const r={};for(const[t,l]of Object.entries(e))r[t]=L(l);return r},"cloneDeep"),Ke=j(e=>{if(!D(e))return{changed:!1,value:e};const r=Object.keys(e);return r.length===1&&r[0]==="url"&&typeof e.url=="string"?{changed:!0,value:e.url}:{changed:!1,value:e}},"tryFormatBugs"),Qe=j(e=>e.endsWith(".git")?e.slice(0,-4):e,"stripGitSuffix"),Ve=j(e=>{if(!D(e))return{changed:!1,value:e};if(typeof e.directory=="string"&&e.directory.length>0)return{changed:!1,value:e};const{type:r}=e;if(r!==void 0&&r!=="git")return{changed:!1,value:e};const{url:t}=e;if(typeof t!="string")return{changed:!1,value:e};const l=We.exec(t)??Xe.exec(t);if(!l)return{changed:!1,value:e};const o=l[1],n=Qe(l[2]??"");if(!o||!n)return{changed:!1,value:e};const i=new Set(["type","url"]);for(const d of Object.keys(e))if(!i.has(d))return{changed:!1,value:e};return{changed:!0,value:`${o}/${n}`}},"tryFormatRepository"),Ye=j(e=>{const r=Object.keys(e),t=[],l=[];for(const i of W)Object.hasOwn(e,i)&&t.push(i);for(const i of r)W.includes(i)||l.push(i);const o=[...t,...l];if(o.length===r.length&&o.every((i,d)=>i===r[d]))return{changed:!1,value:e};const n={};for(const i of o)n[i]=e[i];return{changed:!0,value:n}},"orderConditions"),ee=j(e=>{if(!D(e))return{changed:!1,value:e};let r=!1;const t={};for(const[o,n]of Object.entries(e)){const i=ee(n);t[o]=i.value,i.changed&&(r=!0)}const l=Ye(t);return{changed:r||l.changed,value:l.value}},"sortExportsRecursive"),Ue=j((e,r)=>{const t=L(e);let l=!1;if(r.formatBugs!==!1&&Object.hasOwn(t,"bugs")){const o=Ke(t.bugs);o.changed&&(t.bugs=o.value,l=!0)}if(r.formatRepository!==!1&&Object.hasOwn(t,"repository")){const o=Ve(t.repository);o.changed&&(t.repository=o.value,l=!0)}if(r.sortExports!==!1&&Object.hasOwn(t,"exports")&&D(t.exports)){const o=ee(t.exports);o.changed&&(t.exports=o.value,l=!0)}return{changed:l,pkg:t}},"formatPackageJsonFields");var Ze=Object.defineProperty,x=E((e,r)=>Ze(e,"name",{value:r,configurable:!0}),"c");const er=/at position (\d+)/,rr=/\(?line (\d+) column (\d+)\)?/,tr=x(e=>{const r=new Set,t=[],l=x(n=>{const i=se(n);!r.has(i)&&G(i)&&(r.add(i),t.push(i))},"addFile");l(M(e,"package.json"));const o=ge(e);if(o){const n=J(e,o);for(const i of n)l(M(e,i,"package.json"))}else{const n=M(e,"package.json");if(G(n)){const i=JSON.parse(Q(n)),d=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;if(d){const g=J(e,d);for(const b of g)l(M(e,b,"package.json"))}}}return t},"findPackageJsonFiles"),or=x(e=>/\n([ \t]+)/.exec(e)?.[1]??" ","detectIndent"),nr=x(e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},"resolveIndentOverride"),A=x(e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),"splitList"),ir=x(e=>e.includes(`\r
2
- `)?"crlf":"lf","detectLineEnding"),sr=new Set(["auto","crlf","lf"]),lr=x(e=>{if(e===void 0||e==="")return"auto";if(sr.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},"validateLineEnding"),cr=x((e,r,t)=>r.length===0?e:e.filter(l=>{const o=V(t,l),n=le(l);return!r.some(i=>{const d=i.includes("/")?o:n;return ke(i,d)})}),"filterByIgnore"),ar=x((e,r)=>{if(r.length===0)return e;const t={},l=new Set;for(const o of r)Object.hasOwn(e,o)&&(t[o]=e[o],l.add(o));for(const o of Object.keys(e))l.has(o)||(t[o]=e[o]);return t},"applySortOrder"),dr=x((e,r,t)=>{if(t.length===0)return e;const l={...e};for(const o of t)Object.hasOwn(r,o)&&(l[o]=r[o]);return l},"restoreUnsortedSections"),ur=x((e,r)=>{let t=1,l=1;const o=Math.min(r,e.length);for(let n=0;n<o;n++)e.codePointAt(n)===10?(t++,l=1):l++;return{column:l,line:t}},"computeLineColumn"),X=x((e,r,t=2)=>{const l=e.split(`
1
+ var re=Object.defineProperty;var E=(e,r)=>re(e,"name",{value:r,configurable:!0});import{createRequire as te}from"node:module";import{C as se,a as G,M as T,$ as Q,z as V,Q as le}from"./config.js";import{render as ce}from"@visulima/tui";import{aK as ae,aL as J,aM as de,aN as ue,aO as fe,aP as he,p as k,s as ge}from"./bin.js";import pe,{useSyncExternalStore as me,useRef as F,useCallback as _}from"react";import{o as we}from"../packem_shared/index-DH-5hsrC.js";import{sortPackageJsonStringWithOptions as Y}from"#native";import{jsxs as f,jsx as s,Fragment as ye}from"react/jsx-runtime";import{Box as a}from"@visulima/tui/components/box";import{Text as c}from"@visulima/tui/components/text";import{useApp as xe}from"@visulima/tui/hooks/use-app";import{useInput as be}from"@visulima/tui/hooks/use-input";import{useWindowSize as Se}from"@visulima/tui/hooks/use-window-size";import{ScrollView as ke}from"@visulima/tui/components/scroll-view";import{ScrollBar as ve}from"@visulima/tui/components/scroll-bar";import{f as N}from"../packem_shared/utils-DrNg0XTR.js";const oe=te(import.meta.url),M=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ne=E(e=>{if(typeof M<"u"&&M.versions&&M.versions.node){const[r,t]=M.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return M.getBuiltinModule(e)}return oe(e)},"__cjs_getBuiltinModule"),{writeFileSync:ie}=ne("node:fs");var $e=Object.defineProperty,I=E((e,r)=>$e(e,"name",{value:r,configurable:!0}),"i$1");const q={error:0,rewritten:1,"would-rewrite":1,unchanged:2},Pe=I(e=>[...e].sort((r,t)=>q[r.status]-q[t.status]),"sortByStatusRank"),Ee=I((e,r)=>r==="all"?e:r==="errors"?e.filter(t=>t.status==="error"):r==="rewritten"?e.filter(t=>t.status==="rewritten"||t.status==="would-rewrite"):e.filter(t=>t.status==="unchanged"),"filterEntries");class Oe{static{E(this,"a")}static{I(this,"SortPackageJsonStore")}#e;#r=new Set;constructor(r){this.#e={entries:Pe(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=I(()=>this.#e,"getSnapshot");subscribe=I(r=>(this.#r.add(r),()=>{this.#r.delete(r)}),"subscribe");getFilteredEntries=I(()=>Ee(this.#e.entries,this.#e.filterType),"getFilteredEntries");#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const t=this.getFilteredEntries();this.#e.selectedIndex=t.length===0?-1:Math.max(0,Math.min(r,t.length-1)),this.#t()}selectStep(r){this.select(this.#e.selectedIndex+r)}setFilter(r){this.#e.filterType=r,this.#e.selectedIndex=0,this.#t()}setFocusedPanel(r){this.#e.focusedPanel=r,this.#t()}}var je=Object.defineProperty,Ce=E((e,r)=>je(e,"name",{value:r,configurable:!0}),"c$2");const Re=Ce(({checkMode:e,entry:r,focused:t,scrollRef:l})=>r?f(a,{borderColor:t?"white":"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,children:[s(a,{flexShrink:0,paddingTop:1,paddingX:2,children:s(c,{bold:!0,color:"white",children:r.relativePath})}),f(ke,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[s(c,{}),f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Status:"})}),r.status==="error"?s(c,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?s(c,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?s(c,{bold:!0,color:"yellow",children:"rewritten"}):s(c,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Path:"})}),s(c,{children:r.filePath})]}),r.error?f(ye,{children:[f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"red",children:"ERROR"}),f(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Step:"})}),s(c,{color:"yellow",children:r.error.step})]}),r.error.context&&f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Position:"})}),s(c,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),s(a,{marginTop:1,children:s(c,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"white",children:"SNIPPET"}),f(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const i=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return f(a,{children:[s(c,{color:n.isErrorLine?"red":"gray",children:i}),s(c,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&s(a,{children:s(c,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"white",children:"KEY DIFF"}),s(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?s(c,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(n=>{const i=n.toIndex-n.fromIndex,d=i<0?`↑ ${String(Math.abs(i))}`:`↓ ${String(i)}`,g=i<0?"green":"yellow";return f(a,{children:[s(a,{width:28,children:s(c,{wrap:"truncate",children:n.key})}),s(a,{width:10,children:f(c,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),s(c,{color:g,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&s(a,{marginTop:1,paddingLeft:2,children:s(c,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):s(a,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:s(c,{dimColor:!0,children:"No entry selected"})}),"SortDetailPanel");var Ie=Object.defineProperty,O=E((e,r)=>Ie(e,"name",{value:r,configurable:!0}),"i");const Me={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},Te={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},U={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},Fe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},Ne=[{count:O(e=>e.errors+e.rewrites+e.sorted,"count"),key:"all",label:"All",shortcut:"1"},{count:O(e=>e.rewrites,"count"),key:"rewritten",label:"Rewrites",shortcut:"2"},{count:O(e=>e.errors,"count"),key:"errors",label:"Errors",shortcut:"3"},{count:O(e=>e.sorted,"count"),key:"unchanged",label:"Sorted",shortcut:"4"}],Z=O(e=>{const r={errors:0,rewrites:0,sorted:0};for(const t of e)r[U[t.status]]++;return r},"computeGroupCounts"),De=O(({entry:e,isSelected:r})=>{const t=Me[e.status],l=Te[e.status];return f(a,{flexShrink:0,height:1,children:[s(c,{children:r?">":" "}),s(c,{children:" "}),s(c,{bold:!0,color:t,children:`[${l}]`.padEnd(10)}),s(c,{children:" "}),s(a,{flexGrow:1,children:s(c,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&s(c,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},"EntryRow"),Ae=O(({color:e,count:r,label:t})=>s(a,{flexShrink:0,height:1,children:s(c,{bold:!0,color:e,children:`${t} (${String(r)})`})}),"SectionHeader"),Le=O(({counts:e,entries:r,filterType:t,focused:l,selectedIndex:o,totalEntries:n,viewportHeight:i})=>{const d=l?"white":"gray",g=Z(r),b=(g.errors>0?1:0)+(g.rewrites>0?1:0)+(g.sorted>0?1:0),w=t==="all"&&b>1,p=[];let m;for(const[u,y]of r.entries()){const S=U[y.status];w&&S!==m&&(m!==void 0&&p.push({kind:"spacer"}),p.push({color:S==="errors"?"red":S==="rewrites"?"yellow":"green",count:g[S],kind:"header",label:Fe[S]}),m=S),p.push({entry:y,entryIndex:u,kind:"entry"})}const v=p.findIndex(u=>u.kind==="entry"&&u.entryIndex===o),$=v!==-1,P=p.length,h=Math.max(0,P-i);let C=0;$&&i>0&&(C=Math.min(h,Math.max(0,v-i+1)));const R=P>i&&i>0;return f(a,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[f(a,{flexShrink:0,gap:1,paddingX:1,children:[s(c,{bold:!0,inverse:!0,children:" VIS SORT "}),f(c,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),s(a,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:Ne.map(u=>{const y=t===u.key,S=u.count(e);return f(a,{children:[s(c,{dimColor:!y,children:"["}),s(c,{bold:y,color:y?"cyan":"gray",children:u.shortcut}),s(c,{dimColor:!y,children:"]"}),f(c,{color:y?"white":"gray",children:[" ",u.label]}),f(c,{dimColor:!0,children:[" ","(",S,")"]})]},u.key)})}),f(a,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[s(a,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:s(a,{flexDirection:"column",marginTop:-C,children:p.map((u,y)=>u.kind==="spacer"?s(a,{flexShrink:0,height:1},`s-${String(y)}`):u.kind==="header"?s(Ae,{color:u.color,count:u.count,label:u.label},`h-${u.label}`):s(De,{entry:u.entry,isSelected:u.entryIndex===o},u.entry.filePath))})}),R&&s(a,{flexShrink:0,marginLeft:1,marginRight:1,children:s(ve,{contentHeight:P,placement:"inset",scrollOffset:C,style:"block",viewportHeight:i})})]})]})},"SortListPanel");var Be=Object.defineProperty,Ge=E((e,r)=>Be(e,"name",{value:r,configurable:!0}),"T");const Je=100,H=10,_e=6,qe=1,z={1:"all",2:"rewritten",3:"errors",4:"unchanged"},He=Ge(({checkMode:e,store:r})=>{const{exit:t}=xe(),{columns:l,rows:o}=Se(),n=me(r.subscribe,r.getSnapshot),i=F(null),d=r.getFilteredEntries(),g=d[n.selectedIndex]??null,b=Z(n.entries),w=l>=Je,p=Math.max(0,o-qe),m=w?p:Math.floor(p/2),v=Math.max(0,m-_e),$=_(()=>{t()},[t]),P=F(0),h=F(void 0),C=F(!1),R=_((u,y)=>{P.current+=y,h.current=u,!C.current&&(C.current=!0,queueMicrotask(()=>{C.current=!1;const S=P.current,B=h.current;P.current=0,h.current=void 0,!(S===0||B===void 0)&&(B==="list"?r.selectStep(Math.sign(S)):i.current?.scrollBy(Math.sign(S)))}))},[r]);return be((u,y)=>{if(u==="q"||y.escape){$();return}if(z[u]){r.setFilter(z[u]);return}if(y.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?y.upArrow||u==="k"?R("list",-1):(y.downArrow||u==="j")&&R("list",1):n.focusedPanel==="detail"&&(y.upArrow||u==="k"?R("detail",-1):(y.downArrow||u==="j")&&R("detail",1))}),o<H?s(a,{alignItems:"center",justifyContent:"center",children:f(c,{color:"yellow",children:["Terminal too small. Resize to at least",H," ","rows."]})}):f(a,{flexDirection:"column",height:o,width:l,children:[f(a,{flexDirection:w?"row":"column",flexGrow:1,children:[s(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:s(Le,{counts:b,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:v})}),s(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:s(Re,{checkMode:e,entry:g,focused:n.focusedPanel==="detail",scrollRef:i})})]}),s(a,{flexShrink:0,paddingX:1,children:s(c,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},"VisSortPackageJsonApp");var ze=Object.defineProperty,j=E((e,r)=>ze(e,"name",{value:r,configurable:!0}),"c$1");const W=["types","node-addons","node","import","require","default"],We=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Xe=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,D=j(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isPlainObject"),L=j(e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(t=>L(t));const r={};for(const[t,l]of Object.entries(e))r[t]=L(l);return r},"cloneDeep"),Ke=j(e=>{if(!D(e))return{changed:!1,value:e};const r=Object.keys(e);return r.length===1&&r[0]==="url"&&typeof e.url=="string"?{changed:!0,value:e.url}:{changed:!1,value:e}},"tryFormatBugs"),Qe=j(e=>e.endsWith(".git")?e.slice(0,-4):e,"stripGitSuffix"),Ve=j(e=>{if(!D(e))return{changed:!1,value:e};if(typeof e.directory=="string"&&e.directory.length>0)return{changed:!1,value:e};const{type:r}=e;if(r!==void 0&&r!=="git")return{changed:!1,value:e};const{url:t}=e;if(typeof t!="string")return{changed:!1,value:e};const l=We.exec(t)??Xe.exec(t);if(!l)return{changed:!1,value:e};const o=l[1],n=Qe(l[2]??"");if(!o||!n)return{changed:!1,value:e};const i=new Set(["type","url"]);for(const d of Object.keys(e))if(!i.has(d))return{changed:!1,value:e};return{changed:!0,value:`${o}/${n}`}},"tryFormatRepository"),Ye=j(e=>{const r=Object.keys(e),t=[],l=[];for(const i of W)Object.hasOwn(e,i)&&t.push(i);for(const i of r)W.includes(i)||l.push(i);const o=[...t,...l];if(o.length===r.length&&o.every((i,d)=>i===r[d]))return{changed:!1,value:e};const n={};for(const i of o)n[i]=e[i];return{changed:!0,value:n}},"orderConditions"),ee=j(e=>{if(!D(e))return{changed:!1,value:e};let r=!1;const t={};for(const[o,n]of Object.entries(e)){const i=ee(n);t[o]=i.value,i.changed&&(r=!0)}const l=Ye(t);return{changed:r||l.changed,value:l.value}},"sortExportsRecursive"),Ue=j((e,r)=>{const t=L(e);let l=!1;if(r.formatBugs!==!1&&Object.hasOwn(t,"bugs")){const o=Ke(t.bugs);o.changed&&(t.bugs=o.value,l=!0)}if(r.formatRepository!==!1&&Object.hasOwn(t,"repository")){const o=Ve(t.repository);o.changed&&(t.repository=o.value,l=!0)}if(r.sortExports!==!1&&Object.hasOwn(t,"exports")&&D(t.exports)){const o=ee(t.exports);o.changed&&(t.exports=o.value,l=!0)}return{changed:l,pkg:t}},"formatPackageJsonFields");var Ze=Object.defineProperty,x=E((e,r)=>Ze(e,"name",{value:r,configurable:!0}),"c");const er=/at position (\d+)/,rr=/\(?line (\d+) column (\d+)\)?/,tr=x(e=>{const r=new Set,t=[],l=x(n=>{const i=se(n);!r.has(i)&&G(i)&&(r.add(i),t.push(i))},"addFile");l(T(e,"package.json"));const o=ae(e);if(o){const n=J(e,o);for(const i of n)l(T(e,i,"package.json"))}else{const n=T(e,"package.json");if(G(n)){const i=JSON.parse(Q(n)),d=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;if(d){const g=J(e,d);for(const b of g)l(T(e,b,"package.json"))}}}return t},"findPackageJsonFiles"),or=x(e=>/\n([ \t]+)/.exec(e)?.[1]??" ","detectIndent"),nr=x(e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},"resolveIndentOverride"),A=x(e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),"splitList"),ir=x(e=>e.includes(`\r
2
+ `)?"crlf":"lf","detectLineEnding"),sr=new Set(["auto","crlf","lf"]),lr=x(e=>{if(e===void 0||e==="")return"auto";if(sr.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},"validateLineEnding"),cr=x((e,r,t)=>r.length===0?e:e.filter(l=>{const o=V(t,l),n=le(l);return!r.some(i=>{const d=i.includes("/")?o:n;return we(i,d)})}),"filterByIgnore"),ar=x((e,r)=>{if(r.length===0)return e;const t={},l=new Set;for(const o of r)Object.hasOwn(e,o)&&(t[o]=e[o],l.add(o));for(const o of Object.keys(e))l.has(o)||(t[o]=e[o]);return t},"applySortOrder"),dr=x((e,r,t)=>{if(t.length===0)return e;const l={...e};for(const o of t)Object.hasOwn(r,o)&&(l[o]=r[o]);return l},"restoreUnsortedSections"),ur=x((e,r)=>{let t=1,l=1;const o=Math.min(r,e.length);for(let n=0;n<o;n++)e.codePointAt(n)===10?(t++,l=1):l++;return{column:l,line:t}},"computeLineColumn"),X=x((e,r,t=2)=>{const l=e.split(`
3
3
  `);if(r<1||r>l.length)return[];const o=Math.max(0,r-1-t),n=Math.min(l.length,r+t),i=[];for(let d=o;d<n;d++)i.push({content:l[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return i},"buildSnippet"),K=x((e,r)=>{if(!(e instanceof Error))return;const t=er.exec(e.message);if(t){const{column:o,line:n}=ur(r,Number.parseInt(t[1]??"0",10));return{column:o,line:n,snippet:X(r,n)}}const l=rr.exec(e.message);if(l){const o=Number.parseInt(l[1]??"1",10);return{column:Number.parseInt(l[2]??"1",10),line:o,snippet:X(r,o)}}},"extractParseErrorContext"),fr=x((e,r)=>{const t=Object.keys(JSON.parse(e)),l=Object.keys(JSON.parse(r)),o=new Map(t.map((i,d)=>[i,d])),n=[];for(const[i,d]of l.entries()){const g=o.get(d);g!==void 0&&g!==i&&n.push({fromIndex:g,key:d,toIndex:i})}return n},"computeKeyDiff"),hr=x((e,r,t)=>{const l=r.indent??t.indent??or(e),o=r.lineEnding==="auto"?t.lineEnding??ir(e):r.lineEnding,n=Y(e,{pretty:!1,sortScripts:r.sortScripts});let i=JSON.parse(n);if(r.unsorted.length>0){const w=JSON.parse(e);i=dr(i,w,r.unsorted)}i=ar(i,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},g=Ue(i,d);let b=JSON.stringify(g.pkg,null,l);return r.finalNewline&&(b+=`
4
4
  `),o==="crlf"&&(b=b.replaceAll(`
5
5
  `,`\r
6
- `)),b},"sortContents"),gr=x((e,r)=>{const t=tr(e),l=pe(e),o=me({cwd:e,extraPatterns:we(l)}),n=t.filter(d=>!o.ignores(d)),i=cr(n,r,e);return{afterGitignore:n,allFiles:t,files:i}},"discoverPackageJsonFiles"),pr=x((e,{checkMode:r,cwd:t,normalized:l})=>{const o=V(t,e)||e;let n;try{n=Q(e)}catch(w){return{diff:[],error:{message:N(w),step:"read"},filePath:e,relativePath:o,status:"error"}}let i;try{i=Y(n,{pretty:!1,sortScripts:l.sortScripts})}catch(w){const p={message:N(w),step:"native-sort"},m=K(w,n);return m&&(p.context=m),{diff:[],error:p,filePath:e,relativePath:o,status:"error"}}const d=l.editorconfig?ye(e):{};let g;try{g=hr(n,l,d)}catch(w){const p={message:N(w),step:"json-parse"},m=K(w,n);return m&&(p.context=m),{diff:[],error:p,filePath:e,relativePath:o,status:"error"}}if(n===g)return{diff:[],filePath:e,relativePath:o,status:"unchanged"};let b;try{b=fr(n,i)}catch{b=[]}if(r)return{diff:b,filePath:e,relativePath:o,status:"would-rewrite"};try{ie(e,g,"utf8")}catch(w){return{diff:b,error:{message:N(w),step:"write"},filePath:e,relativePath:o,status:"error"}}return{diff:b,filePath:e,relativePath:o,status:"rewritten"}},"processFile"),mr=x(e=>{if(e.error&&(k.error(`${e.filePath}: ${e.error.message}`),k.info(` step: ${e.error.step}`),e.error.context)){k.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const t=r.isErrorLine?">":" ";k.info(` ${t} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},"printStaticError"),Or=x(async({options:e,visConfig:r,workspaceRoot:t})=>{const l=t??process.cwd(),o=r?.sortPackageJson,n=e.check||!1,i={editorconfig:e.editorconfig===!1?!1:o?.editorconfig??!0,finalNewline:e.finalNewline??o?.finalNewline??!0,formatBugs:e.formatBugs===!1?!1:o?.formatBugs??!0,formatRepository:e.formatRepository===!1?!1:o?.formatRepository??!0,ignore:[...A(e.ignore),...o?.ignore??[]],indent:nr(e.indent??o?.indent),lineEnding:lr(e.lineEnding??o?.lineEnding),sortExports:e.sortExports===!1?!1:o?.sortExports??!0,sortOrder:[...A(e.sortOrder),...o?.sortOrder??[]],sortScripts:e.sortScripts||o?.sortScripts||!1,unsorted:[...A(e.unsorted),...o?.unsorted??[]]},d=gr(l,i.ignore),{afterGitignore:g,allFiles:b,files:w}=d;if(w.length===0){b.length===0?k.info("No package.json files found."):g.length===0?k.info("All package.json files were excluded by .gitignore or workspace exclusions."):k.info("All package.json files were excluded by --ignore.");return}const p=[];for(const h of w)p.push(pr(h,{checkMode:n,cwd:l,normalized:i}));let m=0,v=0,$=0;for(const h of p)h.status==="error"?$++:h.status==="rewritten"||h.status==="would-rewrite"?m++:v++;const P=m>0||$>0;if(process.stdout.isTTY&&!xe&&P){const h=new Oe(p);await he(be.createElement(He,{checkMode:n,store:h}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const h of p)switch(h.status){case"error":{mr(h);break}case"rewritten":{k.success(`Sorted ${h.filePath}`);break}case"would-rewrite":{k.warn(`${h.filePath} is not sorted`);break}}if(n)m>0?(k.info(`${String(m)} file${m===1?"":"s"} not sorted, ${String(v)} already sorted`),process.exitCode=1):$===0&&k.info(`All ${String(v)} package.json file${v===1?" is":"s are"} sorted`);else{const h=[];m>0&&h.push(`sorted ${String(m)} file${m===1?"":"s"}`),v>0&&h.push(`${String(v)} already sorted`),$>0&&h.push(`${String($)} error${$===1?"":"s"}`),h.length>0&&k.info(h.join(", "))}$>0&&(process.exitCode=1)},"execute");export{X as buildSnippet,fr as computeKeyDiff,ur as computeLineColumn,Or as default,gr as discoverPackageJsonFiles,K as extractParseErrorContext,pr as processFile};
6
+ `)),b},"sortContents"),gr=x((e,r)=>{const t=tr(e),l=de(e),o=ue({cwd:e,extraPatterns:fe(l)}),n=t.filter(d=>!o.ignores(d)),i=cr(n,r,e);return{afterGitignore:n,allFiles:t,files:i}},"discoverPackageJsonFiles"),pr=x((e,{checkMode:r,cwd:t,normalized:l})=>{const o=V(t,e)||e;let n;try{n=Q(e)}catch(w){return{diff:[],error:{message:N(w),step:"read"},filePath:e,relativePath:o,status:"error"}}let i;try{i=Y(n,{pretty:!1,sortScripts:l.sortScripts})}catch(w){const p={message:N(w),step:"native-sort"},m=K(w,n);return m&&(p.context=m),{diff:[],error:p,filePath:e,relativePath:o,status:"error"}}const d=l.editorconfig?he(e):{};let g;try{g=hr(n,l,d)}catch(w){const p={message:N(w),step:"json-parse"},m=K(w,n);return m&&(p.context=m),{diff:[],error:p,filePath:e,relativePath:o,status:"error"}}if(n===g)return{diff:[],filePath:e,relativePath:o,status:"unchanged"};let b;try{b=fr(n,i)}catch{b=[]}if(r)return{diff:b,filePath:e,relativePath:o,status:"would-rewrite"};try{ie(e,g,"utf8")}catch(w){return{diff:b,error:{message:N(w),step:"write"},filePath:e,relativePath:o,status:"error"}}return{diff:b,filePath:e,relativePath:o,status:"rewritten"}},"processFile"),mr=x(e=>{if(e.error&&(k.error(`${e.filePath}: ${e.error.message}`),k.info(` step: ${e.error.step}`),e.error.context)){k.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const t=r.isErrorLine?">":" ";k.info(` ${t} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},"printStaticError"),Fr=x(async({options:e,visConfig:r,workspaceRoot:t})=>{const l=t??process.cwd(),o=r?.sortPackageJson,n=e.check||!1,i={editorconfig:e.editorconfig===!1?!1:o?.editorconfig??!0,finalNewline:e.finalNewline??o?.finalNewline??!0,formatBugs:e.formatBugs===!1?!1:o?.formatBugs??!0,formatRepository:e.formatRepository===!1?!1:o?.formatRepository??!0,ignore:[...A(e.ignore),...o?.ignore??[]],indent:nr(e.indent??o?.indent),lineEnding:lr(e.lineEnding??o?.lineEnding),sortExports:e.sortExports===!1?!1:o?.sortExports??!0,sortOrder:[...A(e.sortOrder),...o?.sortOrder??[]],sortScripts:e.sortScripts||o?.sortScripts||!1,unsorted:[...A(e.unsorted),...o?.unsorted??[]]},d=gr(l,i.ignore),{afterGitignore:g,allFiles:b,files:w}=d;if(w.length===0){b.length===0?k.info("No package.json files found."):g.length===0?k.info("All package.json files were excluded by .gitignore or workspace exclusions."):k.info("All package.json files were excluded by --ignore.");return}const p=[];for(const h of w)p.push(pr(h,{checkMode:n,cwd:l,normalized:i}));let m=0,v=0,$=0;for(const h of p)h.status==="error"?$++:h.status==="rewritten"||h.status==="would-rewrite"?m++:v++;const P=m>0||$>0;if(process.stdout.isTTY&&!ge&&P){const h=new Oe(p);await ce(pe.createElement(He,{checkMode:n,store:h}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const h of p)switch(h.status){case"error":{mr(h);break}case"rewritten":{k.success(`Sorted ${h.filePath}`);break}case"would-rewrite":{k.warn(`${h.filePath} is not sorted`);break}}if(n)m>0?(k.info(`${String(m)} file${m===1?"":"s"} not sorted, ${String(v)} already sorted`),process.exitCode=1):$===0&&k.info(`All ${String(v)} package.json file${v===1?" is":"s are"} sorted`);else{const h=[];m>0&&h.push(`sorted ${String(m)} file${m===1?"":"s"}`),v>0&&h.push(`${String(v)} already sorted`),$>0&&h.push(`${String($)} error${$===1?"":"s"}`),h.length>0&&k.info(h.join(", "))}$>0&&(process.exitCode=1)},"execute");export{X as buildSnippet,fr as computeKeyDiff,ur as computeLineColumn,Fr as default,gr as discoverPackageJsonFiles,K as extractParseErrorContext,pr as processFile};
@@ -1,4 +1,4 @@
1
- var ee=Object.defineProperty;var v=(e,t)=>ee(e,"name",{value:t,configurable:!0});import{createRequire as te}from"node:module";import{M as l,i as y,$ as A,h as G}from"../packem_shared/otel-CO8UEfTa.js";import{aN as z,aO as ae,aP as le,aQ as ce,aR as fe,aS as ue,aT as de,aU as pe,aV as K,aW as J,aX as U,aY as Y}from"./bin.js";import{d as ge}from"../packem_shared/readTomlSync-1fKo0R52-DAKNI1Me.js";const se=te(import.meta.url),F=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,B=v(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 se(e)},"__cjs_getBuiltinModule"),{readdirSync:q,statSync:C,writeFileSync:S,unlinkSync:ne,rmSync:re,chmodSync:ie}=B("node:fs"),{cwd:j}=F,{createInterface:oe}=B("node:readline"),{spawnSync:w}=B("node:child_process");var he=Object.defineProperty,N=v((e,t)=>he(e,"name",{value:t,configurable:!0}),"c$2");const me=/^# ([^:\s]\S*)(?::\s+(.+))?$/,ke=N(e=>{const t=[],s=e.split(`
1
+ var ee=Object.defineProperty;var v=(e,t)=>ee(e,"name",{value:t,configurable:!0});import{createRequire as te}from"node:module";import{M as l,a as y,$ as A,h as G}from"./config.js";import{aQ as z,aR as ae,aS as le,aT as ce,aU as fe,aV as ue,aW as de,aX as pe,aY as K,aZ as J,a_ as U,a$ as Y}from"./bin.js";import{d as ge}from"../packem_shared/readTomlSync-1fKo0R52-DtxWULlF.js";const se=te(import.meta.url),F=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,B=v(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 se(e)},"__cjs_getBuiltinModule"),{readdirSync:q,statSync:C,writeFileSync:S,unlinkSync:ne,rmSync:re,chmodSync:ie}=B("node:fs"),{cwd:j}=F,{createInterface:oe}=B("node:readline"),{spawnSync:w}=B("node:child_process");var he=Object.defineProperty,N=v((e,t)=>he(e,"name",{value:t,configurable:!0}),"c$2");const me=/^# ([^:\s]\S*)(?::\s+(.+))?$/,ke=N(e=>{const t=[],s=e.split(`
2
2
  `);let n;for(const r of s){if(r.startsWith("#!")||r.startsWith("# Generated by")||r.startsWith("# NOTE:")||r==="set -e"||r==="")continue;const i=me.exec(r);if(i){n&&t.push(n),n={command:"",id:i[1]??"",...i[2]?{name:i[2]}:{}};continue}n?n.command=n.command.length>0?`${n.command}
3
3
  ${r}`:r:n={command:r,id:"(custom)"}}return n&&t.push(n),t},"parseStageScript"),ye=N((e,t)=>{const s=l(e,t),n=[],r=new Set(z);if(y(s))for(const i of q(s)){if(i.startsWith(".")||i==="_"||!r.has(i))continue;const o=l(s,i);if(!C(o).isFile())continue;const a=A(o),c=ke(a);n.push({blocks:c,rawLineCount:a.split(`
4
4
  `).length,stage:i})}return n.sort((i,o)=>i.stage.localeCompare(o.stage)),{hooksDirectory:t,stages:n}},"listHooks"),be=N(e=>{const t=[];if(e.stages.length===0)return t.push(`No hooks installed in ${e.hooksDirectory}/.`),t;t.push(`Hooks in ${e.hooksDirectory}/:`);for(const s of e.stages)if(t.push("",`${s.stage} (${s.rawLineCount} lines)`),s.blocks.length===0)t.push(" (empty)");else for(const n of s.blocks){const r=n.name?`${n.id} — ${n.name}`:n.id;t.push(` - ${r}`);const i=n.command.split(`
@@ -1,5 +1,5 @@
1
- var _e=Object.defineProperty;var L=(e,n)=>_e(e,"name",{value:n,configurable:!0});import{createRequire as $e}from"node:module";import{n as pe,M as F,$ as je,C as ke,h as Ce,a as Le}from"../packem_shared/otel-CO8UEfTa.js";import{aZ as Pe,y as we,m as Ae,p as se}from"./bin.js";import{r as xe}from"../packem_shared/docker-D5p9mRPU.js";import{F as De}from"../packem_shared/lockfile-B7JJzxnL.js";const ve=$e(import.meta.url),H=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ie=L(e=>{if(typeof H<"u"&&H.versions&&H.versions.node){const[n,t]=H.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return H.getBuiltinModule(e)}return ve(e)},"__cjs_getBuiltinModule"),{readdirSync:Oe,writeFileSync:Se}=ie("node:fs"),{randomUUID:Te}=ie("node:crypto");var Be=Object.defineProperty,j=L((e,n)=>Be(e,"name",{value:n,configurable:!0}),"a$1");const f={ARRAY:"array",BOOLEAN:"boolean",DATE:"date",FUNCTION:"function",JSTOXML_OBJECT:"jstoxml-object",NULL:"null",NUMBER:"number",OBJECT:"object",STRING:"string"},Me=[f.STRING,f.NUMBER,f.BOOLEAN],Re='<?xml version="1.0" encoding="UTF-8"?>',re=["_selfCloseTag","_attrs"],Ee=j((e="",n=0)=>e.repeat(n),"getIndentStr"),Z=j(e=>Array.isArray(e)&&f.ARRAY||typeof e===f.OBJECT&&e!==null&&e._name&&f.JSTOXML_OBJECT||e instanceof Date&&f.DATE||e===null&&f.NULL||typeof e,"getType"),le=j(e=>e.startsWith("<![CDATA["),"isCDATA"),ue=j((e="",n={},t)=>{let o=e;if(typeof e===f.STRING){if(le(e))return e;const s=new RegExp(`(${Object.keys(n).join("|")})(?!(\\w|#)*;)`,"g");o=String(e).replace(s,(p,d)=>n[d]||"")}return typeof t=="function"?t(o):o},"mapStr"),Ne=j((e={},n,t,o)=>(Array.isArray(e)?e:Object.entries(e).map(([s,p])=>({[s]:p}))).reduce((s,p)=>{const d=Object.keys(p)[0],b=p[d];if(typeof t===f.FUNCTION&&t(d,b))return s;const m=n?ue(b,n):b,h=!o&&m===!0?"":`="${m}"`;return s.push(`${d}${h}`),s},[]),"getAttributeKeyVals"),Ie=j((e={},n,t,o)=>{const s=Ne(e,n,t,o);return s.length===0?"":` ${s.join(" ")}`},"formatAttributes"),Ue=j((e={})=>Object.keys(e).map(n=>({_name:n,_content:e[n]})),"objToArray"),Fe=j(e=>Me.includes(Z(e)),"isPrimitive"),Ge=j(e=>!e.match("<"),"isSimpleXML"),Je=j(({header:e,isOutputStart:n})=>e&&n?typeof e===f.BOOLEAN?Re:e:"","getHeaderString"),ce={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;"},q=j((e={},n={})=>{const{depth:t=0,indent:o,_isFirstItem:s,_isOutputStart:p=!0,header:d,attributeReplacements:b={},attributeFilter:m,attributeExplicitTrue:h=!1,contentReplacements:B={},contentMap:P,selfCloseTags:k=!0}=n,E=typeof b=="boolean"&&!b?{}:{...ce,...b},G=typeof B=="boolean"&&!B?{}:{...ce,...B},w=typeof o=="string",A=Ee(o,t),Y=Z(e),J=Je({header:d,indent:o,depth:t,isOutputStart:p}),N=p&&!J&&s&&t===0,I=w&&!N?`
2
- `:"";let v="";switch(Y){case f.JSTOXML_OBJECT:{const{_name:g,_content:l}=e;if(l===null&&typeof P!="function"){v=`${I}${A}${g}`;break}if(Array.isArray(l)&&l.every(Fe))return l.map(C=>q({_name:g,_content:C},{...n,depth:t,_isOutputStart:!1})).join("");if(re.includes(g))break;const $=q(l,{...n,depth:t+1,_isOutputStart:N}),M=Z($),O=Ge($),S=le($),R=`${I}${A}`;if(g==="_comment"){v+=`${R}<!-- ${l} -->`;break}const K=M==="undefined"||$==="",c=k,r=e._selfCloseTag,i=typeof r===f.BOOLEAN?K&&r:K&&c,a=i?"/":"",u=Ie(e._attrs,E,m,h),y=`<${g}${u}${a}>`,T=w&&!O&&!S?`
3
- ${A}`:"",x=i?"":`${$}${T}</${g}>`;v+=`${R}${y}${x}`;break}case f.OBJECT:{const g=Object.keys(e);v=g.map((l,$)=>{const M={...n,_isFirstItem:$===0,_isLastItem:$+1===g.length,_isOutputStart:N},O={_name:l};if(Z(e[l])===f.OBJECT&&(re.forEach(S=>{const R=e[l][S];typeof R<"u"&&(O[S]=R,delete e[l][S])}),typeof e[l]._content<"u"&&Object.keys(e[l]).length>1)){const S=Object.assign({},e[l]);delete S._content,O._content=[...Ue(S),e[l]._content]}return typeof O._content>"u"&&(O._content=e[l]),q(O,M)},n).join("");break}case f.FUNCTION:{const g=e(n);v=q(g,n);break}case f.ARRAY:{v=e.map((g,l)=>{const $={...n,_isFirstItem:l===0,_isLastItem:l+1===e.length,_isOutputStart:N};return q(g,$)}).join("");break}default:{v=ue(e,G,P);break}}return`${J}${v}`},"toXML");var Xe=Object.defineProperty,z=L((e,n)=>Xe(e,"name",{value:n,configurable:!0}),"r$1");const te=z(e=>{try{return pe(e)}catch{return}},"readJsonSafe"),qe=z(e=>{if(e.length===0||e.includes("..")||e.startsWith(".")||e.includes("\0")||e.includes("\\"))return!1;if(e.startsWith("@")){const n=e.indexOf("/");return n>1&&!e.includes("/",n+1)}return!e.includes("/")},"isSafePackageName"),ze=z(e=>e.length>0&&!e.includes("/")&&!e.includes("\\")&&!e.includes("..")&&!e.includes("\0"),"isSafeVersion"),We=z((e,n,t)=>{const o=`${n.replaceAll("/","+")}@${t}`,s=F(e,"node_modules",".pnpm"),p=te(F(s,o,"node_modules",n,"package.json"));if(p)return p;let d;try{d=Oe(s)}catch{return}const b=`${o}_`;for(const m of d){if(!m.startsWith(b))continue;const h=te(F(s,m,"node_modules",n,"package.json"));if(h)return h}},"readPnpmVirtualStore"),He=z((e,n,t)=>{const o=te(F(e,"node_modules",n,"package.json"));return o?.version===t?o:void 0},"readHoistedCopy"),Ve=z((e,n,t)=>{if(!(!qe(n)||!ze(t)))return We(e,n,t)??He(e,n,t)},"readInstalledPackageMetadata");var Ye=Object.defineProperty,me=L((e,n)=>Ye(e,"name",{value:n,configurable:!0}),"i");const fe=new Set(["0BSD","AGPL-3.0","AGPL-3.0-only","AGPL-3.0-or-later","Apache-1.1","Apache-2.0","Artistic-2.0","BlueOak-1.0.0","BSD-2-Clause","BSD-3-Clause","BSL-1.0","CC0-1.0","CC-BY-3.0","CC-BY-4.0","CDDL-1.0","CDDL-1.1","EPL-1.0","EPL-2.0","GPL-2.0","GPL-2.0-only","GPL-2.0-or-later","GPL-3.0","GPL-3.0-only","GPL-3.0-or-later","ISC","LGPL-2.0","LGPL-2.1","LGPL-3.0","MIT","MIT-0","MPL-1.1","MPL-2.0","Python-2.0","Unlicense","WTFPL","Zlib"]),Ke={apache2:"Apache-2.0","apache 2.0":"Apache-2.0",bsd:"BSD-3-Clause","bsd-2":"BSD-2-Clause","bsd-3":"BSD-3-Clause",mit:"MIT",public:"Unlicense","public domain":"Unlicense"},Ze=(()=>{const e=new Map;for(const n of fe)e.set(n.toLowerCase(),n);for(const[n,t]of Object.entries(Ke))e.set(n,t);return e})(),Qe=me(e=>{const n=e.trim();if(n.length!==0)return fe.has(n)?n:Ze.get(n.toLowerCase())},"normalizeSpdxId"),en=me(e=>{let n;if(typeof e.license=="string")n=e.license;else if(e.license&&typeof e.license=="object"&&typeof e.license.type=="string")n=e.license.type;else if(Array.isArray(e.licenses)&&e.licenses.length>0){const s=e.licenses[0];s&&typeof s.type=="string"&&(n=s.type)}if(!n)return;const t=n.trim();if(t.length===0)return;if(/[()]|\b(?:and|or|with)\b/i.test(t))return[{expression:t}];const o=Qe(t);return o?[{license:{id:o}}]:[{license:{name:t}}]},"extractLicenseChoice");var nn=Object.defineProperty,de=L((e,n)=>nn(e,"name",{value:n,configurable:!0}),"t");const tn={sha256:"SHA-256",sha384:"SHA-384",sha512:"SHA-512"},on={sha256:64,sha384:96,sha512:128},sn=de(e=>{const n={name:e.name,version:e.version},{integrity:t}=e;return t&&t.hex.length===on[t.algorithm]&&(n.hash={alg:tn[t.algorithm],content:t.hex}),e.dependencies&&(n.dependencies=e.dependencies),e.peerDependencies&&(n.peerDependencies=e.peerDependencies),e.optionalDependencies&&(n.optionalDependencies=e.optionalDependencies),n},"toResolvedPackage"),rn=[{file:"pnpm-lock.yaml",type:"pnpm"},{file:"package-lock.json",type:"npm"},{file:"yarn.lock",type:"yarn"},{file:"bun.lock",type:"bun"}],cn=de(e=>{for(const{file:n,type:t}of rn){let o;try{o=je(F(e,n))}catch{continue}const s=new Map;for(const p of De(o,t))s.set(`${p.name}@${p.version}`,sn(p));return{packages:s,type:t}}},"readLockfilePackages");var an=Object.defineProperty,he=L((e,n)=>an(e,"name",{value:n,configurable:!0}),"r");const V=he(e=>e.replaceAll(/[^\w.~-]/g,n=>`%${(n.codePointAt(0)??0).toString(16).toUpperCase().padStart(2,"0")}`),"encodeSegment"),U=he((e,n)=>{const t=e.toLowerCase();if(t.startsWith("@")){const o=t.indexOf("/");if(o>0){const s=t.slice(0,o),p=t.slice(o+1);return`pkg:npm/${V(s)}/${V(p)}@${V(n)}`}}return`pkg:npm/${V(t)}@${V(n)}`},"toNpmPurl");var pn=Object.defineProperty,ge=L((e,n)=>pn(e,"name",{value:n,configurable:!0}),"s");const ln=ge(e=>{const n=e.indexOf(":");return n<=0?e:e.slice(0,n)==="npm"?e.slice(n+1):e},"stripProtocolPrefix"),ee=ge((e,n,t)=>{const o=t.get(e);if(!o||o.size===0)return;if(o.has(n))return n;const s=ln(n);if(s!==n&&o.has(s))return s;const p=[...o];return Pe.maxSatisfying(p,s,{includePrerelease:!0})||p[0]},"resolveSpecifier");var un=Object.defineProperty,_=L((e,n)=>un(e,"name",{value:n,configurable:!0}),"p");const mn="1.6",fn="CycloneDX",dn="http://cyclonedx.org/schema/bom-1.6.schema.json",hn="@visulima/vis",ae=_(e=>{try{return pe(e)}catch{return}},"readPackageJson"),gn=_(e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&e.name)return e.email?`${e.name} <${e.email}>`:e.name}},"toAuthorString"),yn=_(e=>{if(e)return typeof e=="string"?e:e.url},"toRepositoryUrl"),bn=_(e=>{if(e)return typeof e=="string"?e:e.url},"toBugsUrl"),_n=_(e=>{const n=[];e.homepage&&n.push({type:"website",url:e.homepage});const t=yn(e.repository);t&&n.push({type:"vcs",url:t});const o=bn(e.bugs);return o&&n.push({type:"issue-tracker",url:o}),n.length>0?n:void 0},"buildExternalReferences"),ne=_((e,n)=>{if(!n)return;n.description&&(e.description=n.description);const t=gn(n.author);t&&(e.author=t);const o=en(n);o&&(e.licenses=o);const s=_n(n);s&&(e.externalReferences=s)},"decoratePackageComponent"),$n=_(e=>{const{focus:n,generatorVersion:t,includeDev:o=!1,now:s=new Date,projectGraph:p,serialNumber:d,workspace:b,workspaceRoot:m}=e,h=n&&n.length>0?[...xe(n,p)].sort():Object.keys(b.projects).sort(),B=new Set(h),P=new Map;for(const c of h){const r=b.projects[c];r&&P.set(c,ae(F(m,r.root,"package.json")))}const k=[],E=new Map;for(const c of h){const r=b.projects[c];if(!r)continue;const i=P.get(c),a=i?.version??"0.0.0",u=U(c,a);E.set(c,u);const y={"bom-ref":u,name:c,purl:u,type:r.projectType==="application"?"application":"library",version:a};ne(y,i),k.push(y)}const G=cn(m),w=new Map,A=new Map;if(G)for(const c of G.packages.values()){w.set(`${c.name}@${c.version}`,c);let r=A.get(c.name);r||(r=new Set,A.set(c.name,r)),r.add(c.version)}const Y=[],J=[],N=new Map;for(const c of h){const r=P.get(c);if(!r)continue;const i=[r.dependencies,r.peerDependencies];o&&i.push(r.devDependencies);const a=new Set,u=_((y,T)=>{if(T)for(const[x,C]of Object.entries(T)){if(B.has(x)){const X=E.get(x);X&&a.add(X);continue}const D=ee(x,C,A);D&&(a.add(U(x,D)),y.push(`${x}@${D}`))}},"seedRef");for(const y of i)u(Y,y);u(J,r.optionalDependencies),N.set(c,a)}const I=new Map,v=new Map,g=_((c,r)=>{const i=[...c];for(;i.length>0;){const a=i.pop(),u=I.get(a);if(u==="required"||u==="optional"&&r==="optional")continue;I.set(a,r);const y=w.get(a);if(!y)continue;const T=v.get(a)??new Set,x=[y.dependencies,y.peerDependencies];for(const C of x)if(C)for(const[D,X]of Object.entries(C))for(const W of X){const Q=ee(D,W,A);Q&&(T.add(U(D,Q)),i.push(`${D}@${Q}`))}if(y.optionalDependencies)for(const[C,D]of Object.entries(y.optionalDependencies))for(const X of D){const W=ee(C,X,A);W&&(T.add(U(C,W)),J.push(`${C}@${W}`))}T.size>0&&v.set(a,T)}},"walk");g(Y,"required"),g(J,"optional");const l=[],$=[...I.keys()].sort();for(const c of $){const r=w.get(c);if(!r)continue;const i=U(r.name,r.version),a={"bom-ref":i,name:r.name,purl:i,scope:I.get(c)??"required",type:"library",version:r.version};r.hash&&(a.hashes=[r.hash]),ne(a,Ve(m,r.name,r.version)),l.push(a)}const M=[];for(const[c,r]of N){const i=E.get(c);if(!i)continue;const a=[...r].sort();M.push(a.length>0?{dependsOn:a,ref:i}:{ref:i})}for(const c of $){const r=w.get(c);if(!r)continue;const i=U(r.name,r.version),a=v.get(c),u=a?[...a].sort():[];M.push(u.length>0?{dependsOn:u,ref:i}:{ref:i})}M.sort((c,r)=>c.ref.localeCompare(r.ref));const O=ae(F(m,"package.json")),S=(()=>{if(n?.length===1){const u=k.find(y=>y.name===n[0]);if(u)return{"bom-ref":u["bom-ref"],name:u.name,purl:u.purl,type:u.type,version:u.version}}const c=O?.name??"workspace",r=O?.version??"0.0.0",i=U(c,r),a={"bom-ref":i,name:c,purl:i,type:"application",version:r};return ne(a,O),a})(),R=S["bom-ref"],K=R?k.filter(c=>c["bom-ref"]!==R):k;return{$schema:dn,bomFormat:fn,components:[...K,...l],dependencies:M,metadata:{component:S,lifecycles:[{phase:"build"}],timestamp:s.toISOString(),tools:{components:[{name:hn,type:"application",...t?{version:t}:{}}]}},serialNumber:d??`urn:uuid:${Te()}`,specVersion:mn,version:1}},"buildCycloneDxBom"),vn=_(e=>{const n={version:e.version??1,xmlns:"http://cyclonedx.org/schema/bom/1.6"};e.serialNumber&&(n.serialNumber=e.serialNumber);const t=[];return e.metadata&&t.push(On(e.metadata)),e.components&&e.components.length>0&&t.push({_content:e.components.map(o=>oe(o)),_name:"components"}),e.dependencies&&e.dependencies.length>0&&t.push({_content:e.dependencies.map(o=>jn(o)),_name:"dependencies"}),`${q({_attrs:n,_content:t,_name:"bom"},{header:!0,indent:" ",selfCloseTags:!0})}
4
- `},"serializeBomToXml"),On=_(e=>{const n=[];return e.timestamp&&n.push({timestamp:e.timestamp}),e.lifecycles&&e.lifecycles.length>0&&n.push({_content:e.lifecycles.map(t=>{const o=[];return t.phase&&o.push({phase:t.phase}),t.name&&o.push({name:t.name}),t.description&&o.push({description:t.description}),{_content:o,_name:"lifecycle"}}),_name:"lifecycles"}),e.tools?.components&&n.push({_content:[{_content:e.tools.components.map(t=>oe(t)),_name:"components"}],_name:"tools"}),e.component&&n.push(oe(e.component)),{_content:n,_name:"metadata"}},"metadataToXmlElement"),oe=_(e=>{const n={type:e.type};e["bom-ref"]&&(n["bom-ref"]=e["bom-ref"]);const t=[];e.group&&t.push({group:e.group}),t.push({name:e.name}),e.version&&t.push({version:e.version}),e.description&&t.push({description:e.description}),e.author&&t.push({author:e.author}),e.hashes&&e.hashes.length>0&&t.push({_content:e.hashes.map(s=>({_attrs:{alg:s.alg},_content:s.content,_name:"hash"})),_name:"hashes"});const o=Sn(e.licenses);return o&&t.push(o),e.purl&&t.push({purl:e.purl}),e.scope&&t.push({scope:e.scope}),e.externalReferences&&e.externalReferences.length>0&&t.push({_content:e.externalReferences.map(s=>({_attrs:{type:s.type},_content:[{url:s.url}],_name:"reference"})),_name:"externalReferences"}),{_attrs:n,_content:t,_name:"component"}},"componentToXmlElement"),Sn=_(e=>{if(!e||e.length===0)return;const n=[];for(const t of e){if("expression"in t){n.push({expression:t.expression});continue}const o=[];"id"in t.license&&t.license.id?o.push({id:t.license.id}):"name"in t.license&&t.license.name&&o.push({name:t.license.name}),n.push({_content:o,_name:"license"})}return{_content:n,_name:"licenses"}},"licensesToXmlElement"),jn=_(e=>e.dependsOn&&e.dependsOn.length>0?{_attrs:{ref:e.ref},_content:e.dependsOn.map(n=>({_attrs:{ref:n},_name:"dependency"})),_name:"dependency"}:{_attrs:{ref:e.ref},_name:"dependency"},"dependencyToXmlElement");var kn=Object.defineProperty,ye=L((e,n)=>kn(e,"name",{value:n,configurable:!0}),"m");const be=["json","xml"],Cn=ye(e=>be.includes(e),"isSbomFormat"),Dn=ye(async({options:e,visConfig:n,workspaceRoot:t})=>{if(!t)throw new Error("Could not determine workspace root. Run inside a monorepo.");const{packageJsons:o,workspace:s}=we(t,n),p=Ae(t,s,o),d=e.focus,b=d?d.split(",").map(w=>w.trim()).filter(Boolean):void 0,m=(e.format??"json").toLowerCase();if(!Cn(m))throw new Error(`Unknown --format: "${m}". Expected one of: ${be.join(", ")}.`);const h=$n({focus:b,includeDev:!!e.includeDev,projectGraph:p,workspace:s,workspaceRoot:t}),B=m==="xml"?vn(h):`${JSON.stringify(h,void 0,2)}
5
- `,P=e.output??(m==="xml"?"sbom.cdx.xml":"sbom.cdx.json");if(P==="-"){process.stdout.write(B);return}const k=ke(t,P);Ce(Le(k)),Se(k,B,"utf8");const E=h.components?.length??0,G=h.dependencies?.length??0;se.success(`SBOM written to ${k}`),se.notice(`${E} components, ${G} dependency edges`)},"execute");export{Dn as default};
1
+ var _e=Object.defineProperty;var L=(e,n)=>_e(e,"name",{value:n,configurable:!0});import{createRequire as $e}from"node:module";import{n as pe,M as F,$ as je,C as ke,h as Ce,K as Le}from"./config.js";import{b2 as Pe,y as we,m as Te,p as se}from"./bin.js";import{r as xe}from"../packem_shared/docker-B4i5yxtP.js";import{F as De}from"../packem_shared/lockfile-i-qvq_k8.js";const ve=$e(import.meta.url),H=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ie=L(e=>{if(typeof H<"u"&&H.versions&&H.versions.node){const[n,t]=H.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return H.getBuiltinModule(e)}return ve(e)},"__cjs_getBuiltinModule"),{readdirSync:Oe,writeFileSync:Se}=ie("node:fs"),{randomUUID:Ae}=ie("node:crypto");var Be=Object.defineProperty,j=L((e,n)=>Be(e,"name",{value:n,configurable:!0}),"a$1");const f={ARRAY:"array",BOOLEAN:"boolean",DATE:"date",FUNCTION:"function",JSTOXML_OBJECT:"jstoxml-object",NULL:"null",NUMBER:"number",OBJECT:"object",STRING:"string"},Me=[f.STRING,f.NUMBER,f.BOOLEAN],Re='<?xml version="1.0" encoding="UTF-8"?>',re=["_selfCloseTag","_attrs"],Ee=j((e="",n=0)=>e.repeat(n),"getIndentStr"),Z=j(e=>Array.isArray(e)&&f.ARRAY||typeof e===f.OBJECT&&e!==null&&e._name&&f.JSTOXML_OBJECT||e instanceof Date&&f.DATE||e===null&&f.NULL||typeof e,"getType"),le=j(e=>e.startsWith("<![CDATA["),"isCDATA"),ue=j((e="",n={},t)=>{let o=e;if(typeof e===f.STRING){if(le(e))return e;const s=new RegExp(`(${Object.keys(n).join("|")})(?!(\\w|#)*;)`,"g");o=String(e).replace(s,(p,d)=>n[d]||"")}return typeof t=="function"?t(o):o},"mapStr"),Ne=j((e={},n,t,o)=>(Array.isArray(e)?e:Object.entries(e).map(([s,p])=>({[s]:p}))).reduce((s,p)=>{const d=Object.keys(p)[0],b=p[d];if(typeof t===f.FUNCTION&&t(d,b))return s;const m=n?ue(b,n):b,h=!o&&m===!0?"":`="${m}"`;return s.push(`${d}${h}`),s},[]),"getAttributeKeyVals"),Ie=j((e={},n,t,o)=>{const s=Ne(e,n,t,o);return s.length===0?"":` ${s.join(" ")}`},"formatAttributes"),Ue=j((e={})=>Object.keys(e).map(n=>({_name:n,_content:e[n]})),"objToArray"),Fe=j(e=>Me.includes(Z(e)),"isPrimitive"),Ge=j(e=>!e.match("<"),"isSimpleXML"),Je=j(({header:e,isOutputStart:n})=>e&&n?typeof e===f.BOOLEAN?Re:e:"","getHeaderString"),ce={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;"},q=j((e={},n={})=>{const{depth:t=0,indent:o,_isFirstItem:s,_isOutputStart:p=!0,header:d,attributeReplacements:b={},attributeFilter:m,attributeExplicitTrue:h=!1,contentReplacements:B={},contentMap:P,selfCloseTags:k=!0}=n,E=typeof b=="boolean"&&!b?{}:{...ce,...b},G=typeof B=="boolean"&&!B?{}:{...ce,...B},w=typeof o=="string",T=Ee(o,t),Y=Z(e),J=Je({header:d,indent:o,depth:t,isOutputStart:p}),N=p&&!J&&s&&t===0,I=w&&!N?`
2
+ `:"";let v="";switch(Y){case f.JSTOXML_OBJECT:{const{_name:g,_content:l}=e;if(l===null&&typeof P!="function"){v=`${I}${T}${g}`;break}if(Array.isArray(l)&&l.every(Fe))return l.map(C=>q({_name:g,_content:C},{...n,depth:t,_isOutputStart:!1})).join("");if(re.includes(g))break;const $=q(l,{...n,depth:t+1,_isOutputStart:N}),M=Z($),O=Ge($),S=le($),R=`${I}${T}`;if(g==="_comment"){v+=`${R}<!-- ${l} -->`;break}const K=M==="undefined"||$==="",c=k,r=e._selfCloseTag,i=typeof r===f.BOOLEAN?K&&r:K&&c,a=i?"/":"",u=Ie(e._attrs,E,m,h),y=`<${g}${u}${a}>`,A=w&&!O&&!S?`
3
+ ${T}`:"",x=i?"":`${$}${A}</${g}>`;v+=`${R}${y}${x}`;break}case f.OBJECT:{const g=Object.keys(e);v=g.map((l,$)=>{const M={...n,_isFirstItem:$===0,_isLastItem:$+1===g.length,_isOutputStart:N},O={_name:l};if(Z(e[l])===f.OBJECT&&(re.forEach(S=>{const R=e[l][S];typeof R<"u"&&(O[S]=R,delete e[l][S])}),typeof e[l]._content<"u"&&Object.keys(e[l]).length>1)){const S=Object.assign({},e[l]);delete S._content,O._content=[...Ue(S),e[l]._content]}return typeof O._content>"u"&&(O._content=e[l]),q(O,M)},n).join("");break}case f.FUNCTION:{const g=e(n);v=q(g,n);break}case f.ARRAY:{v=e.map((g,l)=>{const $={...n,_isFirstItem:l===0,_isLastItem:l+1===e.length,_isOutputStart:N};return q(g,$)}).join("");break}default:{v=ue(e,G,P);break}}return`${J}${v}`},"toXML");var Xe=Object.defineProperty,z=L((e,n)=>Xe(e,"name",{value:n,configurable:!0}),"r$1");const te=z(e=>{try{return pe(e)}catch{return}},"readJsonSafe"),qe=z(e=>{if(e.length===0||e.includes("..")||e.startsWith(".")||e.includes("\0")||e.includes("\\"))return!1;if(e.startsWith("@")){const n=e.indexOf("/");return n>1&&!e.includes("/",n+1)}return!e.includes("/")},"isSafePackageName"),ze=z(e=>e.length>0&&!e.includes("/")&&!e.includes("\\")&&!e.includes("..")&&!e.includes("\0"),"isSafeVersion"),We=z((e,n,t)=>{const o=`${n.replaceAll("/","+")}@${t}`,s=F(e,"node_modules",".pnpm"),p=te(F(s,o,"node_modules",n,"package.json"));if(p)return p;let d;try{d=Oe(s)}catch{return}const b=`${o}_`;for(const m of d){if(!m.startsWith(b))continue;const h=te(F(s,m,"node_modules",n,"package.json"));if(h)return h}},"readPnpmVirtualStore"),He=z((e,n,t)=>{const o=te(F(e,"node_modules",n,"package.json"));return o?.version===t?o:void 0},"readHoistedCopy"),Ve=z((e,n,t)=>{if(!(!qe(n)||!ze(t)))return We(e,n,t)??He(e,n,t)},"readInstalledPackageMetadata");var Ye=Object.defineProperty,me=L((e,n)=>Ye(e,"name",{value:n,configurable:!0}),"i");const fe=new Set(["0BSD","AGPL-3.0","AGPL-3.0-only","AGPL-3.0-or-later","Apache-1.1","Apache-2.0","Artistic-2.0","BlueOak-1.0.0","BSD-2-Clause","BSD-3-Clause","BSL-1.0","CC0-1.0","CC-BY-3.0","CC-BY-4.0","CDDL-1.0","CDDL-1.1","EPL-1.0","EPL-2.0","GPL-2.0","GPL-2.0-only","GPL-2.0-or-later","GPL-3.0","GPL-3.0-only","GPL-3.0-or-later","ISC","LGPL-2.0","LGPL-2.1","LGPL-3.0","MIT","MIT-0","MPL-1.1","MPL-2.0","Python-2.0","Unlicense","WTFPL","Zlib"]),Ke={apache2:"Apache-2.0","apache 2.0":"Apache-2.0",bsd:"BSD-3-Clause","bsd-2":"BSD-2-Clause","bsd-3":"BSD-3-Clause",mit:"MIT",public:"Unlicense","public domain":"Unlicense"},Ze=(()=>{const e=new Map;for(const n of fe)e.set(n.toLowerCase(),n);for(const[n,t]of Object.entries(Ke))e.set(n,t);return e})(),Qe=me(e=>{const n=e.trim();if(n.length!==0)return fe.has(n)?n:Ze.get(n.toLowerCase())},"normalizeSpdxId"),en=me(e=>{let n;if(typeof e.license=="string")n=e.license;else if(e.license&&typeof e.license=="object"&&typeof e.license.type=="string")n=e.license.type;else if(Array.isArray(e.licenses)&&e.licenses.length>0){const s=e.licenses[0];s&&typeof s.type=="string"&&(n=s.type)}if(!n)return;const t=n.trim();if(t.length===0)return;if(/[()]|\b(?:and|or|with)\b/i.test(t))return[{expression:t}];const o=Qe(t);return o?[{license:{id:o}}]:[{license:{name:t}}]},"extractLicenseChoice");var nn=Object.defineProperty,de=L((e,n)=>nn(e,"name",{value:n,configurable:!0}),"t");const tn={sha256:"SHA-256",sha384:"SHA-384",sha512:"SHA-512"},on={sha256:64,sha384:96,sha512:128},sn=de(e=>{const n={name:e.name,version:e.version},{integrity:t}=e;return t&&t.hex.length===on[t.algorithm]&&(n.hash={alg:tn[t.algorithm],content:t.hex}),e.dependencies&&(n.dependencies=e.dependencies),e.peerDependencies&&(n.peerDependencies=e.peerDependencies),e.optionalDependencies&&(n.optionalDependencies=e.optionalDependencies),n},"toResolvedPackage"),rn=[{file:"pnpm-lock.yaml",type:"pnpm"},{file:"package-lock.json",type:"npm"},{file:"yarn.lock",type:"yarn"},{file:"bun.lock",type:"bun"}],cn=de(e=>{for(const{file:n,type:t}of rn){let o;try{o=je(F(e,n))}catch{continue}const s=new Map;for(const p of De(o,t))s.set(`${p.name}@${p.version}`,sn(p));return{packages:s,type:t}}},"readLockfilePackages");var an=Object.defineProperty,he=L((e,n)=>an(e,"name",{value:n,configurable:!0}),"r");const V=he(e=>e.replaceAll(/[^\w.~-]/g,n=>`%${(n.codePointAt(0)??0).toString(16).toUpperCase().padStart(2,"0")}`),"encodeSegment"),U=he((e,n)=>{const t=e.toLowerCase();if(t.startsWith("@")){const o=t.indexOf("/");if(o>0){const s=t.slice(0,o),p=t.slice(o+1);return`pkg:npm/${V(s)}/${V(p)}@${V(n)}`}}return`pkg:npm/${V(t)}@${V(n)}`},"toNpmPurl");var pn=Object.defineProperty,ge=L((e,n)=>pn(e,"name",{value:n,configurable:!0}),"s");const ln=ge(e=>{const n=e.indexOf(":");return n<=0?e:e.slice(0,n)==="npm"?e.slice(n+1):e},"stripProtocolPrefix"),ee=ge((e,n,t)=>{const o=t.get(e);if(!o||o.size===0)return;if(o.has(n))return n;const s=ln(n);if(s!==n&&o.has(s))return s;const p=[...o];return Pe.maxSatisfying(p,s,{includePrerelease:!0})||p[0]},"resolveSpecifier");var un=Object.defineProperty,_=L((e,n)=>un(e,"name",{value:n,configurable:!0}),"p");const mn="1.6",fn="CycloneDX",dn="http://cyclonedx.org/schema/bom-1.6.schema.json",hn="@visulima/vis",ae=_(e=>{try{return pe(e)}catch{return}},"readPackageJson"),gn=_(e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&e.name)return e.email?`${e.name} <${e.email}>`:e.name}},"toAuthorString"),yn=_(e=>{if(e)return typeof e=="string"?e:e.url},"toRepositoryUrl"),bn=_(e=>{if(e)return typeof e=="string"?e:e.url},"toBugsUrl"),_n=_(e=>{const n=[];e.homepage&&n.push({type:"website",url:e.homepage});const t=yn(e.repository);t&&n.push({type:"vcs",url:t});const o=bn(e.bugs);return o&&n.push({type:"issue-tracker",url:o}),n.length>0?n:void 0},"buildExternalReferences"),$n=_(e=>e==="application"||e==="service"||e==="tool"?"application":"library","toCycloneDxComponentType"),ne=_((e,n)=>{if(!n)return;n.description&&(e.description=n.description);const t=gn(n.author);t&&(e.author=t);const o=en(n);o&&(e.licenses=o);const s=_n(n);s&&(e.externalReferences=s)},"decoratePackageComponent"),vn=_(e=>{const{focus:n,generatorVersion:t,includeDev:o=!1,now:s=new Date,projectGraph:p,serialNumber:d,workspace:b,workspaceRoot:m}=e,h=n&&n.length>0?[...xe(n,p)].sort():Object.keys(b.projects).sort(),B=new Set(h),P=new Map;for(const c of h){const r=b.projects[c];r&&P.set(c,ae(F(m,r.root,"package.json")))}const k=[],E=new Map;for(const c of h){const r=b.projects[c];if(!r)continue;const i=P.get(c),a=i?.version??"0.0.0",u=U(c,a);E.set(c,u);const y={"bom-ref":u,name:c,purl:u,type:$n(r.projectType),version:a};ne(y,i),k.push(y)}const G=cn(m),w=new Map,T=new Map;if(G)for(const c of G.packages.values()){w.set(`${c.name}@${c.version}`,c);let r=T.get(c.name);r||(r=new Set,T.set(c.name,r)),r.add(c.version)}const Y=[],J=[],N=new Map;for(const c of h){const r=P.get(c);if(!r)continue;const i=[r.dependencies,r.peerDependencies];o&&i.push(r.devDependencies);const a=new Set,u=_((y,A)=>{if(A)for(const[x,C]of Object.entries(A)){if(B.has(x)){const X=E.get(x);X&&a.add(X);continue}const D=ee(x,C,T);D&&(a.add(U(x,D)),y.push(`${x}@${D}`))}},"seedRef");for(const y of i)u(Y,y);u(J,r.optionalDependencies),N.set(c,a)}const I=new Map,v=new Map,g=_((c,r)=>{const i=[...c];for(;i.length>0;){const a=i.pop(),u=I.get(a);if(u==="required"||u==="optional"&&r==="optional")continue;I.set(a,r);const y=w.get(a);if(!y)continue;const A=v.get(a)??new Set,x=[y.dependencies,y.peerDependencies];for(const C of x)if(C)for(const[D,X]of Object.entries(C))for(const W of X){const Q=ee(D,W,T);Q&&(A.add(U(D,Q)),i.push(`${D}@${Q}`))}if(y.optionalDependencies)for(const[C,D]of Object.entries(y.optionalDependencies))for(const X of D){const W=ee(C,X,T);W&&(A.add(U(C,W)),J.push(`${C}@${W}`))}A.size>0&&v.set(a,A)}},"walk");g(Y,"required"),g(J,"optional");const l=[],$=[...I.keys()].sort();for(const c of $){const r=w.get(c);if(!r)continue;const i=U(r.name,r.version),a={"bom-ref":i,name:r.name,purl:i,scope:I.get(c)??"required",type:"library",version:r.version};r.hash&&(a.hashes=[r.hash]),ne(a,Ve(m,r.name,r.version)),l.push(a)}const M=[];for(const[c,r]of N){const i=E.get(c);if(!i)continue;const a=[...r].sort();M.push(a.length>0?{dependsOn:a,ref:i}:{ref:i})}for(const c of $){const r=w.get(c);if(!r)continue;const i=U(r.name,r.version),a=v.get(c),u=a?[...a].sort():[];M.push(u.length>0?{dependsOn:u,ref:i}:{ref:i})}M.sort((c,r)=>c.ref.localeCompare(r.ref));const O=ae(F(m,"package.json")),S=(()=>{if(n?.length===1){const u=k.find(y=>y.name===n[0]);if(u)return{"bom-ref":u["bom-ref"],name:u.name,purl:u.purl,type:u.type,version:u.version}}const c=O?.name??"workspace",r=O?.version??"0.0.0",i=U(c,r),a={"bom-ref":i,name:c,purl:i,type:"application",version:r};return ne(a,O),a})(),R=S["bom-ref"],K=R?k.filter(c=>c["bom-ref"]!==R):k;return{$schema:dn,bomFormat:fn,components:[...K,...l],dependencies:M,metadata:{component:S,lifecycles:[{phase:"build"}],timestamp:s.toISOString(),tools:{components:[{name:hn,type:"application",...t?{version:t}:{}}]}},serialNumber:d??`urn:uuid:${Ae()}`,specVersion:mn,version:1}},"buildCycloneDxBom"),On=_(e=>{const n={version:e.version??1,xmlns:"http://cyclonedx.org/schema/bom/1.6"};e.serialNumber&&(n.serialNumber=e.serialNumber);const t=[];return e.metadata&&t.push(Sn(e.metadata)),e.components&&e.components.length>0&&t.push({_content:e.components.map(o=>oe(o)),_name:"components"}),e.dependencies&&e.dependencies.length>0&&t.push({_content:e.dependencies.map(o=>kn(o)),_name:"dependencies"}),`${q({_attrs:n,_content:t,_name:"bom"},{header:!0,indent:" ",selfCloseTags:!0})}
4
+ `},"serializeBomToXml"),Sn=_(e=>{const n=[];return e.timestamp&&n.push({timestamp:e.timestamp}),e.lifecycles&&e.lifecycles.length>0&&n.push({_content:e.lifecycles.map(t=>{const o=[];return t.phase&&o.push({phase:t.phase}),t.name&&o.push({name:t.name}),t.description&&o.push({description:t.description}),{_content:o,_name:"lifecycle"}}),_name:"lifecycles"}),e.tools?.components&&n.push({_content:[{_content:e.tools.components.map(t=>oe(t)),_name:"components"}],_name:"tools"}),e.component&&n.push(oe(e.component)),{_content:n,_name:"metadata"}},"metadataToXmlElement"),oe=_(e=>{const n={type:e.type};e["bom-ref"]&&(n["bom-ref"]=e["bom-ref"]);const t=[];e.group&&t.push({group:e.group}),t.push({name:e.name}),e.version&&t.push({version:e.version}),e.description&&t.push({description:e.description}),e.author&&t.push({author:e.author}),e.hashes&&e.hashes.length>0&&t.push({_content:e.hashes.map(s=>({_attrs:{alg:s.alg},_content:s.content,_name:"hash"})),_name:"hashes"});const o=jn(e.licenses);return o&&t.push(o),e.purl&&t.push({purl:e.purl}),e.scope&&t.push({scope:e.scope}),e.externalReferences&&e.externalReferences.length>0&&t.push({_content:e.externalReferences.map(s=>({_attrs:{type:s.type},_content:[{url:s.url}],_name:"reference"})),_name:"externalReferences"}),{_attrs:n,_content:t,_name:"component"}},"componentToXmlElement"),jn=_(e=>{if(!e||e.length===0)return;const n=[];for(const t of e){if("expression"in t){n.push({expression:t.expression});continue}const o=[];"id"in t.license&&t.license.id?o.push({id:t.license.id}):"name"in t.license&&t.license.name&&o.push({name:t.license.name}),n.push({_content:o,_name:"license"})}return{_content:n,_name:"licenses"}},"licensesToXmlElement"),kn=_(e=>e.dependsOn&&e.dependsOn.length>0?{_attrs:{ref:e.ref},_content:e.dependsOn.map(n=>({_attrs:{ref:n},_name:"dependency"})),_name:"dependency"}:{_attrs:{ref:e.ref},_name:"dependency"},"dependencyToXmlElement");var Cn=Object.defineProperty,ye=L((e,n)=>Cn(e,"name",{value:n,configurable:!0}),"m");const be=["json","xml"],Ln=ye(e=>be.includes(e),"isSbomFormat"),Bn=ye(async({options:e,visConfig:n,workspaceRoot:t})=>{if(!t)throw new Error("Could not determine workspace root. Run inside a monorepo.");const{packageJsons:o,workspace:s}=we(t,n),p=Te(t,s,o),d=e.focus,b=d?d.split(",").map(w=>w.trim()).filter(Boolean):void 0,m=(e.format??"json").toLowerCase();if(!Ln(m))throw new Error(`Unknown --format: "${m}". Expected one of: ${be.join(", ")}.`);const h=vn({focus:b,includeDev:!!e.includeDev,projectGraph:p,workspace:s,workspaceRoot:t}),B=m==="xml"?On(h):`${JSON.stringify(h,void 0,2)}
5
+ `,P=e.output??(m==="xml"?"sbom.cdx.xml":"sbom.cdx.json");if(P==="-"){process.stdout.write(B);return}const k=ke(t,P);Ce(Le(k)),Se(k,B,"utf8");const E=h.components?.length??0,G=h.dependencies?.length??0;se.success(`SBOM written to ${k}`),se.notice(`${E} components, ${G} dependency edges`)},"execute");export{Bn as default};
@@ -1,10 +1,10 @@
1
- var Pt=Object.defineProperty;var P=(e,t)=>Pt(e,"name",{value:t,configurable:!0});import{createRequire as Ot}from"node:module";import{n as Ft,B as qe,aG as Je,a2 as Le,t as Mt,A as at,U as ct,f as zt,R as dt,J as ut,V as jt,N as Et,a as Bt,p as u,c as we,aw as j,e as ze,E as b,d as Re,j as ae,q as Te,s as Lt,v as Vt}from"./bin.js";import{M as te,i as Fe,n as ht,h as _t,O as Ut,C as pt}from"../packem_shared/otel-CO8UEfTa.js";import{Box as h,Text as n,ScrollView as Ht,Spinner as gt,Tabs as Gt,Tab as Yt,ScrollBar as Kt,useApp as qt,useWindowSize as Jt,useInput as Xt,Dialog as Wt,render as Qt}from"@visulima/tui";import Zt,{useSyncExternalStore as ei,useState as xe,useEffect as Be,useRef as Xe,useMemo as De,useCallback as We}from"react";import{X as ni}from"../packem_shared/xxh3-DrAUNq4n.js";import{findVisConfigFile as oi}from"./applyDefaults.js";import{x as Ze,A as ft,L as si,F as li,T as ai,U as ci,a as di,I as ui}from"./handler42.js";import{c as hi}from"../packem_shared/runtime-check-l4qFpo08.js";import{f as pi,l as gi,s as fi}from"../packem_shared/dependency-scan-SQeRzrpJ.js";import{jsxs as a,jsx as r,Fragment as mi}from"react/jsx-runtime";import{u as yi}from"../packem_shared/use-measured-height-DjYgUOKk.js";import{s as ki}from"../packem_shared/verify-C6NNOhTA.js";const Nt=Ot(import.meta.url),Ce=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,lt=P(e=>{if(typeof Ce<"u"&&Ce.versions&&Ce.versions.node){const[t,i]=Ce.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return Ce.getBuiltinModule(e)}return Nt(e)},"__cjs_getBuiltinModule"),{statSync:ti,rmSync:Qe,writeFileSync:ii,readFileSync:ri}=lt("node:fs"),{spawnSync:mt}=lt("node:child_process");var wi=Object.defineProperty,Ae=P((e,t)=>wi(e,"name",{value:t,configurable:!0}),"r$2");const Ve=Ae(()=>te(Ft(),"doctor"),"getCacheDirectory"),vi=1800*1e3,et=Ae(e=>{if(!e)return"";try{return String(ti(e).mtimeMs)}catch{return""}},"safeMtime"),bi=2,$i=Ae(e=>{const t=JSON.stringify({configMtime:et(e.configPath),lockfileMtime:et(e.lockfilePath),schema:bi,sections:[...e.sections].toSorted(),socketEnabled:e.socketEnabled,workspaceRoot:e.workspaceRoot});return ni(Buffer.from(t))},"buildDoctorCacheKey"),Si=Ae(e=>{const t=te(Ve(),`${e}.json`);if(Fe(t))try{const i=ht(t);if(Date.now()-i.createdAt>i.ttlMs){Qe(t,{force:!0});return}return{...i.results,sections:new Set(i.results.sections)}}catch{Qe(t,{force:!0});return}},"readDoctorCache"),Ci=Ae((e,t,i=vi)=>{_t(Ve());const s={createdAt:Date.now(),results:{...t,sections:[...t.sections]},ttlMs:i};ii(te(Ve(),`${e}.json`),JSON.stringify(s,void 0,2),"utf8")},"writeDoctorCache");var xi=Object.defineProperty,_=P((e,t)=>xi(e,"name",{value:t,configurable:!0}),"i$3");const Oe="orphans",Ri=_(()=>{if(process.platform!=="linux")return{id:"inotify",message:"inotify capacity check skipped (not Linux).",status:"skip"};let e;try{const t=ri("/proc/sys/fs/inotify/max_user_watches","utf8").trim(),i=Number.parseInt(t,10);Number.isFinite(i)&&i>0&&(e=i)}catch{return{id:"inotify",message:"Could not read /proc/sys/fs/inotify/max_user_watches.",status:"warn"}}return e===void 0?{id:"inotify",message:"inotify max_user_watches reported a non-numeric value.",status:"warn"}:e<65536?{detail:{maxWatches:e},id:"inotify",message:`inotify watcher limit is ${String(e)} — large monorepos can exhaust this. Bump now with \`sudo sysctl fs.inotify.max_user_watches=524288\` and persist via \`/etc/sysctl.d/99-vis.conf\` so it survives reboot.`,status:"warn"}:{detail:{maxWatches:e},id:"inotify",message:`inotify capacity OK (${String(e)} watches).`,status:"ok"}},"checkInotifyCapacity"),Ti=_(()=>{const e=!!process.stdin.isTTY,t=!!process.stdout.isTTY;return e&&t?{id:"tty",message:"Interactive TTY available — watch keybinds enabled.",status:"ok"}:!e&&!t?{id:"tty",message:"No TTY on stdin/stdout — running in CI / piped mode (keybinds disabled).",status:"skip"}:{detail:{stdin:String(e),stdout:String(t)},id:"tty",message:e?"stdin is a TTY but stdout is not — output is being captured; keybinds still work.":"stdout is a TTY but stdin is not — keybinds disabled (input is piped).",status:"skip"}},"checkTtyAvailability"),Ai=_(()=>{const e=process.pid;try{return process.platform==="win32"?wt(e):kt(e)}catch{return[]}},"listOrphanPids"),Ii=_(()=>{const e=process.pid;let t;try{t=process.platform==="win32"?wt(e):kt(e)}catch{return{id:Oe,message:"Could not enumerate processes (ps/tasklist failed).",status:"warn"}}if(t.length===0)return{id:Oe,message:"No orphaned vis/task-runner processes detected.",status:"ok"};if(t.length<=2)return{detail:{count:t.length,pids:t.join(",")},id:Oe,message:`${String(t.length)} possibly orphaned process(es) detected (PIDs: ${t.join(", ")}). Likely benign.`,status:"skip"};const i=process.platform==="win32"?t.map(s=>`taskkill /F /PID ${String(s)}`).join(" & "):`kill ${t.join(" ")}`;return{detail:{count:t.length,pids:t.join(",")},id:"orphans",message:`${String(t.length)} possibly orphaned vis/task-runner processes — run \`vis doctor --fix\` to clean them up, or kill them manually: ${i}`,status:"warn"}},"checkOrphanedRunners"),Di=_((e={})=>{const t=e.enumerate??Ai,i=e.force===!0?"SIGKILL":"SIGTERM",s=e.kill??Mi,o=t(),l=[],c=[];for(const p of o)try{s(p,i),l.push(p)}catch(d){const S=d.code??d.message;if(S==="ESRCH"){l.push(p);continue}c.push({pid:p,reason:S})}return{failed:c,killed:l}},"killOrphanedRunners"),Pi=_(e=>mt("taskkill",e,{encoding:"utf8"}),"defaultTaskkillRunner"),Oi=_((e,t)=>{process.kill(e,t)},"defaultProcessKill"),Ni=_((e,t,i=Pi)=>{const s=t==="SIGKILL"?["/F","/PID",String(e)]:["/PID",String(e)],o=i(s);if(o.error)throw o.error;if(typeof o.status=="number"&&o.status!==0){const l=o.status===128?"ESRCH":`taskkill exited with code ${String(o.status)}`,c=new Error(l);throw c.code=l,c}},"killViaTaskkill"),Fi=_((e,t,i=Oi)=>{i(e,t)},"killViaSignal"),Mi=_((e,t)=>{if(process.platform==="win32"){Ni(e,t);return}Fi(e,t)},"defaultKill"),yt=_((e,t)=>{const i=mt(e,t,{encoding:"utf8"});if(i.error)throw i.error;if(typeof i.status=="number"&&i.status!==0)throw new Error(`${e} exited with code ${String(i.status)}`);return typeof i.stdout=="string"?i.stdout:""},"runProcessListing"),kt=_(e=>{const t=yt("ps",["-Ao","pid=,command="]),i=[];for(const s of t.split(`
2
- `)){if(s.length===0)continue;const o=/^\s*(\d+)\s+(.+)$/.exec(s);if(!o)continue;const l=Number.parseInt(o[1]??"",10),c=(o[2]??"").toLowerCase();!Number.isFinite(l)||l===e||(/(?:^|[ /])vis-native(?:\s|$|[-.])/.test(c)||/(?:^|[ /])vis\s+run\b/.test(c)||/(?:^|[ /])task-runner(?:\s|$|[-.])/.test(c))&&i.push(l)}return i},"listOrphansUnix"),wt=_(e=>{const t=yt("tasklist",["/FO","CSV","/NH"]),i=[];for(const s of t.split(/\r?\n/)){if(s.length===0)continue;const o=s.split(/","/).map(p=>p.replaceAll(/^"|"$/g,"")),l=(o[0]??"").toLowerCase(),c=Number.parseInt(o[1]??"",10);!Number.isFinite(c)||c===e||(l==="vis.exe"||l.startsWith("vis-native")||l.includes("task-runner"))&&i.push(c)}return i},"listOrphansWindows"),zi=_(()=>[Ri(),Ti(),Ii()],"runRuntimeDiagnostics");var ji=Object.defineProperty,ke=P((e,t)=>ji(e,"name",{value:t,configurable:!0}),"s$2");const ye=[{id:"dependencies",label:"Deps"},{id:"security",label:"Security"},{id:"optimization",label:"Optimize"},{id:"runtime",label:"Runtime"}],Me=["dependencies","security","optimization","runtime"],fe=ke(e=>{const t=new Map;for(const i of Me)t.set(i,[]);for(const i of e)t.get(i.section).push(i);for(const[i,s]of t)s.length===0&&t.delete(i);return t},"groupBySection"),me=ke((e,t,i,s)=>{let o=e.filter(l=>l.section===t);if(s&&(o=o.filter(l=>l.severity===s)),i){const l=i.toLowerCase();o=o.filter(c=>c.title.toLowerCase().includes(l))}return[...o]},"filterFindings"),Ei=ke(e=>{const t={dependencies:"idle",optimization:"idle",runtime:"idle",security:"idle"};for(const i of Me)e.has(i)&&(t[i]="idle");return t},"initialStatus");class tt{static{P(this,"DoctorStore")}static{ke(this,"DoctorStore")}#e;#i=new Set;constructor(t=[]){const i=Array.isArray(t)?{findings:t}:t,s=i.findings??[],o=i.activeSections??new Set(Me),l=Me.find(d=>o.has(d))??"dependencies",c=me(s,l,"",void 0),p=Ei(o);if(s.length>0)for(const d of s)p[d.section]="done";this.#e={all:s,entries:c,filterActive:!1,filterText:"",filterType:l,focusedPanel:"list",grouped:fe(c),pendingAction:void 0,sectionError:{},sectionMessage:{},sectionStatus:p,selectedIndex:0,severityFilter:void 0}}getSnapshot=ke(()=>this.#e,"getSnapshot");subscribe=ke(t=>(this.#i.add(t),()=>{this.#i.delete(t)}),"subscribe");setSelectedIndex(t){const i=Math.max(0,Math.min(t,this.#e.entries.length-1));i!==this.#e.selectedIndex&&this.#t({...this.#e,selectedIndex:i})}setFocusedPanel(t){t!==this.#e.focusedPanel&&this.#t({...this.#e,focusedPanel:t})}setFilterType(t){if(t===this.#e.filterType)return;const i=me(this.#e.all,t,this.#e.filterText,this.#e.severityFilter);this.#t({...this.#e,entries:i,filterType:t,grouped:fe(i),selectedIndex:0})}setFilter(t){const i=me(this.#e.all,this.#e.filterType,t,this.#e.severityFilter);this.#t({...this.#e,entries:i,filterText:t,grouped:fe(i),selectedIndex:0})}setFilterActive(t){if(t===this.#e.filterActive)return;if(t){this.#t({...this.#e,filterActive:!0});return}const i=me(this.#e.all,this.#e.filterType,"",this.#e.severityFilter);this.#t({...this.#e,entries:i,filterActive:!1,filterText:"",grouped:fe(i),selectedIndex:0})}setPendingAction(t){this.#t({...this.#e,pendingAction:t})}setSeverityFilter(t){if(t===this.#e.severityFilter)return;const i=me(this.#e.all,this.#e.filterType,this.#e.filterText,t);this.#t({...this.#e,entries:i,grouped:fe(i),selectedIndex:0,severityFilter:t})}startSection(t,i){this.#t({...this.#e,sectionMessage:{...this.#e.sectionMessage,[t]:i},sectionStatus:{...this.#e.sectionStatus,[t]:"running"}})}completeSection(t,i){const s=[...this.#e.all,...i],o=me(s,this.#e.filterType,this.#e.filterText,this.#e.severityFilter),l={...this.#e.sectionMessage};delete l[t],this.#t({...this.#e,all:s,entries:o,grouped:fe(o),sectionMessage:l,sectionStatus:{...this.#e.sectionStatus,[t]:"done"}})}failSection(t,i){this.#t({...this.#e,sectionError:{...this.#e.sectionError,[t]:i},sectionStatus:{...this.#e.sectionStatus,[t]:"error"}})}#t(t){this.#e=t;for(const i of this.#i)try{i()}catch{}}}var Bi=Object.defineProperty,vt=P((e,t)=>Bi(e,"name",{value:t,configurable:!0}),"r$1");const it={error:0,warn:1},Li=vt(e=>!!e.acceptedRisk,"isAcknowledged"),bt=vt(e=>{const t=[];if(e.sections.has("dependencies")){for(const i of e.outdated)t.push({entry:i,id:`outdated:${i.packageName}`,kind:"outdated",section:"dependencies",severity:"warn",subtitle:`${i.currentRange} → ${i.newRange} (${i.updateType})`,title:i.packageName});for(const i of e.duplicates)t.push({id:`duplicate:${i.name}`,kind:"duplicate",pkg:i,section:"dependencies",severity:"warn",subtitle:`${String(i.versions.length)} versions installed`,title:i.name})}if(e.sections.has("security"))for(const i of e.outdated){if(i.vulnerabilities&&i.vulnerabilities.length>0){const s=i.vulnerabilities[0],o=Li(i)?"warn":"error",l=i.vulnerabilities.length;t.push({entry:i,id:`vuln:${i.packageName}`,kind:"vulnerability",packageName:i.packageName,section:"security",severity:o,subtitle:l===1?`${s.severity} · ${s.id}`:`${String(l)} advisories · top: ${s.severity} ${s.id}`,title:i.packageName})}if(i.socketReport&&i.socketReport.alerts.length>0){const s=Math.round(i.socketReport.score.overall*100);t.push({entry:i,id:`socket:${i.packageName}`,kind:"socket",packageName:i.packageName,section:"security",severity:"warn",subtitle:`${String(i.socketReport.alerts.length)} alert${i.socketReport.alerts.length===1?"":"s"} · score ${String(s)}%`,title:i.packageName})}}if(e.sections.has("optimization"))for(const i of e.optimizations)t.push({entry:i,id:`opt:${i.packageName}`,kind:"optimization",section:"optimization",severity:"warn",subtitle:`${i.category} → ${i.replacement}`,title:i.packageName});if(e.sections.has("runtime"))for(const i of e.runtime)i.status==="warn"&&t.push({diagnostic:i,id:`runtime:${i.id}`,kind:"runtime",section:"runtime",severity:"warn",title:i.message});return t.sort((i,s)=>{if(i.section!==s.section){const o=["dependencies","security","optimization","runtime"];return o.indexOf(i.section)-o.indexOf(s.section)}return it[i.severity]-it[s.severity]}),t},"flattenFindings"),$t={dependencies:"Dependencies",optimization:"Optimization",runtime:"Runtime",security:"Security"};var Vi=Object.defineProperty,_i=P((e,t)=>Vi(e,"name",{value:t,configurable:!0}),"i$2");const Ui={error:"red",warn:"yellow"},Hi={error:"✖",warn:"⚠"},Gi={error:" ERROR ",warn:" WARN "},Yi=_i(({children:e,hint:t,message:i,severity:s,title:o})=>{const l=Ui[s];return a(h,{borderColor:l,borderStyle:"single",flexDirection:"column",flexShrink:0,paddingX:1,children:[a(h,{gap:1,children:[r(n,{backgroundColor:l,bold:!0,color:"black",children:Gi[s]}),r(n,{bold:!0,color:l,children:Hi[s]}),r(n,{bold:!0,wrap:"truncate-end",children:o})]}),r(n,{wrap:"truncate-end",children:i}),t?r(n,{dimColor:!0,wrap:"truncate-end",children:t}):null,e]})},"ConfigBanner");var Ki=Object.defineProperty,ie=P((e,t)=>Ki(e,"name",{value:t,configurable:!0}),"d");const qi={CRITICAL:"red",HIGH:"red",LOW:"gray",MODERATE:"yellow",UNKNOWN:"gray"},Ji={critical:"red",high:"red",low:"gray",medium:"yellow"},Xi={major:"red",minor:"yellow",patch:"green"},x=ie(({children:e,label:t,width:i=14})=>a(h,{children:[r(h,{width:i,children:a(n,{dimColor:!0,children:[t,":"]})}),typeof e=="string"?r(n,{children:e}):e]}),"FieldRow"),se=ie(({children:e})=>r(h,{marginTop:1,children:r(n,{bold:!0,color:"white",children:e})}),"SectionTitle"),Wi=ie(({finding:e})=>{const{entry:t}=e,i=Xi[t.updateType]??"white";return a(h,{flexDirection:"column",children:[r(x,{label:"Current",children:t.currentRange}),a(x,{label:"Target",children:[r(n,{children:t.newRange}),a(n,{bold:!0,color:i,children:[" (",t.updateType,")"]})]}),r(x,{label:"Catalog",children:t.catalogName}),t.acceptedRisk?r(x,{label:"Risk ack",children:r(n,{dimColor:!0,children:t.acceptedRisk.reason??"(no reason recorded)"})}):null,r(se,{children:"Action"}),a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis update"})," ","to apply this change."]})]})},"OutdatedDetail"),Qi=ie(({finding:e})=>a(h,{flexDirection:"column",children:[r(x,{label:"Versions",children:r(n,{children:String(e.pkg.versions.length)})}),r(se,{children:"Installed versions"}),e.pkg.versions.map(t=>a(n,{children:[" · ",t]},t)),r(se,{children:"Action"}),a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis dedupe"})," ","to consolidate to a single resolution."]})]}),"DuplicateDetail"),Zi=ie(({finding:e})=>{const t=e.entry.vulnerabilities??[];return a(h,{flexDirection:"column",children:[r(x,{label:"Package",children:e.packageName}),r(x,{label:"Current",children:e.entry.currentRange}),r(x,{label:"Advisories",children:String(t.length)}),e.entry.acceptedRisk?r(x,{label:"Risk ack",children:r(n,{dimColor:!0,children:e.entry.acceptedRisk.reason??"(no reason recorded)"})}):null,t.map(i=>{const s=qi[i.severity]??"gray";return a(h,{flexDirection:"column",marginTop:1,children:[a(h,{children:[r(n,{bold:!0,color:s,children:i.severity}),r(n,{children:" "}),r(n,{children:i.id}),typeof i.cvssScore=="number"?a(n,{dimColor:!0,children:[" · CVSS ",i.cvssScore.toFixed(1)]}):null]}),r(n,{wrap:"wrap",children:i.summary}),i.fixedVersions.length>0?a(n,{dimColor:!0,children:["Fixed in: ",i.fixedVersions.join(", ")]}):null,i.aliases&&i.aliases.length>0?a(n,{dimColor:!0,children:["Aliases: ",i.aliases.join(", ")]}):null]},i.id)})]})},"VulnerabilityDetail"),er=ie(({finding:e})=>{const t=e.entry.socketReport;if(!t)return r(n,{dimColor:!0,children:"No Socket report attached."});const i=Math.round(t.score.overall*100),s=qe(t.score.overall);return a(h,{flexDirection:"column",children:[r(x,{label:"Package",children:e.packageName}),r(x,{label:"Overall",children:a(n,{color:s,children:[String(i),"%"]})}),r(x,{label:"Alerts",children:String(t.alerts.length)}),e.entry.acceptedRisk?r(x,{label:"Risk ack",children:r(n,{dimColor:!0,children:e.entry.acceptedRisk.reason??"(no reason recorded)"})}):null,r(se,{children:"Score breakdown"}),Object.entries(t.score).map(([o,l])=>{if(o==="overall")return null;const c=typeof l=="number"?l:0,p=Math.round(c*100),d=qe(c);return a(h,{children:[r(h,{width:14,children:a(n,{dimColor:!0,children:[o,":"]})}),a(n,{color:d,children:[String(p),"%"]})]},o)}),r(se,{children:"Alerts"}),t.alerts.map((o,l)=>{const c=Ji[o.severity]??"gray";return a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{children:[r(n,{bold:!0,color:c,children:o.severity}),r(n,{children:" "}),r(n,{children:o.type})]}),o.props?r(n,{dimColor:!0,wrap:"wrap",children:JSON.stringify(o.props)}):null]},`${o.type}-${String(l)}`)})]})},"SocketDetail"),tr=ie(({finding:e})=>{const{entry:t}=e;return a(h,{flexDirection:"column",children:[r(x,{label:"Package",children:t.packageName}),r(x,{label:"Category",children:t.category}),r(x,{label:"Replacement",children:t.replacement}),t.overrideSpec?r(x,{label:"Override",children:t.overrideSpec}):null,r(x,{label:"Codemod",children:r(n,{color:t.hasCodemod?"green":"gray",children:t.hasCodemod?"available":"not available"})}),t.docUrl?r(x,{label:"Guide",children:r(n,{color:"cyan",underline:!0,children:t.docUrl})}):null,r(se,{children:"Action"}),t.hasCodemod?a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis optimize"})," ","to apply the codemod interactively."]}):t.overrideSpec?a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis optimize"})," ","to install the package override."]}):t.docUrl?r(n,{dimColor:!0,children:"No automated codemod. Open the migration guide above for the recommended alternative and steps."}):r(n,{dimColor:!0,children:"No automated codemod. Consult the package's docs or the e18e module-replacements guide for an alternative."})]})},"OptimizationDetail"),ir=ie(({finding:e})=>{const{diagnostic:t}=e,i=t.status==="warn"?"yellow":t.status==="ok"?"green":"gray";return a(h,{flexDirection:"column",children:[r(x,{label:"Check",children:t.id}),r(x,{label:"Status",children:r(n,{color:i,children:t.status})}),r(se,{children:"Message"}),r(n,{wrap:"wrap",children:t.message}),t.detail&&Object.keys(t.detail).length>0?a(mi,{children:[r(se,{children:"Details"}),Object.entries(t.detail).map(([s,o])=>a(h,{children:[r(h,{width:20,children:a(n,{dimColor:!0,children:[s,":"]})}),r(n,{children:String(o)})]},s))]}):null]})},"RuntimeDetail"),rr=ie(({finding:e,focused:t,scrollRef:i})=>{const s=t?"white":"gray";if(!e)return r(h,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:r(n,{dimColor:!0,children:"No finding selected"})});let o;switch(e.kind){case"duplicate":{o=r(Qi,{finding:e});break}case"optimization":{o=r(tr,{finding:e});break}case"outdated":{o=r(Wi,{finding:e});break}case"runtime":{o=r(ir,{finding:e});break}case"socket":{o=r(er,{finding:e});break}case"vulnerability":{o=r(Zi,{finding:e});break}default:{o=r(n,{dimColor:!0,children:"Unknown finding kind."});break}}return a(h,{borderColor:s,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[a(h,{flexShrink:0,paddingTop:1,paddingX:2,children:[r(n,{bold:!0,color:"white",children:e.title}),a(n,{dimColor:!0,children:[" ",$t[e.section]]})]}),a(Ht,{flexGrow:1,flexShrink:1,paddingX:2,ref:i,scrollbar:!0,scrollbarColor:"gray",scrollbarStyle:"block",children:[r(n,{}),o]})]})},"DoctorDetailPanel");var nr=Object.defineProperty,Ie=P((e,t)=>nr(e,"name",{value:t,configurable:!0}),"c$2");const St={error:"red",warn:"yellow"},or={error:"✖",warn:"⚠"},sr=Ie(e=>e.kind==="outdated"||e.kind==="vulnerability"||e.kind==="socket"?!!e.entry.acceptedRisk:!1,"hasAcceptedRisk"),lr=Ie(({finding:e,isSelected:t})=>{const i=St[e.severity],s=sr(e);return a(h,{flexShrink:0,height:1,children:[r(n,{children:t?">":" "}),a(n,{color:i,children:[" ",or[e.severity]," "]}),r(h,{flexGrow:1,children:r(n,{bold:t,inverse:t,wrap:"truncate",children:e.title})}),s?r(n,{color:"cyan",children:" ack"}):null,e.subtitle?a(n,{dimColor:!0,wrap:"truncate",children:[" ",e.subtitle]}):null]})},"FindingRow"),ar=Ie(({count:e,section:t})=>a(h,{flexShrink:0,height:1,marginTop:1,children:[r(n,{dimColor:!0,children:"▼ "}),r(n,{bold:!0,color:"white",children:$t[t].toUpperCase()}),a(n,{dimColor:!0,children:[" (",e,")"]})]}),"SectionHeader"),cr=Ie(({count:e,label:t,status:i})=>a(n,{children:[t,i==="running"?a(n,{children:[" ",r(gt,{type:"dots"})]}):null,i==="error"?r(n,{bold:!0,color:"red",children:" ✖"}):a(n,{dimColor:!0,children:[" (",String(e),")"]})]}),"TabLabel"),dr=Ie(({elapsedMs:e,entries:t,filterActive:i,filterText:s,filterType:o,focused:l,fromCache:c=!1,grouped:p,onViewportHeightChange:d,scrollOffset:S,sectionCounts:R,sectionMessage:w,sectionStatus:A,selectedIndex:E,severityFilter:g,totalAll:I,viewportHeight:B})=>{const X=l?"white":"gray",{measuredHeight:L,ref:F}=yi(B,d);let D=0,V=0;for(const v of t)v.severity==="error"?D+=1:v.severity==="warn"&&(V+=1);const W=[];D>0&&W.push(`${String(D)} error${D===1?"":"s"}`),V>0&&W.push(`${String(V)} warn${V===1?"":"s"}`);const re=W.length>0?` (${W.join(", ")})`:"",Y=(e/1e3).toFixed(1),O=[];for(const[v,T]of p){O.push(r(ar,{count:T.length,section:v},`hdr-${v}`));for(const C of T){const H=t.indexOf(C);O.push(r(lr,{finding:C,isSelected:H===E},C.id))}}let U=0;for(const[,v]of p)U+=2+v.length;const K=U>L&&L>0;return a(h,{borderColor:X,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[a(h,{flexShrink:0,gap:1,paddingX:1,children:[r(n,{bold:!0,inverse:!0,children:" DOCTOR "}),a(n,{wrap:"truncate",children:[t.length,t.length===I?"":`/${String(I)}`," finding",t.length===1?"":"s",re]}),g?r(n,{bold:!0,color:St[g],inverse:!0,children:` ${g.toUpperCase()} ONLY `}):null,c?r(n,{bold:!0,color:"cyan",inverse:!0,children:" CACHED "}):null,a(n,{dimColor:!0,children:[" · ",Y,"s"]})]}),r(h,{flexShrink:0,paddingX:1,paddingY:1,children:r(Gt,{isFocused:l,keyMap:{next:[],previous:[],useNumbers:!1,useTab:!1},onChange:P(()=>{},"onChange"),showIndex:!1,value:o,children:ye.map(({id:v,label:T})=>r(Yt,{name:v,children:r(cr,{count:R[v],label:T,status:A[v]})},v))})}),(()=>{const v=Object.keys(A).filter(T=>A[T]==="running"&&w[T]).map(T=>w[T]);return v.length===0?null:r(h,{flexShrink:0,paddingX:1,children:a(n,{dimColor:!0,wrap:"truncate",children:[r(gt,{type:"dots"})," ",v.join(" · ")]})})})(),i&&a(h,{flexShrink:0,paddingX:1,children:[r(n,{bold:!0,color:"white",children:"/ "}),r(n,{children:s}),r(n,{inverse:!0,children:" "})]}),a(h,{flexDirection:"row",flexGrow:1,overflow:"hidden",ref:F,children:[r(h,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:r(h,{flexDirection:"column",marginTop:-S,children:O.length>0?O:r(h,{marginTop:1,children:r(n,{dimColor:!0,children:"No findings match the current filter."})})})}),K&&r(h,{flexShrink:0,marginLeft:1,marginRight:1,children:r(Kt,{contentHeight:U,placement:"inset",scrollOffset:S,style:"block",viewportHeight:L})})]},`list-${o}-${s}`)]})},"DoctorListPanel");var ur=Object.defineProperty,je=P((e,t)=>ur(e,"name",{value:t,configurable:!0}),"g$1");const hr=je(e=>{if(e.kind==="outdated")return{command:`vis update ${e.entry.packageName}`,description:`Update ${e.entry.packageName} to ${e.entry.newRange}`};if(e.kind==="duplicate")return{command:`vis dedupe ${e.pkg.name}`,description:`Dedupe ${e.pkg.name} (${String(e.pkg.versions.length)} versions)`}},"buildUpdateAction"),pr=je(e=>{if(e.kind==="optimization")return{command:`vis optimize ${e.entry.packageName}`,description:`Replace ${e.entry.packageName} with ${e.entry.replacement}`}},"buildOptimizeAction"),gr=je(e=>{if(e.kind!=="outdated"&&e.kind!=="vulnerability"&&e.kind!=="socket")return;const t=e.kind==="outdated"?e.entry.packageName:e.packageName,i=["// Add to vis.config.ts:","security: {"," acceptedRisks: {",` "${t}": {`,' reason: "explain why this risk is acceptable",',' expiresAt: "YYYY-MM-DD",'," },"," },","},"].join(`
3
- `);return{command:i,configSnippet:i,description:`Acknowledge risk for ${t}`}},"buildAckAction"),fr=100,mr=40,yr=10,kr=je(({autoExitSeconds:e=0,banner:t,fromCache:i=!1,startedAt:s,store:o})=>{const{exit:l}=qt(),{columns:c,rows:p}=Jt(),d=ei(o.subscribe,o.getSnapshot),[S,R]=xe(!1),[w,A]=xe(!1),[E,g]=xe(0),[I,B]=xe(()=>Date.now());Be(()=>{const y=setInterval(()=>{B(Date.now())},1e3);return()=>{clearInterval(y)}},[]);const X=I-s,L=Xe(null),F=Xe(null),D=d.entries[d.selectedIndex]??null,V=De(()=>{const y={dependencies:0,optimization:0,runtime:0,security:0};for(const m of d.all)y[m.section]+=1;return y},[d.all]),W=t?t.hint?5:4:0,re=De(()=>{for(const y of Object.keys(d.sectionStatus))if(d.sectionStatus[y]==="running"&&d.sectionMessage[y])return 1;return 0},[d.sectionStatus,d.sectionMessage]),Y=c>=fr,O=Y?Math.max(1,p-W-2):Math.floor(p*.55),U=De(()=>Math.max(1,O-6-re-(d.filterActive?1:0)),[O,re,d.filterActive]),[K,v]=xe(U),T=K>0?K:U,C=De(()=>{let y=0;for(const[,m]of d.grouped)y+=2+m.length;return y},[d.grouped]),H=Math.max(0,C-T);Be(()=>{g(y=>Math.min(y,H))},[H]);const de=We(y=>{let m=0,k=0;for(const[,Se]of d.grouped){m+=2;for(let le=0;le<Se.length;le++){if(k===y)return m;m+=1,k+=1}}return m},[d.grouped]),N=We(y=>{const m=de(y);g(k=>m>k+T-2?Math.min(H,Math.max(0,m-T+2)):m<k+1?Math.max(0,m-1):k)},[de,T,H]);if(Be(()=>{F.current?.scrollToTop()},[D?.id]),Xt((y,m)=>{if(y==="c"&&m.ctrl){l();return}if(!w){if(S){m.escape||y==="?"?R(!1):y==="q"?(R(!1),A(!0)):m.downArrow||y==="j"?L.current?.scrollBy(1):(m.upArrow||y==="k")&&L.current?.scrollBy(-1);return}if(y==="?"){R(!0);return}if(y==="q"){A(!0);return}if(m.tab){o.setFocusedPanel(d.focusedPanel==="list"?"detail":"list");return}if(d.filterActive){if(m.escape||m.return){o.setFilterActive(!1);return}if(m.backspace){g(0),o.setFilter(d.filterText.slice(0,-1));return}y&&!m.ctrl&&!m.meta&&(g(0),o.setFilter(d.filterText+y));return}if(d.focusedPanel==="list"&&(m.leftArrow||m.rightArrow)){const k=ye.findIndex(le=>le.id===d.filterType),Se=m.rightArrow?(k+1)%ye.length:(k-1+ye.length)%ye.length;g(0),F.current?.scrollToTop(),o.setFilterType(ye[Se].id);return}if(d.focusedPanel==="list"){if(m.downArrow||y==="j"){const k=Math.min(d.selectedIndex+1,d.entries.length-1);o.setSelectedIndex(k),N(k);return}if(m.upArrow||y==="k"){const k=Math.max(d.selectedIndex-1,0);o.setSelectedIndex(k),N(k);return}if(m.pageDown){const k=Math.min(d.selectedIndex+10,d.entries.length-1);o.setSelectedIndex(k),N(k);return}if(m.pageUp){const k=Math.max(d.selectedIndex-10,0);o.setSelectedIndex(k),N(k);return}if(m.home){o.setSelectedIndex(0),g(0);return}if(m.end){const k=d.entries.length-1;o.setSelectedIndex(k),N(k);return}if(y==="/"){o.setFilterActive(!0);return}if(y==="e"){o.setSeverityFilter(d.severityFilter==="error"?void 0:"error"),g(0);return}if(y==="w"){o.setSeverityFilter(d.severityFilter==="warn"?void 0:"warn"),g(0);return}if(y==="u"&&D){const k=hr(D);k&&(o.setPendingAction(k),l());return}if(y==="o"&&D){const k=pr(D);k&&(o.setPendingAction(k),l());return}if(y==="a"&&D){const k=gr(D);k&&(o.setPendingAction(k),l());return}if(y==="d"){o.setFocusedPanel("detail");return}return}if(m.escape||m.leftArrow){o.setFocusedPanel("list");return}if(m.downArrow||y==="j"){F.current?.scrollBy(1);return}if(m.upArrow||y==="k"){F.current?.scrollBy(-1);return}if(m.pageDown){F.current?.scrollBy(10);return}if(m.pageUp){F.current?.scrollBy(-10);return}if(m.home){F.current?.scrollToTop();return}m.end&&F.current?.scrollToBottom()}},{isActive:!0}),c<mr||p<yr)return r(h,{alignItems:"center",height:p,justifyContent:"center",width:c,children:a(n,{color:"yellow",children:["Terminal too small (",c,"x",p,")"]})});const Q=d.focusedPanel==="detail",ee=[a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"q"}),r(n,{dimColor:!0,children:"QUIT"})]},"q"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"?"}),r(n,{dimColor:!0,children:"HELP"})]},"?"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"↑↓"}),r(n,{dimColor:!0,children:Q?"SCROLL":"NAV"})]},"nav"),Q?a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"←/Esc"}),r(n,{dimColor:!0,children:"LIST"})]},"lr"):a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"←→"}),r(n,{dimColor:!0,children:"SECTION"})]},"lr"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"/"}),r(n,{dimColor:!0,children:"SEARCH"})]},"search"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"e/w"}),r(n,{dimColor:!0,children:"SEVERITY"})]},"sev"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"u/o/a"}),r(n,{dimColor:!0,children:"ACTION"})]},"actions"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"Tab"}),r(n,{dimColor:!0,children:"PANEL"})]},"tab")],ue=r(h,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",flexShrink:0,children:r(h,{gap:2,overflow:"hidden",paddingX:1,children:ee})}),he=a(Wt,{footer:a(n,{dimColor:!0,children:[r(n,{bold:!0,color:"white",children:"↑↓"})," scroll ",r(n,{bold:!0,color:"white",children:"?"}),"/",r(n,{bold:!0,color:"white",children:"Esc"})," close"]}),scrollRef:L,title:"DOCTOR — KEYBOARD SHORTCUTS",visible:S,width:56,children:[a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"NAVIGATION"})]}),a(h,{children:[r(h,{width:26,children:a(n,{children:[r(n,{bold:!0,color:"white",children:" ↑/k "}),r(n,{dimColor:!0,children:"Move up"})]})}),a(n,{children:[r(n,{bold:!0,color:"white",children:" ↓/j "}),r(n,{dimColor:!0,children:"Move down"})]})]}),a(h,{children:[r(h,{width:26,children:a(n,{children:[r(n,{bold:!0,color:"white",children:" PgUp"}),r(n,{dimColor:!0,children:" Jump up 10"})]})}),a(n,{children:[r(n,{bold:!0,color:"white",children:" PgDn"}),r(n,{dimColor:!0,children:" Jump down 10"})]})]}),a(h,{children:[r(h,{width:26,children:a(n,{children:[r(n,{bold:!0,color:"white",children:" Home"}),r(n,{dimColor:!0,children:" Jump to top"})]})}),a(n,{children:[r(n,{bold:!0,color:"white",children:" End"}),r(n,{dimColor:!0,children:" Jump to bottom"})]})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" Tab"}),r(n,{dimColor:!0,children:" Switch panel"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" →/←"}),r(n,{dimColor:!0,children:" Section tabs (list) / Focus list (detail)"})]})]}),a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"FILTER"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" /"}),r(n,{dimColor:!0,children:" Open text filter (Esc/Enter to close)"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" e"}),r(n,{dimColor:!0,children:" Toggle errors-only filter"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" w"}),r(n,{dimColor:!0,children:" Toggle warns-only filter"})]})]}),a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"ACTIONS"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" u"}),r(n,{dimColor:!0,children:" Exit + suggest update / dedupe command"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" o"}),r(n,{dimColor:!0,children:" Exit + suggest optimize command"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" a"}),r(n,{dimColor:!0,children:" Exit + print risk-ack snippet"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" d"}),r(n,{dimColor:!0,children:" Focus detail panel"})]})]}),a(h,{flexDirection:"column",children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"EXIT"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" q"}),r(n,{dimColor:!0,children:" Quit (with countdown)"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" Ctrl+C"}),r(n,{dimColor:!0,children:" Quit immediately"})]})]})]}),pe=r(dr,{elapsedMs:X,entries:d.entries,filterActive:d.filterActive,filterText:d.filterText,filterType:d.filterType,focused:d.focusedPanel==="list",fromCache:i,grouped:d.grouped,onViewportHeightChange:v,scrollOffset:E,sectionCounts:V,sectionMessage:d.sectionMessage,sectionStatus:d.sectionStatus,selectedIndex:d.selectedIndex,severityFilter:d.severityFilter,totalAll:d.all.length,viewportHeight:T}),ge=t?r(Yi,{hint:t.hint,message:t.message,severity:t.severity,title:t.title}):null,$e=r(rr,{finding:D,focused:d.focusedPanel==="detail",scrollRef:F});if(Y){const y=Math.floor(c*.4);return a(h,{flexDirection:"column",height:p,width:c,children:[ge,a(h,{flexDirection:"row",flexGrow:1,children:[r(h,{flexGrow:1,children:pe}),r(h,{width:y,children:$e})]}),ue,r(Je,{autoExitSeconds:e||3,onCancel:P(()=>{A(!1)},"onCancel"),visible:w}),he]})}return a(h,{flexDirection:"column",height:p,width:c,children:[ge,r(h,{height:O,children:pe}),r(h,{flexGrow:1,children:$e}),ue,r(Je,{autoExitSeconds:e||3,onCancel:P(()=>{A(!1)},"onCancel"),visible:w}),he]})},"VisDoctorApp");var wr=Object.defineProperty,ve=P((e,t)=>wr(e,"name",{value:t,configurable:!0}),"n");const vr=ve(e=>e.replaceAll(/[$()+.?[\\\]^{|}]/g,String.raw`\$&`),"escapeRegex"),br=ve(e=>{const t=e.split("*").map(i=>vr(i));return new RegExp(`^${t.join(".*")}$`,"i")},"compilePattern"),$r=ve(e=>e?e.split(",").map(t=>t.trim()).filter(t=>t.length>0).map(t=>br(t)):[],"parseFilterPatterns"),Ne=ve((e,t)=>{for(const i of t)if(i.test(e))return!0;return!1},"matchesAny"),Sr=ve((e,t)=>{if(t.length===0)return e;const i=e.outdated.filter(d=>Ne(d.packageName,t)),s=e.duplicates.filter(d=>Ne(d.name,t)),o=e.optimizations.filter(d=>Ne(d.packageName,t));let l=0,c=0,p=0;for(const d of i)d.vulnerabilities&&(l+=d.vulnerabilities.length),d.socketReport&&(c+=d.socketReport.alerts.length,d.socketReport.score.overall<Le&&(p+=1));return{...e,duplicates:s,optimizations:o,outdated:i,socketIssues:{alerts:c,lowScore:p},vulnCount:l}},"applyFilter"),Ct=ve((e,t)=>t.length===0?[...e]:e.filter(i=>{if(i.kind==="runtime")return!0;const s=i.kind==="duplicate"?i.pkg.name:i.kind==="outdated"||i.kind==="optimization"?i.entry.packageName:i.packageName;return Ne(s,t)}),"filterFindingsByPattern");var Cr=Object.defineProperty,be=P((e,t)=>Cr(e,"name",{value:t,configurable:!0}),"r");const xt=["dependencies","security","optimization","runtime"],rt=be(e=>{const t=new Set;if(!e)return t;for(const i of e.split(",")){const s=i.trim().toLowerCase();xt.includes(s)&&t.add(s)}return t},"parseSectionList"),xr=be((e,t)=>{if(e!==void 0&&e!=="")return rt(e);const i=rt(t);return new Set(xt.filter(s=>!i.has(s)))},"resolveSections"),Rt=be(e=>{const t={micro:0,native:0,preferred:0,socket:0,total:e.length};for(const i of e)switch(i.category){case"micro-utility":{t.micro+=1;break}case"native":{t.native+=1;break}case"preferred":{t.preferred+=1;break}case"socket":{t.socket+=1;break}}return t},"summarizeOptimizations"),oe=be((e,t)=>{if(!e.sections.has(t))return"skip";switch(t){case"dependencies":return e.outdated.length>0||e.duplicates.length>0?"warn":"ok";case"optimization":return e.optimizations.length>0?"warn":"ok";case"runtime":return e.runtime.some(i=>i.status==="warn")?"warn":"ok";case"security":return e.vulnCount>0||e.socketIssues.alerts>0?"error":e.socketIssues.lowScore>0?"warn":"ok";default:return"ok"}},"sectionStatus"),Rr=be((e,t)=>{const i=Rt(e.optimizations),s={dependencies:oe(e,"dependencies"),optimization:oe(e,"optimization"),runtime:oe(e,"runtime"),security:oe(e,"security")},o=new Set([...Object.values(s),e.supplyChain.status]),l=o.has("error")?"error":o.has("warn")?"warn":"ok";return{dependencies:{duplicates:e.duplicates.length,installed:e.installedCount,outdated:e.outdated.length,status:s.dependencies},elapsedMs:e.elapsedMs,optimizations:{microUtilities:i.micro,native:i.native,preferred:i.preferred,socket:i.socket,status:s.optimization,total:i.total},packageManager:t,runtime:e.runtime.map(c=>({detail:c.detail,id:c.id,message:c.message,status:c.status})),runtimeStatus:s.runtime,security:{alerts:e.socketIssues.alerts,lowScorePackages:e.socketIssues.lowScore,status:s.security,vulnerabilities:e.vulnCount},status:l,supplyChain:{findings:e.supplyChain.findings.map(c=>({detail:c.detail,label:c.label,severity:c.severity})),status:e.supplyChain.status},workspaces:e.workspaceCount}},"buildJsonPayload"),nt=be((e,t)=>{const i=e.runtime.some(o=>o.status==="warn"),s=e.vulnCount>0||e.socketIssues.alerts>0;return t?s||e.outdated.length>0||e.duplicates.length>0||i:s},"shouldFail");var Tr=Object.defineProperty,_e=P((e,t)=>Tr(e,"name",{value:t,configurable:!0}),"i");const Ar=/^(@[\w./-]+\/[\w./-]+|[\w.-]+)@(.+)$/,Ir=_e(e=>{const t=Ar.exec(e);if(t)return{name:t[1],version:t[2]}},"parsePatchKey"),Dr=_e((e,t)=>{let i;try{if(t==="pnpm"){const o=te(e,"pnpm-workspace.yaml");Fe(o)&&(i=Mt(o)?.patchedDependencies)}else if(t==="bun"){const o=te(e,"package.json");Fe(o)&&(i=ht(o)?.patchedDependencies)}}catch{return[]}if(!i||typeof i!="object")return[];const s=[];for(const[o,l]of Object.entries(i)){if(typeof l!="string"||l.length===0)continue;const c=Ir(o);c&&s.push({name:c.name,patchFile:l,resolvedPatchFile:Ut(l)?l:pt(e,l),version:c.version})}return s},"readPatchedDependencies"),Pr=_e(e=>{const t=[];for(const i of e)Fe(i.resolvedPatchFile)||t.push({entry:i,kind:"missing-file"});return t},"findPatchIssues");var Or=Object.defineProperty,Tt=P((e,t)=>Or(e,"name",{value:t,configurable:!0}),"a");const ot=Tt(e=>e.some(t=>t.severity==="error")?"error":e.some(t=>t.severity==="warn")?"warn":"ok","rollUpStatus"),Nr=Tt((e,t={})=>{const i=[],s=e?.security;if(!s)return i.push({detail:"Use defineConfig() from '@visulima/vis/config' to apply secure defaults.",label:"No security config — running with the PM's native defaults",severity:"warn"}),{findings:i,status:ot(i)};s.minimumReleaseAge===void 0?i.push({detail:"Set security.minimumReleaseAge to block packages published in the last N minutes (mitigates supply-chain attacks).",label:"minimumReleaseAge is not set",severity:"warn"}):s.minimumReleaseAge===0?i.push({detail:"New packages can be installed immediately after publishing. Consider setting a non-zero cooldown.",label:"minimumReleaseAge is explicitly 0",severity:"warn"}):i.push({label:`minimumReleaseAge: ${String(s.minimumReleaseAge)} minutes`,severity:"ok"}),s.trustPolicy===void 0||s.trustPolicy==="off"?i.push({detail:"Packages whose trust level has decreased will not be blocked. Consider 'no-downgrade'.",label:`trustPolicy: ${s.trustPolicy??"not set"}`,severity:"warn"}):i.push({label:`trustPolicy: ${s.trustPolicy}`,severity:"ok"}),s.blockExoticSubdeps===void 0||!s.blockExoticSubdeps?i.push({detail:"Transitive dependencies can pull code from git repos or tarball URLs. Set to true to block.",label:`blockExoticSubdeps: ${String(s.blockExoticSubdeps??!1)}`,severity:"warn"}):i.push({label:"blockExoticSubdeps: true",severity:"ok"});const o=s.allowBuilds?Object.keys(s.allowBuilds).length:0;if(o===0?i.push({detail:"Lifecycle scripts are blocked by default. List trusted packages here to opt them back in (e.g. esbuild, @prisma/client).",label:"allowBuilds: not configured",severity:"warn"}):i.push({label:`allowBuilds: ${String(o)} ${o===1?"entry":"entries"}`,severity:"ok"}),s.strictDepBuilds&&o===0&&i.push({detail:"All dependencies with build scripts will be blocked. Run 'vis approve-builds' to populate allowBuilds.",label:"strictDepBuilds is on but allowBuilds is empty",severity:"error"}),t.workspaceRoot){const l=ki(t.workspaceRoot);if(l.length>0){const c=[...new Set(l.map(p=>p.tool))].sort((p,d)=>p.localeCompare(d)).join(", ");i.push({detail:"Run `vis migrate verify` for the full list, then re-run `vis migrate <tool>` to clean up.",label:`${String(l.length)} leftover ${l.length===1?"reference":"references"} to ${c}`,severity:"warn"})}}if(t.workspaceRoot&&t.packageManager){const l=Dr(t.workspaceRoot,t.packageManager);if(l.length>0){const c=Pr(l);if(c.length===0)i.push({label:`patchedDependencies: ${String(l.length)} ${l.length===1?"entry":"entries"} resolved`,severity:"ok"});else for(const p of c)i.push({detail:`Referenced from ${t.packageManager==="pnpm"?"pnpm-workspace.yaml":"package.json"} but the file is not present at ${p.entry.patchFile}.`,label:`patchedDependencies: missing patch file for ${p.entry.name}@${p.entry.version}`,severity:"error"})}}return{findings:i,status:ot(i)}},"buildSupplyChainPosture");var Fr=Object.defineProperty,$=P((e,t)=>Fr(e,"name",{value:t,configurable:!0}),"u");const G=$(e=>e>=1e3?`${(e/1e3).toFixed(1)}s`:`${String(Math.round(e))}ms`,"fmtDuration"),Pe=$(async(e,t,i,s)=>{if(!e)return i();e.start(t);const o=Date.now();try{const l=await i(),c=Date.now()-o,{status:p,summary:d}=s(l,c);return e.finish(t,p,d),l}catch(l){const c=Date.now()-o,p=l instanceof Error?l.message:String(l);throw e.finish(t,"error",`${p} (${G(c)})`),l}},"tracked"),Mr=$((e,t)=>{const i={duplicates:t.duplicates,elapsedMs:0,installedCount:0,optimizations:t.optimizations,outdated:t.outdated,runtime:t.runtime,sections:new Set([e]),socketIssues:{alerts:0,lowScore:0},supplyChain:{findings:[],status:"ok"},vulnCount:0,workspaceCount:0};return bt(i)},"buildSectionFindings"),st=$(async e=>{const{filterPatterns:t,installed:i,progress:s,resolveCodemods:o,sections:l,store:c,visConfig:p,workspaceRoot:d}=e,S=l.has("dependencies"),R=l.has("security"),w=l.has("optimization"),A=l.has("runtime"),E=$((f,M)=>Ct(Mr(f,M),t),"sectionFindings"),g=at(d),{packageManager:I}=ct(d),B=Ze(te(d,"package.json"),!1),X=ft(d),L=new Set(B);for(const f of X){const M=Ze(te(pt(d,f),"package.json"),!1);for(const z of M)L.add(z)}const F=zt(d),D=dt(d,I),V=ut(p?.security?.socket),W=p?.security?.socket?.acceptedRisks,re=si(d,g.name),Y={exclude:[],ignore:[],include:[],includeLocked:!1,includePrerelease:!1,security:!0,target:"latest"},O=S?pi(d,g.name):[],U=w?li(L):[],K=w?ai(L,re,g,!1):[],v=new Set(U.map(f=>f.packageName)),T=K.filter(f=>!v.has(f.packageName)),C=[...U,...T],H=A?zi():[];c&&(S&&c.startSection("dependencies",D.size>0?"checking outdated catalog dependencies":"scanning duplicates"),R&&c.startSection("security",i.length>0?`scanning ${String(i.length)} packages for advisories`:"no installed packages to scan"),w&&c.startSection("optimization","matching e18e + socket overrides"),A&&c.startSection("runtime","running runtime diagnostics")),c&&A&&c.completeSection("runtime",E("runtime",{duplicates:[],optimizations:[],outdated:[],runtime:H}));const de=(S||R)&&D.size>0?Pe(s,"outdated",()=>jt(D,Y,F,void 0,d,V,W),(f,M)=>{const z=f.outdated.length;return{status:z>0?"warn":"ok",summary:z>0?`${String(z)} outdated · ${G(M)}`:`up to date · ${G(M)}`}}):Promise.resolve({failed:[],ignored:[],outdated:[]}),N=R&&i.length>0?Pe(s,"vulnerabilities",()=>Et(i.map(f=>({name:f.name,version:f.version}))),(f,M)=>{let z=0;for(const ne of f.values())z+=ne.length;return{status:z>0?"error":"ok",summary:z>0?`${String(z)} found · ${G(M)}`:`none found · ${G(M)}`}}):Promise.resolve(new Map),Q=R&&V&&i.length>0?Pe(s,"socket",()=>Bt(i.map(f=>({name:f.name,version:f.version})),V),(f,M)=>{let z=0,ne=0;for(const Ke of f.values())z+=Ke.alerts.length,Ke.score.overall<Le&&(ne+=1);const Ye=z+ne;return{status:Ye>0?"warn":"ok",summary:Ye>0?`${String(z)} alert${z===1?"":"s"}, ${String(ne)} low-score · ${G(M)}`:`clean · ${G(M)}`}}):Promise.resolve(new Map);let ee,ue,he,pe;const ge=de.catch(f=>(ee=f instanceof Error?f.message:String(f),c||u.warn(`Outdated scan failed: ${ee}`),{failed:[],ignored:[],outdated:[]})),$e=N.catch(f=>(ue=f instanceof Error?f.message:String(f),c||u.warn(`Vulnerability scan failed: ${ue}`),new Map)),y=Q.catch(f=>(he=f instanceof Error?f.message:String(f),c||u.warn(`Socket scan failed: ${he}`),new Map)),m=c&&S?ge.then(f=>{if(ee){c.failSection("dependencies",ee);return}c.completeSection("dependencies",E("dependencies",{duplicates:O,optimizations:[],outdated:f.outdated,runtime:[]}))}):void 0,k=c&&R?Promise.all([ge,$e,y]).then(([f])=>{const M=ee??ue??he;if(M){c.failSection("security",M);return}c.completeSection("security",E("security",{duplicates:[],optimizations:[],outdated:f.outdated,runtime:[]}))}):void 0,Se=(async()=>{if(o&&w&&C.length>0&&await Pe(s,"codemods",async()=>(await ci(C),C),(f,M)=>{const z=f.filter(ne=>ne.hasCodemod||ne.category==="socket").length;return{status:"ok",summary:`${String(z)} auto-fixable · ${G(M)}`}}).catch(f=>{pe=f instanceof Error?f.message:String(f)}),c&&w){if(pe){c.failSection("optimization",pe);return}c.completeSection("optimization",E("optimization",{duplicates:[],optimizations:C,outdated:[],runtime:[]}))}})(),[le,It,Dt]=await Promise.all([ge,$e,y]);await Promise.all([m,k,Se]);let He=0,Ge=0;if(R&&V)for(const f of Dt.values())He+=f.alerts.length,f.score.overall<Le&&(Ge+=1);let Ee=0;if(R){for(const f of le.outdated)f.vulnerabilities&&f.vulnerabilities.length>0&&(Ee+=f.vulnerabilities.length);for(const f of It.values())Ee+=f.length}return{duplicates:O,installedCount:i.length,optimizations:w?C:[],outdated:S?le.outdated:[],runtime:H,sections:l,socketIssues:{alerts:He,lowScore:Ge},supplyChain:Nr(p,{packageManager:I,workspaceRoot:d}),vulnCount:Ee,workspaceCount:X.length}},"streamScans"),zr=$(e=>{switch(e){case"error":return Re(j.failure);case"skip":return b(j.dash);case"warn":return ze(j.warning);default:return we(j.success)}},"sectionIcon"),ce=$((e,t)=>{const i=process.stderr.columns??80,s=Math.max(20,Math.min(i-2,60)),o=j.dash.repeat(2),l=`${zr(t)} ${ae(e)}`,c=l.replaceAll(/\[[0-9;]*m/g,"").length,p=Math.max(0,s-c-o.length-2);return`${o} ${l} ${b(j.dash.repeat(p))}`},"heading"),J=$(e=>` ${we(j.success)} ${e}`,"itemOk"),Z=$(e=>` ${ze(j.warning)} ${e}`,"itemWarn"),Ue=$(e=>` ${Re(j.failure)} ${e}`,"itemError"),At=$(e=>` ${b(j.dash)} ${b(e)}`,"itemSkip"),q=$((e,t,i)=>{const s=`${ae(String(e))} ${b(t)}`;return i?`${s} ${b(`(${i})`)}`:s},"countLine"),jr=$(e=>{if(e.sections.has("dependencies")){if(u.log(""),u.log(ce("Dependencies",oe(e,"dependencies"))),u.log(J(q(e.installedCount,"packages installed"))),e.outdated.length>0){const t=e.outdated.filter(l=>l.updateType==="major").length,i=e.outdated.filter(l=>l.updateType==="minor").length,s=e.outdated.filter(l=>l.updateType==="patch").length,o=[];t>0&&o.push(`${String(t)} major`),i>0&&o.push(`${String(i)} minor`),s>0&&o.push(`${String(s)} patch`),u.log(Z(q(e.outdated.length,"outdated",o.join(", "))))}else u.log(J("All dependencies up to date"));e.duplicates.length>0?u.log(Z(q(e.duplicates.length,"packages with duplicate versions"))):u.log(J("No duplicate dependencies"))}},"displayDependencies"),Er=$(e=>{e.sections.has("security")&&(u.log(""),u.log(ce("Security",oe(e,"security"))),e.vulnCount>0?u.log(Ue(q(e.vulnCount,`vulnerabilit${e.vulnCount===1?"y":"ies"} found`))):u.log(J("No known vulnerabilities")),e.socketIssues.alerts>0&&u.log(Z(q(e.socketIssues.alerts,`Socket.dev security alert${e.socketIssues.alerts===1?"":"s"}`))),e.socketIssues.lowScore>0&&u.log(Z(q(e.socketIssues.lowScore,`package${e.socketIssues.lowScore===1?"":"s"} with low security score`))),e.socketIssues.alerts===0&&e.socketIssues.lowScore===0&&e.vulnCount===0&&u.log(J("No security issues detected")))},"displaySecurity"),Br=$(e=>{if(!e.sections.has("optimization"))return;u.log(""),u.log(ce("Optimization",oe(e,"optimization")));const t=Rt(e.optimizations);if(t.total===0){u.log(J("No optimizations available"));return}t.native>0&&u.log(Z(q(t.native,"replaceable with native APIs"))),t.preferred>0&&u.log(Z(q(t.preferred,"with lighter alternatives"))),t.micro>0&&u.log(Z(q(t.micro,"trivial micro-utilities"))),t.socket>0&&u.log(Z(q(t.socket,"@socketregistry overrides available")))},"displayOptimization"),Lr=$(e=>{u.log(""),u.log(ce("Supply Chain",e.supplyChain.status));for(const t of e.supplyChain.findings){const i=t.severity==="ok"?J(t.label):t.severity==="error"?Ue(t.label):Z(t.label);u.log(i),t.detail&&u.log(` ${b(j.arrow)} ${b(t.detail)}`)}e.supplyChain.status!=="ok"&&u.log(` ${b(j.arrow)} ${b("Configure with security.* in vis.config.ts. See `vis check --security-config` for details.")}`)},"displaySupplyChain"),Vr=$(e=>{if(e.sections.has("runtime")){u.log(""),u.log(ce("Runtime",oe(e,"runtime")));for(const t of e.runtime)t.status==="ok"?u.log(J(t.message)):t.status==="skip"?u.log(At(t.message)):u.log(Z(t.message))}},"displayRuntime"),_r=$((e,t)=>{const i=e.vulnCount,s=e.runtime.filter(l=>l.status==="warn").length,o=e.outdated.length+e.duplicates.length+e.optimizations.length+s;if(t){if(i===0&&o===0)u.success(`Everything looks good! ${b(`(${G(e.elapsedMs)})`)}`);else{const l=[];i>0&&l.push(Re(`${String(i)} security`)),o>0&&l.push(ze(`${String(o)} improvement${o===1?"":"s"}`)),u.log(`${Re(j.failure)} ${l.join(", ")} ${b(`(${G(e.elapsedMs)})`)}`)}return}u.log(""),u.log(ce("Summary","ok")),i===0&&o===0?u.success(`Everything looks good! ${b(`(${G(e.elapsedMs)})`)}`):(i>0&&u.error(`${String(i)} security issue${i===1?"":"s"}`),o>0&&u.log(` ${Te(j.arrow)} ${ae(String(o))} ${b(`improvement${o===1?"":"s"} available`)} ${b(`(${G(e.elapsedMs)})`)}`))},"displaySummary"),Ur=$(e=>{const t=[];if(e.outdated.length>0&&t.push("vis update — update outdated dependencies"),(e.vulnCount>0||e.socketIssues.alerts>0)&&t.push("vis audit — detailed security analysis"),e.optimizations.length>0&&t.push("vis optimize — apply optimizations interactively"),e.duplicates.length>0&&t.push("vis dedupe — reduce duplicate versions"),t.length>0){u.log(""),u.log(ae("Next steps:"));for(const i of t)u.log(` ${b(j.arrow)} ${i}`)}u.log("")},"displayActions"),Hr=$((e,t)=>{t||(jr(e),Er(e),Br(e),Vr(e),Lr(e)),_r(e,t)},"displayResults"),Gr=$((e,t,i,s,o)=>{const l=[],c=e.has("dependencies"),p=e.has("security"),d=e.has("optimization");return(c||p)&&t>0&&l.push({id:"outdated",label:"Outdated catalog dependencies"}),p&&s>0&&l.push({id:"vulnerabilities",label:"Known vulnerabilities (OSV)"}),p&&i&&s>0&&l.push({id:"socket",label:"Socket.dev supply-chain reports"}),d&&o&&l.push({id:"codemods",label:"Codemod availability"}),l},"planScanTasks"),Yr=$(e=>{if(u.log(""),u.log(`${ae(Te("vis doctor"))} ${b("— project health check")}`),u.log(J(`Detected ${e.packageManagerName} v${e.packageManagerVersion}`)),e.workspaceCount!==void 0&&e.workspaceCount>0&&u.log(J(q(e.workspaceCount,`workspace package${e.workspaceCount===1?"":"s"}`))),e.runtimeFindings.length===0)u.log(J(`Node.js ${e.nodeVersion}`));else{for(const t of e.runtimeFindings){const i=t.severity==="error"?Re:ze;u.log(Ue(`Runtime: ${i(t.message)}`))}u.log(` ${b(j.arrow)} Run ${we("vis toolchain install")} to install pinned versions, or ${we("vis toolchain status")} for the per-tool breakdown.`)}u.log("")},"printBanner"),cn=$(async({logger:e,options:t,visConfig:i,visConfigError:s,workspaceRoot:o})=>{if(!o)throw new Error("Could not determine workspace root.");const l=t.format==="json"||t.json===!0,c=xr(t.only,t.skip),p=!!t.quiet,d=t.progress===!1,S=$r(t.filter);if(c.size===0){u.error("No sections selected. Check your --only / --skip values."),process.exitCode=2;return}const R=Date.now(),w=at(o),A=hi(o),E=!!process.stdout.isTTY,g=!l&&E&&!Lt&&!p&&!d;!l&&!g&&Yr({nodeVersion:process.versions.node,packageManagerName:w.name,packageManagerVersion:w.version,runtimeFindings:A,workspaceCount:void 0});const I=dt(o,ct(o).packageManager),B=gi(o,w.name),X=B.length,L=!!ut(i?.security?.socket),F=ft(o);if(!l&&!p&&!g){const N=F.length>0?b(` · ${String(F.length)} workspace package${F.length===1?"":"s"}`):"";u.log(`${b("·")} ${b("Found")} ${ae(String(X))} ${b(`installed package${X===1?"":"s"}`)}${N}`)}const D=s?{hint:s.file?`Continuing with default settings — fix or regenerate ${s.file} (vis init --force).`:"Continuing with default settings.",message:s.message,severity:"error",title:s.file?`Failed to load ${s.file}`:"Failed to load vis.config"}:void 0,V={bun:"bun.lock",npm:"package-lock.json",pnpm:"pnpm-lock.yaml",yarn:"yarn.lock"}[w.name],W=V?te(o,V):void 0,re=oi(o),Y=t.cache!==!1&&!t.fix?$i({configPath:re,lockfilePath:W,sections:c,socketEnabled:L,workspaceRoot:o}):void 0,O=Y?Si(Y):void 0,U=O!==void 0;let K,v;if(g){const N=O?new tt({activeSections:c,findings:Ct(bt(O),S)}):new tt({activeSections:c}),Q=Qt(Zt.createElement(kr,{banner:D,fromCache:U,startedAt:R,store:N}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0});try{K=O??await st({filterPatterns:S,installed:B,resolveCodemods:!!t.fix,sections:c,store:N,visConfig:i,workspaceRoot:o})}catch(ee){throw Q.unmount(),ee}await Q.waitUntilExit(),v=N.getSnapshot().pendingAction}else if(O)K=O;else{const N=Gr(c,I.size,L,X,!!t.fix),Q=fi(N,{live:!l&&!p&&!d});try{K=await st({filterPatterns:S,installed:B,progress:Q,resolveCodemods:!!t.fix,sections:c,visConfig:i,workspaceRoot:o})}finally{Q.stop()}}const T={...K,elapsedMs:Date.now()-R};if(Y&&!U)try{Ci(Y,T)}catch{}const C=Sr(T,S);if(l){process.stdout.write(`${JSON.stringify(Rr(C,w.name),void 0,2)}
4
- `),t.exitCode&&nt(C,!!t.strict)&&(process.exitCode=1);return}U&&!p&&u.log(`${b("·")} Cached results (use --no-cache to refresh)`),S.length>0&&!p&&u.log(`${b("·")} Filter active: ${Te(t.filter??"")}`),Hr(C,p);const H=C.runtime.some(N=>N.id===Oe&&N.status==="warn"),de=C.sections.has("optimization")&&C.optimizations.length>0;t.fix&&(de||H)?await Kr({force:!!t.fixForce,logger:e,pm:w,recoverOrphans:H,results:C,useEditorconfig:i?.editorconfig??!0,workspaceRoot:o}):p||Ur(C),v&&(process.stdout.write(`
5
- `),process.stdout.write(`${ae("→ ")}${v.description}
6
- `),v.configSnippet?(process.stdout.write(`
7
- `),process.stdout.write(`${b(v.configSnippet)}
8
- `)):process.stdout.write(` ${Te(v.command)}
1
+ var Pt=Object.defineProperty;var P=(e,t)=>Pt(e,"name",{value:t,configurable:!0});import{createRequire as Ot}from"node:module";import{l as Mt,B as qe,aJ as Je,aa as Le,u as Ft,A as ct,U as dt,f as zt,R as ut,J as ht,V as jt,N as Et,a as Bt,p as u,c as ke,aE as z,e as ze,E as b,d as Te,j as le,q as Ae,s as Lt,x as Ut}from"./bin.js";import{M as te,a as Me,n as pt,h as Vt,b as _t,C as gt,j as Ht}from"./config.js";import{render as Gt}from"@visulima/tui";import Yt,{useSyncExternalStore as Kt,useState as Re,useEffect as Xe,useRef as We,useMemo as Be,useCallback as Qe}from"react";import{X as Wt}from"../packem_shared/xxh3-DrAUNq4n.js";import{x as et,A as ft,L as Qt,F as Zt,T as ei,U as ti,a as ii,I as ri}from"./handler42.js";import{c as ni}from"../packem_shared/runtime-check-CBU6W8qG.js";import{f as oi,l as si,s as li}from"../packem_shared/dependency-scan-YdgNVvoz.js";import{jsxs as a,jsx as r,Fragment as ai}from"react/jsx-runtime";import{Box as h}from"@visulima/tui/components/box";import{Dialog as ci}from"@visulima/tui/components/dialog";import{Text as n}from"@visulima/tui/components/text";import{useApp as di}from"@visulima/tui/hooks/use-app";import{useInput as ui}from"@visulima/tui/hooks/use-input";import{useWindowSize as hi}from"@visulima/tui/hooks/use-window-size";import{ScrollView as pi}from"@visulima/tui/components/scroll-view";import{ScrollBar as gi}from"@visulima/tui/components/scroll-bar";import{Spinner as yt}from"@visulima/tui/components/spinner";import{Tab as fi}from"@visulima/tui/components/tab";import{Tabs as mi}from"@visulima/tui/components/tabs";import{u as yi}from"../packem_shared/use-measured-height-DjYgUOKk.js";import{s as ki}from"../packem_shared/verify-WDStBFvK.js";const Nt=Ot(import.meta.url),xe=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,at=P(e=>{if(typeof xe<"u"&&xe.versions&&xe.versions.node){const[t,i]=xe.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return xe.getBuiltinModule(e)}return Nt(e)},"__cjs_getBuiltinModule"),{statSync:qt,rmSync:Ze,writeFileSync:Jt,readFileSync:Xt}=at("node:fs"),{spawnSync:mt}=at("node:child_process");var vi=Object.defineProperty,Ie=P((e,t)=>vi(e,"name",{value:t,configurable:!0}),"r$2");const Ue=Ie(()=>te(Mt(),"doctor"),"getCacheDirectory"),wi=1800*1e3,tt=Ie(e=>{if(!e)return"";try{return String(qt(e).mtimeMs)}catch{return""}},"safeMtime"),bi=2,$i=Ie(e=>{const t=JSON.stringify({configMtime:tt(e.configPath),lockfileMtime:tt(e.lockfilePath),schema:bi,sections:[...e.sections].toSorted(),socketEnabled:e.socketEnabled,workspaceRoot:e.workspaceRoot});return Wt(Buffer.from(t))},"buildDoctorCacheKey"),Si=Ie(e=>{const t=te(Ue(),`${e}.json`);if(Me(t))try{const i=pt(t);if(Date.now()-i.createdAt>i.ttlMs){Ze(t,{force:!0});return}return{...i.results,sections:new Set(i.results.sections)}}catch{Ze(t,{force:!0});return}},"readDoctorCache"),Ci=Ie((e,t,i=wi)=>{Vt(Ue());const s={createdAt:Date.now(),results:{...t,sections:[...t.sections]},ttlMs:i};Jt(te(Ue(),`${e}.json`),JSON.stringify(s,void 0,2),"utf8")},"writeDoctorCache");var xi=Object.defineProperty,V=P((e,t)=>xi(e,"name",{value:t,configurable:!0}),"i$2");const Oe="orphans",Ri=V(()=>{if(process.platform!=="linux")return{id:"inotify",message:"inotify capacity check skipped (not Linux).",status:"skip"};let e;try{const t=Xt("/proc/sys/fs/inotify/max_user_watches","utf8").trim(),i=Number.parseInt(t,10);Number.isFinite(i)&&i>0&&(e=i)}catch{return{id:"inotify",message:"Could not read /proc/sys/fs/inotify/max_user_watches.",status:"warn"}}return e===void 0?{id:"inotify",message:"inotify max_user_watches reported a non-numeric value.",status:"warn"}:e<65536?{detail:{maxWatches:e},id:"inotify",message:`inotify watcher limit is ${String(e)} — large monorepos can exhaust this. Bump now with \`sudo sysctl fs.inotify.max_user_watches=524288\` and persist via \`/etc/sysctl.d/99-vis.conf\` so it survives reboot.`,status:"warn"}:{detail:{maxWatches:e},id:"inotify",message:`inotify capacity OK (${String(e)} watches).`,status:"ok"}},"checkInotifyCapacity"),Ti=V(()=>{const e=!!process.stdin.isTTY,t=!!process.stdout.isTTY;return e&&t?{id:"tty",message:"Interactive TTY available — watch keybinds enabled.",status:"ok"}:!e&&!t?{id:"tty",message:"No TTY on stdin/stdout — running in CI / piped mode (keybinds disabled).",status:"skip"}:{detail:{stdin:String(e),stdout:String(t)},id:"tty",message:e?"stdin is a TTY but stdout is not — output is being captured; keybinds still work.":"stdout is a TTY but stdin is not — keybinds disabled (input is piped).",status:"skip"}},"checkTtyAvailability"),Ai=V(()=>{const e=process.pid;try{return process.platform==="win32"?wt(e):vt(e)}catch{return[]}},"listOrphanPids"),Ii=V(()=>{const e=process.pid;let t;try{t=process.platform==="win32"?wt(e):vt(e)}catch{return{id:Oe,message:"Could not enumerate processes (ps/tasklist failed).",status:"warn"}}if(t.length===0)return{id:Oe,message:"No orphaned vis/task-runner processes detected.",status:"ok"};if(t.length<=2)return{detail:{count:t.length,pids:t.join(",")},id:Oe,message:`${String(t.length)} possibly orphaned process(es) detected (PIDs: ${t.join(", ")}). Likely benign.`,status:"skip"};const i=process.platform==="win32"?t.map(s=>`taskkill /F /PID ${String(s)}`).join(" & "):`kill ${t.join(" ")}`;return{detail:{count:t.length,pids:t.join(",")},id:"orphans",message:`${String(t.length)} possibly orphaned vis/task-runner processes — run \`vis doctor --fix\` to clean them up, or kill them manually: ${i}`,status:"warn"}},"checkOrphanedRunners"),Di=V((e={})=>{const t=e.enumerate??Ai,i=e.force===!0?"SIGKILL":"SIGTERM",s=e.kill??Fi,o=t(),l=[],c=[];for(const p of o)try{s(p,i),l.push(p)}catch(d){const S=d.code??d.message;if(S==="ESRCH"){l.push(p);continue}c.push({pid:p,reason:S})}return{failed:c,killed:l}},"killOrphanedRunners"),Pi=V(e=>mt("taskkill",e,{encoding:"utf8"}),"defaultTaskkillRunner"),Oi=V((e,t)=>{process.kill(e,t)},"defaultProcessKill"),Ni=V((e,t,i=Pi)=>{const s=t==="SIGKILL"?["/F","/PID",String(e)]:["/PID",String(e)],o=i(s);if(o.error)throw o.error;if(typeof o.status=="number"&&o.status!==0){const l=o.status===128?"ESRCH":`taskkill exited with code ${String(o.status)}`,c=new Error(l);throw c.code=l,c}},"killViaTaskkill"),Mi=V((e,t,i=Oi)=>{i(e,t)},"killViaSignal"),Fi=V((e,t)=>{if(process.platform==="win32"){Ni(e,t);return}Mi(e,t)},"defaultKill"),kt=V((e,t)=>{const i=mt(e,t,{encoding:"utf8"});if(i.error)throw i.error;if(typeof i.status=="number"&&i.status!==0)throw new Error(`${e} exited with code ${String(i.status)}`);return typeof i.stdout=="string"?i.stdout:""},"runProcessListing"),vt=V(e=>{const t=kt("ps",["-Ao","pid=,command="]),i=[];for(const s of t.split(`
2
+ `)){if(s.length===0)continue;const o=/^\s*(\d+)\s+(.+)$/.exec(s);if(!o)continue;const l=Number.parseInt(o[1]??"",10),c=(o[2]??"").toLowerCase();!Number.isFinite(l)||l===e||(/(?:^|[ /])vis-native(?:\s|$|[-.])/.test(c)||/(?:^|[ /])vis\s+run\b/.test(c)||/(?:^|[ /])task-runner(?:\s|$|[-.])/.test(c))&&i.push(l)}return i},"listOrphansUnix"),wt=V(e=>{const t=kt("tasklist",["/FO","CSV","/NH"]),i=[];for(const s of t.split(/\r?\n/)){if(s.length===0)continue;const o=s.split(/","/).map(p=>p.replaceAll(/^"|"$/g,"")),l=(o[0]??"").toLowerCase(),c=Number.parseInt(o[1]??"",10);!Number.isFinite(c)||c===e||(l==="vis.exe"||l.startsWith("vis-native")||l.includes("task-runner"))&&i.push(c)}return i},"listOrphansWindows"),zi=V(()=>[Ri(),Ti(),Ii()],"runRuntimeDiagnostics");var ji=Object.defineProperty,ye=P((e,t)=>ji(e,"name",{value:t,configurable:!0}),"s$2");const me=[{id:"dependencies",label:"Deps"},{id:"security",label:"Security"},{id:"optimization",label:"Optimize"},{id:"runtime",label:"Runtime"}],Fe=["dependencies","security","optimization","runtime"],ge=ye(e=>{const t=new Map;for(const i of Fe)t.set(i,[]);for(const i of e)t.get(i.section).push(i);for(const[i,s]of t)s.length===0&&t.delete(i);return t},"groupBySection"),fe=ye((e,t,i,s)=>{let o=e.filter(l=>l.section===t);if(s&&(o=o.filter(l=>l.severity===s)),i){const l=i.toLowerCase();o=o.filter(c=>c.title.toLowerCase().includes(l))}return[...o]},"filterFindings"),Ei=ye(e=>{const t={dependencies:"idle",optimization:"idle",runtime:"idle",security:"idle"};for(const i of Fe)e.has(i)&&(t[i]="idle");return t},"initialStatus");class it{static{P(this,"DoctorStore")}static{ye(this,"DoctorStore")}#e;#i=new Set;constructor(t=[]){const i=Array.isArray(t)?{findings:t}:t,s=i.findings??[],o=i.activeSections??new Set(Fe),l=Fe.find(d=>o.has(d))??"dependencies",c=fe(s,l,"",void 0),p=Ei(o);if(s.length>0)for(const d of s)p[d.section]="done";this.#e={all:s,entries:c,filterActive:!1,filterText:"",filterType:l,focusedPanel:"list",grouped:ge(c),pendingAction:void 0,sectionError:{},sectionMessage:{},sectionStatus:p,selectedIndex:0,severityFilter:void 0}}getSnapshot=ye(()=>this.#e,"getSnapshot");subscribe=ye(t=>(this.#i.add(t),()=>{this.#i.delete(t)}),"subscribe");setSelectedIndex(t){const i=Math.max(0,Math.min(t,this.#e.entries.length-1));i!==this.#e.selectedIndex&&this.#t({...this.#e,selectedIndex:i})}setFocusedPanel(t){t!==this.#e.focusedPanel&&this.#t({...this.#e,focusedPanel:t})}setFilterType(t){if(t===this.#e.filterType)return;const i=fe(this.#e.all,t,this.#e.filterText,this.#e.severityFilter);this.#t({...this.#e,entries:i,filterType:t,grouped:ge(i),selectedIndex:0})}setFilter(t){const i=fe(this.#e.all,this.#e.filterType,t,this.#e.severityFilter);this.#t({...this.#e,entries:i,filterText:t,grouped:ge(i),selectedIndex:0})}setFilterActive(t){if(t===this.#e.filterActive)return;if(t){this.#t({...this.#e,filterActive:!0});return}const i=fe(this.#e.all,this.#e.filterType,"",this.#e.severityFilter);this.#t({...this.#e,entries:i,filterActive:!1,filterText:"",grouped:ge(i),selectedIndex:0})}setPendingAction(t){this.#t({...this.#e,pendingAction:t})}setSeverityFilter(t){if(t===this.#e.severityFilter)return;const i=fe(this.#e.all,this.#e.filterType,this.#e.filterText,t);this.#t({...this.#e,entries:i,grouped:ge(i),selectedIndex:0,severityFilter:t})}startSection(t,i){this.#t({...this.#e,sectionMessage:{...this.#e.sectionMessage,[t]:i},sectionStatus:{...this.#e.sectionStatus,[t]:"running"}})}completeSection(t,i){const s=[...this.#e.all,...i],o=fe(s,this.#e.filterType,this.#e.filterText,this.#e.severityFilter),l={...this.#e.sectionMessage};delete l[t],this.#t({...this.#e,all:s,entries:o,grouped:ge(o),sectionMessage:l,sectionStatus:{...this.#e.sectionStatus,[t]:"done"}})}failSection(t,i){this.#t({...this.#e,sectionError:{...this.#e.sectionError,[t]:i},sectionStatus:{...this.#e.sectionStatus,[t]:"error"}})}#t(t){this.#e=t;for(const i of this.#i)try{i()}catch{}}}var Bi=Object.defineProperty,bt=P((e,t)=>Bi(e,"name",{value:t,configurable:!0}),"r$1");const rt={error:0,warn:1},Li=bt(e=>!!e.acceptedRisk,"isAcknowledged"),$t=bt(e=>{const t=[];if(e.sections.has("dependencies")){for(const i of e.outdated)t.push({entry:i,id:`outdated:${i.packageName}`,kind:"outdated",section:"dependencies",severity:"warn",subtitle:`${i.currentRange} → ${i.newRange} (${i.updateType})`,title:i.packageName});for(const i of e.duplicates)t.push({id:`duplicate:${i.name}`,kind:"duplicate",pkg:i,section:"dependencies",severity:"warn",subtitle:`${String(i.versions.length)} versions installed`,title:i.name})}if(e.sections.has("security"))for(const i of e.outdated){if(i.vulnerabilities&&i.vulnerabilities.length>0){const s=i.vulnerabilities[0],o=Li(i)?"warn":"error",l=i.vulnerabilities.length;t.push({entry:i,id:`vuln:${i.packageName}`,kind:"vulnerability",packageName:i.packageName,section:"security",severity:o,subtitle:l===1?`${s.severity} · ${s.id}`:`${String(l)} advisories · top: ${s.severity} ${s.id}`,title:i.packageName})}if(i.socketReport&&i.socketReport.alerts.length>0){const s=Math.round(i.socketReport.score.overall*100);t.push({entry:i,id:`socket:${i.packageName}`,kind:"socket",packageName:i.packageName,section:"security",severity:"warn",subtitle:`${String(i.socketReport.alerts.length)} alert${i.socketReport.alerts.length===1?"":"s"} · score ${String(s)}%`,title:i.packageName})}}if(e.sections.has("optimization"))for(const i of e.optimizations)t.push({entry:i,id:`opt:${i.packageName}`,kind:"optimization",section:"optimization",severity:"warn",subtitle:`${i.category} → ${i.replacement}`,title:i.packageName});if(e.sections.has("runtime"))for(const i of e.runtime)i.status==="warn"&&t.push({diagnostic:i,id:`runtime:${i.id}`,kind:"runtime",section:"runtime",severity:"warn",title:i.message});return t.sort((i,s)=>{if(i.section!==s.section){const o=["dependencies","security","optimization","runtime"];return o.indexOf(i.section)-o.indexOf(s.section)}return rt[i.severity]-rt[s.severity]}),t},"flattenFindings"),St={dependencies:"Dependencies",optimization:"Optimization",runtime:"Runtime",security:"Security"};var Ui=Object.defineProperty,Vi=P((e,t)=>Ui(e,"name",{value:t,configurable:!0}),"a$2");const _i={error:"red",warn:"yellow"},Hi={error:"✖",warn:"⚠"},Gi={error:" ERROR ",warn:" WARN "},Yi=Vi(({children:e,hint:t,message:i,severity:s,title:o})=>{const l=_i[s];return a(h,{borderColor:l,borderStyle:"single",flexDirection:"column",flexShrink:0,paddingX:1,children:[a(h,{gap:1,children:[r(n,{backgroundColor:l,bold:!0,color:"black",children:Gi[s]}),r(n,{bold:!0,color:l,children:Hi[s]}),r(n,{bold:!0,wrap:"truncate-end",children:o})]}),r(n,{wrap:"truncate-end",children:i}),t?r(n,{dimColor:!0,wrap:"truncate-end",children:t}):null,e]})},"ConfigBanner");var Ki=Object.defineProperty,ie=P((e,t)=>Ki(e,"name",{value:t,configurable:!0}),"d");const qi={CRITICAL:"red",HIGH:"red",LOW:"gray",MODERATE:"yellow",UNKNOWN:"gray"},Ji={critical:"red",high:"red",low:"gray",medium:"yellow"},Xi={major:"red",minor:"yellow",patch:"green"},x=ie(({children:e,label:t,width:i=14})=>a(h,{children:[r(h,{width:i,children:a(n,{dimColor:!0,children:[t,":"]})}),typeof e=="string"?r(n,{children:e}):e]}),"FieldRow"),oe=ie(({children:e})=>r(h,{marginTop:1,children:r(n,{bold:!0,color:"white",children:e})}),"SectionTitle"),Wi=ie(({finding:e})=>{const{entry:t}=e,i=Xi[t.updateType]??"white";return a(h,{flexDirection:"column",children:[r(x,{label:"Current",children:t.currentRange}),a(x,{label:"Target",children:[r(n,{children:t.newRange}),a(n,{bold:!0,color:i,children:[" (",t.updateType,")"]})]}),r(x,{label:"Catalog",children:t.catalogName}),t.acceptedRisk?r(x,{label:"Risk ack",children:r(n,{dimColor:!0,children:t.acceptedRisk.reason??"(no reason recorded)"})}):null,r(oe,{children:"Action"}),a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis update"})," ","to apply this change."]})]})},"OutdatedDetail"),Qi=ie(({finding:e})=>a(h,{flexDirection:"column",children:[r(x,{label:"Versions",children:r(n,{children:String(e.pkg.versions.length)})}),r(oe,{children:"Installed versions"}),e.pkg.versions.map(t=>a(n,{children:[" · ",t]},t)),r(oe,{children:"Action"}),a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis dedupe"})," ","to consolidate to a single resolution."]})]}),"DuplicateDetail"),Zi=ie(({finding:e})=>{const t=e.entry.vulnerabilities??[];return a(h,{flexDirection:"column",children:[r(x,{label:"Package",children:e.packageName}),r(x,{label:"Current",children:e.entry.currentRange}),r(x,{label:"Advisories",children:String(t.length)}),e.entry.acceptedRisk?r(x,{label:"Risk ack",children:r(n,{dimColor:!0,children:e.entry.acceptedRisk.reason??"(no reason recorded)"})}):null,t.map(i=>{const s=qi[i.severity]??"gray";return a(h,{flexDirection:"column",marginTop:1,children:[a(h,{children:[r(n,{bold:!0,color:s,children:i.severity}),r(n,{children:" "}),r(n,{children:i.id}),typeof i.cvssScore=="number"?a(n,{dimColor:!0,children:[" · CVSS ",i.cvssScore.toFixed(1)]}):null]}),r(n,{wrap:"wrap",children:i.summary}),i.fixedVersions.length>0?a(n,{dimColor:!0,children:["Fixed in: ",i.fixedVersions.join(", ")]}):null,i.aliases&&i.aliases.length>0?a(n,{dimColor:!0,children:["Aliases: ",i.aliases.join(", ")]}):null]},i.id)})]})},"VulnerabilityDetail"),er=ie(({finding:e})=>{const t=e.entry.socketReport;if(!t)return r(n,{dimColor:!0,children:"No Socket report attached."});const i=Math.round(t.score.overall*100),s=qe(t.score.overall);return a(h,{flexDirection:"column",children:[r(x,{label:"Package",children:e.packageName}),r(x,{label:"Overall",children:a(n,{color:s,children:[String(i),"%"]})}),r(x,{label:"Alerts",children:String(t.alerts.length)}),e.entry.acceptedRisk?r(x,{label:"Risk ack",children:r(n,{dimColor:!0,children:e.entry.acceptedRisk.reason??"(no reason recorded)"})}):null,r(oe,{children:"Score breakdown"}),Object.entries(t.score).map(([o,l])=>{if(o==="overall")return null;const c=typeof l=="number"?l:0,p=Math.round(c*100),d=qe(c);return a(h,{children:[r(h,{width:14,children:a(n,{dimColor:!0,children:[o,":"]})}),a(n,{color:d,children:[String(p),"%"]})]},o)}),r(oe,{children:"Alerts"}),t.alerts.map((o,l)=>{const c=Ji[o.severity]??"gray";return a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{children:[r(n,{bold:!0,color:c,children:o.severity}),r(n,{children:" "}),r(n,{children:o.type})]}),o.props?r(n,{dimColor:!0,wrap:"wrap",children:JSON.stringify(o.props)}):null]},`${o.type}-${String(l)}`)})]})},"SocketDetail"),tr=ie(({finding:e})=>{const{entry:t}=e;return a(h,{flexDirection:"column",children:[r(x,{label:"Package",children:t.packageName}),r(x,{label:"Category",children:t.category}),r(x,{label:"Replacement",children:t.replacement}),t.overrideSpec?r(x,{label:"Override",children:t.overrideSpec}):null,r(x,{label:"Codemod",children:r(n,{color:t.hasCodemod?"green":"gray",children:t.hasCodemod?"available":"not available"})}),t.docUrl?r(x,{label:"Guide",children:r(n,{color:"cyan",underline:!0,children:t.docUrl})}):null,r(oe,{children:"Action"}),t.hasCodemod?a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis optimize"})," ","to apply the codemod interactively."]}):t.overrideSpec?a(n,{dimColor:!0,children:["Run"," ",r(n,{bold:!0,color:"white",children:"vis optimize"})," ","to install the package override."]}):t.docUrl?r(n,{dimColor:!0,children:"No automated codemod. Open the migration guide above for the recommended alternative and steps."}):r(n,{dimColor:!0,children:"No automated codemod. Consult the package's docs or the e18e module-replacements guide for an alternative."})]})},"OptimizationDetail"),ir=ie(({finding:e})=>{const{diagnostic:t}=e,i=t.status==="warn"?"yellow":t.status==="ok"?"green":"gray";return a(h,{flexDirection:"column",children:[r(x,{label:"Check",children:t.id}),r(x,{label:"Status",children:r(n,{color:i,children:t.status})}),r(oe,{children:"Message"}),r(n,{wrap:"wrap",children:t.message}),t.detail&&Object.keys(t.detail).length>0?a(ai,{children:[r(oe,{children:"Details"}),Object.entries(t.detail).map(([s,o])=>a(h,{children:[r(h,{width:20,children:a(n,{dimColor:!0,children:[s,":"]})}),r(n,{children:String(o)})]},s))]}):null]})},"RuntimeDetail"),rr=ie(({finding:e,focused:t,scrollRef:i})=>{const s=t?"white":"gray";if(!e)return r(h,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:r(n,{dimColor:!0,children:"No finding selected"})});let o;switch(e.kind){case"duplicate":{o=r(Qi,{finding:e});break}case"optimization":{o=r(tr,{finding:e});break}case"outdated":{o=r(Wi,{finding:e});break}case"runtime":{o=r(ir,{finding:e});break}case"socket":{o=r(er,{finding:e});break}case"vulnerability":{o=r(Zi,{finding:e});break}default:{o=r(n,{dimColor:!0,children:"Unknown finding kind."});break}}return a(h,{borderColor:s,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[a(h,{flexShrink:0,paddingTop:1,paddingX:2,children:[r(n,{bold:!0,color:"white",children:e.title}),a(n,{dimColor:!0,children:[" ",St[e.section]]})]}),a(pi,{flexGrow:1,flexShrink:1,paddingX:2,ref:i,scrollbar:!0,scrollbarColor:"gray",scrollbarStyle:"block",children:[r(n,{}),o]})]})},"DoctorDetailPanel");var nr=Object.defineProperty,De=P((e,t)=>nr(e,"name",{value:t,configurable:!0}),"c$2");const Ct={error:"red",warn:"yellow"},or={error:"✖",warn:"⚠"},sr=De(e=>e.kind==="outdated"||e.kind==="vulnerability"||e.kind==="socket"?!!e.entry.acceptedRisk:!1,"hasAcceptedRisk"),lr=De(({finding:e,isSelected:t})=>{const i=Ct[e.severity],s=sr(e);return a(h,{flexShrink:0,height:1,children:[r(n,{children:t?">":" "}),a(n,{color:i,children:[" ",or[e.severity]," "]}),r(h,{flexGrow:1,children:r(n,{bold:t,inverse:t,wrap:"truncate",children:e.title})}),s?r(n,{color:"cyan",children:" ack"}):null,e.subtitle?a(n,{dimColor:!0,wrap:"truncate",children:[" ",e.subtitle]}):null]})},"FindingRow"),ar=De(({count:e,section:t})=>a(h,{flexShrink:0,height:1,marginTop:1,children:[r(n,{dimColor:!0,children:"▼ "}),r(n,{bold:!0,color:"white",children:St[t].toUpperCase()}),a(n,{dimColor:!0,children:[" (",e,")"]})]}),"SectionHeader"),cr=De(({count:e,label:t,status:i})=>a(n,{children:[t,i==="running"?a(n,{children:[" ",r(yt,{type:"dots"})]}):null,i==="error"?r(n,{bold:!0,color:"red",children:" ✖"}):a(n,{dimColor:!0,children:[" (",String(e),")"]})]}),"TabLabel"),dr=De(({elapsedMs:e,entries:t,filterActive:i,filterText:s,filterType:o,focused:l,fromCache:c=!1,grouped:p,onViewportHeightChange:d,scrollOffset:S,sectionCounts:R,sectionMessage:v,sectionStatus:A,selectedIndex:j,severityFilter:g,totalAll:I,viewportHeight:E})=>{const W=l?"white":"gray",{measuredHeight:L,ref:O}=yi(E,d);let D=0,U=0;for(const w of t)w.severity==="error"?D+=1:w.severity==="warn"&&(U+=1);const Q=[];D>0&&Q.push(`${String(D)} error${D===1?"":"s"}`),U>0&&Q.push(`${String(U)} warn${U===1?"":"s"}`);const se=Q.length>0?` (${Q.join(", ")})`:"",Y=(e/1e3).toFixed(1),N=[];for(const[w,T]of p){N.push(r(ar,{count:T.length,section:w},`hdr-${w}`));for(const C of T){const q=t.indexOf(C);N.push(r(lr,{finding:C,isSelected:q===j},C.id))}}let _=0;for(const[,w]of p)_+=2+w.length;const K=_>L&&L>0;return a(h,{borderColor:W,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[a(h,{flexShrink:0,gap:1,paddingX:1,children:[r(n,{bold:!0,inverse:!0,children:" DOCTOR "}),a(n,{wrap:"truncate",children:[t.length,t.length===I?"":`/${String(I)}`," finding",t.length===1?"":"s",se]}),g?r(n,{bold:!0,color:Ct[g],inverse:!0,children:` ${g.toUpperCase()} ONLY `}):null,c?r(n,{bold:!0,color:"cyan",inverse:!0,children:" CACHED "}):null,a(n,{dimColor:!0,children:[" · ",Y,"s"]})]}),r(h,{flexShrink:0,paddingX:1,paddingY:1,children:r(mi,{isFocused:l,keyMap:{next:[],previous:[],useNumbers:!1,useTab:!1},onChange:P(()=>{},"onChange"),showIndex:!1,value:o,children:me.map(({id:w,label:T})=>r(fi,{name:w,children:r(cr,{count:R[w],label:T,status:A[w]})},w))})}),(()=>{const w=Object.keys(A).filter(T=>A[T]==="running"&&v[T]).map(T=>v[T]);return w.length===0?null:r(h,{flexShrink:0,paddingX:1,children:a(n,{dimColor:!0,wrap:"truncate",children:[r(yt,{type:"dots"})," ",w.join(" · ")]})})})(),i&&a(h,{flexShrink:0,paddingX:1,children:[r(n,{bold:!0,color:"white",children:"/ "}),r(n,{children:s}),r(n,{inverse:!0,children:" "})]}),a(h,{flexDirection:"row",flexGrow:1,overflow:"hidden",ref:O,children:[r(h,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:r(h,{flexDirection:"column",marginTop:-S,children:N.length>0?N:r(h,{marginTop:1,children:r(n,{dimColor:!0,children:"No findings match the current filter."})})})}),K&&r(h,{flexShrink:0,marginLeft:1,marginRight:1,children:r(gi,{contentHeight:_,placement:"inset",scrollOffset:S,style:"block",viewportHeight:L})})]},`list-${o}-${s}`)]})},"DoctorListPanel");var ur=Object.defineProperty,je=P((e,t)=>ur(e,"name",{value:t,configurable:!0}),"g$1");const hr=je(e=>{if(e.kind==="outdated")return{command:`vis update ${e.entry.packageName}`,description:`Update ${e.entry.packageName} to ${e.entry.newRange}`};if(e.kind==="duplicate")return{command:`vis dedupe ${e.pkg.name}`,description:`Dedupe ${e.pkg.name} (${String(e.pkg.versions.length)} versions)`}},"buildUpdateAction"),pr=je(e=>{if(e.kind==="optimization")return{command:`vis optimize ${e.entry.packageName}`,description:`Replace ${e.entry.packageName} with ${e.entry.replacement}`}},"buildOptimizeAction"),gr=je(e=>{if(e.kind!=="outdated"&&e.kind!=="vulnerability"&&e.kind!=="socket")return;const t=e.kind==="outdated"?e.entry.packageName:e.packageName,i=["// Add to vis.config.ts:","security: {"," acceptedRisks: {",` "${t}": {`,' reason: "explain why this risk is acceptable",',' expiresAt: "YYYY-MM-DD",'," },"," },","},"].join(`
3
+ `);return{command:i,configSnippet:i,description:`Acknowledge risk for ${t}`}},"buildAckAction"),fr=100,mr=40,yr=10,kr=je(({autoExitSeconds:e=0,banner:t,fromCache:i=!1,startedAt:s,store:o})=>{const{exit:l}=di(),{columns:c,rows:p}=hi(),d=Kt(o.subscribe,o.getSnapshot),[S,R]=Re(!1),[v,A]=Re(!1),[j,g]=Re(0),[I,E]=Re(()=>Date.now());Xe(()=>{const y=setInterval(()=>{E(Date.now())},1e3);return()=>{clearInterval(y)}},[]);const W=I-s,L=We(null),O=We(null),D=d.entries[d.selectedIndex]??null,U=Be(()=>{const y={dependencies:0,optimization:0,runtime:0,security:0};for(const m of d.all)y[m.section]+=1;return y},[d.all]),Q=t?t.hint?5:4:0,se=Be(()=>{for(const y of Object.keys(d.sectionStatus))if(d.sectionStatus[y]==="running"&&d.sectionMessage[y])return 1;return 0},[d.sectionStatus,d.sectionMessage]),Y=c>=fr,N=Y?Math.max(1,p-Q-2):Math.floor(p*.55),_=Math.max(1,N-6-se-(d.filterActive?1:0)),[K,w]=Re(_),T=K>0?K:_,C=Be(()=>{let y=0;for(const[,m]of d.grouped)y+=2+m.length;return y},[d.grouped]),q=Math.max(0,C-T),be=Math.min(j,q),B=Qe(y=>{let m=0,k=0;for(const[,he]of d.grouped){m+=2;for(let pe=0;pe<he.length;pe++){if(k===y)return m;m+=1,k+=1}}return m},[d.grouped]),H=Qe(y=>{const m=B(y);g(k=>m>k+T-2?Math.min(q,Math.max(0,m-T+2)):m<k+1?Math.max(0,m-1):k)},[B,T,q]);if(Xe(()=>{O.current?.scrollToTop()},[D?.id]),ui((y,m)=>{if(y==="c"&&m.ctrl){l();return}if(!v){if(S){m.escape||y==="?"?R(!1):y==="q"?(R(!1),A(!0)):m.downArrow||y==="j"?L.current?.scrollBy(1):(m.upArrow||y==="k")&&L.current?.scrollBy(-1);return}if(y==="?"){R(!0);return}if(y==="q"){A(!0);return}if(m.tab){o.setFocusedPanel(d.focusedPanel==="list"?"detail":"list");return}if(d.filterActive){if(m.escape||m.return){o.setFilterActive(!1);return}if(m.backspace){g(0),o.setFilter(d.filterText.slice(0,-1));return}y&&!m.ctrl&&!m.meta&&(g(0),o.setFilter(d.filterText+y));return}if(d.focusedPanel==="list"&&(m.leftArrow||m.rightArrow)){const k=me.findIndex(pe=>pe.id===d.filterType),he=m.rightArrow?(k+1)%me.length:(k-1+me.length)%me.length;g(0),O.current?.scrollToTop(),o.setFilterType(me[he].id);return}if(d.focusedPanel==="list"){if(m.downArrow||y==="j"){const k=Math.min(d.selectedIndex+1,d.entries.length-1);o.setSelectedIndex(k),H(k);return}if(m.upArrow||y==="k"){const k=Math.max(d.selectedIndex-1,0);o.setSelectedIndex(k),H(k);return}if(m.pageDown){const k=Math.min(d.selectedIndex+10,d.entries.length-1);o.setSelectedIndex(k),H(k);return}if(m.pageUp){const k=Math.max(d.selectedIndex-10,0);o.setSelectedIndex(k),H(k);return}if(m.home){o.setSelectedIndex(0),g(0);return}if(m.end){const k=d.entries.length-1;o.setSelectedIndex(k),H(k);return}if(y==="/"){o.setFilterActive(!0);return}if(y==="e"){o.setSeverityFilter(d.severityFilter==="error"?void 0:"error"),g(0);return}if(y==="w"){o.setSeverityFilter(d.severityFilter==="warn"?void 0:"warn"),g(0);return}if(y==="u"&&D){const k=hr(D);k&&(o.setPendingAction(k),l());return}if(y==="o"&&D){const k=pr(D);k&&(o.setPendingAction(k),l());return}if(y==="a"&&D){const k=gr(D);k&&(o.setPendingAction(k),l());return}if(y==="d"){o.setFocusedPanel("detail");return}return}if(m.escape||m.leftArrow){o.setFocusedPanel("list");return}if(m.downArrow||y==="j"){O.current?.scrollBy(1);return}if(m.upArrow||y==="k"){O.current?.scrollBy(-1);return}if(m.pageDown){O.current?.scrollBy(10);return}if(m.pageUp){O.current?.scrollBy(-10);return}if(m.home){O.current?.scrollToTop();return}m.end&&O.current?.scrollToBottom()}},{isActive:!0}),c<mr||p<yr)return r(h,{alignItems:"center",height:p,justifyContent:"center",width:c,children:a(n,{color:"yellow",children:["Terminal too small (",c,"x",p,")"]})});const Z=d.focusedPanel==="detail",$e=[a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"q"}),r(n,{dimColor:!0,children:"QUIT"})]},"q"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"?"}),r(n,{dimColor:!0,children:"HELP"})]},"?"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"↑↓"}),r(n,{dimColor:!0,children:Z?"SCROLL":"NAV"})]},"nav"),Z?a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"←/Esc"}),r(n,{dimColor:!0,children:"LIST"})]},"lr"):a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"←→"}),r(n,{dimColor:!0,children:"SECTION"})]},"lr"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"/"}),r(n,{dimColor:!0,children:"SEARCH"})]},"search"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"e/w"}),r(n,{dimColor:!0,children:"SEVERITY"})]},"sev"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"u/o/a"}),r(n,{dimColor:!0,children:"ACTION"})]},"actions"),a(h,{gap:1,children:[r(n,{bold:!0,color:"white",children:"Tab"}),r(n,{dimColor:!0,children:"PANEL"})]},"tab")],ce=r(h,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",flexShrink:0,children:r(h,{gap:2,overflow:"hidden",paddingX:1,children:$e})}),de=a(ci,{footer:a(n,{dimColor:!0,children:[r(n,{bold:!0,color:"white",children:"↑↓"})," scroll ",r(n,{bold:!0,color:"white",children:"?"}),"/",r(n,{bold:!0,color:"white",children:"Esc"})," close"]}),scrollRef:L,title:"DOCTOR — KEYBOARD SHORTCUTS",visible:S,width:56,children:[a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"NAVIGATION"})]}),a(h,{children:[r(h,{width:26,children:a(n,{children:[r(n,{bold:!0,color:"white",children:" ↑/k "}),r(n,{dimColor:!0,children:"Move up"})]})}),a(n,{children:[r(n,{bold:!0,color:"white",children:" ↓/j "}),r(n,{dimColor:!0,children:"Move down"})]})]}),a(h,{children:[r(h,{width:26,children:a(n,{children:[r(n,{bold:!0,color:"white",children:" PgUp"}),r(n,{dimColor:!0,children:" Jump up 10"})]})}),a(n,{children:[r(n,{bold:!0,color:"white",children:" PgDn"}),r(n,{dimColor:!0,children:" Jump down 10"})]})]}),a(h,{children:[r(h,{width:26,children:a(n,{children:[r(n,{bold:!0,color:"white",children:" Home"}),r(n,{dimColor:!0,children:" Jump to top"})]})}),a(n,{children:[r(n,{bold:!0,color:"white",children:" End"}),r(n,{dimColor:!0,children:" Jump to bottom"})]})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" Tab"}),r(n,{dimColor:!0,children:" Switch panel"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" →/←"}),r(n,{dimColor:!0,children:" Section tabs (list) / Focus list (detail)"})]})]}),a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"FILTER"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" /"}),r(n,{dimColor:!0,children:" Open text filter (Esc/Enter to close)"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" e"}),r(n,{dimColor:!0,children:" Toggle errors-only filter"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" w"}),r(n,{dimColor:!0,children:" Toggle warns-only filter"})]})]}),a(h,{flexDirection:"column",marginBottom:1,children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"ACTIONS"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" u"}),r(n,{dimColor:!0,children:" Exit + suggest update / dedupe command"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" o"}),r(n,{dimColor:!0,children:" Exit + suggest optimize command"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" a"}),r(n,{dimColor:!0,children:" Exit + print risk-ack snippet"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" d"}),r(n,{dimColor:!0,children:" Focus detail panel"})]})]}),a(h,{flexDirection:"column",children:[a(h,{marginBottom:1,children:[r(n,{dimColor:!0,children:"── "}),r(n,{bold:!0,color:"white",children:"EXIT"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" q"}),r(n,{dimColor:!0,children:" Quit (with countdown)"})]}),a(n,{children:[r(n,{bold:!0,color:"white",children:" Ctrl+C"}),r(n,{dimColor:!0,children:" Quit immediately"})]})]})]}),ue=r(dr,{elapsedMs:W,entries:d.entries,filterActive:d.filterActive,filterText:d.filterText,filterType:d.filterType,focused:d.focusedPanel==="list",fromCache:i,grouped:d.grouped,onViewportHeightChange:w,scrollOffset:be,sectionCounts:U,sectionMessage:d.sectionMessage,sectionStatus:d.sectionStatus,selectedIndex:d.selectedIndex,severityFilter:d.severityFilter,totalAll:d.all.length,viewportHeight:T}),Se=t?r(Yi,{hint:t.hint,message:t.message,severity:t.severity,title:t.title}):null,Ce=r(rr,{finding:D,focused:d.focusedPanel==="detail",scrollRef:O});if(Y){const y=Math.floor(c*.4);return a(h,{flexDirection:"column",height:p,width:c,children:[Se,a(h,{flexDirection:"row",flexGrow:1,children:[r(h,{flexGrow:1,children:ue}),r(h,{width:y,children:Ce})]}),ce,r(Je,{autoExitSeconds:e||3,onCancel:P(()=>{A(!1)},"onCancel"),visible:v}),de]})}return a(h,{flexDirection:"column",height:p,width:c,children:[Se,r(h,{height:N,children:ue}),r(h,{flexGrow:1,children:Ce}),ce,r(Je,{autoExitSeconds:e||3,onCancel:P(()=>{A(!1)},"onCancel"),visible:v}),de]})},"VisDoctorApp");var vr=Object.defineProperty,ve=P((e,t)=>vr(e,"name",{value:t,configurable:!0}),"n");const wr=ve(e=>e.replaceAll(/[$()+.?[\\\]^{|}]/g,String.raw`\$&`),"escapeRegex"),br=ve(e=>{const t=e.split("*").map(i=>wr(i));return new RegExp(`^${t.join(".*")}$`,"i")},"compilePattern"),$r=ve(e=>e?e.split(",").map(t=>t.trim()).filter(t=>t.length>0).map(t=>br(t)):[],"parseFilterPatterns"),Ne=ve((e,t)=>{for(const i of t)if(i.test(e))return!0;return!1},"matchesAny"),Sr=ve((e,t)=>{if(t.length===0)return e;const i=e.outdated.filter(d=>Ne(d.packageName,t)),s=e.duplicates.filter(d=>Ne(d.name,t)),o=e.optimizations.filter(d=>Ne(d.packageName,t));let l=0,c=0,p=0;for(const d of i)d.vulnerabilities&&(l+=d.vulnerabilities.length),d.socketReport&&(c+=d.socketReport.alerts.length,d.socketReport.score.overall<Le&&(p+=1));return{...e,duplicates:s,optimizations:o,outdated:i,socketIssues:{alerts:c,lowScore:p},vulnCount:l}},"applyFilter"),xt=ve((e,t)=>t.length===0?[...e]:e.filter(i=>{if(i.kind==="runtime")return!0;const s=i.kind==="duplicate"?i.pkg.name:i.kind==="outdated"||i.kind==="optimization"?i.entry.packageName:i.packageName;return Ne(s,t)}),"filterFindingsByPattern");var Cr=Object.defineProperty,we=P((e,t)=>Cr(e,"name",{value:t,configurable:!0}),"r");const Rt=["dependencies","security","optimization","runtime"],nt=we(e=>{const t=new Set;if(!e)return t;for(const i of e.split(",")){const s=i.trim().toLowerCase();Rt.includes(s)&&t.add(s)}return t},"parseSectionList"),xr=we((e,t)=>{if(e!==void 0&&e!=="")return nt(e);const i=nt(t);return new Set(Rt.filter(s=>!i.has(s)))},"resolveSections"),Tt=we(e=>{const t={micro:0,native:0,preferred:0,socket:0,total:e.length};for(const i of e)switch(i.category){case"micro-utility":{t.micro+=1;break}case"native":{t.native+=1;break}case"preferred":{t.preferred+=1;break}case"socket":{t.socket+=1;break}}return t},"summarizeOptimizations"),ne=we((e,t)=>{if(!e.sections.has(t))return"skip";switch(t){case"dependencies":return e.outdated.length>0||e.duplicates.length>0?"warn":"ok";case"optimization":return e.optimizations.length>0?"warn":"ok";case"runtime":return e.runtime.some(i=>i.status==="warn")?"warn":"ok";case"security":return e.vulnCount>0||e.socketIssues.alerts>0?"error":e.socketIssues.lowScore>0?"warn":"ok";default:return"ok"}},"sectionStatus"),Rr=we((e,t)=>{const i=Tt(e.optimizations),s={dependencies:ne(e,"dependencies"),optimization:ne(e,"optimization"),runtime:ne(e,"runtime"),security:ne(e,"security")},o=new Set([...Object.values(s),e.supplyChain.status]),l=o.has("error")?"error":o.has("warn")?"warn":"ok";return{dependencies:{duplicates:e.duplicates.length,installed:e.installedCount,outdated:e.outdated.length,status:s.dependencies},elapsedMs:e.elapsedMs,optimizations:{microUtilities:i.micro,native:i.native,preferred:i.preferred,socket:i.socket,status:s.optimization,total:i.total},packageManager:t,runtime:e.runtime.map(c=>({detail:c.detail,id:c.id,message:c.message,status:c.status})),runtimeStatus:s.runtime,security:{alerts:e.socketIssues.alerts,lowScorePackages:e.socketIssues.lowScore,status:s.security,vulnerabilities:e.vulnCount},status:l,supplyChain:{findings:e.supplyChain.findings.map(c=>({detail:c.detail,label:c.label,severity:c.severity})),status:e.supplyChain.status},workspaces:e.workspaceCount}},"buildJsonPayload"),ot=we((e,t)=>{const i=e.runtime.some(o=>o.status==="warn"),s=e.vulnCount>0||e.socketIssues.alerts>0;return t?s||e.outdated.length>0||e.duplicates.length>0||i:s},"shouldFail");var Tr=Object.defineProperty,Ve=P((e,t)=>Tr(e,"name",{value:t,configurable:!0}),"i");const Ar=/^(@[\w./-]+\/[\w./-]+|[\w.-]+)@(.+)$/,Ir=Ve(e=>{const t=Ar.exec(e);if(t)return{name:t[1],version:t[2]}},"parsePatchKey"),Dr=Ve((e,t)=>{let i;try{if(t==="pnpm"){const o=te(e,"pnpm-workspace.yaml");Me(o)&&(i=Ft(o)?.patchedDependencies)}else if(t==="bun"){const o=te(e,"package.json");Me(o)&&(i=pt(o)?.patchedDependencies)}}catch{return[]}if(!i||typeof i!="object")return[];const s=[];for(const[o,l]of Object.entries(i)){if(typeof l!="string"||l.length===0)continue;const c=Ir(o);c&&s.push({name:c.name,patchFile:l,resolvedPatchFile:_t(l)?l:gt(e,l),version:c.version})}return s},"readPatchedDependencies"),Pr=Ve(e=>{const t=[];for(const i of e)Me(i.resolvedPatchFile)||t.push({entry:i,kind:"missing-file"});return t},"findPatchIssues");var Or=Object.defineProperty,At=P((e,t)=>Or(e,"name",{value:t,configurable:!0}),"a");const st=At(e=>e.some(t=>t.severity==="error")?"error":e.some(t=>t.severity==="warn")?"warn":"ok","rollUpStatus"),Nr=At((e,t={})=>{const i=[],s=e?.security;if(!s)return i.push({detail:"Use defineConfig() from '@visulima/vis/config' to apply secure defaults.",label:"No security config — running with the PM's native defaults",severity:"warn"}),{findings:i,status:st(i)};s.minimumReleaseAge===void 0?i.push({detail:"Set security.minimumReleaseAge to block packages published in the last N minutes (mitigates supply-chain attacks).",label:"minimumReleaseAge is not set",severity:"warn"}):s.minimumReleaseAge===0?i.push({detail:"New packages can be installed immediately after publishing. Consider setting a non-zero cooldown.",label:"minimumReleaseAge is explicitly 0",severity:"warn"}):i.push({label:`minimumReleaseAge: ${String(s.minimumReleaseAge)} minutes`,severity:"ok"}),s.trustPolicy===void 0||s.trustPolicy==="off"?i.push({detail:"Packages whose trust level has decreased will not be blocked. Consider 'no-downgrade'.",label:`trustPolicy: ${s.trustPolicy??"not set"}`,severity:"warn"}):i.push({label:`trustPolicy: ${s.trustPolicy}`,severity:"ok"}),s.blockExoticSubdeps===void 0||!s.blockExoticSubdeps?i.push({detail:"Transitive dependencies can pull code from git repos or tarball URLs. Set to true to block.",label:`blockExoticSubdeps: ${String(s.blockExoticSubdeps??!1)}`,severity:"warn"}):i.push({label:"blockExoticSubdeps: true",severity:"ok"});const o=s.allowBuilds?Object.keys(s.allowBuilds).length:0;if(o===0?i.push({detail:"Lifecycle scripts are blocked by default. List trusted packages here to opt them back in (e.g. esbuild, @prisma/client).",label:"allowBuilds: not configured",severity:"warn"}):i.push({label:`allowBuilds: ${String(o)} ${o===1?"entry":"entries"}`,severity:"ok"}),s.strictDepBuilds&&o===0&&i.push({detail:"All dependencies with build scripts will be blocked. Run 'vis approve-builds' to populate allowBuilds.",label:"strictDepBuilds is on but allowBuilds is empty",severity:"error"}),t.workspaceRoot){const l=ki(t.workspaceRoot);if(l.length>0){const c=[...new Set(l.map(p=>p.tool))].sort((p,d)=>p.localeCompare(d)).join(", ");i.push({detail:"Run `vis migrate verify` for the full list, then re-run `vis migrate <tool>` to clean up.",label:`${String(l.length)} leftover ${l.length===1?"reference":"references"} to ${c}`,severity:"warn"})}}if(t.workspaceRoot&&t.packageManager){const l=Dr(t.workspaceRoot,t.packageManager);if(l.length>0){const c=Pr(l);if(c.length===0)i.push({label:`patchedDependencies: ${String(l.length)} ${l.length===1?"entry":"entries"} resolved`,severity:"ok"});else for(const p of c)i.push({detail:`Referenced from ${t.packageManager==="pnpm"?"pnpm-workspace.yaml":"package.json"} but the file is not present at ${p.entry.patchFile}.`,label:`patchedDependencies: missing patch file for ${p.entry.name}@${p.entry.version}`,severity:"error"})}}return{findings:i,status:st(i)}},"buildSupplyChainPosture");var Mr=Object.defineProperty,$=P((e,t)=>Mr(e,"name",{value:t,configurable:!0}),"u");const G=$(e=>e>=1e3?`${(e/1e3).toFixed(1)}s`:`${String(Math.round(e))}ms`,"fmtDuration"),Pe=$(async(e,t,i,s)=>{if(!e)return i();e.start(t);const o=Date.now();try{const l=await i(),c=Date.now()-o,{status:p,summary:d}=s(l,c);return e.finish(t,p,d),l}catch(l){const c=Date.now()-o,p=l instanceof Error?l.message:String(l);throw e.finish(t,"error",`${p} (${G(c)})`),l}},"tracked"),Fr=$((e,t)=>{const i={duplicates:t.duplicates,elapsedMs:0,installedCount:0,optimizations:t.optimizations,outdated:t.outdated,runtime:t.runtime,sections:new Set([e]),socketIssues:{alerts:0,lowScore:0},supplyChain:{findings:[],status:"ok"},vulnCount:0,workspaceCount:0};return $t(i)},"buildSectionFindings"),lt=$(async e=>{const{filterPatterns:t,installed:i,progress:s,resolveCodemods:o,sections:l,store:c,visConfig:p,workspaceRoot:d}=e,S=l.has("dependencies"),R=l.has("security"),v=l.has("optimization"),A=l.has("runtime"),j=$((f,M)=>xt(Fr(f,M),t),"sectionFindings"),g=ct(d),{packageManager:I}=dt(d),E=et(te(d,"package.json"),!1),W=ft(d),L=new Set(E);for(const f of W){const M=et(te(gt(d,f),"package.json"),!1);for(const F of M)L.add(F)}const O=zt(d),D=ut(d,I),U=ht(p?.security?.socket),Q=p?.security?.socket?.acceptedRisks,se=Qt(d,g.name),Y={exclude:[],ignore:[],include:[],includeLocked:!1,includePrerelease:!1,security:!0,target:"latest"},N=S?oi(d,g.name):[],_=v?Zt(L):[],K=v?ei(L,se,g,!1):[],w=new Set(_.map(f=>f.packageName)),T=K.filter(f=>!w.has(f.packageName)),C=[..._,...T],q=A?zi():[];c&&(S&&c.startSection("dependencies",D.size>0?"checking outdated catalog dependencies":"scanning duplicates"),R&&c.startSection("security",i.length>0?`scanning ${String(i.length)} packages for advisories`:"no installed packages to scan"),v&&c.startSection("optimization","matching e18e + socket overrides"),A&&c.startSection("runtime","running runtime diagnostics")),c&&A&&c.completeSection("runtime",j("runtime",{duplicates:[],optimizations:[],outdated:[],runtime:q}));const be=(S||R)&&D.size>0?Pe(s,"outdated",()=>jt(D,Y,O,void 0,d,U,Q),(f,M)=>{const F=f.outdated.length;return{status:F>0?"warn":"ok",summary:F>0?`${String(F)} outdated · ${G(M)}`:`up to date · ${G(M)}`}}):Promise.resolve({failed:[],ignored:[],outdated:[]}),B=R&&i.length>0?Pe(s,"vulnerabilities",()=>Et(i.map(f=>({name:f.name,version:f.version}))),(f,M)=>{let F=0;for(const re of f.values())F+=re.length;return{status:F>0?"error":"ok",summary:F>0?`${String(F)} found · ${G(M)}`:`none found · ${G(M)}`}}):Promise.resolve(new Map),H=R&&U&&i.length>0?Pe(s,"socket",()=>Bt(i.map(f=>({name:f.name,version:f.version})),U),(f,M)=>{let F=0,re=0;for(const Ke of f.values())F+=Ke.alerts.length,Ke.score.overall<Le&&(re+=1);const Ye=F+re;return{status:Ye>0?"warn":"ok",summary:Ye>0?`${String(F)} alert${F===1?"":"s"}, ${String(re)} low-score · ${G(M)}`:`clean · ${G(M)}`}}):Promise.resolve(new Map);let Z,$e,ce,de;const ue=be.catch(f=>(Z=f instanceof Error?f.message:String(f),c||u.warn(`Outdated scan failed: ${Z}`),{failed:[],ignored:[],outdated:[]})),Se=B.catch(f=>($e=f instanceof Error?f.message:String(f),c||u.warn(`Vulnerability scan failed: ${$e}`),new Map)),Ce=H.catch(f=>(ce=f instanceof Error?f.message:String(f),c||u.warn(`Socket scan failed: ${ce}`),new Map)),y=c&&S?ue.then(f=>{if(Z){c.failSection("dependencies",Z);return}c.completeSection("dependencies",j("dependencies",{duplicates:N,optimizations:[],outdated:f.outdated,runtime:[]}))}):void 0,m=c&&R?Promise.all([ue,Se,Ce]).then(([f])=>{const M=Z??$e??ce;if(M){c.failSection("security",M);return}c.completeSection("security",j("security",{duplicates:[],optimizations:[],outdated:f.outdated,runtime:[]}))}):void 0,k=(async()=>{if(o&&v&&C.length>0&&await Pe(s,"codemods",async()=>(await ti(C),C),(f,M)=>{const F=f.filter(re=>re.hasCodemod||re.category==="socket").length;return{status:"ok",summary:`${String(F)} auto-fixable · ${G(M)}`}}).catch(f=>{de=f instanceof Error?f.message:String(f)}),c&&v){if(de){c.failSection("optimization",de);return}c.completeSection("optimization",j("optimization",{duplicates:[],optimizations:C,outdated:[],runtime:[]}))}})(),[he,pe,Dt]=await Promise.all([ue,Se,Ce]);await Promise.all([y,m,k]);let He=0,Ge=0;if(R&&U)for(const f of Dt.values())He+=f.alerts.length,f.score.overall<Le&&(Ge+=1);let Ee=0;if(R){for(const f of he.outdated)f.vulnerabilities&&f.vulnerabilities.length>0&&(Ee+=f.vulnerabilities.length);for(const f of pe.values())Ee+=f.length}return{duplicates:N,installedCount:i.length,optimizations:v?C:[],outdated:S?he.outdated:[],runtime:q,sections:l,socketIssues:{alerts:He,lowScore:Ge},supplyChain:Nr(p,{packageManager:I,workspaceRoot:d}),vulnCount:Ee,workspaceCount:W.length}},"streamScans"),zr=$(e=>{switch(e){case"error":return Te(z.failure);case"skip":return b(z.dash);case"warn":return ze(z.warning);default:return ke(z.success)}},"sectionIcon"),ae=$((e,t)=>{const i=process.stderr.columns??80,s=Math.max(20,Math.min(i-2,60)),o=z.dash.repeat(2),l=`${zr(t)} ${le(e)}`,c=l.replaceAll(/\[[0-9;]*m/g,"").length,p=Math.max(0,s-c-o.length-2);return`${o} ${l} ${b(z.dash.repeat(p))}`},"heading"),X=$(e=>` ${ke(z.success)} ${e}`,"itemOk"),ee=$(e=>` ${ze(z.warning)} ${e}`,"itemWarn"),_e=$(e=>` ${Te(z.failure)} ${e}`,"itemError"),It=$(e=>` ${b(z.dash)} ${b(e)}`,"itemSkip"),J=$((e,t,i)=>{const s=`${le(String(e))} ${b(t)}`;return i?`${s} ${b(`(${i})`)}`:s},"countLine"),jr=$(e=>{if(e.sections.has("dependencies")){if(u.log(""),u.log(ae("Dependencies",ne(e,"dependencies"))),u.log(X(J(e.installedCount,"packages installed"))),e.outdated.length>0){const t=e.outdated.filter(l=>l.updateType==="major").length,i=e.outdated.filter(l=>l.updateType==="minor").length,s=e.outdated.filter(l=>l.updateType==="patch").length,o=[];t>0&&o.push(`${String(t)} major`),i>0&&o.push(`${String(i)} minor`),s>0&&o.push(`${String(s)} patch`),u.log(ee(J(e.outdated.length,"outdated",o.join(", "))))}else u.log(X("All dependencies up to date"));e.duplicates.length>0?u.log(ee(J(e.duplicates.length,"packages with duplicate versions"))):u.log(X("No duplicate dependencies"))}},"displayDependencies"),Er=$(e=>{e.sections.has("security")&&(u.log(""),u.log(ae("Security",ne(e,"security"))),e.vulnCount>0?u.log(_e(J(e.vulnCount,`vulnerabilit${e.vulnCount===1?"y":"ies"} found`))):u.log(X("No known vulnerabilities")),e.socketIssues.alerts>0&&u.log(ee(J(e.socketIssues.alerts,`Socket.dev security alert${e.socketIssues.alerts===1?"":"s"}`))),e.socketIssues.lowScore>0&&u.log(ee(J(e.socketIssues.lowScore,`package${e.socketIssues.lowScore===1?"":"s"} with low security score`))),e.socketIssues.alerts===0&&e.socketIssues.lowScore===0&&e.vulnCount===0&&u.log(X("No security issues detected")))},"displaySecurity"),Br=$(e=>{if(!e.sections.has("optimization"))return;u.log(""),u.log(ae("Optimization",ne(e,"optimization")));const t=Tt(e.optimizations);if(t.total===0){u.log(X("No optimizations available"));return}t.native>0&&u.log(ee(J(t.native,"replaceable with native APIs"))),t.preferred>0&&u.log(ee(J(t.preferred,"with lighter alternatives"))),t.micro>0&&u.log(ee(J(t.micro,"trivial micro-utilities"))),t.socket>0&&u.log(ee(J(t.socket,"@socketregistry overrides available")))},"displayOptimization"),Lr=$(e=>{u.log(""),u.log(ae("Supply Chain",e.supplyChain.status));for(const t of e.supplyChain.findings){const i=t.severity==="ok"?X(t.label):t.severity==="error"?_e(t.label):ee(t.label);u.log(i),t.detail&&u.log(` ${b(z.arrow)} ${b(t.detail)}`)}e.supplyChain.status!=="ok"&&u.log(` ${b(z.arrow)} ${b("Configure with security.* in vis.config.ts. See `vis check --security-config` for details.")}`)},"displaySupplyChain"),Ur=$(e=>{if(e.sections.has("runtime")){u.log(""),u.log(ae("Runtime",ne(e,"runtime")));for(const t of e.runtime)t.status==="ok"?u.log(X(t.message)):t.status==="skip"?u.log(It(t.message)):u.log(ee(t.message))}},"displayRuntime"),Vr=$((e,t)=>{const i=e.vulnCount,s=e.runtime.filter(l=>l.status==="warn").length,o=e.outdated.length+e.duplicates.length+e.optimizations.length+s;if(t){if(i===0&&o===0)u.success(`Everything looks good! ${b(`(${G(e.elapsedMs)})`)}`);else{const l=[];i>0&&l.push(Te(`${String(i)} security`)),o>0&&l.push(ze(`${String(o)} improvement${o===1?"":"s"}`)),u.log(`${Te(z.failure)} ${l.join(", ")} ${b(`(${G(e.elapsedMs)})`)}`)}return}u.log(""),u.log(ae("Summary","ok")),i===0&&o===0?u.success(`Everything looks good! ${b(`(${G(e.elapsedMs)})`)}`):(i>0&&u.error(`${String(i)} security issue${i===1?"":"s"}`),o>0&&u.log(` ${Ae(z.arrow)} ${le(String(o))} ${b(`improvement${o===1?"":"s"} available`)} ${b(`(${G(e.elapsedMs)})`)}`))},"displaySummary"),_r=$(e=>{const t=[];if(e.outdated.length>0&&t.push("vis update — update outdated dependencies"),(e.vulnCount>0||e.socketIssues.alerts>0)&&t.push("vis audit — detailed security analysis"),e.optimizations.length>0&&t.push("vis optimize — apply optimizations interactively"),e.duplicates.length>0&&t.push("vis dedupe — reduce duplicate versions"),t.length>0){u.log(""),u.log(le("Next steps:"));for(const i of t)u.log(` ${b(z.arrow)} ${i}`)}u.log("")},"displayActions"),Hr=$((e,t)=>{t||(jr(e),Er(e),Br(e),Ur(e),Lr(e)),Vr(e,t)},"displayResults"),Gr=$((e,t,i,s,o)=>{const l=[],c=e.has("dependencies"),p=e.has("security"),d=e.has("optimization");return(c||p)&&t>0&&l.push({id:"outdated",label:"Outdated catalog dependencies"}),p&&s>0&&l.push({id:"vulnerabilities",label:"Known vulnerabilities (OSV)"}),p&&i&&s>0&&l.push({id:"socket",label:"Socket.dev supply-chain reports"}),d&&o&&l.push({id:"codemods",label:"Codemod availability"}),l},"planScanTasks"),Yr=$(e=>{if(u.log(""),u.log(`${le(Ae("vis doctor"))} ${b("— project health check")}`),u.log(X(`Detected ${e.packageManagerName} v${e.packageManagerVersion}`)),e.workspaceCount!==void 0&&e.workspaceCount>0&&u.log(X(J(e.workspaceCount,`workspace package${e.workspaceCount===1?"":"s"}`))),e.runtimeFindings.length===0)u.log(X(`Node.js ${e.nodeVersion}`));else{for(const t of e.runtimeFindings){const i=t.severity==="error"?Te:ze;u.log(_e(`Runtime: ${i(t.message)}`))}u.log(` ${b(z.arrow)} Run ${ke("vis toolchain install")} to install pinned versions, or ${ke("vis toolchain status")} for the per-tool breakdown.`)}u.log("")},"printBanner"),vn=$(async({logger:e,options:t,visConfig:i,visConfigError:s,workspaceRoot:o})=>{if(!o)throw new Error("Could not determine workspace root.");const l=t.format==="json"||t.json===!0,c=xr(t.only,t.skip),p=!!t.quiet,d=t.progress===!1,S=$r(t.filter);if(c.size===0){u.error("No sections selected. Check your --only / --skip values."),process.exitCode=2;return}const R=Date.now(),v=ct(o),A=ni(o),j=!!process.stdout.isTTY,g=!l&&j&&!Lt&&!p&&!d;!l&&!g&&Yr({nodeVersion:process.versions.node,packageManagerName:v.name,packageManagerVersion:v.version,runtimeFindings:A,workspaceCount:void 0});const I=ut(o,dt(o).packageManager),E=si(o,v.name),W=E.length,L=!!ht(i?.security?.socket),O=ft(o);if(!l&&!p&&!g){const B=O.length>0?b(` · ${String(O.length)} workspace package${O.length===1?"":"s"}`):"";u.log(`${b("·")} ${b("Found")} ${le(String(W))} ${b(`installed package${W===1?"":"s"}`)}${B}`)}const D=s?{hint:s.file?`Continuing with default settings — fix or regenerate ${s.file} (vis init --force).`:"Continuing with default settings.",message:s.message,severity:"error",title:s.file?`Failed to load ${s.file}`:"Failed to load vis.config"}:void 0,U={bun:"bun.lock",npm:"package-lock.json",pnpm:"pnpm-lock.yaml",yarn:"yarn.lock"}[v.name],Q=U?te(o,U):void 0,se=Ht(o),Y=t.cache!==!1&&!t.fix?$i({configPath:se,lockfilePath:Q,sections:c,socketEnabled:L,workspaceRoot:o}):void 0,N=Y?Si(Y):void 0,_=N!==void 0;let K,w;if(g){const B=N?new it({activeSections:c,findings:xt($t(N),S)}):new it({activeSections:c}),H=Gt(Yt.createElement(kr,{banner:D,fromCache:_,startedAt:R,store:B}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0});try{K=N??await lt({filterPatterns:S,installed:E,resolveCodemods:!!t.fix,sections:c,store:B,visConfig:i,workspaceRoot:o})}catch(Z){throw H.unmount(),Z}await H.waitUntilExit(),w=B.getSnapshot().pendingAction}else if(N)K=N;else{const B=Gr(c,I.size,L,W,!!t.fix),H=li(B,{live:!l&&!p&&!d});try{K=await lt({filterPatterns:S,installed:E,progress:H,resolveCodemods:!!t.fix,sections:c,visConfig:i,workspaceRoot:o})}finally{H.stop()}}const T={...K,elapsedMs:Date.now()-R};if(Y&&!_)try{Ci(Y,T)}catch{}const C=Sr(T,S);if(l){process.stdout.write(`${JSON.stringify(Rr(C,v.name),void 0,2)}
4
+ `),t.exitCode&&ot(C,!!t.strict)&&(process.exitCode=1);return}_&&!p&&u.log(`${b("·")} Cached results (use --no-cache to refresh)`),S.length>0&&!p&&u.log(`${b("·")} Filter active: ${Ae(t.filter??"")}`),Hr(C,p);const q=C.runtime.some(B=>B.id===Oe&&B.status==="warn"),be=C.sections.has("optimization")&&C.optimizations.length>0;t.fix&&(be||q)?await Kr({force:!!t.fixForce,logger:e,pm:v,recoverOrphans:q,results:C,useEditorconfig:i?.editorconfig??!0,workspaceRoot:o}):p||_r(C),w&&(process.stdout.write(`
5
+ `),process.stdout.write(`${le("→ ")}${w.description}
6
+ `),w.configSnippet?(process.stdout.write(`
7
+ `),process.stdout.write(`${b(w.configSnippet)}
8
+ `)):process.stdout.write(` ${Ae(w.command)}
9
9
  `),process.stdout.write(`
10
- `)),t.exitCode&&nt(C,!!t.strict)&&(process.exitCode=1)},"execute"),Kr=$(async e=>{const{force:t,logger:i,pm:s,recoverOrphans:o,results:l,useEditorconfig:c,workspaceRoot:p}=e;u.log(""),u.log(ce("Applying fixes","ok"));const d=l.optimizations.filter(g=>g.category==="socket"&&g.overrideSpec).map(g=>({original:g.packageName,spec:g.overrideSpec})),S=l.optimizations.filter(g=>g.category!=="socket"&&g.hasCodemod),R=l.optimizations.filter(g=>g.category!=="socket"&&!g.hasCodemod);let w=!1,A=0;const E=[];if(o){const g=Di({force:t});if(g.killed.length>0&&(u.success(`Cleaned up ${String(g.killed.length)} orphaned process${g.killed.length===1?"":"es"} (PIDs: ${g.killed.join(", ")}).`),w=!0),g.failed.length>0){const I=t?"":" Re-run with `--fix --fix-force` to escalate to SIGKILL.";u.warn(`Could not signal ${String(g.failed.length)} orphan${g.failed.length===1?"":"s"}: ${g.failed.map(B=>`${String(B.pid)} (${B.reason})`).join(", ")}.${I}`)}}if(d.length>0){const g=di(p,te(p,"package.json"),d,s,c);g.added.length>0&&(u.success(`Added ${String(g.added.length)} security override${g.added.length===1?"":"s"}.`),w=!0),g.updated.length>0&&(u.success(`Updated ${String(g.updated.length)} override${g.updated.length===1?"":"s"}.`),w=!0)}for(const g of S)try{const I=await ui(p,g.packageName);I.filesChanged>0&&(u.success(`${g.packageName}: ${String(I.filesChanged)} file${I.filesChanged===1?"":"s"} updated`),A+=1,w=!0)}catch(I){const B=I instanceof Error?I.message:String(I);E.push({error:B,package:g.packageName}),u.warn(`${g.packageName}: codemod failed — ${B}`)}d.length>0&&(u.log(`${Te(j.arrow)} Running ${s.name} install to update lockfile…`),Vt(s,{dev:!1,filter:[],force:!1,frozenLockfile:!1,ignoreScripts:!1,lockfileOnly:!1,noOptional:!1,offline:!1,prod:!1,recursive:!1,silent:!1,workspaceRoot:!1},p,i),w=!0),u.log(""),w?u.success(`Fixes applied. ${A>0?`${String(A)} codemod${A===1?"":"s"} applied.`:""}`.trim()):u.log(At("No auto-fixable items in the current run.")),E.length>0&&u.warn(`${String(E.length)} codemod${E.length===1?"":"s"} failed (run ${we("vis optimize")} for the interactive picker).`),R.length>0&&u.notice(`${String(R.length)} optimization${R.length===1?"":"s"} need manual review (no codemod). Run ${we("vis optimize")} to inspect them.`)},"runFixes");export{cn as default};
10
+ `)),t.exitCode&&ot(C,!!t.strict)&&(process.exitCode=1)},"execute"),Kr=$(async e=>{const{force:t,logger:i,pm:s,recoverOrphans:o,results:l,useEditorconfig:c,workspaceRoot:p}=e;u.log(""),u.log(ae("Applying fixes","ok"));const d=l.optimizations.filter(g=>g.category==="socket"&&g.overrideSpec).map(g=>({original:g.packageName,spec:g.overrideSpec})),S=l.optimizations.filter(g=>g.category!=="socket"&&g.hasCodemod),R=l.optimizations.filter(g=>g.category!=="socket"&&!g.hasCodemod);let v=!1,A=0;const j=[];if(o){const g=Di({force:t});if(g.killed.length>0&&(u.success(`Cleaned up ${String(g.killed.length)} orphaned process${g.killed.length===1?"":"es"} (PIDs: ${g.killed.join(", ")}).`),v=!0),g.failed.length>0){const I=t?"":" Re-run with `--fix --fix-force` to escalate to SIGKILL.";u.warn(`Could not signal ${String(g.failed.length)} orphan${g.failed.length===1?"":"s"}: ${g.failed.map(E=>`${String(E.pid)} (${E.reason})`).join(", ")}.${I}`)}}if(d.length>0){const g=ii(p,te(p,"package.json"),d,s,c);g.added.length>0&&(u.success(`Added ${String(g.added.length)} security override${g.added.length===1?"":"s"}.`),v=!0),g.updated.length>0&&(u.success(`Updated ${String(g.updated.length)} override${g.updated.length===1?"":"s"}.`),v=!0)}for(const g of S)try{const I=await ri(p,g.packageName);I.filesChanged>0&&(u.success(`${g.packageName}: ${String(I.filesChanged)} file${I.filesChanged===1?"":"s"} updated`),A+=1,v=!0)}catch(I){const E=I instanceof Error?I.message:String(I);j.push({error:E,package:g.packageName}),u.warn(`${g.packageName}: codemod failed — ${E}`)}d.length>0&&(u.log(`${Ae(z.arrow)} Running ${s.name} install to update lockfile…`),Ut(s,{dev:!1,filter:[],force:!1,frozenLockfile:!1,ignoreScripts:!1,lockfileOnly:!1,noOptional:!1,offline:!1,prod:!1,recursive:!1,silent:!1,workspaceRoot:!1},p,i),v=!0),u.log(""),v?u.success(`Fixes applied. ${A>0?`${String(A)} codemod${A===1?"":"s"} applied.`:""}`.trim()):u.log(It("No auto-fixable items in the current run.")),j.length>0&&u.warn(`${String(j.length)} codemod${j.length===1?"":"s"} failed (run ${ke("vis optimize")} for the interactive picker).`),R.length>0&&u.notice(`${String(R.length)} optimization${R.length===1?"":"s"} need manual review (no codemod). Run ${ke("vis optimize")} to inspect them.`)},"runFixes");export{vn as default};