var X=Object.defineProperty;var w=(e,o)=>X(e,"name",{value:o,configurable:!0});import{createRequire as Q}from"node:module";import{q as S,E as m,j as R,e as F,T as H,I as E}from"../packem_shared/Table-3pFgIUZ2-DABgc6rj.js";import{M as b,a as M,l as ee}from"../packem_shared/readFileSync-DseCu8sg-DEq4Fn3a.js";import{o as B,s as oe,C as q,S as te}from"./bin.js";import{d as ne}from"../packem_shared/lockfile-Cu2BH6bl.js";import{s as re,p as se}from"../packem_shared/docker-EJiTY0Sz.js";import{b as ue}from"./config.js";const Z=Q(import.meta.url),x=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,N=w(e=>{if(typeof x<"u"&&x.versions&&x.versions.node){const[o,t]=x.versions.node.split(".").map(Number);if(o>22||o===22&&t>=3||o===20&&t>=16)return x.getBuiltinModule(e)}return Z(e)},"__cjs_getBuiltinModule"),{createInterface:L}=N("node:readline"),{spawn:ie}=N("node:child_process"),{createHash:ae}=N("node:crypto"),{existsSync:V,writeFileSync:le,chmodSync:ce}=N("node:fs");var de=Object.defineProperty,$=w((e,o)=>de(e,"name",{value:o,configurable:!0}),"n$1");const C={aube:{base:["RUN corepack enable"],build:$(e=>e?`RUN aube run --filter ${e} build`:"RUN aube run build","build"),install:"RUN aube install --frozen-lockfile"},bun:{base:["RUN npm install -g bun"],build:$(e=>e?`RUN bun run --filter ${e} build`:"RUN bun run build","build"),install:"RUN --mount=type=cache,target=/root/.bun/install/cache bun install --frozen-lockfile"},npm:{base:[],build:$(e=>e?`RUN npm run build --workspace ${e}`:"RUN npm run build","build"),install:"RUN --mount=type=cache,target=/root/.npm npm ci"},pnpm:{base:["ENV PNPM_HOME=/pnpm","ENV PATH=$PNPM_HOME:$PATH","RUN corepack enable"],build:$(e=>e?`RUN pnpm --filter ${e} build`:"RUN pnpm build","build"),install:"RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile"},yarn:{base:["RUN corepack enable"],build:$(e=>e?`RUN yarn workspace ${e} build`:"RUN yarn build","build"),install:"RUN --mount=type=cache,target=/usr/local/share/.cache/yarn yarn install --immutable"}},fe=$(e=>{const{focus:o,manager:t,nodeVersion:r}=e,n=C[t]??C.npm;return["# syntax=docker/dockerfile:1","","# Generated by 'vis docker init'. Before building, scaffold the context:",`#   vis docker scaffold${o?` --focus=${o}`:""} --include-sources`,"# then build with BuildKit enabled (DOCKER_BUILDKIT=1).","",`FROM node:${r}-slim AS base`,"WORKDIR /app",...n.base,"","# --- install dependencies from the scaffolded manifests only ---","FROM base AS deps","COPY .vis/docker/workspace/ ./",n.install,"","# --- build the focus project, then drop unfocused workspace projects ---","FROM deps AS build","COPY .vis/docker/sources/ ./",n.build(o),"RUN npx vis docker prune --context=.vis/docker","","# --- minimal runtime image ---",`FROM node:${r}-slim AS runtime`,"WORKDIR /app","ENV NODE_ENV=production","COPY --from=build /app ./","USER node","# TODO: point this at your app's entrypoint",'CMD ["node", "index.js"]',""].join(`
`)},"generateDockerfile");var pe=Object.defineProperty,g=w((e,o)=>pe(e,"name",{value:o,configurable:!0}),"i$1");const D="v2.14.0",U=`https://github.com/hadolint/hadolint/releases/download/${D}`,me=g((e=process.platform,o=process.arch)=>{const t=e==="darwin"?"macos":e==="linux"?"linux":e==="win32"?"windows":void 0;if(t===void 0)return;const r=o==="arm64"?"arm64":o==="x64"?"x86_64":void 0;if(t==="windows")return"hadolint-windows-x86_64.exe";if(r!==void 0)return`hadolint-${t}-${r}`},"resolveHadolintAsset"),K=g(e=>b(B(),"hadolint",D,e.endsWith(".exe")?"hadolint.exe":"hadolint"),"cachedBinaryPath"),ge=g(()=>{const e=process.platform==="win32"?"hadolint.exe":"hadolint",o=(process.env.PATH??"").split(process.platform==="win32"?";":":");for(const t of o)if(t!==""&&V(b(t,e)))return e},"findOnPath"),he=g(e=>e.trim().split(/\s+/u)[0]??"","parseSha256Sidecar"),A=g(async e=>{const o=await fetch(e,{redirect:"follow"});if(!o.ok)throw new Error(`download failed (${String(o.status)} ${o.statusText}) for ${e}`);return Buffer.from(await o.arrayBuffer())},"fetchBuffer"),we=g(async e=>{const o=K(e),[t,r]=await Promise.all([A(`${U}/${e}`),A(`${U}/${e}.sha256`)]),n=he(r.toString("utf8")).toLowerCase(),s=ae("sha256").update(t).digest("hex");if(n==="")throw new Error("hadolint checksum sidecar was empty or unparseable. Refusing to use the download.");if(n!==s)throw new Error(`hadolint checksum mismatch (expected ${n}, got ${s}). Refusing to use the download.`);return ue(b(B(),"hadolint",D)),le(o,t),process.platform!=="win32"&&ce(o,493),o},"downloadHadolint"),be=g(async()=>{const e=L({input:process.stdin,output:process.stderr}),o=await new Promise(t=>{e.question(`  Download hadolint ${S(D)} now? ${m("[y/N]")} `,r=>{t(r.trim().toLowerCase())})});return e.close(),o==="y"||o==="yes"},"confirmInstall"),$e=g(async e=>{const{autoInstall:o=!1,log:t}=e,r=ge();if(r!==void 0)return r;const n=me();if(n===void 0){t(`hadolint has no prebuilt binary for ${process.platform}/${process.arch}. Install it manually: https://github.com/hadolint/hadolint`);return}const s=K(n);if(V(s))return s;if(!o){if(!(process.stdin.isTTY&&!oe)){t(`hadolint is not installed. Re-run with ${R("--install")} (or install hadolint on PATH) to enable Dockerfile linting.`);return}if(t(`${R("hadolint")} is required to lint Dockerfiles but was not found on your PATH.`),!await be()){t(`Skipped. Install it yourself or re-run with ${R("--install")}.`);return}}t(`Downloading hadolint ${D} (${n})…`);try{const i=await we(n);return t(`Installed hadolint to ${m(i)}`),i}catch(i){t(`Failed to download hadolint: ${i.message}`);return}},"ensureHadolint"),_=g(async(e,o,t)=>{if(o.length===0)return[];const r=["--format","json","--no-fail",...t!==void 0&&t!==""?["--config",t]:[],...o],n=await new Promise((i,c)=>{const a=ie(e,r,{shell:process.platform==="win32",stdio:["ignore","pipe","pipe"],windowsHide:!0});let u="",d="";a.stdout?.on("data",l=>{u+=l.toString("utf8")}),a.stderr?.on("data",l=>{d+=l.toString("utf8")}),a.on("error",c),a.on("close",()=>{if(u.trim()===""&&d.trim()!==""){c(new Error(d.trim()));return}i(u)})});if(n.trim()==="")return[];let s;try{s=JSON.parse(n)}catch{throw new Error("Could not parse hadolint JSON output.")}return Array.isArray(s)?s:[]},"runHadolint");var ye=Object.defineProperty,y=w((e,o)=>ye(e,"name",{value:o,configurable:!0}),"n");const T=y((e,o,t)=>{if(!(!/\bapt-get\b/u.test(e)||!/\binstall\b/u.test(e)||t.test(e)))return e.replace(/\binstall\b/u,`install ${o}`)},"addAptGetInstallFlag"),j={DL3014:y(e=>T(e,"-y",/(?:^|\s)(?:-y|--yes|--assume-yes|-qq?)\b/u),"DL3014"),DL3015:y(e=>T(e,"--no-install-recommends",/--no-install-recommends\b/u),"DL3015"),DL3020:y(e=>/^\s*ADD\b/u.test(e)?e.replace(/^(\s*)ADD\b/u,"$1COPY"):void 0,"DL3020"),DL3027:y(e=>/(?:^|\s)apt\s/u.test(e)&&!/\bapt-get\b/u.test(e)?e.replace(/(^|\s)apt(\s)/u,"$1apt-get$2"):void 0,"DL3027")},Y=new Set(Object.keys(j)),ke=y((e,o)=>{const t=e.includes(`\r
`)?`\r
`:`
`,r=e.split(/\r?\n/u),n=new Set;let s=0;const i=new Map;for(const c of o){if(!j[c.code])continue;const a=i.get(c.line)??[];a.push(c),i.set(c.line,a)}for(const[c,a]of i){const u=c-1;if(!(u<0||u>=r.length))for(const d of a){const l=j[d.code],f=l?.(r[u]??"");f!==void 0&&f!==r[u]&&(r[u]=f,n.add(d.code),s+=1)}}return{content:s>0?r.join(t):e,fixedCodes:[...n],fixedCount:s}},"applyFixers");var ve=Object.defineProperty,k=w((e,o)=>ve(e,"name",{value:o,configurable:!0}),"a");const I={error:0,info:2,style:3,warning:1},xe=k((e,o)=>{switch(e){case"error":return H(o);case"info":return S(o);case"warning":return F(o);default:return m(o)}},"colorForLevel"),Re=k((e,o)=>(e.length>0?e:["Dockerfile"]).map(t=>M(t)?t:b(o,t)).filter(t=>ee(t)),"resolveFiles"),De=k((e,o)=>{const t=[...e].sort((n,s)=>n.file.localeCompare(s.file)||n.line-s.line||n.column-s.column||I[n.level]-I[s.level]);let r="";for(const n of t){n.file!==r&&(r=n.file,o.info(`
${R(r)}`));const s=m(`${String(n.line)}:${String(n.column)}`),i=xe(n.level,n.level.padEnd(7)),c=Y.has(n.code)?m(" (fixable)"):"";o.info(`  ${s}  ${i}  ${S(n.code)}  ${n.message}${c}`)}},"renderFindings"),Ne=k(e=>{const o={error:0,info:0,style:0,warning:0};for(const t of e)o[t.level]+=1;return o},"summarize"),Se=k(async e=>{const{autoInstall:o,configPath:t,cwd:r,files:n,fix:s,fs:i,json:c,logger:a}=e,u=Re(n,r);if(u.length===0)return a.error(`No Dockerfile found${n.length>0?` at: ${n.join(", ")}`:` in ${r}`}. Pass a path: vis docker lint <path>`),1;const d=await $e({autoInstall:o,log:k(p=>{a.info(p)},"log")});if(d===void 0)return 0;let l=await _(d,u,t),f=0;if(s&&l.length>0){for(const p of u){const W=l.filter(G=>G.file===p),J=await i.readFile(p,"utf8"),O=ke(J,W);O.fixedCount>0&&(await i.writeFile(p,O.content),f+=O.fixedCount)}f>0&&(l=await _(d,u,t))}if(c)return process.stdout.write(`${JSON.stringify({findings:l,fixed:f},null,2)}
`),l.some(p=>p.level==="error")?1:0;if(s&&f>0&&a.info(E(`✔ Auto-fixed ${String(f)} issue${f===1?"":"s"}.`)),l.length===0)return a.info(E("✔ No Dockerfile issues found.")),0;De(l,a);const v=Ne(l),P=l.filter(p=>Y.has(p.code)).length;return a.info(`
${R(String(l.length))} issue${l.length===1?"":"s"}: ${H(`${String(v.error)} error`)}, ${F(`${String(v.warning)} warning`)}, ${S(`${String(v.info)} info`)}, ${m(`${String(v.style)} style`)}`),!s&&P>0&&a.info(m(`Run 'vis docker lint --fix' to auto-fix ${String(P)} of them.`)),v.error>0?1:0},"runDockerLint");var Oe=Object.defineProperty,h=w((e,o)=>Oe(e,"name",{value:o,configurable:!0}),"i");const z=h(e=>{if(!e)throw new Error("Could not determine workspace root. Run inside a monorepo.");return e},"requireWorkspaceRoot"),Fe=h(async({logger:e,options:o,visConfig:t,workspaceRoot:r})=>{const n=z(r),{packageJsons:s,workspace:i}=q(n,t),c=te(n,i,s),a=(o.focus??"").split(",").map(l=>l.trim()).filter(Boolean);if(a.length===0)throw new Error("Missing --focus. Pass one or more project names, comma-separated.");const u=b(n,o.out??".vis/docker"),{projects:d}=re({focus:a,includeSources:!!o.includeSources,log:h(l=>{e.info(l)},"log"),outDir:u,projectGraph:c,pruneLockfile:o.pruneLockfile!==!1,workspace:i,workspaceRoot:n});e.info(`Scaffolded ${d.length} project(s) into ${u}`),e.info(`Focus closure: ${d.toSorted().join(", ")}`)},"scaffoldExecute"),He=h(async({logger:e,options:o,visConfig:t,workspaceRoot:r})=>{const n=z(r),{workspace:s}=q(n,t),i=b(n,o.context??".vis/docker"),{removed:c}=se({contextRoot:i,workspace:s,workspaceRoot:n});e.info(`Pruned ${c.length} unfocused project(s)`),c.length>0&&e.debug?.(c.join(`
`))},"pruneExecute"),Me=h(async({argument:e,fs:o,logger:t,options:r,process:n,workspaceRoot:s})=>{const i=await Se({autoInstall:!!r.install,configPath:r.config,cwd:s??n.cwd,files:e.filter(Boolean),fix:!!r.fix,fs:o,json:!!r.json,logger:t});i!==0&&(process.exitCode=i)},"lintExecute"),je=h(async(e,o)=>{try{return await e.access(o),!0}catch{return!1}},"canAccess"),Pe=h(async e=>{const o=L({input:process.stdin,output:process.stderr}),t=await new Promise(r=>{o.question(`  ${e} already exists. Overwrite? ${m("[y/N]")} `,n=>{r(n.trim().toLowerCase())})});return o.close(),t==="y"||t==="yes"},"confirmOverwrite"),Be=h(async({argument:e,fs:o,logger:t,options:r,process:n,workspaceRoot:s})=>{const i=s??n.cwd,c=e[0]??"Dockerfile",a=M(c)?c:b(i,c),u=ne(i)?.manager??"npm",d=(r.focus??"").split(",").map(f=>f.trim()).find(Boolean),l=fe({focus:d,manager:u,nodeVersion:r.node??"22"});if(r.dryRun){process.stdout.write(l.endsWith(`
`)?l:`${l}
`);return}if(await je(o,a)&&!r.force){if(!process.stdin.isTTY){t.error(`${a} already exists. Re-run with --force to overwrite.`),process.exitCode=1;return}if(!await Pe(a)){t.info("Aborted — existing Dockerfile left untouched.");return}}await o.writeFile(a,l),t.info(`Created ${a} (package manager: ${u}).`),t.info(m(`Next: vis docker scaffold${d?` --focus=${d}`:""} --include-sources, then DOCKER_BUILDKIT=1 docker build .`))},"initExecute");export{Be as initExecute,Me as lintExecute,He as pruneExecute,Fe as scaffoldExecute};
