// @bun
import{Zb as _}from"./chunk-bqh4yh6g.js";function W(w){let q=w.split("/").pop()||"";if(["Dockerfile","dockerfile","Dockerfile.dev","Dockerfile.prod","Dockerfile.production","Dockerfile.development","Dockerfile.test","Dockerfile.staging"].includes(q))return!0;return q.startsWith("Dockerfile")||q.startsWith("dockerfile")}async function x(w,q){try{if(!W(w))return null;let z=[],j=q.split(`
`);for(let E=0;E<j.length;E++){let A=j[E].trim();if(!A||A.startsWith("#"))continue;let G=A.match(/^FROM\s+(\S+)(?:\s+as\s+\w+)?$/i);if(G){let J=G[1];if(J==="scratch"||J.startsWith("$"))continue;let K=$(J);if(K)z.push({name:K.name,currentVersion:K.version,type:"docker-image",file:w})}if(A.match(/^RUN\s+(.+)$/i)){let J=O();z.push(...J)}}return{path:w,type:"Dockerfile",content:q,dependencies:z}}catch(z){return console.warn(`Failed to parse Dockerfile ${w}:`,z),null}}function $(w){try{let q,z;if(w.includes(":")){let j=w.lastIndexOf(":"),E=w.substring(0,j),A=w.substring(j+1);if(/^\d+\//.test(A))q=w,z="latest";else q=E,z=A}else q=w,z="latest";if(z.includes("$")||z.startsWith("sha256:"))return null;return{name:q,version:z}}catch(q){return console.warn(`Failed to parse image reference ${w}:`,q),null}}function O(){return[]}async function B(w){try{let q=w.replace(/^docker\.io\//,"").replace(/^library\//,""),z;if(!q.includes("/"))z=`https://registry.hub.docker.com/v2/repositories/library/${q}/tags/?page_size=100`;else z=`https://registry.hub.docker.com/v2/repositories/${q}/tags/?page_size=100`;let j=await fetch(z);if(!j.ok)return console.warn(`Failed to fetch tags for ${w}: ${j.status}`),null;let E=await j.json();if(!E.results||!Array.isArray(E.results))return null;let A=E.results.map((G)=>G.name).filter((G)=>{if(G==="latest"||G.includes("rc")||G.includes("beta")||G.includes("alpha"))return!1;return/^\d+(?:\.\d+)*(?:-\w+)?$/.test(G)}).sort((G,L)=>{let J=G.split(".").map(Number),K=L.split(".").map(Number);for(let H=0;H<Math.max(J.length,K.length);H++){let Q=J[H]||0,S=K[H]||0;if(Q!==S)return S-Q}return 0});return A.length>0?A[0]:null}catch(q){return console.warn(`Failed to fetch latest version for Docker image ${w}:`,q),null}}async function M(w,q,z){try{if(!W(w))return console.log(`\u26A0\uFE0F updateDockerfile: ${w} is not a Dockerfile, returning original content`),q;let j=q;for(let E of z){if(E.dependencyType!=="docker-image")continue;let A=E.name.replace(/\s*\(.*\)$/,""),G=A.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),L=new RegExp(`(FROM\\s+${G})(:)([^\\s]+)(\\s.*)?$`,"gim"),J=(H)=>{let Q=["latest","main","master","develop","dev","stable"],S=H.toLowerCase().trim();return Q.includes(S)},K=j.matchAll(L);for(let H of K){let Q=H[0],S=H[1],X=H[2],T=H[3],Y=H[4]||"";if(J(T)){console.log(`\u26A0\uFE0F Skipping update for ${A} - version "${T}" should be respected`);continue}let Z=`${S}${X}${E.newVersion}${Y}`;j=j.replace(Q,Z),console.log(`\uD83D\uDCDD Updated ${A}: ${T} \u2192 ${E.newVersion}`)}}return j}catch(j){return console.warn(`Failed to update Dockerfile ${w}:`,j),q}}async function D(w){let q=[],z=new Map;for(let j of w)if(j.dependencyType==="docker-image"&&W(j.file)){if(!z.has(j.file))z.set(j.file,[]);z.get(j.file).push(j)}for(let[j,E]of z)try{let A=await import("fs");if(A.existsSync(j)){let G=A.readFileSync(j,"utf-8"),L=await M(j,G,E);if(L!==G)q.push({path:j,content:L,type:"update"}),console.log(`\u2705 Generated update for ${j} with ${E.length} image changes`);else console.log(`\u2139\uFE0F No changes needed for ${j} - versions already up to date`)}else console.warn(`\u26A0\uFE0F Dockerfile ${j} does not exist`)}catch(A){console.warn(`Failed to generate updates for Dockerfile ${j}:`,A)}return q}
export{W as p,x as q,B as r,M as s,D as t};

//# debugId=B8D8F37DBFB8BE7164756E2164756E21
