// @bun
import{B as J,F as L}from"./chunk-hggcmr0j.js";function R(q){let z=q.split("/").pop()||"";return z==="composer.json"||z==="composer.lock"}async function S(q,z){try{let j=JSON.parse(z),A=[];if(j.require)Z(j.require,"require",q,A);if(j["require-dev"])Z(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 _(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 B(q,z){let j=q.split("/").pop()||"";if(j==="composer.json")return S(q,z);if(j==="composer.lock")return _(q,z);return null}function Z(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 M(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 O=(await import("fs")).readFileSync(b,"utf-8"),Q=JSON.parse(O);for(let E of W){let T=!1;if(Q.require&&Q.require[E.name]){let H=Q.require[E.name],K;if(H.includes(","))K=H.replace(/\d+\.\d+(?:\.\d+)?/g,(G)=>{return G===H.match(/\d+\.\d+(?:\.\d+)?/)?.[0]?E.newVersion:G});else{let G=H.match(/^(\D*)/);K=`${G?G[1]:""}${E.newVersion}`}let X=new RegExp(`("${E.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"\\s*:\\s*")([^"]+)(")`,"g");O=O.replace(X,`$1${K}$3`),T=!0}if(!T&&Q["require-dev"]&&Q["require-dev"][E.name]){let H=Q["require-dev"][E.name],K;if(H.includes(","))K=H.replace(/\d+\.\d+(?:\.\d+)?/g,(G)=>{return G===H.match(/\d+\.\d+(?:\.\d+)?/)?.[0]?E.newVersion:G});else{let G=H.match(/^(\D*)/);K=`${G?G[1]:""}${E.newVersion}`}let X=new RegExp(`("${E.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"\\s*:\\s*")([^"]+)(")`,"g");O=O.replace(X,`$1${K}$3`),T=!0}if(!T)console.warn(`Package ${E.name} not found in ${b}`)}z.push({path:b,content:O,type:"update"})}catch(Y){console.error(`Failed to update ${b}:`,Y)}return z}export{_ as parseComposerLock,S as parseComposerJson,B as parseComposerFile,R as isComposerFile,M as generateComposerUpdates};
