@visulima/vis 1.0.0-alpha.44 → 1.0.0-alpha.46

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 (145) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/bin.js +1 -1
  3. package/dist/binx.js +1 -1
  4. package/dist/packem_chunks/CONFIG_FILES.js +3 -3
  5. package/dist/packem_chunks/agent-instructions.js +11 -0
  6. package/dist/packem_chunks/bloom-status.js +1 -1
  7. package/dist/packem_chunks/bloom-sync.js +1 -1
  8. package/dist/packem_chunks/catalog.js +63 -62
  9. package/dist/packem_chunks/cli-exec.js +1 -1
  10. package/dist/packem_chunks/cli-main.js +172 -973
  11. package/dist/packem_chunks/defineReleasePlugin.js +3 -0
  12. package/dist/packem_chunks/detect.js +1 -1
  13. package/dist/packem_chunks/fix.js +1 -1
  14. package/dist/packem_chunks/group-tags.js +1 -0
  15. package/dist/packem_chunks/handler.js +1 -1
  16. package/dist/packem_chunks/handler10.js +1 -1
  17. package/dist/packem_chunks/handler11.js +1 -1
  18. package/dist/packem_chunks/handler12.js +2 -2
  19. package/dist/packem_chunks/handler13.js +1 -1
  20. package/dist/packem_chunks/handler14.js +1 -1
  21. package/dist/packem_chunks/handler15.js +1 -1
  22. package/dist/packem_chunks/handler16.js +1 -1
  23. package/dist/packem_chunks/handler17.js +1 -1
  24. package/dist/packem_chunks/handler18.js +1 -1
  25. package/dist/packem_chunks/handler19.js +1 -1
  26. package/dist/packem_chunks/handler20.js +1 -1
  27. package/dist/packem_chunks/handler21.js +1 -1
  28. package/dist/packem_chunks/handler24.js +1 -1
  29. package/dist/packem_chunks/handler26.js +1 -1
  30. package/dist/packem_chunks/handler27.js +1 -1
  31. package/dist/packem_chunks/handler28.js +1 -1
  32. package/dist/packem_chunks/handler29.js +1 -1
  33. package/dist/packem_chunks/handler3.js +1 -1
  34. package/dist/packem_chunks/handler30.js +1 -1
  35. package/dist/packem_chunks/handler32.js +1 -1
  36. package/dist/packem_chunks/handler4.js +1 -1
  37. package/dist/packem_chunks/handler40.js +19 -19
  38. package/dist/packem_chunks/handler5.js +3 -3
  39. package/dist/packem_chunks/handler50.js +4 -4
  40. package/dist/packem_chunks/handler51.js +3 -3
  41. package/dist/packem_chunks/handler54.js +1 -1
  42. package/dist/packem_chunks/handler57.js +11 -5
  43. package/dist/packem_chunks/handler58.js +5 -11
  44. package/dist/packem_chunks/handler59.js +11 -3
  45. package/dist/packem_chunks/handler6.js +6 -6
  46. package/dist/packem_chunks/handler60.js +3 -22
  47. package/dist/packem_chunks/handler61.js +21 -60
  48. package/dist/packem_chunks/handler62.js +61 -3
  49. package/dist/packem_chunks/handler63.js +3 -6
  50. package/dist/packem_chunks/handler64.js +6 -9
  51. package/dist/packem_chunks/handler65.js +9 -2
  52. package/dist/packem_chunks/handler66.js +2 -24
  53. package/dist/packem_chunks/handler67.js +24 -25
  54. package/dist/packem_chunks/handler68.js +25 -153
  55. package/dist/packem_chunks/handler69.js +153 -10
  56. package/dist/packem_chunks/handler7.js +1 -1
  57. package/dist/packem_chunks/handler70.js +10 -23
  58. package/dist/packem_chunks/handler71.js +23 -322
  59. package/dist/packem_chunks/handler72.js +273 -659
  60. package/dist/packem_chunks/handler73.js +708 -48
  61. package/dist/packem_chunks/handler74.js +48 -27
  62. package/dist/packem_chunks/handler75.js +27 -3
  63. package/dist/packem_chunks/handler76.js +3 -190
  64. package/dist/packem_chunks/handler77.js +189 -37
  65. package/dist/packem_chunks/handler78.js +38 -0
  66. package/dist/packem_chunks/handler9.js +1 -1
  67. package/dist/packem_chunks/heal-accept.js +1 -1
  68. package/dist/packem_chunks/heal.js +1 -1
  69. package/dist/packem_chunks/help-command.js +1 -1
  70. package/dist/packem_chunks/index2.js +802 -7
  71. package/dist/packem_chunks/index3.js +7 -135
  72. package/dist/packem_chunks/index4.js +134 -73
  73. package/dist/packem_chunks/index5.js +74 -0
  74. package/dist/packem_chunks/keys-refresh.js +1 -1
  75. package/dist/packem_chunks/lean.js +1 -1
  76. package/dist/packem_chunks/list.js +1 -1
  77. package/dist/packem_chunks/loader.js +1 -1
  78. package/dist/packem_chunks/orchestrator.js +26 -23
  79. package/dist/packem_chunks/print-config.js +1 -1
  80. package/dist/packem_chunks/prune.js +1 -1
  81. package/dist/packem_chunks/registry.js +2 -2
  82. package/dist/packem_chunks/shell-runner.js +1 -1
  83. package/dist/packem_chunks/state.js +3 -3
  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 +2 -2
  88. package/dist/packem_chunks/ts-loader.js +1 -1
  89. package/dist/packem_chunks/verify-lockfile.js +1 -1
  90. package/dist/packem_chunks/version-resolver.js +2 -2
  91. package/dist/packem_shared/ReleaseClient-BY4OZNCK.js +1 -0
  92. package/dist/packem_shared/{advisories-CefYKEPe.js → advisories-B76fBVL-.js} +1 -1
  93. package/dist/packem_shared/affected-shas-CCxG4tvm.js +1 -0
  94. package/dist/packem_shared/{ai-analysis-CO6S0afy.js → ai-analysis-DF_AfeS3.js} +4 -4
  95. package/dist/packem_shared/{ai-fix-CI0Vvqld.js → ai-fix-D1bFLkfk.js} +3 -3
  96. package/dist/packem_shared/bin-BlGVEhl8.js +1 -0
  97. package/dist/packem_shared/{build-scripts-MTSK6TNr.js → build-scripts-q__dKE2y.js} +1 -1
  98. package/dist/packem_shared/{command-runtime-BE-vKsGH.js → command-runtime-3FTGuUsK.js} +1 -1
  99. package/dist/packem_shared/{cyclonedx-BeUmPgfO.js → cyclonedx-CmrYQ0vx.js} +1 -1
  100. package/dist/packem_shared/{docker-CViFYtmM.js → docker-BYqiD711.js} +1 -1
  101. package/dist/packem_shared/{env-C2ZCnfP_.js → env-DJlbJiFh.js} +2 -2
  102. package/dist/packem_shared/{failure-log-jFfZRJK9.js → failure-log-Bt7sW4p7.js} +1 -1
  103. package/dist/packem_shared/{index-D7EZ612R.js → index-C6tpgeIV.js} +2 -2
  104. package/dist/packem_shared/{index-CQjzW7m8.js → index-D6fJJDli.js} +1 -1
  105. package/dist/packem_shared/{lifecycle-Dyb47wbD.js → lifecycle-XeMei1ED.js} +1 -1
  106. package/dist/packem_shared/{manifests-WBnsV_Eb.js → manifests-DSBr3-dw.js} +1 -1
  107. package/dist/packem_shared/{native-config-sync-BFDVK9LH.js → native-config-sync-D-z2Uwqu.js} +1 -1
  108. package/dist/packem_shared/{osv-bloom-BsQ-aFiM.js → osv-bloom-DMhXP184.js} +2 -2
  109. package/dist/packem_shared/{packument-DquNPIq9.js → packument-CY2QDFml.js} +1 -1
  110. package/dist/packem_shared/plugins.d-ND23R9I3.d.ts +4 -0
  111. package/dist/packem_shared/pm-runner-CQcraCcu.js +1 -0
  112. package/dist/packem_shared/{provenance-DIq8KyBV.js → provenance-DVHiWZrW.js} +1 -1
  113. package/dist/packem_shared/{registry-keys-C8K11ets.js → registry-keys-BKEq72qX.js} +1 -1
  114. package/dist/packem_shared/{resolve-explicit-Dr4kIybR.js → resolve-explicit-UtkNrGKq.js} +1 -1
  115. package/dist/packem_shared/resolve-runtime-QRaQucfL.js +1 -0
  116. package/dist/packem_shared/{runtime-check-BXehSP06.js → runtime-check-qnrPTlma.js} +1 -1
  117. package/dist/packem_shared/{s1ngularity-CtMmtXJo.js → s1ngularity-DUZtU95L.js} +1 -1
  118. package/dist/packem_shared/scan-progress-BgtHexnt.js +2 -0
  119. package/dist/packem_shared/{signatures-CE8OAK-i.js → signatures-QoCuUv9E.js} +1 -1
  120. package/dist/packem_shared/target-merge-Dg25Izl5.js +11 -0
  121. package/dist/packem_shared/{toolchain-C44mPKPu.js → toolchain-Zb3VzZb4.js} +1 -1
  122. package/dist/packem_shared/{typosquats-CQz-1Y6K.js → typosquats-C12CP_2G.js} +1 -1
  123. package/dist/packem_shared/use-measured-height-BpKmrlkw.js +1 -0
  124. package/dist/packem_shared/{vis-update-app-Cpme_3Du.js → vis-update-app-BoCQ4ute.js} +1 -1
  125. package/dist/packem_shared/{watch-loop-JfGKIgKB.js → watch-loop-BZudYfcl.js} +1 -1
  126. package/dist/release/index.d.ts +39 -2
  127. package/dist/release/index.js +1 -1
  128. package/dist/release/plugin-sdk.d.ts +2 -1
  129. package/dist/release/plugin-sdk.js +1 -1
  130. package/dist/release/types.d.ts +117 -1
  131. package/dist/release/types.js +1 -1
  132. package/index.js +52 -52
  133. package/package.json +11 -11
  134. package/schemas/vis-config.schema.json +33 -0
  135. package/schemas/vis-release-config.schema.json +33 -0
  136. package/dist/packem_shared/ReleaseClient-YHzBIxYS.js +0 -1
  137. package/dist/packem_shared/affected-shas-CwRY5aoc.js +0 -1
  138. package/dist/packem_shared/bin-P6Q5tKrP.js +0 -1
  139. package/dist/packem_shared/pm-runner-D4jM58Oz.js +0 -1
  140. package/dist/packem_shared/resolve-runtime-Tx0bvg0h.js +0 -1
  141. package/dist/packem_shared/scan-progress-D4yywI6P.js +0 -2
  142. package/dist/packem_shared/target-merge-DOm6h6tW.js +0 -11
  143. package/dist/packem_shared/use-measured-height-XK9YSwtv.js +0 -1
  144. package/dist/packem_shared/window-ops-DDePlWLV.js +0 -2
  145. /package/dist/packem_shared/{readJsonSync-CvkZyKmL-ihoybKvs.js → readJsonSync-DuMMeB3s-ihoybKvs.js} +0 -0
