@visulima/vis 5.0.0 → 6.0.0

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 (162) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/LICENSE.md +151 -88
  3. package/README.md +2 -2
  4. package/dist/bin.js +1 -1
  5. package/dist/binx.js +1 -1
  6. package/dist/config/index.d.ts +16 -18
  7. package/dist/packem_chunks/CONFIG_FILES.js +4 -4
  8. package/dist/packem_chunks/bloom-status.js +1 -1
  9. package/dist/packem_chunks/bloom-sync.js +1 -1
  10. package/dist/packem_chunks/catalog.js +61 -51
  11. package/dist/packem_chunks/cli-exec.js +1 -1
  12. package/dist/packem_chunks/cli-main.js +202 -176
  13. package/dist/packem_chunks/dart-plan.js +1 -1
  14. package/dist/packem_chunks/dart-projects.js +1 -1
  15. package/dist/packem_chunks/dispatch.js +1 -1
  16. package/dist/packem_chunks/doctor-probe.js +1 -1
  17. package/dist/packem_chunks/fix.js +1 -1
  18. package/dist/packem_chunks/handler.js +1 -1
  19. package/dist/packem_chunks/handler10.js +4 -4
  20. package/dist/packem_chunks/handler11.js +1 -1
  21. package/dist/packem_chunks/handler12.js +1 -1
  22. package/dist/packem_chunks/handler13.js +1 -1
  23. package/dist/packem_chunks/handler14.js +1 -1
  24. package/dist/packem_chunks/handler15.js +1 -1
  25. package/dist/packem_chunks/handler16.js +1 -1
  26. package/dist/packem_chunks/handler17.js +1 -1
  27. package/dist/packem_chunks/handler18.js +1 -1
  28. package/dist/packem_chunks/handler19.js +1 -1
  29. package/dist/packem_chunks/handler2.js +1 -1
  30. package/dist/packem_chunks/handler20.js +2 -2
  31. package/dist/packem_chunks/handler21.js +1 -1
  32. package/dist/packem_chunks/handler22.js +2 -2
  33. package/dist/packem_chunks/handler23.js +1 -1
  34. package/dist/packem_chunks/handler24.js +1 -1
  35. package/dist/packem_chunks/handler26.js +3 -3
  36. package/dist/packem_chunks/handler27.js +1 -1
  37. package/dist/packem_chunks/handler28.js +1 -1
  38. package/dist/packem_chunks/handler29.js +1 -1
  39. package/dist/packem_chunks/handler3.js +1 -1
  40. package/dist/packem_chunks/handler30.js +1 -1
  41. package/dist/packem_chunks/handler39.js +6 -6
  42. package/dist/packem_chunks/handler5.js +1 -1
  43. package/dist/packem_chunks/handler50.js +2 -2
  44. package/dist/packem_chunks/handler51.js +1 -1
  45. package/dist/packem_chunks/handler53.js +1 -1
  46. package/dist/packem_chunks/handler54.js +1 -1
  47. package/dist/packem_chunks/handler55.js +1 -1
  48. package/dist/packem_chunks/handler58.js +1 -1
  49. package/dist/packem_chunks/handler59.js +1 -1
  50. package/dist/packem_chunks/handler6.js +1 -1
  51. package/dist/packem_chunks/handler60.js +7 -7
  52. package/dist/packem_chunks/handler61.js +2 -2
  53. package/dist/packem_chunks/handler62.js +2 -2
  54. package/dist/packem_chunks/handler63.js +1 -1
  55. package/dist/packem_chunks/handler64.js +2 -2
  56. package/dist/packem_chunks/handler65.js +3 -3
  57. package/dist/packem_chunks/handler66.js +2 -2
  58. package/dist/packem_chunks/handler67.js +31 -20
  59. package/dist/packem_chunks/handler68.js +1 -1
  60. package/dist/packem_chunks/handler69.js +4 -4
  61. package/dist/packem_chunks/handler7.js +1 -1
  62. package/dist/packem_chunks/handler70.js +5 -5
  63. package/dist/packem_chunks/handler71.js +1 -1
  64. package/dist/packem_chunks/handler72.js +1 -1
  65. package/dist/packem_chunks/handler73.js +1 -1
  66. package/dist/packem_chunks/handler74.js +1 -1
  67. package/dist/packem_chunks/handler75.js +36 -36
  68. package/dist/packem_chunks/handler76.js +1 -1
  69. package/dist/packem_chunks/handler77.js +3 -3
  70. package/dist/packem_chunks/handler78.js +24 -24
  71. package/dist/packem_chunks/handler8.js +1 -1
  72. package/dist/packem_chunks/handler9.js +1 -1
  73. package/dist/packem_chunks/heal-accept.js +1 -1
  74. package/dist/packem_chunks/heal.js +1 -1
  75. package/dist/packem_chunks/help-command.js +40 -7
  76. package/dist/packem_chunks/index2.js +32 -32
  77. package/dist/packem_chunks/index6.js +1 -1
  78. package/dist/packem_chunks/keys-refresh.js +1 -1
  79. package/dist/packem_chunks/lean.js +3 -4
  80. package/dist/packem_chunks/list.js +1 -1
  81. package/dist/packem_chunks/loader.js +1 -1
  82. package/dist/packem_chunks/orchestrator.js +1 -1
  83. package/dist/packem_chunks/prompts.js +1 -1
  84. package/dist/packem_chunks/status.js +1 -1
  85. package/dist/packem_chunks/sync.js +1 -1
  86. package/dist/packem_chunks/sync2.js +1 -1
  87. package/dist/packem_chunks/tripwire.js +1 -1
  88. package/dist/packem_chunks/ts-loader.js +5 -5
  89. package/dist/packem_chunks/verify-lockfile.js +1 -1
  90. package/dist/packem_shared/{affected-selection-BJXJW_3Q.js → affected-selection-DDxwjwM4.js} +1 -1
  91. package/dist/packem_shared/{affected-shas-B_kfSKss.js → affected-shas-BuaWvmsG.js} +1 -1
  92. package/dist/packem_shared/{ai-fix-BC6aIRJT.js → ai-fix-C2BhFFhi.js} +5 -5
  93. package/dist/packem_shared/{augment-B9kSZuvW.js → augment-CxUPE8KX.js} +1 -1
  94. package/dist/packem_shared/{bin-Dx8mjl3g.js → bin-Be7_QhQK.js} +1 -1
  95. package/dist/packem_shared/{build-scripts-CEDx_nJp.js → build-scripts-DxyVSkgM.js} +1 -1
  96. package/dist/packem_shared/command-runtime-BXvH5EC0.js +1 -0
  97. package/dist/packem_shared/{dart-pubspec-BK_cK2EP.js → dart-pubspec-DvmyleIr.js} +2 -2
  98. package/dist/packem_shared/{dependency-scan-B8jroa1D.js → dependency-scan-DKK3ZEZI.js} +1 -1
  99. package/dist/packem_shared/{docker-DXqV-07f.js → docker-BTuwdXaC.js} +1 -1
  100. package/dist/packem_shared/{ecosystem-gate-CeV20GSB.js → ecosystem-gate-BpQNUJzN.js} +1 -1
  101. package/dist/packem_shared/{env-consistency-Dt_uDbSP.js → env-consistency-CUBJHENL.js} +1 -1
  102. package/dist/packem_shared/{failure-log-D2x5BT8S.js → failure-log-kp0n2rbD.js} +1 -1
  103. package/dist/packem_shared/{formatBytes-BHAzNIrn-CrusHOew.js → formatBytes-BHAzNIrn-DRcKvqnb.js} +1 -1
  104. package/dist/packem_shared/{index-BzhrR_iC.js → index-BdMIfGVZ.js} +15 -15
  105. package/dist/packem_shared/index-C9ENZqH9.js +39 -0
  106. package/dist/packem_shared/{index-nEyN71oX.js → index-DQfNpt2u.js} +1 -1
  107. package/dist/packem_shared/{index-C_ScJMpb.js → index-DsSWb5XH.js} +1 -1
  108. package/dist/packem_shared/{index.server-sXNQYpsl.js → index.server-D8BLnYZO.js} +2 -2
  109. package/dist/packem_shared/{isAccessibleSync-DYKTrrvc-C-_5cgwu.js → isAccessibleSync-DYKTrrvc-BwaMhQs0.js} +1 -1
  110. package/dist/packem_shared/{lifecycle-D6PMPor-.js → lifecycle-BAhkhE2L.js} +1 -1
  111. package/dist/packem_shared/{lockfile-CiUtEbnt.js → lockfile-DHmlPGk1.js} +1 -1
  112. package/dist/packem_shared/{manifests-Du4yKlf_.js → manifests-Dd4Hoztt.js} +1 -1
  113. package/dist/packem_shared/{min-release-age-JViyQuBM.js → min-release-age-BJnOQaoF.js} +1 -1
  114. package/dist/packem_shared/{missing-package-json-Cu5YVAot.js → missing-package-json-DfzrGwe1.js} +1 -1
  115. package/dist/packem_shared/{multi-eco-lockfiles-B2X3yhyo.js → multi-eco-lockfiles-BIa6xvJc.js} +1 -1
  116. package/dist/packem_shared/{native-config-sync-TdTWjVgI.js → native-config-sync-Dr9XvxOf.js} +1 -1
  117. package/dist/packem_shared/osv-bloom-t40ra5U5.js +2 -0
  118. package/dist/packem_shared/{package-version-CiRZecQu.js → package-version-CFuNUWDG.js} +2 -2
  119. package/dist/packem_shared/{packument-Df46y5MY.js → packument-C9nRiBJf.js} +1 -1
  120. package/dist/packem_shared/pm-runner-ImwtpnWY.js +1 -0
  121. package/dist/packem_shared/{project-name-filter-CH8Ih7Qr.js → project-name-filter-C2rkW-Vn.js} +1 -1
  122. package/dist/packem_shared/{provenance-DKeR0Ig1.js → provenance-DF-ypZj3.js} +1 -1
  123. package/dist/packem_shared/{readJsonSync-CbryXYxN-EWl7_7KX.js → readJsonSync-CbryXYxN-Bm5i10UW.js} +1 -1
  124. package/dist/packem_shared/{registry-keys-DwB3ZXS_.js → registry-keys-BLuHOyZu.js} +1 -1
  125. package/dist/packem_shared/{resolve-explicit-BmV8YBE-.js → resolve-explicit-BDaQRR6o.js} +1 -1
  126. package/dist/packem_shared/resolve-runtime-Cr19Pk6L.js +1 -0
  127. package/dist/packem_shared/{run-file-UBukWaha.js → run-file-XbRCF6Mp.js} +1 -1
  128. package/dist/packem_shared/{runtime-check-1U8HrQd9.js → runtime-check-Bh5q9IrT.js} +1 -1
  129. package/dist/packem_shared/{s1ngularity-DZhkIqL4.js → s1ngularity-UCZN7skW.js} +1 -1
  130. package/dist/packem_shared/{scan-progress-CkumcBG-.js → scan-progress-DcYI76zE.js} +1 -1
  131. package/dist/packem_shared/{selectors-edwcgNl3.js → selectors-DCiEU0iv.js} +2 -2
  132. package/dist/packem_shared/{signatures-BxTMck2l.js → signatures-CicxPHN4.js} +1 -1
  133. package/dist/packem_shared/target-merge-BClIXg2k.js +14 -0
  134. package/dist/packem_shared/{target-options-DsHFmRZH.js → target-options-PgWIuJnb.js} +1 -1
  135. package/dist/packem_shared/{task-env-DzR4RkOj.js → task-env-Dl08aklA.js} +1 -1
  136. package/dist/packem_shared/toolchain-DvUxlbDz.js +5 -0
  137. package/dist/packem_shared/{typosquats-8u0drCqQ.js → typosquats-DxPzyK7u.js} +1 -1
  138. package/dist/packem_shared/{verify-B_MblU_Q.js → verify-CadR9PUk.js} +1 -1
  139. package/dist/packem_shared/{vis-update-app-BCIccZfA.js → vis-update-app-DrFWQyPn.js} +1 -1
  140. package/dist/packem_shared/{vis-user-error-Dd7hwxlW.js → vis-user-error-k7CLTpA4.js} +15 -15
  141. package/dist/packem_shared/{watch-CcTketln.js → watch-Dr_6yz3o.js} +1 -1
  142. package/dist/packem_shared/watch-loop-BId9vT7Q.js +11 -0
  143. package/dist/packem_shared/{writeFileSync-DJoHk3Ks-BPRoepNw.js → writeFileSync-DJoHk3Ks-Dhem3Uof.js} +1 -1
  144. package/dist/release/core/version-actions/index.d.ts +1 -1
  145. package/dist/release/presets.d.ts +1 -55
  146. package/dist/release/presets.js +1 -1
  147. package/dist/release/types.d.ts +1 -18
  148. package/dist/runtime/preload.js +1 -1
  149. package/index.d.ts +204 -204
  150. package/index.js +26 -26
  151. package/package.json +10 -10
  152. package/schemas/vis-config.schema.json +6 -28
  153. package/schemas/vis-release-config.schema.json +1 -12
  154. package/dist/packem_shared/Table-BB8xHTU5-BLPS917D.js +0 -11
  155. package/dist/packem_shared/command-runtime-p4IXiIf6.js +0 -1
  156. package/dist/packem_shared/index-BisalDCf.js +0 -39
  157. package/dist/packem_shared/osv-bloom-BCAX5ARR.js +0 -2
  158. package/dist/packem_shared/pm-runner-3iiQayy-.js +0 -1
  159. package/dist/packem_shared/resolve-runtime-CNiHcVtx.js +0 -1
  160. package/dist/packem_shared/target-merge-DVJl-7Qz.js +0 -4
  161. package/dist/packem_shared/toolchain-BRdpaAC4.js +0 -5
  162. package/dist/packem_shared/watch-loop-BBkg02-Q.js +0 -11
