ts-pantry 0.11.39 → 0.11.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{E as Ie,L as Oe,M as ie,O as re,Qa as Me,Ra as Re,S as oe,Ta as Le,Wa as Ve,Ya as Fe,bb as ze,cb as We,db as Ue,ga as Ee,ha as Te,ia as Ae,ja as _e,ka as Pe,oa as ae,pa as Be,qa as Ne}from"../chunk-3dbeqd3c.js";import"../chunk-nfdg722p.js";import"../chunk-afzfbcrx.js";import"../chunk-w55vdzzf.js";import{Ib as U,Jb as je,Lb as se,Mb as G,Rb as De,Vb as ne}from"../chunk-5y7jxjtz.js";import"../chunk-415b756j.js";import"../chunk-agh1vkqm.js";import{mc as W,nc as ee,oc as te}from"../chunk-rqny4g8r.js";import"../chunk-p763mye8.js";import"../chunk-8rg91cqd.js";import{Kc as Ce,Lc as zt}from"../chunk-hxd34yh9.js";import{Pc as N}from"../chunk-a20hctx6.js";import d from"node:fs";import y from"node:path";import u from"node:process";import{existsSync as He}from"node:fs";import q from"node:fs/promises";import ue from"node:os";import H from"node:path";import B from"node:process";import{EventEmitter as Ke}from"node:events";import j from"node:process";import he from"node:process";import Y from"node:process";import F from"node:process";import L from"node:process";import me from"node:tty";import Nt,{stdin as ps,stdout as fs}from"node:process";class ge{configPath;config=null;events=[];retryCount=0;maxRetries=3;retryDelayMs=1000;constructor(){let e=ue.homedir(),t=H.join(e,".config","clapp");this.configPath=H.join(t,"telemetry.json")}async isEnabled(){if(B.env.DO_NOT_TRACK==="1"||B.env.DO_NOT_TRACK==="true")return!1;if(B.env.NO_TELEMETRY==="1"||B.env.NO_TELEMETRY==="true")return!1;return(await this.loadConfig()).enabled}async enable(){let e=await this.loadConfig();if(e.enabled=!0,!e.userId)e.userId=this.generateUserId();await this.saveConfig(e)}async disable(){let e=await this.loadConfig();e.enabled=!1,await this.saveConfig(e)}async track(e,t){if(!await this.isEnabled())return;let n={event:e,...t,timestamp:Date.now(),platform:ue.platform(),nodeVersion:B.version};if(this.events.push(n),this.events.length>=10)await this.send()}async trackCommand(e,t){await this.track("command",{command:e,duration:t})}async trackError(e,t){await this.track("error",{error:e,command:t})}async send(){if(!await this.isEnabled()||this.events.length===0)return!0;try{this.events=[],this.retryCount=0;let t=await this.loadConfig();return t.lastSent=Date.now(),await this.saveConfig(t),!0}catch{if(this.retryCount<this.maxRetries){this.retryCount++;let t=this.retryDelayMs*2**(this.retryCount-1);return await this.sleep(t),this.send()}return this.events=[],this.retryCount=0,!1}}async flush(){if(this.events.length===0)return!0;return this.send()}sleep(e){return new Promise((t)=>setTimeout(t,e))}async status(){let e=await this.loadConfig();return{enabled:e.enabled,doNotTrack:B.env.DO_NOT_TRACK==="1"||B.env.DO_NOT_TRACK==="true",eventsQueued:this.events.length,lastSent:e.lastSent}}async loadConfig(){if(this.config)return this.config;try{if(He(this.configPath)){let e=await q.readFile(this.configPath,"utf-8");return this.config=JSON.parse(e),this.config}}catch{}return this.config={enabled:!1},this.config}async saveConfig(e){this.config=e;try{let t=H.dirname(this.configPath);await q.mkdir(t,{recursive:!0}),await q.writeFile(this.configPath,JSON.stringify(e,null,2),"utf-8")}catch{}}generateUserId(){let e=Math.random().toString(36).substring(2,15),t=Date.now().toString(36);return`${e}-${t}`}}var es=new ge;function Je(e,t={}){let s={_:[]},n=t.alias||{},i=new Set(t.boolean||[]),r={};for(let l of Object.keys(n))for(let o of n[l])r[o]=l;for(let l of i)if(n[l])for(let o of n[l])i.add(o);function a(l,o){let c=r[l]||l;if(s[c]=o,n[c])for(let p of n[c])s[p]=o;if(r[l]&&n[r[l]])for(let p of n[r[l]])s[p]=o;s[l]=o}for(let l=0;l<e.length;l++){let o=e[l];if(o==="--"){s._.push(...e.slice(l+1));break}if(o.startsWith("--")){let c=o.indexOf("=");if(c!==-1){let p=o.slice(2,c),g=o.slice(c+1);a(p,g)}else{let p=o.slice(2);if(p.startsWith("no-")){let h=p.slice(3);a(h,!1);continue}let g=r[p]||p;if(i.has(g)||i.has(p))a(p,!0);else{let h=e[l+1];if(h!==void 0&&!h.startsWith("-"))a(p,h),l++;else a(p,!0)}}}else if(o.startsWith("-")&&o.length>1){let c=o.slice(1);for(let p=0;p<c.length;p++){let g=c[p],h=r[g]||g;if(p===c.length-1&&!i.has(h)&&!i.has(g)){let f=e[l+1];if(f!==void 0&&!f.startsWith("-"))a(g,f),l++;else a(g,!0)}else a(g,!0)}}else s._.push(o)}return s}function J(e){return e.replace(/[<[].+/,"").trim()}function Ye(e){let t=/<([^>]+)>/g,s=/\[([^\]]+)\]/g,n=[],i=(l)=>{let o=!1,c=l[1];if(c.startsWith("..."))c=c.slice(3),o=!0;return{required:l[0].startsWith("<"),value:c,variadic:o}},r;while(r=t.exec(e))n.push(i(r));let a;while(a=s.exec(e))n.push(i(a));return n}function Ze(e){let t={alias:{},boolean:[]};for(let[s,n]of e.entries()){if(n.names.length>1)t.alias[n.names[0]]=n.names.slice(1);if(n.isBoolean)if(n.negated){if(!e.some((r,a)=>a!==s&&r.names.some((l)=>n.names.includes(l))&&typeof r.required==="boolean"))t.boolean.push(n.names[0])}else t.boolean.push(n.names[0])}return t}function de(e){return e.reduce((t,s)=>t.length>=s.length?t:s,"")}function K(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function Xe(e){return e.replace(/([a-z])-([a-z])/g,(t,s,n)=>s+n.toUpperCase())}function Qe(e,t,s){let n=0,i=t.length,r=e,a;for(;n<i;++n)a=r[t[n]],r=r[t[n]]=n===i-1?s:a!=null?a:!!~t[n+1].indexOf(".")||!(+t[n+1]>-1)?{}:[]}function et(e,t){for(let s of Object.keys(t)){let n=t[s];if(n.shouldTransform){if(e[s]=Array.prototype.concat.call([],e[s]),typeof n.transformFunction==="function")e[s]=e[s].map(n.transformFunction)}}}function tt(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function ye(e){return e.split(".").map((t,s)=>s===0?Xe(t):t).join(".")}class V extends Error{exitCode=2;isUsageError=!0;constructor(e){super(e);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}format(e=!1){if(e&&this.stack)return`${this.message}
2
+ import{E as Ie,L as Oe,M as ie,O as re,Qa as Me,Ra as Re,S as oe,Ta as Le,Wa as Ve,Ya as Fe,bb as ze,cb as We,db as Ue,ga as Ee,ha as Te,ia as Ae,ja as _e,ka as Pe,oa as ae,pa as Be,qa as Ne}from"../chunk-6s6encmz.js";import"../chunk-nfdg722p.js";import"../chunk-afzfbcrx.js";import"../chunk-w55vdzzf.js";import{Ib as U,Jb as je,Lb as se,Mb as G,Rb as De,Vb as ne}from"../chunk-5y7jxjtz.js";import"../chunk-415b756j.js";import"../chunk-agh1vkqm.js";import{mc as W,nc as ee,oc as te}from"../chunk-rqny4g8r.js";import"../chunk-m0byff93.js";import"../chunk-py2pv4ka.js";import{Kc as Ce,Lc as zt}from"../chunk-hxd34yh9.js";import{Pc as N}from"../chunk-a20hctx6.js";import d from"node:fs";import y from"node:path";import u from"node:process";import{existsSync as He}from"node:fs";import q from"node:fs/promises";import ue from"node:os";import H from"node:path";import B from"node:process";import{EventEmitter as Ke}from"node:events";import j from"node:process";import he from"node:process";import Y from"node:process";import F from"node:process";import L from"node:process";import me from"node:tty";import Nt,{stdin as ps,stdout as fs}from"node:process";class ge{configPath;config=null;events=[];retryCount=0;maxRetries=3;retryDelayMs=1000;constructor(){let e=ue.homedir(),t=H.join(e,".config","clapp");this.configPath=H.join(t,"telemetry.json")}async isEnabled(){if(B.env.DO_NOT_TRACK==="1"||B.env.DO_NOT_TRACK==="true")return!1;if(B.env.NO_TELEMETRY==="1"||B.env.NO_TELEMETRY==="true")return!1;return(await this.loadConfig()).enabled}async enable(){let e=await this.loadConfig();if(e.enabled=!0,!e.userId)e.userId=this.generateUserId();await this.saveConfig(e)}async disable(){let e=await this.loadConfig();e.enabled=!1,await this.saveConfig(e)}async track(e,t){if(!await this.isEnabled())return;let n={event:e,...t,timestamp:Date.now(),platform:ue.platform(),nodeVersion:B.version};if(this.events.push(n),this.events.length>=10)await this.send()}async trackCommand(e,t){await this.track("command",{command:e,duration:t})}async trackError(e,t){await this.track("error",{error:e,command:t})}async send(){if(!await this.isEnabled()||this.events.length===0)return!0;try{this.events=[],this.retryCount=0;let t=await this.loadConfig();return t.lastSent=Date.now(),await this.saveConfig(t),!0}catch{if(this.retryCount<this.maxRetries){this.retryCount++;let t=this.retryDelayMs*2**(this.retryCount-1);return await this.sleep(t),this.send()}return this.events=[],this.retryCount=0,!1}}async flush(){if(this.events.length===0)return!0;return this.send()}sleep(e){return new Promise((t)=>setTimeout(t,e))}async status(){let e=await this.loadConfig();return{enabled:e.enabled,doNotTrack:B.env.DO_NOT_TRACK==="1"||B.env.DO_NOT_TRACK==="true",eventsQueued:this.events.length,lastSent:e.lastSent}}async loadConfig(){if(this.config)return this.config;try{if(He(this.configPath)){let e=await q.readFile(this.configPath,"utf-8");return this.config=JSON.parse(e),this.config}}catch{}return this.config={enabled:!1},this.config}async saveConfig(e){this.config=e;try{let t=H.dirname(this.configPath);await q.mkdir(t,{recursive:!0}),await q.writeFile(this.configPath,JSON.stringify(e,null,2),"utf-8")}catch{}}generateUserId(){let e=Math.random().toString(36).substring(2,15),t=Date.now().toString(36);return`${e}-${t}`}}var es=new ge;function Je(e,t={}){let s={_:[]},n=t.alias||{},i=new Set(t.boolean||[]),r={};for(let l of Object.keys(n))for(let o of n[l])r[o]=l;for(let l of i)if(n[l])for(let o of n[l])i.add(o);function a(l,o){let c=r[l]||l;if(s[c]=o,n[c])for(let p of n[c])s[p]=o;if(r[l]&&n[r[l]])for(let p of n[r[l]])s[p]=o;s[l]=o}for(let l=0;l<e.length;l++){let o=e[l];if(o==="--"){s._.push(...e.slice(l+1));break}if(o.startsWith("--")){let c=o.indexOf("=");if(c!==-1){let p=o.slice(2,c),g=o.slice(c+1);a(p,g)}else{let p=o.slice(2);if(p.startsWith("no-")){let h=p.slice(3);a(h,!1);continue}let g=r[p]||p;if(i.has(g)||i.has(p))a(p,!0);else{let h=e[l+1];if(h!==void 0&&!h.startsWith("-"))a(p,h),l++;else a(p,!0)}}}else if(o.startsWith("-")&&o.length>1){let c=o.slice(1);for(let p=0;p<c.length;p++){let g=c[p],h=r[g]||g;if(p===c.length-1&&!i.has(h)&&!i.has(g)){let f=e[l+1];if(f!==void 0&&!f.startsWith("-"))a(g,f),l++;else a(g,!0)}else a(g,!0)}}else s._.push(o)}return s}function J(e){return e.replace(/[<[].+/,"").trim()}function Ye(e){let t=/<([^>]+)>/g,s=/\[([^\]]+)\]/g,n=[],i=(l)=>{let o=!1,c=l[1];if(c.startsWith("..."))c=c.slice(3),o=!0;return{required:l[0].startsWith("<"),value:c,variadic:o}},r;while(r=t.exec(e))n.push(i(r));let a;while(a=s.exec(e))n.push(i(a));return n}function Ze(e){let t={alias:{},boolean:[]};for(let[s,n]of e.entries()){if(n.names.length>1)t.alias[n.names[0]]=n.names.slice(1);if(n.isBoolean)if(n.negated){if(!e.some((r,a)=>a!==s&&r.names.some((l)=>n.names.includes(l))&&typeof r.required==="boolean"))t.boolean.push(n.names[0])}else t.boolean.push(n.names[0])}return t}function de(e){return e.reduce((t,s)=>t.length>=s.length?t:s,"")}function K(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function Xe(e){return e.replace(/([a-z])-([a-z])/g,(t,s,n)=>s+n.toUpperCase())}function Qe(e,t,s){let n=0,i=t.length,r=e,a;for(;n<i;++n)a=r[t[n]],r=r[t[n]]=n===i-1?s:a!=null?a:!!~t[n+1].indexOf(".")||!(+t[n+1]>-1)?{}:[]}function et(e,t){for(let s of Object.keys(t)){let n=t[s];if(n.shouldTransform){if(e[s]=Array.prototype.concat.call([],e[s]),typeof n.transformFunction==="function")e[s]=e[s].map(n.transformFunction)}}}function tt(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function ye(e){return e.split(".").map((t,s)=>s===0?Xe(t):t).join(".")}class V extends Error{exitCode=2;isUsageError=!0;constructor(e){super(e);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}format(e=!1){if(e&&this.stack)return`${this.message}
3
3
 
4
4
  Stack trace:
5
5
  ${this.stack}`;return this.message}}function st(){let{env:e}=he,{TERM:t,TERM_PROGRAM:s}=e;if(he.platform!=="win32")return t!=="linux";return Boolean(e.WT_SESSION)||Boolean(e.TERMINUS_SUBLIME)||e.ConEmuTask==="{cmd::Cmder}"||s==="Terminus-Sublime"||s==="vscode"||t==="xterm-256color"||t==="alacritty"||t==="rxvt-unicode"||t==="rxvt-unicode-256color"||e.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var z="\x1B",E=`${z}[`;var pe={to(e,t){if(!t)return`${E}${e+1}G`;return`${E}${t+1};${e+1}H`},move(e,t){let s="";if(e<0)s+=`${E}${-e}D`;else if(e>0)s+=`${E}${e}C`;if(t<0)s+=`${E}${-t}A`;else if(t>0)s+=`${E}${t}B`;return s},up:(e=1)=>`${E}${e}A`,down:(e=1)=>`${E}${e}B`,forward:(e=1)=>`${E}${e}C`,backward:(e=1)=>`${E}${e}D`,nextLine:(e=1)=>`${E}E`.repeat(e),prevLine:(e=1)=>`${E}F`.repeat(e),left:`${E}G`,hide:`${E}?25l`,show:`${E}?25h`,save:`${z}7`,restore:`${z}8`};var is={screen:`${E}2J`,up:(e=1)=>`${E}1J`.repeat(e),down:(e=1)=>`${E}J`.repeat(e),line:`${E}2K`,lineEnd:`${E}K`,lineStart:`${E}1K`,lines(e){let t="";for(let s=0;s<e;s++)t+=this.line+(s<e-1?pe.up():"");if(e)t+=pe.left;return t}},rs={screen:`${z}c`};function nt(e,t){let s=[];for(let n=0;n<=t.length;n++)s[n]=[n];for(let n=0;n<=e.length;n++)s[0][n]=n;for(let n=1;n<=t.length;n++)for(let i=1;i<=e.length;i++)if(t.charAt(n-1)===e.charAt(i-1))s[n][i]=s[n-1][i-1];else s[n][i]=Math.min(s[n-1][i-1]+1,s[n][i-1]+1,s[n-1][i]+1);return s[t.length][e.length]}function $e(e,t,s=2,n=3){return t.map((i)=>({cmd:i,distance:nt(e,i)})).filter(({distance:i})=>i<=s).sort((i,r)=>i.distance-r.distance).slice(0,n).map(({cmd:i})=>i)}class be{rawName;description;name;names;isBoolean;required;config;negated;constructor(e,t,s){if(this.rawName=e,this.description=t,this.config=Object.assign({},s),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=J(e).split(",").map((n)=>{let i=n.trim().replace(/^-{1,2}/,"");if(i.startsWith("no-"))this.negated=!0,i=i.replace(/^no-/,"");return ye(i)}).sort((n,i)=>n.length>i.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var as=Y.argv,it=`${Y.platform}-${Y.arch} bun-v${typeof Bun<"u"?Bun.version:"unknown"}`,fe=F.argv,rt=`${F.platform}-${F.arch} node-${F.version}`;class Z{rawName;description;config;cli;options;aliasNames;name;namespace;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;beforeHooks;afterHooks;middleware;constructor(e,t,s,n){this.rawName=e,this.description=t,this.config=s,this.cli=n,this.options=[],this.aliasNames=[],this.name=J(e);let i=J(e),r=i.indexOf(":");if(r>0)this.namespace=i.substring(0,r),this.name=i.substring(r+1);if(this.args=Ye(e),this.examples=[],this.beforeHooks=[],this.afterHooks=[],this.middleware=[],!s)this.config={}}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,s){let n=new be(e,t,s);return this.options.push(n),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}before(e){return this.beforeHooks.push(e),this}after(e){return this.afterHooks.push(e),this}use(e){return this.middleware.push(e),this}isMatched(e){if(this.aliasNames.includes(e))return!0;if(this.namespace)return`${this.namespace}:${this.name}`===e;return this.name===e}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof X}get displayName(){return this.namespace?`${this.namespace}:${this.name}`:this.name}hasOption(e){return e=e.split(".")[0],!!this.options.find((t)=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:s,options:n,helpCallback:i}=this.cli.globalCommand,r=[{body:`${e}${s?`/${s}`:""}`}];if(r.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let o=de(t.map((f)=>f.rawName)),c=new Map,p=[];for(let f of t)if(f.namespace){if(!c.has(f.namespace))c.set(f.namespace,[]);c.get(f.namespace).push(f)}else p.push(f);let g="";if(p.length>0)g+=p.map((f)=>` ${K(f.rawName,o.length)} ${f.description}`).join(`
@@ -28,7 +28,7 @@ Received ${s}, cleaning up...`),e)try{await e()}catch(n){console.error("Error du
28
28
  ✗ Command "${e}" not found.
29
29
  `)),this.enableDidYouMean){let t=[];for(let n of this.commands){if(n.displayName)t.push(n.displayName);if(n.aliasNames)t.push(...n.aliasNames)}let s=$e(e,t);if(s.length>0)console.log(R.yellow("Did you mean one of these?")),s.forEach((n)=>console.log(` ${R.dim("•")} ${this.name} ${n}`)),console.log("")}console.log(R.dim("Run"),`${this.name} --help`,R.dim("to see all available commands")),j.exit(1)}async parse(e=fe,t={}){let{run:s=!0,exitOnError:n=!1}=t;if(n)try{return await this.parse(e,{run:s})}catch(o){throw this.handleUsageError(o),o}if(this.rawArgs=e,!this.name)this.name=e[1]?tt(e[1]):"cli";let i=!0,r=e.slice(2),a=r[0];if(a&&!a.startsWith("-")){for(let o of this.commands)if(o.isMatched(a)){let c=this.mri(r,o);i=!1;let p={...c,args:c.args.slice(1)};this.setParsedInfo(p,o,a),this.emit(`command:${a}`,o);break}}if(i){for(let o of this.commands)if(o.name===""){i=!1;let c=this.mri(r,o);this.setParsedInfo(c,o),this.emit("command:!",o);break}}if(i){let o=this.mri(e.slice(2));this.setParsedInfo(o)}if(this.options.verbose)this.isVerbose=!0;if(this.options.quiet)this.isQuiet=!0;if(this.options.debug)this.isDebug=!0;if(this.options.noInteraction)this.isNoInteraction=!0;if(this.options.env)this.environment=String(this.options.env);if(this.options.dryRun)this.isDryRun=!0;if(this.options.force)this.isForce=!0;if(this.options.noEmoji!==void 0)this.useEmoji=!this.options.noEmoji;if(this.options.theme)this.theme=String(this.options.theme);if(this.options.noCache!==void 0)this.isNoCache=Boolean(this.options.noCache);if(this.options.help&&this.showHelpOnExit)this.outputHelp(),s=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),s=!1,this.unsetMatchedCommand();let l={args:this.args,options:this.options};if(s)await this.runMatchedCommand();if(!this.matchedCommand&&this.args[0]){if(this.emit("command:*"),!(this.listenerCount("command:*")>0))this.showCommandNotFound(this.args[0])}return l}mri(e,t){let s=[...this.globalCommand.options,...t?t.options:[]],n=Ze(s),i=[],r=e.indexOf("--");if(r>-1)i=e.slice(r+1),e=e.slice(0,r);let a=Je(e,n),l={_:a._};for(let h of Object.keys(a))if(h!=="_")l[ye(h)]=a[h];let o=l._,c={"--":i},p=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,g=Object.create(null);for(let h of s){if(!p&&h.config.default!==void 0)for(let f of h.names)c[f]=h.config.default;if(Array.isArray(h.config.type)){if(g[h.name]===void 0)g[h.name]={shouldTransform:!0,transformFunction:h.config.type[0]}}}for(let h of Object.keys(l))if(h!=="_"){let f=h.split(".");Qe(c,f,l[h]),et(c,g)}return{args:o,options:c}}async run(e=fe){return this.parse(e,{run:!0,exitOnError:!0})}handleUsageError(e){if(!(!!e&&typeof e==="object"&&e.name==="ClappError"&&e.isUsageError!==!1))return;let n=e,i=n.message??"command-line error",r=this.name?`${this.name}: `:"",a=/--help/.test(i)?"":`
30
30
  Run \`${this.name??"cli"} --help\` for usage.`;j.stderr.write(`${r}${i}${a}
31
- `),j.exit(n.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let n=[];s.args.forEach((l,o)=>{if(l.variadic)n.push(e.slice(o));else n.push(e[o])}),n.push(t);let i={command:s,args:n,options:t};for(let l of s.beforeHooks)await l(i);let r,a=async()=>{let l=s.commandAction.apply(this,n);if(l instanceof Promise)r=await l;else r=l;return r};if(s.middleware.length>0){let l=0,o=async()=>{if(l<s.middleware.length){let c=s.middleware[l++];await c({...i,next:o})}else await a()};await o()}else await a();for(let l of s.afterHooks)await l(i);return r}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return j.removeAllListeners("SIGINT"),j.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class we{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,s=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:s})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,s]of this.cache.entries())if(e-s.timestamp>s.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var cs=new we;function ct(){if("FORCE_COLOR"in L.env)return L.env.FORCE_COLOR!=="0";if("NO_COLOR"in L.env||L.env.TERM==="dumb")return!1;if(L.platform==="win32")return!0;return me.isatty(1)&&me.isatty(2)}var ve=ct();function C(e,t){if(!ve)return(s)=>s;return(s)=>e+s+t}var ut=C("\x1B[0m","\x1B[0m"),ht=C("\x1B[31m","\x1B[39m"),dt=C("\x1B[32m","\x1B[39m"),pt=C("\x1B[33m","\x1B[39m"),ft=C("\x1B[34m","\x1B[39m"),mt=C("\x1B[35m","\x1B[39m"),gt=C("\x1B[36m","\x1B[39m"),yt=C("\x1B[37m","\x1B[39m"),$t=C("\x1B[90m","\x1B[39m"),bt=C("\x1B[1m","\x1B[22m"),wt=C("\x1B[3m","\x1B[23m"),vt=C("\x1B[4m","\x1B[24m"),xt=C("\x1B[2m","\x1B[22m"),St=C("\x1B[7m","\x1B[27m"),kt=C("\x1B[8m","\x1B[28m"),Ct=C("\x1B[9m","\x1B[29m"),It=C("\x1B[41m","\x1B[49m"),Ot=C("\x1B[42m","\x1B[49m"),Et=C("\x1B[43m","\x1B[49m"),Tt=C("\x1B[44m","\x1B[49m"),At=C("\x1B[45m","\x1B[49m"),_t=C("\x1B[46m","\x1B[49m"),Pt=C("\x1B[47m","\x1B[49m"),jt=ve,Dt={reset:ut,red:ht,green:dt,yellow:pt,blue:ft,magenta:mt,cyan:gt,white:yt,gray:$t,bold:bt,italic:wt,underline:vt,dim:xt,inverse:St,hidden:kt,strikethrough:Ct,bgRed:It,bgGreen:Ot,bgYellow:Et,bgBlue:Tt,bgMagenta:At,bgCyan:_t,bgWhite:Pt,isColorSupported:jt},Bt=Dt,Mt=["up","down","left","right","space","enter","cancel"],ms={actions:new Set(Mt),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var gs=Nt.platform.startsWith("win"),ys=Symbol("clapp:cancel");var Rt=st();var S=(e,t)=>Rt?e:t,$s=S("◆","*"),bs=S("■","x"),ws=S("▲","x"),vs=S("◇","o"),xs=S("┌","T"),Lt=S("│","|"),Ss=S("└","—"),ks=S("●",">"),Cs=S("○"," "),Is=S("◻","[•]"),Os=S("◼","[+]"),Es=S("◻","[ ]"),Ts=S("▪","•"),As=S("─","-"),_s=S("╮","+"),Ps=S("├","+"),js=S("╯","+"),Ds=S("●","•"),Bs=S("◆","*"),Ns=S("▲","!"),Ms=S("■","x");var Rs={light:S("─","-"),heavy:S("━","="),block:S("█","#")};function Vt(){return`${Bt.gray(Lt)} `}var Ls=Vt();var xe="0.11.39";zt();async function Wt(e="src/pantry"){if(!d.existsSync(e))throw Error(`Pantry directory not found: ${e}. Please run 'bun ./bin/cli.ts update-pantry' first.`);let t=[];function s(n,i=""){let r=d.readdirSync(n,{withFileTypes:!0}),a=y.join(n,"package.yml");if(i&&d.existsSync(a))t.push(i);for(let l of r)if(l.isDirectory()&&!l.name.startsWith(".")){let o=i?`${i}/${l.name}`:l.name,c=y.join(n,l.name);s(c,o)}}return s(e),console.log(`\uD83D\uDCE6 Found ${t.length} packages in local pantry`),t.sort()}async function Ut(e=!1){async function t(a){let l=new URL("https://s3.amazonaws.com/dist.tea.xyz/");if(l.searchParams.set("list-type","2"),l.searchParams.set("prefix",""),l.searchParams.set("max-keys","1000"),a)l.searchParams.set("continuation-token",a);let o=await fetch(l.toString());if(!o.ok)throw Error(`Failed to fetch S3 listing: ${o.status}`);let c=await o.text(),p=[],g=c.match(/<Key>([^<]+)<\/Key>/g);if(g)for(let I of g){let O=I.replace(/<Key>([^<]+)<\/Key>/,"$1");p.push({Key:O})}let h=c.includes("<IsTruncated>true</IsTruncated>"),f=c.match(/<NextContinuationToken>([^<]+)<\/NextContinuationToken>/),m=f?f[1]:void 0;return{IsTruncated:h,NextContinuationToken:m,Contents:p}}console.log("Scraping packages from S3 registry...");let s=new Set,n;do{let a=await t(n);for(let l of a.Contents){let o=l.Key,c=o.split("/");if(c.length===0)continue;if(c[0].startsWith(".")||c[0].includes(" ")||o.match(/\.(md|txt|yml|yaml|json)$/i))continue;let p=["darwin","linux","windows"],g=-1;for(let h=1;h<c.length;h++)if(p.includes(c[h])){g=h;break}if(g>0){let h=c.slice(0,g).join("/");if(h.includes("."))s.add(h)}else if(c.length>=2&&c[0].includes(".")&&!c[1].startsWith("v")&&!c[1].match(/^\d/)){let h=`${c[0]}/${c[1]}`;s.add(h)}else if(c.length>=1&&c[0].includes("."))s.add(c[0])}n=a.NextContinuationToken,console.log(`Found ${s.size} packages so far...`)}while(n);let i=Array.from(s).sort(),r=[];for(let a of i){if(!a.includes(".")||a.match(/^[a-z0-9.-]+\.[a-z]{2,}(\/[\w.-]+){0,20}$/i)===null)continue;if(a.endsWith("/README.rst")||a.endsWith("/README")||a.includes("/docs/"))continue;if(a.endsWith("/.pkgroot"))continue;if(["amazon.com/aws","charm.sh","code.videolan.org","crates.io"].includes(a))continue;r.push(a)}return console.log(`\uD83D\uDCE6 Found ${r.length} valid packages in registry`),r}async function Gt(e,t){let n=`/**
31
+ `),j.exit(n.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let n=[];s.args.forEach((l,o)=>{if(l.variadic)n.push(e.slice(o));else n.push(e[o])}),n.push(t);let i={command:s,args:n,options:t};for(let l of s.beforeHooks)await l(i);let r,a=async()=>{let l=s.commandAction.apply(this,n);if(l instanceof Promise)r=await l;else r=l;return r};if(s.middleware.length>0){let l=0,o=async()=>{if(l<s.middleware.length){let c=s.middleware[l++];await c({...i,next:o})}else await a()};await o()}else await a();for(let l of s.afterHooks)await l(i);return r}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return j.removeAllListeners("SIGINT"),j.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class we{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,s=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:s})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,s]of this.cache.entries())if(e-s.timestamp>s.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var cs=new we;function ct(){if("FORCE_COLOR"in L.env)return L.env.FORCE_COLOR!=="0";if("NO_COLOR"in L.env||L.env.TERM==="dumb")return!1;if(L.platform==="win32")return!0;return me.isatty(1)&&me.isatty(2)}var ve=ct();function C(e,t){if(!ve)return(s)=>s;return(s)=>e+s+t}var ut=C("\x1B[0m","\x1B[0m"),ht=C("\x1B[31m","\x1B[39m"),dt=C("\x1B[32m","\x1B[39m"),pt=C("\x1B[33m","\x1B[39m"),ft=C("\x1B[34m","\x1B[39m"),mt=C("\x1B[35m","\x1B[39m"),gt=C("\x1B[36m","\x1B[39m"),yt=C("\x1B[37m","\x1B[39m"),$t=C("\x1B[90m","\x1B[39m"),bt=C("\x1B[1m","\x1B[22m"),wt=C("\x1B[3m","\x1B[23m"),vt=C("\x1B[4m","\x1B[24m"),xt=C("\x1B[2m","\x1B[22m"),St=C("\x1B[7m","\x1B[27m"),kt=C("\x1B[8m","\x1B[28m"),Ct=C("\x1B[9m","\x1B[29m"),It=C("\x1B[41m","\x1B[49m"),Ot=C("\x1B[42m","\x1B[49m"),Et=C("\x1B[43m","\x1B[49m"),Tt=C("\x1B[44m","\x1B[49m"),At=C("\x1B[45m","\x1B[49m"),_t=C("\x1B[46m","\x1B[49m"),Pt=C("\x1B[47m","\x1B[49m"),jt=ve,Dt={reset:ut,red:ht,green:dt,yellow:pt,blue:ft,magenta:mt,cyan:gt,white:yt,gray:$t,bold:bt,italic:wt,underline:vt,dim:xt,inverse:St,hidden:kt,strikethrough:Ct,bgRed:It,bgGreen:Ot,bgYellow:Et,bgBlue:Tt,bgMagenta:At,bgCyan:_t,bgWhite:Pt,isColorSupported:jt},Bt=Dt,Mt=["up","down","left","right","space","enter","cancel"],ms={actions:new Set(Mt),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var gs=Nt.platform.startsWith("win"),ys=Symbol("clapp:cancel");var Rt=st();var S=(e,t)=>Rt?e:t,$s=S("◆","*"),bs=S("■","x"),ws=S("▲","x"),vs=S("◇","o"),xs=S("┌","T"),Lt=S("│","|"),Ss=S("└","—"),ks=S("●",">"),Cs=S("○"," "),Is=S("◻","[•]"),Os=S("◼","[+]"),Es=S("◻","[ ]"),Ts=S("▪","•"),As=S("─","-"),_s=S("╮","+"),Ps=S("├","+"),js=S("╯","+"),Ds=S("●","•"),Bs=S("◆","*"),Ns=S("▲","!"),Ms=S("■","x");var Rs={light:S("─","-"),heavy:S("━","="),block:S("█","#")};function Vt(){return`${Bt.gray(Lt)} `}var Ls=Vt();var xe="0.11.40";zt();async function Wt(e="src/pantry"){if(!d.existsSync(e))throw Error(`Pantry directory not found: ${e}. Please run 'bun ./bin/cli.ts update-pantry' first.`);let t=[];function s(n,i=""){let r=d.readdirSync(n,{withFileTypes:!0}),a=y.join(n,"package.yml");if(i&&d.existsSync(a))t.push(i);for(let l of r)if(l.isDirectory()&&!l.name.startsWith(".")){let o=i?`${i}/${l.name}`:l.name,c=y.join(n,l.name);s(c,o)}}return s(e),console.log(`\uD83D\uDCE6 Found ${t.length} packages in local pantry`),t.sort()}async function Ut(e=!1){async function t(a){let l=new URL("https://s3.amazonaws.com/dist.tea.xyz/");if(l.searchParams.set("list-type","2"),l.searchParams.set("prefix",""),l.searchParams.set("max-keys","1000"),a)l.searchParams.set("continuation-token",a);let o=await fetch(l.toString());if(!o.ok)throw Error(`Failed to fetch S3 listing: ${o.status}`);let c=await o.text(),p=[],g=c.match(/<Key>([^<]+)<\/Key>/g);if(g)for(let I of g){let O=I.replace(/<Key>([^<]+)<\/Key>/,"$1");p.push({Key:O})}let h=c.includes("<IsTruncated>true</IsTruncated>"),f=c.match(/<NextContinuationToken>([^<]+)<\/NextContinuationToken>/),m=f?f[1]:void 0;return{IsTruncated:h,NextContinuationToken:m,Contents:p}}console.log("Scraping packages from S3 registry...");let s=new Set,n;do{let a=await t(n);for(let l of a.Contents){let o=l.Key,c=o.split("/");if(c.length===0)continue;if(c[0].startsWith(".")||c[0].includes(" ")||o.match(/\.(md|txt|yml|yaml|json)$/i))continue;let p=["darwin","linux","windows"],g=-1;for(let h=1;h<c.length;h++)if(p.includes(c[h])){g=h;break}if(g>0){let h=c.slice(0,g).join("/");if(h.includes("."))s.add(h)}else if(c.length>=2&&c[0].includes(".")&&!c[1].startsWith("v")&&!c[1].match(/^\d/)){let h=`${c[0]}/${c[1]}`;s.add(h)}else if(c.length>=1&&c[0].includes("."))s.add(c[0])}n=a.NextContinuationToken,console.log(`Found ${s.size} packages so far...`)}while(n);let i=Array.from(s).sort(),r=[];for(let a of i){if(!a.includes(".")||a.match(/^[a-z0-9.-]+\.[a-z]{2,}(\/[\w.-]+){0,20}$/i)===null)continue;if(a.endsWith("/README.rst")||a.endsWith("/README")||a.includes("/docs/"))continue;if(a.endsWith("/.pkgroot"))continue;if(["amazon.com/aws","charm.sh","code.videolan.org","crates.io"].includes(a))continue;r.push(a)}return console.log(`\uD83D\uDCE6 Found ${r.length} valid packages in registry`),r}async function Gt(e,t){let n=`/**
32
32
  * Constants used throughout the ts-pantry package
33
33
  * This file is auto-generated from ${t}. Do not edit manually.
34
34
  * Generated on ${new Date().toISOString()}
@@ -91,7 +91,7 @@ ${i.join(`
91
91
  Conflicts found:`),h.conflicts.forEach((m)=>{console.log(` ${m.package}: ${m.versions.join(", ")}`)});if(console.log(`
92
92
  \uD83D\uDCCB All unique packages to install:`),h.uniquePackages.forEach((m,I)=>{let O=h.allDependencies.find((x)=>x.name===m),b=O&&O.version&&O.version!=="latest"?` (${O.version})`:"";console.log(` ${I+1}. ${m}${b}`)}),c)console.log(`
93
93
  \uD83D\uDE80 Install command:`),console.log(`pantry install ${h.uniquePackages.join(" ")}`);if(Object.values(h.osSpecificDeps).reduce((m,I)=>m+I.length,0)>0)console.log(`
94
- \uD83D\uDDA5️ OS-specific dependencies:`),Object.entries(h.osSpecificDeps).forEach(([m,I])=>{if(I.length>0)console.log(` ${m}: ${I.map((O)=>O.name).join(", ")}`)})}u.exit(0)}catch(s){if(t.json){let n={success:!1,error:String(s),timestamp:new Date().toISOString()};console.log(JSON.stringify(n))}else console.error("Error resolving dependencies:",s);u.exit(1)}});k.command("get-php-versions","Get PHP versions suitable for CI/CD workflows").option("--format <type>","Output format: json (default), yaml, or csv",{default:"json"}).option("--branches <branches>","Comma-separated list of PHP branches to include (e.g., 8.4,8.3,8.2)").option("--fallback <versions>","Comma-separated list of fallback versions if detection fails").action(async(e)=>{try{let{getPhpVersionsForWorkflow:t}=await import("../chunk-92zrwkxc.js"),s={};if(e.branches)s.supportedBranches=e.branches.split(",").map((i)=>i.trim());if(e.fallback)s.fallbackVersions=e.fallback.split(",").map((i)=>i.trim());let n=t(s);switch(e.format.toLowerCase()){case"yaml":console.log(`php_versions:
94
+ \uD83D\uDDA5️ OS-specific dependencies:`),Object.entries(h.osSpecificDeps).forEach(([m,I])=>{if(I.length>0)console.log(` ${m}: ${I.map((O)=>O.name).join(", ")}`)})}u.exit(0)}catch(s){if(t.json){let n={success:!1,error:String(s),timestamp:new Date().toISOString()};console.log(JSON.stringify(n))}else console.error("Error resolving dependencies:",s);u.exit(1)}});k.command("get-php-versions","Get PHP versions suitable for CI/CD workflows").option("--format <type>","Output format: json (default), yaml, or csv",{default:"json"}).option("--branches <branches>","Comma-separated list of PHP branches to include (e.g., 8.4,8.3,8.2)").option("--fallback <versions>","Comma-separated list of fallback versions if detection fails").action(async(e)=>{try{let{getPhpVersionsForWorkflow:t}=await import("../chunk-srp1ajsz.js"),s={};if(e.branches)s.supportedBranches=e.branches.split(",").map((i)=>i.trim());if(e.fallback)s.fallbackVersions=e.fallback.split(",").map((i)=>i.trim());let n=t(s);switch(e.format.toLowerCase()){case"yaml":console.log(`php_versions:
95
95
  ${n.map((i)=>` - "${i}"`).join(`
96
96
  `)}`);break;case"csv":console.log(n.join(","));break;case"json":default:console.log(JSON.stringify(n));break}u.exit(0)}catch(t){console.error("Error getting PHP versions:",t),u.exit(1)}});k.command("generate-zig","Generate Zig package definitions from TypeScript packages").option("--packages-dir <dir>","Directory containing TypeScript package files",{default:"src/packages"}).option("--output <file>","Output Zig file path",{default:"packages.zig"}).option("--aliases","Also generate aliases file").option("--aliases-output <file>","Output file for Zig aliases",{default:"aliases.zig"}).action(async(e)=>{try{let{generateZigDefinitions:t,generateZigAliases:s}=await import("../chunk-btrd677x.js"),{packagesDir:n="src/packages",output:i="packages.zig",aliases:r=!1,aliasesOutput:a="aliases.zig"}=e;if(console.log("\uD83D\uDE80 Generating Zig package definitions..."),await t(n,i),r)console.log(`
97
97
  \uD83D\uDE80 Generating Zig package aliases...`),await s(n,a);console.log(`
@@ -1,10 +1,10 @@
1
- import{eb as Je}from"./chunk-nfdg722p.js";import{Yb as at}from"./chunk-415b756j.js";import{ec as Q,fc as Qt,hc as Ve}from"./chunk-agh1vkqm.js";import{Ac as Tt,Bc as Ot,Cc as qe,rc as Dt,sc as It,vc as Et,wc as We,yc as Nt}from"./chunk-p763mye8.js";import{Jc as cs}from"./chunk-8rg91cqd.js";import{Kc as he,Lc as Cr}from"./chunk-hxd34yh9.js";import{Pc as K}from"./chunk-a20hctx6.js";import Ir from"node:process";Cr();import $t from"node:process";function At(e){return e in he}function Dr(e){if(!e.includes(".")||e.startsWith(".")||e.endsWith("."))return!1;if(/^v?\d+(?:\.\d+){0,10}$/.test(e))return!1;return/^[a-z0-9][\w.\-/]*$/i.test(e)}function gs(e){return At(e)||Dr(e)}function ds(e){return["darwin","linux","windows"].includes(e)}function us(e){return["x86_64","aarch64","armv7l","i686"].includes(e)}function Rt(){return Object.keys(he)}function fs(){return Object.values(he)}function ms(e){if(At(e))return{originalName:e,resolvedDomain:he[e],isAlias:!0};return{originalName:e,resolvedDomain:e,isAlias:!1}}function hs(e){let t=e.lastIndexOf("@");if(t===-1)return{name:e};let r=e.slice(0,t),n=e.slice(t+1);return{name:r,version:n,versionSpec:n}}function ys(e,t){return t?`${e}@${t}`:e}function ke(){let e=$t.platform,t=$t.arch,r,n,s=!0;switch(e){case"darwin":r="darwin";break;case"linux":r="linux";break;case"win32":r="windows";break;default:r="linux",s=!1}switch(t){case"x64":n="x86_64";break;case"arm64":n="aarch64";break;case"arm":n="armv7l";break;case"ia32":n="i686";break;default:n="x86_64",s=!1}return{platform:r,architecture:n,isSupported:s}}function bs(e,t="latest",r){let n=r||ke(),s;switch(n.platform){case"darwin":s="tar.xz";break;case"linux":s="tar.xz";break;case"windows":s="zip";break;default:s="tar.xz"}return{packageName:e,version:t,platform:n.platform,architecture:n.architecture,format:s}}var ks={LATEST:"latest",ANY:"*"},Ct={RUNTIME:["nodejs.org","python.org","go.dev","rust-lang.org"],BUILD_TOOLS:["cmake.org","ninja-build.org","gradle.org","maven.apache.org"],DATABASES:["postgresql.org","mysql.com","redis.io","mongodb.com"],EDITORS:["neovim.io","vim.org","code.visualstudio.com"],CLI_TOOLS:["cli.github.com","curl.se","wget.gnu.org","jq.dev"]};function xs(e){return Ct[e]}function Ps(e,t){return Ct[t].includes(e)}function ws(e){return e}function Ss(e,t){return[e,t]}function vs(e){return e}async function Ds(e){try{let t=await We(e);if(!t)return{success:!1,error:`Package '${e}' not found. Use 'search' to find available packages.`};return{success:!0,data:t}}catch(t){return{success:!1,error:`Failed to get package info: ${t}`}}}async function Is(e){try{if(!e||e.trim().length===0)return{success:!1,error:"Search term cannot be empty"};return{success:!0,data:await Nt(e.trim())}}catch(t){return{success:!1,error:`Search failed: ${t}`}}}async function Es(e=20){try{return{success:!0,data:(await Tt(e)).slice(0,e)}}catch(t){return{success:!1,error:`Failed to list popular packages: ${t}`}}}async function Ns(e=20){try{return{success:!0,data:await Ot(e)}}catch(t){return{success:!1,error:`Failed to list active packages: ${t}`}}}function Ts(){try{return{success:!0,data:Rt()}}catch(e){return{success:!1,error:`Failed to list aliases: ${e}`}}}async function Os(e){try{let t=await qe(e);if(!t.isValid)return{success:!1,error:t.error};return{success:!0,data:{packageName:t.packageName,version:t.version,isValid:!0}}}catch(t){return{success:!1,error:`Validation failed: ${t}`}}}async function Vs(e){try{let t=await qe(e);if(!t.isValid)return{success:!1,error:t.error};let r=t.packageName,n=t.version||"latest",s=await Et(r,n);if(!s)return{success:!1,error:`Could not resolve version '${n}' for package '${r}'`};let o=await We(r);if(!o)return{success:!1,error:`Package '${r}' not found`};let a=ke(),i={packageName:r,resolvedVersion:s,platform:a.platform,architecture:a.architecture,dependencies:o.dependencies,companions:o.companions,installCommand:`pkgx install ${r}@${s}`},c=[];if(!a.isSupported)c.push(`Platform ${a.platform}/${a.architecture} may not be fully supported`);if(o.dependencies.length>0)c.push(`This package has ${o.dependencies.length} dependencies that will also be installed`);return{success:!0,data:i,warnings:c.length>0?c:void 0}}catch(t){return{success:!1,error:`Failed to create install plan: ${t}`}}}async function js(e){try{let t=await Dt(e);if(!t)return{success:!1,error:`Package '${e}' not found`};let r=await It(e);return{success:!0,data:{latest:t,total:r.length,versions:r}}}catch(t){return{success:!1,error:`Failed to get version info: ${t}`}}}function Fs(e){let t=[`Package: ${e.name}`,`Domain: ${e.domain}`,`Description: ${e.description}`,`Latest Version: ${e.latestVersion}`,`Total Versions: ${e.totalVersions}`];if(e.programs.length>0)t.push(`Programs: ${e.programs.join(", ")}`);if(e.dependencies.length>0)t.push(`Dependencies: ${e.dependencies.join(", ")}`);if(e.companions.length>0)t.push(`Companions: ${e.companions.join(", ")}`);return t.join(`
1
+ import{eb as Je}from"./chunk-nfdg722p.js";import{Yb as at}from"./chunk-415b756j.js";import{ec as Q,fc as Qt,hc as Ve}from"./chunk-agh1vkqm.js";import{Ac as Tt,Bc as Ot,Cc as qe,rc as Dt,sc as It,vc as Et,wc as We,yc as Nt}from"./chunk-m0byff93.js";import{Jc as cs}from"./chunk-py2pv4ka.js";import{Kc as he,Lc as Cr}from"./chunk-hxd34yh9.js";import{Pc as K}from"./chunk-a20hctx6.js";import Ir from"node:process";Cr();import $t from"node:process";function At(e){return e in he}function Dr(e){if(!e.includes(".")||e.startsWith(".")||e.endsWith("."))return!1;if(/^v?\d+(?:\.\d+){0,10}$/.test(e))return!1;return/^[a-z0-9][\w.\-/]*$/i.test(e)}function gs(e){return At(e)||Dr(e)}function ds(e){return["darwin","linux","windows"].includes(e)}function us(e){return["x86_64","aarch64","armv7l","i686"].includes(e)}function Rt(){return Object.keys(he)}function fs(){return Object.values(he)}function ms(e){if(At(e))return{originalName:e,resolvedDomain:he[e],isAlias:!0};return{originalName:e,resolvedDomain:e,isAlias:!1}}function hs(e){let t=e.lastIndexOf("@");if(t===-1)return{name:e};let r=e.slice(0,t),n=e.slice(t+1);return{name:r,version:n,versionSpec:n}}function ys(e,t){return t?`${e}@${t}`:e}function ke(){let e=$t.platform,t=$t.arch,r,n,s=!0;switch(e){case"darwin":r="darwin";break;case"linux":r="linux";break;case"win32":r="windows";break;default:r="linux",s=!1}switch(t){case"x64":n="x86_64";break;case"arm64":n="aarch64";break;case"arm":n="armv7l";break;case"ia32":n="i686";break;default:n="x86_64",s=!1}return{platform:r,architecture:n,isSupported:s}}function bs(e,t="latest",r){let n=r||ke(),s;switch(n.platform){case"darwin":s="tar.xz";break;case"linux":s="tar.xz";break;case"windows":s="zip";break;default:s="tar.xz"}return{packageName:e,version:t,platform:n.platform,architecture:n.architecture,format:s}}var ks={LATEST:"latest",ANY:"*"},Ct={RUNTIME:["nodejs.org","python.org","go.dev","rust-lang.org"],BUILD_TOOLS:["cmake.org","ninja-build.org","gradle.org","maven.apache.org"],DATABASES:["postgresql.org","mysql.com","redis.io","mongodb.com"],EDITORS:["neovim.io","vim.org","code.visualstudio.com"],CLI_TOOLS:["cli.github.com","curl.se","wget.gnu.org","jq.dev"]};function xs(e){return Ct[e]}function Ps(e,t){return Ct[t].includes(e)}function ws(e){return e}function Ss(e,t){return[e,t]}function vs(e){return e}async function Ds(e){try{let t=await We(e);if(!t)return{success:!1,error:`Package '${e}' not found. Use 'search' to find available packages.`};return{success:!0,data:t}}catch(t){return{success:!1,error:`Failed to get package info: ${t}`}}}async function Is(e){try{if(!e||e.trim().length===0)return{success:!1,error:"Search term cannot be empty"};return{success:!0,data:await Nt(e.trim())}}catch(t){return{success:!1,error:`Search failed: ${t}`}}}async function Es(e=20){try{return{success:!0,data:(await Tt(e)).slice(0,e)}}catch(t){return{success:!1,error:`Failed to list popular packages: ${t}`}}}async function Ns(e=20){try{return{success:!0,data:await Ot(e)}}catch(t){return{success:!1,error:`Failed to list active packages: ${t}`}}}function Ts(){try{return{success:!0,data:Rt()}}catch(e){return{success:!1,error:`Failed to list aliases: ${e}`}}}async function Os(e){try{let t=await qe(e);if(!t.isValid)return{success:!1,error:t.error};return{success:!0,data:{packageName:t.packageName,version:t.version,isValid:!0}}}catch(t){return{success:!1,error:`Validation failed: ${t}`}}}async function Vs(e){try{let t=await qe(e);if(!t.isValid)return{success:!1,error:t.error};let r=t.packageName,n=t.version||"latest",s=await Et(r,n);if(!s)return{success:!1,error:`Could not resolve version '${n}' for package '${r}'`};let o=await We(r);if(!o)return{success:!1,error:`Package '${r}' not found`};let a=ke(),i={packageName:r,resolvedVersion:s,platform:a.platform,architecture:a.architecture,dependencies:o.dependencies,companions:o.companions,installCommand:`pkgx install ${r}@${s}`},c=[];if(!a.isSupported)c.push(`Platform ${a.platform}/${a.architecture} may not be fully supported`);if(o.dependencies.length>0)c.push(`This package has ${o.dependencies.length} dependencies that will also be installed`);return{success:!0,data:i,warnings:c.length>0?c:void 0}}catch(t){return{success:!1,error:`Failed to create install plan: ${t}`}}}async function js(e){try{let t=await Dt(e);if(!t)return{success:!1,error:`Package '${e}' not found`};let r=await It(e);return{success:!0,data:{latest:t,total:r.length,versions:r}}}catch(t){return{success:!1,error:`Failed to get version info: ${t}`}}}function Fs(e){let t=[`Package: ${e.name}`,`Domain: ${e.domain}`,`Description: ${e.description}`,`Latest Version: ${e.latestVersion}`,`Total Versions: ${e.totalVersions}`];if(e.programs.length>0)t.push(`Programs: ${e.programs.join(", ")}`);if(e.dependencies.length>0)t.push(`Dependencies: ${e.dependencies.join(", ")}`);if(e.companions.length>0)t.push(`Companions: ${e.companions.join(", ")}`);return t.join(`
2
2
  `)}function Ms(e){if(e.length===0)return"No packages found matching your search.";let t=[`Found ${e.length} package(s):
3
3
  `];for(let r of e)t.push(`${r.name} (${r.domain})`),t.push(` ${r.description}`),t.push(` Latest: ${r.latestVersion} (${r.totalVersions} versions available)`),t.push("");return t.join(`
4
4
  `)}function _s(e){let t=[`Installation Plan for ${e.packageName}@${e.resolvedVersion}`,`Platform: ${e.platform}/${e.architecture}`,`Command: ${e.installCommand}`];if(e.dependencies.length>0)t.push(`Dependencies: ${e.dependencies.join(", ")}`);if(e.companions.length>0)t.push(`Companions: ${e.companions.join(", ")}`);return t.join(`
5
5
  `)}function Bs(){try{let e=ke();return{success:!0,data:{platform:e.platform,architecture:e.architecture,isSupported:e.isSupported,nodeVersion:Ir.version}}}catch(e){return{success:!1,error:`Failed to get system info: ${e}`}}}import ae from"node:fs";import Pe from"node:path";function we(e){if(!ae.existsSync(e))throw Error(`Dependency file not found: ${e}`);let t=ae.readFileSync(e,"utf-8"),r=[],n=t.split(`
6
6
  `),s=!1,o=!1,a=0;for(let i of n){let c=i.trim();if(!c||c.startsWith("#"))continue;if(i.match(/^(dependencies|deps):\s*$/)){s=!0,o=!1,a=i.search(/\S/);continue}if(i.match(/^global:\s*true\s*$/)||i.match(/^global:\s*$/)&&!s){o=!0;continue}if(i.match(/^\w+:/)&&!i.includes(" ")&&s&&a===0){s=!1;continue}if(s||o){if(i.match(/^\s+(dependencies|deps):\s*$/))continue;let l=i.indexOf(":");if(l>0){let g=i.substring(0,l).trim(),d=i.substring(l+1).trim();if(g&&d){let p=g,y=d.replace(/^['"]|['"]$/g,"");if(p==="global"||p==="dependencies"||p==="deps")continue;let f=y,h=y;if(y.startsWith("^"))f=y.substring(1),h=y;else if(y.startsWith("~"))f=y.substring(1),h=y;else if(y.startsWith(">=")||y.startsWith("<=")||y.startsWith(">")||y.startsWith("<")){let m=/^([><=]+)/.exec(y);if(m){let u=m[1];f=y.substring(u.length).trim(),h=y}}else if(y==="*"||y==="latest")f="latest",h="*";else f=y,h=`@${y}`;r.push({name:p,version:f,constraint:h,isOsSpecific:!1})}}}}return r}function Er(e){if(!ae.existsSync(e))throw Error(`Dependency file not found: ${e}`);let t=ae.readFileSync(e,"utf-8"),r=we(e),n;try{let s=typeof Bun<"u"&&Bun.YAML?Bun.YAML.parse(t):Nr(t);if(s?.services){let o=Array.isArray(s.services.autoStart)?s.services.autoStart.map((a)=>String(a)):[];if(o.length>0)n={enabled:s.services.enabled===!0,autoStart:o}}}catch{}return{dependencies:r,services:n}}function Nr(e){let t={},r=e.split(`
7
- `),n=!1,s=!1,o=[],a=!1;for(let i of r){let c=i.trim();if(!c||c.startsWith("#"))continue;if(i.match(/^services:\s*$/)){n=!0,s=!1;continue}if(n&&!i.startsWith(" ")&&!i.startsWith("\t")&&!c.startsWith("-")){if(c!=="services:"){n=!1,s=!1;continue}}if(n){if(c.startsWith("enabled:")){a=c.includes("true");continue}if(c.match(/^autoStart:\s*$/)){s=!0;continue}if(s&&c.startsWith("- ")){let l=c.slice(2).trim();if(l)o.push(l)}}}if(o.length>0)t.services={enabled:a,autoStart:o};return t}async function Ws(e,t="src/packages"){try{let r;if(e.includes("/"))r=Pe.join(t,`${e}.ts`);else{let g=`${e.replace(/\./g,"")}.ts`;r=Pe.join(t,g)}if(!ae.existsSync(r))return[];let n=ae.readFileSync(r,"utf-8"),s=n.indexOf("versions:");if(s===-1)return[];let o=n.substring(s),a=o.indexOf("["),i=o.indexOf("] as const");if(a===-1||i===-1)return[];let l=o.substring(a+1,i).match(/'([^']+)'/g);if(!l)return[];return l.map((g)=>g.replace(/'/g,""))}catch{return[]}}async function Tr(e){try{let{packages:t}=await import("./chunk-k004pgye.js").catch(()=>import("./src/index.js")),r=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),n=t[r];if(!n){let s=Object.values(t);n=s.find((o)=>o.domain===e)||s.find((o)=>Array.isArray(o.aliases)&&o.aliases.includes(e))}if(n&&n.versions&&Array.isArray(n.versions))return n.versions;return[]}catch{return[]}}async function Vt(e,t){let r=await Tr(e);if(r.length===0)return t.split("#")[0].trim().replace(/^[@^~>=<]+/,"")||"latest";let n=t.split("#")[0].trim();if(n==="*"||n==="latest")return r[0];if(n.startsWith("@")){let o=n.slice(1);return r.includes(o)?o:r[0]}return Or(r,n)||r[0]}function Or(e,t){if(t.startsWith("^")){let r=t.slice(1),[n]=pe(r);return e.filter((o)=>{let[a]=pe(o);return a===n&&oe(o,r)>=0})[0]||null}if(t.startsWith("~")){let r=t.slice(1),[n,s]=pe(r);return e.filter((a)=>{let[i,c]=pe(a);return i===n&&c===s&&oe(a,r)>=0})[0]||null}if(t.startsWith(">=")){let r=t.slice(2).trim();return e.filter((s)=>oe(s,r)>=0)[0]||null}if(t.startsWith(">")){let r=t.slice(1).trim();return e.filter((s)=>oe(s,r)>0)[0]||null}if(t.startsWith("<=")){let r=t.slice(2).trim();return e.filter((s)=>oe(s,r)<=0)[0]||null}if(t.startsWith("<")){let r=t.slice(1).trim();return e.filter((s)=>oe(s,r)<0)[0]||null}if(t.startsWith("=")){let r=t.slice(1).trim();return e.includes(r)?r:null}return e.includes(t)?t:null}function pe(e){let t=e.split(".").map((r)=>{let n=r.match(/^\d+/);return n?Number.parseInt(n[0],10):0});return[t[0]||0,t[1]||0,t[2]||0]}function oe(e,t){if(e==="latest"&&t!=="latest")return 1;if(t==="latest"&&e!=="latest")return-1;if(e==="latest"&&t==="latest")return 0;let r=e.split("#")[0].trim(),n=t.split("#")[0].trim(),[s,o,a]=pe(r),[i,c,l]=pe(n);if(s>i)return 1;if(s<i)return-1;if(o>c)return 1;if(o<c)return-1;if(a>l)return 1;if(a<l)return-1;return 0}var xe=null;async function Vr(){if(xe)return xe;return xe=(await import("./chunk-k004pgye.js").catch(()=>import("./src/index.js"))).packages,xe}async function jr(e){try{let t=await Vr(),r=t[e];if(r)return{dependencies:r.dependencies||[],companions:r.companions||[]};let n=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),s=t[n];if(s)return{dependencies:s.dependencies||[],companions:s.companions||[]};let a=Object.values(t).find((i)=>i.domain===e);if(a)return{dependencies:a.dependencies||[],companions:a.companions||[]};return null}catch(t){return console.warn(`Failed to load package data for ${e}: ${t}`),null}}async function Se(e,t={},r=new Set,n=0){let{maxDepth:s=10,verbose:o=!1,targetOs:a,includeOsSpecific:i=!0}=t;if(n>s){if(o)console.warn(` Warning: max dependency depth (${s}) exceeded for ${e}`);return[]}if(r.has(e))return[];if(r.add(e),o)console.log(`${" ".repeat(n)}Resolving dependencies for: ${e}`);let c=[];try{let g=function(f){let h=f.match(/^(linux|darwin|windows):(.+)$/),m=!!h,u=h?h[2]:f,x=h?h[1]:void 0;if(m&&(!i||a&&x!==a))return null;let w=u,k="latest",b="*",P=u.match(/^(@?[^@^~>=<]+(?:\/[^@^~>=<]+)?)([@^~>=<].+)?$/);if(P){if(w=P[1],P[2]){let S=P[2];if(S.startsWith("@"))k=S.substring(1),b=S;else b=S,k=S.replace(/^\D*/,"")}}return{dep:{name:w,version:k,constraint:b,isOsSpecific:m,os:x},pkgName:w}},l=await jr(e),p=[...l?.dependencies||[],...l?.companions||[]].map(g).filter((f)=>f!==null);for(let{dep:f}of p)c.push(f);let y=await Promise.allSettled(p.map(({pkgName:f})=>Se(f,t,r,n+1)));for(let f of y)if(f.status==="fulfilled")c.push(...f.value);else if(o)console.warn(` Warning: transitive dependency resolution failed: ${f.reason}`)}catch(l){if(o)console.warn(`${" ".repeat(n)}Warning: Could not resolve dependencies for ${e}: ${l}`)}return c}async function Ge(e,t={}){let r=new Map,n=[],s={linux:[],darwin:[],windows:[]};for(let i of e){if(!r.has(i.name))r.set(i.name,[]);if(r.get(i.name).push(i),i.isOsSpecific&&i.os)s[i.os].push(i)}let o=[],a=[];for(let[i,c]of r)if(c.length===1){let l=await Vt(i,c[0].constraint),g={...c[0],version:l};o.push(g),a.push(i)}else{let l=c.map((f)=>f.version),g=[...new Set(l)];if(g.length>1)n.push({package:i,versions:g});let d=await Promise.all(c.map(async(f)=>({...f,resolvedVersion:await Vt(i,f.constraint)}))),p=d[0];for(let f of d.slice(1))if(p.constraint==="*"&&f.constraint!=="*")p=f;else if(p.constraint!=="*"&&f.constraint==="*");else if(oe(f.resolvedVersion,p.resolvedVersion)>0)p=f;let y={...p,version:p.resolvedVersion};delete y.resolvedVersion,o.push(y),a.push(i)}return{allDependencies:o,uniquePackages:a,conflicts:n,osSpecificDeps:s}}async function jt(e,t={}){let{verbose:r=!1}=t;if(r)console.log(`Parsing dependency file: ${e}`);let n=we(e);if(r)console.log(`Found ${n.length} direct dependencies`);let s=[...n],o=await Promise.all(n.map(async(c)=>{if(r)console.log(`Resolving transitive dependencies for: ${c.name}`);return Se(c.name,t)}));for(let c of o)s.push(...c);if(r)console.log(`Total dependencies found (before deduplication): ${s.length}`);let a=await Ge(s,t);if(r){if(console.log(`Unique packages after deduplication: ${a.uniquePackages.length}`),a.conflicts.length>0)console.log(`Version conflicts found: ${a.conflicts.length}`)}let i=Pe.extname(e);if(i===".yaml"||i===".yml"){let c=Er(e);if(c.services)a.services=c.services}return a}function qs(e){let t=["deps.yaml","deps.yml","dependencies.yaml","dependencies.yml","pkgx.yaml","pkgx.yml",".deps.yaml",".deps.yml"],r=[];for(let n of t){let s=Pe.join(e,n);if(ae.existsSync(s))r.push(s)}return r}import*as v from"node:fs";import*as T from"node:path";import*as X from"node:os";import*as Ze from"node:https";import*as Xe from"node:http";import{execFileSync as ve}from"node:child_process";import{createHash as Fr}from"node:crypto";import{Transform as Mr}from"node:stream";import{pipeline as _r}from"node:stream/promises";var Bt=(process.env.PANTRY_REGISTRY_URL||"https://registry.pantry.dev").replace(/\/$/,"");function Br(e,t){if(e!=="ziglang.org")return t;return t.replace(/(-dev\.\d+)\+([0-9A-Za-z-]+)$/,"$1_$2")}function Re(){let e=process.env.XDG_DATA_HOME,t=e&&e.length>0?e:T.join(X.homedir(),".local","share");return T.join(t,"pantry","global","bin")}function Ce(){let e=X.platform(),t=X.arch();return{os:e==="darwin"?"darwin":e==="win32"?"windows":"linux",arch:t==="arm64"?"aarch64":"x86_64"}}function Ke(e,t){let r=e.replace(/(-dev\.\d+)_([0-9A-Za-z-]+)$/,"$1+$2"),n=t.os==="darwin"?"macos":t.os,s=t.arch==="aarch64"?"aarch64":"x86_64",o=t.os==="windows"?"zip":"tar.xz",a=`zig-${s}-${n}-${r}`,i=`${a}.${o}`;return{url:r.includes("-dev.")?`https://ziglang.org/builds/${i}`:`https://ziglang.org/download/${r}/${i}`,format:o,prefix:a}}function Lr(e,t){let[r,n,s]=e.split(".").map(Number);if(r!==3||!Number.isInteger(n)||!Number.isInteger(s))throw Error(`Unsupported SQLite version: ${e}`);let o=n>=52?2026:n>=48?2025:2024,i={"darwin-aarch64":"osx-arm64","darwin-x86_64":"osx-x64","linux-x86_64":"linux-x64","windows-aarch64":"win-arm64","windows-x86_64":"win-x64"}[`${t.os}-${t.arch}`];if(!i)throw Error(`Unsupported platform for SQLite tools: ${t.os}-${t.arch}`);let c=`${r}${n}${String(s).padStart(2,"0")}00`;return`https://sqlite.org/${o}/sqlite-tools-${i}-${c}.zip`}function Lt(e){return e==="bun.sh"||e==="bun.com"}var ce={"github.com/mail-os/mail":{getDownloadUrl(e,t){if(t.os!=="linux"||t.arch!=="x86_64")throw Error("github.com/mail-os/mail currently publishes linux-x86_64 release binaries");let r={darwin:"macos",linux:"linux",windows:"windows"},n=`mail-${t.arch}-${r[t.os]}`;return`https://github.com/mail-os/mail/releases/download/v${e}/${n}.tar.gz`},getArchiveFormat(){return"tar.gz"},getBinaries(e){let t={darwin:"macos",linux:"linux",windows:"windows"};return[`mail-${e.arch}-${t[e.os]}`,"mail"]}},"ziglang.org":{getDownloadUrl(e,t){return Ke(e,t).url},getArchiveFormat(e){return Ke("0.0.0",e).format},getBinaries(e){return e.os==="windows"?["zig.exe"]:["zig"]},getArchivePrefix(e,t){return Ke(e,t).prefix}},"bun.sh":{getDownloadUrl(e,t){let r={"darwin-aarch64":"darwin-aarch64","darwin-x86_64":"darwin-x64","linux-aarch64":"linux-aarch64","linux-x86_64":"linux-x64","windows-x86_64":"windows-x64"},n=`${t.os}-${t.arch}`,s=r[n]||"linux-x64";return`https://github.com/oven-sh/bun/releases/download/bun-v${e}/bun-${s}.zip`},getArchiveFormat(){return"zip"},getBinaries(e){return e.os==="windows"?["bun.exe"]:["bun","bunx"]},getArchivePrefix(e,t){let r={"darwin-aarch64":"bun-darwin-aarch64","darwin-x86_64":"bun-darwin-x64","linux-aarch64":"bun-linux-aarch64","linux-x86_64":"bun-linux-x64","windows-x86_64":"bun-windows-x64"},n=`${t.os}-${t.arch}`,s=r[n];if(!s)throw Error(`Unsupported platform for bun: ${n}`);return s}},"sqlite.org":{getDownloadUrl(e,t){return Lr(e,t)},getArchiveFormat(){return"zip"},getBinaries(e){let t=e.os==="windows"?".exe":"";return[`sqlite3${t}`,`sqldiff${t}`,`sqlite3_analyzer${t}`,`sqlite3_rsync${t}`]}},"nodejs.org":{getDownloadUrl(e,t){let r={darwin:"darwin",linux:"linux",windows:"win"},n={x86_64:"x64",aarch64:"arm64"},s=t.os==="windows"?"zip":"tar.xz";return`https://nodejs.org/dist/v${e}/node-v${e}-${r[t.os]}-${n[t.arch]}.${s}`},getArchiveFormat(e){return e.os==="windows"?"zip":"tar.xz"},getBinaries(e){return e.os==="windows"?["node.exe","npm.cmd","npx.cmd"]:["node","npm","npx"]},getArchivePrefix(e,t){let r={darwin:"darwin",linux:"linux",windows:"win"},n={x86_64:"x64",aarch64:"arm64"};return`node-v${e}-${r[t.os]}-${n[t.arch]}`}}};function Ft(e,t,r,n){v.mkdirSync(r,{recursive:!0});let s=null;for(let o of t){let a=T.join(e,o);if(!v.existsSync(a))a=T.join(e,"bin",o);if(!v.existsSync(a)){if(s){let c=T.join(r,o);try{v.unlinkSync(c)}catch{}if(n.os==="windows")v.copyFileSync(s,c);else v.symlinkSync(s,c)}continue}if(!s)s=a;let i=T.join(r,o);try{v.unlinkSync(i)}catch{}if(n.os==="windows")v.copyFileSync(a,i);else v.symlinkSync(a,i)}}async function zt(e,t,r={}){let n=r.platform||Ce(),s=ce[e];if(!s)throw Error(`Unknown package: ${e}. Supported: ${Object.keys(ce).join(", ")}`);if(/^[\^~>=<]/.test(t))t=await Yr(e,t,n);else if(t==="latest"||t==="*"||!t)t=await Qe(e,n);else if(e==="ziglang.org"&&t.endsWith("-dev")){let h=await Ur(t,n,{onRetry:r.onRetry});if(!h)throw Error(`Could not resolve ${t} to a published ziglang.org development build`);t=h}if(t=Br(e,t),!t)throw Error(`Could not resolve a concrete version for ${e} (got empty string from resolver)`);let o=r.installDir||T.join(process.cwd(),"pantry"),a=T.join(o,".bin"),i=T.join(o,e.replace(/\./g,"-"),t),c=s.getBinaries(n);if(c.length===0)throw Error(`No binaries defined for ${e} on ${n.os}-${n.arch}`);let l=T.join(i,c[0]),g=T.join(i,"bin",c[0]);if(v.existsSync(l)||v.existsSync(g)){if(!r.quiet)console.log(` ✓ ${e}@${t} (cached)`);if(r.createBinLinks!==!1)Ft(i,c,a,n);let h=Mt(i,c,n,r);return{name:e,version:t,installPath:i,binaries:c,globalLinks:h}}let d=s.getDownloadUrl(t,n),p=s.getArchiveFormat(n);if(!r.quiet)console.log(` → ${e}@${t} from ${new URL(d).hostname}`);let y=v.mkdtempSync(T.join(X.tmpdir(),"pantry-")),f=T.join(y,`archive.${p}`);try{let h;if(d.startsWith(`${Bt}/binaries/`)){let k=T.join(y,"archive.sha256");await _t(`${d}.sha256`,k,{quiet:r.quiet,onRetry:r.onRetry});let b=v.readFileSync(k,"utf8").match(/\b([a-f0-9]{64})\b/i)?.[1];if(!b)throw Error(`Invalid SHA-256 checksum response for ${d}`);h=b.toLowerCase()}await _t(d,f,{quiet:r.quiet,onRetry:r.onRetry,expectedSha256:h});let m=T.join(y,"extracted");v.mkdirSync(m,{recursive:!0}),await tn(f,m,p);let u=m,x=s.getArchivePrefix?.(t,n);if(x){let k=T.join(m,x);if(v.existsSync(k))u=k;else{let P=v.readdirSync(m).find((S)=>v.statSync(T.join(m,S)).isDirectory());if(P)u=T.join(m,P)}}if(v.mkdirSync(i,{recursive:!0}),rn(u,i),n.os!=="windows"){for(let k of c){let b=T.join(i,k);if(v.existsSync(b))v.chmodSync(b,493);let P=T.join(i,"bin",k);if(v.existsSync(P))v.chmodSync(P,493)}for(let k of["bin","sbin","libexec"])Ht(T.join(i,k))}if(r.createBinLinks!==!1)Ft(i,c,a,n);if(!r.quiet)console.log(` ✓ ${e}@${t}`);let w=Mt(i,c,n,r);return{name:e,version:t,installPath:i,binaries:c,globalLinks:w}}finally{try{v.rmSync(y,{recursive:!0,force:!0})}catch{}}}function Mt(e,t,r,n){if(!n.globalBin)return[];let s=typeof n.globalBin==="string"?n.globalBin:Re();v.mkdirSync(s,{recursive:!0});let o=[];for(let a of t){let i=T.join(e,a);if(!v.existsSync(i))i=T.join(e,"bin",a);if(!v.existsSync(i))continue;let c=T.join(s,a);try{v.unlinkSync(c)}catch{}if(r.os==="windows")v.copyFileSync(i,c);else v.symlinkSync(i,c);o.push(c)}if(!n.quiet&&o.length>0)console.log(` → linked ${o.length} binary(ies) into ${s}`);return o}async function zr(e,t={}){return Promise.all(e.map((r)=>zt(r.domain,r.version,t)))}async function Qe(e,t=Ce()){if(Lt(e)){let n=(await Y("https://api.github.com/repos/oven-sh/bun/releases/latest").catch(()=>null))?.tag_name?.replace(/^bun-v/,"")||"";if(n)return n;let s=await He(e);if(s)return s;throw Error("Failed to resolve latest bun.sh version (GitHub API unreachable, no bundled metadata)")}if(e==="ziglang.org"){let r=await et(e,t);if(r.length>0)return r.sort(Je)[0];throw Error(`Failed to resolve a ziglang.org version published for ${Ut(t)}`)}if(e==="nodejs.org"){let n=await Y("https://nodejs.org/dist/index.json").catch(()=>null)||[],o=(n.find((i)=>i.lts)?.version||n[0]?.version||"").replace(/^v/,"");if(o)return o;let a=await He(e);if(a)return a;throw Error("Failed to resolve latest nodejs.org version")}if(e==="github.com/mail-os/mail"){let n=(await Y("https://api.github.com/repos/mail-os/mail/releases/latest").catch(()=>null))?.tag_name?.replace(/^v/,"")||"";if(n)return n;let o=((await Y("https://api.github.com/repos/mail-os/mail/tags?per_page=1").catch(()=>null))?.[0]?.name||"").replace(/^v/,"");if(o)return o;let a=await He(e);if(a)return a;throw Error("Failed to resolve latest github.com/mail-os/mail version")}throw Error(`Cannot resolve latest version for ${e}`)}async function He(e){try{let t=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),{packages:r}=await import("./chunk-k004pgye.js").catch(()=>import("./src/index.js")),s=r[t]?.versions||[];return s.find((o)=>!o.includes("-"))||s[0]||""}catch{return""}}async function Ur(e,t,r={}){let s=(await et("ziglang.org",t,r)).filter((i)=>i.startsWith(`${e}.`)).sort(Je)[0];if(s)return s;let a=(await Y("https://ziglang.org/download/index.json",3,r).catch(()=>null))?.master?.version||"";return a.startsWith(`${e}.`)?a:null}function Ut(e){let t=e.arch==="aarch64"?"arm64":"x86-64";return`${e.os}-${t}`}function Wr(e,t){let r=Ut(t);return Object.entries(e?.versions||{}).filter(([,n])=>Object.hasOwn(n.platforms||{},r)).map(([n])=>n)}async function et(e,t,r={}){let n=await Y(`${Bt}/binaries/${encodeURI(e)}/metadata.json`,5,r).catch(()=>null);return Wr(n,t)}function Wt(e){let t=e.match(/^([~^]|>=|<=|>|<|=)(\d+(?:\.\d+){0,10}(?:-[0-9A-Za-z.-]+)?(?:[+_][0-9A-Za-z.-]+)?)/);if(!t)return null;return{operator:t[1],target:t[2]}}function $e(e){return e.split(/[+_-]/,1)[0].split(".").map((t)=>Number.parseInt(t,10))}function qt(e,t){let r=$e(e),n=$e(t);for(let c=0;c<Math.max(r.length,n.length,3);c++){let l=(r[c]||0)-(n[c]||0);if(l)return l}let s=e.includes("-"),o=t.includes("-");if(s!==o)return s?-1:1;let a=Number.parseInt(e.match(/-dev\.(\d+)/)?.[1]||"0",10),i=Number.parseInt(t.match(/-dev\.(\d+)/)?.[1]||"0",10);return a-i}function qr(e,t){let{operator:r,target:n}=t;if(e.includes("-")&&!n.includes("-"))return!1;let s=$e(e),o=$e(n);if(s.some(Number.isNaN)||o.some(Number.isNaN))return!1;let[a,i,c]=[s[0]||0,s[1]||0,s[2]||0],[l,g,d]=[o[0]||0,o[1]||0,o[2]||0],p=qt(e,n);if(r==="^"){if(p<0)return!1;if(l===0&&g===0)return a===0&&i===0&&c===d;if(l===0)return a===0&&i===g;return a===l}if(r==="~"){if(p<0)return!1;return o.length===1?a===l:a===l&&i===g}if(r===">=")return p>=0;if(r==="<=")return p<=0;if(r===">")return p>0;if(r==="<")return p<0;if(r==="=")return p===0;return!1}async function Gr(e,t){if(Lt(e))return(await Y("https://api.github.com/repos/oven-sh/bun/releases?per_page=100").catch(()=>null)||[]).map((s)=>(s.tag_name||"").replace(/^bun-v/,"")).filter(Boolean);if(e==="nodejs.org")return(await Y("https://nodejs.org/dist/index.json").catch(()=>null)||[]).map((s)=>(s.version||"").replace(/^v/,"")).filter(Boolean);if(e==="ziglang.org"){let r=await Y("https://ziglang.org/download/index.json").catch(()=>null),n=Kr(r,t);if(n.length>0)return n;return await et(e,t)}return[]}function Kr(e,t){let r=`${t.arch}-${t.os==="darwin"?"macos":t.os}`;return Object.entries(e||{}).filter(([,n])=>Boolean(n[r])).map(([n,s])=>s.version||n).filter(Boolean)}function Ye(e,t){return qt(t,e)}function Hr(e,t){let r=Wt(e);if(!r)return null;return[...new Set(t)].sort(Ye).find((n)=>qr(n,r))||null}async function Yr(e,t,r){if(!Wt(t))return Qe(e,r);let n;try{let i=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),{packages:c}=await import("./chunk-k004pgye.js").catch(()=>import("./src/index.js"));n=c[i]?.versions||[]}catch{n=[]}let s=await Gr(e,r),o=e==="ziglang.org"?s.sort(Ye):[...new Set([...s,...n])].sort(Ye),a=Hr(t,o);if(a)return a;throw Error(`No version of ${e} satisfies "${t}" (checked ${o.length} version${o.length===1?"":"s"}${o.length>0?`, newest ${o[0]}`:""}).`)}var Jr=4;function Ae(e){return e instanceof Error?e.message:String(e)}function Zr(e){if(typeof e==="object"&&e!==null&&"statusCode"in e){let r=Number(e.statusCode);if(Number.isFinite(r))return r}let t=Ae(e).match(/\bHTTP\s+(\d{3})\b/i);return t?Number(t[1]):void 0}function Xr(e){if(typeof e!=="object"||e===null)return"";let t="code"in e?String(e.code||""):"";if(t)return t;let r="cause"in e?e.cause:void 0;return typeof r==="object"&&r!==null&&"code"in r?String(r.code||""):""}function Qr(e){let t=Zr(e);if(t!==void 0)return t===408||t===425||t===429||t>=500;if(/^(?:ECONNRESET|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENETDOWN|ENETUNREACH|EHOSTUNREACH|UND_ERR_SOCKET)$/i.test(Xr(e)))return!0;return/socket hang up|connection reset|premature close|aborted|terminated|timed? ?out|temporar|stalled|incomplete download|checksum mismatch/i.test(Ae(e))}async function Gt(e,t,r={}){let n=r.maxAttempts??Jr,s=r.retryDelayMs??1000,o=r.sleep??((i)=>new Promise((c)=>setTimeout(c,i))),a;for(let i=1;i<=n;i+=1)try{return await t()}catch(c){if(a=c,!Qr(c))throw c;if(i===n)break;let l=Math.min(s*2**(i-1),1e4);r.onRetry?.(`${e} failed (${Ae(c)}); retrying in ${l}ms`),await o(l)}throw Error(`${e} failed after ${n} attempts: ${Ae(a)}`)}function Kt(e,t,r){return new Promise((n,s)=>{let a=(e.startsWith("https")?Ze.get:Xe.get)(e,{headers:{"User-Agent":"pantry-installer"}},(i)=>{if(i.statusCode&&i.statusCode>=300&&i.statusCode<400&&i.headers.location){if(i.resume(),t<=0)return s(Error(`Too many redirects for ${e}`));let c=new URL(i.headers.location,e).href;return Kt(c,t-1,r).then(n,s)}if(!i.statusCode||i.statusCode<200||i.statusCode>=300){i.resume();let c=Object.assign(Error(`HTTP ${i.statusCode||"unknown"} downloading ${e}`),{statusCode:i.statusCode});return s(c)}i.setTimeout(r,()=>{i.destroy(Error(`Download stalled (no data for ${r/1000}s): ${e}`))}),n(i)});a.setTimeout(r,()=>{a.destroy(Error(`Download timed out after ${r/1000}s: ${e}`))}),a.once("error",s)})}async function en(e,t,r){let n=`${t}.part`;try{v.rmSync(n,{force:!0})}catch{}let s=await Kt(e,10,r.stallTimeoutMs??60000),o=!r.quiet&&process.stderr.isTTY,a=Number.parseInt(String(s.headers["content-length"]||""),10),i=Number.isFinite(a)?a:0,c=0,l=0,g=r.expectedSha256?Fr("sha256"):void 0,d=new Mr({transform(p,y,f){c+=p.length,g?.update(p);let h=Date.now();if(o&&h-l>200){l=h;let m=(c/1048576).toFixed(1);if(i>0){let u=(i/1048576).toFixed(1),x=Math.floor(c/i*100);process.stderr.write(`\r ${m}/${u} MB (${x}%)`)}else process.stderr.write(`\r ${m} MB`)}f(null,p)}});try{if(await _r(s,d,v.createWriteStream(n)),!s.complete||i>0&&c!==i)throw Error(`Incomplete download for ${e}: received ${c} of ${i||"unknown"} bytes`);if(r.expectedSha256){let p=g.digest("hex");if(p!==r.expectedSha256.toLowerCase())throw Error(`Checksum mismatch for ${e}: expected ${r.expectedSha256}, got ${p}`)}v.renameSync(n,t)}catch(p){try{v.rmSync(n,{force:!0})}catch{}throw p}finally{if(o&&l>0)process.stderr.write("\r\x1B[K")}}async function _t(e,t,r={}){await Gt(`Download ${e}`,()=>en(e,t,r),r)}async function tn(e,t,r){if(r==="zip")if(process.platform==="win32")ve("powershell",["-NoProfile","-Command","Expand-Archive","-Path",e,"-DestinationPath",t,"-Force"],{stdio:"pipe"});else ve("unzip",["-o","-q",e,"-d",t],{stdio:"pipe"});else if(r==="tar.xz")ve("tar",["xJf",e,"-C",t],{stdio:"pipe"});else if(r==="tar.gz")ve("tar",["xzf",e,"-C",t],{stdio:"pipe"});else throw Error(`Unsupported archive format: ${r}`)}function rn(e,t){v.cpSync(e,t,{recursive:!0})}function Ht(e){let t;try{t=v.readdirSync(e,{withFileTypes:!0})}catch{return}for(let r of t){let n=T.join(e,r.name);try{if(r.isDirectory()){Ht(n);continue}if(!r.isFile())continue;let s=v.statSync(n).mode&511,o=s|(s&292)>>2;if(o!==s)v.chmodSync(n,o)}catch{}}}function Yt(e,t){return new Promise((r,n)=>{let s=e.startsWith("https")?Ze.get:Xe.get,o={"User-Agent":"pantry-installer",Accept:"application/json"};if(e.includes("api.github.com")){let i=process.env.GITHUB_TOKEN||process.env.GH_TOKEN;if(i)o.Authorization=`Bearer ${i}`}let a=s(e,{headers:o,timeout:30000},(i)=>{if(i.statusCode&&i.statusCode>=300&&i.statusCode<400&&i.headers.location){if(t<=0)return n(Error(`Too many redirects for ${e}`));let l=new URL(i.headers.location,e).href;return Yt(l,t-1).then(r,n)}if(!i.statusCode||i.statusCode<200||i.statusCode>=300)return n(Object.assign(Error(`HTTP ${i.statusCode||"unknown"} fetching ${e}`),{statusCode:i.statusCode}));let c="";i.on("data",(l)=>c+=l),i.on("end",()=>{try{r(JSON.parse(c))}catch(l){n(l)}})});a.on("error",n),a.on("timeout",()=>{a.destroy(),n(Error(`Request timed out: ${e}`))})})}function Y(e,t=5,r={}){return Gt(`Fetch ${e}`,()=>Yt(e,t),r)}ce["bun.com"]=ce["bun.sh"];function nn(e){return e in ce}function Xs(){return Object.keys(ce)}function Qs(e){let t=ce[e];if(!t)return;let r=Ce();return t.getBinaries(r)[0]}import*as L from"node:fs";import*as Ee from"node:os";import*as le from"node:path";var De="# >>> pantry shell-init >>>",Ie="# <<< pantry shell-init <<<";function Ne(){let e=process.env.SHELL??"";if(e.endsWith("/zsh")||e==="zsh")return"zsh";if(e.endsWith("/bash")||e==="bash")return"bash";if(e.endsWith("/fish")||e==="fish")return"fish";return"unknown"}function tt(e){let t=Ee.homedir();switch(e){case"zsh":{let r=process.env.ZDOTDIR;return le.join(r&&r.length>0?r:t,".zshrc")}case"bash":{if(Ee.platform()==="darwin"){let r=le.join(t,".bash_profile");if(L.existsSync(r))return r}return le.join(t,".bashrc")}case"fish":return le.join(t,".config","fish","config.fish");case"unknown":return null}}function Jt(e={}){let t=e.globalBin??Re();if((e.shell??Ne())==="fish")return[De,`if test -d "${t}"`,` set -gx PATH "${t}" $PATH`,"end",Ie,""].join(`
7
+ `),n=!1,s=!1,o=[],a=!1;for(let i of r){let c=i.trim();if(!c||c.startsWith("#"))continue;if(i.match(/^services:\s*$/)){n=!0,s=!1;continue}if(n&&!i.startsWith(" ")&&!i.startsWith("\t")&&!c.startsWith("-")){if(c!=="services:"){n=!1,s=!1;continue}}if(n){if(c.startsWith("enabled:")){a=c.includes("true");continue}if(c.match(/^autoStart:\s*$/)){s=!0;continue}if(s&&c.startsWith("- ")){let l=c.slice(2).trim();if(l)o.push(l)}}}if(o.length>0)t.services={enabled:a,autoStart:o};return t}async function Ws(e,t="src/packages"){try{let r;if(e.includes("/"))r=Pe.join(t,`${e}.ts`);else{let g=`${e.replace(/\./g,"")}.ts`;r=Pe.join(t,g)}if(!ae.existsSync(r))return[];let n=ae.readFileSync(r,"utf-8"),s=n.indexOf("versions:");if(s===-1)return[];let o=n.substring(s),a=o.indexOf("["),i=o.indexOf("] as const");if(a===-1||i===-1)return[];let l=o.substring(a+1,i).match(/'([^']+)'/g);if(!l)return[];return l.map((g)=>g.replace(/'/g,""))}catch{return[]}}async function Tr(e){try{let{packages:t}=await import("./chunk-v0par3ra.js").catch(()=>import("./src/index.js")),r=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),n=t[r];if(!n){let s=Object.values(t);n=s.find((o)=>o.domain===e)||s.find((o)=>Array.isArray(o.aliases)&&o.aliases.includes(e))}if(n&&n.versions&&Array.isArray(n.versions))return n.versions;return[]}catch{return[]}}async function Vt(e,t){let r=await Tr(e);if(r.length===0)return t.split("#")[0].trim().replace(/^[@^~>=<]+/,"")||"latest";let n=t.split("#")[0].trim();if(n==="*"||n==="latest")return r[0];if(n.startsWith("@")){let o=n.slice(1);return r.includes(o)?o:r[0]}return Or(r,n)||r[0]}function Or(e,t){if(t.startsWith("^")){let r=t.slice(1),[n]=pe(r);return e.filter((o)=>{let[a]=pe(o);return a===n&&oe(o,r)>=0})[0]||null}if(t.startsWith("~")){let r=t.slice(1),[n,s]=pe(r);return e.filter((a)=>{let[i,c]=pe(a);return i===n&&c===s&&oe(a,r)>=0})[0]||null}if(t.startsWith(">=")){let r=t.slice(2).trim();return e.filter((s)=>oe(s,r)>=0)[0]||null}if(t.startsWith(">")){let r=t.slice(1).trim();return e.filter((s)=>oe(s,r)>0)[0]||null}if(t.startsWith("<=")){let r=t.slice(2).trim();return e.filter((s)=>oe(s,r)<=0)[0]||null}if(t.startsWith("<")){let r=t.slice(1).trim();return e.filter((s)=>oe(s,r)<0)[0]||null}if(t.startsWith("=")){let r=t.slice(1).trim();return e.includes(r)?r:null}return e.includes(t)?t:null}function pe(e){let t=e.split(".").map((r)=>{let n=r.match(/^\d+/);return n?Number.parseInt(n[0],10):0});return[t[0]||0,t[1]||0,t[2]||0]}function oe(e,t){if(e==="latest"&&t!=="latest")return 1;if(t==="latest"&&e!=="latest")return-1;if(e==="latest"&&t==="latest")return 0;let r=e.split("#")[0].trim(),n=t.split("#")[0].trim(),[s,o,a]=pe(r),[i,c,l]=pe(n);if(s>i)return 1;if(s<i)return-1;if(o>c)return 1;if(o<c)return-1;if(a>l)return 1;if(a<l)return-1;return 0}var xe=null;async function Vr(){if(xe)return xe;return xe=(await import("./chunk-v0par3ra.js").catch(()=>import("./src/index.js"))).packages,xe}async function jr(e){try{let t=await Vr(),r=t[e];if(r)return{dependencies:r.dependencies||[],companions:r.companions||[]};let n=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),s=t[n];if(s)return{dependencies:s.dependencies||[],companions:s.companions||[]};let a=Object.values(t).find((i)=>i.domain===e);if(a)return{dependencies:a.dependencies||[],companions:a.companions||[]};return null}catch(t){return console.warn(`Failed to load package data for ${e}: ${t}`),null}}async function Se(e,t={},r=new Set,n=0){let{maxDepth:s=10,verbose:o=!1,targetOs:a,includeOsSpecific:i=!0}=t;if(n>s){if(o)console.warn(` Warning: max dependency depth (${s}) exceeded for ${e}`);return[]}if(r.has(e))return[];if(r.add(e),o)console.log(`${" ".repeat(n)}Resolving dependencies for: ${e}`);let c=[];try{let g=function(f){let h=f.match(/^(linux|darwin|windows):(.+)$/),m=!!h,u=h?h[2]:f,x=h?h[1]:void 0;if(m&&(!i||a&&x!==a))return null;let w=u,k="latest",b="*",P=u.match(/^(@?[^@^~>=<]+(?:\/[^@^~>=<]+)?)([@^~>=<].+)?$/);if(P){if(w=P[1],P[2]){let S=P[2];if(S.startsWith("@"))k=S.substring(1),b=S;else b=S,k=S.replace(/^\D*/,"")}}return{dep:{name:w,version:k,constraint:b,isOsSpecific:m,os:x},pkgName:w}},l=await jr(e),p=[...l?.dependencies||[],...l?.companions||[]].map(g).filter((f)=>f!==null);for(let{dep:f}of p)c.push(f);let y=await Promise.allSettled(p.map(({pkgName:f})=>Se(f,t,r,n+1)));for(let f of y)if(f.status==="fulfilled")c.push(...f.value);else if(o)console.warn(` Warning: transitive dependency resolution failed: ${f.reason}`)}catch(l){if(o)console.warn(`${" ".repeat(n)}Warning: Could not resolve dependencies for ${e}: ${l}`)}return c}async function Ge(e,t={}){let r=new Map,n=[],s={linux:[],darwin:[],windows:[]};for(let i of e){if(!r.has(i.name))r.set(i.name,[]);if(r.get(i.name).push(i),i.isOsSpecific&&i.os)s[i.os].push(i)}let o=[],a=[];for(let[i,c]of r)if(c.length===1){let l=await Vt(i,c[0].constraint),g={...c[0],version:l};o.push(g),a.push(i)}else{let l=c.map((f)=>f.version),g=[...new Set(l)];if(g.length>1)n.push({package:i,versions:g});let d=await Promise.all(c.map(async(f)=>({...f,resolvedVersion:await Vt(i,f.constraint)}))),p=d[0];for(let f of d.slice(1))if(p.constraint==="*"&&f.constraint!=="*")p=f;else if(p.constraint!=="*"&&f.constraint==="*");else if(oe(f.resolvedVersion,p.resolvedVersion)>0)p=f;let y={...p,version:p.resolvedVersion};delete y.resolvedVersion,o.push(y),a.push(i)}return{allDependencies:o,uniquePackages:a,conflicts:n,osSpecificDeps:s}}async function jt(e,t={}){let{verbose:r=!1}=t;if(r)console.log(`Parsing dependency file: ${e}`);let n=we(e);if(r)console.log(`Found ${n.length} direct dependencies`);let s=[...n],o=await Promise.all(n.map(async(c)=>{if(r)console.log(`Resolving transitive dependencies for: ${c.name}`);return Se(c.name,t)}));for(let c of o)s.push(...c);if(r)console.log(`Total dependencies found (before deduplication): ${s.length}`);let a=await Ge(s,t);if(r){if(console.log(`Unique packages after deduplication: ${a.uniquePackages.length}`),a.conflicts.length>0)console.log(`Version conflicts found: ${a.conflicts.length}`)}let i=Pe.extname(e);if(i===".yaml"||i===".yml"){let c=Er(e);if(c.services)a.services=c.services}return a}function qs(e){let t=["deps.yaml","deps.yml","dependencies.yaml","dependencies.yml","pkgx.yaml","pkgx.yml",".deps.yaml",".deps.yml"],r=[];for(let n of t){let s=Pe.join(e,n);if(ae.existsSync(s))r.push(s)}return r}import*as v from"node:fs";import*as T from"node:path";import*as X from"node:os";import*as Ze from"node:https";import*as Xe from"node:http";import{execFileSync as ve}from"node:child_process";import{createHash as Fr}from"node:crypto";import{Transform as Mr}from"node:stream";import{pipeline as _r}from"node:stream/promises";var Bt=(process.env.PANTRY_REGISTRY_URL||"https://registry.pantry.dev").replace(/\/$/,"");function Br(e,t){if(e!=="ziglang.org")return t;return t.replace(/(-dev\.\d+)\+([0-9A-Za-z-]+)$/,"$1_$2")}function Re(){let e=process.env.XDG_DATA_HOME,t=e&&e.length>0?e:T.join(X.homedir(),".local","share");return T.join(t,"pantry","global","bin")}function Ce(){let e=X.platform(),t=X.arch();return{os:e==="darwin"?"darwin":e==="win32"?"windows":"linux",arch:t==="arm64"?"aarch64":"x86_64"}}function Ke(e,t){let r=e.replace(/(-dev\.\d+)_([0-9A-Za-z-]+)$/,"$1+$2"),n=t.os==="darwin"?"macos":t.os,s=t.arch==="aarch64"?"aarch64":"x86_64",o=t.os==="windows"?"zip":"tar.xz",a=`zig-${s}-${n}-${r}`,i=`${a}.${o}`;return{url:r.includes("-dev.")?`https://ziglang.org/builds/${i}`:`https://ziglang.org/download/${r}/${i}`,format:o,prefix:a}}function Lr(e,t){let[r,n,s]=e.split(".").map(Number);if(r!==3||!Number.isInteger(n)||!Number.isInteger(s))throw Error(`Unsupported SQLite version: ${e}`);let o=n>=52?2026:n>=48?2025:2024,i={"darwin-aarch64":"osx-arm64","darwin-x86_64":"osx-x64","linux-x86_64":"linux-x64","windows-aarch64":"win-arm64","windows-x86_64":"win-x64"}[`${t.os}-${t.arch}`];if(!i)throw Error(`Unsupported platform for SQLite tools: ${t.os}-${t.arch}`);let c=`${r}${n}${String(s).padStart(2,"0")}00`;return`https://sqlite.org/${o}/sqlite-tools-${i}-${c}.zip`}function Lt(e){return e==="bun.sh"||e==="bun.com"}var ce={"github.com/mail-os/mail":{getDownloadUrl(e,t){if(t.os!=="linux"||t.arch!=="x86_64")throw Error("github.com/mail-os/mail currently publishes linux-x86_64 release binaries");let r={darwin:"macos",linux:"linux",windows:"windows"},n=`mail-${t.arch}-${r[t.os]}`;return`https://github.com/mail-os/mail/releases/download/v${e}/${n}.tar.gz`},getArchiveFormat(){return"tar.gz"},getBinaries(e){let t={darwin:"macos",linux:"linux",windows:"windows"};return[`mail-${e.arch}-${t[e.os]}`,"mail"]}},"ziglang.org":{getDownloadUrl(e,t){return Ke(e,t).url},getArchiveFormat(e){return Ke("0.0.0",e).format},getBinaries(e){return e.os==="windows"?["zig.exe"]:["zig"]},getArchivePrefix(e,t){return Ke(e,t).prefix}},"bun.sh":{getDownloadUrl(e,t){let r={"darwin-aarch64":"darwin-aarch64","darwin-x86_64":"darwin-x64","linux-aarch64":"linux-aarch64","linux-x86_64":"linux-x64","windows-x86_64":"windows-x64"},n=`${t.os}-${t.arch}`,s=r[n]||"linux-x64";return`https://github.com/oven-sh/bun/releases/download/bun-v${e}/bun-${s}.zip`},getArchiveFormat(){return"zip"},getBinaries(e){return e.os==="windows"?["bun.exe"]:["bun","bunx"]},getArchivePrefix(e,t){let r={"darwin-aarch64":"bun-darwin-aarch64","darwin-x86_64":"bun-darwin-x64","linux-aarch64":"bun-linux-aarch64","linux-x86_64":"bun-linux-x64","windows-x86_64":"bun-windows-x64"},n=`${t.os}-${t.arch}`,s=r[n];if(!s)throw Error(`Unsupported platform for bun: ${n}`);return s}},"sqlite.org":{getDownloadUrl(e,t){return Lr(e,t)},getArchiveFormat(){return"zip"},getBinaries(e){let t=e.os==="windows"?".exe":"";return[`sqlite3${t}`,`sqldiff${t}`,`sqlite3_analyzer${t}`,`sqlite3_rsync${t}`]}},"nodejs.org":{getDownloadUrl(e,t){let r={darwin:"darwin",linux:"linux",windows:"win"},n={x86_64:"x64",aarch64:"arm64"},s=t.os==="windows"?"zip":"tar.xz";return`https://nodejs.org/dist/v${e}/node-v${e}-${r[t.os]}-${n[t.arch]}.${s}`},getArchiveFormat(e){return e.os==="windows"?"zip":"tar.xz"},getBinaries(e){return e.os==="windows"?["node.exe","npm.cmd","npx.cmd"]:["node","npm","npx"]},getArchivePrefix(e,t){let r={darwin:"darwin",linux:"linux",windows:"win"},n={x86_64:"x64",aarch64:"arm64"};return`node-v${e}-${r[t.os]}-${n[t.arch]}`}}};function Ft(e,t,r,n){v.mkdirSync(r,{recursive:!0});let s=null;for(let o of t){let a=T.join(e,o);if(!v.existsSync(a))a=T.join(e,"bin",o);if(!v.existsSync(a)){if(s){let c=T.join(r,o);try{v.unlinkSync(c)}catch{}if(n.os==="windows")v.copyFileSync(s,c);else v.symlinkSync(s,c)}continue}if(!s)s=a;let i=T.join(r,o);try{v.unlinkSync(i)}catch{}if(n.os==="windows")v.copyFileSync(a,i);else v.symlinkSync(a,i)}}async function zt(e,t,r={}){let n=r.platform||Ce(),s=ce[e];if(!s)throw Error(`Unknown package: ${e}. Supported: ${Object.keys(ce).join(", ")}`);if(/^[\^~>=<]/.test(t))t=await Yr(e,t,n);else if(t==="latest"||t==="*"||!t)t=await Qe(e,n);else if(e==="ziglang.org"&&t.endsWith("-dev")){let h=await Ur(t,n,{onRetry:r.onRetry});if(!h)throw Error(`Could not resolve ${t} to a published ziglang.org development build`);t=h}if(t=Br(e,t),!t)throw Error(`Could not resolve a concrete version for ${e} (got empty string from resolver)`);let o=r.installDir||T.join(process.cwd(),"pantry"),a=T.join(o,".bin"),i=T.join(o,e.replace(/\./g,"-"),t),c=s.getBinaries(n);if(c.length===0)throw Error(`No binaries defined for ${e} on ${n.os}-${n.arch}`);let l=T.join(i,c[0]),g=T.join(i,"bin",c[0]);if(v.existsSync(l)||v.existsSync(g)){if(!r.quiet)console.log(` ✓ ${e}@${t} (cached)`);if(r.createBinLinks!==!1)Ft(i,c,a,n);let h=Mt(i,c,n,r);return{name:e,version:t,installPath:i,binaries:c,globalLinks:h}}let d=s.getDownloadUrl(t,n),p=s.getArchiveFormat(n);if(!r.quiet)console.log(` → ${e}@${t} from ${new URL(d).hostname}`);let y=v.mkdtempSync(T.join(X.tmpdir(),"pantry-")),f=T.join(y,`archive.${p}`);try{let h;if(d.startsWith(`${Bt}/binaries/`)){let k=T.join(y,"archive.sha256");await _t(`${d}.sha256`,k,{quiet:r.quiet,onRetry:r.onRetry});let b=v.readFileSync(k,"utf8").match(/\b([a-f0-9]{64})\b/i)?.[1];if(!b)throw Error(`Invalid SHA-256 checksum response for ${d}`);h=b.toLowerCase()}await _t(d,f,{quiet:r.quiet,onRetry:r.onRetry,expectedSha256:h});let m=T.join(y,"extracted");v.mkdirSync(m,{recursive:!0}),await tn(f,m,p);let u=m,x=s.getArchivePrefix?.(t,n);if(x){let k=T.join(m,x);if(v.existsSync(k))u=k;else{let P=v.readdirSync(m).find((S)=>v.statSync(T.join(m,S)).isDirectory());if(P)u=T.join(m,P)}}if(v.mkdirSync(i,{recursive:!0}),rn(u,i),n.os!=="windows"){for(let k of c){let b=T.join(i,k);if(v.existsSync(b))v.chmodSync(b,493);let P=T.join(i,"bin",k);if(v.existsSync(P))v.chmodSync(P,493)}for(let k of["bin","sbin","libexec"])Ht(T.join(i,k))}if(r.createBinLinks!==!1)Ft(i,c,a,n);if(!r.quiet)console.log(` ✓ ${e}@${t}`);let w=Mt(i,c,n,r);return{name:e,version:t,installPath:i,binaries:c,globalLinks:w}}finally{try{v.rmSync(y,{recursive:!0,force:!0})}catch{}}}function Mt(e,t,r,n){if(!n.globalBin)return[];let s=typeof n.globalBin==="string"?n.globalBin:Re();v.mkdirSync(s,{recursive:!0});let o=[];for(let a of t){let i=T.join(e,a);if(!v.existsSync(i))i=T.join(e,"bin",a);if(!v.existsSync(i))continue;let c=T.join(s,a);try{v.unlinkSync(c)}catch{}if(r.os==="windows")v.copyFileSync(i,c);else v.symlinkSync(i,c);o.push(c)}if(!n.quiet&&o.length>0)console.log(` → linked ${o.length} binary(ies) into ${s}`);return o}async function zr(e,t={}){return Promise.all(e.map((r)=>zt(r.domain,r.version,t)))}async function Qe(e,t=Ce()){if(Lt(e)){let n=(await Y("https://api.github.com/repos/oven-sh/bun/releases/latest").catch(()=>null))?.tag_name?.replace(/^bun-v/,"")||"";if(n)return n;let s=await He(e);if(s)return s;throw Error("Failed to resolve latest bun.sh version (GitHub API unreachable, no bundled metadata)")}if(e==="ziglang.org"){let r=await et(e,t);if(r.length>0)return r.sort(Je)[0];throw Error(`Failed to resolve a ziglang.org version published for ${Ut(t)}`)}if(e==="nodejs.org"){let n=await Y("https://nodejs.org/dist/index.json").catch(()=>null)||[],o=(n.find((i)=>i.lts)?.version||n[0]?.version||"").replace(/^v/,"");if(o)return o;let a=await He(e);if(a)return a;throw Error("Failed to resolve latest nodejs.org version")}if(e==="github.com/mail-os/mail"){let n=(await Y("https://api.github.com/repos/mail-os/mail/releases/latest").catch(()=>null))?.tag_name?.replace(/^v/,"")||"";if(n)return n;let o=((await Y("https://api.github.com/repos/mail-os/mail/tags?per_page=1").catch(()=>null))?.[0]?.name||"").replace(/^v/,"");if(o)return o;let a=await He(e);if(a)return a;throw Error("Failed to resolve latest github.com/mail-os/mail version")}throw Error(`Cannot resolve latest version for ${e}`)}async function He(e){try{let t=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),{packages:r}=await import("./chunk-v0par3ra.js").catch(()=>import("./src/index.js")),s=r[t]?.versions||[];return s.find((o)=>!o.includes("-"))||s[0]||""}catch{return""}}async function Ur(e,t,r={}){let s=(await et("ziglang.org",t,r)).filter((i)=>i.startsWith(`${e}.`)).sort(Je)[0];if(s)return s;let a=(await Y("https://ziglang.org/download/index.json",3,r).catch(()=>null))?.master?.version||"";return a.startsWith(`${e}.`)?a:null}function Ut(e){let t=e.arch==="aarch64"?"arm64":"x86-64";return`${e.os}-${t}`}function Wr(e,t){let r=Ut(t);return Object.entries(e?.versions||{}).filter(([,n])=>Object.hasOwn(n.platforms||{},r)).map(([n])=>n)}async function et(e,t,r={}){let n=await Y(`${Bt}/binaries/${encodeURI(e)}/metadata.json`,5,r).catch(()=>null);return Wr(n,t)}function Wt(e){let t=e.match(/^([~^]|>=|<=|>|<|=)(\d+(?:\.\d+){0,10}(?:-[0-9A-Za-z.-]+)?(?:[+_][0-9A-Za-z.-]+)?)/);if(!t)return null;return{operator:t[1],target:t[2]}}function $e(e){return e.split(/[+_-]/,1)[0].split(".").map((t)=>Number.parseInt(t,10))}function qt(e,t){let r=$e(e),n=$e(t);for(let c=0;c<Math.max(r.length,n.length,3);c++){let l=(r[c]||0)-(n[c]||0);if(l)return l}let s=e.includes("-"),o=t.includes("-");if(s!==o)return s?-1:1;let a=Number.parseInt(e.match(/-dev\.(\d+)/)?.[1]||"0",10),i=Number.parseInt(t.match(/-dev\.(\d+)/)?.[1]||"0",10);return a-i}function qr(e,t){let{operator:r,target:n}=t;if(e.includes("-")&&!n.includes("-"))return!1;let s=$e(e),o=$e(n);if(s.some(Number.isNaN)||o.some(Number.isNaN))return!1;let[a,i,c]=[s[0]||0,s[1]||0,s[2]||0],[l,g,d]=[o[0]||0,o[1]||0,o[2]||0],p=qt(e,n);if(r==="^"){if(p<0)return!1;if(l===0&&g===0)return a===0&&i===0&&c===d;if(l===0)return a===0&&i===g;return a===l}if(r==="~"){if(p<0)return!1;return o.length===1?a===l:a===l&&i===g}if(r===">=")return p>=0;if(r==="<=")return p<=0;if(r===">")return p>0;if(r==="<")return p<0;if(r==="=")return p===0;return!1}async function Gr(e,t){if(Lt(e))return(await Y("https://api.github.com/repos/oven-sh/bun/releases?per_page=100").catch(()=>null)||[]).map((s)=>(s.tag_name||"").replace(/^bun-v/,"")).filter(Boolean);if(e==="nodejs.org")return(await Y("https://nodejs.org/dist/index.json").catch(()=>null)||[]).map((s)=>(s.version||"").replace(/^v/,"")).filter(Boolean);if(e==="ziglang.org"){let r=await Y("https://ziglang.org/download/index.json").catch(()=>null),n=Kr(r,t);if(n.length>0)return n;return await et(e,t)}return[]}function Kr(e,t){let r=`${t.arch}-${t.os==="darwin"?"macos":t.os}`;return Object.entries(e||{}).filter(([,n])=>Boolean(n[r])).map(([n,s])=>s.version||n).filter(Boolean)}function Ye(e,t){return qt(t,e)}function Hr(e,t){let r=Wt(e);if(!r)return null;return[...new Set(t)].sort(Ye).find((n)=>qr(n,r))||null}async function Yr(e,t,r){if(!Wt(t))return Qe(e,r);let n;try{let i=e.replace(/[^a-z0-9]/gi,"").toLowerCase(),{packages:c}=await import("./chunk-v0par3ra.js").catch(()=>import("./src/index.js"));n=c[i]?.versions||[]}catch{n=[]}let s=await Gr(e,r),o=e==="ziglang.org"?s.sort(Ye):[...new Set([...s,...n])].sort(Ye),a=Hr(t,o);if(a)return a;throw Error(`No version of ${e} satisfies "${t}" (checked ${o.length} version${o.length===1?"":"s"}${o.length>0?`, newest ${o[0]}`:""}).`)}var Jr=4;function Ae(e){return e instanceof Error?e.message:String(e)}function Zr(e){if(typeof e==="object"&&e!==null&&"statusCode"in e){let r=Number(e.statusCode);if(Number.isFinite(r))return r}let t=Ae(e).match(/\bHTTP\s+(\d{3})\b/i);return t?Number(t[1]):void 0}function Xr(e){if(typeof e!=="object"||e===null)return"";let t="code"in e?String(e.code||""):"";if(t)return t;let r="cause"in e?e.cause:void 0;return typeof r==="object"&&r!==null&&"code"in r?String(r.code||""):""}function Qr(e){let t=Zr(e);if(t!==void 0)return t===408||t===425||t===429||t>=500;if(/^(?:ECONNRESET|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENETDOWN|ENETUNREACH|EHOSTUNREACH|UND_ERR_SOCKET)$/i.test(Xr(e)))return!0;return/socket hang up|connection reset|premature close|aborted|terminated|timed? ?out|temporar|stalled|incomplete download|checksum mismatch/i.test(Ae(e))}async function Gt(e,t,r={}){let n=r.maxAttempts??Jr,s=r.retryDelayMs??1000,o=r.sleep??((i)=>new Promise((c)=>setTimeout(c,i))),a;for(let i=1;i<=n;i+=1)try{return await t()}catch(c){if(a=c,!Qr(c))throw c;if(i===n)break;let l=Math.min(s*2**(i-1),1e4);r.onRetry?.(`${e} failed (${Ae(c)}); retrying in ${l}ms`),await o(l)}throw Error(`${e} failed after ${n} attempts: ${Ae(a)}`)}function Kt(e,t,r){return new Promise((n,s)=>{let a=(e.startsWith("https")?Ze.get:Xe.get)(e,{headers:{"User-Agent":"pantry-installer"}},(i)=>{if(i.statusCode&&i.statusCode>=300&&i.statusCode<400&&i.headers.location){if(i.resume(),t<=0)return s(Error(`Too many redirects for ${e}`));let c=new URL(i.headers.location,e).href;return Kt(c,t-1,r).then(n,s)}if(!i.statusCode||i.statusCode<200||i.statusCode>=300){i.resume();let c=Object.assign(Error(`HTTP ${i.statusCode||"unknown"} downloading ${e}`),{statusCode:i.statusCode});return s(c)}i.setTimeout(r,()=>{i.destroy(Error(`Download stalled (no data for ${r/1000}s): ${e}`))}),n(i)});a.setTimeout(r,()=>{a.destroy(Error(`Download timed out after ${r/1000}s: ${e}`))}),a.once("error",s)})}async function en(e,t,r){let n=`${t}.part`;try{v.rmSync(n,{force:!0})}catch{}let s=await Kt(e,10,r.stallTimeoutMs??60000),o=!r.quiet&&process.stderr.isTTY,a=Number.parseInt(String(s.headers["content-length"]||""),10),i=Number.isFinite(a)?a:0,c=0,l=0,g=r.expectedSha256?Fr("sha256"):void 0,d=new Mr({transform(p,y,f){c+=p.length,g?.update(p);let h=Date.now();if(o&&h-l>200){l=h;let m=(c/1048576).toFixed(1);if(i>0){let u=(i/1048576).toFixed(1),x=Math.floor(c/i*100);process.stderr.write(`\r ${m}/${u} MB (${x}%)`)}else process.stderr.write(`\r ${m} MB`)}f(null,p)}});try{if(await _r(s,d,v.createWriteStream(n)),!s.complete||i>0&&c!==i)throw Error(`Incomplete download for ${e}: received ${c} of ${i||"unknown"} bytes`);if(r.expectedSha256){let p=g.digest("hex");if(p!==r.expectedSha256.toLowerCase())throw Error(`Checksum mismatch for ${e}: expected ${r.expectedSha256}, got ${p}`)}v.renameSync(n,t)}catch(p){try{v.rmSync(n,{force:!0})}catch{}throw p}finally{if(o&&l>0)process.stderr.write("\r\x1B[K")}}async function _t(e,t,r={}){await Gt(`Download ${e}`,()=>en(e,t,r),r)}async function tn(e,t,r){if(r==="zip")if(process.platform==="win32")ve("powershell",["-NoProfile","-Command","Expand-Archive","-Path",e,"-DestinationPath",t,"-Force"],{stdio:"pipe"});else ve("unzip",["-o","-q",e,"-d",t],{stdio:"pipe"});else if(r==="tar.xz")ve("tar",["xJf",e,"-C",t],{stdio:"pipe"});else if(r==="tar.gz")ve("tar",["xzf",e,"-C",t],{stdio:"pipe"});else throw Error(`Unsupported archive format: ${r}`)}function rn(e,t){v.cpSync(e,t,{recursive:!0})}function Ht(e){let t;try{t=v.readdirSync(e,{withFileTypes:!0})}catch{return}for(let r of t){let n=T.join(e,r.name);try{if(r.isDirectory()){Ht(n);continue}if(!r.isFile())continue;let s=v.statSync(n).mode&511,o=s|(s&292)>>2;if(o!==s)v.chmodSync(n,o)}catch{}}}function Yt(e,t){return new Promise((r,n)=>{let s=e.startsWith("https")?Ze.get:Xe.get,o={"User-Agent":"pantry-installer",Accept:"application/json"};if(e.includes("api.github.com")){let i=process.env.GITHUB_TOKEN||process.env.GH_TOKEN;if(i)o.Authorization=`Bearer ${i}`}let a=s(e,{headers:o,timeout:30000},(i)=>{if(i.statusCode&&i.statusCode>=300&&i.statusCode<400&&i.headers.location){if(t<=0)return n(Error(`Too many redirects for ${e}`));let l=new URL(i.headers.location,e).href;return Yt(l,t-1).then(r,n)}if(!i.statusCode||i.statusCode<200||i.statusCode>=300)return n(Object.assign(Error(`HTTP ${i.statusCode||"unknown"} fetching ${e}`),{statusCode:i.statusCode}));let c="";i.on("data",(l)=>c+=l),i.on("end",()=>{try{r(JSON.parse(c))}catch(l){n(l)}})});a.on("error",n),a.on("timeout",()=>{a.destroy(),n(Error(`Request timed out: ${e}`))})})}function Y(e,t=5,r={}){return Gt(`Fetch ${e}`,()=>Yt(e,t),r)}ce["bun.com"]=ce["bun.sh"];function nn(e){return e in ce}function Xs(){return Object.keys(ce)}function Qs(e){let t=ce[e];if(!t)return;let r=Ce();return t.getBinaries(r)[0]}import*as L from"node:fs";import*as Ee from"node:os";import*as le from"node:path";var De="# >>> pantry shell-init >>>",Ie="# <<< pantry shell-init <<<";function Ne(){let e=process.env.SHELL??"";if(e.endsWith("/zsh")||e==="zsh")return"zsh";if(e.endsWith("/bash")||e==="bash")return"bash";if(e.endsWith("/fish")||e==="fish")return"fish";return"unknown"}function tt(e){let t=Ee.homedir();switch(e){case"zsh":{let r=process.env.ZDOTDIR;return le.join(r&&r.length>0?r:t,".zshrc")}case"bash":{if(Ee.platform()==="darwin"){let r=le.join(t,".bash_profile");if(L.existsSync(r))return r}return le.join(t,".bashrc")}case"fish":return le.join(t,".config","fish","config.fish");case"unknown":return null}}function Jt(e={}){let t=e.globalBin??Re();if((e.shell??Ne())==="fish")return[De,`if test -d "${t}"`,` set -gx PATH "${t}" $PATH`,"end",Ie,""].join(`
8
8
  `);return[De,`if [ -d "${t}" ] && [[ ":$PATH:" != *":${t}:"* ]]; then`,` export PATH="${t}:$PATH"`,"fi",Ie,""].join(`
9
9
  `)}function sn(e={}){let t=e.shell??Ne(),r=tt(t);if(!r)throw Error(`Could not detect a supported shell (got SHELL=${process.env.SHELL??"<unset>"}). Run \`ts-pantry shell-init\` and copy the printed snippet into your rc file manually.`);let n=Jt({...e,shell:t}),s="";if(L.existsSync(r)){if(s=L.readFileSync(r,"utf-8"),s.includes(De))return{rcFile:r,shell:t,changed:!1}}else L.mkdirSync(le.dirname(r),{recursive:!0});let o=s.length>0&&!s.endsWith(`
10
10
  `)?`
@@ -1,2 +1,2 @@
1
- import{Ic as I,Jc as C}from"./chunk-8rg91cqd.js";import{Kc as h,Lc as x}from"./chunk-hxd34yh9.js";import{Mc as y,Pc as j}from"./chunk-a20hctx6.js";x();async function p(){try{let{packages:s}=await import("./chunk-k004pgye.js");return s}catch{return{}}}async function b(s){let r=P(s);if(!r)return null;let e=(await p())[r];if(!e||!e.versions||e.versions.length===0)return null;return e.versions[0]}async function v(s){let r=P(s);if(!r)return[];let e=(await p())[r];if(!e||!e.versions)return[];return[...e.versions]}function D(s={}){let r=["8.4.11","8.3.14","8.2.26","8.1.30"],t=s.fallbackVersions||r;try{let{pantry:e}=(C(),y(I)),n=e.phpnet||e.php;if(!n||!n.versions||n.versions.length===0)return t;let i=[...n.versions],a=s.supportedBranches||A(i),c=new Map;for(let u of i){let[f,m]=u.split(".");if(!f||!m)continue;let o=`${f}.${m}`;if(a.includes(o)&&!c.has(o))c.set(o,u)}let l=a.map((u)=>c.get(u)).filter(Boolean);return l.length>0?l:t}catch{return t}}function A(s){let r=new Map;for(let e of s){let[n,i]=e.split(".");if(!n||!i)continue;let a=`${n}.${i}`;r.set(a,(r.get(a)||0)+1)}return Array.from(r.keys()).filter((e)=>{let[n]=e.split(".");return n==="8"&&r.get(e)>3}).sort((e,n)=>{let[i,a]=e.split(".").map(Number),[c,l]=n.split(".").map(Number);if(i!==c)return c-i;return l-a}).slice(0,4)}async function B(s,r){return(await v(s)).includes(r)}async function W(s,r="latest"){if(r==="latest")return await b(s);let t=await v(s);if(t.length===0)return null;if(t.includes(r))return r;if(r.startsWith("^")){let n=r.slice(1).split(".")[0];return t.filter((a)=>a.startsWith(`${n}.`))[0]||null}if(r.startsWith("~")){let e=r.slice(1),[n,i]=e.split("."),a=`${n}.${i}.`;return t.filter((l)=>l.startsWith(a))[0]||null}if(r.startsWith(">=")){let n=r.slice(2).split(".").map(Number);return t.filter((a)=>{let c=a.split(".").map(Number);for(let l=0;l<Math.max(c.length,n.length);l++){let u=c[l]??0,f=n[l]??0;if(u>f)return!0;if(u<f)return!1}return!0})[0]||null}return await b(s)}async function k(s){let r=P(s);if(!r)return null;let e=(await p())[r];if(!e)return null;let n=await b(s);if(!n)return null;return{name:String(s),domain:r,description:e.description||"",latestVersion:n,totalVersions:e.versions?.length||0,programs:[...e.programs||[]],dependencies:[...e.dependencies||[]],companions:[...e.companions||[]],versions:[...e.versions||[]]}}function P(s){let r=String(s);if(r in h){let t=h[r];return N(t)}return N(r)}function N(s){if(s.includes("/")){let[r,...t]=s.split("/"),e=t.join("/"),n=r.replace(/\./g,""),i=e.replace(/[/\-_.]/g,"").toLowerCase();return`${n}${i}`.toLowerCase()}return s.replace(/[.\-_]/g,"").toLowerCase()}async function O(s){let r=[],t=s.toLowerCase();for(let[n,i]of Object.entries(h))if(n.toLowerCase().includes(t)){let a=await k(n);if(a)r.push(a)}let e=await p();for(let[n,i]of Object.entries(e))if(n.toLowerCase().includes(t)||i.description?.toLowerCase().includes(t)){let a=await k(n);if(a&&!r.some((c)=>c.domain===n))r.push(a)}return r}async function F(s){let r=[],t=await p();for(let e of Object.keys(t))if(s.test(e)){let n=await k(e);if(n)r.push(n)}return r}async function M(s=10){let r=[],t=await p();for(let e of Object.keys(t)){let n=await k(e);if(n&&n.totalVersions>=s)r.push(n)}return r.sort((e,n)=>n.totalVersions-e.totalVersions)}async function R(s=50){return(await M(5)).slice(0,s)}async function _(s){try{let r=s.lastIndexOf("@");if(r===-1){let a=s;if(!P(a))return{isValid:!1,error:`Unknown package: ${a}`};return{isValid:!0,packageName:a}}let t=s.slice(0,r),e=s.slice(r+1);if(!P(t))return{isValid:!1,error:`Unknown package: ${t}`};if(e==="latest")return{isValid:!0,packageName:t,version:e};if(!await B(t,e))return{isValid:!1,packageName:t,version:e,error:`Version ${e} not available for package ${t}`};return{isValid:!0,packageName:t,version:e}}catch{return{isValid:!1,error:`Invalid package specification: ${s}`}}}function d(s){let r=s.replace(/^v/,"").split("+")[0],[t,...e]=r.split("-"),[n,i,a]=t.split(".").map((c)=>{let l=Number.parseInt(c,10);return Number.isNaN(l)?0:l});return{major:n??0,minor:i??0,patch:a??0,prerelease:e.length>0?e.join("-").split("."):[]}}function w(s,r){let t=d(s),e=d(r);if(t.major!==e.major)return e.major-t.major;if(t.minor!==e.minor)return e.minor-t.minor;if(t.patch!==e.patch)return e.patch-t.patch;let n=t.prerelease.length>0,i=e.prerelease.length>0;if(n!==i)return n?1:-1;if(!n)return 0;for(let a=0;a<Math.max(t.prerelease.length,e.prerelease.length);a++){let c=t.prerelease[a],l=e.prerelease[a];if(c===void 0)return 1;if(l===void 0)return-1;let u=Number.parseInt(c,10),f=Number.parseInt(l,10),m=!Number.isNaN(u)&&String(u)===c,o=!Number.isNaN(f)&&String(f)===l;if(m&&o){if(u!==f)return f-u}else if(m!==o)return m?1:-1;else if(c!==l)return c<l?1:-1}return 0}function T(s,r){if(!r||r.length===0)return null;let t=[...r].sort(w),e=s.replace(/^[\^~]/,""),n=d(e),i=e.replace(/^v/,"").split("+")[0].split("-")[0],a=i.split(".").length>=3,c=n.prerelease.length>0,l=(o)=>{if(o.prerelease.length===0)return!0;if(!c)return!1;return o.major===n.major&&o.minor===n.minor&&o.patch===n.patch},u=(o,g)=>w(g,e)<=0||o.prerelease.length>0,f=(o)=>{for(let g of t){let V=d(g);if(!l(V))continue;if(o(V,g))return g}return null};if(s.startsWith("^"))return f((o,g)=>{if(o.major!==n.major)return!1;if(n.major===0&&o.minor!==n.minor)return!1;return u(o,g)});if(s.startsWith("~"))return f((o,g)=>{if(o.major!==n.major||o.minor!==n.minor)return!1;return!a||u(o,g)});if(t.includes(e))return e;let m=i.split(".").filter(Boolean).map((o)=>Number.parseInt(o,10));if(m.length>0&&m.every((o)=>!Number.isNaN(o))){let o=f((g)=>{if(m[0]!==void 0&&g.major!==m[0])return!1;if(m[1]!==void 0&&g.minor!==m[1])return!1;if(m[2]!==void 0&&g.patch!==m[2])return!1;return!0});if(o)return o}return f(()=>!0)??t[0]??null}
1
+ import{Ic as I,Jc as C}from"./chunk-py2pv4ka.js";import{Kc as h,Lc as x}from"./chunk-hxd34yh9.js";import{Mc as y,Pc as j}from"./chunk-a20hctx6.js";x();async function p(){try{let{packages:s}=await import("./chunk-v0par3ra.js");return s}catch{return{}}}async function b(s){let r=P(s);if(!r)return null;let e=(await p())[r];if(!e||!e.versions||e.versions.length===0)return null;return e.versions[0]}async function v(s){let r=P(s);if(!r)return[];let e=(await p())[r];if(!e||!e.versions)return[];return[...e.versions]}function D(s={}){let r=["8.4.11","8.3.14","8.2.26","8.1.30"],t=s.fallbackVersions||r;try{let{pantry:e}=(C(),y(I)),n=e.phpnet||e.php;if(!n||!n.versions||n.versions.length===0)return t;let i=[...n.versions],a=s.supportedBranches||A(i),c=new Map;for(let u of i){let[f,m]=u.split(".");if(!f||!m)continue;let o=`${f}.${m}`;if(a.includes(o)&&!c.has(o))c.set(o,u)}let l=a.map((u)=>c.get(u)).filter(Boolean);return l.length>0?l:t}catch{return t}}function A(s){let r=new Map;for(let e of s){let[n,i]=e.split(".");if(!n||!i)continue;let a=`${n}.${i}`;r.set(a,(r.get(a)||0)+1)}return Array.from(r.keys()).filter((e)=>{let[n]=e.split(".");return n==="8"&&r.get(e)>3}).sort((e,n)=>{let[i,a]=e.split(".").map(Number),[c,l]=n.split(".").map(Number);if(i!==c)return c-i;return l-a}).slice(0,4)}async function B(s,r){return(await v(s)).includes(r)}async function W(s,r="latest"){if(r==="latest")return await b(s);let t=await v(s);if(t.length===0)return null;if(t.includes(r))return r;if(r.startsWith("^")){let n=r.slice(1).split(".")[0];return t.filter((a)=>a.startsWith(`${n}.`))[0]||null}if(r.startsWith("~")){let e=r.slice(1),[n,i]=e.split("."),a=`${n}.${i}.`;return t.filter((l)=>l.startsWith(a))[0]||null}if(r.startsWith(">=")){let n=r.slice(2).split(".").map(Number);return t.filter((a)=>{let c=a.split(".").map(Number);for(let l=0;l<Math.max(c.length,n.length);l++){let u=c[l]??0,f=n[l]??0;if(u>f)return!0;if(u<f)return!1}return!0})[0]||null}return await b(s)}async function k(s){let r=P(s);if(!r)return null;let e=(await p())[r];if(!e)return null;let n=await b(s);if(!n)return null;return{name:String(s),domain:r,description:e.description||"",latestVersion:n,totalVersions:e.versions?.length||0,programs:[...e.programs||[]],dependencies:[...e.dependencies||[]],companions:[...e.companions||[]],versions:[...e.versions||[]]}}function P(s){let r=String(s);if(r in h){let t=h[r];return N(t)}return N(r)}function N(s){if(s.includes("/")){let[r,...t]=s.split("/"),e=t.join("/"),n=r.replace(/\./g,""),i=e.replace(/[/\-_.]/g,"").toLowerCase();return`${n}${i}`.toLowerCase()}return s.replace(/[.\-_]/g,"").toLowerCase()}async function O(s){let r=[],t=s.toLowerCase();for(let[n,i]of Object.entries(h))if(n.toLowerCase().includes(t)){let a=await k(n);if(a)r.push(a)}let e=await p();for(let[n,i]of Object.entries(e))if(n.toLowerCase().includes(t)||i.description?.toLowerCase().includes(t)){let a=await k(n);if(a&&!r.some((c)=>c.domain===n))r.push(a)}return r}async function F(s){let r=[],t=await p();for(let e of Object.keys(t))if(s.test(e)){let n=await k(e);if(n)r.push(n)}return r}async function M(s=10){let r=[],t=await p();for(let e of Object.keys(t)){let n=await k(e);if(n&&n.totalVersions>=s)r.push(n)}return r.sort((e,n)=>n.totalVersions-e.totalVersions)}async function R(s=50){return(await M(5)).slice(0,s)}async function _(s){try{let r=s.lastIndexOf("@");if(r===-1){let a=s;if(!P(a))return{isValid:!1,error:`Unknown package: ${a}`};return{isValid:!0,packageName:a}}let t=s.slice(0,r),e=s.slice(r+1);if(!P(t))return{isValid:!1,error:`Unknown package: ${t}`};if(e==="latest")return{isValid:!0,packageName:t,version:e};if(!await B(t,e))return{isValid:!1,packageName:t,version:e,error:`Version ${e} not available for package ${t}`};return{isValid:!0,packageName:t,version:e}}catch{return{isValid:!1,error:`Invalid package specification: ${s}`}}}function d(s){let r=s.replace(/^v/,"").split("+")[0],[t,...e]=r.split("-"),[n,i,a]=t.split(".").map((c)=>{let l=Number.parseInt(c,10);return Number.isNaN(l)?0:l});return{major:n??0,minor:i??0,patch:a??0,prerelease:e.length>0?e.join("-").split("."):[]}}function w(s,r){let t=d(s),e=d(r);if(t.major!==e.major)return e.major-t.major;if(t.minor!==e.minor)return e.minor-t.minor;if(t.patch!==e.patch)return e.patch-t.patch;let n=t.prerelease.length>0,i=e.prerelease.length>0;if(n!==i)return n?1:-1;if(!n)return 0;for(let a=0;a<Math.max(t.prerelease.length,e.prerelease.length);a++){let c=t.prerelease[a],l=e.prerelease[a];if(c===void 0)return 1;if(l===void 0)return-1;let u=Number.parseInt(c,10),f=Number.parseInt(l,10),m=!Number.isNaN(u)&&String(u)===c,o=!Number.isNaN(f)&&String(f)===l;if(m&&o){if(u!==f)return f-u}else if(m!==o)return m?1:-1;else if(c!==l)return c<l?1:-1}return 0}function T(s,r){if(!r||r.length===0)return null;let t=[...r].sort(w),e=s.replace(/^[\^~]/,""),n=d(e),i=e.replace(/^v/,"").split("+")[0].split("-")[0],a=i.split(".").length>=3,c=n.prerelease.length>0,l=(o)=>{if(o.prerelease.length===0)return!0;if(!c)return!1;return o.major===n.major&&o.minor===n.minor&&o.patch===n.patch},u=(o,g)=>w(g,e)<=0||o.prerelease.length>0,f=(o)=>{for(let g of t){let V=d(g);if(!l(V))continue;if(o(V,g))return g}return null};if(s.startsWith("^"))return f((o,g)=>{if(o.major!==n.major)return!1;if(n.major===0&&o.minor!==n.minor)return!1;return u(o,g)});if(s.startsWith("~"))return f((o,g)=>{if(o.major!==n.major||o.minor!==n.minor)return!1;return!a||u(o,g)});if(t.includes(e))return e;let m=i.split(".").filter(Boolean).map((o)=>Number.parseInt(o,10));if(m.length>0&&m.every((o)=>!Number.isNaN(o))){let o=f((g)=>{if(m[0]!==void 0&&g.major!==m[0])return!1;if(m[1]!==void 0&&g.minor!==m[1])return!1;if(m[2]!==void 0&&g.patch!==m[2])return!1;return!0});if(o)return o}return f(()=>!0)??t[0]??null}
2
2
  export{b as rc,v as sc,D as tc,B as uc,W as vc,k as wc,P as xc,O as yc,F as zc,M as Ac,R as Bc,_ as Cc,d as Dc,w as Ec,T as Fc};