@@ -1,27 +1,48 @@
1
- import{createRequire as mt}from"node:module";import{y as b,J as it,B as yt,A as at,m as O,f as B,k as kt}from"../packem_shared/index-CE6MsgcV.js";import{$ as vt,m as w,n as C,i as x,k as Tt,W as St}from"./catalog.js";import ot from"./index.js";import{k as ct}from"../packem_shared/main-B3juSU5z.js";import"../packem_shared/env-C2ZCnfP_.js";import"../packem_shared/window-ops-DDePlWLV.js";import{o as It}from"../packem_shared/spinner-DuJJvFTl.js";import{C as dt,D as _,T as lt}from"../packem_shared/symbols-DPTlrJ3B.js";import{s as V,E as $,q as P,V as G,I as Et}from"../packem_shared/index.server-J83sowC4.js";import{withEnhancedPath as Mt}from"@visulima/task-runner";const wt=mt(import.meta.url),A=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,H=t=>{if(typeof A<"u"&&A.versions&&A.versions.node){const[e,s]=A.versions.node.split(".").map(Number);if(e>22||e===22&&s>=3||e===20&&s>=16)return A.getBuiltinModule(t)}return wt(t)},{readFileSync:xt,writeFileSync:bt,unlinkSync:$t}=H("node:fs"),{randomBytes:Ct}=H("node:crypto"),{availableParallelism:z}=H("node:os");class E extends Error{constructor(e,s){super(e,s),this.name=this.constructor.name}}class At extends E{}class v extends E{}class W extends E{}class R extends E{stderr;constructor(e,s,r){super(e,r),this.stderr=s}}class K extends E{}class I extends E{commandTitle;constructor(e,s,r){super(s,r),this.commandTitle=e}}const ut=t=>t.includes("/"),D=(t,e)=>e?t.toLowerCase():t,jt=(t,e,s,r={})=>{const n=ut(t),a=r.caseInsensitive===!0,c=D(t,a),i=[];for(const o of e){const l=n?b(s,o):it(o);ot(c,D(l,a))&&i.push(o)}return i},Rt=(t,e,s,r={})=>{if(!e||e.length===0)return[...t];const n=r.caseInsensitive===!0;return t.filter(a=>{for(const c of e){const i=ut(c)?b(s,a):it(a),o=D(c,n);if(ot(o,D(i,n)))return!1}return!0})},L=t=>typeof t=="object"&&t!==null&&typeof t.title=="string"&&typeof t.task=="function",N=t=>typeof t=="object"&&t!==null&&typeof t.command=="string"&&typeof t.task!="function",Nt=(t,e)=>{const s=b(t,e);return s===""||!s.startsWith("..")&&!at(s)},Ot=(t,e)=>{let s;for(const r of e)Nt(r,t)&&(s===void 0||r.length>s.length)&&(s=r);return s},_t=async t=>{let e=0,s=0;const r=()=>(e+=1,`pattern-${e}`),n=()=>(s+=1,`cmd-${s}`),a=(o,l,h,d)=>{if(o.perPackage===!0){const u=t.workspacePackages??[],p=new Map;for(const f of h){const g=Ot(f,u)??t.cwd,y=p.get(g)??[];y.push(b(g,f)),p.set(g,y)}for(const f of[...p.keys()].sort()){const g=b(t.cwd,f)||".";d.push({command:o.command,cwd:f,files:p.get(f)??[],id:n(),source:"string",title:`${o.command} — ${g}`})}return}if(o.cwd!==void 0){const u=yt(t.cwd,o.cwd);d.push({command:o.command,cwd:u,files:h,id:n(),source:"string",title:`${o.command} ${b(t.cwd,u)||"."}`});return}d.push({command:o.command,files:l,id:n(),source:"string",title:o.command})},c=async(o,l,h,d)=>{if(typeof o=="string"){d.push({command:o,files:l,id:n(),source:"string",title:o});return}if(Array.isArray(o)){for(const u of o)await c(u,l,h,d);return}if(N(o)){a(o,l,h,d);return}if(typeof o=="function"){const u=await o([...l]);if(typeof u=="string"){d.push({command:u,files:l,id:n(),source:"function",title:u});return}if(Array.isArray(u)){for(const p of u)if(typeof p=="string")d.push({command:p,files:l,id:n(),source:"function",title:p});else if(N(p))a(p,l,h,d);else if(L(p))d.push({files:l,id:n(),run:p.task,source:"custom",title:p.title});else throw new v("Task function returned an array with an unsupported entry — expected strings, { command, … }, or { title, task }.");return}if(N(u)){a(u,l,h,d);return}if(L(u)){d.push({files:l,id:n(),run:u.task,source:"custom",title:u.title});return}throw new v("Task function returned an unsupported value — expected string, string[], { command, … }, or { title, task }.")}if(L(o)){d.push({files:l,id:n(),run:o.task,source:"custom",title:o.title});return}throw new v("Unsupported task value — expected string, string[], function, { command, … }, or { title, task }.")},i=[];for(const[o,l]of Object.entries(t.config)){const h=jt(o,t.files,t.cwd,{caseInsensitive:t.caseInsensitive===!0});if(h.length===0)continue;const d=t.relative?h.map(p=>b(t.cwd,p)):h,u=[];await c(l,d,h,u),u.length!==0&&i.push({commands:u,files:d,id:r(),pattern:o,title:`${o} — ${h.length} file${h.length===1?"":"s"}`})}return i},Dt=async t=>{if(t.config!==void 0)return t.config;throw new v(`No staged config provided. Add \`staged\` to your vis.config.ts:
2
-
3
- import { defineConfig } from "@visulima/vis/config";
4
-
5
- export default defineConfig({
6
- staged: { "*.ts": "eslint --fix" },
7
- });
8
-
9
- Coming from lint-staged or nano-staged? Run \`vis migrate lint-staged\` (or \`vis migrate nano-staged\`) to move the config in and remove the legacy files.`)},Y=t=>{if(typeof t!="object"||t===null)throw new v("Staged config must be an object mapping glob patterns to tasks.");const e=Object.entries(t);if(e.length===0)throw new v("Staged config is empty — at least one glob pattern is required.");for(const[s,r]of e){if(!s||s.trim()==="")throw new v("Staged config keys must be non-empty glob patterns.");ht(s,r)}return t},ht=(t,e)=>{if(typeof e=="string"){if(e.trim()==="")throw new v(`Task for "${t}" is an empty string.`);return}if(Array.isArray(e)){if(e.length===0)throw new v(`Task array for "${t}" is empty.`);for(const s of e)ht(t,s);return}if(typeof e!="function"){if(typeof e=="object"&&e!==null&&typeof e.command=="string"&&typeof e.task=="function")throw new v(`Task for "${t}" sets both \`command\` and \`task\` — use one or the other.`);if(N(e)){if(e.command.trim()==="")throw new v(`Command task for "${t}" has an empty \`command\`.`);return}if(!Ft(e))throw new v(`Invalid task for "${t}" — expected string, string[], function, { command, … }, or { title, task } object.`)}},Ft=t=>typeof t=="object"&&t!==null&&typeof t.title=="string"&&typeof t.task=="function",J=2048,m=async(t,e)=>{const s=e.input===void 0?void 0:typeof e.input=="string"?e.input:e.input.toString("utf8"),r=await ct("git",[...t],{nodeOptions:{cwd:e.cwd,env:e.env?{...process.env,...e.env}:void 0,stdio:s===void 0?["ignore","pipe","pipe"]:["pipe","pipe","pipe"]},stdin:s}),n=typeof r.exitCode=="number"?r.exitCode:1;if(n!==0&&!e.lenient){const{stderr:a}=r,c=a.length>J?`${a.slice(0,J)}…`:a;throw new R(`git ${t.join(" ")} failed with exit code ${n}: ${c.trim()}`,a)}return{exitCode:n,stderr:r.stderr,stdout:r.stdout}},M=async(t,e)=>{const{stdout:s}=await m(t,e);return s.trim()},Pt=async t=>{const e=await m(["rev-parse","--is-inside-work-tree"],{cwd:t,lenient:!0});return e.exitCode===0&&e.stdout.trim()==="true"},Gt=async t=>M(["rev-parse","--absolute-git-dir"],{cwd:t}),ft=async t=>M(["rev-parse","--show-toplevel"],{cwd:t}),Q=async t=>M(["write-tree"],{cwd:t}),Lt=async t=>{const e=await m(["rev-parse","HEAD^{tree}"],{cwd:t,lenient:!0});return e.exitCode===0?e.stdout.trim():""},j={major:2,minor:32},Ht=t=>{const e=/git version (\d+)\.(\d+)/.exec(t);if(!e)return null;const s=Number.parseInt(e[1]??"",10),r=Number.parseInt(e[2]??"",10);return Number.isNaN(s)||Number.isNaN(r)?null:{major:s,minor:r}},qt=async t=>{const e=Ht(await M(["--version"],{cwd:t}));if(e!==null&&(e.major<j.major||e.major===j.major&&e.minor<j.minor))throw new R(`Git ${j.major}.${j.minor} or newer is required; found ${e.major}.${e.minor}.`)},Ut="ACMR",X=500,Bt=async t=>{const{stdout:e}=await m(["diff-files","--raw","-z"],{cwd:t}),s=e.split("\0").filter(n=>n.length>0),r=[];for(let n=0;n<s.length;n+=1){const a=s[n];if(!a?.startsWith(":"))continue;const c=a.slice(1).split(" "),i=c[3],o=c[4],l=s[n+1];n+=1,o==="A"&&i!==void 0&&/^0+$/.test(i)&&l!==void 0&&r.push(l)}return r},Z=async t=>{const{stdout:e}=await m(["ls-files","--others","--exclude-standard","-z"],{cwd:t});return e.split("\0").filter(s=>s.length>0)},Vt=async(t,e)=>{if(t.length===0)return;const s=`${t.join("\0")}\0`;await m(["rm","--cached","--quiet","--pathspec-from-file=-","--pathspec-file-nul","--"],{cwd:e.cwd,input:s})},zt=async t=>{const e=t.diffFilter??Ut,s=t.diff===void 0?["diff","--name-only","-z",`--diff-filter=${e}`,"--staged"]:["diff","--name-only","-z",`--diff-filter=${e}`,...t.diff.split(/\s+/).filter(Boolean)],{stdout:r}=await m(s,{cwd:t.cwd}),n=r.split("\0").filter(c=>c.length>0);if(n.length===0)return[];const a=t.workTree??await ft(t.cwd);return n.map(c=>at(c)?c:O(a,c))},Wt=async(t,e)=>{if(t.length===0)return null;const s=[];for(let a=0;a<t.length;a+=X){const c=t.slice(a,a+X),{stdout:i}=await m(["diff","--binary","--unified=0","--no-color","--no-ext-diff","--src-prefix=a/","--dst-prefix=b/","--patch","--submodule=short","--",...c],{cwd:e.cwd});i.length>0&&s.push(i)}if(s.length===0)return null;const r=s.join(""),n=r.endsWith(`
10
- `)?r:`${r}
11
- `;return Buffer.from(n,"utf8")},Kt=async t=>{const{stdout:e}=await m(["status","--porcelain=v1","-z"],{cwd:t}),s=e.split("\0"),r=[];for(let n=0;n<s.length;n+=1){const a=s[n];if(a===void 0||a.length<4)continue;const c=a.charAt(0),i=a.charAt(1),o=a.slice(3),l=c==="R"||c==="C"||i==="R"||i==="C";c!==" "&&c!=="?"&&i!==" "&&i!=="?"&&r.push(o),l&&(n+=1)}return r},Yt=async(t,e)=>{if(t.length===0)return;const s=`${t.join("\0")}\0`;await m(["checkout","--force","--pathspec-from-file=-","--pathspec-file-nul","--"],{cwd:e.cwd,input:s})},Jt=async(t,e)=>{if(await m(["update-index","--again"],{cwd:e.cwd,lenient:!0}),t.length===0)return;const s=`${t.join("\0")}\0`;await m(["add","-u","--pathspec-from-file=-","--pathspec-file-nul","--"],{cwd:e.cwd,input:s})},Qt="vis_staged_automatic_backup",pt=()=>`${Qt}-${process.pid}-${Date.now()}-${Ct(3).toString("hex")}`,Xt=async t=>{const e=await M(["stash","create"],{cwd:t});return e.length===0?null:(await m(["stash","store","-m",pt(),e],{cwd:t}),e)},Zt=async t=>{const e=pt(),{exitCode:s,stdout:r}=await m(["stash","push","--keep-index","--include-untracked","--quiet","-m",e],{cwd:t,lenient:!0});if(s!==0)return null;const n=r.trim();return n.length>0&&/no local changes/i.test(n)?null:M(["rev-parse","stash@{0}"],{cwd:t})},q=async(t,e)=>{const{exitCode:s,stdout:r}=await m(["reflog","--format=%H %gd","refs/stash"],{cwd:t,lenient:!0});if(s!==0)return null;for(const n of r.split(/\r?\n/)){const[a,c]=n.split(/\s+/,2);if(a===e&&c!==void 0)return c}return null},tt=async(t,e)=>{if(e===null)return;const s=await q(t,e);s!==null&&await m(["stash","drop","--quiet",s],{cwd:t})},te=async(t,e)=>{if(e===null)throw new W("Backup stash was not found — can't revert working tree.");const s=await q(t,e);if(s===null)throw new W(`Backup stash ${e} is no longer reachable — can't revert working tree.`);await m(["reset","--hard","HEAD"],{cwd:t}),await m(["stash","apply","--index","--quiet",s],{cwd:t})},ee=async(t,e)=>{if(e===null)return;const s=await q(t,e);s!==null&&await m(["stash","pop","--quiet",s],{cwd:t})};class se{stagedFiles=[];partiallyStaged=[];workTree="";gitDir="";preTaskIndexTree="";postTaskIndexTree="";headTree="";revertApplied=!1;warnings=[];cwd;options;patch=null;backupStashSha=null;merge=[];shouldStash;shouldHidePartial;shouldHideUnstaged;shouldHideAll;hideAllStashSha=null;intentToAddPaths=[];preTaskUntracked=new Set;constructor(e){this.cwd=e.cwd??process.cwd(),this.options=e,this.shouldStash=e.stash!==!1&&e.diff===void 0,this.shouldHidePartial=e.hidePartiallyStaged!==!1,this.shouldHideUnstaged=e.hideUnstaged===!0,this.shouldHideAll=e.hideAll===!0}async prepare(){if(!await Pt(this.cwd))throw new R(`Not a git repository: ${this.cwd}`);await qt(this.cwd),this.workTree=await ft(this.cwd),this.gitDir=await Gt(this.cwd),this.stagedFiles=await zt({cwd:this.workTree,diff:this.options.diff,diffFilter:this.options.diffFilter,workTree:this.workTree}),this.partiallyStaged=this.stagedFiles.length===0?[]:await Kt(this.workTree),this.snapshotMergeState(),this.intentToAddPaths=await Bt(this.workTree),this.intentToAddPaths.length>0&&await Vt(this.intentToAddPaths,{cwd:this.workTree}),this.shouldStash?this.backupStashSha=await Xt(this.workTree):this.partiallyStaged.length>0&&this.warnings.push("Running with --no-stash on partially-staged files — unstaged deltas will be captured to a patch, but if re-applying the patch fails after tasks run the changes cannot be recovered."),this.shouldHideAll?this.hideAllStashSha=await Zt(this.workTree):await this.hideUnstagedChanges(),this.preTaskIndexTree=this.stagedFiles.length===0?"":await Q(this.workTree),this.postTaskIndexTree=this.preTaskIndexTree,this.headTree=await Lt(this.workTree),this.preTaskUntracked=new Set(await Z(this.workTree))}async applyModifications({autoStage:e=!1}={}){if(this.stagedFiles.length===0)return;const s=this.stagedFiles.map(r=>b(this.workTree,r));if(await Jt(s,{cwd:this.workTree}),e){const r=(await Z(this.workTree)).filter(n=>!this.preTaskUntracked.has(n));if(r.length>0){const n=`${r.join("\0")}\0`;await m(["add","--pathspec-from-file=-","--pathspec-file-nul","--"],{cwd:this.workTree,input:n})}}if(this.intentToAddPaths.length>0)try{await m(["add","--intent-to-add","--",...this.intentToAddPaths],{cwd:this.workTree})}catch{}this.postTaskIndexTree=await Q(this.workTree)}indexTreeChanged(){return this.preTaskIndexTree.length>0&&this.postTaskIndexTree.length>0&&this.preTaskIndexTree!==this.postTaskIndexTree}postTaskIndexMatchesHead(){return this.postTaskIndexTree.length>0&&this.headTree.length>0&&this.postTaskIndexTree===this.headTree}async restoreUnstagedChanges(){if(this.revertApplied||this.patch===null||this.shouldHideAll)return;const e=["apply","--whitespace=nowarn","--recount","--unidiff-zero"];let s;try{await m(e,{cwd:this.workTree,input:this.patch});return}catch(r){s=r instanceof R?r.stderr:String(r)}try{await m([...e,"--3way"],{cwd:this.workTree,input:this.patch})}catch(r){const n=r instanceof R&&r.stderr?r.stderr:String(r);throw new K(`Failed to re-apply unstaged changes after running tasks. Original changes remain in the backup stash — recover with \`git stash list\` and \`git stash apply\`.
12
- First attempt: ${s??"(no stderr)"}
13
- Second attempt: ${n}`,{cause:r})}}async revert(){if(this.backupStashSha!==null){try{await te(this.workTree,this.backupStashSha)}catch(e){throw new K("Revert failed while restoring the backup stash. Use `git stash list` to recover manually.",{cause:e})}if(await tt(this.workTree,this.backupStashSha),this.intentToAddPaths.length>0)try{await m(["add","--intent-to-add","--",...this.intentToAddPaths],{cwd:this.workTree})}catch{}this.revertApplied=!0}}async cleanup(e){if(this.restoreMergeState(),this.hideAllStashSha!==null)try{await ee(this.workTree,this.hideAllStashSha)}catch{}e&&this.backupStashSha!==null&&!this.revertApplied&&await tt(this.workTree,this.backupStashSha)}recoveryHint(){return this.backupStashSha===null?null:`Backup stash is preserved (sha ${this.backupStashSha.slice(0,7)}) — restore with: git stash apply --index ${this.backupStashSha}`}async hideUnstagedChanges(){const e=new Set(this.stagedFiles.map(r=>b(this.workTree,r))),s=this.shouldHideUnstaged?[...e]:this.shouldHidePartial?this.partiallyStaged.filter(r=>e.has(r)):[];s.length!==0&&(this.patch=await Wt(s,{cwd:this.workTree}),this.patch!==null&&await Yt(s,{cwd:this.workTree}))}snapshotMergeState(){this.gitDir.length!==0&&(this.merge=["MERGE_HEAD","MERGE_MODE","MERGE_MSG"].map(e=>{const s=O(this.gitDir,e);return B(s)?{body:xt(s),existed:!0,name:e}:{body:null,existed:!1,name:e}}))}restoreMergeState(){if(!(this.gitDir.length===0||this.merge.length===0))for(const e of this.merge){const s=O(this.gitDir,e.name);try{e.existed&&e.body!==null?bt(s,e.body):B(s)&&$t(s)}catch{}}}}const re=t=>{switch(t){case"failed":return"red";case"running":return"cyan";case"skipped":return"yellow";case"success":return"green";default:return"gray"}},et=t=>{if(t==="running")return w.jsx(It,{type:"dots"});const e=t==="failed"?dt:t==="skipped"?_:t==="success"?lt:_;return w.jsx(x,{color:re(t),children:e})},st=({state:t,tick:e,verbose:s})=>w.jsxs(C,{flexDirection:"column",children:[[...t.patterns.values()].map(r=>w.jsxs(C,{flexDirection:"column",children:[w.jsxs(C,{children:[et(r.status),w.jsxs(x,{children:[" ",r.title]})]}),[...r.commands.values()].map(n=>w.jsxs(C,{flexDirection:"column",marginLeft:2,children:[w.jsxs(C,{children:[et(n.status),w.jsxs(x,{children:[" ",n.title," "]}),n.status!=="pending"&&n.status!=="running"?w.jsxs(x,{color:"gray",children:["(",n.durationMs,"ms)"]}):null]}),s&&n.output?w.jsx(C,{flexDirection:"column",marginLeft:2,children:n.output.split(/\r?\n/).slice(0,20).map((a,c)=>w.jsx(x,{color:"gray",children:a},`${n.id}-line-${c}`))}):null,n.status==="failed"&&n.error?w.jsx(C,{marginLeft:2,children:w.jsx(x,{color:"red",children:n.error.message})}):null]},n.id))]},r.id)),t.infoMessages.map((r,n)=>w.jsx(x,{color:"gray",children:r},`info-${n}`)),t.warnMessages.map((r,n)=>w.jsx(x,{color:"yellow",children:r},`warn-${n}`)),t.errorMessages.map(({message:r},n)=>w.jsx(x,{color:"red",children:r},`err-${n}`))]}),ne=(t={})=>{const e=t.verbose===!0,s={errorMessages:[],infoMessages:[],patterns:new Map,started:!1,warnMessages:[]};let r=0;const n=vt(w.jsx(st,{state:s,tick:r,verbose:e}),{exitOnCtrlC:!1,stdout:process.stderr}),a=()=>{r+=1,n.rerender(w.jsx(st,{state:s,tick:r,verbose:e}))};return{commandEnd({commandId:c,durationMs:i,error:o,output:l,patternId:h,status:d}){const u=s.patterns.get(h)?.commands.get(c);u&&(u.status=d,u.durationMs=i,u.output=l,u.error=o,a())},commandStart({commandId:c,patternId:i}){const o=s.patterns.get(i)?.commands.get(c);o&&(o.status="running",a())},error({error:c,message:i}){s.errorMessages.push({error:c,message:i}),a()},info({message:c}){s.infoMessages.push(c),a()},patternEnd({patternId:c,status:i}){const o=s.patterns.get(c);o&&(o.status=i,a())},patternStart({patternId:c}){const i=s.patterns.get(c);i&&(i.status="running",a())},start({patterns:c}){s.started=!0;for(const i of c){const o=new Map;for(const l of i.commands)o.set(l.id,{durationMs:0,id:l.id,status:"pending",title:l.title});s.patterns.set(i.id,{commands:o,id:i.id,status:"pending",title:i.title})}a()},async stop(){n.unmount(),await n.waitUntilExit()},warn({message:c}){s.warnMessages.push(c),a()}}},rt=(t={})=>{const{quiet:e=!1,verbose:s=!1}=t,r=new Map,n=new Map,a=i=>{e||process.stderr.write(`${i}
14
- `)},c=i=>{switch(i){case"failed":return G(dt);case"running":return P(">");case"skipped":return V(_);case"success":return Et(lt);default:return $(_)}};return{commandEnd({commandId:i,durationMs:o,error:l,output:h,status:d}){const u=n.get(i)??i,p=$(`(${o}ms)`);if(a(` ${c(d)} ${u} ${p}`),d==="failed"&&l&&a($(l.message)),(d==="failed"||s)&&h&&h.trim().length>0)for(const f of h.split(/\r?\n/))a(` ${$(f)}`)},commandStart({commandId:i}){if(!s)return;const o=n.get(i)??i;a(` ${$("…")} ${o}`)},error({error:i,message:o}){e?process.stderr.write(`${G(o)}
15
- `):a(G(o)),i?.stack&&(s||!e)&&process.stderr.write(`${$(i.stack)}
16
- `)},info({message:i}){a($(i))},patternEnd({patternId:i,status:o}){const l=r.get(i)??i;a(`${c(o)} ${l}`)},patternStart({patternId:i}){const o=r.get(i)??i;a(`${P(">")} ${o}`)},start({patterns:i}){if(i.length===0){a($("No staged files matched any pattern."));return}const o=new Set(i.flatMap(l=>l.files)).size;a(`${P(">")} Running staged tasks on ${o} file${o===1?"":"s"} across ${i.length} pattern${i.length===1?"":"s"}`);for(const l of i){r.set(l.id,l.title);for(const h of l.commands)n.set(h.id,h.title)}},stop(){},warn({message:i}){a(V(i))}}},ie=async t=>{const{env:e}=process;if(t.debug===!0||t.quiet===!0||e.NODE_ENV==="test"||e.TERM==="dumb"||e.CI!==void 0||!process.stderr.isTTY)return rt({quiet:t.quiet,verbose:t.verbose});try{return ne({verbose:t.verbose})}catch{return rt({quiet:t.quiet,verbose:t.verbose})}},ae=t=>{const e=[];let s="",r=!1,n=!1;for(let a=0;a<t.length;a+=1){const c=t[a];if(c===void 0)break;if(c==="\\"&&!r&&a+1<t.length){const i=t[a+1];if(i!==void 0){n&&i!=='"'&&i!=="\\"&&(s+=c),s+=i,a+=1;continue}}if(c==='"'&&!r){n=!n;continue}if(c==="'"&&!n){r=!r;continue}if(!r&&!n&&/\s/.test(c)){s.length>0&&(e.push(s),s="");continue}s+=c}if(r||n)throw new v(`Unterminated ${r?"single":"double"} quote in command: ${t}`);return s.length>0&&e.push(s),e},gt=process.platform==="win32"?28e3:131072,oe=(t,e,s)=>{const r=[];let n=[],a=e;const c=s<=0?gt:s;for(const i of t){const o=Buffer.byteLength(i)+1;n.length>0&&a+o>c&&(r.push(n),n=[],a=e),n.push(i),a+=o}return n.length>0&&r.push(n),r},ce=async(t,e,s)=>{const r=ae(t);if(r.length===0)throw new I(t,"Empty command for staged task.");const[n,...a]=r;if(n===void 0)throw new I(t,"Empty command for staged task.");const c=Buffer.byteLength(n)+a.reduce((h,d)=>h+Buffer.byteLength(d)+1,0),i=oe(e,c,s.maxArgLength??gt),o=Date.now(),l=[];for(const h of i){if(s.signal?.aborted===!0)throw new I(t,"Task aborted by earlier failure.");const d=ct(n,[...a,...h],{nodeOptions:{cwd:s.cwd,env:de(s.env,s.cwd),killSignal:s.killSignal??"SIGTERM",stdio:["ignore","pipe","pipe"]},...s.signal===void 0?{}:{signal:s.signal}}),u=await d,p=[u.stdout,u.stderr].filter(g=>g.length>0).join(`
17
- `);p.length>0&&l.push(p);const f=d.process?.signalCode??null;if(d.aborted||f!==null||u.exitCode===void 0){const g=d.aborted?"Task aborted by earlier failure.":f===null?p.trim()||"Task exited without a numeric status code.":`Task killed by signal ${f}.`;throw new I(t,g)}if(u.exitCode!==0)throw new I(t,p.trim()||`Exit code ${u.exitCode} from ${n}`)}return{durationMs:Date.now()-o,output:l.join(`
18
- `)}},de=(t,e)=>{const s={...process.env};process.stderr.isTTY&&s.FORCE_COLOR===void 0&&s.NO_COLOR===void 0&&(s.FORCE_COLOR="1");const r=t?{...s,...t}:s;return Mt(r,e)},le=async(t,e,s)=>{const r=he(s.concurrent,t.length),n=[],a=new AbortController;let c=!1,i=0;const o=()=>{c||(c=!0,s.continueOnError||a.abort())};s.externalSignal&&(s.externalSignal.aborted?o():s.externalSignal.addEventListener("abort",()=>{o()},{once:!0}));const l=f=>{for(const g of f.commands)e.commandEnd({commandId:g.id,durationMs:0,patternId:f.id,status:"skipped"})},h=async f=>{if(c){l(f),e.patternEnd({patternId:f.id,status:"skipped"});return}e.patternStart({patternId:f.id});let g="success";for(const y of f.commands){if(c){e.commandEnd({commandId:y.id,durationMs:0,patternId:f.id,status:"skipped"}),g=g==="success"?"skipped":g;continue}e.commandStart({commandId:y.id,patternId:f.id});const T=await ue(y,s,a.signal),S=T.status==="failed"&&a.signal.aborted?{...T,status:"skipped"}:T;if(e.commandEnd({commandId:y.id,durationMs:S.durationMs,error:S.error,output:S.output,patternId:f.id,status:S.status}),S.status==="failed"){n.push(y.title),g="failed",o();break}if(S.status==="skipped"){g=g==="success"?"skipped":g;break}}e.patternEnd({patternId:f.id,status:g})},d=async()=>{for(;i<t.length;){const f=t[i];i+=1,f&&await h(f)}},u=[];for(let f=0;f<Math.min(r,t.length);f+=1)u.push(d());await Promise.all(u);const p=s.externalSignal?.aborted===!0;return{failedCommands:n,success:n.length===0&&!p}},ue=async(t,e,s)=>{const r=Date.now();try{if(t.source==="custom"&&t.run)return await t.run([...t.files]),{durationMs:Date.now()-r,status:"success"};if(t.command){const n=await ce(t.command,t.files,{cwd:t.cwd??e.cwd,killSignal:e.killSignal,maxArgLength:e.maxArgLength,signal:s});return{durationMs:n.durationMs,output:e.verbose?n.output:void 0,status:"success"}}return{durationMs:Date.now()-r,error:new I(t.title,"Command has no invocation target."),status:"failed"}}catch(n){const a=n instanceof Error?n:new Error(String(n));return{durationMs:Date.now()-r,error:a,output:a instanceof I?a.message:void 0,status:"failed"}}},he=(t,e)=>{if(t===!1)return 1;if(t===!0){const r=Math.max(1,typeof z=="function"?z():4);return Math.min(Math.max(1,e),r)}const s=Math.floor(t);return s>0?s:1},fe=!0,pe=t=>{try{return!kt(t)}catch{return!1}},ge=t=>{try{const e=Tt(t);return e?St(t,e).map(s=>O(t,s)):[]}catch{return[]}},me=async(t={})=>{const e=t.cwd??process.cwd(),s=await ie(t),r=await Dt(t);typeof r!="function"&&Y(r);const n=new se({...t,cwd:e}),a=new AbortController;let c=!1;const i=d=>{if(c){process.removeListener("SIGINT",i),process.removeListener("SIGTERM",i),process.kill(process.pid,d);return}c=!0,s.warn({message:`Received ${d} — cancelling staged tasks and restoring state. Press Ctrl+C again to abort.`}),a.abort()};process.on("SIGINT",i),process.on("SIGTERM",i);let o={failedCommands:[],ranTasks:!1,success:!0},l=!1,h=!1;try{await n.prepare(),l=!0;for(const T of n.warnings)s.warn({message:T});if(n.stagedFiles.length===0)return t.allowEmpty!==!0&&s.info({message:"No staged files found."}),h=!0,{failedCommands:[],ranTasks:!1,success:!0};const d=pe(e),u=Rt(n.stagedFiles,t.ignore,e,{caseInsensitive:d});if(u.length===0&&n.stagedFiles.length>0)return s.info({message:"Every staged file was excluded by the `ignore` list."}),h=!0,{failedCommands:[],ranTasks:!1,success:!0};const p=typeof r=="function"?Y(await r([...u])):r,f=await _t({caseInsensitive:d,config:p,cwd:e,files:u,relative:t.relative,workspacePackages:ge(e)});if(s.start({patterns:f}),f.length===0)return s.info({message:"No staged files matched any pattern."}),h=!0,{failedCommands:[],ranTasks:!1,success:!0};const{failedCommands:g,success:y}=await le(f,s,{concurrent:t.concurrent??fe,continueOnError:t.continueOnError===!0,cwd:e,externalSignal:a.signal,killSignal:t.killSignal,maxArgLength:t.maxArgLength,verbose:t.verbose});if(o={failedCommands:g,ranTasks:!0,success:y},y){if(t.diff===void 0&&(await n.applyModifications({autoStage:t.autoStage===!0}),t.failOnChanges===!0&&n.indexTreeChanged()&&(s.warn({message:"Tasks modified staged content — failing because --fail-on-changes is set."}),o={failedCommands:[...g],ranTasks:!0,success:!1}),t.allowEmpty!==!0&&n.postTaskIndexMatchesHead()))throw new At("All staged changes were reverted by tasks. Re-stage changes or rerun with --allow-empty.")}else if(t.revert===!0)s.info({message:"Reverting working tree from backup stash."}),await n.revert();else{const T=n.recoveryHint();T&&s.warn({message:T})}return await n.restoreUnstagedChanges(),h=o.success,o}catch(d){const u=d instanceof Error?d.message:String(d),p=d instanceof Error?d:new Error(u);if(s.error({error:p,message:u}),d instanceof E)return{failedCommands:o.failedCommands,ranTasks:o.ranTasks,success:!1};throw d}finally{if(process.removeListener("SIGINT",i),process.removeListener("SIGTERM",i),l)try{await n.cleanup(h)}catch(d){s.error({error:d,message:"Cleanup failed."})}await s.stop()}},we="VIS_STAGED_CONCURRENT",nt=t=>{const e=t.trim();if(e==="true"||e==="")return!0;if(e==="false")return!1;const s=Number(e);return Number.isNaN(s)?!0:s},ye=(t,e)=>{const s={};e!==void 0&&(s.config=e);const r=k=>t[k]===void 0?void 0:!!t[k],n=k=>{const F=t[k];return typeof F=="string"&&F.length>0?F:void 0},a=r("allow-empty");a!==void 0&&(s.allowEmpty=a);const c=r("auto-stage");c!==void 0&&(s.autoStage=c);const i=r("continue-on-error");i!==void 0&&(s.continueOnError=i);const o=r("debug");o!==void 0&&(s.debug=o);const l=r("fail-on-changes");l!==void 0&&(s.failOnChanges=l);const h=r("hide-partially-staged");h!==void 0&&(s.hidePartiallyStaged=h);const d=r("hide-unstaged");d!==void 0&&(s.hideUnstaged=d);const u=r("quiet");u!==void 0&&(s.quiet=u);const p=r("relative");p!==void 0&&(s.relative=p);const f=r("revert");f!==void 0&&(s.revert=f);const g=r("stash");g!==void 0&&(s.stash=g);const y=r("verbose");y!==void 0&&(s.verbose=y);const T=n("cwd");T!==void 0&&(s.cwd=T);const S=n("diff");S!==void 0&&(s.diff=S);const U=n("diff-filter");if(U!==void 0&&(s.diffFilter=U),r("force-kill")===!0&&(s.killSignal="SIGKILL"),t.concurrent===void 0){const k=process.env[we];k!==void 0&&(s.concurrent=nt(k.trim()))}else{const{concurrent:k}=t;s.concurrent=nt(typeof k=="string"?k:typeof k=="number"||typeof k=="boolean"?String(k):"")}return s},Ae=async({options:t,visConfig:e})=>{const s=(e??{}).staged;if(!s)throw new Error(`No "staged" config found in vis.config.ts. Add one:
19
-
20
- // vis.config.ts
21
- import { defineConfig } from "@visulima/vis/config";
22
-
23
- export default defineConfig({
24
- staged: { '*': 'vis check --fix' },
25
- });
26
-
27
- Migrating from lint-staged or nano-staged? Run \`vis migrate lint-staged\` (or \`vis migrate nano-staged\`) to move the config in and remove the legacy files.`);(await me(ye(t,s))).success||(process.exitCode=1)};export{ye as buildRunOptions,Ae as default};
1
+ import{createRequire as ht}from"node:module";import{I as ze,s as I,E as q,q as Ge,V as G,j as yt}from"../packem_shared/index.server-J83sowC4.js";import{m as _,f as O,v as K,I as Y,A as kt,T as wt}from"../packem_shared/index-CE6MsgcV.js";import{u as Ee,m as vt}from"./ts-loader.js";import{E as bt}from"../packem_shared/public-api-WqUCiyIe.js";import{P as Rt,ak as xt,i as ge}from"./cli-main.js";import{_ as At,w as St,x as Et,g as Ct,R as Tt,c as jt,V as It,y as Nt,z as Ke,$ as Ce,d as P,h as me,i as L,H as Je,A as Dt,F as W,Z as Ut,L as Vt,j as Ot,G as Bt}from"./catalog.js";import{B as _t}from"../packem_shared/env-DJlbJiFh.js";import{I as le}from"../packem_shared/index-B0EsgdzO.js";import{K as qt,Z as Wt,W as Te}from"../packem_shared/ai-analysis-DF_AfeS3.js";import{v as Ht,h as Lt,s as Ye}from"../packem_shared/pm-runner-CQcraCcu.js";import{a as Ft,r as zt}from"../packem_shared/command-runtime-3FTGuUsK.js";import{r as Gt,a as Kt,p as Jt}from"../packem_shared/resolve-explicit-UtkNrGKq.js";import{S as Yt}from"../packem_shared/min-release-age-C71MO72F.js";import{r as Zt,s as Xt}from"../packem_shared/typosquats-C12CP_2G.js";import{U as Qt,b as en,u as je,e as tn}from"../packem_shared/vis-update-app-BoCQ4ute.js";import{h as Ze,P as Xe}from"../packem_shared/peer-warnings-BXAzXqY3.js";import{f as Qe}from"../packem_shared/utils-CRueU43T.js";import{s as te}from"../packem_shared/index-Cg0IHaFI.js";import{r as nn,q as sn}from"../packem_shared/advisories-B76fBVL-.js";const $t=ht(import.meta.url),Q=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Le=e=>{if(typeof Q<"u"&&Q.versions&&Q.versions.node){const[n,t]=Q.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return Q.getBuiltinModule(e)}return $t(e)},{createInterface:Fe}=Le("node:readline"),{existsSync:Mt,realpathSync:Pt}=Le("node:fs"),on=e=>{const n=[];for(const t of e.filters)n.push("--filter",t);return e.workspaceRoot&&n.push("--filter","."),n.push("update"),e.latest&&n.push("--latest"),e.recursive&&n.push("--recursive"),e.interactive&&n.push("--interactive"),e.dev&&n.push("--dev"),e.prod&&n.push("--prod"),e.noOptional&&n.push("--no-optional"),e.noSave&&n.push("--no-save"),n.push(...e.packages),{args:n,bin:"pnpm"}},rn=e=>{const n=[];return e.filters.length>0&&n.push("workspace",e.filters[0]),n.push("upgrade"),e.latest&&n.push("--latest"),n.push(...e.packages),{args:n,bin:"yarn"}},an=e=>{const n=[];if(e.filters.length>0||e.recursive){n.push("workspaces","foreach","--all");for(const t of e.filters)n.push("--include",t)}return n.push("up"),e.interactive&&n.push("--interactive"),n.push(...e.packages),{args:n,bin:"yarn"}},cn=(e,n)=>{const t=["update"];e.latest&&n.push("npm does not support --latest flag. Packages will be updated within their semver range."),e.interactive&&n.push("npm does not support --interactive mode.");for(const s of e.filters)t.push("--workspace",s);return e.recursive&&t.push("--workspaces"),e.workspaceRoot&&t.push("--include-workspace-root"),e.dev&&t.push("--dev"),e.prod&&t.push("--production"),e.noOptional&&t.push("--no-optional"),e.noSave&&t.push("--no-save"),t.push(...e.packages),{args:t,bin:"npm"}},ln=e=>{const n=["update"];e.latest&&n.push("--latest");for(const t of e.filters)n.push("--filter",t);return n.push(...e.packages),{args:n,bin:"bun"}},un=(e,n)=>{const t=["outdated","--update"];return e.latest&&t.push("--latest"),e.interactive&&t.push("--interactive"),e.filters.length>0&&n.push("deno outdated has no --filter flag; ignoring."),(e.dev||e.prod)&&n.push("deno outdated has no --dev / --prod flags; dev/prod is governed by deno.json."),e.noOptional&&n.push("deno outdated has no --no-optional flag; ignoring."),e.noSave&&n.push("deno outdated has no --no-save flag; ignoring."),t.push(...e.packages),{args:t,bin:"deno"}},dn=(e,n,t)=>{const s=[];if(t.global&&e!=="aube"&&e!=="deno")return{command:{args:["update","--global",...t.packages],bin:"npm"},warnings:s};let r;switch(e){case"aube":{const o=Ht(t);r={args:o.args,bin:o.bin},s.push(...o.warnings);break}case"bun":{r=ln(t);break}case"deno":{r=un(t,s);break}case"npm":{r=cn(t,s);break}case"pnpm":{r=on(t);break}case"yarn":{r=n.startsWith("1.")?rn(t):an(t);break}default:{const o=e;throw new Error(`Unsupported package manager: ${String(o)}`)}}return{command:r,warnings:s}},et=e=>{const n=e.indexOf("@");return n<=0?e:e.slice(0,n)},pn=e=>{switch(e){case"docker":case"docker-compose":return"docker";case"github-actions":return"actions";case"gitlab-ci":return"gitlab";default:return}},fn=(e,n)=>{const t=[".github/dependabot.yml",".github/dependabot.yaml"];for(const s of t){const r=_(e,s);if(!O(r))continue;let o;try{o=bt(K(r))}catch{continue}if(o?.updates){for(const i of o.updates){const a=pn(i["package-ecosystem"]);if(!(!a||!Array.isArray(i.ignore)))for(const d of i.ignore){const c=d["dependency-name"];typeof c=="string"&&c.length>0&&n[a].add(et(c))}}return}}},gn=Object.freeze({"docker-compose":"docker",dockerfile:"docker","github-actions":"actions",gitlabci:"gitlab","gitlabci-include":"gitlab"}),mn=Object.freeze({docker:"docker","github-tags":"actions"}),he=(e,n)=>{if(n)for(const t of n)typeof t=="string"&&t.length>0&&e.add(et(t))},hn=e=>{let n="",t=0;const{length:s}=e;let r=!1,o="";for(;t<s;){const i=e[t]??"";if(r){if(n+=i,i==="\\"&&t+1<s){n+=e[t+1]??"",t+=2;continue}i===o&&(r=!1),t+=1;continue}if(i==='"'||i==="'"){r=!0,o=i,n+=i,t+=1;continue}if(i==="/"&&e[t+1]==="/"){for(;t<s&&e[t]!==`
2
+ `;)t+=1;continue}if(i==="/"&&e[t+1]==="*"){for(t+=2;t<s&&!(e[t]==="*"&&e[t+1]==="/");)t+=1;t+=2;continue}if(i===","){let a=t+1;for(;a<s&&/\s/.test(e[a]??"");)a+=1;const d=e[a];if(d==="}"||d==="]"){t+=1;continue}}n+=i,t+=1}return n},$n=(e,n)=>{const t=["renovate.json","renovate.json5",".renovaterc",".renovaterc.json"];for(const s of t){const r=_(e,s);if(!O(r))continue;let o;try{const a=K(r);o=JSON.parse(hn(a))}catch{continue}if(!o)continue;if(Array.isArray(o.ignoreDeps))for(const a of["actions","docker","gitlab"])he(n[a],o.ignoreDeps);const i=[["github-actions","actions"],["dockerfile","docker"],["docker-compose","docker"],["gitlabci","gitlab"],["gitlabci-include","gitlab"]];for(const[a,d]of i){const c=o[a];he(n[d],c?.ignoreDeps)}if(!Array.isArray(o.packageRules))return;for(const a of o.packageRules){if(a.enabled!==!1)continue;const d=new Set;for(const u of a.matchManagers??[]){const f=gn[u];f&&d.add(f)}for(const u of a.matchDatasources??[]){const f=mn[u];f&&d.add(f)}d.size===0&&(d.add("actions"),d.add("docker"),d.add("gitlab"));const c=[...a.matchPackageNames??[],...a.matchDepNames??[],...a.matchPackagePatterns??[]];for(const u of d)he(n[u],c)}return}},yn=e=>{const n={actions:new Set,docker:new Set,gitlab:new Set};return fn(e,n),$n(e,n),n},ke=(e,n,t)=>{const s=t[n];if(s.size===0)return!1;if(s.has(e))return!0;for(const r of s)if(/[*?[\]/.+]/.test(r))try{const o=r.replaceAll(/[.+^${}()|]/g,String.raw`\$&`).replaceAll("*",".*").replaceAll("?",".");if(new RegExp(`^${o}$`).test(e))return!0}catch{}return!1},F=e=>{const n=e.trim();if(n==="")return;const t=n.startsWith("v")||n.startsWith("V")?n.slice(1):n,s=(te.valid(t)?te.parse(t):void 0)??te.coerce(t,{includePrerelease:!0});if(s)return{major:s.major,minor:s.minor,normalized:`${String(s.major)}.${String(s.minor)}.${String(s.patch)}${s.prerelease.length>0?`-${s.prerelease.join(".")}`:""}`,patch:s.patch,prerelease:s.prerelease.length>0,raw:n}},kn=(e,n)=>te.rcompare(e.normalized,n.normalized),we=(e,n,t,s)=>{if(!n&&t!=="latest")return;const r=e.filter(o=>o.prerelease?!1:n?t==="patch"&&(o.major!==n.major||o.minor!==n.minor)||t==="minor"&&o.major!==n.major?!1:te.gt(o.normalized,n.normalized):!0);if(r.length!==0)return r.toSorted(kn)[0]},ve=(e,n)=>!e||!n?"unknown":n.major!==e.major?"major":n.minor!==e.minor?"minor":n.patch!==e.patch?"patch":"unknown",wn="GitHub Actions",Ie=(e,n)=>`${e}@${n}`,vn=e=>({fixedVersions:e.fixedVersions,id:e.id,severity:e.severity,summary:e.summary}),bn=(e,n)=>{if(n.length===0)return n;const t=nn(e);if(!Mt(t))return n;const s=new Map;for(const o of n){const i=o.currentVersion??o.currentRef;i&&s.set(Ie(o.name,i),{name:o.name,version:i})}if(s.size===0)return n;const r=new Map;try{for(const[o,i]of s){const a=sn([i],{ecosystem:wn,workspaceRoot:e}).get(i.name);a&&a.length>0&&r.set(o,a)}}catch{return n}return r.size===0?n:n.map(o=>{const i=o.currentVersion??o.currentRef;if(!i)return o;const a=r.get(Ie(o.name,i));return a?{...o,advisories:a.map(d=>vn(d))}:o})},tt=e=>{if(!e)return{};const n={};for(const t of e.split(",")){const s=/^\s*<([^>]+)>\s*;\s*(.+)$/.exec(t);if(!s)continue;const r=s[1]??"",o=s[2]??"";switch(/rel\s*=\s*"?([^";\s]+)"?/i.exec(o)?.[1]?.toLowerCase()){case"first":{n.first=r;break}case"last":{n.last=r;break}case"next":{n.next=r;break}case"prev":case"previous":{n.previous=r;break}}}return n};class Rn{token;apiBase;fetchImpl;tagsCache=new Map;commitCache=new Map;constructor(n){this.token=n.token??process.env.GITHUB_TOKEN??process.env.GH_TOKEN,this.apiBase=n.apiBase??"https://api.github.com",this.fetchImpl=n.fetch??fetch}async listTags(n,t){const s=`${n}/${t}`,r=this.tagsCache.get(s);if(r)return r;const o=this.fetchTags(n,t);return this.tagsCache.set(s,o),o}async resolveRef(n,t,s){const r=`${n}/${t}@${s}`,o=this.commitCache.get(r);if(o)return o;const i=this.fetchCommit(n,t,s);return this.commitCache.set(r,i),i}buildHeaders(){const n={Accept:"application/vnd.github+json","User-Agent":"vis-update-actions","X-GitHub-Api-Version":"2022-11-28"};return this.token&&(n.Authorization=`Bearer ${this.token}`),n}async fetchTags(n,t){const s=`${this.apiBase}/repos/${encodeURIComponent(n)}/${encodeURIComponent(t)}/tags?per_page=100`,r={parsed:[],tags:[]},o=[];let i=s,a=0;for(;i&&a<5;){const c=i;let u;try{u=await this.fetchImpl(c,{headers:this.buildHeaders()})}catch{return r}if(!u.ok)return r;let f;try{f=await u.json()}catch{return r}if(!Array.isArray(f))return r;for(const g of f){const m=typeof g.name=="string"?g.name:"",h=typeof g.commit?.sha=="string"?g.commit.sha:"";m!==""&&h!==""&&o.push({name:m,sha:h})}i=tt(u.headers.get("link")).next,a+=1}const d=[];for(const c of o){const u=F(c.name);u&&d.push({...u,sha:c.sha})}return{parsed:d,tags:o}}async fetchCommit(n,t,s){const r=`${this.apiBase}/repos/${encodeURIComponent(n)}/${encodeURIComponent(t)}/commits/${encodeURIComponent(s)}`;try{const o=await this.fetchImpl(r,{headers:this.buildHeaders()});if(!o.ok)return;const i=await o.json();return typeof i.sha!="string"?void 0:{committedAt:i.commit?.committer?.date,sha:i.sha}}catch{return}}}const xn=".github/workflows",An=".github/actions",Sn=/^\s*-?\s*uses:\s*(['"]?)([^'"\s#]+)\1(?:\s*#\s*(.+))?\s*$/,En=/^[a-f0-9]{40}$/i,Cn=/actions-up-ignore-next-line(?::\s*(.+))?/i,Tn=/actions-up-ignore-start/i,jn=/actions-up-ignore-end/i,In=e=>{const n=e.split("/");if(n.length<2)return;const[t,s,...r]=n;if(!(!t||!s))return{owner:t,repo:s,subpath:r.length>0?r.join("/"):void 0}},Nn=(e,n)=>{const t=n.split(/\r?\n/),s=[];let r,o=!1;for(const[i,a]of t.entries()){const d=a??"";if(Tn.test(d)&&(o=!0),jn.test(d)){o=!1;continue}const c=d.trim(),u=c===""||c.startsWith("#")?Cn.exec(d):void 0;if(u){r=u[1]??"actions-up-ignore-next-line";continue}const f=Sn.exec(d);if(!f){r=void 0;continue}const g=f[1]??"",m=g==="'"||g==='"'?g:"",h=f[2]??"",R=f[3]?.trim();if(h.startsWith("./")||h.startsWith("../")||h.startsWith("docker://")){r=void 0;continue}const A=h.lastIndexOf("@");if(A<=0){r=void 0;continue}const $=h.slice(0,A),S=h.slice(A+1),y=In($);if(!y){r=void 0;continue}let p=r??(o?"actions-up-ignore-block":void 0);if(R){const k=/^actions-up-ignore(?:-next-line)?(?::\s*(.+))?(?:\s|$)/i.exec(R);k&&(p=p??k[1]??"actions-up-ignore")}r=void 0,s.push({file:e,ignoreReason:p,isSha:En.test(S),line:i+1,original:`${m}${h}${m}`,owner:y.owner,quote:m,ref:S,repo:y.repo,slug:$,subpath:y.subpath,trailingComment:R&&!p?R:void 0})}return s},Ne=e=>e.endsWith(".yml")||e.endsWith(".yaml"),Dn=(e,n=[])=>{const t=[],s=new Set,r=a=>{if(s.has(a))return;s.add(a);let d;try{d=K(a)}catch{return}const c=Nn(a,d);t.push(...c)},o=_(e,xn);if(O(o))for(const a of Y(o,{includeDirs:!1,includeSymlinks:!1,maxDepth:1}))Ne(a.name)&&r(a.path);const i=_(e,An);if(O(i))for(const a of Y(i,{includeDirs:!1,includeSymlinks:!1,maxDepth:3}))(a.name==="action.yml"||a.name==="action.yaml")&&r(a.path);for(const a of["action.yml","action.yaml"]){const d=_(e,a);O(d)&&r(d)}for(const a of n){const d=kt(a)?a:_(e,a);if(O(d))for(const c of Y(d,{includeDirs:!1,includeSymlinks:!1}))Ne(c.name)&&r(c.path)}return t},Un=40,Vn=1440*60*1e3,On=new Set(["develop","edge","main","master","stable","trunk"]),Bn=e=>e.length===Un&&/^[a-f0-9]{40}$/i.test(e)?!1:On.has(e.toLowerCase())?!0:F(e)===void 0,De=(e,n)=>{for(const t of n)try{if(new RegExp(t).test(e))return!0}catch{if(e.includes(t))return!0}return!1},_n=(e,n,t,s)=>{const r=s==="sha"||e.isSha,{quote:o}=e;return r?`${o}${e.slug}@${n}${o} # ${t}`:`${o}${e.slug}@${t}${o}`},Mn=async(e,n)=>{const{ignoreRules:t,options:s,references:r,resolverOptions:o}=n,i=[],a=[],d=[];if(r.length===0)return{failed:d,ignored:a,updates:i};const c=new Rn({apiBase:o?.apiBase,fetch:o?.fetch,token:s.githubToken??o?.token}),u=new Map;for(const $ of r){const S=`${$.owner}/${$.repo}`,y=u.get(S)??[];y.push($),u.set(S,y)}const f=Math.max(1,s.maxConcurrentRequests),g=[...u.keys()];let m=0;const h=async $=>{const S=u.get($)??[],[y,p]=$.split("/");if(!y||!p)return;let k;try{k=await c.listTags(y,p)}catch{for(const l of S)d.push({file:l.file,reason:`failed to list tags for ${$}`});return}for(const l of S){const E=l.slug;let w;if(l.ignoreReason?w=l.ignoreReason:De(E,s.exclude)?w="matched --exclude":s.include.length>0&&!De(E,s.include)?w="not matched by --include":s.respectDependabotConfig&&t&&ke(E,"actions",t)&&(w="ignored by dependabot/renovate config"),w){a.push({currentRef:l.ref,currentVersion:l.isSha?l.trailingComment?.replace(/^#\s*/,""):l.ref,ecosystem:"actions",file:l.file,ignored:!0,line:l.line,name:E,newRef:l.ref,newVersion:void 0,original:l.original,reason:w,replacement:l.original,updateType:"unknown"});continue}if(!s.includeBranches&&!l.isSha&&Bn(l.ref)){a.push({currentRef:l.ref,currentVersion:l.ref,ecosystem:"actions",file:l.file,ignored:!0,line:l.line,name:E,newRef:l.ref,newVersion:void 0,original:l.original,reason:"branch reference (use --include-branches)",replacement:l.original,updateType:"unknown"});continue}const C=l.isSha?l.trailingComment?.replace(/^#\s*/,"").split(/\s+/)[0]??"":l.ref,T=F(C);if(l.isSha&&!T&&s.mode!=="latest"){a.push({currentRef:l.ref,currentVersion:void 0,ecosystem:"actions",file:l.file,ignored:!0,line:l.line,name:E,newRef:l.ref,newVersion:void 0,original:l.original,reason:`SHA pin has no version-hint comment; cannot apply --target=${s.mode}`,replacement:l.original,updateType:"unknown"});continue}const x=we(k.parsed,T,s.mode);if(!x)continue;if(s.minAgeDays!==void 0){const M=await c.resolveRef(y,p,x.sha),D=M?.committedAt?new Date(M.committedAt).getTime():void 0;if(D&&(Date.now()-D)/Vn<s.minAgeDays){a.push({currentRef:l.ref,currentVersion:T?.raw,ecosystem:"actions",file:l.file,ignored:!0,line:l.line,name:E,newRef:l.ref,newVersion:x.raw,original:l.original,reason:`release younger than ${String(s.minAgeDays)} days`,replacement:l.original,updateType:"unknown"});continue}}const j=s.style==="sha"||l.isSha?x.sha:x.raw,N=_n(l,x.sha,x.raw,s.style);i.push({currentRef:l.ref,currentVersion:T?.raw??l.trailingComment?.replace(/^#\s*/,""),ecosystem:"actions",file:l.file,line:l.line,name:E,newRef:j,newVersion:x.raw,original:l.original,replacement:N,updateType:ve(T,x),url:`https://github.com/${y}/${p}/releases/tag/${x.raw}`})}},R=[];for(let $=0;$<Math.min(f,g.length);$++)R.push((async()=>{for(;m<g.length;){const S=g[m];m+=1,S!==void 0&&await h(S)}})());await Promise.all(R);const A=bn(e,i);return{failed:d,ignored:a,updates:A}},Pn=e=>e.toSorted((n,t)=>n.file!==t.file?n.file<t.file?-1:1:n.line-t.line),nt=e=>{const n=[],t=[];if(e.length===0)return{applied:n,skipped:t};const s=Pn(e),r=new Map;for(const o of s){const i=r.get(o.file)??[];i.push(o),r.set(o.file,i)}for(const[o,i]of r){let a;try{a=K(o)}catch(g){for(const m of i)t.push({reason:`read failed: ${g.message}`,update:m});continue}const d=a.includes(`\r
3
+ `)?`\r
4
+ `:`
5
+ `,c=a.split(/\r?\n/),u=[];for(const g of i){const m=g.line-1,h=c[m];if(h===void 0){t.push({reason:`line ${String(g.line)} out of range`,update:g});continue}const R=h.indexOf(g.original);if(R===-1){t.push({reason:"original token not found on expected line",update:g});continue}const A=h.slice(0,R),$=h.slice(R+g.original.length),S=/#\s*v?\d/.test(g.replacement)&&/^\s*#\s*v?\d[\w.+-]*\s*$/i.test($)?"":$;c[m]=`${A}${g.replacement}${S}`,u.push(g)}if(u.length===0)continue;const f=c.join(d);try{wt(o,f),n.push(...u)}catch(g){for(const m of u)t.push({reason:`write failed: ${g.message}`,update:m})}}return{applied:n,skipped:t}};class qn{tokens;fetchImpl;tagCache=new Map;constructor(n={}){this.tokens=n.tokens??{},this.fetchImpl=n.fetch??fetch}async listTags(n,t,s){const r=`${n}/${t}/${s}`,o=this.tagCache.get(r);if(o)return o;const i=n==="docker.io"?this.listDockerHubTags(t,s):this.listV2Tags(n,t,s);return this.tagCache.set(r,i),i}async listDockerHubTags(n,t){const s={parsed:[],raw:[]},r=[],o=new Map;let i=`https://hub.docker.com/v2/repositories/${encodeURIComponent(n)}/${encodeURIComponent(t)}/tags?page_size=100`,a=0;for(;i&&a<5;){try{const d=await this.fetchImpl(i,{headers:{Accept:"application/json"}});if(!d.ok)break;const c=await d.json();if(Array.isArray(c.results)){for(const u of c.results)if(typeof u.name=="string"&&(r.push(u.name),typeof u.last_updated=="string")){const f=Date.parse(u.last_updated);Number.isNaN(f)||o.set(u.name,f)}}i=typeof c.next=="string"?c.next:void 0}catch{break}a+=1}return r.length===0?s:{parsed:r.map(d=>{const c=F(d);if(c)return{...c,lastUpdated:o.get(d)}}).filter(d=>d!==void 0),raw:r}}async listV2Tags(n,t,s){const r={parsed:[],raw:[]},o=t==="library"?s:`${t}/${s}`,i={Accept:"application/json"},a=this.tokens[n]??process.env[`DOCKER_REGISTRY_TOKEN_${n.toUpperCase().replaceAll(/[^A-Z0-9]/g,"_")}`];a&&(i.Authorization=`Bearer ${a}`);const d=`https://${n}`,c=[];let u=`${d}/v2/${o}/tags/list?n=100`,f=i,g=0;const m=()=>{const h=[];for(const R of c){const A=F(R);A&&h.push({...A,lastUpdated:void 0})}return{parsed:h,raw:c}};for(;u&&g<5;){try{let h=await this.fetchImpl(u,{headers:f});if(h.status===401&&f===i){const $=Hn(h.headers.get("www-authenticate"));if($){const S=await this.fetchBearerToken($);S&&(f={...i,Authorization:`Bearer ${S}`},h=await this.fetchImpl(u,{headers:f}))}}if(!h.ok)return g===0?r:m();const R=await h.json();if(!Array.isArray(R.tags))return g===0?r:m();for(const $ of R.tags)typeof $=="string"&&c.push($);const A=tt(h.headers.get("link"));u=A.next?new URL(A.next,d).toString():void 0}catch{return g===0?r:m()}g+=1}return c.length===0?r:m()}async fetchBearerToken(n){const t=new URLSearchParams({scope:n.scope,service:n.service}),s=`${n.realm}?${t.toString()}`;try{const r=await this.fetchImpl(s,{headers:{Accept:"application/json"}});if(!r.ok)return;const o=await r.json();return o.token??o.access_token}catch{return}}}const Wn=e=>{const n=[];let t=0;const{length:s}=e;for(;t<s;){for(;t<s&&/\s/.test(e[t]??"");)t+=1;const r=t;for(;t<s&&e[t]!=="="&&e[t]!==",";)t+=1;const o=e.slice(r,t).trim();if(e[t]!=="="){for(;t<s&&e[t]!==",";)t+=1;t+=1;continue}t+=1;let i="";if(e[t]==='"'){for(t+=1;t<s&&e[t]!=='"';){if(e[t]==="\\"&&t+1<s){i+=e[t+1]??"",t+=2;continue}i+=e[t]??"",t+=1}t+=1}else{for(;t<s&&e[t]!==",";)i+=e[t]??"",t+=1;i=i.trim()}for(o.length>0&&n.push({key:o,value:i});t<s&&(/\s/.test(e[t]??"")||e[t]===",");)t+=1}return n},Hn=e=>{if(!e)return;const n=/^Bearer\s+(.*)$/i.exec(e);if(!n)return;const t=new Map;for(const{key:o,value:i}of Wn(n[1]??""))t.set(o.toLowerCase(),i);const s=t.get("realm"),r=t.get("service");if(s)return{realm:s,scope:t.get("scope")??"",service:r??""}},Ln="docker.io",Fn="sha256:",ae=e=>{const n=e.trim();if(n===""||n.startsWith("$")||n.includes("${")||n.includes("$("))return;let t=n,s;const r=t.indexOf(`@${Fn}`);r!==-1&&(s=t.slice(r+1),t=t.slice(0,r));let o=Ln,i=t;const a=t.indexOf("/");if(a>0){const h=t.slice(0,a);(h==="localhost"||h.includes(".")||h.includes(":"))&&(o=h,i=t.slice(a+1))}let d="latest",c=i;const u=i.lastIndexOf(":");u!==-1&&!i.slice(u).includes("/")&&(d=i.slice(u+1),c=i.slice(0,u));let f="library",g=c;const m=c.indexOf("/");if(m!==-1&&(f=c.slice(0,m),g=c.slice(m+1)),g!=="")return{digest:s,name:g,namespace:f,original:n,registry:o,tag:d}},ce=/vis-update-ignore-next-line/i,st=/vis-update-ignore(?:\s|$|:)/i,ot=e=>{const n=e.trim();return n===""||n.startsWith("#")},zn=/^\s*FROM\s+(?:--\S+\s+)*([^\s#]+)(?:\s[^#]*)?(#.*)?$/i,Gn=(e,n)=>{const t=n.split(/\r?\n/),s=[];let r=!1;for(const[o,i]of t.entries()){if(ce.test(i)&&ot(i)){r=!0;continue}const a=zn.exec(i);if(!a){i.trim()!==""&&!i.trim().startsWith("#")&&(r=!1);continue}const d=a[1]??"";if(d==="scratch"){r=!1;continue}const c=a[2]?.trim();let u=r?"vis-update-ignore-next-line":void 0;c&&ce.test(c)?u=u??"vis-update-ignore-next-line":c&&st.test(c)&&(u=u??"vis-update-ignore");const f=ae(d);r=!1,f&&s.push({...f,file:e,ignoreReason:u,kind:"dockerfile",line:o+1})}return s},Kn=/^\s*image:\s*(['"]?)([^'"\s#]+)\1(\s*#.*)?$/,Jn=(e,n)=>{const t=n.split(/\r?\n/),s=[];let r=!1;for(const[o,i]of t.entries()){if(ce.test(i)&&ot(i)){r=!0;continue}const a=Kn.exec(i);if(!a){i.trim()!==""&&!i.trim().startsWith("#")&&(r=!1);continue}const d=a[2]??"",c=a[3]?.trim();let u=r?"vis-update-ignore-next-line":void 0;c&&ce.test(c)?u=u??"vis-update-ignore-next-line":c&&st.test(c)&&(u=u??"vis-update-ignore");const f=ae(d);r=!1,f&&s.push({...f,file:e,ignoreReason:u,kind:"compose",line:o+1})}return s},Ue=e=>{const n=e.toLowerCase();return n==="dockerfile"||n.startsWith("dockerfile.")?!0:n.endsWith(".dockerfile")},Yn=e=>{const n=e.toLowerCase();return/^(?:docker-)?compose(?:\..+)?\.ya?ml$/.test(n)},Zn=new Set([".cache",".git",".nx",".pnpm-store",".turbo","build","dist","node_modules"]),Xn=/(?:^|\/)(?:\.git|node_modules|\.pnpm-store|\.turbo|\.nx|dist|build|\.cache)(?:\/|$)/,Qn=e=>{const n=[];if(!O(e))return n;const t=new Set,s=(r,o)=>{let i;try{i=Pt.native(r)}catch{i=r}if(t.has(i))return;t.add(i);let a;try{a=K(r)}catch{return}n.push(...o==="dockerfile"?Gn(r,a):Jn(r,a))};for(const r of Y(e,{includeDirs:!1,includeSymlinks:!1,skip:[Xn]})){const{name:o}=r;Zn.has(o)||(Ue(o)?s(r.path,"dockerfile"):Yn(o)&&s(r.path,"compose"))}for(const r of["Dockerfile","dockerfile","compose.yml","compose.yaml","docker-compose.yml","docker-compose.yaml"]){const o=_(e,r);O(o)&&s(o,Ue(r)?"dockerfile":"compose")}return n},es=864e5,Ve=(e,n)=>{for(const t of n)try{if(new RegExp(t).test(e))return!0}catch{if(e.includes(t))return!0}return!1},Oe=e=>{const n=e.namespace==="library"?e.name:`${e.namespace}/${e.name}`;return e.registry==="docker.io"?n:`${e.registry}/${n}`},ts=e=>e.digest!==void 0&&e.digest.length>0,ns=e=>{if(e.registry==="docker.io")return`https://hub.docker.com/${e.namespace==="library"?`_/${e.name}`:`r/${e.namespace}/${e.name}`}/tags`;const n=e.namespace==="library"?e.name:`${e.namespace}/${e.name}`;return`https://${e.registry}/${n}`},ss=(e,n)=>{const t=e.namespace==="library"?e.name:`${e.namespace}/${e.name}`;return`${e.registry==="docker.io"?t:`${e.registry}/${t}`}:${n}`},rt=async(e,n)=>{const{ignoreRules:t,options:s,references:r,registryOptions:o}=n,i=[],a=[],d=[];if(r.length===0)return{failed:d,ignored:a,updates:i};const c=new qn({fetch:o?.fetch,tokens:o?.tokens}),u=new Map;for(const A of r){const $=`${A.registry}|${A.namespace}|${A.name}`,S=u.get($)??[];S.push(A),u.set($,S)}const f=Math.max(1,s.maxConcurrentRequests),g=[...u.keys()];let m=0;const h=async A=>{const $=u.get(A)??[],S=$[0];if(!S)return;let y;try{y=await c.listTags(S.registry,S.namespace,S.name)}catch{for(const p of $)d.push({file:p.file,reason:`failed to list tags for ${Oe(p)}`});return}for(const p of $){const k=Oe(p);let l;if(p.ignoreReason?l=p.ignoreReason:Ve(k,s.exclude)?l="matched --exclude":s.include.length>0&&!Ve(k,s.include)?l="not matched by --include":s.respectDependabotConfig&&t&&ke(k,"docker",t)&&(l="ignored by dependabot/renovate config"),l){a.push({currentRef:p.tag,currentVersion:p.tag,ecosystem:"docker",file:p.file,ignored:!0,line:p.line,name:k,newRef:p.tag,newVersion:void 0,original:p.original,reason:l,replacement:p.original,updateType:"unknown"});continue}if(ts(p)){a.push({currentRef:p.tag,currentVersion:p.tag,ecosystem:"docker",file:p.file,ignored:!0,line:p.line,name:k,newRef:p.tag,newVersion:void 0,original:p.original,reason:"digest-pinned image (refresh the pin manually to update)",replacement:p.original,updateType:"digest"});continue}const E=F(p.tag);if(!E&&!s.includeBranches){a.push({currentRef:p.tag,currentVersion:p.tag,ecosystem:"docker",file:p.file,ignored:!0,line:p.line,name:k,newRef:p.tag,newVersion:void 0,original:p.original,reason:"non-semver tag (use --include-branches)",replacement:p.original,updateType:"unknown"});continue}if(!E&&s.mode!=="latest"){a.push({currentRef:p.tag,currentVersion:p.tag,ecosystem:"docker",file:p.file,ignored:!0,line:p.line,name:k,newRef:p.tag,newVersion:void 0,original:p.original,reason:`branch ref has no version baseline for --target=${s.mode}`,replacement:p.original,updateType:"unknown"});continue}const w=we(y.parsed,E,s.mode);if(!w)continue;if(s.minAgeDays!==void 0&&w.lastUpdated!==void 0&&(Date.now()-w.lastUpdated)/es<s.minAgeDays){a.push({currentRef:p.tag,currentVersion:p.tag,ecosystem:"docker",file:p.file,ignored:!0,line:p.line,name:k,newRef:w.raw,newVersion:w.raw,original:p.original,reason:`release younger than ${String(s.minAgeDays)} days`,replacement:p.original,updateType:"unknown"});continue}const C=w.raw,T=ss(p,C);i.push({currentRef:p.tag,currentVersion:p.tag,ecosystem:"docker",file:p.file,line:p.line,name:k,newRef:C,newVersion:C,original:p.original,replacement:T,updateType:ve(E,w),url:ns(p)})}},R=[];for(let A=0;A<Math.min(f,g.length);A++)R.push((async()=>{for(;m<g.length;){const $=g[m];m+=1,$!==void 0&&await h($)}})());return await Promise.all(R),{failed:d,ignored:a,updates:i}};class os{token;tokenHeader;defaultApiBase;fetchImpl;tagCache=new Map;constructor(n){const t=n.token??process.env.GITLAB_TOKEN;t?(this.token=t,this.tokenHeader="PRIVATE-TOKEN"):process.env.CI_JOB_TOKEN?(this.token=process.env.CI_JOB_TOKEN,this.tokenHeader="JOB-TOKEN"):(this.token=void 0,this.tokenHeader="PRIVATE-TOKEN"),this.defaultApiBase=n.apiBase??"https://gitlab.com",this.fetchImpl=n.fetch??fetch}async listTags(n){const t=this.tagCache.get(n);if(t)return t;const s=this.fetchTags(n);return this.tagCache.set(n,s),s}resolveHostAndPath(n){const t=n.indexOf("/");if(t>0){const s=n.slice(0,t);if(s.includes("."))return{host:`https://${s}`,path:n.slice(t+1)}}return{host:this.defaultApiBase,path:n}}async fetchTags(n){const{host:t,path:s}=this.resolveHostAndPath(n),r=encodeURIComponent(s),o=`${t}/api/v4/projects/${r}/repository/tags?per_page=100`,i={Accept:"application/json","User-Agent":"vis-update-gitlab"};this.token&&(i[this.tokenHeader]=this.token);try{const a=await this.fetchImpl(o,{headers:i});if(!a.ok)return{error:`HTTP ${String(a.status)} from ${t}`,parsed:[],tags:[]};const d=await a.json();if(!Array.isArray(d))return{error:`unexpected response shape from ${t}`,parsed:[],tags:[]};const c=d.map(f=>({name:typeof f.name=="string"?f.name:"",sha:typeof f.commit?.id=="string"?f.commit.id:""})).filter(f=>f.name!==""),u=[];for(const f of c){const g=F(f.name);g&&u.push({...g,sha:f.sha})}return{parsed:u,tags:c}}catch(a){return{error:a instanceof Error?a.message:"fetch failed",parsed:[],tags:[]}}}}const rs=/vis-update-ignore-next-line/i,ee=/vis-update-ignore(?:\s|$|:)/i,is=new Set([".gitlab-ci.yaml",".gitlab-ci.yml"]),as=e=>is.has(e)||e.endsWith(".gitlab-ci.yml")||e.endsWith(".gitlab-ci.yaml"),cs=/^\s*-?\s*project:\s*(['"]?)([^'"\s#]+)\1(?:\s*#.*)?$/,ls=/^\s*ref:\s*(['"]?)([^'"\s#]+)\1(\s*#.*)?$/,us=/^\s*-?\s*component:\s*(['"]?)([^'"\s#]+)\1(\s*#.*)?$/,ds=/^\s*image:\s*(['"]?)([^'"\s#]+)\1(\s*#.*)?$/,ps=/^\s*(?:-\s*)?(?:include:\s*)?\{([^}]*)\}\s*(?:#.*)?$/,fs=/project:\s*(['"]?)([^'"\s,}]+)\1/,gs=/ref:\s*(['"]?)([^'"\s,}]+)\1/,ms=/component:\s*(['"]?)([^'"\s,}]+)\1/,hs=/^(\s*-\s*name:\s*)(['"]?)([^'"\s#]+)\2(\s*#.*)?$/,$s=/^(\s*-\s*)(['"]?)([^'"\s#:]+:[^'"\s#]+)\2(\s*#.*)?$/,ys=/^\s*-?\s*[a-z_][\w-]*:\s*(?:#.*)?$/i,ks=(e,n)=>{const t=n.split(/\r?\n/),s=[],r=[];let o,i=!1,a=!1,d=-1;for(const[c,u]of t.entries()){const f=u??"",g=f.trim(),m=g===""||g.startsWith("#");if(rs.test(f)&&m){i=!0;continue}const h=/^(\s*)services:\s*(?:#.*)?$/.exec(f);if(h){a=!0,d=h[1]?.length??0;continue}a&&g!==""&&!g.startsWith("-")&&!g.startsWith("#")&&f.search(/\S/)<=d&&(a=!1,d=-1);const R=ds.exec(f);if(R){const p=R[2]??"",k=ae(p);if(k){const l=R[3]?.trim();let E=i?"vis-update-ignore-next-line":void 0;l&&ee.test(l)&&(E=E??"vis-update-ignore"),r.push({...k,file:e,ignoreReason:E,kind:"compose",line:c+1})}i=!1;continue}if(a){const p=hs.exec(f),k=p?void 0:$s.exec(f),l=p??k;if(l){const E=l[3]??"",w=ae(E);if(w){const C=l[4]?.trim();let T=i?"vis-update-ignore-next-line":void 0;C&&ee.test(C)&&(T=T??"vis-update-ignore"),r.push({...w,file:e,ignoreReason:T,kind:"compose",line:c+1})}}}const A=cs.exec(f);if(A){o={line:c+1,project:A[2]??""};continue}const $=ls.exec(f);if($&&o){const p=$[3]?.trim();let k=i?"vis-update-ignore-next-line":void 0;p&&ee.test(p)&&(k=k??"vis-update-ignore"),s.push({file:e,ignoreReason:k,kind:"project",line:c+1,original:$[2]??"",project:o.project,ref:$[2]??""}),o=void 0,i=!1;continue}const S=us.exec(f);if(S){const p=S[2]??"",k=p.lastIndexOf("@");if(k>0){const l=p.slice(0,k),E=p.slice(k+1),w=l.lastIndexOf("/"),C=w>0?l.slice(0,w):l,T=w>0?l.slice(w+1):void 0,x=S[3]?.trim();let j=i?"vis-update-ignore-next-line":void 0;x&&ee.test(x)&&(j=j??"vis-update-ignore"),s.push({componentName:T,file:e,ignoreReason:j,kind:"component",line:c+1,original:p,project:C,ref:E})}i=!1;continue}const y=ps.exec(f);if(y){const p=y[1]??"",k=/#(.*)$/.exec(f)?.[1]?.trim();let l=i?"vis-update-ignore-next-line":void 0;k&&ee.test(k)&&(l=l??"vis-update-ignore");const E=ms.exec(p);if(E){const w=E[2]??"",C=w.lastIndexOf("@");if(C>0){const T=w.slice(0,C),x=w.slice(C+1),j=T.lastIndexOf("/"),N=j>0?T.slice(0,j):T,M=j>0?T.slice(j+1):void 0;s.push({componentName:M,file:e,ignoreReason:l,kind:"component",line:c+1,original:w,project:N,ref:x})}}else{const w=fs.exec(p),C=gs.exec(p);w&&C&&s.push({file:e,ignoreReason:l,kind:"project",line:c+1,original:C[2]??"",project:w[2]??"",ref:C[2]??""})}i=!1;continue}g!==""&&!g.startsWith("#")&&!ys.test(f)&&(i=!1)}return{images:r,includes:s}},Be=/^(?:\.git|node_modules|\.pnpm-store|\.turbo|\.nx|dist|build|\.cache)$/,ws=e=>{const n=[],t=[];if(!O(e))return{images:t,includes:n};const s=o=>{let i;try{i=K(o)}catch{return}const{images:a,includes:d}=ks(o,i);n.push(...d),t.push(...a)};for(const o of[".gitlab-ci.yml",".gitlab-ci.yaml"]){const i=_(e,o);O(i)&&s(i)}const r=_(e,".gitlab");if(O(r))for(const o of Y(r,{includeDirs:!1,includeSymlinks:!1,skip:[Be]}))(o.name.endsWith(".yml")||o.name.endsWith(".yaml"))&&s(o.path);for(const o of Y(e,{includeDirs:!1,includeSymlinks:!1,maxDepth:2,skip:[Be]}))as(o.name)&&!t.some(i=>i.file===o.path)&&!n.some(i=>i.file===o.path)&&s(o.path);return{images:t,includes:n}},_e=(e,n)=>{for(const t of n)try{if(new RegExp(t).test(e))return!0}catch{if(e.includes(t))return!0}return!1},vs=(e,n,t)=>{const s=e.indexOf("/");return s>0&&e.slice(0,s).includes(".")?`https://${e.slice(0,s)}/${e.slice(s+1)}/-/releases/${n}`:`${t}/${e}/-/releases/${n}`},bs=async(e,n)=>{const{ignoreRules:t,imageReferences:s,includes:r,options:o,registryOptions:i,resolverOptions:a}=n,d=[],c=[],u=[];if(s.length>0){const y=await rt(e,{ignoreRules:t,options:o,references:s,registryOptions:i});for(const p of y.updates)d.push({...p,ecosystem:"gitlab"});for(const p of y.ignored)c.push({...p,ecosystem:"gitlab"});u.push(...y.failed)}if(r.length===0)return{failed:u,ignored:c,updates:d};const f=new os({apiBase:a?.apiBase,fetch:a?.fetch,token:o.gitlabToken??a?.token}),g=a?.apiBase??"https://gitlab.com",m=new Map;for(const y of r){const p=m.get(y.project)??[];p.push(y),m.set(y.project,p)}const h=Math.max(1,o.maxConcurrentRequests),R=[...m.keys()];let A=0;const $=async y=>{const p=m.get(y)??[];let k;try{k=await f.listTags(y)}catch{for(const l of p)u.push({file:l.file,reason:`failed to list tags for ${y}`});return}if(k.error){for(const l of p)u.push({file:l.file,reason:`failed to list tags for ${y}: ${k.error}`});return}for(const l of p){const E=l.kind==="component"&&l.componentName?`${l.project}/${l.componentName}`:l.project;let w;l.ignoreReason?w=l.ignoreReason:_e(E,o.exclude)?w="matched --exclude":o.include.length>0&&!_e(E,o.include)?w="not matched by --include":o.respectDependabotConfig&&t&&ke(E,"gitlab",t)&&(w="ignored by dependabot/renovate config");const C=N=>({currentRef:l.ref,currentVersion:l.ref,ecosystem:"gitlab",file:l.file,ignored:!0,line:l.line,name:E,newRef:l.ref,newVersion:void 0,original:l.original,reason:N,replacement:l.original,updateType:"unknown"});if(w){c.push(C(w));continue}const T=F(l.ref);if(!T&&!o.includeBranches){c.push(C("branch reference (use --include-branches)"));continue}if(!T&&o.mode!=="latest"){c.push(C(`branch ref has no version baseline for --target=${o.mode}`));continue}const x=we(k.parsed,T,o.mode);if(!x)continue;let j;l.kind==="component"?j=`${l.componentName?`${l.project}/${l.componentName}`:l.project}@${x.raw}`:j=x.raw,d.push({currentRef:l.ref,currentVersion:T?.raw??l.ref,ecosystem:"gitlab",file:l.file,line:l.line,name:E,newRef:x.raw,newVersion:x.raw,original:l.original,replacement:j,updateType:ve(T,x),url:vs(l.project,x.raw,g)})}},S=[];for(let y=0;y<Math.min(h,R.length);y++)S.push((async()=>{for(;A<R.length;){const p=R[A];A+=1,p!==void 0&&await $(p)}})());return await Promise.all(S),{failed:u,ignored:c,updates:d}},Rs={disabled:new Set,exclude:[],githubToken:void 0,gitlabToken:void 0,include:[],includeBranches:!1,maxConcurrentRequests:8,minAgeDays:void 0,mode:"latest",respectDependabotConfig:!0,style:"sha"},it=async e=>{const n={...Rs,...e.options,disabled:e.options?.disabled??new Set},t=n.respectDependabotConfig?yn(e.workspaceRoot):void 0,s={actions:{failed:[],ignored:[],updates:[]},docker:{failed:[],ignored:[],updates:[]},gitlab:{failed:[],ignored:[],updates:[]}},r=[];let o=0;if(!n.disabled.has("actions")){const d=Dn(e.workspaceRoot);d.length>0&&(o+=1,r.push(Mn(e.workspaceRoot,{ignoreRules:t,options:n,references:d}).then(c=>{s.actions=c})))}if(!n.disabled.has("docker")){const d=Qn(e.workspaceRoot);d.length>0&&(o+=1,r.push(rt(e.workspaceRoot,{ignoreRules:t,options:n,references:d}).then(c=>{s.docker=c})))}if(!n.disabled.has("gitlab")){const{images:d,includes:c}=ws(e.workspaceRoot);d.length+c.length>0&&(o+=1,r.push(bs(e.workspaceRoot,{ignoreRules:t,imageReferences:d,includes:c,options:n}).then(u=>{s.gitlab=u})))}await Promise.all(r);const i=[...s.actions.updates,...s.docker.updates,...s.gitlab.updates],a=[...s.actions.ignored,...s.docker.ignored,...s.gitlab.ignored];return{failed:[...s.actions.failed,...s.docker.failed,...s.gitlab.failed],ignored:a,perEcosystem:s,scanned:o,updates:i}},xs={actions:"GitHub Actions",docker:"Docker",gitlab:"GitLab CI"},$e=e=>e.updateType==="major",As=e=>{switch(e){case"major":return G;case"minor":return I;case"patch":return ze;default:return Ge}},Me=e=>{const n=As(e.updateType),t=e.currentVersion??e.currentRef,s=e.newVersion??e.newRef,r=e.url?` ${q(e.url)}`:"",o=e.advisories&&e.advisories.length>0?` ${G(`⚠ ${String(e.advisories.length)} advisor${e.advisories.length===1?"y":"ies"}`)}`:"";return` ${n(e.updateType.padEnd(7))} ${e.name} ${q(t)} → ${s}${o}${r}`},Pe=e=>!e.advisories||e.advisories.length===0?[]:e.advisories.map(n=>` ${n.severity==="CRITICAL"||n.severity==="HIGH"?G(n.severity):I(n.severity)} ${n.id} ${q(n.summary)}`),Ss=(e,n)=>{const t=[],s=e.updates.length;if(s===0&&e.scanned===0)return"";if(s===0){if(e.failed.length===0&&e.ignored.length===0)return t.push(`${ze("✓")} All ecosystem references up to date.`),t.join(`
6
+ `);if(t.push(`${I("")} No actionable updates found.`),e.failed.length>0){t.push(`
7
+ ${I("Failed lookups:")}`);for(const o of e.failed)t.push(` ${o.file}: ${o.reason}`)}if(n.showIgnored&&e.ignored.length>0){t.push(`
8
+ ${q("Ignored:")}`);for(const o of e.ignored)t.push(` ${q(o.name)} ${q(o.reason??"")}`)}return t.join(`
9
+ `)}t.push(`
10
+ ${Ge("Ecosystem updates")} — ${String(s)} reference${s===1?"":"s"} can be bumped:`);const r=e.updates.filter(o=>$e(o));if(r.length>0){t.push(`
11
+ ${G(yt(`⚠ Breaking changes (${String(r.length)})`))}`),t.push(` ${q("Review release notes before applying these cross a major-version boundary.")}`);for(const o of r)t.push(Me(o)),t.push(...Pe(o))}for(const o of Object.keys(e.perEcosystem)){const i=e.perEcosystem[o];if(i.updates.length!==0){t.push(`
12
+ ${xs[o]} (${String(i.updates.length)})`);for(const a of i.updates)t.push(Me(a)),t.push(...Pe(a))}}if(n.showIgnored&&e.ignored.length>0){t.push(`
13
+ ${q("Ignored:")}`);for(const o of e.ignored)t.push(` ${q(o.name)} ${q(o.reason??"")}`)}if(e.failed.length>0){t.push(`
14
+ ${I("Failed lookups:")}`);for(const o of e.failed)t.push(` ${o.file}: ${o.reason}`)}return n.previewOnly&&t.push(`
15
+ ${I("ℹ")} ${q("Not applied automatically — re-run with `--interactive` to choose which to apply, or `--yes` to apply all.")}`),t.join(`
16
+ `)},Es=e=>JSON.stringify({ecosystems:{failed:e.failed,ignored:e.ignored,perEcosystem:e.perEcosystem,scanned:e.scanned,updates:e.updates}},void 0,2),Cs=()=>{const e=Fe({input:process.stdin,output:process.stdout});return{ask:n=>new Promise(t=>{e.question(n,s=>{t(s.trim())})}),close:()=>{e.close()},write:n=>{process.stdout.write(`${n}
17
+ `)}}},Ts=(e,n)=>e.split(",").map(t=>Number.parseInt(t.trim(),10)-1).filter(t=>Number.isInteger(t)&&t>=0&&t<n),js=async(e,n=Cs())=>{if(e.length===0)return n.close(),[];n.write(""),n.write("Outdated ecosystem references:");for(const[s,r]of e.entries()){const o=r.currentVersion??r.currentRef,i=r.newVersion??r.newRef,a=$e(r)?" [BREAKING]":"";n.write(` ${String(s+1)}. [${r.ecosystem}] ${r.name}: ${o} → ${i} (${r.updateType})${a}`)}n.write("");const t=(await n.ask("Apply updates? [a]ll / [s]afe / [n]one / numbers: ")).toLowerCase();if(t==="a"||t==="all")return n.close(),e;if(t==="s"||t==="safe")return n.close(),e.filter(s=>!$e(s));if(t==="n"||t==="none"||t==="")return n.close(),[];if(/^[\d ,]+$/.test(t)){const s=Ts(t,e.length);return n.close(),s.map(r=>e[r]).filter(r=>r!==void 0)}return n.close(),[]},at=e=>{const n=e.trim();if(n==="")return;const t=/^(\d+(?:\.\d+)?)\s*([mhdw])?$/i.exec(n);if(!t)return;const s=Number.parseFloat(t[1]);if(!(!Number.isFinite(s)||s<0))switch((t[2]??"m").toLowerCase()){case"d":return s*60*24;case"h":return s*60;case"m":return s;case"w":return s*60*24*7;default:return}},Is=e=>{const n=e.trim();return/^\d+(?:\.\d+)?$/.test(n)?Number.parseFloat(n)*1440:at(n)},lo=e=>!Number.isFinite(e)||e<=0?"0m":e%1440===0?`${String(e/1440)}d`:e%60===0?`${String(e/60)}h`:`${String(e)}m`,be=(e,n)=>{try{switch(n){case"bun":{const t=_(e,"bunfig.toml");if(O(t)){const s=vt(t),r=s?.install?.minimumReleaseAge;return{excludes:Array.isArray(s?.install?.minimumReleaseAgeExcludes)?s.install.minimumReleaseAgeExcludes:void 0,minutes:typeof r=="number"?Math.round(r/60):void 0}}break}case"npm":{const t=_(e,".npmrc");if(O(t)){const s=K(t),r=/^\s*min-release-age\s*=\s*([^\s#;]+)/m.exec(s);return{minutes:r?Is(r[1]):void 0}}break}case"pnpm":{const t=_(e,"pnpm-workspace.yaml");if(O(t)){const s=Ee(t);return{excludes:Array.isArray(s?.minimumReleaseAgeExclude)?s.minimumReleaseAgeExclude:void 0,minutes:typeof s?.minimumReleaseAge=="number"?s.minimumReleaseAge:void 0}}break}case"yarn":{const t=_(e,".yarnrc.yml");if(O(t)){const s=Ee(t),r=s?.npmMinimalAgeGate,o=Array.isArray(s?.npmPreapprovedPackages)?s.npmPreapprovedPackages:void 0;if(typeof r=="string")return{excludes:o,minutes:at(r)};if(typeof r=="number")return{excludes:o,minutes:r}}break}}}catch{}return{}},Ns={bun:"minimumReleaseAgeExcludes",pnpm:"minimumReleaseAgeExclude",yarn:"npmPreapprovedPackages"},ct={bun:"bunfig.toml minimumReleaseAgeExcludes",npm:".npmrc",pnpm:"pnpm-workspace.yaml minimumReleaseAgeExclude",yarn:".yarnrc.yml npmPreapprovedPackages"},lt=(e,n,t)=>{const s=be(n,e);if(typeof s.minutes!="number"||s.minutes<=0)return{added:[],unsupported:!1};if(!(e in Ns))return{added:[],unsupported:!0};const r=s.excludes??[],o=[...new Set(t)].filter(i=>!r.includes(i));return o.length===0?{added:[],unsupported:!1}:(Yt(e,n,s.minutes,[...r,...o]),{added:o,unsupported:!1})},ut=(e,n,t)=>{t.added.length>0?e.info(`Added ${String(t.added.length)} package${t.added.length===1?"":"s"} to ${ct[n]??"the package manager config"} so --ignore-release-age versions install: ${t.added.join(", ")}`):t.unsupported&&e.warn(`${I("⚠")} npm has no per-package release-age exclude list, so vis can't exempt just the selected packages. Lower min-release-age in .npmrc or pass --min-release-age=0 to the install.`)},Ds=(e,n,t)=>{const s=e.latest?"latest":e.target??n.target??"latest";if(!["latest","minor","patch"].includes(s))throw new Error(`Invalid target "${s}". Use: latest, minor, or patch.`);const r=e.maxConcurrentRequests,o=typeof r=="number"&&r>0?r:n.maxConcurrentRequests,i=typeof e.releaseChannel=="string"?e.releaseChannel.toLowerCase():void 0;if(i!==void 0&&!["any","same","stable"].includes(i))throw new Error(`Invalid --release-channel "${String(e.releaseChannel)}". Use: any, same, or stable.`);const a=i??n.releaseChannel;return{exclude:[...W(e.exclude),...W(n.exclude)],ignore:W(n.ignore),include:[...W(e.include),...W(n.include),...t],includeLocked:e.includeLocked||n.includeLocked||!1,includePrerelease:e.prerelease||n.prerelease||!1,maxConcurrentRequests:o,minimumReleaseAge:n.minimumReleaseAge,minimumReleaseAgeExclude:n.minimumReleaseAgeExclude,packageMode:n.packageMode,releaseChannel:a,security:e.security===!1?!1:e.ai||(n.security??!0),target:s}},qe=(e,n)=>{if(e.length!==0){n.info(`
18
+ ${I("")} ${String(e.length)} package${e.length===1?"":"s"} skipped by target constraint (use --target latest to include):`);for(const t of e)n.info(` ${t.packageName} ${t.currentRange} ${t.newRange} (${t.updateType})`)}},We=(e,n,t,s,r)=>{t==="json"?process.stdout.write(`${Vt({checkedCount:0,failed:n,filteredByTarget:[],ignored:[],outdated:e})}
19
+ `):t==="minimal"?process.stdout.write(`${Ot(e)}
20
+ `):(Bt(e,s),s.info(Je(e,r)))},He=async(e,n,t,s,r,o,i)=>{const a=Ut(e,t,n,!0,{useEditorconfig:i}),d=n==="pnpm"?"pnpm-workspace.yaml":"package.json";if(r.info(`
21
+ Updated ${d}`),a&&r.info(`Backup saved to ${a}`),s.changelog){r.info(`
22
+ Fetching changelogs...`);const c=await Ke(t,void 0,o);for(const u of c){const f=u.releaseUrl??u.repoUrl??u.npmUrl;r.info(` ${u.packageName}: ${f}`)}}if(s["ignore-release-age"]===!0&&t.length>0&&ut(r,n,lt(n,e,t.map(c=>c.packageName))),s.install??!0){const c=n,u=["install"];r.info(`Running ${c} ${u.join(" ")}...
23
+ `);try{const{code:f,output:g}=await Ye(c,u,{cwd:e,env:process.env});f!==0?r.warn(`${c} ${u.join(" ")} failed. You may need to run it manually.`):s.peer!==!0&&Ze(g)&&r.info(Xe)}catch{r.warn(`${c} ${u.join(" ")} failed. You may need to run it manually.`)}}},ye={applied:!1,canceled:!1,jsonEmitted:!1},Us={actions:"GitHub Actions",docker:"Docker",gitlab:"GitLab CI"},Vs={digest:"patch",major:"major",minor:"minor",patch:"patch",pin:"patch",unknown:"patch"},Os=e=>({catalogName:Us[e.ecosystem],currentRange:e.currentVersion??e.currentRef,detailUrl:e.url,displayName:e.name,kind:"ecosystem",newRange:e.newVersion??e.newRef,packageName:tn(e),targetVersion:e.newVersion??e.newRef,updateType:Vs[e.updateType]??"patch"}),Bs=async(e,n,t,s,r,o)=>{const i=t.update??{},a=[["global","--global is not supported in catalog mode"],["recursive","--recursive is not needed in catalog mode (catalogs are workspace-level)"],["filter","--filter is not supported in catalog mode (use --include/--exclude instead)"],["no-save","--no-save is not supported in catalog mode"],["workspace-root","--workspace-root is not needed in catalog mode"],["no-optional","--no-optional is not supported in catalog mode"]];for(const[b,U]of a)s[b]&&o.warn(`${I("⚠")} ${U}, ignoring.`);const d=s["ignore-release-age"]===!0,c=ge("minReleaseAge")||d,{excludes:u,minutes:f}=c?{excludes:void 0,minutes:void 0}:be(e,n),g=c?void 0:i.minimumReleaseAge??f,m=c?void 0:i.minimumReleaseAgeExclude??u;if(d?o.info(`${I("⚠")} --ignore-release-age: selecting the latest versions regardless of minimumReleaseAge.`):c&&(i.minimumReleaseAge!==void 0||f!==void 0)&&o.info("minimumReleaseAge gate disabled via MARSHALL_DISABLE_MIN_RELEASE_AGE."),!c&&i.minimumReleaseAge!==void 0&&f!==void 0&&i.minimumReleaseAge!==f){const b=n==="pnpm"?"pnpm-workspace.yaml":"bunfig.toml";o.warn(`${I("⚠")} minimumReleaseAge mismatch: vis config = ${String(i.minimumReleaseAge)} min, ${b} = ${String(f)} min. Consider keeping them in sync.`)}const h=Ct(e),R=s["include-internal"],A=s.peer,$=Tt(e,n,{depFields:i.depFields,dev:s.dev,includeInternal:R,peer:A,prod:s.prod});if($.size===0)return o.info("No catalogs found."),ye;const S={...i,minimumReleaseAge:g,minimumReleaseAgeExclude:m},y=Ds(s,S,r);let p=0;for(const b of $.values())p+=b.size;const k=!!process.stdout.isTTY&&!le;let l;const E=k?(b,U)=>{l?l.rerender(P.createElement(je,{current:b,total:U})):(process.stdout.write(`
24
+ `),l=Ce(P.createElement(je,{current:b,total:U}),{interactive:!0,patchConsole:!1}))}:(b,U)=>{o.info(`Checking ${String(b)}/${String(U)} dependencies...`)};k||o.info(`Checking ${String(p)} catalog dependencies...
25
+ `);const w=new Set;ge("socket")&&w.add("socket"),ge("depsDev")&&w.add("deps-dev");const C=t.security?.policies?.score?.minimum,T=jt(t.security,{disabled:w,minimumScore:C}),{checkedCount:x,failed:j,filteredByTarget:N,ignored:M,outdated:D}=await It($,y,h,E,e,T,t.security?.acceptedRisks);l&&(l.clear(),l.unmount());const ne=R?{ignored:[],outdated:[]}:Nt(e,{depFields:i.depFields,dev:s.dev,exclude:y.exclude,ignore:y.ignore,include:y.include,packageMode:y.packageMode,peer:A,prod:s.prod,target:y.target});if(ne.outdated.length>0){const b=new Set(D.map(U=>`${U.catalogName}|${U.packageName}`));for(const U of ne.outdated)b.has(`${U.catalogName}|${U.packageName}`)||D.push(U)}if(ne.ignored.length>0)for(const b of ne.ignored)M.includes(b)||M.push(b);const Re=x-D.length-j.length;if(j.length>0&&o.warn(`Failed to fetch: ${j.join(", ")}`),M.length>0&&o.info(`Skipped ${String(M.length)} ignored package${M.length===1?"":"s"}: ${M.join(", ")}`),!k&&x>D.length){const b=[...$.values()].reduce((X,ue)=>X+ue.size,0),U=b>x?` (${String(b)} catalog entries, ${String(b-x)} duplicates)`:"";o.info(`Checked ${String(x)} unique packages${U}: ${String(D.length)} outdated, ${String(Re)} up-to-date${j.length>0?`, ${String(j.length)} failed`:""}${N.length>0?`, ${String(N.length)} skipped by target`:""}`)}if(D.length===0)return N.length>0?o.info(`All catalog dependencies are up to date within the current target.
26
+ ${String(N.length)} package${N.length===1?" has":"s have"} newer versions available with --target latest:
27
+ ${N.map(b=>` ${b.packageName} ${b.currentRange} ${b.newRange} (${b.updateType})`).join(`
28
+ `)}`):o.info("All catalog dependencies are up to date."),ye;const z=s.format??i.format??"table";let H;if(s.ai){const b=qt(s.aiType??"impact");H=await Wt(D,o,t.ai,b)}const se=!!s.dryRun;if(!se&&r.length>0&&s.marshallCheck!==!1){const b=await Gt(r);if(b.length>0){const U=await Kt(b,{config:t?.security?.marshalls,workspaceRoot:e});if(!await Jt(U))return process.exitCode=1,{applied:!1,canceled:!0,jsonEmitted:!1}}}if(k&&z==="table"){const b=new Map,U=[];let X=!1;if(r.length===0){const v=dt(s,t);if(v.disabled.size<3)try{const V=await it({options:v,workspaceRoot:e});X=V.scanned>0;for(const B of V.updates){const J=Os(B);b.set(J.packageName,B),U.push(J)}}catch(V){o.warn(`${I("⚠")} Ecosystem update scan failed: ${V.message}`)}}const ue=new Qt([...D,...U],H??null);let de;if(s.changelog){o.info("Fetching changelogs...");const v=await Ke(D,void 0,h);de=new Map;for(const V of v){const B=V.releaseUrl??V.repoUrl??V.npmUrl;B&&de.set(V.packageName,B)}}const pe=t.tui?.autoExit??!1,ft=pe===!0?3:typeof pe=="number"?pe:0,xe=await Ce(P.createElement(en,{autoExitSeconds:ft,changelogUrls:de,checkedCount:x,filteredOutEntries:N,isDryRun:se,store:ue,totalCatalogEntries:p}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit(),fe=process.stdout.columns||80;process.stdout.write(`
29
+ `);for(const v of D){const V=v.vulnerabilities?.length||v.socketReport&&v.socketReport.alerts.length>0,B=!!v.acceptedRisk,J=V?B?"✓":"⚠":"✓",gt=B?"gray":v.updateType==="major"?"red":v.updateType==="minor"?"yellow":"green",ie=v.socketReport?.score.overall,mt=ie===void 0?"":` [${String(Math.round(ie*100))}%]`,Se=ie===void 0?void 0:_t(ie);process.stdout.write(`${me(P.createElement(L,null," ",P.createElement(L,{color:gt},J),` ${v.packageName} ${v.currentRange} → ${v.newRange}`,P.createElement(L,{dimColor:!0},` ${v.updateType}`),Se?P.createElement(L,{color:Se},mt):null),{columns:fe})}
30
+ `)}if(process.stdout.write(`
31
+ `),o.info(Je(D,C)),x>D.length){const v=[...$.values()].reduce((B,J)=>B+J.size,0),V=v>x?` (${String(v)} catalog entries, ${String(v-x)} duplicates)`:"";o.log(),o.info(`Checked ${String(x)} unique packages${V}: ${String(Re)} up-to-date${j.length>0?`, ${String(j.length)} failed`:""}`)}if(N.length>0){process.stdout.write(`
32
+ `);const v=`${String(N.length)} package${N.length===1?"":"s"} skipped by target constraint (use --target latest to include):`;process.stdout.write(`${me(P.createElement(L,{color:"yellow"},` ${v}`),{columns:fe})}
33
+ `);for(const V of N)process.stdout.write(`${me(P.createElement(L,null," ",P.createElement(L,{dimColor:!0},V.packageName),` ${V.currentRange} → ${V.newRange}`,P.createElement(L,{dimColor:!0},` ${V.updateType}`)),{columns:fe})}
34
+ `)}const oe=Array.isArray(xe)?xe:[],re=oe.filter(v=>v.kind!=="ecosystem"),Ae=oe.filter(v=>v.kind==="ecosystem").map(v=>b.get(v.packageName)).filter(v=>v!==void 0);if(!se&&oe.length>0){if(re.length>0){o.info(`
35
+ Applying ${String(re.length)} catalog update${re.length===1?"":"s"}...
36
+ `);const v={...s,install:s.install??i.install};await He(e,n,re,v,o,h,t.editorconfig??!0)}if(Ae.length>0){const{applied:v,skipped:V}=nt(Ae);v.length>0&&o.info(`${String(v.length)} ecosystem reference${v.length===1?"":"s"} updated.`);for(const B of V)o.warn(`${I("⚠")} Skipped ${B.update.name} (${B.update.file}): ${B.reason}`)}return{applied:!0,canceled:!1,ecosystemHandled:X,jsonEmitted:!1}}return{applied:!1,canceled:oe.length===0,ecosystemHandled:X,jsonEmitted:!1}}if(se){if(z==="json"){const b={failed:j,filteredByTarget:N,ignored:M,outdated:D};H&&(b.aiAnalysis=H),process.stdout.write(`${JSON.stringify(b,void 0,2)}
37
+ `)}else o.info(`Would update ${String(D.length)} dependencies:
38
+ `),We(D,j,z,o,C),H&&(o.info(""),o.info(Te(H))),qe(N,o);return{applied:!1,canceled:!1,jsonEmitted:z==="json"}}H&&z!=="json"&&(o.info(Te(H)),o.info(""));let Z=D;if(s.interactive&&(Z=await Dt(D),Z.length===0))return o.info("No updates selected."),{applied:!1,canceled:!0,jsonEmitted:!1};o.info(`Updating ${String(Z.length)} catalog dependencies...
39
+ `),We(Z,[],z,o,C),qe(N,o);const pt={...s,install:s.install??i.install};return await He(e,n,Z,pt,o,h),{applied:!0,canceled:!1,jsonEmitted:z==="json"}},_s=async(e,n,t,s,r,o)=>{if(s["ignore-release-age"]===!0){const u=be(e,n),f=typeof u.minutes=="number"&&u.minutes>0;if(f&&r.length>0){const g=r.map(m=>Qe(m).name);ut(o,n,lt(n,e,g))}else f&&o.warn(`${I("⚠")} --ignore-release-age without package names can't pre-exempt packages in pm-wrapper mode (vis doesn't know which will change). Pass explicit package names, use catalog mode, or lower the gate in ${ct[n]??"your package manager config"}.`)}const i={dev:s.dev,filters:W(s.filter),global:s.global,interactive:s.interactive,latest:s.latest||s.target==="latest",noOptional:s.optional===!1,noSave:s.save===!1,packages:r,prod:s.prod,recursive:s.recursive,workspaceRoot:s.workspaceRoot},{command:a,warnings:d}=dn(n,t,i);for(const u of d)o.warn(u);const c=`${a.bin} ${a.args.join(" ")}`.trim();if(s.dryRun)return o.info(`Would run: ${c}`),ye;o.info(`Running: ${c}`);try{const{code:u,output:f}=await Ye(a.bin,a.args,{cwd:e,env:process.env});if(u!==0)return o.error(`
40
+ ${G("✖")} Update failed (exit code ${String(u)})`),o.error(` Command: ${c}`),o.error(` Directory: ${e}
41
+ `),process.exitCode=u,{applied:!1,canceled:!1,jsonEmitted:!1};s.peer!==!0&&Ze(f)&&o.info(Xe)}catch(u){const f=u.status??1;return o.error(`
42
+ ${G("✖")} Update failed (exit code ${String(f)})`),o.error(` Command: ${c}`),o.error(` Directory: ${e}
43
+ `),process.exitCode=f,{applied:!1,canceled:!1,jsonEmitted:!1}}return{applied:!0,canceled:!1,jsonEmitted:!1}},Ms=async(e,n,t)=>{const s=e.latest===!0||e.target==="latest";if(n||!s||e.dryRun===!0||e.yes===!0||e.interactive===!0)return!0;if(!(process.stdout.isTTY&&!le))return t.error(`${G("✖")} Refusing to run blanket --latest update in a non-interactive context.`),t.error(" Re-run with --yes to confirm, --dry-run to preview, or pass explicit package names."),process.exitCode=1,!1;const r=Fe({input:process.stdin,output:process.stdout});try{const o=(await new Promise(i=>{r.question(`${I("⚠")} About to upgrade ALL dependencies to their latest versions. This may include breaking changes.
44
+ Continue? [y/N] `,i)})).trim().toLowerCase();return o==="y"||o==="yes"?!0:(t.info("Aborted."),!1)}finally{r.close()}},dt=(e,n)=>{const t=new Set;e.actions===!1&&t.add("actions"),e.docker===!1&&t.add("docker"),e.gitlab===!1&&t.add("gitlab");const s=e.style??"sha";if(s!=="sha"&&s!=="preserve")throw new Error(`Invalid --style "${s}". Use: sha or preserve.`);const r=e.latest===!0?"latest":e.target??"latest";if(r!=="latest"&&r!=="minor"&&r!=="patch")throw new Error(`Invalid target "${r}". Use: latest, minor, or patch.`);const o=r,i=n.update??{};return{disabled:t,exclude:[...W(e.exclude),...W(i.exclude)],githubToken:e.actionsToken??void 0,gitlabToken:e.gitlabToken??void 0,include:W(e.include),includeBranches:e.includeBranches===!0,maxConcurrentRequests:typeof e.maxConcurrentRequests=="number"&&e.maxConcurrentRequests>0?e.maxConcurrentRequests:8,minAgeDays:typeof i.minimumReleaseAge=="number"&&i.minimumReleaseAge>0?i.minimumReleaseAge/1440:void 0,mode:o,respectDependabotConfig:!0,style:s}},Ps=(e,n)=>e.dryRun===!0||process.exitCode!==void 0&&process.exitCode!==0||n.canceled?!1:e.yes===!0?!0:e.interactive===!0&&!!process.stdout.isTTY&&!le,qs=async(e,n,t,s,r)=>{const o=dt(n,t);if(o.disabled.size===3)return;let i;try{i=await it({options:o,workspaceRoot:e})}catch(m){s.warn(`${I("⚠")} Ecosystem update scan failed: ${m.message}`);return}if(i.scanned===0)return i;const a=n.format??"table",d=!!n.dryRun,c=Ps(n,r);if(a==="json")r.jsonEmitted?s.warn(`${I("⚠")} ${String(i.updates.length)} ecosystem update${i.updates.length===1?"":"s"} available but not emitted in --format=json (catalog already wrote one JSON document). Rerun with --format=table or --no-catalog to see them.`):process.stdout.write(`${Es(i)}
45
+ `);else if(a!=="minimal"){const m=Ss(i,{previewOnly:!c&&!d,showIgnored:n.interactive===!0});m&&s.info(m)}if(i.updates.length===0)return i;if(d)return a==="minimal"&&s.info(`
46
+ ${I("ℹ")} ${String(i.updates.length)} ecosystem reference${i.updates.length===1?"":"s"} can be bumped — not applied (--dry-run). Re-run without --dry-run and with \`--interactive\` or \`--yes\` to apply.`),i;if(!c)return a==="minimal"&&s.info(`
47
+ ${I("ℹ")} ${String(i.updates.length)} ecosystem reference${i.updates.length===1?"":"s"} can be bumped — not applied automatically. Re-run with \`--interactive\` to choose, or \`--yes\` to apply all (or \`--no-actions\` / \`--no-docker\` / \`--no-gitlab\` to silence by ecosystem).`),i;let u=i.updates;if(n.interactive===!0&&process.stdout.isTTY&&!le&&(u=await js(i.updates),u.length===0))return s.info(`${I("ℹ")} No ecosystem updates selected.`),i;const{applied:f,skipped:g}=nt(u);if(f.length>0&&s.info(`
48
+ ${String(f.length)} ecosystem reference${f.length===1?"":"s"} updated.`),g.length>0){s.warn(`${I("⚠")} ${String(g.length)} ecosystem update${g.length===1?"":"s"} skipped:`);for(const m of g)s.warn(` ${m.update.name} (${m.update.file}:${String(m.update.line)}): ${m.reason}`)}return i},Ws=e=>{const n=e.style;if(n!==void 0&&n!=="sha"&&n!=="preserve")throw new Error(`Invalid --style "${n}". Use: sha or preserve.`);const t=e.target;if(t!==void 0&&t!=="latest"&&t!=="minor"&&t!=="patch")throw new Error(`Invalid --target "${t}". Use: latest, minor, or patch.`)},uo=async({argument:e,logger:n,options:t,visConfig:s,workspaceRoot:r})=>{if(!r)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");Ws(t);let o=e;const i=r,{packageManager:a}=Rt(i);if(t.typosquatCheck!==!1){if(o.length>0){const u=o.map(m=>Qe(m)),f=s?.security?.typosquatAllowlist,g=await Zt(u.map(m=>m.name),f);if(!g.ok){process.exitCode=1;return}o=u.map((m,h)=>{const R=g.packages[h];return R!==m.name?m.versionSpec?`${R}@${m.versionSpec}`:R??"":o[h]??""})}else if(!await Xt(i,s?.security?.typosquatAllowlist)){process.exitCode=1;return}}if(t.rollback){if(!At(i,a)){n.info("No backup found. Run 'vis update' first to create a backup.");return}if(St(i,a))n.info("Restored from backup.");else throw new Error("Failed to restore from backup.");return}if(!await Ms(t,o.length>0,n))return;const d=t.catalog!==!1&&Et(i,a);let c;if(d)c=await Bs(i,a,s??{},t,o,n);else{const u=Lt(i,{backend:Ft(zt({logger:n,options:t,visConfig:s},i)),configBackend:s?.install?.backend,configCorepack:s?.install?.corepack}),f=u.name==="aube"?"":xt(u.name);c=await _s(i,u.name,f,t,o,n)}o.length===0&&c.ecosystemHandled!==!0&&await qs(i,t,s??{},n,c)};export{lt as addReleaseAgeExcludesForInstall,uo as default,lo as formatMinutesAsTimeString,Is as parseNpmReleaseAgeValue,at as parseTimeStringToMinutes,be as readPmNativeMinimumReleaseAge,Ms as requireBlanketUpdateConfirmation,qs as runEcosystemUpdate,Ps as shouldApplyEcosystem};