@@ -1,4 +1,4 @@
1
- import{z as A,m as G,a as I,e as b}from"../packem_shared/index-BzhrR_iC.js";import x from"./index.js";import{d as U,E as F}from"./catalog.js";import{n as B}from"../packem_shared/manifests-Du4yKlf_.js";import{_ as E,$ as J}from"./cli-main.js";import{l as K}from"../packem_shared/glob-Cyk1H9ZL-Dxlf9Swz.js";import{U as R,h as M}from"../packem_shared/writeFileSync-DJoHk3Ks-BPRoepNw.js";import{T as q}from"../packem_shared/target-merge-DVJl-7Qz.js";const H=(e,t)=>{const n=t.replace(/^\.?\//,"");return n===""||n==="."?`/${e}/`:e===""||e==="."?`/${n}`:`/${e}/${n}`},N=(e,t,n=[])=>{const s=[],o=new Set;for(const[c,r]of Object.entries(t?.globalPaths??{}))s.push({owners:r,path:c,source:"project-json"}),o.add(c);for(const[c,r]of Object.entries(e.projects)){const a=r.owners??[];for(const f of a){const l=H(r.root??c,f.path);s.push({channel:f.channel,owners:f.owners,path:l,projectId:c,source:"project-json"}),o.add(l)}}for(const c of n)o.has(c.path)||(s.push(c),o.add(c.path));return(t?.orderBy??"file-source")==="project-id"?s.sort((c,r)=>(c.projectId??"").localeCompare(r.projectId??"")||c.path.localeCompare(r.path)):s.sort((c,r)=>c.path.localeCompare(r.path)),s},z="Update each project's project.json `owners` field and re-run the command.",Y=e=>["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.",e?`# Re-run with: ${e}`:`# ${z}`,""],D=e=>{const t=[];for(const n of e){const s=n.owners.join(" "),o=n.channel?` # notify: ${n.channel}`:"";t.push(`${n.path} ${s}${o}`)}return t},Q=(e,t={})=>[...Y(t.regenerationCommand),...D(e),""].join(`
1
+ import{a as A,$ as G,b as I,e as b}from"../packem_shared/index-BdMIfGVZ.js";import x from"./index.js";import{d as U,E as F}from"./catalog.js";import{n as B}from"../packem_shared/manifests-Dd4Hoztt.js";import{_ as E,$ as J}from"./cli-main.js";import{l as K}from"../packem_shared/glob-Cyk1H9ZL-Dxlf9Swz.js";import{U as R,h as M}from"../packem_shared/writeFileSync-DJoHk3Ks-Dhem3Uof.js";import{T as q}from"../packem_shared/target-merge-BClIXg2k.js";const H=(e,t)=>{const n=t.replace(/^\.?\//,"");return n===""||n==="."?`/${e}/`:e===""||e==="."?`/${n}`:`/${e}/${n}`},N=(e,t,n=[])=>{const s=[],o=new Set;for(const[c,r]of Object.entries(t?.globalPaths??{}))s.push({owners:r,path:c,source:"project-json"}),o.add(c);for(const[c,r]of Object.entries(e.projects)){const a=r.owners??[];for(const f of a){const l=H(r.root??c,f.path);s.push({channel:f.channel,owners:f.owners,path:l,projectId:c,source:"project-json"}),o.add(l)}}for(const c of n)o.has(c.path)||(s.push(c),o.add(c.path));return(t?.orderBy??"file-source")==="project-id"?s.sort((c,r)=>(c.projectId??"").localeCompare(r.projectId??"")||c.path.localeCompare(r.path)):s.sort((c,r)=>c.path.localeCompare(r.path)),s},z="Update each project's project.json `owners` field and re-run the command.",Y=e=>["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.",e?`# Re-run with: ${e}`:`# ${z}`,""],D=e=>{const t=[];for(const n of e){const s=n.owners.join(" "),o=n.channel?` # notify: ${n.channel}`:"";t.push(`${n.path} ${s}${o}`)}return t},Q=(e,t={})=>[...Y(t.regenerationCommand),...D(e),""].join(`
2
2
  `),O={begin:"# BEGIN vis-codeowners",end:"# END vis-codeowners"},X=(e,t=O,n={})=>{const s=n.regenerationCommand?`# Generated by vis sync codeowners — re-run with: ${n.regenerationCommand}`:"# Generated by `vis sync codeowners` — do not edit by hand.";return[t.begin,s,...D(e),t.end].join(`
3
3
  `)},Z=(e,t,n=O)=>{const s=e.indexOf(n.begin),o=e.indexOf(n.end);if(s!==-1&&o!==-1&&o>s){const r=e.slice(0,s),a=o+n.end.length,f=e.slice(a);return`${r}${t}${f}`}const i=e.replace(/\s+$/u,"");return`${i.length===0?"":`${i}
4
4
 
@@ -1,6 +1,6 @@
1
- import{a as B,z as J,e as I,$ as K,U as q}from"../packem_shared/index-BzhrR_iC.js";import{U as Y,V as z,W as V,T as Z,C as Q,p as E,q as ee}from"./cli-main.js";import{i as re}from"../packem_shared/index-BjdW45xX.js";import{F as t,X as u,o as a,x as R,R as te,z as se,H as ne,J as oe,K as ie,k as ce,l as A}from"./catalog.js";import le from"./index.js";import{sortPackageJsonStringWithOptions as U}from"#native";import{e as C}from"../packem_shared/utils-DQFHJn72.js";import{y as L}from"../packem_shared/isAccessibleSync-DYKTrrvc-C-_5cgwu.js";const _={error:0,rewritten:1,"would-rewrite":1,unchanged:2},ae=e=>[...e].sort((r,s)=>_[r.status]-_[s.status]),de=(e,r)=>r==="all"?e:r==="errors"?e.filter(s=>s.status==="error"):r==="rewritten"?e.filter(s=>s.status==="rewritten"||s.status==="would-rewrite"):e.filter(s=>s.status==="unchanged");class ue{#e;#r=new Set;constructor(r){this.#e={entries:ae(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=()=>this.#e;subscribe=r=>(this.#r.add(r),()=>{this.#r.delete(r)});getFilteredEntries=()=>de(this.#e.entries,this.#e.filterType);#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const s=this.getFilteredEntries();this.#e.selectedIndex=s.length===0?-1:Math.max(0,Math.min(r,s.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()}}const fe=({checkMode:e,entry:r,focused:s,scrollRef:c})=>{const o=s?"white":"gray";return r?t.jsxs(u,{borderColor:o,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(u,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(a,{bold:!0,color:"white",children:r.relativePath})}),t.jsxs(Y,{flexGrow:1,flexShrink:1,paddingX:2,ref:c,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(a,{}),t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Status:"})}),r.status==="error"?t.jsx(a,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?t.jsx(a,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?t.jsx(a,{bold:!0,color:"yellow",children:"rewritten"}):t.jsx(a,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Path:"})}),t.jsx(a,{children:r.filePath})]}),r.error?t.jsxs(t.Fragment,{children:[t.jsxs(u,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"red",children:"ERROR"}),t.jsxs(u,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Step:"})}),t.jsx(a,{color:"yellow",children:r.error.step})]}),r.error.context&&t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Position:"})}),t.jsx(a,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),t.jsx(u,{marginTop:1,children:t.jsx(a,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&t.jsxs(u,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"white",children:"SNIPPET"}),t.jsxs(u,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const i=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return t.jsxs(u,{children:[t.jsx(a,{color:n.isErrorLine?"red":"gray",children:i}),t.jsx(a,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&t.jsx(u,{children:t.jsx(a,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):t.jsxs(u,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"white",children:"KEY DIFF"}),t.jsx(u,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?t.jsx(a,{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)}`,f=i<0?"green":"yellow";return t.jsxs(u,{children:[t.jsx(u,{width:28,children:t.jsx(a,{wrap:"truncate",children:n.key})}),t.jsx(u,{width:10,children:t.jsxs(a,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),t.jsx(a,{color:f,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&t.jsx(u,{marginTop:1,paddingLeft:2,children:t.jsx(a,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):t.jsx(u,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(a,{dimColor:!0,children:"No entry selected"})})},he={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},ge={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},W={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},xe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},pe=[{count:e=>e.errors+e.rewrites+e.sorted,key:"all",label:"All",shortcut:"1"},{count:e=>e.rewrites,key:"rewritten",label:"Rewrites",shortcut:"2"},{count:e=>e.errors,key:"errors",label:"Errors",shortcut:"3"},{count:e=>e.sorted,key:"unchanged",label:"Sorted",shortcut:"4"}],H=e=>{const r={errors:0,rewrites:0,sorted:0};for(const s of e)r[W[s.status]]++;return r},me=({entry:e,isSelected:r})=>{const s=he[e.status],c=ge[e.status];return t.jsxs(u,{flexShrink:0,height:1,children:[t.jsx(a,{children:r?">":" "}),t.jsx(a,{children:" "}),t.jsx(a,{bold:!0,color:s,children:`[${c}]`.padEnd(10)}),t.jsx(a,{children:" "}),t.jsx(u,{flexGrow:1,children:t.jsx(a,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&t.jsx(a,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},je=({color:e,count:r,label:s})=>t.jsx(u,{flexShrink:0,height:1,children:t.jsx(a,{bold:!0,color:e,children:`${s} (${String(r)})`})}),Se=({counts:e,entries:r,filterType:s,focused:c,selectedIndex:o,totalEntries:n,viewportHeight:i})=>{const d=c?"white":"gray",f=H(r),x=(f.errors>0?1:0)+(f.rewrites>0?1:0)+(f.sorted>0?1:0),m=s==="all"&&x>1,h=[];let j;for(const[l,g]of r.entries()){const k=W[g.status];m&&k!==j&&(j!==void 0&&h.push({kind:"spacer"}),h.push({color:k==="errors"?"red":k==="rewrites"?"yellow":"green",count:f[k],kind:"header",label:xe[k]}),j=k),h.push({entry:g,entryIndex:l,kind:"entry"})}const p=h.findIndex(l=>l.kind==="entry"&&l.entryIndex===o),y=p!==-1,S=h.length,w=Math.max(0,S-i);let b=0;y&&i>0&&(b=Math.min(w,Math.max(0,p-i+1)));const O=S>i&&i>0;return t.jsxs(u,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(u,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(a,{bold:!0,inverse:!0,children:" VIS SORT "}),t.jsxs(a,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),t.jsx(u,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:pe.map(l=>{const g=s===l.key,k=l.count(e);return t.jsxs(u,{children:[t.jsx(a,{dimColor:!g,children:"["}),t.jsx(a,{bold:g,color:g?"cyan":"gray",children:l.shortcut}),t.jsx(a,{dimColor:!g,children:"]"}),t.jsxs(a,{color:g?"white":"gray",children:[" ",l.label]}),t.jsxs(a,{dimColor:!0,children:[" ","(",k,")"]})]},l.key)})}),t.jsxs(u,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(u,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(u,{flexDirection:"column",marginTop:-b,children:h.map((l,g)=>l.kind==="spacer"?t.jsx(u,{flexShrink:0,height:1},`s-${String(g)}`):l.kind==="header"?t.jsx(je,{color:l.color,count:l.count,label:l.label},`h-${l.label}`):t.jsx(me,{entry:l.entry,isSelected:l.entryIndex===o},l.entry.filePath))})}),O&&t.jsx(u,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(z,{contentHeight:S,placement:"inset",scrollOffset:b,style:"block",viewportHeight:i})})]})]})},we=100,D=10,ye=6,ke=1,F={1:"all",2:"rewritten",3:"errors",4:"unchanged"},Ee=({checkMode:e,store:r})=>{const{exit:s}=V(),{columns:c,rows:o}=Z(),n=R.useSyncExternalStore(r.subscribe,r.getSnapshot),i=R.useRef(null),d=r.getFilteredEntries(),f=d[n.selectedIndex]??null,x=H(n.entries),m=c>=we,h=Math.max(0,o-ke),j=m?h:Math.floor(h/2),p=Math.max(0,j-ye),y=R.useCallback(()=>{s()},[s]),S=R.useRef(0),w=R.useRef(void 0),b=R.useRef(!1),O=R.useCallback((l,g)=>{S.current+=g,w.current=l,!b.current&&(b.current=!0,queueMicrotask(()=>{b.current=!1;const k=S.current,N=w.current;S.current=0,w.current=void 0,!(k===0||N===void 0)&&(N==="list"?r.selectStep(Math.sign(k)):i.current?.scrollBy(Math.sign(k)))}))},[r]);return Q((l,g)=>{if(l==="q"||g.escape){y();return}if(F[l]){r.setFilter(F[l]);return}if(g.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?g.upArrow||l==="k"?O("list",-1):(g.downArrow||l==="j")&&O("list",1):n.focusedPanel==="detail"&&(g.upArrow||l==="k"?O("detail",-1):(g.downArrow||l==="j")&&O("detail",1))}),o<D?t.jsx(u,{alignItems:"center",justifyContent:"center",children:t.jsxs(a,{color:"yellow",children:["Terminal too small. Resize to at least",D," ","rows."]})}):t.jsxs(u,{flexDirection:"column",height:o,width:c,children:[t.jsxs(u,{flexDirection:m?"row":"column",flexGrow:1,children:[t.jsx(u,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(Se,{counts:x,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:p})}),t.jsx(u,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(fe,{checkMode:e,entry:f,focused:n.focusedPanel==="detail",scrollRef:i})})]}),t.jsx(u,{flexShrink:0,paddingX:1,children:t.jsx(a,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},M=["types","node-addons","node","import","require","default"],be=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Oe=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,T=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>$(s));const r={};for(const[s,c]of Object.entries(e))r[s]=$(c);return r},Re=e=>{if(!T(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}},Ie=e=>e.endsWith(".git")?e.slice(0,-4):e,Ce=e=>{if(!T(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:s}=e;if(typeof s!="string")return{changed:!1,value:e};const c=be.exec(s)??Oe.exec(s);if(!c)return{changed:!1,value:e};const o=c[1],n=Ie(c[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}`}},Te=e=>{const r=Object.keys(e),s=[],c=[];for(const d of M)Object.hasOwn(e,d)&&s.push(d);for(const d of r)M.includes(d)||c.push(d);const o=[...s,...c];if(o.length===r.length&&o.every((d,f)=>d===r[f]))return{changed:!1,value:e};const i={};for(const d of o)i[d]=e[d];return{changed:!0,value:i}},X=e=>{if(!T(e))return{changed:!1,value:e};let r=!1;const s={};for(const[o,n]of Object.entries(e)){const i=X(n);s[o]=i.value,i.changed&&(r=!0)}const c=Te(s);return{changed:r||c.changed,value:c.value}},Pe=(e,r)=>{const s=$(e);let c=!1;if(r.formatBugs!==!1&&Object.hasOwn(s,"bugs")){const o=Re(s.bugs);o.changed&&(s.bugs=o.value,c=!0)}if(r.formatRepository!==!1&&Object.hasOwn(s,"repository")){const o=Ce(s.repository);o.changed&&(s.repository=o.value,c=!0)}if(r.sortExports!==!1&&Object.hasOwn(s,"exports")&&T(s.exports)){const o=X(s.exports);o.changed&&(s.exports=o.value,c=!0)}return{changed:c,pkg:s}},$e=/at position (\d+)/,Ne=/\(?line (\d+) column (\d+)\)?/,Ae=e=>{const r=new Set,s=[],c=n=>{const i=q(n);!r.has(i)&&L(i)&&(r.add(i),s.push(i))};c(I(e,"package.json"));const o=ce(e);if(o){const n=A(e,o);for(const i of n)c(I(e,i,"package.json"))}else{const n=I(e,"package.json");if(L(n)){const i=JSON.parse(J(n)),d=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;if(d){const f=A(e,d);for(const x of f)c(I(e,x,"package.json"))}}}return s},Le=e=>/\n([ \t]+)/.exec(e)?.[1]??" ",_e=e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},P=e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(s=>s.split(",")).map(s=>s.trim()).filter(s=>s.length>0),De=e=>e.includes(`\r
1
+ import{b as B,a as J,e as I,m as K,U as q}from"../packem_shared/index-BdMIfGVZ.js";import{U as Y,V as z,W as V,T as Z,C as Q,p as E,q as ee}from"./cli-main.js";import{i as re}from"../packem_shared/index-BjdW45xX.js";import{F as t,X as u,o as a,x as R,R as te,z as se,H as ne,J as oe,K as ie,k as ce,l as A}from"./catalog.js";import le from"./index.js";import{sortPackageJsonStringWithOptions as U}from"#native";import{e as C}from"../packem_shared/utils-DQFHJn72.js";import{y as L}from"../packem_shared/isAccessibleSync-DYKTrrvc-BwaMhQs0.js";const _={error:0,rewritten:1,"would-rewrite":1,unchanged:2},ae=e=>[...e].sort((r,s)=>_[r.status]-_[s.status]),de=(e,r)=>r==="all"?e:r==="errors"?e.filter(s=>s.status==="error"):r==="rewritten"?e.filter(s=>s.status==="rewritten"||s.status==="would-rewrite"):e.filter(s=>s.status==="unchanged");class ue{#e;#r=new Set;constructor(r){this.#e={entries:ae(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=()=>this.#e;subscribe=r=>(this.#r.add(r),()=>{this.#r.delete(r)});getFilteredEntries=()=>de(this.#e.entries,this.#e.filterType);#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const s=this.getFilteredEntries();this.#e.selectedIndex=s.length===0?-1:Math.max(0,Math.min(r,s.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()}}const fe=({checkMode:e,entry:r,focused:s,scrollRef:c})=>{const o=s?"white":"gray";return r?t.jsxs(u,{borderColor:o,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(u,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(a,{bold:!0,color:"white",children:r.relativePath})}),t.jsxs(Y,{flexGrow:1,flexShrink:1,paddingX:2,ref:c,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(a,{}),t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Status:"})}),r.status==="error"?t.jsx(a,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?t.jsx(a,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?t.jsx(a,{bold:!0,color:"yellow",children:"rewritten"}):t.jsx(a,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Path:"})}),t.jsx(a,{children:r.filePath})]}),r.error?t.jsxs(t.Fragment,{children:[t.jsxs(u,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"red",children:"ERROR"}),t.jsxs(u,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Step:"})}),t.jsx(a,{color:"yellow",children:r.error.step})]}),r.error.context&&t.jsxs(u,{children:[t.jsx(u,{width:10,children:t.jsx(a,{dimColor:!0,children:"Position:"})}),t.jsx(a,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),t.jsx(u,{marginTop:1,children:t.jsx(a,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&t.jsxs(u,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"white",children:"SNIPPET"}),t.jsxs(u,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const i=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return t.jsxs(u,{children:[t.jsx(a,{color:n.isErrorLine?"red":"gray",children:i}),t.jsx(a,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&t.jsx(u,{children:t.jsx(a,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):t.jsxs(u,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"white",children:"KEY DIFF"}),t.jsx(u,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?t.jsx(a,{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)}`,f=i<0?"green":"yellow";return t.jsxs(u,{children:[t.jsx(u,{width:28,children:t.jsx(a,{wrap:"truncate",children:n.key})}),t.jsx(u,{width:10,children:t.jsxs(a,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),t.jsx(a,{color:f,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&t.jsx(u,{marginTop:1,paddingLeft:2,children:t.jsx(a,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):t.jsx(u,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(a,{dimColor:!0,children:"No entry selected"})})},he={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},ge={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},W={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},xe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},pe=[{count:e=>e.errors+e.rewrites+e.sorted,key:"all",label:"All",shortcut:"1"},{count:e=>e.rewrites,key:"rewritten",label:"Rewrites",shortcut:"2"},{count:e=>e.errors,key:"errors",label:"Errors",shortcut:"3"},{count:e=>e.sorted,key:"unchanged",label:"Sorted",shortcut:"4"}],H=e=>{const r={errors:0,rewrites:0,sorted:0};for(const s of e)r[W[s.status]]++;return r},me=({entry:e,isSelected:r})=>{const s=he[e.status],c=ge[e.status];return t.jsxs(u,{flexShrink:0,height:1,children:[t.jsx(a,{children:r?">":" "}),t.jsx(a,{children:" "}),t.jsx(a,{bold:!0,color:s,children:`[${c}]`.padEnd(10)}),t.jsx(a,{children:" "}),t.jsx(u,{flexGrow:1,children:t.jsx(a,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&t.jsx(a,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},je=({color:e,count:r,label:s})=>t.jsx(u,{flexShrink:0,height:1,children:t.jsx(a,{bold:!0,color:e,children:`${s} (${String(r)})`})}),Se=({counts:e,entries:r,filterType:s,focused:c,selectedIndex:o,totalEntries:n,viewportHeight:i})=>{const d=c?"white":"gray",f=H(r),x=(f.errors>0?1:0)+(f.rewrites>0?1:0)+(f.sorted>0?1:0),m=s==="all"&&x>1,h=[];let j;for(const[l,g]of r.entries()){const k=W[g.status];m&&k!==j&&(j!==void 0&&h.push({kind:"spacer"}),h.push({color:k==="errors"?"red":k==="rewrites"?"yellow":"green",count:f[k],kind:"header",label:xe[k]}),j=k),h.push({entry:g,entryIndex:l,kind:"entry"})}const p=h.findIndex(l=>l.kind==="entry"&&l.entryIndex===o),y=p!==-1,S=h.length,w=Math.max(0,S-i);let b=0;y&&i>0&&(b=Math.min(w,Math.max(0,p-i+1)));const O=S>i&&i>0;return t.jsxs(u,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(u,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(a,{bold:!0,inverse:!0,children:" VIS SORT "}),t.jsxs(a,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),t.jsx(u,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:pe.map(l=>{const g=s===l.key,k=l.count(e);return t.jsxs(u,{children:[t.jsx(a,{dimColor:!g,children:"["}),t.jsx(a,{bold:g,color:g?"cyan":"gray",children:l.shortcut}),t.jsx(a,{dimColor:!g,children:"]"}),t.jsxs(a,{color:g?"white":"gray",children:[" ",l.label]}),t.jsxs(a,{dimColor:!0,children:[" ","(",k,")"]})]},l.key)})}),t.jsxs(u,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(u,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(u,{flexDirection:"column",marginTop:-b,children:h.map((l,g)=>l.kind==="spacer"?t.jsx(u,{flexShrink:0,height:1},`s-${String(g)}`):l.kind==="header"?t.jsx(je,{color:l.color,count:l.count,label:l.label},`h-${l.label}`):t.jsx(me,{entry:l.entry,isSelected:l.entryIndex===o},l.entry.filePath))})}),O&&t.jsx(u,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(z,{contentHeight:S,placement:"inset",scrollOffset:b,style:"block",viewportHeight:i})})]})]})},we=100,D=10,ye=6,ke=1,F={1:"all",2:"rewritten",3:"errors",4:"unchanged"},Ee=({checkMode:e,store:r})=>{const{exit:s}=V(),{columns:c,rows:o}=Z(),n=R.useSyncExternalStore(r.subscribe,r.getSnapshot),i=R.useRef(null),d=r.getFilteredEntries(),f=d[n.selectedIndex]??null,x=H(n.entries),m=c>=we,h=Math.max(0,o-ke),j=m?h:Math.floor(h/2),p=Math.max(0,j-ye),y=R.useCallback(()=>{s()},[s]),S=R.useRef(0),w=R.useRef(void 0),b=R.useRef(!1),O=R.useCallback((l,g)=>{S.current+=g,w.current=l,!b.current&&(b.current=!0,queueMicrotask(()=>{b.current=!1;const k=S.current,$=w.current;S.current=0,w.current=void 0,!(k===0||$===void 0)&&($==="list"?r.selectStep(Math.sign(k)):i.current?.scrollBy(Math.sign(k)))}))},[r]);return Q((l,g)=>{if(l==="q"||g.escape){y();return}if(F[l]){r.setFilter(F[l]);return}if(g.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?g.upArrow||l==="k"?O("list",-1):(g.downArrow||l==="j")&&O("list",1):n.focusedPanel==="detail"&&(g.upArrow||l==="k"?O("detail",-1):(g.downArrow||l==="j")&&O("detail",1))}),o<D?t.jsx(u,{alignItems:"center",justifyContent:"center",children:t.jsxs(a,{color:"yellow",children:["Terminal too small. Resize to at least",D," ","rows."]})}):t.jsxs(u,{flexDirection:"column",height:o,width:c,children:[t.jsxs(u,{flexDirection:m?"row":"column",flexGrow:1,children:[t.jsx(u,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(Se,{counts:x,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:p})}),t.jsx(u,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(fe,{checkMode:e,entry:f,focused:n.focusedPanel==="detail",scrollRef:i})})]}),t.jsx(u,{flexShrink:0,paddingX:1,children:t.jsx(a,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},M=["types","node-addons","node","import","require","default"],be=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Oe=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,T=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),N=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>N(s));const r={};for(const[s,c]of Object.entries(e))r[s]=N(c);return r},Re=e=>{if(!T(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}},Ie=e=>e.endsWith(".git")?e.slice(0,-4):e,Ce=e=>{if(!T(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:s}=e;if(typeof s!="string")return{changed:!1,value:e};const c=be.exec(s)??Oe.exec(s);if(!c)return{changed:!1,value:e};const o=c[1],n=Ie(c[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}`}},Te=e=>{const r=Object.keys(e),s=[],c=[];for(const d of M)Object.hasOwn(e,d)&&s.push(d);for(const d of r)M.includes(d)||c.push(d);const o=[...s,...c];if(o.length===r.length&&o.every((d,f)=>d===r[f]))return{changed:!1,value:e};const i={};for(const d of o)i[d]=e[d];return{changed:!0,value:i}},X=e=>{if(!T(e))return{changed:!1,value:e};let r=!1;const s={};for(const[o,n]of Object.entries(e)){const i=X(n);s[o]=i.value,i.changed&&(r=!0)}const c=Te(s);return{changed:r||c.changed,value:c.value}},Pe=(e,r)=>{const s=N(e);let c=!1;if(r.formatBugs!==!1&&Object.hasOwn(s,"bugs")){const o=Re(s.bugs);o.changed&&(s.bugs=o.value,c=!0)}if(r.formatRepository!==!1&&Object.hasOwn(s,"repository")){const o=Ce(s.repository);o.changed&&(s.repository=o.value,c=!0)}if(r.sortExports!==!1&&Object.hasOwn(s,"exports")&&T(s.exports)){const o=X(s.exports);o.changed&&(s.exports=o.value,c=!0)}return{changed:c,pkg:s}},Ne=/at position (\d+)/,$e=/\(?line (\d+) column (\d+)\)?/,Ae=e=>{const r=new Set,s=[],c=n=>{const i=q(n);!r.has(i)&&L(i)&&(r.add(i),s.push(i))};c(I(e,"package.json"));const o=ce(e);if(o){const n=A(e,o);for(const i of n)c(I(e,i,"package.json"))}else{const n=I(e,"package.json");if(L(n)){const i=JSON.parse(J(n)),d=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;if(d){const f=A(e,d);for(const x of f)c(I(e,x,"package.json"))}}}return s},Le=e=>/\n([ \t]+)/.exec(e)?.[1]??" ",_e=e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},P=e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(s=>s.split(",")).map(s=>s.trim()).filter(s=>s.length>0),De=e=>e.includes(`\r
2
2
  `)?"crlf":"lf",Fe=new Set(["auto","crlf","lf"]),Me=e=>{if(e===void 0||e==="")return"auto";if(Fe.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},Ge=(e,r,s)=>r.length===0?e:e.filter(c=>{const o=B(s,c),n=K(c);return!r.some(i=>{const d=i.includes("/")?o:n;return le(i,d)})}),ve=(e,r)=>{if(r.length===0)return e;const s={},c=new Set;for(const o of r)Object.hasOwn(e,o)&&(s[o]=e[o],c.add(o));for(const o of Object.keys(e))c.has(o)||(s[o]=e[o]);return s},Be=(e,r,s)=>{if(s.length===0)return e;const c={...e};for(const o of s)Object.hasOwn(r,o)&&(c[o]=r[o]);return c},Je=(e,r)=>{let s=1,c=1;const o=Math.min(r,e.length);for(let n=0;n<o;n++)e.codePointAt(n)===10?(s++,c=1):c++;return{column:c,line:s}},G=(e,r,s=2)=>{const c=e.split(`
3
- `);if(r<1||r>c.length)return[];const o=Math.max(0,r-1-s),n=Math.min(c.length,r+s),i=[];for(let d=o;d<n;d++)i.push({content:c[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return i},v=(e,r)=>{if(!(e instanceof Error))return;const s=$e.exec(e.message);if(s){const{column:o,line:n}=Je(r,Number.parseInt(s[1]??"0",10));return{column:o,line:n,snippet:G(r,n)}}const c=Ne.exec(e.message);if(c){const o=Number.parseInt(c[1]??"1",10);return{column:Number.parseInt(c[2]??"1",10),line:o,snippet:G(r,o)}}},Ue=(e,r)=>{const s=Object.keys(JSON.parse(e)),c=Object.keys(JSON.parse(r)),o=new Map(s.map((i,d)=>[i,d])),n=[];for(const[i,d]of c.entries()){const f=o.get(d);f!==void 0&&f!==i&&n.push({fromIndex:f,key:d,toIndex:i})}return n},We=(e,r,s)=>{const c=r.indent??s.indent??Le(e),o=r.lineEnding==="auto"?s.lineEnding??De(e):r.lineEnding,n=U(e,{pretty:!1,sortScripts:r.sortScripts});let i=JSON.parse(n);if(r.unsorted.length>0){const m=JSON.parse(e);i=Be(i,m,r.unsorted)}i=ve(i,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},f=Pe(i,d);let x=JSON.stringify(f.pkg,null,c);return r.finalNewline&&(x+=`
3
+ `);if(r<1||r>c.length)return[];const o=Math.max(0,r-1-s),n=Math.min(c.length,r+s),i=[];for(let d=o;d<n;d++)i.push({content:c[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return i},v=(e,r)=>{if(!(e instanceof Error))return;const s=Ne.exec(e.message);if(s){const{column:o,line:n}=Je(r,Number.parseInt(s[1]??"0",10));return{column:o,line:n,snippet:G(r,n)}}const c=$e.exec(e.message);if(c){const o=Number.parseInt(c[1]??"1",10);return{column:Number.parseInt(c[2]??"1",10),line:o,snippet:G(r,o)}}},Ue=(e,r)=>{const s=Object.keys(JSON.parse(e)),c=Object.keys(JSON.parse(r)),o=new Map(s.map((i,d)=>[i,d])),n=[];for(const[i,d]of c.entries()){const f=o.get(d);f!==void 0&&f!==i&&n.push({fromIndex:f,key:d,toIndex:i})}return n},We=(e,r,s)=>{const c=r.indent??s.indent??Le(e),o=r.lineEnding==="auto"?s.lineEnding??De(e):r.lineEnding,n=U(e,{pretty:!1,sortScripts:r.sortScripts});let i=JSON.parse(n);if(r.unsorted.length>0){const m=JSON.parse(e);i=Be(i,m,r.unsorted)}i=ve(i,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},f=Pe(i,d);let x=JSON.stringify(f.pkg,null,c);return r.finalNewline&&(x+=`
4
4
  `),o==="crlf"&&(x=x.replaceAll(`
5
5
  `,`\r
6
6
  `)),x},He=(e,r)=>{const s=Ae(e),c=se(e),o=ne({cwd:e,extraPatterns:oe(c)}),n=s.filter(d=>!o.ignores(d)),i=Ge(n,r,e);return{afterGitignore:n,allFiles:s,files:i}},Xe=async(e,{checkMode:r,cwd:s,fs:c,normalized:o})=>{const n=B(s,e)||e;let i;try{i=J(e)}catch(h){return{diff:[],error:{message:C(h),step:"read"},filePath:e,relativePath:n,status:"error"}}let d;try{d=U(i,{pretty:!1,sortScripts:o.sortScripts})}catch(h){const j={message:C(h),step:"native-sort"},p=v(h,i);return p&&(j.context=p),{diff:[],error:j,filePath:e,relativePath:n,status:"error"}}const f=o.editorconfig?ie(e):{};let x;try{x=We(i,o,f)}catch(h){const j={message:C(h),step:"json-parse"},p=v(h,i);return p&&(j.context=p),{diff:[],error:j,filePath:e,relativePath:n,status:"error"}}if(i===x)return{diff:[],filePath:e,relativePath:n,status:"unchanged"};let m;try{m=Ue(i,d)}catch{m=[]}if(r)return{diff:m,filePath:e,relativePath:n,status:"would-rewrite"};try{await c.writeFile(e,x,"utf8")}catch(h){return{diff:m,error:{message:C(h),step:"write"},filePath:e,relativePath:n,status:"error"}}return{diff:m,filePath:e,relativePath:n,status:"rewritten"}},Ke=e=>{if(e.error&&(E.error(`${e.filePath}: ${e.error.message}`),E.info(` step: ${e.error.step}`),e.error.context)){E.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const s=r.isErrorLine?">":" ";E.info(` ${s} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},tr=async({fs:e,options:r,visConfig:s,workspaceRoot:c})=>{const o=c??process.cwd(),n=s?.sortPackageJson,i=r.check||!1,f={editorconfig:r.editorconfig?n?.editorconfig??!0:!1,finalNewline:r.finalNewline??n?.finalNewline??!0,formatBugs:r.formatBugs?n?.formatBugs??!0:!1,formatRepository:r.formatRepository?n?.formatRepository??!0:!1,ignore:[...P(r.ignore),...n?.ignore??[]],indent:_e(r.indent??n?.indent),lineEnding:Me(r.lineEnding??n?.lineEnding),sortExports:r.sortExports?n?.sortExports??!0:!1,sortOrder:[...P(r.sortOrder),...n?.sortOrder??[]],sortScripts:r.sortScripts||n?.sortScripts||!1,unsorted:[...P(r.unsorted),...n?.unsorted??[]]},x=He(o,f.ignore),{afterGitignore:m,allFiles:h,files:j}=x;if(j.length===0){h.length===0?E.info("No package.json files found."):m.length===0?E.info("All package.json files were excluded by .gitignore or workspace exclusions."):E.info("All package.json files were excluded by --ignore.");return}const p=[];for(const l of j)p.push(await Xe(l,{checkMode:i,cwd:o,fs:e,normalized:f}));let y=0,S=0,w=0;for(const l of p)l.status==="error"?w++:l.status==="rewritten"||l.status==="would-rewrite"?y++:S++;const b=y>0||w>0;if(!!process.stdout.isTTY&&!re&&b){const l=new ue(p);await ee(te.createElement(Ee,{checkMode:i,store:l}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const l of p)switch(l.status){case"error":{Ke(l);break}case"rewritten":{E.success(`Sorted ${l.filePath}`);break}case"would-rewrite":{E.warn(`${l.filePath} is not sorted`);break}}if(i)y>0?(E.info(`${String(y)} file${y===1?"":"s"} not sorted, ${String(S)} already sorted`),process.exitCode=1):w===0&&E.info(`All ${String(S)} package.json file${S===1?" is":"s are"} sorted`);else{const l=[];y>0&&l.push(`sorted ${String(y)} file${y===1?"":"s"}`),S>0&&l.push(`${String(S)} already sorted`),w>0&&l.push(`${String(w)} error${w===1?"":"s"}`),l.length>0&&E.info(l.join(", "))}w>0&&(process.exitCode=1)};export{G as buildSnippet,Ue as computeKeyDiff,Je as computeLineColumn,tr as default,He as discoverPackageJsonFiles,v as extractParseErrorContext,Xe as processFile};
@@ -1,8 +1,8 @@
1
- import{createRequire as Q}from"node:module";import{J as I,j as re,F as O,X as U,b as D,q as ie}from"../packem_shared/index.server-sXNQYpsl.js";import{a as S}from"../packem_shared/index-BzhrR_iC.js";import{Z as se}from"./cli-main.js";import{d as f,f as b,u as ae,r as oe,a as ce,b as le,s as de,c as ue,e as fe,g as ge,v as pe,w as me,x as P,k as he,l as xe,m as we,n as ve,o as ye,p as ke,t as be,q as $e}from"../packem_shared/watch-loop-BBkg02-Q.js";import{T as d}from"./catalog.js";import{R as Ae}from"./ts-loader.js";let ee;const te=e=>(ee??=Q(import.meta.url))(e),k=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ne=e=>{if(typeof k<"u"&&k.versions&&k.versions.node){const[t,n]=k.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return k.getBuiltinModule(e)}return te(e)},{createHash:h}=ne("node:crypto"),Ce={1:"warning",2:"error"},Fe={argsCheck:(e,t)=>V(e,t,!1),argsFix:(e,t)=>V(e,t,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,t)=>{const n=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.eslint.packageNames[0]),r=b(e,d.eslint.configFiles);if(!(!n&&!r))return{adapter:"eslint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:t.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n)for(const s of i.messages)r.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:i.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":Ce[s.severity]??"warning"});return r}},V=(e,t,n)=>{const r=["--format","json","--no-error-on-unmatched-pattern"];return n&&r.push("--fix"),t.quiet&&r.push("--quiet"),typeof t.maxWarnings=="number"&&r.push("--max-warnings",String(t.maxWarnings)),t.extraArgs?.length&&r.push(...t.extraArgs),r.push(...e),r},Se=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,je=e=>{const t=Se.exec(e);if(!t)return;const[,n,r,i,s,c]=t;return{column:i===void 0?void 0:Number(i),file:n,line:Number(r),message:c,ruleId:s}},_e=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Ne={argsCheck:(e,t)=>M(e,t,!1),argsFix:(e,t)=>M(e,t,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,t)=>{const n=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=d.markdownlint.packageNames.map(i=>f(t,i)).find(i=>i!==void 0),r=b(e,d.markdownlint.configFiles);if(!(!n&&!r))return{adapter:"markdownlint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,t)=>{const n=(e.stderr||e.stdout||"").trim();if(!n)return[];const r=[];for(const i of n.split(/\r?\n/)){const s=je(i.trim());s&&r.push({adapter:"markdownlint",column:s.column,file:_e(s.file)?s.file:`${t.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return r}},M=(e,t,n)=>{const r=[];return n&&r.push("--fix"),t.extraArgs?.length&&r.push(...t.extraArgs),e.length===0?r.push("**/*.md"):r.push(...e),r},qe={advice:"info",error:"error",warning:"warning"},Ie={argsCheck:(e,t)=>L(e,t,!1),argsFix:(e,t)=>L(e,t,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,t)=>{const n=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.oxlint.packageNames[0]),r=b(e,d.oxlint.configFiles);if(!(!n&&!r))return{adapter:"oxlint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:t.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n.diagnostics??[]){const s=i.labels?.[0]?.span;r.push({adapter:"oxlint",column:s?.column,file:i.filename??t.root,fixable:!1,line:s?.line,message:i.message??"",ruleId:i.code,severity:qe[i.severity??""]??"warning"})}return r}},L=(e,t,n)=>{const r=["--format","json"];return n&&r.push("--fix"),t.quiet&&r.push("--quiet"),typeof t.maxWarnings=="number"&&r.push(`--max-warnings=${String(t.maxWarnings)}`),t.extraArgs?.length&&r.push(...t.extraArgs),r.push(...e),r},We={error:"error",info:"info",style:"info",warning:"warning"},Re=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Te=(e,t)=>e?Re(e)?e:`${t}/${e}`:t,Ee={argsCheck:(e,t)=>B(e,t),argsFix:(e,t)=>B(e,t),bin:()=>["shellcheck"],cacheKey:(e,t)=>{const n=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.shellcheck.packageNames[0]),r=b(e,d.shellcheck.configFiles);if(!(!n&&!r))return{adapter:"shellcheck",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:t.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n.comments??[])r.push({adapter:"shellcheck",column:i.column,endColumn:i.endColumn,endLine:i.endLine,file:Te(i.file,t.root),fixable:!!i.fix,line:i.line,message:i.message??"",ruleId:i.code===void 0?void 0:`SC${String(i.code)}`,severity:We[i.level??""]??"warning"});return r}},B=(e,t)=>{const n=["--format=json1"];return t.extraArgs?.length&&n.push(...t.extraArgs),n.push(...e),n},Oe={error:"error",warning:"warning"},Pe={argsCheck:(e,t)=>J(e,t,!1),argsFix:(e,t)=>J(e,t,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,t)=>{const n=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.stylelint.packageNames[0]),r=b(e,d.stylelint.configFiles);if(!(!n&&!r))return{adapter:"stylelint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:t.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n)for(const s of i.warnings??[])r.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:i.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:Oe[s.severity??""]??"warning"});return r}},J=(e,t,n)=>{const r=["--formatter","json"];return n&&r.push("--fix"),t.quiet&&r.push("--quiet"),typeof t.maxWarnings=="number"&&r.push("--max-warnings",String(t.maxWarnings)),t.extraArgs?.length&&r.push(...t.extraArgs),r.push(...e),r},G="@typescript/native-preview",Ve=2e3,Me=/^(.*)\((\d+),(\d+)\): (error|warning) (TS\d+): (.*)$/,Le=/^(error|warning) (TS\d+): (.*)$/,Y=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Be=(e,t)=>Y(e)?e:`${t}/${e}`,z=e=>{try{return Ae(e)}catch{return}},Je=e=>{const t=z(e);return Array.isArray(t?.config.references)&&t.config.references.length>0},Ke=e=>{const t=ae(e);return!f(t,"typescript")&&f(t,G)?"tsgo":"tsc"},Ue={argsCheck:(e,t)=>K(t),argsFix:(e,t)=>K(t),bin:e=>{const t=["pnpm","exec",Ke(e.root)],n=e.configFile?S(e.root,e.configFile):"tsconfig.json";return e.configFile&&Je(e.root)?[...t,"-b","--pretty","false",n]:[...t,"-p",n,"--noEmit","--pretty","false"]},cacheKey:(e,t)=>{const n=["typecheck",e.declaredVersion??"unknown",e.configFile??"no-config",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,"typescript"),r=f(t,G),i=z(e),s=i?S(e,i.path):void 0;if(!(!n&&!r||!i||!s||s===".."||s.startsWith("../")||Y(s)))return{adapter:"typecheck",configFile:i.path,declared:!0,declaredVersion:n??r,root:e}},extensions:["cts","mts","ts","tsx"],id:"typecheck",kind:"lint",optIn:!0,parse:(e,t)=>{const n=[];for(const r of`${e.stdout}
1
+ import{createRequire as Q}from"node:module";import{J as I,j as re,F as O,X as U,b as D,q as ie}from"../packem_shared/index.server-D8BLnYZO.js";import{b as S}from"../packem_shared/index-BdMIfGVZ.js";import{Z as se}from"./cli-main.js";import{d as f,f as b,t as ae,w as oe,r as ce,a as le,b as de,s as ue,c as fe,e as ge,g as pe,u as me,v as P,j as he,k as xe,l as we,m as ve,n as ye,o as ke,q as be,p as $e}from"../packem_shared/watch-loop-BId9vT7Q.js";import{T as d}from"./catalog.js";import{R as Ae}from"./ts-loader.js";let ee;const te=e=>(ee??=Q(import.meta.url))(e),k=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ne=e=>{if(typeof k<"u"&&k.versions&&k.versions.node){const[t,n]=k.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return k.getBuiltinModule(e)}return te(e)},{createHash:h}=ne("node:crypto"),Ce={1:"warning",2:"error"},Fe={argsCheck:(e,t)=>V(e,t,!1),argsFix:(e,t)=>V(e,t,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,t)=>{const n=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.eslint.packageNames[0]),r=b(e,d.eslint.configFiles);if(!(!n&&!r))return{adapter:"eslint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:t.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n)for(const s of i.messages)r.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:i.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":Ce[s.severity]??"warning"});return r}},V=(e,t,n)=>{const r=["--format","json","--no-error-on-unmatched-pattern"];return n&&r.push("--fix"),t.quiet&&r.push("--quiet"),typeof t.maxWarnings=="number"&&r.push("--max-warnings",String(t.maxWarnings)),t.extraArgs?.length&&r.push(...t.extraArgs),r.push(...e),r},Se=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,je=e=>{const t=Se.exec(e);if(!t)return;const[,n,r,i,s,c]=t;return{column:i===void 0?void 0:Number(i),file:n,line:Number(r),message:c,ruleId:s}},_e=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Ne={argsCheck:(e,t)=>M(e,t,!1),argsFix:(e,t)=>M(e,t,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,t)=>{const n=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=d.markdownlint.packageNames.map(i=>f(t,i)).find(i=>i!==void 0),r=b(e,d.markdownlint.configFiles);if(!(!n&&!r))return{adapter:"markdownlint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,t)=>{const n=(e.stderr||e.stdout||"").trim();if(!n)return[];const r=[];for(const i of n.split(/\r?\n/)){const s=je(i.trim());s&&r.push({adapter:"markdownlint",column:s.column,file:_e(s.file)?s.file:`${t.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return r}},M=(e,t,n)=>{const r=[];return n&&r.push("--fix"),t.extraArgs?.length&&r.push(...t.extraArgs),e.length===0?r.push("**/*.md"):r.push(...e),r},qe={advice:"info",error:"error",warning:"warning"},Ie={argsCheck:(e,t)=>L(e,t,!1),argsFix:(e,t)=>L(e,t,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,t)=>{const n=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.oxlint.packageNames[0]),r=b(e,d.oxlint.configFiles);if(!(!n&&!r))return{adapter:"oxlint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:t.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n.diagnostics??[]){const s=i.labels?.[0]?.span;r.push({adapter:"oxlint",column:s?.column,file:i.filename??t.root,fixable:!1,line:s?.line,message:i.message??"",ruleId:i.code,severity:qe[i.severity??""]??"warning"})}return r}},L=(e,t,n)=>{const r=["--format","json"];return n&&r.push("--fix"),t.quiet&&r.push("--quiet"),typeof t.maxWarnings=="number"&&r.push(`--max-warnings=${String(t.maxWarnings)}`),t.extraArgs?.length&&r.push(...t.extraArgs),r.push(...e),r},We={error:"error",info:"info",style:"info",warning:"warning"},Re=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Te=(e,t)=>e?Re(e)?e:`${t}/${e}`:t,Ee={argsCheck:(e,t)=>B(e,t),argsFix:(e,t)=>B(e,t),bin:()=>["shellcheck"],cacheKey:(e,t)=>{const n=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.shellcheck.packageNames[0]),r=b(e,d.shellcheck.configFiles);if(!(!n&&!r))return{adapter:"shellcheck",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:t.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n.comments??[])r.push({adapter:"shellcheck",column:i.column,endColumn:i.endColumn,endLine:i.endLine,file:Te(i.file,t.root),fixable:!!i.fix,line:i.line,message:i.message??"",ruleId:i.code===void 0?void 0:`SC${String(i.code)}`,severity:We[i.level??""]??"warning"});return r}},B=(e,t)=>{const n=["--format=json1"];return t.extraArgs?.length&&n.push(...t.extraArgs),n.push(...e),n},Oe={error:"error",warning:"warning"},Pe={argsCheck:(e,t)=>J(e,t,!1),argsFix:(e,t)=>J(e,t,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,t)=>{const n=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",t.maxWarnings===void 0?"":`mw=${t.maxWarnings}`,t.quiet?"q":"",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,d.stylelint.packageNames[0]),r=b(e,d.stylelint.configFiles);if(!(!n&&!r))return{adapter:"stylelint",configFile:r,declared:!!n,declaredVersion:n,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,t)=>{if(!e.stdout.trim())return[];let n;try{n=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:t.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of n)for(const s of i.warnings??[])r.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:i.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:Oe[s.severity??""]??"warning"});return r}},J=(e,t,n)=>{const r=["--formatter","json"];return n&&r.push("--fix"),t.quiet&&r.push("--quiet"),typeof t.maxWarnings=="number"&&r.push("--max-warnings",String(t.maxWarnings)),t.extraArgs?.length&&r.push(...t.extraArgs),r.push(...e),r},G="@typescript/native-preview",Ve=2e3,Me=/^(.*)\((\d+),(\d+)\): (error|warning) (TS\d+): (.*)$/,Le=/^(error|warning) (TS\d+): (.*)$/,Y=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Be=(e,t)=>Y(e)?e:`${t}/${e}`,z=e=>{try{return Ae(e)}catch{return}},Je=e=>{const t=z(e);return Array.isArray(t?.config.references)&&t.config.references.length>0},Ke=e=>{const t=ae(e);return!f(t,"typescript")&&f(t,G)?"tsgo":"tsc"},Ue={argsCheck:(e,t)=>K(t),argsFix:(e,t)=>K(t),bin:e=>{const t=["pnpm","exec",Ke(e.root)],n=e.configFile?S(e.root,e.configFile):"tsconfig.json";return e.configFile&&Je(e.root)?[...t,"-b","--pretty","false",n]:[...t,"-p",n,"--noEmit","--pretty","false"]},cacheKey:(e,t)=>{const n=["typecheck",e.declaredVersion??"unknown",e.configFile??"no-config",...t.extraArgs??[]];return h("sha256").update(n.join("|")).digest("hex").slice(0,16)},detect:(e,t)=>{const n=f(t,"typescript"),r=f(t,G),i=z(e),s=i?S(e,i.path):void 0;if(!(!n&&!r||!i||!s||s===".."||s.startsWith("../")||Y(s)))return{adapter:"typecheck",configFile:i.path,declared:!0,declaredVersion:n??r,root:e}},extensions:["cts","mts","ts","tsx"],id:"typecheck",kind:"lint",optIn:!0,parse:(e,t)=>{const n=[];for(const r of`${e.stdout}
2
2
  ${e.stderr}`.split(/\r?\n/)){const i=Me.exec(r);if(i){n.push({adapter:"typecheck",column:Number(i[3]),file:Be(i[1],t.root),fixable:!1,line:Number(i[2]),message:i[6],ruleId:i[5],severity:i[4]==="warning"?"warning":"error"});continue}const s=Le.exec(r);if(s){n.push({adapter:"typecheck",file:t.root,fixable:!1,message:s[3],ruleId:s[2],severity:s[1]==="warning"?"warning":"error"});continue}const c=n.at(-1);c&&/^\s+\S/.test(r)&&(c.message+=`
3
3
  ${r.trim()}`)}if(n.length===0&&e.exitCode!==0){const r=`${e.stdout}
4
4
  ${e.stderr}`.trim().slice(0,Ve);n.push({adapter:"typecheck",file:t.root,fixable:!1,message:e.exitCode===null?`type-check did not complete (killed or timed out)${r?`:
5
5
  ${r}`:""}`:`type-check failed (exit ${String(e.exitCode)}) with unrecognised output:
6
- ${r}`,severity:"error"})}return n},scope:"project"},K=e=>e.extraArgs?.length?[...e.extraArgs]:[],De=[Ie,ge,Fe,Pe,pe,Ne,Ee,me,Ue],st=async({logger:e,options:t,visConfig:n,workspaceRoot:r})=>{const i=r??process.cwd(),s=n?.lint,c=oe(De,s?.order),$=ce(i,c),x=le($,c,"lint").filter(({adapter:o})=>{const l=s?.adapters?.[o.id]?.enabled;return o.optIn?l===!0:l!==!1});for(const o of c)o.optIn&&s?.adapters?.[o.id]?.enabled===!0&&!$.has(o.id)&&e.warn(`vis lint: adapters.${o.id}.enabled is set, but ${o.id} was not detected (needs a tsconfig.json and a typescript dependency at the workspace root). Skipping it.`);if(x.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck, deno; typecheck runs only when enabled).");return}const j=o=>{const l=s?.adapters?.[o]?.extraArgs;return l&&l.length>0?[...l]:void 0},A={extraArgs:void 0,maxWarnings:typeof t.maxWarnings=="number"?t.maxWarnings:void 0,quiet:t.quiet??!1},W=Ge(t),H=t.fix?"fix":"check";let g;if(t.staged){if(g=de(i),g===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(g.length===0){e.info(I("✓ lint: no staged files"));return}}else if(typeof t.since=="string"&&t.since.length>0){if(g=ue(i,t.since),g===void 0)e.warn(`vis lint: could not resolve --since ${t.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(g.length===0){e.info(I(`✓ lint: no files changed since ${t.since}`));return}}const _=W.length>0?W:void 0,X=se(i,void 0,void 0,!0),N=t.format??"human";N==="human"&&t.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const R=async o=>{const l=o!==void 0&&o.length>0&&_===void 0,w=[];for(const{adapter:a,presence:y}of x){let u;if(a.scope==="project"){const q=_??o;if(q&&q.length>0&&P(q,a.extensions).length===0)continue;u=["."]}else if(l){if(u=P(o,a.extensions),u.length===0)continue}else u=_??o??["."];const F=j(a.id),E={adapter:a,files:u,presence:y};F&&(E.options={...A,extraArgs:F}),w.push(E)}if(w.length===0)return;const Z=await he(w,A,H,{cacheRoot:X}),C=w.map((a,y)=>{const u=Z[y],F=a.adapter.parse(u,a.presence);return{adapter:a.adapter,durationMs:u.durationMs,exitCode:u.exitCode,findings:F}}),v=xe(C.map(a=>({adapter:a.adapter.id,durationMs:a.durationMs,exitCode:a.exitCode,findingCount:a.findings.length,findings:a.findings}))),m=N==="human"?void 0:we({cwd:i,target:t.output});try{switch(N){case"github":{m.write(ke({runs:C.map(a=>({findings:a.findings})),workspaceRoot:i}));break}case"json":{m.write(`${JSON.stringify({findings:v.findings,runs:v.runs},null,2)}
7
- `);break}case"junit":{m.write(ye({runs:C.map(a=>({adapter:a.adapter.id,durationMs:a.durationMs,findings:a.findings})),workspaceRoot:i}));break}case"minimal":{ze(v.findings,i,m);break}case"sarif":{m.write(ve({runs:C.map(a=>({adapter:a.adapter.id,findings:a.findings,presence:w.find(y=>y.adapter.id===a.adapter.id)?.presence})),workspaceRoot:i}));break}default:Ye(v.findings,i,e)}}finally{m?.close()}const T=$e(v);T!==0&&(process.exitCode=T)};if(t.watch){const o=[...new Set(x.flatMap(({adapter:l})=>l.extensions))];await fe({extensions:o,initialFiles:g,label:"lint",log:l=>{e.info(l)},runCycle:R,workspaceRoot:i});return}await R(g)},Ge=e=>{const t=e;return[...t._??t.args??[]]},Ye=(e,t,n)=>{if(e.length===0){n.info(I("✓ lint: no findings"));return}const r=be(e);for(const[c,$]of r){n.info(re(S(t,c)));for(const p of $){const x=He(p),j=Xe(p.severity),A=p.ruleId?O(` ${p.ruleId}`):"";n.info(` ${O(x)} ${j} ${p.message}${A}`)}}const i=e.filter(c=>c.severity==="error").length,s=e.filter(c=>c.severity==="warning").length;n.info(""),n.info(`${U(`${String(i)} error${i===1?"":"s"}`)}, ${D(`${String(s)} warning${s===1?"":"s"}`)}`)},ze=(e,t,n)=>{for(const r of e){const i=S(t,r.file),s=r.line??"",c=r.column??"";n.write(`${r.adapter} ${i} ${String(s)} ${String(c)} ${r.severity} ${r.ruleId??""} ${r.message}
6
+ ${r}`,severity:"error"})}return n},scope:"project"},K=e=>e.extraArgs?.length?[...e.extraArgs]:[],De=[Ie,pe,Fe,Pe,me,Ne,Ee,Ue],st=async({logger:e,options:t,visConfig:n,workspaceRoot:r})=>{const i=r??process.cwd(),s=n?.lint;oe(e,"lint",s);const c=ce(De,s?.order),$=le(i,c),x=de($,c,"lint").filter(({adapter:o})=>{const l=s?.adapters?.[o.id]?.enabled;return o.optIn?l===!0:l!==!1});for(const o of c)o.optIn&&s?.adapters?.[o.id]?.enabled===!0&&!$.has(o.id)&&e.warn(`vis lint: adapters.${o.id}.enabled is set, but ${o.id} was not detected (needs a tsconfig.json and a typescript dependency at the workspace root). Skipping it.`);if(x.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck; typecheck runs only when enabled).");return}const j=o=>{const l=s?.adapters?.[o]?.extraArgs;return l&&l.length>0?[...l]:void 0},A={extraArgs:void 0,maxWarnings:typeof t.maxWarnings=="number"?t.maxWarnings:void 0,quiet:t.quiet??!1},W=Ge(t),H=t.fix?"fix":"check";let g;if(t.staged){if(g=ue(i),g===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(g.length===0){e.info(I("✓ lint: no staged files"));return}}else if(typeof t.since=="string"&&t.since.length>0){if(g=fe(i,t.since),g===void 0)e.warn(`vis lint: could not resolve --since ${t.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(g.length===0){e.info(I(`✓ lint: no files changed since ${t.since}`));return}}const _=W.length>0?W:void 0,X=se(i,void 0,void 0,!0),N=t.format??"human";N==="human"&&t.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const R=async o=>{const l=o!==void 0&&o.length>0&&_===void 0,w=[];for(const{adapter:a,presence:y}of x){let u;if(a.scope==="project"){const q=_??o;if(q&&q.length>0&&P(q,a.extensions).length===0)continue;u=["."]}else if(l){if(u=P(o,a.extensions),u.length===0)continue}else u=_??o??["."];const F=j(a.id),E={adapter:a,files:u,presence:y};F&&(E.options={...A,extraArgs:F}),w.push(E)}if(w.length===0)return;const Z=await he(w,A,H,{cacheRoot:X}),C=w.map((a,y)=>{const u=Z[y],F=a.adapter.parse(u,a.presence);return{adapter:a.adapter,durationMs:u.durationMs,exitCode:u.exitCode,findings:F}}),v=xe(C.map(a=>({adapter:a.adapter.id,durationMs:a.durationMs,exitCode:a.exitCode,findingCount:a.findings.length,findings:a.findings}))),m=N==="human"?void 0:we({cwd:i,target:t.output});try{switch(N){case"github":{m.write(ke({runs:C.map(a=>({findings:a.findings})),workspaceRoot:i}));break}case"json":{m.write(`${JSON.stringify({findings:v.findings,runs:v.runs},null,2)}
7
+ `);break}case"junit":{m.write(ye({runs:C.map(a=>({adapter:a.adapter.id,durationMs:a.durationMs,findings:a.findings})),workspaceRoot:i}));break}case"minimal":{ze(v.findings,i,m);break}case"sarif":{m.write(ve({runs:C.map(a=>({adapter:a.adapter.id,findings:a.findings,presence:w.find(y=>y.adapter.id===a.adapter.id)?.presence})),workspaceRoot:i}));break}default:Ye(v.findings,i,e)}}finally{m?.close()}const T=$e(v);T!==0&&(process.exitCode=T)};if(t.watch){const o=[...new Set(x.flatMap(({adapter:l})=>l.extensions))];await ge({extensions:o,initialFiles:g,label:"lint",log:l=>{e.info(l)},runCycle:R,workspaceRoot:i});return}await R(g)},Ge=e=>{const t=e;return[...t._??t.args??[]]},Ye=(e,t,n)=>{if(e.length===0){n.info(I("✓ lint: no findings"));return}const r=be(e);for(const[c,$]of r){n.info(re(S(t,c)));for(const p of $){const x=He(p),j=Xe(p.severity),A=p.ruleId?O(` ${p.ruleId}`):"";n.info(` ${O(x)} ${j} ${p.message}${A}`)}}const i=e.filter(c=>c.severity==="error").length,s=e.filter(c=>c.severity==="warning").length;n.info(""),n.info(`${U(`${String(i)} error${i===1?"":"s"}`)}, ${D(`${String(s)} warning${s===1?"":"s"}`)}`)},ze=(e,t,n)=>{for(const r of e){const i=S(t,r.file),s=r.line??"",c=r.column??"";n.write(`${r.adapter} ${i} ${String(s)} ${String(c)} ${r.severity} ${r.ruleId??""} ${r.message}
8
8
  `)}},He=e=>e.line===void 0?"":e.column===void 0?String(e.line):`${String(e.line)}:${String(e.column)}`,Xe=e=>e==="error"?U("error"):e==="warning"?D("warn "):ie("info ");export{st as default};
@@ -1,2 +1,2 @@
1
- import{createRequire as F}from"node:module";import{i as W}from"../packem_shared/index-BjdW45xX.js";import{p as Y}from"../packem_shared/prompt-DMzaQEVa.js";import{e as U}from"../packem_shared/index-BzhrR_iC.js";import{l as B,m as X,n as J,D as Q,o as Z,$ as ee,k as _}from"../packem_shared/formatBytes-BHAzNIrn-CrusHOew.js";import{y as te}from"../packem_shared/isAccessibleSync-DYKTrrvc-C-_5cgwu.js";import{p as se}from"../packem_shared/readJsonSync-CbryXYxN-EWl7_7KX.js";import{h as re,U as oe}from"../packem_shared/writeFileSync-DJoHk3Ks-BPRoepNw.js";import{g as ne,r as ce}from"../packem_shared/packument-Df46y5MY.js";import{q as ie,j as ae,F as v,b as S,X as E,J as A}from"../packem_shared/index.server-sXNQYpsl.js";import{a as le,o as fe}from"../packem_shared/pm-runner-3iiQayy-.js";import{r as ue,a as pe}from"../packem_shared/command-runtime-p4IXiIf6.js";let V;const z=e=>(V??=F(import.meta.url))(e),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,M=e=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[t,s]=$.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return $.getBuiltinModule(e)}return z(e)},{renameSync:q}=M("node:fs"),{stripVTControlCharacters:G}=M("node:util"),de=(e={})=>{const t=e.isCi??W;return(e.isTty??!!(process.stdin.isTTY&&process.stdout.isTTY))&&!t},k=U(B(),"dlx-seen.json"),H=(e,t)=>`${e}@${t}`,me=e=>{if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.alertKeys)&&t.alertKeys.every(s=>typeof s=="string")&&typeof t.seenAt=="number"},P=()=>{try{if(te(k)){const e=se(k);if(e&&typeof e=="object"&&e.packages&&typeof e.packages=="object"&&e.version===1){const t={};for(const[s,r]of Object.entries(e.packages))me(r)&&(t[s]=r);return{packages:t,version:1}}}}catch{}return{packages:{},version:1}},he=e=>{try{re(B());const t=`${k}.${String(process.pid)}.tmp`;oe(t,JSON.stringify(e)),q(t,k)}catch{}},ge=(e,t,s)=>e.packages[H(t,s)],ye=(e,t)=>{if(!e)return!0;const s=new Set(Array.isArray(e.alertKeys)?e.alertKeys:[]);return t.some(r=>!s.has(r))},R=(e,t,s,r)=>{const o=P();o.packages[H(e,t)]={alertKeys:[...s].sort(),seenAt:r},he(o)},ve=/[\u0000-\u0008\u000B-\u001F\u007F]/g,K=e=>G(e).replaceAll(" "," ").replaceAll(ve,""),x=["CHANGELOG.md","CHANGELOG","changelog.md","CHANGES.md","HISTORY.md"],be=4e3,C=async(e,t,s)=>{if(t?.aborted)return;const r=new AbortController,o=setTimeout(()=>{r.abort()},be),a=()=>{r.abort()};t?.addEventListener("abort",a,{once:!0});try{const n=await fetch(e,{headers:s,signal:r.signal});return n.ok?await n.text():void 0}catch{return}finally{clearTimeout(o),t?.removeEventListener("abort",a)}},$e=e=>{const t=typeof e=="string"?e:e?.url;if(!t)return;const s=/github\.com[/:]([^/]+)\/([^/#]+?)(?:\.git)?(?:[/#]|$)/i.exec(t)??/^github:([^/]+)\/([^/#]+)/i.exec(t);return s?{directory:typeof e=="object"?e?.directory:void 0,owner:s[1],repo:s[2].replace(/\.git$/,"")}:void 0},O=(e,t)=>{const s=e.split(/\r?\n/),r=/^(#{1,4})\s+(.*)$/,o=t.replaceAll(/[$()*+.?[\\\]^{|}]/g,String.raw`\$&`),a=new RegExp(String.raw`(?<![\w.])${o}(?![\w.])`);let n=-1,u=0;for(const[c,l]of s.entries()){const f=r.exec(l);if(f&&a.test(f[2])){n=c,u=f[1].length;break}}if(n===-1)return;const i=[];for(let c=n+1;c<s.length;c+=1){const l=r.exec(s[c]);if(l&&l[1].length<=u)break;i.push(s[c])}return i},I=(e,t=4)=>e.map(r=>r.trim()).filter(r=>r.length>0).map(r=>K(r.replace(/^#{1,6}\s+/,"").replace(/^[*-]\s+/,"- ")).trim()).filter(r=>r.length>0&&!/^\[.*\]:/.test(r)).slice(0,t),L=(e,t)=>{if(!e)return"";const s=Date.parse(e);if(Number.isNaN(s))return"";const r=Math.floor((t-s)/(1440*60*1e3));if(r<=0)return"today";if(r===1)return"1d ago";if(r<30)return`${String(r)}d ago`;const o=Math.floor(r/30);return o<12?`${String(o)}mo ago`:`${String(Math.floor(o/12))}y ago`},N=(e,t,s)=>{const r=e.time??{},o=L(r[t],s),a=[o?`${e.name}@${t} — published ${o}`:`${e.name}@${t}`],n=Date.parse(r[t]??""),i=Object.entries(r).filter(([c])=>c!=="created"&&c!=="modified"&&c!==t).sort((c,l)=>Date.parse(l[1])-Date.parse(c[1])).filter(([,c])=>Date.parse(c)<n).slice(0,3);for(const[c,l]of i)a.push(`- ${c} (${L(l,s)})`);return{lines:a,source:"npm-diff",version:t}},Se=async e=>{const{name:t,now:s,offline:r,packument:o,signal:a,version:n}=e;if(r)return o?N(o,n,s):void 0;for(const c of x){const l=`https://cdn.jsdelivr.net/npm/${t}@${n}/${c}`,f=await C(l,a);if(f){const y=O(f,n),p=I(y??f.split(/\r?\n/));if(p.length>0)return{lines:p,source:"package-file",url:l,version:n}}}const u=o?.versions[n],i=$e(u?.repository);if(i){const c=i.directory?`${i.directory.replaceAll(/^\/+|\/+$/g,"")}/`:"";for(const l of["HEAD","main","master"])for(const f of x){const y=`https://raw.githubusercontent.com/${i.owner}/${i.repo}/${l}/${c}${f}`,p=await C(y,a);if(p){const m=O(p,n),h=I(m??p.split(/\r?\n/));if(h.length>0){const d=`https://github.com/${i.owner}/${i.repo}/blob/${l}/${c}${f}`;return{lines:h,source:"repo-file",url:d,version:n}}}}}if(o)return N(o,n,s)},we={dynamicRequire:"dynamic require",envVars:"env access",filesystemAccess:"filesystem",networkAccess:"network",shellAccess:"shell",telemetry:"telemetry",unsafe:"eval/unsafe",usesEval:"eval/unsafe"},ke=["preinstall","install","postinstall"],Te=(e,t)=>({fileCount:e?.dist?.fileCount,tarballBytes:t?.size,unpackedBytes:e?.dist?.unpackedSize}),Ee=(e,t)=>{const s=ke.filter(n=>!!e?.scripts?.[n]),r=e?.bin,o=typeof r=="string"?["(default)"]:Object.keys(r??{}).map(n=>K(n)),a=[...new Set(t.map(n=>we[n.type]).filter(n=>n!==void 0))];return{bins:o,capabilities:a,lifecycleScripts:s}},_e=(e,t,s)=>{const r=e.get(`${t}@${s}`);if(r)return r;for(const o of e.values())if(o.name===t&&o.version===s)return o},Ae=async e=>{const{name:t,now:s,offline:r,signal:o,socketToken:a,spec:n,workspaceRoot:u}=e;let i;try{i=await ne(t,{offline:r,signal:o,workspaceRoot:u})}catch{i=void 0}const c=i?ce(i,n):void 0;if(!c)return;const l=i?.versions[c],f=async()=>{if(!(r||!a))try{const g=await J([{name:t,version:c}],{apiToken:a,minimumScore:Q});return _e(g,t,c)}catch{return}},y=Se({name:t,now:s,offline:r,packument:i,signal:o,version:c}).catch(()=>{}),[p,m]=await Promise.all([f(),y]),h=p?.alerts??[],d=[...new Set(h.filter(g=>g.severity==="critical"||g.severity==="high").map(g=>g.key))].sort(),b=p?Math.round((p.score.overall??X(p.score))*100):void 0;return{changelog:m,name:t,permissions:Ee(l,h),security:{alerts:h,available:!!p,highSeverityKeys:d,score:b},size:Te(l,p),version:c}},w=e=>Z(G(e)),Re={critical:E,high:E,low:v,medium:S},D=e=>{if(!(e===void 0||e<0))return ee(e,{decimals:1,space:!0})},xe=e=>{const{fileCount:t,tarballBytes:s,unpackedBytes:r}=e.size,o=D(r),a=D(s);if(o&&a){const n=t===void 0?"":`, ${String(t)} files`;return`${o} unpacked (${a} tarball${n})`}if(o)return`${o} unpacked`;if(a)return`${a} tarball`},Ce=e=>{const{alerts:t,available:s,score:r}=e.security;if(!s)return v("unavailable — set VIS_SOCKET_TOKEN for a Socket.dev score");const o=r===void 0?v:r>=70?A:r>=40?S:E,a=r===void 0?"n/a":`${String(r)}/100`,n=new Map;for(const l of t)n.set(l.severity,(n.get(l.severity)??0)+1);const u=[],i=["critical","high","medium","low"];for(const l of i){const f=n.get(l);f&&u.push(Re[l](`${String(f)} ${l}`))}const c=u.length>0?` ${S("!")} ${u.join(", ")}`:` ${A("no alerts")}`;return`${o(a)} ${v("(Socket.dev)")}${c}`},Oe=e=>{const{bins:t,capabilities:s,lifecycleScripts:r}=e.permissions,o=[];for(const a of r)o.push(S(`${a} script`));for(const a of s)o.push(S(a));return t.length>0&&o.push(v(`bins: ${t.join(", ")}`)),o.length>0?o.join(v(" · ")):void 0},Ie=e=>{const t=[],s=xe(e);s&&t.push({label:"size",values:[s]}),t.push({label:"score",values:[Ce(e)]});const r=Oe(e);if(r&&t.push({label:"perms",values:[r]}),e.changelog){const o=e.changelog.source==="npm-diff"?"registry":e.changelog.source==="repo-file"?"repo CHANGELOG":"CHANGELOG";t.push({label:"latest",values:[...e.changelog.lines,v(`source: ${o}`)]})}return t},j=6,Le=e=>{const t=Ie(e),s=` first run: ${e.name}@${e.version} `,r=[];for(const i of t)i.values.forEach((c,l)=>{const f=l===0?ie(i.label.padEnd(j)):" ".repeat(j);r.push(`${f} ${c}`)});const o=Math.max(w(s),...r.map(i=>w(i))),a=i=>`${i}${" ".repeat(Math.max(0,o-w(i)))}`,n=`┌─${ae(s)}${"─".repeat(Math.max(0,o-w(s)))}─┐`,u=`└─${"─".repeat(o)}─┘`;return[n,...r.map(i=>`│ ${a(i)} │`),u]},Ne=e=>{if(e.startsWith("@")){const s=e.indexOf("@",1);return s===-1?{name:e}:{name:e.slice(0,s),spec:e.slice(s+1)}}const t=e.indexOf("@");return t<=0?{name:e}:{name:e.slice(0,t),spec:e.slice(t+1)}},De=e=>e===""||e.startsWith(".")||e.startsWith("/")||e.startsWith("~")?!1:!(e.startsWith("@")?e.slice(1):e).includes(":"),je=6e3,Me=e=>{process.stdout.write(e)},Be=async e=>{const{forceInfo:t=!1,noInfo:s=!1,offline:r=!1,pkg:o,socketToken:a,workspaceRoot:n,yes:u=!1}=e;if(s||!De(o))return{proceed:!0};const i=e.now??Date.now(),c=u||!de({isCi:e.isCi,isTty:e.isTty}),l=e.output??Me;if(c&&!t)return{proceed:!0};const{name:f,spec:y}=Ne(o),p=new AbortController;let m;const h=new Promise(T=>{m=setTimeout(()=>{p.abort(),T(void 0)},je)}),d=await Promise.race([Ae({name:f,now:i,offline:r,signal:p.signal,socketToken:a,spec:y,workspaceRoot:n}).catch(()=>{}),h]);if(m&&clearTimeout(m),!d)return{proceed:!0};const b=ge(P(),d.name,d.version);if(!t&&!ye(b,d.security.highSeverityKeys))return{proceed:!0};for(const T of Le(d))l(`${T}
2
- `);if(c)return R(d.name,d.version,d.security.highSeverityKeys,i),{proceed:!0};const g=await Y("? Ok to proceed? (y/N) ",e.readline);return g&&R(d.name,d.version,d.security.highSeverityKeys,i),{proceed:g}},Je=async({argument:e,logger:t,options:s,process:r,visConfig:o,workspaceRoot:a})=>{const n=e;if(!n||n.length===0)throw new Error("No package specified. Usage: vis dlx <package[@version]> [args...]");const[u,...i]=n,c=a??r.cwd,l=s.package?Array.isArray(s.package)?s.package:[s.package]:[],f=s.shellMode?l:[u,...l];for(const h of f){const d=!s.info||_(r.env.VIS_DLX_NO_INFO),b=!d&&s.info;if(!(await Be({forceInfo:b,noInfo:d,offline:s.offline||!1,pkg:h,socketToken:o?.security?.socket?.apiToken??r.env.VIS_SOCKET_TOKEN,workspaceRoot:c,yes:s.yes||_(r.env.VIS_DLX_YES)})).proceed){t.info("Aborted."),process.exitCode=1;return}}const y=ue({logger:t,options:s,visConfig:o},c),p=le(c,{backend:pe(y),configBackend:o?.install?.backend,configCorepack:o?.install?.corepack}),m=fe(p,{additionalPackages:l,args:i,package:u,shellMode:s.shellMode||!1,silent:s.silent||!1},c,t,{offline:s.offline||!1});m!==0&&(process.exitCode=m)};export{Je as default};
1
+ import{createRequire as F}from"node:module";import{i as W}from"../packem_shared/index-BjdW45xX.js";import{p as Y}from"../packem_shared/prompt-DMzaQEVa.js";import{e as U}from"../packem_shared/index-BdMIfGVZ.js";import{l as B,m as X,n as J,D as Q,o as Z,$ as ee,k as _}from"../packem_shared/formatBytes-BHAzNIrn-DRcKvqnb.js";import{y as te}from"../packem_shared/isAccessibleSync-DYKTrrvc-BwaMhQs0.js";import{p as se}from"../packem_shared/readJsonSync-CbryXYxN-Bm5i10UW.js";import{h as re,U as oe}from"../packem_shared/writeFileSync-DJoHk3Ks-Dhem3Uof.js";import{g as ne,r as ce}from"../packem_shared/packument-C9nRiBJf.js";import{q as ie,j as ae,F as v,b as S,X as E,J as A}from"../packem_shared/index.server-D8BLnYZO.js";import{a as le,o as fe}from"../packem_shared/pm-runner-ImwtpnWY.js";import{r as ue,a as pe}from"../packem_shared/command-runtime-BXvH5EC0.js";let V;const z=e=>(V??=F(import.meta.url))(e),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,M=e=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[t,s]=$.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return $.getBuiltinModule(e)}return z(e)},{renameSync:q}=M("node:fs"),{stripVTControlCharacters:G}=M("node:util"),de=(e={})=>{const t=e.isCi??W;return(e.isTty??!!(process.stdin.isTTY&&process.stdout.isTTY))&&!t},k=U(B(),"dlx-seen.json"),H=(e,t)=>`${e}@${t}`,me=e=>{if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.alertKeys)&&t.alertKeys.every(s=>typeof s=="string")&&typeof t.seenAt=="number"},P=()=>{try{if(te(k)){const e=se(k);if(e&&typeof e=="object"&&e.packages&&typeof e.packages=="object"&&e.version===1){const t={};for(const[s,r]of Object.entries(e.packages))me(r)&&(t[s]=r);return{packages:t,version:1}}}}catch{}return{packages:{},version:1}},he=e=>{try{re(B());const t=`${k}.${String(process.pid)}.tmp`;oe(t,JSON.stringify(e)),q(t,k)}catch{}},ge=(e,t,s)=>e.packages[H(t,s)],ye=(e,t)=>{if(!e)return!0;const s=new Set(Array.isArray(e.alertKeys)?e.alertKeys:[]);return t.some(r=>!s.has(r))},R=(e,t,s,r)=>{const o=P();o.packages[H(e,t)]={alertKeys:[...s].sort(),seenAt:r},he(o)},ve=/[\u0000-\u0008\u000B-\u001F\u007F]/g,K=e=>G(e).replaceAll(" "," ").replaceAll(ve,""),x=["CHANGELOG.md","CHANGELOG","changelog.md","CHANGES.md","HISTORY.md"],be=4e3,C=async(e,t,s)=>{if(t?.aborted)return;const r=new AbortController,o=setTimeout(()=>{r.abort()},be),a=()=>{r.abort()};t?.addEventListener("abort",a,{once:!0});try{const n=await fetch(e,{headers:s,signal:r.signal});return n.ok?await n.text():void 0}catch{return}finally{clearTimeout(o),t?.removeEventListener("abort",a)}},$e=e=>{const t=typeof e=="string"?e:e?.url;if(!t)return;const s=/github\.com[/:]([^/]+)\/([^/#]+?)(?:\.git)?(?:[/#]|$)/i.exec(t)??/^github:([^/]+)\/([^/#]+)/i.exec(t);return s?{directory:typeof e=="object"?e?.directory:void 0,owner:s[1],repo:s[2].replace(/\.git$/,"")}:void 0},O=(e,t)=>{const s=e.split(/\r?\n/),r=/^(#{1,4})\s+(.*)$/,o=t.replaceAll(/[$()*+.?[\\\]^{|}]/g,String.raw`\$&`),a=new RegExp(String.raw`(?<![\w.])${o}(?![\w.])`);let n=-1,u=0;for(const[c,l]of s.entries()){const f=r.exec(l);if(f&&a.test(f[2])){n=c,u=f[1].length;break}}if(n===-1)return;const i=[];for(let c=n+1;c<s.length;c+=1){const l=r.exec(s[c]);if(l&&l[1].length<=u)break;i.push(s[c])}return i},I=(e,t=4)=>e.map(r=>r.trim()).filter(r=>r.length>0).map(r=>K(r.replace(/^#{1,6}\s+/,"").replace(/^[*-]\s+/,"- ")).trim()).filter(r=>r.length>0&&!/^\[.*\]:/.test(r)).slice(0,t),L=(e,t)=>{if(!e)return"";const s=Date.parse(e);if(Number.isNaN(s))return"";const r=Math.floor((t-s)/(1440*60*1e3));if(r<=0)return"today";if(r===1)return"1d ago";if(r<30)return`${String(r)}d ago`;const o=Math.floor(r/30);return o<12?`${String(o)}mo ago`:`${String(Math.floor(o/12))}y ago`},N=(e,t,s)=>{const r=e.time??{},o=L(r[t],s),a=[o?`${e.name}@${t} — published ${o}`:`${e.name}@${t}`],n=Date.parse(r[t]??""),i=Object.entries(r).filter(([c])=>c!=="created"&&c!=="modified"&&c!==t).sort((c,l)=>Date.parse(l[1])-Date.parse(c[1])).filter(([,c])=>Date.parse(c)<n).slice(0,3);for(const[c,l]of i)a.push(`- ${c} (${L(l,s)})`);return{lines:a,source:"npm-diff",version:t}},Se=async e=>{const{name:t,now:s,offline:r,packument:o,signal:a,version:n}=e;if(r)return o?N(o,n,s):void 0;for(const c of x){const l=`https://cdn.jsdelivr.net/npm/${t}@${n}/${c}`,f=await C(l,a);if(f){const y=O(f,n),p=I(y??f.split(/\r?\n/));if(p.length>0)return{lines:p,source:"package-file",url:l,version:n}}}const u=o?.versions[n],i=$e(u?.repository);if(i){const c=i.directory?`${i.directory.replaceAll(/^\/+|\/+$/g,"")}/`:"";for(const l of["HEAD","main","master"])for(const f of x){const y=`https://raw.githubusercontent.com/${i.owner}/${i.repo}/${l}/${c}${f}`,p=await C(y,a);if(p){const m=O(p,n),h=I(m??p.split(/\r?\n/));if(h.length>0){const d=`https://github.com/${i.owner}/${i.repo}/blob/${l}/${c}${f}`;return{lines:h,source:"repo-file",url:d,version:n}}}}}if(o)return N(o,n,s)},we={dynamicRequire:"dynamic require",envVars:"env access",filesystemAccess:"filesystem",networkAccess:"network",shellAccess:"shell",telemetry:"telemetry",unsafe:"eval/unsafe",usesEval:"eval/unsafe"},ke=["preinstall","install","postinstall"],Te=(e,t)=>({fileCount:e?.dist?.fileCount,tarballBytes:t?.size,unpackedBytes:e?.dist?.unpackedSize}),Ee=(e,t)=>{const s=ke.filter(n=>!!e?.scripts?.[n]),r=e?.bin,o=typeof r=="string"?["(default)"]:Object.keys(r??{}).map(n=>K(n)),a=[...new Set(t.map(n=>we[n.type]).filter(n=>n!==void 0))];return{bins:o,capabilities:a,lifecycleScripts:s}},_e=(e,t,s)=>{const r=e.get(`${t}@${s}`);if(r)return r;for(const o of e.values())if(o.name===t&&o.version===s)return o},Ae=async e=>{const{name:t,now:s,offline:r,signal:o,socketToken:a,spec:n,workspaceRoot:u}=e;let i;try{i=await ne(t,{offline:r,signal:o,workspaceRoot:u})}catch{i=void 0}const c=i?ce(i,n):void 0;if(!c)return;const l=i?.versions[c],f=async()=>{if(!(r||!a))try{const g=await J([{name:t,version:c}],{apiToken:a,minimumScore:Q});return _e(g,t,c)}catch{return}},y=Se({name:t,now:s,offline:r,packument:i,signal:o,version:c}).catch(()=>{}),[p,m]=await Promise.all([f(),y]),h=p?.alerts??[],d=[...new Set(h.filter(g=>g.severity==="critical"||g.severity==="high").map(g=>g.key))].sort(),b=p?Math.round((p.score.overall??X(p.score))*100):void 0;return{changelog:m,name:t,permissions:Ee(l,h),security:{alerts:h,available:!!p,highSeverityKeys:d,score:b},size:Te(l,p),version:c}},w=e=>Z(G(e)),Re={critical:E,high:E,low:v,medium:S},D=e=>{if(!(e===void 0||e<0))return ee(e,{decimals:1,space:!0})},xe=e=>{const{fileCount:t,tarballBytes:s,unpackedBytes:r}=e.size,o=D(r),a=D(s);if(o&&a){const n=t===void 0?"":`, ${String(t)} files`;return`${o} unpacked (${a} tarball${n})`}if(o)return`${o} unpacked`;if(a)return`${a} tarball`},Ce=e=>{const{alerts:t,available:s,score:r}=e.security;if(!s)return v("unavailable — set VIS_SOCKET_TOKEN for a Socket.dev score");const o=r===void 0?v:r>=70?A:r>=40?S:E,a=r===void 0?"n/a":`${String(r)}/100`,n=new Map;for(const l of t)n.set(l.severity,(n.get(l.severity)??0)+1);const u=[],i=["critical","high","medium","low"];for(const l of i){const f=n.get(l);f&&u.push(Re[l](`${String(f)} ${l}`))}const c=u.length>0?` ${S("!")} ${u.join(", ")}`:` ${A("no alerts")}`;return`${o(a)} ${v("(Socket.dev)")}${c}`},Oe=e=>{const{bins:t,capabilities:s,lifecycleScripts:r}=e.permissions,o=[];for(const a of r)o.push(S(`${a} script`));for(const a of s)o.push(S(a));return t.length>0&&o.push(v(`bins: ${t.join(", ")}`)),o.length>0?o.join(v(" · ")):void 0},Ie=e=>{const t=[],s=xe(e);s&&t.push({label:"size",values:[s]}),t.push({label:"score",values:[Ce(e)]});const r=Oe(e);if(r&&t.push({label:"perms",values:[r]}),e.changelog){const o=e.changelog.source==="npm-diff"?"registry":e.changelog.source==="repo-file"?"repo CHANGELOG":"CHANGELOG";t.push({label:"latest",values:[...e.changelog.lines,v(`source: ${o}`)]})}return t},j=6,Le=e=>{const t=Ie(e),s=` first run: ${e.name}@${e.version} `,r=[];for(const i of t)i.values.forEach((c,l)=>{const f=l===0?ie(i.label.padEnd(j)):" ".repeat(j);r.push(`${f} ${c}`)});const o=Math.max(w(s),...r.map(i=>w(i))),a=i=>`${i}${" ".repeat(Math.max(0,o-w(i)))}`,n=`┌─${ae(s)}${"─".repeat(Math.max(0,o-w(s)))}─┐`,u=`└─${"─".repeat(o)}─┘`;return[n,...r.map(i=>`│ ${a(i)} │`),u]},Ne=e=>{if(e.startsWith("@")){const s=e.indexOf("@",1);return s===-1?{name:e}:{name:e.slice(0,s),spec:e.slice(s+1)}}const t=e.indexOf("@");return t<=0?{name:e}:{name:e.slice(0,t),spec:e.slice(t+1)}},De=e=>e===""||e.startsWith(".")||e.startsWith("/")||e.startsWith("~")?!1:!(e.startsWith("@")?e.slice(1):e).includes(":"),je=6e3,Me=e=>{process.stdout.write(e)},Be=async e=>{const{forceInfo:t=!1,noInfo:s=!1,offline:r=!1,pkg:o,socketToken:a,workspaceRoot:n,yes:u=!1}=e;if(s||!De(o))return{proceed:!0};const i=e.now??Date.now(),c=u||!de({isCi:e.isCi,isTty:e.isTty}),l=e.output??Me;if(c&&!t)return{proceed:!0};const{name:f,spec:y}=Ne(o),p=new AbortController;let m;const h=new Promise(T=>{m=setTimeout(()=>{p.abort(),T(void 0)},je)}),d=await Promise.race([Ae({name:f,now:i,offline:r,signal:p.signal,socketToken:a,spec:y,workspaceRoot:n}).catch(()=>{}),h]);if(m&&clearTimeout(m),!d)return{proceed:!0};const b=ge(P(),d.name,d.version);if(!t&&!ye(b,d.security.highSeverityKeys))return{proceed:!0};for(const T of Le(d))l(`${T}
2
+ `);if(c)return R(d.name,d.version,d.security.highSeverityKeys,i),{proceed:!0};const g=await Y("? Ok to proceed? (y/N) ",e.readline);return g&&R(d.name,d.version,d.security.highSeverityKeys,i),{proceed:g}},Je=async({argument:e,logger:t,options:s,process:r,visConfig:o,workspaceRoot:a})=>{const n=e;if(!n||n.length===0)throw new Error("No package specified. Usage: vis dlx <package[@version]> [args...]");const[u,...i]=n,c=a??r.cwd,l=s.package?Array.isArray(s.package)?s.package:[s.package]:[],f=s.shellMode?l:[u,...l];for(const h of f){const d=!s.info||_(r.env.VIS_DLX_NO_INFO),b=!d&&s.info;if(!(await Be({forceInfo:b,noInfo:d,offline:s.offline||!1,pkg:h,socketToken:o?.security?.socket?.apiToken??r.env.VIS_SOCKET_TOKEN,workspaceRoot:c,yes:s.yes||_(r.env.VIS_DLX_YES)})).proceed){t.info("Aborted."),process.exitCode=1;return}}const y=ue({options:s,visConfig:o},c),p=le(c,{backend:pe(y),configBackend:o?.install?.backend,configCorepack:o?.install?.corepack}),m=fe(p,{additionalPackages:l,args:i,package:u,shellMode:s.shellMode||!1,silent:s.silent||!1},c,t,{offline:s.offline||!1});m!==0&&(process.exitCode=m)};export{Je as default};
@@ -1,28 +1,39 @@
1
- import{createRequire as be}from"node:module";import{F as $,b as L,X as ce,J,q as ae}from"../packem_shared/index.server-sXNQYpsl.js";import{v as T,a as G,U as I,z as Se,e as M}from"../packem_shared/index-BzhrR_iC.js";import{fingerprint as E,scan as le,scanFiles as Ee,inspectRuleset as Ie,listRules as K,listRequiredValidators as Te,scanGitHistory as Re}from"@visulima/secret-scanner";import{a4 as Ae,a5 as Q,p as y}from"./cli-main.js";import{I as je,W as Ne}from"../packem_shared/getRandomSpinner-4ZEcbTYv-DCyIuj19.js";import{U as Fe}from"../packem_shared/writeFileSync-DJoHk3Ks-BPRoepNw.js";import{y as X}from"../packem_shared/isAccessibleSync-DYKTrrvc-C-_5cgwu.js";import{p as Me}from"../packem_shared/readJsonSync-CbryXYxN-EWl7_7KX.js";let ve;const ke=e=>(ve??=be(import.meta.url))(e),j=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,W=e=>{if(typeof j<"u"&&j.versions&&j.versions.node){const[t,n]=j.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return j.getBuiltinModule(e)}return ke(e)},{createRequire:Ce}=W("node:module"),{pathToFileURL:ue}=W("node:url"),{execFileSync:Le}=W("node:child_process");let Oe;const _e=e=>(Oe??=Ce(import.meta.url))(e),N=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Be=e=>{if(typeof N<"u"&&N.versions&&N.versions.node){const[t,n]=N.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return N.getBuiltinModule(e)}return _e(e)},{styleText:qe}=Be("node:util"),Ue={error:"✖",info:"ℹ",success:"✓",warning:"⚠"},De=()=>{const{env:e}=process;return!!e.CI||e.CONTINUOUS_INTEGRATION==="true"||"BUILD_NUMBER"in e||"RUN_ID"in e},Pe=/\u001B\[[\d;]*[a-z]/gi,He=e=>[...e.replaceAll(Pe,"")].length,ze=e=>{const t=[];return e.bold&&t.push("bold"),e.dim&&t.push("dim"),e.italic&&t.push("italic"),e.underline&&t.push("underline"),e.strikethrough&&t.push("strikethrough"),e.color&&t.push(e.color),e.bgColor&&t.push(e.bgColor),t.length===0?n=>n:n=>qe(t,n)};let Ve=class{#i=0;#l;#e=!1;#r="";#o="";#m=0;#u=0;#t;#n;#f="";#c;#p;#s;#x;#d=0;#a;#b;constructor(t={},n){if(t.frames)this.#c=t.frames;else{const s=t.name??"dots",r=Ne(s);if(!r)throw new Error(`Unknown spinner "${s}". Pass a custom \`frames\` set or use one of: ${je().join(", ")}.`);this.#c=r}this.#p=t.verbose!==!1,this.#r=t.prefixText??"",this.#t=n,this.#s=t.stream??process.stderr,this.#x=n?!0:this.#s.isTTY&&!De(),this.#b={...Ue,...t.icons},typeof t.style=="function"?this.#a=t.style:t.style&&(this.#a=ze(t.style))}get elapsedTime(){return this.#m===0?0:(this.#u||Date.now())-this.#m}get text(){return this.#o}set text(t){this.#o=t,this.#e&&this.#w()}get prefixText(){return this.#r}set prefixText(t){this.#r=t,this.#e&&this.#w()}get isRunning(){return this.#e}setInteractiveManager(t){this.#t=t}setMultiSpinner(t){this.#n=t}tick(){this.#e&&(this.#i=(this.#i+1)%this.#c.frames.length)}start(t,n){return this.#e?this:this.#p?(this.#e=!0,this.#m=Date.now(),this.#u=0,this.#i=0,this.#f="",t&&(this.#o=t),n?.prefixText&&(this.#r=n.prefixText),this.#n?(this.#n.renderAll(),this):(this.#t?(this.#t.hook(),this.#v(),this.#y()):(this.#k(),this.#y()),this)):this}stop(){if(this.#e){if(this.#h(),this.#e=!1,this.#u=Date.now(),this.#f="",this.#n){this.#n.renderAll();return}this.#t?(this.#t.erase("stdout"),this.#t.unhook(!1)):this.#$()}}stopAndPersist(t){if(!this.#e||(this.#h(),this.#e=!1,this.#u=Date.now(),!this.#p))return;const n=t?.prefixText??this.#r,s=t?.text??this.#o;let r=t?.symbol??"";n&&(r=r?`${n} ${r}`:n),s&&(r=r?`${r} ${s}`:s),this.#S(r)}succeed(t){this.#g("success",t)}failed(t){this.#g("error",t)}warn(t){this.#g("warning",t)}info(t){this.#g("info",t)}pause(){this.#h()}resume(){this.#e&&(this.#h(),this.#n||this.#y())}getFrameOutput(){if(!this.#e&&this.#f)return this.#f;const t=this.#c.frames[this.#i];let n=this.#a?this.#a(t):t;return this.#r&&(n=`${this.#r} ${n}`),this.#o&&(n=`${n} ${this.#o}`),n}#y(){this.#x&&(this.#l=setInterval(()=>{this.#e&&(this.#i=(this.#i+1)%this.#c.frames.length,this.#w())},this.#c.interval),this.#l.unref())}#h(){this.#l&&(clearInterval(this.#l),this.#l=void 0)}#w(){this.#n?this.#n.renderAll():this.#t?this.#v():this.#k()}#v(){this.#t&&this.#t.update("stdout",[this.getFrameOutput()])}#k(){const t=this.getFrameOutput();if(this.#$(),this.#s.isTTY){this.#s.write(t);const n=this.#s.columns||80;this.#d=Math.max(1,Math.ceil(He(t)/n))}else this.#s.write(`${t}
2
- `),this.#d=0}#$(){if(this.#d>0&&this.#s.isTTY){for(let t=1;t<this.#d;t+=1)this.#s.write("\x1B[1A\x1B[2K");this.#s.write("\r\x1B[K")}this.#d=0}#S(t){this.#f=t,this.#n?this.#n.renderAll():this.#t?(this.#t.update("stdout",[t]),this.#t.unhook(!1)):(this.#$(),this.#s.write(`${t}
3
- `))}#g(t,n){if(!this.#e||(this.#h(),this.#e=!1,this.#u=Date.now(),!this.#p))return;let s="";const r=this.#b[t];r&&(s=this.#a?this.#a(r):r),this.#r&&(s=`${this.#r} ${s}`),n&&(s=`${s} ${n}`),this.#S(s)}};const We=(e,t,n)=>{const s=n.toLowerCase();e[s]??=new Map;const r=e[s].get(t);if(r!==void 0)return r;const{size:i}=e[s],c=`<${n.toUpperCase()}${i>0?String(i):""}>`;return e[s].set(t,c),c},Z=(e,t)=>{const{replacement:n,tag:s,text:r}=t;return typeof n=="function"?String(n(r,void 0)):typeof n=="string"?n:We(e,r,s)},Je=(e,t)=>{const n={};let s="",r=0;for(const i of e){const{start:c,text:o}=i;if(o==="")continue;if(Number.isInteger(c)&&c>=0&&t.slice(c,c+o.length)===o){if(c<r)continue;s+=t.slice(r,c)+Z(n,i),r=c+o.length;continue}let a=t.indexOf(o,r);if(a===-1)continue;const l=Z(n,i);for(;a!==-1;)s+=t.slice(r,a)+l,r=a+o.length,a=t.indexOf(o,r)}return s+t.slice(r)},Ge=e=>[...e.reduce((t,n)=>t.set(n.text+String(n.start)+n.tag,n),new Map).values()].toSorted((t,n)=>{const s=t.start-n.start;return s!==0?s:n.text.length-t.text.length}),Ke=(e,t)=>{const n=[];for(const s of e){const{key:r,pattern:i}=s,c=s.compiledPattern??new RegExp(i,"giu");c.lastIndex=0;let o;for(;(o=c.exec(t))!==null;){const a=s;n.push({replacement:a.userReplacement??a.replacement!==void 0?a.replacement:void 0,start:o.index,tag:r,text:o[0]}),o.index===c.lastIndex&&(c.lastIndex+=1)}}return n},Xe=(e,t,n,s)=>Ge([...Ke(n,e)]),fe=(e,t,n)=>{const s=[],r=[];for(const o of t)typeof o=="object"&&o.pattern&&s.push(o),r.push((typeof o=="object"?o.key:String(o)).toLowerCase());let i=e;const c=Xe(e,r,s);return i=Je(c,i),i},k=e=>{const t=typeof e;return e!==null&&(t==="object"||t==="function")},q=new Set(["__proto__","prototype","constructor"]),Ye=Math.max(...[...q].map(e=>e.length)),de=1e6,Qe=e=>e>="0"&&e<="9";function he(e){if(e==="0")return!0;if(/^[1-9]\d*$/.test(e)){const t=Number.parseInt(e,10);return t<=Number.MAX_SAFE_INTEGER&&t<=de}return!1}function D(e,t){return q.has(e)?!1:(e&&he(e)?t.push(Number.parseInt(e,10)):t.push(e),!0)}function Ze(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);const t=[];let n="",s="",r=!1,i="start",c=!1,o=0;for(const a of e){if(o++,c){n+=a,c=!1;continue}if(a==="\\"){if(i==="index")throw new Error(`Invalid character '${a}' in an index at position ${o}`);if(i==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${o}`);c=!0,i=i==="start"?"property":i;continue}switch(a){case".":{if(i==="index")throw new Error(`Invalid character '${a}' in an index at position ${o}`);if(i==="indexEnd"){i="property";break}if(!D(n,t))return[];n="",i="property";break}case"[":{if(i==="index")throw new Error(`Invalid character '${a}' in an index at position ${o}`);if(i==="indexEnd"){i="index";break}if(i==="property"&&n.length<=Ye&&q.has(n))return[];r=i==="property",i="index";break}case"]":{if(i==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${o}`);if(i!=="index"){i==="start"&&(i="property"),n+=a;break}if(s===""){n+="[]",i="property";break}if((n!==""||r)&&!D(n,t))return[];n="",r=!1;const l=Number.parseInt(s,10),f=l<=de&&s===String(l);t.push(f?l:s),s="",i="indexEnd";break}default:{if(i==="index"){if(!Qe(a))throw new Error(`Invalid character '${a}' in an index at position ${o}`);s+=a;break}if(i==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${o}`);i==="start"&&(i="property"),n+=a}}}switch(c&&(n+="\\"),i){case"property":{if(!D(n,t))return[];break}case"index":throw new Error("Index was not closed");case"start":{t.push("");break}}return t}function U(e){if(typeof e=="string")return Ze(e);if(Array.isArray(e)){const t=[];for(const[n,s]of e.entries()){if(typeof s!="string"&&typeof s!="number")throw new TypeError(`Expected a string or number for path segment at index ${n}, got ${typeof s}`);if(typeof s=="number"&&!Number.isFinite(s))throw new TypeError(`Path segment at index ${n} must be a finite number, got ${s}`);if(q.has(s))return[];typeof s=="string"&&he(s)?t.push(Number.parseInt(s,10)):t.push(s)}return t}return[]}function et(e,t,n){if(!k(e)||typeof t!="string"&&!Array.isArray(t))return e;const s=U(t);if(s.length===0)return n;for(let r=0;r<s.length;r++){const i=s[r];if(e=e[i],e==null){if(r!==s.length-1)return n;break}}return e===void 0?n:e}function tt(e,t,n){if(!k(e)||typeof t!="string"&&!Array.isArray(t))return e;const s=e,r=U(t);if(r.length===0)return e;for(let i=0;i<r.length;i++){const c=r[i];if(i===r.length-1){e[c]=n;continue}const o=e[c];if(k(o)){e=o;continue}const a=typeof r[i+1]=="number";e[c]=a?[]:{},e=e[c]}return s}function nt(e,t){if(!k(e)||typeof t!="string"&&!Array.isArray(t))return!1;const n=U(t);if(n.length===0)return!1;for(let s=0;s<n.length;s++){const r=n[s];if(s===n.length-1)return Object.hasOwn(e,r)?(delete e[r],!0):!1;const i=e[r];if(!k(i))return!1;e=i}}function ee(e,t){if(!k(e)||typeof t!="string"&&!Array.isArray(t))return!1;const n=U(t);if(n.length===0)return!1;for(const s of n){if(!k(e)||!(s in e))return!1;e=e[s]}return!0}const P="#;/?:@&",H=new RegExp(String.raw`([${P}][^${P}=\s]+=[^${P}=\s]*)`,"g"),st=e=>{const t=[];let n=0;H.lastIndex=0;let s=H.exec(e);for(;s!==null;){const{0:i,index:c}=s;t.push({key:void 0,value:e.slice(n,c+1)}),n=c+i.length,t.push({key:i.slice(1,i.indexOf("=")),value:i.slice(i.indexOf("=")+1)}),s=H.exec(e)}const r=e.slice(n);return r.length>0&&t.push({key:void 0,value:r}),t},te=(e,t)=>{for(let n=0;n<e.length;n+=1){let s=e[n].string,r=e[n].index;for(;r<t.length;){const i=t[r];if(!s.includes(i))break;const c=s.slice(1);for(e.push({index:r,string:c}),c.includes(i)||e.pop(),s=s.slice(s.indexOf(i)+i.length),r+=1;t[r]==="";)r+=1;if(r>=t.length){if(t.at(-1)!==""&&s.length>0)break;return!0}}}return!1},z=(e,t)=>{if(!t.includes("*"))return t===e;const n=t.split("*");let s=0,r=e;for(;n[s]==="";)if(s+=1,s===t.length)return!0;if(s===0&&!e.startsWith(n[0]))return!1;const i=[];for(;s<n.length;){const c=n[s];if(!r.includes(c))return te(i,n);const o=r.slice(1);for(i.push({index:s,string:o}),o.includes(c)||i.pop(),r=r.slice(r.indexOf(c)+c.length),s+=1;n[s]==="";)s+=1}return s>=n.length&&n.at(-1)!==""&&r.length>0?r===e?!1:te(i,n):!0},rt=/(?:http|https):\/\/?/,R=(e,t,n)=>typeof e.replacement=="function"?e.replacement(t,n):e.replacement,pe=(e,t,n)=>e.wildcard?z(t,e.key)||z(n,e.key):t===e.key||n===e.key,it=(e,t,n,s)=>{n.remove?delete e[t]:e[t]=R(n,e[t],s)},ne=(e,t,n,s,r,i)=>{const c=[],o=[];for(const l of s)!l.wildcard&&!l.deep&&ee(e,l.key)?o.push(l):c.push(l);const a=Object.keys(e);for(const l of a){if(!Object.hasOwn(e,l))continue;const f=l.toLowerCase(),u=i?`${i}.${f}`:f;let h;for(const g of c)pe(g,f,u)&&(h=g);h?it(e,l,h,u):e[l]=x(e[l],t,n,c,r,u)}for(const l of o)if(ee(e,l.key))if(l.remove)nt(e,l.key);else{const f=i?`${i}.${l.key}`:l.key;tt(e,l.key,R(l,et(e,l.key),f))}},se=(e,t)=>{const n=t.toLowerCase();return e.find(s=>s.key===n||!!s.wildcard&&z(n,s.key))},ot=(e,t,n)=>{const s=st(e),r=[];for(const i of s){const{key:c,value:o}=i;if(c===void 0){const a=se(t,o);r.push(a?String(R(a,o,void 0)):fe(o,t))}else{const a=se(t,c);a?r.push(`${c}=${String(R(a,o,void 0))}`):r.push(`${c}=${o}`)}}return r.join("")},x=(e,t,n,s,r,i)=>{if(e==null)return e;if(typeof e=="object"&&e.constructor===String)return x(String(e),t,n,s,r,i);if(typeof e=="object"&&t.has(e))return t.get(e);if(typeof e=="object"&&!Array.isArray(e)){if(e instanceof Error){const o=new Error(e.message);Object.defineProperties(o,{name:{configurable:!0,enumerable:!1,value:e.name,writable:!0},stack:{configurable:!0,enumerable:!1,value:e.stack,writable:!0}}),e.code!==void 0&&(o.code=e.code);const a=Object.keys(e);for(const l of a)o[l]=e[l];return n(e,o),ne(o,t,n,s,r,i),o}if(e instanceof Map){const o=new Map;n(e,o);const a=e.entries();let l=a.next();for(;!l.done;){const[f,u]=l.value;if(typeof f=="string"||typeof f=="object"&&f!==null&&f.constructor===String){const h=f.toLowerCase(),g=i?`${i}.${h}`:h;let p;for(const m of s)pe(m,h,g)&&(p=m);p?p.remove||o.set(f,R(p,u,g)):o.set(f,x(u,t,n,s,r,g))}else o.set(x(f,t,n,s,r),x(u,t,n,s,r));l=a.next()}return o}if(e instanceof Set){const o=new Set;n(e,o);const a=e.values();let l=a.next();for(;!l.done;)o.add(x(l.value,t,n,s,r,i)),l=a.next();return o}const c={...e};return n(e,c),ne(c,t,n,s,r,i),c}if(typeof e=="string"){const c=e;try{const o=JSON.parse(c);if(typeof o=="object"&&o!==null){const a=x(o,t,n,s,r,i);return JSON.stringify(a)}}catch{}return rt.test(c)?ot(c,s):fe(c,s)}if(Array.isArray(e)){const c=[];n(e,c);for(const[o,a]of e.entries()){const l=o.toString().toLowerCase(),f=i?`${i}.${l}`.toLowerCase():l,u=s.find(h=>h.key===l||h.key===f);u?c.push(R(u,a,f)):c.push(x(a,t,n,s,r,f))}return c}return e},ct=(e,t)=>{const n=[];for(const s of e)if(typeof s=="string"){const r=s.includes("*");n.push({deep:!1,key:s.toLowerCase(),replacement:`<${s.toUpperCase()}>`,userReplacement:!1,wildcard:r})}else if(typeof s=="number")n.push({deep:!1,key:s.toString(),replacement:"<REDACTED>"});else{const r=s.key.toLowerCase(),i={...s,key:r,replacement:s.replacement??`<${r.toUpperCase()}>`,userReplacement:s.replacement!==void 0,wildcard:r.includes("*")?!0:s.wildcard};if(i.pattern!==void 0){const c=i.pattern instanceof RegExp?i.pattern.source:i.pattern;i.compiledPattern=new RegExp(c,"giu")}n.push(i)}return n},at=(e,t,n)=>{if(e==null||typeof e=="number"||typeof e=="boolean")return e;const s=new WeakMap;return x(e,s,(r,i)=>{s.set(r,i)},t,n)},ge=(e,t,n)=>{const s=ct(t);return at(e,s,n)},Y=(e={})=>{const t=new Ae(new Q(process.stdout),new Q(process.stderr));return new Ve(e,t)},lt=(e,t)=>{if(!T(e))return e;const n=G(t,e);return n===""||n.startsWith("..")?e:n},A=(e,t)=>{const n=lt(e.file,t);return n===e.file?e:{...e,file:n}},me=e=>{if(!X(e))return[];try{const t=Me(e);return Array.isArray(t)?t:[]}catch{return[]}},ut=(e,t,n)=>{const s=me(t).map(o=>A(o,n)),r=new Set(s.map(o=>E(o))),i=e.map(o=>A(o,n)),c=new Set(i.map(o=>E(o)));return{fresh:i.filter(o=>!r.has(E(o))),resolved:s.filter(o=>!c.has(E(o))),surviving:i.filter(o=>r.has(E(o)))}},ye=(e,t,n,s={})=>{const r=e.map(c=>A(c,n));let i;if(s.replace)i=r;else{const c=me(t).map(a=>A(a,n)),o=new Set;i=[];for(const a of[...c,...r]){const l=E(a);o.has(l)||(o.add(l),i.push(a))}}return Fe(t,`${JSON.stringify(i,null,4)}
4
- `),i.length},re=1,ft=e=>{const t=new Map;for(const n of e){const s=t.get(n.file);s?s.push(n):t.set(n.file,[n])}return t},dt=e=>{try{return Se(e).split(/\r?\n/)}catch{return}},ht=(e,t,n)=>{const s=Math.max(1,t);return`${e.slice(0,s-1).replaceAll(/[^\t]/g," ")}${"^".repeat(Math.max(1,n))}`},pt=(e,t,n,s={})=>{if(e.length===0)return n?$("No secrets detected."):"No secrets detected.";const r=n?{cyan:ae,dim:$,green:J,red:ce,yellow:L}:{cyan:o=>o,dim:o=>o,green:o=>o,red:o=>o,yellow:o=>o},i=[],c=ft(e);for(const[o,a]of c){const l=G(t,o)||o;i.push(r.cyan(l));const f=s.redact?void 0:dt(o);for(const u of a){const h=[u.source,u.confidence].filter(Boolean).join(", "),g=h?` ${r.dim(`(${h})`)}`:"",p=u.alternateMatches&&u.alternateMatches.length>0?` ${r.dim(`also: ${u.alternateMatches.join(", ")}`)}`:"";let m="";switch(u.validation){case"error":{m=` ${r.yellow("! error")}`;break}case"rejected":{m=` ${r.red("✗ rejected")}`;break}case"skipped":{m=` ${r.dim("— unverifiable")}`;break}case"verified":{m=` ${r.green("✓ verified")}`;break}}if(i.push(` ${r.red("✖")} ${r.yellow(`[${u.ruleId}]`)}${g}${m} ${r.dim(`line ${String(u.startLine)}:${String(u.startColumn)}`)}${p}`),f){const C=Math.max(0,u.startLine-1-re),b=Math.min(f.length,u.startLine+re);for(let d=C;d<b;d+=1){const S=String(d+1).padStart(4," "),v=d+1===u.startLine,w=v?r.red("▶"):" ";if(i.push(` ${w} ${r.dim(S)} │ ${f[d]??""}`),v){const O=Math.max(1,(u.endColumn??u.startColumn+1)-u.startColumn),xe=ht(f[d]??"",u.startColumn,O);i.push(` ${r.dim(" │ ")}${r.red(xe)}`)}}}i.push("")}}return i.join(`
5
- `).trimEnd()},gt=(e,t,n={})=>{if(e.length===0)return t?$("No secrets detected in git history."):"No secrets detected in git history.";const s=t?{cyan:ae,dim:$,green:J,red:ce,yellow:L}:{cyan:c=>c,dim:c=>c,green:c=>c,red:c=>c,yellow:c=>c},r=new Map;for(const c of e){const o=r.get(c.commit.sha);o?o.push(c):r.set(c.commit.sha,[c])}const i=[];for(const[c,o]of r){const{authorName:a,date:l,message:f}=o[0].commit;i.push(`${s.yellow(c.slice(0,10))} ${f}`),i.push(` ${s.dim(`${a} · ${l}`)}`);for(const u of o){const h=[u.source,u.confidence].filter(Boolean).join(", "),g=h?` ${s.dim(`(${h})`)}`:"",p=n.redact?"":` ${s.dim(u.match)}`;i.push(` ${s.red("✖")} ${s.yellow(`[${u.ruleId}]`)}${g} ${s.cyan(u.file)} ${s.dim(`line ${String(u.startLine)}:${String(u.startColumn)}`)}${p}`)}i.push("")}return i.join(`
6
- `).trimEnd()},mt=(e,t)=>{if(!T(e))return e.replaceAll("\\","/");try{return ue(e).toString()}catch{return`file://${I(t,e).replaceAll("\\","/")}`}},yt=(e,t=100)=>e.length<=t?e:`${e.slice(0,t-1).trimEnd()}…`,we=(e,t,n=process.cwd(),s=[])=>{const r=new Map(s.map(a=>[a.id,a])),i=new Set;for(const a of e)i.add(a.ruleId);const c=[...new Set([...r.keys(),...i])].sort((a,l)=>a.localeCompare(l)),o=new Map(c.map((a,l)=>[a,l]));return JSON.stringify({$schema:"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json",runs:[{originalUriBaseIds:{SRCROOT:{uri:ue(n).toString()}},results:e.map(a=>{const l={};return a.source&&(l.source=a.source),a.confidence&&(l.confidence=a.confidence),a.alternateMatches&&a.alternateMatches.length>0&&(l.alternateRules=a.alternateMatches),a.validation&&(l.validation=a.validation),{level:"error",locations:[{physicalLocation:{artifactLocation:{uri:mt(a.file,n),uriBaseId:T(a.file)?void 0:"SRCROOT"},region:{endColumn:a.endColumn,endLine:a.endLine,snippet:{text:a.match},startColumn:a.startColumn,startLine:a.startLine}}}],message:{text:a.description||a.ruleId},properties:Object.keys(l).length>0?l:void 0,ruleId:a.ruleId,ruleIndex:o.get(a.ruleId)??-1}}),tool:{driver:{informationUri:"https://visulima.com/packages/secret-scanner",name:"visulima-secret-scanner",rules:c.map(a=>{const l=r.get(a),f=l?.description??`Detected by rule \`${a}\``,u={};return l?.tags&&l.tags.length>0&&(u.tags=l.tags),l?.source&&(u.source=l.source),l?.confidence&&(u.confidence=l.confidence),{defaultConfiguration:{level:"error"},fullDescription:{text:f},helpUri:"https://visulima.com/packages/secret-scanner",id:a,name:a,properties:Object.keys(u).length>0?u:void 0,shortDescription:{text:yt(f)}}}),version:t}}}],version:"2.1.0"},void 0,2)},B=(e,t)=>{try{return Le("git",t,{cwd:e,encoding:"utf8",stdio:["ignore","pipe","pipe"]}).trim()}catch{return""}},V=e=>e.split(/\r?\n/).map(t=>t.trim()).filter(Boolean),wt=e=>V(B(e,["diff","--cached","--name-only","--diff-filter=ACMR"])).map(t=>T(t)?t:M(e,t)),ie=(e,t)=>{const n=B(e,["diff","--name-only","--diff-filter=ACMR",`${t}...HEAD`]),s=V(n);if(s.length===0){const r=B(e,["diff","--name-only","--diff-filter=ACMR",t]);return V(r).map(i=>T(i)?i:M(e,i))}return s.map(r=>T(r)?r:M(e,r))},_=e=>B(e,["rev-parse","--show-toplevel"]).length>0,F=".secrets-baseline.json",oe=e=>e?Array.isArray(e)?e:[e]:[],$e=e=>{const t=new Set(["json","sarif","text"]);if(e&&!t.has(e))throw new Error(`--format must be one of: ${[...t].join(", ")} (got "${e}")`);return e??"text"},$t=e=>{if(e===void 0)return;const t=new Set(["high","low","medium"]);if(!t.has(e))throw new Error(`--min-confidence must be one of: ${[...t].join(", ")} (got "${e}")`);return e},xt=async(e,t)=>{const n=await K(e);process.stdout.write(`${String(n.length)} rules loaded
1
+ import{createRequire as gt}from"node:module";import{F as x,b as Y,X as qe,J as ye,q as Ue}from"../packem_shared/index.server-D8BLnYZO.js";import{z as M,b as $e,U as F,a as yt,e as H}from"../packem_shared/index-BdMIfGVZ.js";import{fingerprint as N,scan as Pe,scanFiles as $t,inspectRuleset as bt,listRules as be,listRequiredValidators as xt,scanGitHistory as vt}from"@visulima/secret-scanner";import{p as $}from"./cli-main.js";import{I as kt,W as Et}from"../packem_shared/getRandomSpinner-4ZEcbTYv-DCyIuj19.js";import{U as St}from"../packem_shared/writeFileSync-DJoHk3Ks-Dhem3Uof.js";import{y as ve}from"../packem_shared/isAccessibleSync-DYKTrrvc-BwaMhQs0.js";import{p as Tt}from"../packem_shared/readJsonSync-CbryXYxN-Bm5i10UW.js";let mt;const wt=e=>(mt??=gt(import.meta.url))(e),_=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,we=e=>{if(typeof _<"u"&&_.versions&&_.versions.node){const[t,n]=_.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return _.getBuiltinModule(e)}return wt(e)},{createRequire:xe}=we("node:module"),{pathToFileURL:He}=we("node:url"),{execFileSync:It}=we("node:child_process");let At;const Bt=e=>(At??=xe(import.meta.url))(e),L=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Nt=e=>{if(typeof L<"u"&&L.versions&&L.versions.node){const[t,n]=L.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return L.getBuiltinModule(e)}return Bt(e)},{styleText:Rt}=Nt("node:util"),Ft={error:"✖",info:"ℹ",success:"✓",warning:"⚠"},Mt=()=>{const{env:e}=process;return!!e.CI||e.CONTINUOUS_INTEGRATION==="true"||"BUILD_NUMBER"in e||"RUN_ID"in e},jt=/\u001B\[[\d;]*[a-z]/gi,Ct=e=>[...e.replaceAll(jt,"")].length,Ot=e=>{const t=[];return e.bold&&t.push("bold"),e.dim&&t.push("dim"),e.italic&&t.push("italic"),e.underline&&t.push("underline"),e.strikethrough&&t.push("strikethrough"),e.color&&t.push(e.color),e.bgColor&&t.push(e.bgColor),t.length===0?n=>n:n=>Rt(t,n)};let Wt=class{#n=0;#i;#e=!1;#t="";#r="";#c=0;#o=0;#s;#a;#d="";#u;#g;#l;#b;#f=0;#h;#x;constructor(t={},n){if(t.frames)this.#u=t.frames;else{const s=t.name??"dots",i=Et(s);if(!i)throw new Error(`Unknown spinner "${s}". Pass a custom \`frames\` set or use one of: ${kt().join(", ")}.`);this.#u=i}this.#g=t.verbose!==!1,this.#t=t.prefixText??"",this.#s=n,this.#l=t.stream??process.stderr,this.#b=n?!0:this.#l.isTTY&&!Mt(),this.#x={...Ft,...t.icons},typeof t.style=="function"?this.#h=t.style:t.style&&(this.#h=Ot(t.style))}get elapsedTime(){return this.#c===0?0:(this.#o||Date.now())-this.#c}get text(){return this.#r}set text(t){this.#r=t,this.#e&&this.#y()}get prefixText(){return this.#t}set prefixText(t){this.#t=t,this.#e&&this.#y()}get isRunning(){return this.#e}setInteractiveManager(t){this.#s=t}setMultiSpinner(t){this.#a=t}tick(){this.#e&&(this.#n=(this.#n+1)%this.#u.frames.length)}start(t,n){return this.#e?this:this.#g?(this.#e=!0,this.#c=Date.now(),this.#o=0,this.#n=0,this.#d="",t&&(this.#r=t),n?.prefixText&&(this.#t=n.prefixText),this.#a?(this.#a.renderAll(),this):(this.#s?(this.#s.hook(),this.#v(),this.#w()):(this.#k(),this.#w()),this)):this}stop(){if(this.#e){if(this.#p(),this.#e=!1,this.#o=Date.now(),this.#d="",this.#a){this.#a.renderAll();return}this.#s?(this.#s.erase("stdout"),this.#s.unhook(!1)):this.#$()}}stopAndPersist(t){if(!this.#e||(this.#p(),this.#e=!1,this.#o=Date.now(),!this.#g))return;const n=t?.prefixText??this.#t,s=t?.text??this.#r;let i=t?.symbol??"";n&&(i=i?`${n} ${i}`:n),s&&(i=i?`${i} ${s}`:s),this.#E(i)}succeed(t){this.#m("success",t)}failed(t){this.#m("error",t)}warn(t){this.#m("warning",t)}info(t){this.#m("info",t)}pause(){this.#p()}resume(){this.#e&&(this.#p(),this.#a||this.#w())}getFrameOutput(){if(!this.#e&&this.#d)return this.#d;const t=this.#u.frames[this.#n];let n=this.#h?this.#h(t):t;return this.#t&&(n=`${this.#t} ${n}`),this.#r&&(n=`${n} ${this.#r}`),n}#w(){this.#b&&(this.#i=setInterval(()=>{this.#e&&(this.#n=(this.#n+1)%this.#u.frames.length,this.#y())},this.#u.interval),this.#i.unref())}#p(){this.#i&&(clearInterval(this.#i),this.#i=void 0)}#y(){this.#a?this.#a.renderAll():this.#s?this.#v():this.#k()}#v(){this.#s&&this.#s.update("stdout",[this.getFrameOutput()])}#k(){const t=this.getFrameOutput();if(this.#$(),this.#l.isTTY){this.#l.write(t);const n=this.#l.columns||80;this.#f=Math.max(1,Math.ceil(Ct(t)/n))}else this.#l.write(`${t}
2
+ `),this.#f=0}#$(){if(this.#f>0&&this.#l.isTTY){for(let t=1;t<this.#f;t+=1)this.#l.write("\x1B[1A\x1B[2K");this.#l.write("\r\x1B[K")}this.#f=0}#E(t){this.#d=t,this.#a?this.#a.renderAll():this.#s?(this.#s.update("stdout",[t]),this.#s.unhook(!1)):(this.#$(),this.#l.write(`${t}
3
+ `))}#m(t,n){if(!this.#e||(this.#p(),this.#e=!1,this.#o=Date.now(),!this.#g))return;let s="";const i=this.#x[t];i&&(s=this.#h?this.#h(i):i),this.#t&&(s=`${this.#t} ${s}`),n&&(s=`${s} ${n}`),this.#E(s)}};const _t=(e,t,n)=>{const s=n.toLowerCase();e[s]??=new Map;const i=e[s].get(t);if(i!==void 0)return i;const{size:r}=e[s],o=`<${n.toUpperCase()}${r>0?String(r):""}>`;return e[s].set(t,o),o},Te=(e,t)=>{const{replacement:n,tag:s,text:i}=t;return typeof n=="function"?String(n(i,void 0)):typeof n=="string"?n:_t(e,i,s)},Lt=(e,t)=>{const n={};let s="",i=0;for(const r of e){const{start:o,text:c}=r;if(c==="")continue;if(Number.isInteger(o)&&o>=0&&t.slice(o,o+c.length)===c){if(o<i)continue;s+=t.slice(i,o)+Te(n,r),i=o+c.length;continue}let a=t.indexOf(c,i);if(a===-1)continue;const l=Te(n,r);for(;a!==-1;)s+=t.slice(i,a)+l,i=a+c.length,a=t.indexOf(c,i)}return s+t.slice(i)},Dt=e=>[...e.reduce((t,n)=>t.set(n.text+String(n.start)+n.tag,n),new Map).values()].toSorted((t,n)=>{const s=t.start-n.start;return s!==0?s:n.text.length-t.text.length}),qt=(e,t)=>{const n=[];for(const s of e){const{key:i,pattern:r}=s,o=s.compiledPattern??new RegExp(r,"giu");o.lastIndex=0;let c;for(;(c=o.exec(t))!==null;){const a=s;n.push({replacement:a.userReplacement??a.replacement!==void 0?a.replacement:void 0,start:c.index,tag:i,text:c[0]}),c.index===o.lastIndex&&(o.lastIndex+=1)}}return n},Ut=(e,t,n,s)=>Dt([...qt(n,e)]),ze=(e,t,n)=>{const s=[],i=[];for(const c of t)typeof c=="object"&&c.pattern&&s.push(c),i.push((typeof c=="object"?c.key:String(c)).toLowerCase());let r=e;const o=Ut(e,i,s);return r=Lt(o,r),r},B=e=>{const t=typeof e;return e!==null&&(t==="object"||t==="function")},ne=new Set(["__proto__","prototype","constructor"]),Pt=Math.max(...[...ne].map(e=>e.length)),Ye=1e6,Ht=e=>e>="0"&&e<="9";function Ve(e){if(e==="0")return!0;if(/^[1-9]\d*$/.test(e)){const t=Number.parseInt(e,10);return t<=Number.MAX_SAFE_INTEGER&&t<=Ye}return!1}function re(e,t){return ne.has(e)?!1:(e&&Ve(e)?t.push(Number.parseInt(e,10)):t.push(e),!0)}function zt(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);const t=[];let n="",s="",i=!1,r="start",o=!1,c=0;for(const a of e){if(c++,o){n+=a,o=!1;continue}if(a==="\\"){if(r==="index")throw new Error(`Invalid character '${a}' in an index at position ${c}`);if(r==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${c}`);o=!0,r=r==="start"?"property":r;continue}switch(a){case".":{if(r==="index")throw new Error(`Invalid character '${a}' in an index at position ${c}`);if(r==="indexEnd"){r="property";break}if(!re(n,t))return[];n="",r="property";break}case"[":{if(r==="index")throw new Error(`Invalid character '${a}' in an index at position ${c}`);if(r==="indexEnd"){r="index";break}if(r==="property"&&n.length<=Pt&&ne.has(n))return[];i=r==="property",r="index";break}case"]":{if(r==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${c}`);if(r!=="index"){r==="start"&&(r="property"),n+=a;break}if(s===""){n+="[]",r="property";break}if((n!==""||i)&&!re(n,t))return[];n="",i=!1;const l=Number.parseInt(s,10),u=l<=Ye&&s===String(l);t.push(u?l:s),s="",r="indexEnd";break}default:{if(r==="index"){if(!Ht(a))throw new Error(`Invalid character '${a}' in an index at position ${c}`);s+=a;break}if(r==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${c}`);r==="start"&&(r="property"),n+=a}}}switch(o&&(n+="\\"),r){case"property":{if(!re(n,t))return[];break}case"index":throw new Error("Index was not closed");case"start":{t.push("");break}}return t}function se(e){if(typeof e=="string")return zt(e);if(Array.isArray(e)){const t=[];for(const[n,s]of e.entries()){if(typeof s!="string"&&typeof s!="number")throw new TypeError(`Expected a string or number for path segment at index ${n}, got ${typeof s}`);if(typeof s=="number"&&!Number.isFinite(s))throw new TypeError(`Path segment at index ${n} must be a finite number, got ${s}`);if(ne.has(s))return[];typeof s=="string"&&Ve(s)?t.push(Number.parseInt(s,10)):t.push(s)}return t}return[]}function Yt(e,t,n){if(!B(e)||typeof t!="string"&&!Array.isArray(t))return e;const s=se(t);if(s.length===0)return n;for(let i=0;i<s.length;i++){const r=s[i];if(e=e[r],e==null){if(i!==s.length-1)return n;break}}return e===void 0?n:e}function Vt(e,t,n){if(!B(e)||typeof t!="string"&&!Array.isArray(t))return e;const s=e,i=se(t);if(i.length===0)return e;for(let r=0;r<i.length;r++){const o=i[r];if(r===i.length-1){e[o]=n;continue}const c=e[o];if(B(c)){e=c;continue}const a=typeof i[r+1]=="number";e[o]=a?[]:{},e=e[o]}return s}function Gt(e,t){if(!B(e)||typeof t!="string"&&!Array.isArray(t))return!1;const n=se(t);if(n.length===0)return!1;for(let s=0;s<n.length;s++){const i=n[s];if(s===n.length-1)return Object.hasOwn(e,i)?(delete e[i],!0):!1;const r=e[i];if(!B(r))return!1;e=r}}function Ie(e,t){if(!B(e)||typeof t!="string"&&!Array.isArray(t))return!1;const n=se(t);if(n.length===0)return!1;for(const s of n){if(!B(e)||!(s in e))return!1;e=e[s]}return!0}const oe="#;/?:@&",ce=new RegExp(String.raw`([${oe}][^${oe}=\s]+=[^${oe}=\s]*)`,"g"),Kt=e=>{const t=[];let n=0;ce.lastIndex=0;let s=ce.exec(e);for(;s!==null;){const{0:r,index:o}=s;t.push({key:void 0,value:e.slice(n,o+1)}),n=o+r.length,t.push({key:r.slice(1,r.indexOf("=")),value:r.slice(r.indexOf("=")+1)}),s=ce.exec(e)}const i=e.slice(n);return i.length>0&&t.push({key:void 0,value:i}),t},Ae=(e,t)=>{for(let n=0;n<e.length;n+=1){let s=e[n].string,i=e[n].index;for(;i<t.length;){const r=t[i];if(!s.includes(r))break;const o=s.slice(1);for(e.push({index:i,string:o}),o.includes(r)||e.pop(),s=s.slice(s.indexOf(r)+r.length),i+=1;t[i]==="";)i+=1;if(i>=t.length){if(t.at(-1)!==""&&s.length>0)break;return!0}}}return!1},de=(e,t)=>{if(!t.includes("*"))return t===e;const n=t.split("*");let s=0,i=e;for(;n[s]==="";)if(s+=1,s===t.length)return!0;if(s===0&&!e.startsWith(n[0]))return!1;const r=[];for(;s<n.length;){const o=n[s];if(!i.includes(o))return Ae(r,n);const c=i.slice(1);for(r.push({index:s,string:c}),c.includes(o)||r.pop(),i=i.slice(i.indexOf(o)+o.length),s+=1;n[s]==="";)s+=1}return s>=n.length&&n.at(-1)!==""&&i.length>0?i===e?!1:Ae(r,n):!0},Jt=/(?:http|https):\/\/?/,j=(e,t,n)=>typeof e.replacement=="function"?e.replacement(t,n):e.replacement,Ge=(e,t,n)=>e.wildcard?de(t,e.key)||de(n,e.key):t===e.key||n===e.key,Xt=(e,t,n,s)=>{n.remove?delete e[t]:e[t]=j(n,e[t],s)},Be=(e,t,n,s,i,r)=>{const o=[],c=[];for(const l of s)!l.wildcard&&!l.deep&&Ie(e,l.key)?c.push(l):o.push(l);const a=Object.keys(e);for(const l of a){if(!Object.hasOwn(e,l))continue;const u=l.toLowerCase(),h=r?`${r}.${u}`:u;let d;for(const f of o)Ge(f,u,h)&&(d=f);d?Xt(e,l,d,h):e[l]=E(e[l],t,n,o,i,h)}for(const l of c)if(Ie(e,l.key))if(l.remove)Gt(e,l.key);else{const u=r?`${r}.${l.key}`:l.key;Vt(e,l.key,j(l,Yt(e,l.key),u))}},Ne=(e,t)=>{const n=t.toLowerCase();return e.find(s=>s.key===n||!!s.wildcard&&de(n,s.key))},Zt=(e,t,n)=>{const s=Kt(e),i=[];for(const r of s){const{key:o,value:c}=r;if(o===void 0){const a=Ne(t,c);i.push(a?String(j(a,c,void 0)):ze(c,t))}else{const a=Ne(t,o);a?i.push(`${o}=${String(j(a,c,void 0))}`):i.push(`${o}=${c}`)}}return i.join("")},E=(e,t,n,s,i,r)=>{if(e==null)return e;if(typeof e=="object"&&e.constructor===String)return E(String(e),t,n,s,i,r);if(typeof e=="object"&&t.has(e))return t.get(e);if(typeof e=="object"&&!Array.isArray(e)){if(e instanceof Error){const c=new Error(e.message);Object.defineProperties(c,{name:{configurable:!0,enumerable:!1,value:e.name,writable:!0},stack:{configurable:!0,enumerable:!1,value:e.stack,writable:!0}}),e.code!==void 0&&(c.code=e.code);const a=Object.keys(e);for(const l of a)c[l]=e[l];return n(e,c),Be(c,t,n,s,i,r),c}if(e instanceof Map){const c=new Map;n(e,c);const a=e.entries();let l=a.next();for(;!l.done;){const[u,h]=l.value;if(typeof u=="string"||typeof u=="object"&&u!==null&&u.constructor===String){const d=u.toLowerCase(),f=r?`${r}.${d}`:d;let g;for(const p of s)Ge(p,d,f)&&(g=p);g?g.remove||c.set(u,j(g,h,f)):c.set(u,E(h,t,n,s,i,f))}else c.set(E(u,t,n,s,i),E(h,t,n,s,i));l=a.next()}return c}if(e instanceof Set){const c=new Set;n(e,c);const a=e.values();let l=a.next();for(;!l.done;)c.add(E(l.value,t,n,s,i,r)),l=a.next();return c}const o={...e};return n(e,o),Be(o,t,n,s,i,r),o}if(typeof e=="string"){const o=e;try{const c=JSON.parse(o);if(typeof c=="object"&&c!==null){const a=E(c,t,n,s,i,r);return JSON.stringify(a)}}catch{}return Jt.test(o)?Zt(o,s):ze(o,s)}if(Array.isArray(e)){const o=[];n(e,o);for(const[c,a]of e.entries()){const l=c.toString().toLowerCase(),u=r?`${r}.${l}`.toLowerCase():l,h=s.find(d=>d.key===l||d.key===u);h?o.push(j(h,a,u)):o.push(E(a,t,n,s,i,u))}return o}return e},Qt=(e,t)=>{const n=[];for(const s of e)if(typeof s=="string"){const i=s.includes("*");n.push({deep:!1,key:s.toLowerCase(),replacement:`<${s.toUpperCase()}>`,userReplacement:!1,wildcard:i})}else if(typeof s=="number")n.push({deep:!1,key:s.toString(),replacement:"<REDACTED>"});else{const i=s.key.toLowerCase(),r={...s,key:i,replacement:s.replacement??`<${i.toUpperCase()}>`,userReplacement:s.replacement!==void 0,wildcard:i.includes("*")?!0:s.wildcard};if(r.pattern!==void 0){const o=r.pattern instanceof RegExp?r.pattern.source:r.pattern;r.compiledPattern=new RegExp(o,"giu")}n.push(r)}return n},en=(e,t,n)=>{if(e==null||typeof e=="number"||typeof e=="boolean")return e;const s=new WeakMap;return E(e,s,(i,r)=>{s.set(i,r)},t,n)},Ke=(e,t,n)=>{const s=Qt(t);return en(e,s,n)};let tn;const nn=e=>(tn??=xe(import.meta.url))(e),R=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ke=e=>{if(typeof R<"u"&&R.versions&&R.versions.node){const[t,n]=R.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return R.getBuiltinModule(e)}return nn(e)},I=R,{execFileSync:sn}=ke("node:child_process"),q=ke("node:fs"),rn=ke("node:tty"),on=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],cn=12288,an=65510,ln=[12288,12288,65281,65376,65504,65510],un=8361,hn=65518,dn=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],fn=32,pn=10630,gn=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],mn=4352,wn=262141,Je=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141],V=(e,t)=>{let n=0,s=Math.floor(e.length/2)-1;for(;n<=s;){const i=Math.floor((n+s)/2),r=i*2;if(t<e[r])s=i-1;else if(t>e[r+1])n=i+1;else return!0}return!1},Re=19968,[yn,$n]=bn(Je);function bn(e){let t=e[0],n=e[1];for(let s=0;s<e.length;s+=2){const i=e[s],r=e[s+1];if(Re>=i&&Re<=r)return[i,r];r-i>n-t&&(t=i,n=r)}return[t,n]}const xn=e=>e<161||e>1114109?!1:V(on,e),vn=e=>e<cn||e>an?!1:V(ln,e),kn=e=>e<un||e>hn?!1:V(dn,e),En=e=>e<fn||e>pn?!1:V(gn,e),Sn=e=>e>=yn&&e<=$n?!0:e<mn||e>wn?!1:V(Je,e);function Tn(e){return xn(e)?"ambiguous":vn(e)?"fullwidth":kn(e)?"halfwidth":En(e)?"narrow":Sn(e)?"wide":"neutral"}function In(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}function Xe(e){return In(e),Tn(e)}const Ze=String.raw,Fe=Ze`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,An=()=>new RegExp(Ze`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${Fe}(?:\u200D${Fe})*`,"gu"),O=new Set(["\x1B","›"]),ie="\x07",Qe="[",Ee="m",z="]8;;",Bn=39,Nn=/[\u200B\uFEFF\u2060-\u2064]/g,Rn=new RegExp(`(?:\\${Qe}(?<code>\\d+)m|\\${z}(?<uri>.*)${ie})`),Fn=Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]])),et=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g,K=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,Mn=An(),Me=new Map,jn=e=>[e.ambiguousIsNarrow?1:0,e.control,e.fullWidth,e.regular,e.wide].join("|"),Cn=e=>{const t=jn(e.width);let n=Me.get(t);return n||(n=new Map,Me.set(t,n)),n},J=new RegExp(et.source,"y"),ae=new RegExp(Mn.source,"uy"),X=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,tt=e=>e>=32&&e<=126?"latin":e===8203||e===8204||e===8205||e===8288?"zero":e<=31||e>=127&&e<=159?"control":e>=160&&e<=255||e>=9472&&e<=9599?"latin":e>=4352&&e<=4607||e>=11904&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65519&&!(e>=65377&&e<=65439)||e>=12352&&e<=12543?"wide":e===8230?"latin":"other",On=(e,t)=>{const n=Cn(t),s=Math.floor(e/65536),i=e%65536;let r=n.get(s);if(r||(r=new Map,n.set(s,r)),r.has(i))return r.get(i);let o;switch(tt(e)){case"control":{o=t.width.control;break}case"latin":{o=t.width.regular;break}case"wide":{o=t.width.wide;break}case"zero":{o=0;break}default:switch(Xe(e)){case"ambiguous":{o=t.width.ambiguousIsNarrow?t.width.regular:t.width.wide;break}case"fullwidth":{o=t.width.fullWidth;break}case"wide":{o=t.width.wide;break}default:o=t.width.regular}}return r.set(i,o),o},Wn=e=>e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||e>=917760&&e<=917999||e>=65024&&e<=65039||e>=3633&&e<=3642||e>=3655&&e<=3662||e>=3761&&e<=3769||e>=3771&&e<=3772||e>=3784&&e<=3789||e>=2304&&e<=2307||e>=2362&&e<=2383||e>=2385&&e<=2391||e>=2402&&e<=2403||e>=2433&&e<=2435||e>=2492&&e<=2500||e>=2509&&e<=2509||e>=2561&&e<=2563||e>=2620&&e<=2637||e>=1611&&e<=1631||e>=1648&&e<=1648||e>=1750&&e<=1773||e>=2276&&e<=2302||e>=1425&&e<=1469||e>=1471&&e<=1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e>=1479&&e<=1479||e>=3893&&e<=3893||e>=3895&&e<=3895||e>=3897&&e<=3897||e>=3953&&e<=3966||e>=3968&&e<=3972||e>=3974&&e<=3975?!0:e>=768&&e<=777||e>=803&&e<=803,fe=(e,t={})=>{if(!e||e.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const n={truncation:{countAnsiEscapeCodes:t.countAnsiEscapeCodes??!1,ellipsis:t.ellipsis??"",ellipsisWidth:t.ellipsisWidth??(t.ellipsis?fe(t.ellipsis,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:t.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:t.ambiguousIsNarrow??!1,ansi:t.ansiWidth??0,control:t.controlWidth??0,emoji:t.emojiWidth??2,fullWidth:t.fullWidth??2,halfWidth:t.halfWidth??1,regular:t.regularWidth??1,tab:t.tabWidth??8,wide:t.wideWidth??2}},s=Math.max(0,n.truncation.limit-n.truncation.ellipsisWidth),{length:i}=e,r=i>1e4;let o=0,c=0,a=i,l=!1;const u=e.includes("\x1B")||e.includes("›");for(;o<i;){if(u&&(e[o]==="\x1B"||e[o]==="›")){if(e.startsWith("\x1B]8;;",o)){const w="\x1B]8;;\x07",y=w.length,m=e.indexOf("\x07",o+5);if(m!==-1){const v=e.indexOf(w,m+1);if(v!==-1){const k=v+y,b=e.slice(m+1,v).replace(et,""),T=fe(b,{ambiguousIsNarrow:n.width.ambiguousIsNarrow,ansiWidth:n.width.ansi,controlWidth:n.width.control,countAnsiEscapeCodes:!1,ellipsis:n.truncation.ellipsis,ellipsisWidth:n.truncation.ellipsisWidth,emojiWidth:n.width.emoji,fullWidth:n.width.fullWidth,halfWidth:n.width.halfWidth,limit:Math.max(0,s-c),regularWidth:n.width.regular,tabWidth:n.width.tab,wideWidth:n.width.wide}),W=T.width;if(T.truncated)l=!0,a=Math.min(a,o);else if(c+W>s&&(a=Math.min(a,o),l=!0,c+W>n.truncation.limit))break;if(c+=W,o=k,l&&c>=n.truncation.limit)break;continue}}}if(J.lastIndex=o,J.test(e)){const w=J.lastIndex-o,y=n.truncation.countAnsiEscapeCodes?w:n.width.ansi;if(c+y>s&&(a=Math.min(a,o),c+y>n.truncation.limit)){l=!0;break}c+=y,o=J.lastIndex;continue}}const f=e.codePointAt(o);if(f===8203||f===65279||f>=8288&&f<=8292){o+=1;continue}if(f===9){if(c+n.width.tab>s&&(a=Math.min(a,o),c+n.width.tab>n.truncation.limit)){l=!0;break}c+=n.width.tab,o+=1;continue}if(X.lastIndex=o,X.test(e)){const w=(X.lastIndex-o)*n.width.regular;if(c+w>s){const y=n.width.regular>0?Math.floor((s-c)/n.width.regular):0;if(a=Math.min(a,o+y),c+w>n.truncation.limit){l=!0;break}}c+=w,o=X.lastIndex;continue}if((f<=31||f>=127&&f<=159)&&(K.lastIndex=o,K.test(e))){const w=(K.lastIndex-o)*n.width.control;if(c+w>s){const y=n.width.control>0?Math.floor((s-c)/n.width.control):0;if(a=Math.min(a,o+y),c+w>n.truncation.limit){l=!0;break}}c+=w,o=K.lastIndex;continue}if(ae.lastIndex=o,ae.test(e)){if(c+n.width.emoji>s&&(a=Math.min(a,o),c+n.width.emoji>n.truncation.limit)){l=!0;break}c+=n.width.emoji,o=ae.lastIndex;continue}const g=e.codePointAt(o)??0;if(Wn(g)){o+=g>65535?2:1;continue}let p;if(r)p=On(g,n);else switch(tt(g)){case"control":{p=n.width.control;break}case"latin":{p=n.width.regular;break}case"wide":{p=n.width.wide;break}case"zero":{p=0;break}default:switch(Xe(g)){case"ambiguous":{p=n.width.ambiguousIsNarrow?n.width.regular:n.width.wide;break}case"fullwidth":{p=n.width.fullWidth;break}case"wide":{p=n.width.wide;break}default:p=n.width.regular}}if(c+p>s&&(a=Math.min(a,o),c+p>n.truncation.limit)){l=!0;break}c+=p,o+=g>65535?2:1}let h=c,d=!1;return l&&n.truncation.limit>=n.truncation.ellipsisWidth&&(h=n.truncation.limit,d=!0),{ellipsed:d,index:l?a:i,truncated:l,width:h}},S=(e,t={})=>fe(e,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,_n=/\x1B\[(\d+)m/;class nt{activeForeground=void 0;activeBackground=void 0;activeFormatting=[];processEscape(t){const n=_n.exec(t);if(!n)return;const s=Number.parseInt(n[1],10);switch(s){case 0:{this.activeForeground=void 0,this.activeBackground=void 0,this.activeFormatting=[];break}case 39:{this.activeForeground=void 0;break}case 49:{this.activeBackground=void 0;break}default:if(s>=30&&s<=37||s>=90&&s<=97)this.activeForeground=t;else if(s>=40&&s<=47||s>=100&&s<=107)this.activeBackground=t;else if([1,2,3,4,7,8,9].includes(s))this.activeFormatting.push(t);else if([22,23,24,27,28,29].includes(s)){const i={22:"[1m",23:"[3m",24:"[4m",27:"[7m",28:"[8m",29:"[9m"}[s];i&&(this.activeFormatting=this.activeFormatting.filter(r=>!r.includes(i)))}}}getStartEscapesForAllActiveAttributes(){return[this.activeBackground,this.activeForeground,...this.activeFormatting].filter(Boolean).join("")}getEndEscapesForAllActiveAttributes(){const t=[];if(this.activeFormatting.length>0){const n={"\x1B[1m":"\x1B[22m","\x1B[2m":"\x1B[22m","\x1B[3m":"\x1B[23m","\x1B[4m":"\x1B[24m","\x1B[7m":"\x1B[27m","\x1B[8m":"\x1B[28m","\x1B[9m":"\x1B[29m"};[...this.activeFormatting].toReversed().forEach(s=>{const i=n[s];i&&t.push(i)})}return this.activeForeground&&t.push("\x1B[39m"),this.activeBackground&&t.push("\x1B[49m"),t.join("")}}const Ln=(e,t)=>{if(!O.has(e[t]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const n=!0,s=e.slice(t+1,t+1+z.length).join("")===z;return{isInsideEscape:n,isInsideLinkEscape:s}},Dn=(e,t={})=>{const n=new nt;let s="",i=!1,r="",o="",c=!1;const a=[...e];for(let l=0;l<a.length;l++){const u=a[l];if(u&&O.has(u)){if(s){const p=t.getWidth?.(s)??0,w={isEscapeSequence:!1,isGrapheme:!0,text:s,width:p};if(c&&(w.isHyperlink=!0,w.hyperlinkUrl=o),t.onSegment?.(w,n)===!1)return;s=""}i=!0,r=u;const f=Ln(a,l),{isInsideLinkEscape:g}=f;if(g){let p=l+1;for(o="";p<a.length;){const y=a[p];if(y===ie)break;o+=y,p+=1}o=o.slice(4);const w={hyperlinkUrl:o,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(t.onSegment?.(w,n)===!1)return;l=p,c=!0,i=!1,r="";continue}if(l+1<a.length&&a[l+1]==="\\"&&c){const p={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(t.onSegment?.(p,n)===!1)return;c=!1,o="",l+=1,i=!1,r="";continue}}if(i){if(r!==u&&(r+=u),u===Ee){i=!1,n.processEscape(r);const f={isEscapeSequence:!0,isGrapheme:!1,text:r,width:0};if(t.onSegment?.(f,n)===!1)return;r=""}continue}s+=u;const h=t.getWidth?.(s)??0,d={isEscapeSequence:!1,isGrapheme:!0,text:s,width:h};if(c&&(d.isHyperlink=!0,d.hyperlinkUrl=o),t.onSegment?.(d,n)===!1)return;s=""}if(s){const l=t.getWidth?.(s)??0,u={isEscapeSequence:!1,isGrapheme:!0,text:s,width:l};c&&(u.isHyperlink=!0,u.hyperlinkUrl=o),t.onSegment?.(u,n)}if(r){const l={isEscapeSequence:!0,isGrapheme:!1,text:r,width:0};t.onSegment?.(l,n)}},je=e=>`${O.values().next().value}${Qe}${String(e)}${Ee}`,Ce=e=>`${O.values().next().value}${z}${e}${ie}`,qn=e=>{if(e.length===0)return"";if(e.length===1)return e[0];let t="",n,s;const i=e.join(`
4
+ `),r=[...i];let o=0;for(const[c,a]of r.entries()){if(t+=a,O.has(a)){const u=Rn.exec(i.slice(o))?.groups??{};if(u.code!==void 0){const h=Number.parseFloat(u.code);n=h===Bn?void 0:h}else u.uri!==void 0&&(s=u.uri.length===0?void 0:u.uri)}const l=Fn.get(Number(n));r[c+1]===`
5
+ `?(s&&(t+=Ce("")),n&&l&&(t+=je(l))):a===`
6
+ `&&(n&&l&&(t+=je(n)),s&&(t+=Ce(s))),o+=a.length}return t},st=/(?=\s)|(?<=\s)/,it=/^\s+$/,Oe=new Map,Un=e=>{const t=Oe.get(e);if(t!==void 0)return t;const n=S(e);return Oe.set(e,n),n},le=e=>{if(!e.includes("\x1B"))return e;let t=e;return e.includes("\x1B[30m")&&(t+="\x1B[39m"),e.includes("\x1B[42m")&&(t+="\x1B[49m"),t},A=e=>{const t=e.split(" ");let n=t.length;for(;n>0&&S(t[n-1])===0;)n--;return n===t.length?e:t.slice(0,n).join(" ")+t.slice(n).join("")},rt=(e,t,n)=>{if(e.length===0)return[""];if(t<=0)return[e];const s=[],i=new nt;let r="",o=0,c=!1,a=!1,l="",u=0;for(;u<e.length;){const h=e.codePointAt(u),d=String.fromCodePoint(h),f=d.length;if(O.has(d)){c=!0,l=d,r+=d,a=e.startsWith(z,u+1),u+=1;continue}if(c){l+=d,r+=d,a?d===ie&&(c=a=!1):d===Ee&&(c=!1,i.processEscape(l)),u+=1;continue}const g=Un(d),p=d===" ";if(g===0){r+=d,u+=f;continue}if(o+g>t&&(r&&s.push(r+i.getEndEscapesForAllActiveAttributes()),r=i.getStartEscapesForAllActiveAttributes(),o=S(r),p&&n)){for(;u<e.length&&e[u]===" ";)u+=1;continue}if(r+=d,o+=g,o===t&&u+f<e.length&&(s.push(r+i.getEndEscapesForAllActiveAttributes()),r=i.getStartEscapesForAllActiveAttributes(),o=S(r),u+f<e.length&&e[u+f]===" "&&n)){for(u+=f;u<e.length&&e[u]===" ";)u+=1;continue}u+=f}return r&&s.push(r+i.getEndEscapesForAllActiveAttributes()),n?s.map(h=>A(h)):s},Pn=(e,t,n)=>{if(e.length===0)return[];const s=n?e.trim():e;if(s.length===0)return[];const i=[];let r="",o=0;return Dn(s,{getWidth:S,onSegment:(c,a)=>{const l=c.text??"";if(c.isEscapeSequence)r+=l;else{const u=l===" ";if(c.width===0)return r+=l,!0;if(o+c.width>t&&(r&&i.push(r),r=a.getStartEscapesForAllActiveAttributes(),o=0,u))return n||i.push(a.getStartEscapesForAllActiveAttributes()+l),!0;r+=l,o+=c.width}return!0}}),r&&i.push(r),n?i.map(c=>A(c)):i},Hn=(e,t,n)=>{if(e.length===0)return[];const s=n?e.trim():e;if(s.length===0)return[];const i=s.split(st),r=[];let o="",c=0,a=0;for(;a<i.length;){const l=i[a],u=it.test(l),h=S(l);if(l.length===0){a+=1;continue}if(n&&u&&c===0){a+=1;continue}if(c+h>t&&c>0){n?r.push(A(o)):r.push(o),o="",c=0;continue}o+=l,c+=h,a+=1}return o&&(n?r.push(A(o)):r.push(o)),r},zn=(e,t,n)=>{if(e.length===0)return[];const s=n?e.trim():e;if(s.length===0)return[];const i=s.split(st),r=[];let o="",c=0,a=0;for(;a<i.length;){const l=i[a],u=it.test(l),h=S(l);if(l.length===0){a+=1;continue}if(n&&u&&c===0){a+=1;continue}if(h>t){o&&r.push(le(n?A(o):o));const d=rt(l,t,n);if(d.length>0){for(let f=0;f<d.length-1;f+=1)r.push(d[f]);o=d.at(-1),c=S(o)}else o="",c=0;a+=1;continue}if(c+h>t&&c>0&&(r.push(le(n?A(o):o)),o="",c=0,n&&u)){a+=1;continue}o+=l,c+=h,a+=1}return o&&r.push(le(n?A(o):o)),r},U={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},Yn=(e,t={})=>{const{removeZeroWidthCharacters:n=!0,trim:s=!0,width:i=80,wrapMode:r=U.PRESERVE_WORDS}=t;if(s&&e.trim()==="")return"";let o=e.normalize("NFC").replaceAll(`\r
7
+ `,`
8
+ `);return n&&(o=o.replaceAll(Nn,"")),o.split(`
9
+ `).map(c=>{if(s&&c.trim()==="")return"";let a;switch(r){case U.BREAK_AT_CHARACTERS:{a=Pn(c,i,s);break}case U.BREAK_WORDS:{a=zn(c,i,s);break}case U.STRICT_WIDTH:{a=rt(c,i,s);break}default:a=Hn(c,i,s)}return qn(a)}).join(`
10
+ `)},ot=80,ct=24,pe=(e,t,{shell:n,env:s}={})=>sn(e,t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:500,shell:n,env:s}).trim(),Z=(e,t)=>({columns:Number.parseInt(e,10),rows:Number.parseInt(t,10)}),at=(e,t)=>{const{columns:n,rows:s}=Z(e,t);if(!(Number.isNaN(n)||Number.isNaN(s))&&!(n===ot&&s===ct))return{columns:n,rows:s}},Vn=()=>{if(I.platform!=="linux")return!0;try{const e=q.readFileSync("/proc/self/stat","utf8"),t=e.lastIndexOf(") ");if(t===-1)return!1;const n=e.slice(t+2).trim().split(/\s+/),s=Number.parseInt(n[2],10),i=Number.parseInt(n[5],10);return Number.isNaN(s)||Number.isNaN(i)||i<=0?!1:s===i}catch{return!1}};function ue(){const{env:e,stdout:t,stderr:n}=I;if(t?.columns&&t?.rows)return Z(t.columns,t.rows);if(n?.columns&&n?.rows)return Z(n.columns,n.rows);if(e.COLUMNS&&e.LINES)return Z(e.COLUMNS,e.LINES);const s={columns:ot,rows:ct};return I.platform==="win32"?he()??s:I.platform==="darwin"?We()??he()??s:We()??he()??Gn()??s}const We=()=>{try{const e=I.platform==="darwin"?q.constants.O_EVTONLY|q.constants.O_NONBLOCK:q.constants.O_NONBLOCK,{columns:t,rows:n}=rn.WriteStream(q.openSync("/dev/tty",e));return{columns:t,rows:n}}catch{}},he=()=>{try{const e=pe("tput",["cols"],{env:{TERM:"dumb",...I.env}}),t=pe("tput",["lines"],{env:{TERM:"dumb",...I.env}});if(e&&t)return at(e,t)}catch{}},Gn=()=>{try{if(!Vn())return;const e=pe("resize",["-u"]).match(/\d+/g);if(e.length===2)return at(e[0],e[1])}catch{}};class Kn{#n;#i=!1;#e=!1;#t=0;#r=0;#c;#o;constructor(t,n){this.#n={stderr:n,stdout:t},this.#c=ue(),this.#o=()=>{this.#c=ue()};for(const s of Object.keys(this.#n))this.#n[s].onEarlyFlush(()=>{this.erase(s),this.#t=0,this.#r=0})}get lastLength(){return this.#t}get outside(){return this.#r}get isHooked(){return this.#i}get isSuspended(){return this.#e}clear(t){this.erase(t),this.#t=0,this.#r=0}done(t){this.#t=0,this.#r=0}erase(t,n=this.#t){this.#n[t].erase(n)}hook(){if(this.#i)return!1;const t=Object.values(this.#n);for(const n of t)n.active();return this.#c=ue(),process.stdout.isTTY&&typeof process.stdout.on=="function"&&process.stdout.on("resize",this.#o),this.#s(!0),!0}resume(t,n){if(this.#e&&this.#i){this.#e=!1,n&&this.erase(t,n),this.#t=0,this.#r=0;const s=Object.values(this.#n);for(const i of s)i.active()}}suspend(t,n=!0){if(!this.#e){this.#e=!0,n&&this.erase(t);const s=Object.values(this.#n);for(const i of s)i.renew()}}unhook(t=!0){if(!this.#i)return!1;const n=Object.values(this.#n);for(const s of n)s.inactive(t);return typeof process.stdout.off=="function"&&process.stdout.off("resize",this.#o),this.#s(),!0}update(t,n,s=0){if(this.#e)return;if(n.length===0){this.clear(t);return}const i=this.#n[t],{columns:r,rows:o}=this.#c,c=Math.max(0,Math.min(o-1,s)),a=this.lastLength-c,l=Math.max(a-o,this.outside);let u=n.flatMap(h=>Yn(h,{trim:!1,width:r,wrapMode:U.STRICT_WIDTH}).split(`
11
+ `));o<=a?(i.erase(o),c<l&&(u=u.slice(l-c+1))):a&&i.erase(a),i.write(`${u.join(`
12
+ `)}
13
+ `),this.#t=l?l+u.length+1:c+u.length,this.#r=Math.max(this.lastLength-o,this.outside)}#s(t=!1){this.#i=t,this.#t=0,this.#r=0}}let Jn;const Xn=e=>(Jn??=xe(import.meta.url))(e),D=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Zn=e=>{if(typeof D<"u"&&D.versions&&D.versions.node){const[t,n]=D.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return D.getBuiltinModule(e)}return Xn(e)},{StringDecoder:Qn}=Zn("node:string_decoder"),G="\x1B[",lt=typeof globalThis<"u"&&typeof globalThis.window=="object"&&globalThis.window.document!==void 0,es=/^(?:msys|cygwin)$/,ut=process,ge=ut?.env??{};!lt&&ge.TERM_PROGRAM;!lt&&(ut?.platform==="win32"||ge.OSTYPE!==void 0&&es.test(ge.OSTYPE));const ts=`${G}?25l`,ns=`${G}G`,ss=`${G}?25h`,is=(e=1)=>`${G}${String(e)}A`;var rs=(e=>(e[e.Default=0]="Default",e[e.BlinkingBlock=1]="BlinkingBlock",e[e.SteadyBlock=2]="SteadyBlock",e[e.BlinkingUnderline=3]="BlinkingUnderline",e[e.SteadyUnderline=4]="SteadyUnderline",e[e.BlinkingBar=5]="BlinkingBar",e[e.SteadyBar=6]="SteadyBar",e))(rs||{}),os=(e=>(e[e.ToEnd=0]="ToEnd",e[e.ToBeginning=1]="ToBeginning",e[e.EntireScreen=2]="EntireScreen",e[e.EntireScreenAndScrollback=3]="EntireScreenAndScrollback",e))(os||{}),cs=(e=>(e[e.ToEnd=0]="ToEnd",e[e.ToBeginning=1]="ToBeginning",e[e.EntireLine=2]="EntireLine",e))(cs||{});const as=e=>`${G}${String(e)}K`,ls=as(2),us=e=>{if(e<=0)return"";let t="";for(let n=0;n<e;n+=1)t+=ls,n<e-1&&(t+=is());return t+=ns,t},hs=1e4;class ee{static DRAIN=!0;#n=new Qn;#i=[];#e;#t;#r;#c;#o;isTTY;constructor(t,n={}){this.#c=t.write.bind(t),this.#o=t,this.#r=n.maxHistory??hs,this.isTTY=t.isTTY}active(){this.isTTY&&this.write(ts);const t=(n,...s)=>{const i=s.at(-1);return this.#i.push(typeof n=="string"?n:this.#n.write(Buffer.from(n))),this.#i.length>this.#r&&(this.isTTY&&this.#t!==void 0&&this.#t(),this.#s(this.#i.length-Math.floor(this.#r/2))),typeof i=="function"&&i(),ee.DRAIN};this.#e=t,this.#o.write=this.#e}erase(t){t>0&&this.isTTY&&this.write(us(t+1))}inactive(t=!1){this.#i.length>0&&(t&&this.write(`
14
+ `),this.#s(this.#i.length));const n=this.#n.end();n&&this.write(n),this.renew()}renew(){this.#e===void 0||this.#o.write===this.#e?this.#o.write=this.#c:console.warn("[@visulima/interactive-manager] stream.write was replaced by a third party while the hook was active; leaving it untouched to avoid stomping the other patch."),this.#e=void 0,this.isTTY&&this.write(ss)}onEarlyFlush(t){this.#t=t}write(t){this.#c.apply(this.#o,[t])}#s(t){if(t<=0)return;const n=this.#i.splice(0,t);for(const s of n)this.write(s)}}const Se=(e={})=>{const t=new Kn(new ee(process.stdout),new ee(process.stderr));return new Wt(e,t)},ds=(e,t)=>{if(!M(e))return e;const n=$e(t,e);return n===""||n.startsWith("..")?e:n},C=(e,t)=>{const n=ds(e.file,t);return n===e.file?e:{...e,file:n}},ht=e=>{if(!ve(e))return[];try{const t=Tt(e);return Array.isArray(t)?t:[]}catch{return[]}},fs=(e,t,n)=>{const s=ht(t).map(c=>C(c,n)),i=new Set(s.map(c=>N(c))),r=e.map(c=>C(c,n)),o=new Set(r.map(c=>N(c)));return{fresh:r.filter(c=>!i.has(N(c))),resolved:s.filter(c=>!o.has(N(c))),surviving:r.filter(c=>i.has(N(c)))}},dt=(e,t,n,s={})=>{const i=e.map(o=>C(o,n));let r;if(s.replace)r=i;else{const o=ht(t).map(a=>C(a,n)),c=new Set;r=[];for(const a of[...o,...i]){const l=N(a);c.has(l)||(c.add(l),r.push(a))}}return St(t,`${JSON.stringify(r,null,4)}
15
+ `),r.length},_e=1,ps=e=>{const t=new Map;for(const n of e){const s=t.get(n.file);s?s.push(n):t.set(n.file,[n])}return t},gs=e=>{try{return yt(e).split(/\r?\n/)}catch{return}},ms=(e,t,n)=>{const s=Math.max(1,t);return`${e.slice(0,s-1).replaceAll(/[^\t]/g," ")}${"^".repeat(Math.max(1,n))}`},ws=(e,t,n,s={})=>{if(e.length===0)return n?x("No secrets detected."):"No secrets detected.";const i=n?{cyan:Ue,dim:x,green:ye,red:qe,yellow:Y}:{cyan:c=>c,dim:c=>c,green:c=>c,red:c=>c,yellow:c=>c},r=[],o=ps(e);for(const[c,a]of o){const l=$e(t,c)||c;r.push(i.cyan(l));const u=s.redact?void 0:gs(c);for(const h of a){const d=[h.source,h.confidence].filter(Boolean).join(", "),f=d?` ${i.dim(`(${d})`)}`:"",g=h.alternateMatches&&h.alternateMatches.length>0?` ${i.dim(`also: ${h.alternateMatches.join(", ")}`)}`:"";let p="";switch(h.validation){case"error":{p=` ${i.yellow("! error")}`;break}case"rejected":{p=` ${i.red("✗ rejected")}`;break}case"skipped":{p=` ${i.dim("— unverifiable")}`;break}case"verified":{p=` ${i.green("✓ verified")}`;break}}if(r.push(` ${i.red("✖")} ${i.yellow(`[${h.ruleId}]`)}${f}${p} ${i.dim(`line ${String(h.startLine)}:${String(h.startColumn)}`)}${g}`),u){const w=Math.max(0,h.startLine-1-_e),y=Math.min(u.length,h.startLine+_e);for(let m=w;m<y;m+=1){const v=String(m+1).padStart(4," "),k=m+1===h.startLine,b=k?i.red("▶"):" ";if(r.push(` ${b} ${i.dim(v)} │ ${u[m]??""}`),k){const T=Math.max(1,(h.endColumn??h.startColumn+1)-h.startColumn),W=ms(u[m]??"",h.startColumn,T);r.push(` ${i.dim(" │ ")}${i.red(W)}`)}}}r.push("")}}return r.join(`
16
+ `).trimEnd()},ys=(e,t,n={})=>{if(e.length===0)return t?x("No secrets detected in git history."):"No secrets detected in git history.";const s=t?{cyan:Ue,dim:x,green:ye,red:qe,yellow:Y}:{cyan:o=>o,dim:o=>o,green:o=>o,red:o=>o,yellow:o=>o},i=new Map;for(const o of e){const c=i.get(o.commit.sha);c?c.push(o):i.set(o.commit.sha,[o])}const r=[];for(const[o,c]of i){const{authorName:a,date:l,message:u}=c[0].commit;r.push(`${s.yellow(o.slice(0,10))} ${u}`),r.push(` ${s.dim(`${a} · ${l}`)}`);for(const h of c){const d=[h.source,h.confidence].filter(Boolean).join(", "),f=d?` ${s.dim(`(${d})`)}`:"",g=n.redact?"":` ${s.dim(h.match)}`;r.push(` ${s.red("✖")} ${s.yellow(`[${h.ruleId}]`)}${f} ${s.cyan(h.file)} ${s.dim(`line ${String(h.startLine)}:${String(h.startColumn)}`)}${g}`)}r.push("")}return r.join(`
17
+ `).trimEnd()},$s=(e,t)=>{if(!M(e))return e.replaceAll("\\","/");try{return He(e).toString()}catch{return`file://${F(t,e).replaceAll("\\","/")}`}},bs=(e,t=100)=>e.length<=t?e:`${e.slice(0,t-1).trimEnd()}…`,ft=(e,t,n=process.cwd(),s=[])=>{const i=new Map(s.map(a=>[a.id,a])),r=new Set;for(const a of e)r.add(a.ruleId);const o=[...new Set([...i.keys(),...r])].sort((a,l)=>a.localeCompare(l)),c=new Map(o.map((a,l)=>[a,l]));return JSON.stringify({$schema:"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json",runs:[{originalUriBaseIds:{SRCROOT:{uri:He(n).toString()}},results:e.map(a=>{const l={};return a.source&&(l.source=a.source),a.confidence&&(l.confidence=a.confidence),a.alternateMatches&&a.alternateMatches.length>0&&(l.alternateRules=a.alternateMatches),a.validation&&(l.validation=a.validation),{level:"error",locations:[{physicalLocation:{artifactLocation:{uri:$s(a.file,n),uriBaseId:M(a.file)?void 0:"SRCROOT"},region:{endColumn:a.endColumn,endLine:a.endLine,snippet:{text:a.match},startColumn:a.startColumn,startLine:a.startLine}}}],message:{text:a.description||a.ruleId},properties:Object.keys(l).length>0?l:void 0,ruleId:a.ruleId,ruleIndex:c.get(a.ruleId)??-1}}),tool:{driver:{informationUri:"https://visulima.com/packages/secret-scanner",name:"visulima-secret-scanner",rules:o.map(a=>{const l=i.get(a),u=l?.description??`Detected by rule \`${a}\``,h={};return l?.tags&&l.tags.length>0&&(h.tags=l.tags),l?.source&&(h.source=l.source),l?.confidence&&(h.confidence=l.confidence),{defaultConfiguration:{level:"error"},fullDescription:{text:u},helpUri:"https://visulima.com/packages/secret-scanner",id:a,name:a,properties:Object.keys(h).length>0?h:void 0,shortDescription:{text:bs(u)}}}),version:t}}}],version:"2.1.0"},void 0,2)},te=(e,t)=>{try{return It("git",t,{cwd:e,encoding:"utf8",stdio:["ignore","pipe","pipe"]}).trim()}catch{return""}},me=e=>e.split(/\r?\n/).map(t=>t.trim()).filter(Boolean),xs=e=>me(te(e,["diff","--cached","--name-only","--diff-filter=ACMR"])).map(t=>M(t)?t:H(e,t)),Le=(e,t)=>{const n=te(e,["diff","--name-only","--diff-filter=ACMR",`${t}...HEAD`]),s=me(n);if(s.length===0){const i=te(e,["diff","--name-only","--diff-filter=ACMR",t]);return me(i).map(r=>M(r)?r:H(e,r))}return s.map(i=>M(i)?i:H(e,i))},Q=e=>te(e,["rev-parse","--show-toplevel"]).length>0,P=".secrets-baseline.json",De=e=>e?Array.isArray(e)?e:[e]:[],pt=e=>{const t=new Set(["json","sarif","text"]);if(e&&!t.has(e))throw new Error(`--format must be one of: ${[...t].join(", ")} (got "${e}")`);return e??"text"},vs=e=>{if(e===void 0)return;const t=new Set(["high","low","medium"]);if(!t.has(e))throw new Error(`--min-confidence must be one of: ${[...t].join(", ")} (got "${e}")`);return e},ks=async(e,t)=>{const n=await be(e);process.stdout.write(`${String(n.length)} rules loaded
7
18
 
8
- `);for(const s of n){const r=t?L(s.id):s.id,i=s.tags.length>0?` ${t?$(`[${s.tags.join(", ")}]`):`[${s.tags.join(", ")}]`}`:"";if(process.stdout.write(`${r}${i}
19
+ `);for(const s of n){const i=t?Y(s.id):s.id,r=s.tags.length>0?` ${t?x(`[${s.tags.join(", ")}]`):`[${s.tags.join(", ")}]`}`:"";if(process.stdout.write(`${i}${r}
9
20
  ${s.description}
10
- `),s.keywords.length>0){const c=`keywords: ${s.keywords.slice(0,6).join(", ")}${s.keywords.length>6?", ...":""}`;process.stdout.write(` ${t?$(c):c}
21
+ `),s.keywords.length>0){const o=`keywords: ${s.keywords.slice(0,6).join(", ")}${s.keywords.length>6?", ...":""}`;process.stdout.write(` ${t?x(o):o}
11
22
  `)}process.stdout.write(`
12
- `)}},bt=async(e,t)=>{const n=await Te(e);if(n.length===0){process.stdout.write(t?`${$("No non-HTTP validators required by the current ruleset.")}
23
+ `)}},Es=async(e,t)=>{const n=await xt(e);if(n.length===0){process.stdout.write(t?`${x("No non-HTTP validators required by the current ruleset.")}
13
24
  `:`No non-HTTP validators required by the current ruleset.
14
25
  `);return}process.stdout.write(`${String(n.length)} non-HTTP validator type(s) referenced by the current ruleset:
15
26
 
16
- `);for(const s of n){const r=t?L(s.displayName):s.displayName,i=`(${s.type}, ${String(s.ruleCount)} rule${s.ruleCount===1?"":"s"})`;process.stdout.write(`${r} ${t?$(i):i}
27
+ `);for(const s of n){const i=t?Y(s.displayName):s.displayName,r=`(${s.type}, ${String(s.ruleCount)} rule${s.ruleCount===1?"":"s"})`;process.stdout.write(`${i} ${t?x(r):r}
17
28
  `),process.stdout.write(` ${s.summary}
18
- `);const c=s.packageName?`install: npm add ${s.packageName}`:"no driver — bespoke implementation required";process.stdout.write(` ${t?$(c):c}
29
+ `);const o=s.packageName?`install: npm add ${s.packageName}`:"no driver — bespoke implementation required";process.stdout.write(` ${t?x(o):o}
19
30
 
20
- `)}},vt=async(e,t,n)=>{const s=M(e,F);if(!n&&X(s)){y.warn(`Detected existing ${F} — refusing to overwrite. Delete it first to re-init.`),process.exitCode=1;return}y.info(n?"[dry-run] Previewing init — no files will be written.":"Scanning workspace to seed baseline…");const r=Y();r.start("scanning");let i;try{i=await le([e],t),r.succeed()}catch(o){throw r.failed(),o}if(n){y.info(`[dry-run] Would create ${F} with ${String(i.length)} finding(s).`);return}const c=ye(i,s,e,{replace:!0});y.success(`Wrote ${F} (${String(c)} findings).`),y.notice("Commit it. Use `vis secrets --baseline .secrets-baseline.json` in CI. Add path patterns to .gitignore to exclude directories from scanning.")},kt=(e,t,n)=>{const s=t??{},r=d=>d?I(n,d):void 0,i=(d,S)=>{const v=oe(d);return v.length>0?v:S},c=(s.config?.presets??[]).map(d=>`tag:preset:${d}`),o=i(e.enableRule,s.rules?.enable)??[],a=[...o,...c.filter(d=>!o.includes(d))],l=a.length>0?a:void 0,f=i(e.excludeRule,s.rules?.exclude),u=i(e.includeRule,s.rules?.include),h=i(e.exclude,s.walk?.excludePatterns),g=oe(e.excludeFrom).map(d=>I(n,d)),p=g.length>0?g:s.walk?.excludeFromFiles?.map(d=>I(n,d)),m=r(e.baseline)??r(s.baseline),C=r(e.config)??r(s.config?.path),b=$t(e.minConfidence??s.config?.minConfidence);return{baseline:m,concurrency:e.concurrency,config:{extendBundled:e.extendBundled===!1?!1:s.config?.extendBundled,inline:s.config?.inline,minConfidence:b,onlyVerified:e.onlyVerified??s.config?.onlyVerified??!1,path:C,validate:e.validate??s.config?.validate??!1},redact:e.redact??s.redact,rules:{enable:l,exclude:f,include:u},verbose:e.verbose??!1,walk:{excludeFromFiles:p,excludePatterns:h,gitignore:e.gitignore===!1?!1:s.walk?.gitignore??!0,includeHidden:e.includeHidden??s.walk?.includeHidden,maxFileSize:e.maxSize??s.walk?.maxFileSize}}},St=e=>{process.stderr.write(`${$("baseline diff: ")}${J(`+${String(e.fresh.length)} new`)} · ${L(`${String(e.surviving.length)} unchanged`)} · ${$(`-${String(e.resolved.length)} resolved`)}
21
- `)},Et=async(e,t,n)=>{if(e.staged){if(!_(n))throw new Error("--staged requires a git working tree, and none was detected.");return{files:wt(n)}}if(e.since){if(!_(n))throw new Error("--since requires a git working tree, and none was detected.");return{files:ie(n,e.since)}}if(e.affected){if(!_(n))return y.warn("--affected requires git; falling back to full scan"),{paths:t&&t.length>0?t.map(r=>I(n,r)):[n]};const s=process.env.VIS_BASE??"HEAD~1";return{files:ie(n,s)}}return{paths:t&&t.length>0?t.map(s=>I(n,s)):[n]}},It=(e,t,n,s,r,i,c)=>{switch(t){case"json":{const o=e.map(a=>A(a,n));process.stdout.write(`${JSON.stringify(o,null,2)}
22
- `);break}case"sarif":{process.stdout.write(`${we(e,r,n,i)}
23
- `);break}default:process.stdout.write(`${pt(e,n,s,{redact:c})}
24
- `)}},Tt=async(e,t,n,s,r)=>{if(e.staged||e.since||e.affected)throw new Error("--history scans commit history and can't be combined with --staged / --since / --affected (those scan the working tree).");if(!_(t))throw new Error("--history requires a git working tree, and none was detected.");const i=$e(e.format),c=!e.quiet&&i==="text",o=Y({verbose:c});o.start("scanning git history for secrets");let a;try{a=await Re({...n,cwd:t,maxCommits:e.maxCommits,range:e.historyRange}),o.succeed()}catch(u){throw o.failed(),new Error(`git-history secret scan failed: ${u instanceof Error?u.message:String(u)}`,{cause:u})}const l=n.redact===!0,f=l?ge(a,["match","secret"]):a;switch(i){case"json":{process.stdout.write(`${JSON.stringify(f.map(u=>A(u,t)),null,2)}
25
- `);break}case"sarif":{const u=await K(n).catch(()=>[]);process.stdout.write(`${we(f,r,t,u)}
26
- `);break}default:process.stdout.write(`${gt(f,s,{redact:l})}
27
- `)}if(a.length>0){e.quiet||(y.warn(`${String(a.length)} potential secret(s) found across git history`),y.notice("Findings reference the commit that introduced them — rotate the credential and rewrite history (e.g. git filter-repo) if it is still reachable.")),process.exitCode=1;return}e.quiet||y.success("No secrets detected in git history.")},Bt=async({argument:e,options:t,visConfig:n,workspaceRoot:s})=>{const r=t,i=e,c=s??process.cwd(),o=!r.quiet&&process.stdout.isTTY,a=n?.secrets,l=kt(r,a,c),f="0.0.0-alpha";if(r.listRules){await xt(l,o);return}if(r.listValidators){await bt(l,o);return}if(r.init){await vt(c,l,r.dryRun??!1);return}if(r.history){await Tt(r,c,l,o,f);return}const u=await Et(r,i??[],c);if(u.files?.length===0){r.quiet||y.success("No files to scan.");return}const h=!r.quiet&&!["json","sarif"].includes(r.format??"text"),g=Y({verbose:h});g.start("scanning for secrets");let p;try{p=u.files===void 0?await le(u.paths??[c],l):await Ee(u.files,l),g.succeed()}catch(w){throw g.failed(),new Error(`secret scan failed: ${w instanceof Error?w.message:String(w)}`,{cause:w})}if(r.verbose){const w=await Ie(l);if(w.length>0){y.warn(`${String(w.length)} rule(s) skipped due to invalid regex. First few:`);for(const O of w.slice(0,5))process.stderr.write(` - ${O.ruleId}: ${O.reason}
28
- `)}}const m=typeof l.baseline=="string"?l.baseline:M(c,F),C=!r.quiet&&X(m);if(r.updateBaseline){const w=ye(p,m,c,{replace:r.replaceBaseline});y.success(`Baseline updated: ${G(c,m)||m} now contains ${String(w)} entries.`);return}const b=$e(r.format),d=b==="sarif"?await K(l).catch(()=>[]):[],S=l.redact===!0,v=S?ge(p,["match","secret"]):p;if(It(v,b,c,o,f,d,S),b==="text"&&C&&St(ut(p,m,c)),p.length>0){r.quiet||(y.warn(`${String(p.length)} potential secret(s) found`),y.notice("Suppress individual lines with `gitleaks:allow` / `secret-scanner:allow`, or run `vis secrets --update-baseline`.")),process.exitCode=1;return}r.quiet||y.success("No secrets detected.")};export{Bt as default,kt as resolveScanOptions};
31
+ `)}},Ss=async(e,t,n)=>{const s=H(e,P);if(!n&&ve(s)){$.warn(`Detected existing ${P} — refusing to overwrite. Delete it first to re-init.`),process.exitCode=1;return}$.info(n?"[dry-run] Previewing init — no files will be written.":"Scanning workspace to seed baseline…");const i=Se();i.start("scanning");let r;try{r=await Pe([e],t),i.succeed()}catch(c){throw i.failed(),c}if(n){$.info(`[dry-run] Would create ${P} with ${String(r.length)} finding(s).`);return}const o=dt(r,s,e,{replace:!0});$.success(`Wrote ${P} (${String(o)} findings).`),$.notice("Commit it. Use `vis secrets --baseline .secrets-baseline.json` in CI. Add path patterns to .gitignore to exclude directories from scanning.")},Ts=(e,t,n)=>{const s=t??{},i=m=>m?F(n,m):void 0,r=(m,v)=>{const k=De(m);return k.length>0?k:v},o=(s.config?.presets??[]).map(m=>`tag:preset:${m}`),c=r(e.enableRule,s.rules?.enable)??[],a=[...c,...o.filter(m=>!c.includes(m))],l=a.length>0?a:void 0,u=r(e.excludeRule,s.rules?.exclude),h=r(e.includeRule,s.rules?.include),d=r(e.exclude,s.walk?.excludePatterns),f=De(e.excludeFrom).map(m=>F(n,m)),g=f.length>0?f:s.walk?.excludeFromFiles?.map(m=>F(n,m)),p=i(e.baseline)??i(s.baseline),w=i(e.config)??i(s.config?.path),y=vs(e.minConfidence??s.config?.minConfidence);return{baseline:p,concurrency:e.concurrency,config:{extendBundled:e.extendBundled===!1?!1:s.config?.extendBundled,inline:s.config?.inline,minConfidence:y,onlyVerified:e.onlyVerified??s.config?.onlyVerified??!1,path:w,validate:e.validate??s.config?.validate??!1},redact:e.redact??s.redact,rules:{enable:l,exclude:u,include:h},verbose:e.verbose??!1,walk:{excludeFromFiles:g,excludePatterns:d,gitignore:e.gitignore===!1?!1:s.walk?.gitignore??!0,includeHidden:e.includeHidden??s.walk?.includeHidden,maxFileSize:e.maxSize??s.walk?.maxFileSize}}},Is=e=>{process.stderr.write(`${x("baseline diff: ")}${ye(`+${String(e.fresh.length)} new`)} · ${Y(`${String(e.surviving.length)} unchanged`)} · ${x(`-${String(e.resolved.length)} resolved`)}
32
+ `)},As=async(e,t,n)=>{if(e.staged){if(!Q(n))throw new Error("--staged requires a git working tree, and none was detected.");return{files:xs(n)}}if(e.since){if(!Q(n))throw new Error("--since requires a git working tree, and none was detected.");return{files:Le(n,e.since)}}if(e.affected){if(!Q(n))return $.warn("--affected requires git; falling back to full scan"),{paths:t&&t.length>0?t.map(i=>F(n,i)):[n]};const s=process.env.VIS_BASE??"HEAD~1";return{files:Le(n,s)}}return{paths:t&&t.length>0?t.map(s=>F(n,s)):[n]}},Bs=(e,t,n,s,i,r,o)=>{switch(t){case"json":{const c=e.map(a=>C(a,n));process.stdout.write(`${JSON.stringify(c,null,2)}
33
+ `);break}case"sarif":{process.stdout.write(`${ft(e,i,n,r)}
34
+ `);break}default:process.stdout.write(`${ws(e,n,s,{redact:o})}
35
+ `)}},Ns=async(e,t,n,s,i)=>{if(e.staged||e.since||e.affected)throw new Error("--history scans commit history and can't be combined with --staged / --since / --affected (those scan the working tree).");if(!Q(t))throw new Error("--history requires a git working tree, and none was detected.");const r=pt(e.format),o=!e.quiet&&r==="text",c=Se({verbose:o});c.start("scanning git history for secrets");let a;try{a=await vt({...n,cwd:t,maxCommits:e.maxCommits,range:e.historyRange}),c.succeed()}catch(h){throw c.failed(),new Error(`git-history secret scan failed: ${h instanceof Error?h.message:String(h)}`,{cause:h})}const l=n.redact===!0,u=l?Ke(a,["match","secret"]):a;switch(r){case"json":{process.stdout.write(`${JSON.stringify(u.map(h=>C(h,t)),null,2)}
36
+ `);break}case"sarif":{const h=await be(n).catch(()=>[]);process.stdout.write(`${ft(u,i,t,h)}
37
+ `);break}default:process.stdout.write(`${ys(u,s,{redact:l})}
38
+ `)}if(a.length>0){e.quiet||($.warn(`${String(a.length)} potential secret(s) found across git history`),$.notice("Findings reference the commit that introduced them — rotate the credential and rewrite history (e.g. git filter-repo) if it is still reachable.")),process.exitCode=1;return}e.quiet||$.success("No secrets detected in git history.")},qs=async({argument:e,options:t,visConfig:n,workspaceRoot:s})=>{const i=t,r=e,o=s??process.cwd(),c=!i.quiet&&process.stdout.isTTY,a=n?.secrets,l=Ts(i,a,o),u="0.0.0-alpha";if(i.listRules){await ks(l,c);return}if(i.listValidators){await Es(l,c);return}if(i.init){await Ss(o,l,i.dryRun??!1);return}if(i.history){await Ns(i,o,l,c,u);return}const h=await As(i,r??[],o);if(h.files?.length===0){i.quiet||$.success("No files to scan.");return}const d=!i.quiet&&!["json","sarif"].includes(i.format??"text"),f=Se({verbose:d});f.start("scanning for secrets");let g;try{g=h.files===void 0?await Pe(h.paths??[o],l):await $t(h.files,l),f.succeed()}catch(b){throw f.failed(),new Error(`secret scan failed: ${b instanceof Error?b.message:String(b)}`,{cause:b})}if(i.verbose){const b=await bt(l);if(b.length>0){$.warn(`${String(b.length)} rule(s) skipped due to invalid regex. First few:`);for(const T of b.slice(0,5))process.stderr.write(` - ${T.ruleId}: ${T.reason}
39
+ `)}}const p=typeof l.baseline=="string"?l.baseline:H(o,P),w=!i.quiet&&ve(p);if(i.updateBaseline){const b=dt(g,p,o,{replace:i.replaceBaseline});$.success(`Baseline updated: ${$e(o,p)||p} now contains ${String(b)} entries.`);return}const y=pt(i.format),m=y==="sarif"?await be(l).catch(()=>[]):[],v=l.redact===!0,k=v?Ke(g,["match","secret"]):g;if(Bs(k,y,o,c,u,m,v),y==="text"&&w&&Is(fs(g,p,o)),g.length>0){i.quiet||($.warn(`${String(g.length)} potential secret(s) found`),$.notice("Suppress individual lines with `gitleaks:allow` / `secret-scanner:allow`, or run `vis secrets --update-baseline`.")),process.exitCode=1;return}i.quiet||$.success("No secrets detected.")};export{qs as default,Ts as resolveScanOptions};
@@ -1,4 +1,4 @@
1
- import{createRequire as Q}from"node:module";import{J as v,j as w,F as g,q as x,b,X as D}from"../packem_shared/index.server-sXNQYpsl.js";import{e as I,z as se,a as $}from"../packem_shared/index-BzhrR_iC.js";import U from"./index.js";import{y as _}from"../packem_shared/isAccessibleSync-DYKTrrvc-C-_5cgwu.js";import{$ as oe,_ as F,v as ne,a6 as ae,a7 as ie,a8 as re,a9 as ce}from"./cli-main.js";import{k as pe,l as z,E as W,p as L,N as K,a as fe}from"./catalog.js";import{p as S}from"../packem_shared/readJsonSync-CbryXYxN-EWl7_7KX.js";import{U as le}from"../packem_shared/writeFileSync-DJoHk3Ks-BPRoepNw.js";import{T as j}from"../packem_shared/target-merge-DVJl-7Qz.js";import{l as ue}from"../packem_shared/missing-package-json-Cu5YVAot.js";let Z;const ee=e=>(Z??=Q(import.meta.url))(e),V=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,te=e=>{if(typeof V<"u"&&V.versions&&V.versions.node){const[a,s]=V.versions.node.split(".").map(Number);if(a>22||a===22&&s>=3||a===20&&s>=16)return V.getBuiltinModule(e)}return ee(e)},{readFileSync:Y,writeFileSync:H}=te("node:fs"),de=e=>/[*?[\]{}!]/.test(e),ge=e=>typeof e=="string"?e:e.reason,me=e=>typeof e=="string"?void 0:e.replacement,q=(e,a)=>e.some(s=>U(s,a)),G=(e,a)=>{if(typeof e=="string")return!0;const s=Array.isArray(e.packages)&&e.packages.length>0,t=Array.isArray(e.paths)&&e.paths.length>0;return!!(!s&&!t||s&&a.packageName!==void 0&&q(e.packages,a.packageName)||t&&q(e.paths,a.packageDir))},he=(e,a)=>{const s=a[e.depName];if(s!==void 0&&G(s,e))return{pattern:e.depName,rule:s};for(const[t,r]of Object.entries(a))if(de(t)&&U(t,e.depName)&&G(r,e))return{pattern:t,rule:r}},ke=(e,a)=>{if(Object.keys(a).length===0)return[];const s=[];for(const t of e){if(t.isInternal)continue;const r=he(t,a);r&&s.push({depName:t.depName,depType:t.depType,matchedPattern:r.pattern,packageDir:t.packageDir,packageJsonPath:t.packageJsonPath,packageName:t.packageName,reason:ge(r.rule),replacement:me(r.rule),specifier:t.specifier})}return s},ye=new Set(["dependencies","devDependencies","peerDependencies"]),Pe=e=>e.startsWith("catalog:"),$e=e=>e.startsWith("workspace:"),we=(e,a)=>{if(!e)return!1;for(const s of e.values())if(s.has(a))return!0;return!1},ve=(e,a={})=>{const s=a.min??3,t=new Set(a.ignoreDeps),r=e.filter(i=>i.isInternal||!ye.has(i.depType)||$e(i.specifier)||a.dep!==void 0&&i.depName!==a.dep?!1:!t.has(i.depName)),n=new Map;for(const i of r){const c=n.get(i.depName);c?c.push(i):n.set(i.depName,[i])}const o=[];for(const[i,c]of n){if(we(a.catalogs,i)||c.some(h=>Pe(h.specifier)))continue;const p=new Map;for(const h of c){let d=p.get(h.specifier);d||(d=new Set,p.set(h.specifier,d)),d.add(h.packageJsonPath)}const m=[...p.entries()].sort((h,d)=>h[1].size!==d[1].size?d[1].size-h[1].size:h[0].localeCompare(d[0]))[0];!m||m[1].size<s||o.push({catalogName:"default",depName:i,instanceCount:m[1].size,specifier:m[0]})}return o.sort((i,c)=>i.depName.localeCompare(c.depName))},De=(e,a)=>{if(a.length===0)return;const s=I(e,"pnpm-workspace.yaml"),r=_(s)?Y(s,"utf8"):"",n=r.includes(`\r
1
+ import{createRequire as Q}from"node:module";import{J as v,j as w,F as g,q as x,b,X as D}from"../packem_shared/index.server-D8BLnYZO.js";import{e as I,a as se,b as $}from"../packem_shared/index-BdMIfGVZ.js";import U from"./index.js";import{y as _}from"../packem_shared/isAccessibleSync-DYKTrrvc-BwaMhQs0.js";import{$ as oe,_ as F,v as ne,a4 as ae,a5 as ie,a6 as re,a7 as ce}from"./cli-main.js";import{k as pe,l as z,E as W,p as L,N as K,a as fe}from"./catalog.js";import{p as S}from"../packem_shared/readJsonSync-CbryXYxN-Bm5i10UW.js";import{U as le}from"../packem_shared/writeFileSync-DJoHk3Ks-Dhem3Uof.js";import{T as j}from"../packem_shared/target-merge-BClIXg2k.js";import{l as ue}from"../packem_shared/missing-package-json-DfzrGwe1.js";let Z;const ee=e=>(Z??=Q(import.meta.url))(e),V=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,te=e=>{if(typeof V<"u"&&V.versions&&V.versions.node){const[a,s]=V.versions.node.split(".").map(Number);if(a>22||a===22&&s>=3||a===20&&s>=16)return V.getBuiltinModule(e)}return ee(e)},{readFileSync:Y,writeFileSync:H}=te("node:fs"),de=e=>/[*?[\]{}!]/.test(e),ge=e=>typeof e=="string"?e:e.reason,me=e=>typeof e=="string"?void 0:e.replacement,q=(e,a)=>e.some(s=>U(s,a)),G=(e,a)=>{if(typeof e=="string")return!0;const s=Array.isArray(e.packages)&&e.packages.length>0,t=Array.isArray(e.paths)&&e.paths.length>0;return!!(!s&&!t||s&&a.packageName!==void 0&&q(e.packages,a.packageName)||t&&q(e.paths,a.packageDir))},he=(e,a)=>{const s=a[e.depName];if(s!==void 0&&G(s,e))return{pattern:e.depName,rule:s};for(const[t,r]of Object.entries(a))if(de(t)&&U(t,e.depName)&&G(r,e))return{pattern:t,rule:r}},ke=(e,a)=>{if(Object.keys(a).length===0)return[];const s=[];for(const t of e){if(t.isInternal)continue;const r=he(t,a);r&&s.push({depName:t.depName,depType:t.depType,matchedPattern:r.pattern,packageDir:t.packageDir,packageJsonPath:t.packageJsonPath,packageName:t.packageName,reason:ge(r.rule),replacement:me(r.rule),specifier:t.specifier})}return s},ye=new Set(["dependencies","devDependencies","peerDependencies"]),Pe=e=>e.startsWith("catalog:"),$e=e=>e.startsWith("workspace:"),we=(e,a)=>{if(!e)return!1;for(const s of e.values())if(s.has(a))return!0;return!1},ve=(e,a={})=>{const s=a.min??3,t=new Set(a.ignoreDeps),r=e.filter(i=>i.isInternal||!ye.has(i.depType)||$e(i.specifier)||a.dep!==void 0&&i.depName!==a.dep?!1:!t.has(i.depName)),n=new Map;for(const i of r){const c=n.get(i.depName);c?c.push(i):n.set(i.depName,[i])}const o=[];for(const[i,c]of n){if(we(a.catalogs,i)||c.some(h=>Pe(h.specifier)))continue;const p=new Map;for(const h of c){let d=p.get(h.specifier);d||(d=new Set,p.set(h.specifier,d)),d.add(h.packageJsonPath)}const m=[...p.entries()].sort((h,d)=>h[1].size!==d[1].size?d[1].size-h[1].size:h[0].localeCompare(d[0]))[0];!m||m[1].size<s||o.push({catalogName:"default",depName:i,instanceCount:m[1].size,specifier:m[0]})}return o.sort((i,c)=>i.depName.localeCompare(c.depName))},De=(e,a)=>{if(a.length===0)return;const s=I(e,"pnpm-workspace.yaml"),r=_(s)?Y(s,"utf8"):"",n=r.includes(`\r
2
2
  `)?`\r
3
3
  `:`
4
4
  `,o=a.filter(d=>d.catalogName==="default").sort((d,u)=>d.depName.localeCompare(u.depName));if(o.length===0)return;const i=r.length>0?r.split(n):[],c=i.findIndex(d=>/^catalog\s*:\s*$/.test(d));if(c===-1){const d=["catalog:"];for(const J of o)d.push(` ${J.depName}: "${J.specifier}"`);let u=0;for(;u<i.length&&(i[u]??"").trim().length===0;)u+=1;const k=[...i.slice(0,u),...d,"",...i.slice(u)].join(n);return H(s,k.endsWith(n)?k:`${k}${n}`),s}let p=i.length;const f=new Set;for(let d=c+1;d<i.length;d+=1){const u=i[d]??"",k=u.trimStart();if(u.length===0)continue;if(u.length-k.length===0&&k.length>0&&!k.startsWith("#")){p=d;break}const P=/^([\w./@-]+)\s*:/.exec(k);P?.[1]&&f.add(P[1])}const m=[];for(const d of o)f.has(d.depName)||m.push(` ${d.depName}: "${d.specifier}"`);if(m.length===0)return;const h=[...i.slice(0,p),...m,...i.slice(p)].join(n);return H(s,h.endsWith(n)?h:`${h}${n}`),s},be=(e,a)=>{if(a.length===0)return"";const s=I(e,"pnpm-workspace.yaml"),r=_(s)?Y(s,"utf8"):"",n=[...a].sort((f,m)=>f.depName.localeCompare(m.depName)),o=["--- pnpm-workspace.yaml","+++ pnpm-workspace.yaml"],i=r.includes(`\r