// @bun
import"./chunk-bqh4yh6g.js";import{readFileSync as $}from"fs";function R(q){let z=q.split("/").pop()||"";return z==="composer.json"||z==="composer.lock"}async function J(q,z){try{let j=JSON.parse(z),A=[];if(j.require)Y(j.require,"require",q,A);if(j["require-dev"])Y(j["require-dev"],"require-dev",q,A);return{path:q,type:"composer.json",content:z,dependencies:A}}catch(j){return console.warn(`Failed to parse composer.json file ${q}:`,j),null}}async function L(q,z){try{let j=JSON.parse(z),A=[];if(j.packages){for(let b of j.packages)if(b.name&&b.version)A.push({name:b.name,currentVersion:b.version,type:"require",file:q})}if(j["packages-dev"]){for(let b of j["packages-dev"])if(b.name&&b.version)A.push({name:b.name,currentVersion:b.version,type:"require-dev",file:q})}return{path:q,type:"composer.lock",content:z,dependencies:A}}catch(j){return console.warn(`Failed to parse composer.lock file ${q}:`,j),null}}async function S(q,z){let j=q.split("/").pop()||"";if(j==="composer.json")return J(q,z);if(j==="composer.lock")return L(q,z);return null}function Y(q,z,j,A){for(let[b,W]of Object.entries(q)){if(b==="php"||b.startsWith("ext-"))continue;if(b.includes("/"))A.push({name:b,currentVersion:W,type:z,file:j})}}async function B(q){let z=[],j=q.filter((b)=>b.file.endsWith("composer.json"));if(j.length===0)return z;let A=new Map;for(let b of j){if(!A.has(b.file))A.set(b.file,[]);A.get(b.file).push({name:b.name,newVersion:b.newVersion})}for(let[b,W]of A)try{let K=$(b,"utf-8"),Q=JSON.parse(K);for(let E of W){let T=!1;if(Q.require&&Q.require[E.name]){let H=Q.require[E.name],O;if(H.includes(","))O=H.replace(/\d+\.\d+(?:\.\d+)?/g,(G)=>{return G===H.match(/\d+\.\d+(?:\.\d+)?/)?.[0]?E.newVersion:G});else{let G=H.match(/^(\D*)/);O=`${G?G[1]:""}${E.newVersion}`}let X=new RegExp(`("${E.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"\\s*:\\s*")([^"]+)(")`,"g");K=K.replace(X,`$1${O}$3`),T=!0}if(!T&&Q["require-dev"]&&Q["require-dev"][E.name]){let H=Q["require-dev"][E.name],O;if(H.includes(","))O=H.replace(/\d+\.\d+(?:\.\d+)?/g,(G)=>{return G===H.match(/\d+\.\d+(?:\.\d+)?/)?.[0]?E.newVersion:G});else{let G=H.match(/^(\D*)/);O=`${G?G[1]:""}${E.newVersion}`}let X=new RegExp(`("${E.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"\\s*:\\s*")([^"]+)(")`,"g");K=K.replace(X,`$1${O}$3`),T=!0}if(!T)console.warn(`Package ${E.name} not found in ${b}`)}z.push({path:b,content:K,type:"update"})}catch(K){console.error(`Failed to update ${b}:`,K)}return z}export{L as parseComposerLock,J as parseComposerJson,S as parseComposerFile,R as isComposerFile,B as generateComposerUpdates};

//# debugId=E7A8E0CA3AAA396164756E2164756E21
