var y=Object.defineProperty;var d=(r,n)=>y(r,"name",{value:n,configurable:!0});import{createRequire as w}from"node:module";import{M as u,l as f}from"../packem_shared/readFileSync-DseCu8sg-DEq4Fn3a.js";import{s as m,E as k}from"./config.js";import{p as e}from"./bin.js";import{A as j}from"../packem_shared/pm-runner-DmKT2FqF.js";const v=w(import.meta.url),l=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=d(r=>{if(typeof l<"u"&&l.versions&&l.versions.node){const[n,s]=l.versions.node.split(".").map(Number);if(n>22||n===22&&s>=3||n===20&&s>=16)return l.getBuiltinModule(r)}return v(r)},"__cjs_getBuiltinModule"),{spawnSync:h}=$("node:child_process");var _=Object.defineProperty,c=d((r,n)=>_(r,"name",{value:n,configurable:!0}),"c");const t="@lavamoat/preinstall-always-fail",p=c(r=>{const n=u(r,"package.json");if(!f(n))return"no-package-json";try{const s=m(n);if(s.devDependencies?.[t]||s.dependencies?.[t])return"installed"}catch{}return"missing"},"tripwireStatus"),b=c(r=>{const n=u(r,"package.json");if(!f(n))return!1;try{const s=m(n);let o=!1;const a=c(i=>!i||!(t in i)?i:(o=!0,Object.fromEntries(Object.entries(i).filter(([g])=>g!==t))),"stripFrom");return s.devDependencies=a(s.devDependencies),s.dependencies=a(s.dependencies),o&&k(n,`${JSON.stringify(s,null,2)}
`),o}catch{return!1}},"removeFromPackageJson"),O=c(({options:r,workspaceRoot:n})=>{const s=n??process.cwd();if(r.status){switch(p(s)){case"installed":{e.success(`Preinstall tripwire is installed (${t}).`),e.info("Removing 'ignore-scripts=true' will cause future installs to fail loudly.");break}case"missing":{e.warn("Preinstall tripwire is not installed."),e.info(`Run 'vis security tripwire' to add ${t} as a devDependency.`);break}default:e.error("No package.json found at the workspace root."),process.exitCode=1}return}if(r.remove){b(s)?e.success(`Removed ${t} from package.json. Run your PM's install to clean node_modules.`):e.info(`${t} was not present in package.json.`);return}if(p(s)==="installed"){e.info(`${t} is already installed.`);return}const o=j(s),a={bun:["add","-d",t],npm:["install","--save-dev",t],pnpm:["add","-D","-w",t],yarn:["add","-D",t]}[o.name];if(!a){e.error(`Cannot install tripwire — unsupported package manager '${o.name}'.`),process.exitCode=1;return}e.info(`Installing ${t} via ${o.name}…`);const i=h(o.name,a,{cwd:s,stdio:"inherit"});if(i.error){e.error(`Failed to install tripwire: ${i.error.message}`),process.exitCode=1;return}if(i.signal!==null){e.error(`${o.name} was terminated by signal ${i.signal}`),process.exitCode=1;return}if(i.status!==0){e.error(`${o.name} exited with code ${String(i.status)}`),process.exitCode=i.status??1;return}e.success(`Installed ${t} as a devDependency.`),e.notice(""),e.notice("How the tripwire works:"),e.notice(`  ${t} declares a preinstall script that always fails.`),e.notice("  When 'ignore-scripts=true' is set (.npmrc / bunfig.toml / .yarnrc.yml),"),e.notice("  the script is skipped and installs succeed normally. If someone deletes"),e.notice("  that setting, the next install fails — loudly — instead of silently"),e.notice("  running every dependency's lifecycle scripts.")},"execute");export{O as default};
