// @bun
import{La as _}from"./chunk-e9b0zqk5.js";import{Zb as B}from"./chunk-bqh4yh6g.js";function T(w){let z=w.split("/").pop()||"";if(["deps.yaml","dependencies.yaml","pkgx.yaml",".deps.yaml"].includes(z))return!0;let j=z.replace(/\.(yaml|yml)$/,"");return["deps","dependencies","pkgx",".deps"].includes(j)}async function N(w,z){try{if(!T(w))return null;let G=[];try{let q=await _(w);if(q&&typeof q==="object"){if(q.allDependencies&&Array.isArray(q.allDependencies)){for(let H of q.allDependencies)if(H.name&&H.constraint)G.push({name:H.name,currentVersion:H.constraint,type:"dependencies",file:w})}}}catch(q){console.warn(`ts-pkgx failed to parse ${w}, attempting fallback YAML parsing:`,q)}if(G.length===0)try{G=await I(z,w)}catch(q){console.warn(`Fallback YAML parsing failed for ${w}:`,q),G=[]}let j=w.split("/").pop()||"";return{path:w,type:j,content:z,dependencies:G}}catch(G){return console.warn(`Failed to parse dependency file ${w}:`,G),null}}async function I(w,z){let G=[],j=w.split(`
`),q=!1;for(let H of j){let J=H.trim();if(J==="dependencies:"){q=!0;continue}if(q){if(J&&!H.startsWith(" ")&&!H.startsWith("\t")){q=!1;continue}let K=J.match(/^([\w@/-]+):\s*(.+)$/);if(K){let[,X,L]=K;G.push({name:X.trim(),currentVersion:L.trim(),type:"dependencies",file:z})}}}return G}async function S(w,z,G){try{if(!T(w))return console.log(`\u26A0\uFE0F updateDependencyFile: ${w} is not a dependency file, returning original content`),z;if(z.trim().startsWith("{")&&z.includes('"require"'))return console.log(`\u26A0\uFE0F updateDependencyFile: Content appears to be JSON (composer.json), but file is ${w}`),console.log(`Content preview: ${z.substring(0,200)}`),z;let j=z;for(let q of G){let H=q.name.replace(/\s*\(dev\)$/,"").replace(/\s*\(peer\)$/,"").replace(/\s*\(optional\)$/,""),J=new RegExp(`(\\s*\\b${H.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b\\s*:\\s*)([^\\s#\\n\\r]+)(\\s*#.*)?`,"g"),K=j.match(J);if(K){let L=K[0].match(new RegExp(`(\\s*\\b${H.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b\\s*:\\s*)([^\\s#\\n\\r]+)(\\s*#.*)?`));if(L){let $=L[1],Q=L[2],b=L[3]||"";if(((Y)=>{let R=["latest","*","main","master","develop","dev"],E=Y.toLowerCase().trim();return R.includes(E)})(Q)){console.log(`\u26A0\uFE0F Skipping update for ${H} - version "${Q}" should be respected`);continue}let Z=Q.match(/^(\D*)/),A=Z?Z[1]:"",O=/^[\^~>=<]/.test(q.newVersion)?q.newVersion:`${A}${q.newVersion}`,W=`${$}${O}${b}`;j=j.replace(J,W)}}}return j}catch(j){return console.warn(`Failed to update dependency file ${w}:`,j),z}}async function x(w){let z=[],G=new Map;for(let j of w)if(T(j.file)){if(!G.has(j.file))G.set(j.file,[]);G.get(j.file).push(j)}for(let[j,q]of G)try{let H=await import("fs");if(H.existsSync(j)){let J=H.readFileSync(j,"utf-8"),K=await S(j,J,q);if(K!==J)z.push({path:j,content:K,type:"update"}),console.log(`\u2705 Generated update for ${j} with ${q.length} package changes`);else console.log(`\u2139\uFE0F No changes needed for ${j} - versions already up to date`)}else console.warn(`\u26A0\uFE0F Dependency file ${j} does not exist`)}catch(H){console.warn(`Failed to generate updates for dependency file ${j}:`,H)}return z}
export{T as N,N as O,S as P,x as Q};

//# debugId=40ECC6D8502E36D264756E2164756E21
