import{j as W,l as B}from"./chunk-LUG2BZJP.js";import{O as v,a as O}from"./chunk-E24W34C4.js";import{f as h}from"./chunk-3QVXHF6I.js";import{d as u,g as T}from"./chunk-ELIH6GCC.js";import{$a as S,Bb as L,Fb as o,Hb as s,Pb as d,Ta as w,Ua as i,Wa as D,ma as x,ua as b}from"./chunk-EYDNSYYE.js";import{d as c,i as k}from"./chunk-773TIA5M.js";import{a as I}from"./chunk-CX5CC6P5.js";import{e as R,g}from"./chunk-VKWPEFWQ.js";g();g();function M(e,n){try{return JSON.parse(e)}catch(a){let r=a instanceof Error?a.message:String(a),t=n?` from ${n}`:"";throw new u(`Failed to parse JSON${t}.
${r}`)}}var l=R(I(),1),N="yarn.lock",j="package-lock.json",J="pnpm-lock.yaml",$="bun.lockb",C="bun.lock",V="pnpm-workspace.yaml",ke=[N,J,j,$,C],we={yarn:[N],npm:[j],pnpm:[J],bun:[$,C],homebrew:[],unknown:[]},E=["yarn","npm","pnpm","bun","homebrew","unknown"],_=class extends u{constructor(){super("Unknown package manager")}},y=class extends u{constructor(n){super(s`The directory ${o.path(n)} doesn't have a package.json.`)}},P=class extends T{constructor(n){super(s`Couldn't find a a package.json traversing directories from ${o.path(n)}`)}};function A(e=process.env){return e.npm_config_user_agent?.includes("yarn")?"yarn":e.npm_config_user_agent?.includes("pnpm")?"pnpm":e.npm_config_user_agent?.includes("bun")?"bun":e.npm_config_user_agent?.includes("npm")?"npm":"unknown"}function U(e){return i(c(e,$))||i(c(e,C))}function G(e){switch(e){case"yarn":case"npm":case"pnpm":case"bun":return e;case"homebrew":case"unknown":return"npm"}}function K(e,n,...a){switch(e){case"npm":return{command:"npm",args:["exec","--",n,...a]};case"pnpm":return{command:"pnpm",args:["exec",n,...a]};case"yarn":return{command:"yarn",args:["run",n,...a]};case"bun":return{command:"bun",args:["x",n,...a]}}}async function F(e){let n=e;for(d(s`Looking for a lockfile in ${o.path(n)}...`);;){if(i(c(n,N)))return"yarn";if(i(c(n,J))||i(c(n,V)))return"pnpm";if(U(n))return"bun";if(i(c(n,j)))return"npm";let r=k(n);if(r===n)break;n=r}let a=A();return a!=="unknown"?a:"npm"}async function he(e,n,...a){let r=G(await F(e));return K(r,n,...a)}async function ye(e){let n=await D(c(e.directory,"**/package.json"),{ignore:[c(e.directory,"node_modules/**/package.json")],cwd:e.directory,onlyFiles:!0,deep:e.deep}),a=new O;try{await Promise.all(n.map(async r=>{let t=k(r);await z({directory:t,packageManager:e.packageManager,stdout:void 0,stderr:void 0,signal:a.signal,args:[]})}))}catch(r){throw a.abort(),r}}async function z(e){let n={cwd:e.directory,stdin:void 0,stdout:e.stdout,stderr:e.stderr,signal:e.signal},a=["install"];e.args&&(a=a.concat(e.args)),await h("cmd_all_timing_network_ms")(async()=>{await v(e.packageManager,a,n)})}async function xe(e){return(await f(e)).name}async function be(e){return(await f(e)).version}async function H(e){let n=await f(e),a=n.dependencies??{},r=n.devDependencies??{};return{...a,...r}}async function ve(e){let n=c(e,"package.json"),a=await f(n),r=c(e,V);return!!a.workspaces||w(r)}async function Me(e,n,{cacheExpiryInHours:a=0}={}){let r=async()=>(d(s`Checking if there's a version of ${e} newer than ${n}`),ne(e)),t=`npm-package-${e}`,p;try{p=await W(t,r,a*3600*1e3)}catch{return}if(p&&new l.SemVer(n).compare(p)<0)return p}function _e(e,n){let a=`npm-package-${e}`,r=B(a)?.value;if(r&&new l.SemVer(n).compare(r)<0)return r}function Pe(e,n){return(0,l.satisfies)(e,n)}async function f(e){if(!await w(e))throw new y(k(e));return M(await x(e),e)}async function Y(e,n){d(s`Adding the following dependencies if needed:
${o.json(e)}
With options:
${o.json(n)}
  `);let a=c(n.directory,"package.json");if(!await w(a))throw new y(n.directory);let r=Object.keys(await H(a)),t=e.filter(p=>!r.includes(p.name));t.length!==0&&await q(t,n)}async function q(e,n){let a=e.map(r=>r.version?`${r.name}@${r.version}`:r.name);switch(n.stdout?.write(`Installing ${a.join(" ")} with ${n.packageManager}`),n.packageManager){case"npm":for(let r of a)await m(n,Q(r,n.type));break;case"yarn":await m(n,X(a,n.type,!!n.addToRootDirectory));break;case"pnpm":await m(n,Z(a,n.type,!!n.addToRootDirectory));break;case"bun":await m(n,ee(a,n.type)),await m(n,["install"]);break;case"homebrew":throw new u("Homebrew can't be used to install project dependencies. Use npm, yarn, pnpm, or bun.");case"unknown":throw new _}}async function m(e,n){return h("cmd_all_timing_network_ms")(async()=>v(e.packageManager,n,{cwd:e.directory,stdout:e.stdout,stderr:e.stderr,signal:e.signal}))}async function Ne(e,n){await Y(e.map(a=>({name:a,version:void 0})),n)}function Q(e,n){let a=["install"];switch(a=a.concat(e),n){case"dev":a.push("--save-dev");break;case"peer":a.push("--save-peer");break;case"prod":a.push("--save-prod");break}return e.match(/@\d/g)&&a.push("--save-exact"),a}function X(e,n,a=!1){let r=["add"];switch(a&&r.push("-W"),r=r.concat(e),n){case"dev":r.push("--dev");break;case"peer":r.push("--peer");break;case"prod":r.push("--prod");break}return r}function Z(e,n,a=!1){let r=["add"];switch(a&&r.push("-w"),r=r.concat(e),n){case"dev":r.push("--save-dev");break;case"peer":r.push("--save-peer");break;case"prod":r.push("--save-prod");break}return r}function ee(e,n){let a=["add"];switch(a=a.concat(e),n){case"dev":a.push("--development");break;case"peer":a.push("--optional");break;case"prod":break}return a}async function je(e){let n=await S("package.json",{cwd:e,type:"file"});if(n){let a=M(await x(n),n);return{path:n,content:a}}else throw new P(e)}async function Je(e,n){let a=await F(e),r=c(e,"package.json"),t=await f(r);a==="yarn"&&(t.resolutions=t.resolutions?{...t.resolutions,...n}:n),(a==="npm"||a==="pnpm"||a==="bun")&&(t.overrides=t.overrides?{...t.overrides,...n}:n),await b(r,JSON.stringify(t,null,2))}async function ne(e){return d(s`Getting the latest version of NPM package: ${o.raw(e)}`),h("cmd_all_timing_network_ms")(async()=>{let{default:n}=await import("./latest-version-32HXMWJ7.js");return n(e)})}async function $e(e,n){d(s`JSON-encoding and writing content to package.json at ${o.path(e)}...`);let a=c(e,"package.json");await b(a,JSON.stringify(n,null,2))}function Ce(e,n=process.env){if(e&&E.includes(e))return e;let a=A(n);if(a!=="unknown")return a;let r=L();return r!=="unknown"?r:"npm"}export{N as a,j as b,J as c,$ as d,V as e,ke as f,we as g,E as h,_ as i,y as j,P as k,A as l,F as m,he as n,ye as o,z as p,xe as q,be as r,H as s,ve as t,Me as u,_e as v,Pe as w,f as x,Y as y,q as z,Ne as A,je as B,Je as C,$e as D,Ce as E};
