var x=Object.defineProperty;var k=(t,s)=>x(t,"name",{value:s,configurable:!0});import{createRequire as B}from"node:module";import{aj as P,p as o,ak as R}from"./bin.js";import{A as V}from"../packem_shared/pm-runner-DmKT2FqF.js";import{x as C}from"../packem_shared/build-scripts-DE6U8jVq.js";import{M as y,l as w}from"../packem_shared/readFileSync-DseCu8sg-DEq4Fn3a.js";import{s as q}from"./config.js";const D=B(import.meta.url),v=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,M=k(t=>{if(typeof v<"u"&&v.versions&&v.versions.node){const[s,f]=v.versions.node.split(".").map(Number);if(s>22||s===22&&f>=3||s===20&&f>=16)return v.getBuiltinModule(t)}return D(t)},"__cjs_getBuiltinModule"),{readdirSync:_,statSync:O}=M("node:fs");var A=Object.defineProperty,S=k((t,s)=>A(t,"name",{value:s,configurable:!0}),"p$1");const N=S((t,s={})=>{const f=y(t,"node_modules");if(!w(f))return[];const l=new Map,p=new Set,b=S((n,i,a)=>{const e=`${i}@${a}`;if(p.has(e))return;p.add(e);const r=a.startsWith(t)?a.slice(t.length+1):a;let u=l.get(n);u||(u=[],l.set(n,u)),u.some($=>$.name===i)||u.push({name:i,relativePath:r})},"recordBin"),m=S((n,i="")=>{let a;try{a=_(n)}catch{return}for(const e of a){const r=y(n,e);if(e.startsWith("@")){m(r,`${e}/`);continue}if(e===".pnpm"&&i===""){let c;try{c=_(r)}catch{continue}for(const d of c){const h=y(r,d,"node_modules");w(h)&&m(h)}continue}if(e.startsWith("."))continue;const u=i+e,$=y(r,"package.json");try{if(!O(r).isDirectory()||!w($))continue;const c=q($),d=typeof c.name=="string"?c.name:u;if(typeof c.bin=="string"){const j=d.includes("/")?d.split("/").pop():d;b(j,d,r)}else if(c.bin&&typeof c.bin=="object")for(const j of Object.keys(c.bin))b(j,d,r);const h=y(r,"node_modules");w(h)&&m(h)}catch{}}},"scanDir");m(f);const g=[];for(const[n,i]of l)i.length<2||s[n]===!0||i.every(a=>s[`${a.name}#${n}`]===!0)||g.push({bin:n,packages:i});return g.sort((n,i)=>n.bin.localeCompare(i.bin))},"collectBinShadows");var T=Object.defineProperty,W=k((t,s)=>T(t,"name",{value:s,configurable:!0}),"p");const U=new Set(["bun","npm","pnpm","yarn"]),K=W(({options:t,visConfig:s,workspaceRoot:f})=>{const l=f??process.cwd(),p=V(l),b=s?.security?.policies?.installScripts?.allow??{},m=s?.security?.allowBins??{},g=s?.security?.pinVersions===!0,n=C(l,b,{pinVersions:g}),i=N(l,m),a=s&&U.has(p.name)?P(s,p.name,l):void 0;if(t.json){process.stdout.write(`${JSON.stringify({binConflicts:i,drift:a,excess:n.excess,installed:n.installed.map(e=>({hooks:e.hooks,name:e.name,version:e.version})),packageManager:p.name,pinVersions:g,unapproved:n.unapproved.map(e=>({hooks:e.hooks,name:e.name,version:e.version})),versionDrift:n.versionDrift},void 0,2)}
`);return}if(o.info(`Build-script status (${p.name}):
`),n.installed.length===0&&n.unapproved.length===0&&o.success("  No installed packages declare lifecycle scripts."),n.installed.length>0){o.success(`  Approved (${String(n.installed.length)}):`);for(const e of n.installed)o.info(`    ✓ ${e.name} — ${e.hooks.join(", ")}`)}if(n.unapproved.length>0){o.info(""),o.warn(`  Unapproved (${String(n.unapproved.length)}):`);for(const e of n.unapproved)o.info(`    ✗ ${e.name} — ${e.hooks.join(", ")}`);o.notice("    Run 'vis approve-builds' to review.")}if(n.excess.length>0){o.info(""),o.warn(`  Stale allowlist entries (${String(n.excess.length)}):`);for(const e of n.excess)o.info(`    ! ${e}`);o.notice("    Remove these from vis.config.ts security.policies.installScripts.allow.")}if(n.versionDrift.length>0){o.info(""),o.warn(`  Version drift (pinVersions: true) — ${String(n.versionDrift.length)} entr${n.versionDrift.length===1?"y":"ies"} point at outdated versions:`);for(const{from:e,to:r}of n.versionDrift)o.info(`    ${e}  →  ${r}`);o.notice("    Update vis.config.ts security.policies.installScripts.allow keys to migrate.")}if(i.length>0){o.info(""),o.warn(`  Bin conflicts (${String(i.length)}) — multiple packages expose the same bin name:`);for(const e of i)o.info(`    ${e.bin} ← ${e.packages.map(r=>r.name).join(", ")}`);o.notice("    Add the bin (or 'pkg#bin') to vis.config.ts security.allowBins to silence this.")}if(a?.hasDrift){o.info("");for(const e of R(a))o.warn(e)}},"execute");export{K as default};
