import{c as w}from"./chunk-ICFFBMFB.js";import{c as F,e as x}from"./chunk-ZNWFTUFV.js";import{B as h,m as S,t as L,u as P,v as f,z as N}from"./chunk-VRRDIXFQ.js";import{o as $,q as m}from"./chunk-LUG2BZJP.js";import{a as c}from"./chunk-J3KRY2SD.js";import{O as V,S as y,v as R}from"./chunk-E24W34C4.js";import{Bb as U,Cb as D,Fb as u,Hb as p,Mb as d,Pb as l,Qb as E,yb as A}from"./chunk-EYDNSYYE.js";import{c as _}from"./chunk-JCNRQYRP.js";import{p as C,q as b,r as I}from"./chunk-773TIA5M.js";import{g as v}from"./chunk-VKWPEFWQ.js";v();function M(){let e=U();if(!(!e||e==="unknown"))return e==="homebrew"?"brew upgrade shopify-cli":e==="yarn"?`${e} global add @shopify/cli@latest`:`${e} ${e==="pnpm"?"add":"install"} -g @shopify/cli@latest`}async function re(e={}){let n=I()??b(),o=D(n),t=A();if(_()){d("Skipping upgrade in development mode.");return}if(!(e.autoupgrade&&!t))if(t){let a=M();if(!a)throw new Error("Could not determine the package manager");let[r,...i]=a.split(" ");if(!r)throw new Error("Could not determine the command to run");let s=f("@shopify/cli",c),T=s?`\u2728 New version of Shopify CLI available! (${c} \u2192 ${s})`:"\u2728 New version of Shopify CLI available!";d(p`${T}
   Now upgrading by running: ${u.genericShellCommand(a)}...`),await V(r,i,{stdio:"inherit"}),R({headline:"Shopify CLI upgraded.",body:s?`You're now on version ${s}.`:"You're now on the latest version."})}else if(o)await Y(o,c);else throw new Error("Could not determine the local project directory")}function ie(){let e=c,n=f("@shopify/cli",e);if(!n){l("Auto-upgrade: No newer version available.");return}if(process.env.SHOPIFY_CLI_FORCE_AUTO_UPGRADE==="1")return l("Auto-upgrade: Forcing auto-upgrade because of SHOPIFY_CLI_FORCE_AUTO_UPGRADE."),n;if(!m()){l("Auto-upgrade: Skipping because auto-upgrade is not enabled.");return}if(y()){l("Auto-upgrade: Skipping auto-upgrade in CI.");return}if(w(e)){l("Auto-upgrade: Skipping auto-upgrade for pre-release version.");return}return n}async function se(){try{let{notifications:e}=await F();return x(e,"",["autoupgrade"]).some(o=>o.type==="error")}catch{return!1}}async function ce(){if(y()||w(c)||m())return;let e=f("@shopify/cli",c);e&&await $("warn-on-available-upgrade",{days:1},async()=>{E(G(e))})}function G(e,n=!1){let o=M(),t=o?p`💡 Version ${e} available! Run ${u.genericShellCommand(o)}`.value:p`💡 Version ${e} available!`.value;if(n){let a=`https://github.com/Shopify/cli/releases/tag/${e}`,r=p`⚠️  This is a major version — review breaking changes before upgrading:\n   ${u.link(a,a)}`.value;return`${t}

${r}`}return t}async function Y(e,n){let o=(await h(e)).content,t=o.dependencies??{},a=o.devDependencies??{},i={...t,...a}[await k()];if(!i){l("Auto-upgrade: CLI dependency not found in project dependencies, skipping local upgrade.");return}i.slice(0,1).match(/[\^~]/)&&(i=n);let s=await P(await k(),i);s?q(i,s):W(i),await J("prod",t,e),await J("dev",a,e)}async function J(e,n,o){let t=[await k(),...await j()].filter(r=>!!n[r]).map(r=>({name:r,version:"latest"})),a=await L(o);t.length>0&&await N(t,{packageManager:await S(o),type:e,directory:o,stdout:process.stdout,stderr:process.stderr,addToRootDirectory:a})}async function k(){return(await O()).name}async function j(){return(await O())?.oclif?.plugins??[]}var g;async function O(){if(!g){let e=await h(C(import.meta.url));g=g??e.content}return g}function W(e){d(p`You're on the latest version, ${u.yellow(e)}, no need to upgrade!`)}function q(e,n){d(p`Upgrading CLI from ${u.yellow(e)} to ${u.yellow(n)}...`)}export{M as a,re as b,ie as c,se as d,ce as e,G as f};
