bvm-core 1.1.35 → 1.1.36

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/bvm-shim.js CHANGED
@@ -59,17 +59,30 @@ if (!version) {
59
59
 
60
60
  const versionDir = path.join(BVM_DIR, 'versions', version);
61
61
  const binDir = path.join(versionDir, 'bin');
62
- const realExecutable = path.join(binDir, CMD + '.exe');
62
+ let realExecutable = path.join(binDir, CMD + '.exe');
63
+ let finalArgs = ARGS;
63
64
 
64
65
  if (!fs.existsSync(realExecutable)) {
65
- console.error("BVM Error: Command '" + CMD + "' not found in Bun " + version + " at " + realExecutable);
66
- process.exit(127);
66
+ if (CMD === 'bunx') {
67
+ // Fallback: Use 'bun.exe x' if 'bunx.exe' is missing
68
+ const bunExe = path.join(binDir, 'bun.exe');
69
+ if (fs.existsSync(bunExe)) {
70
+ realExecutable = bunExe;
71
+ finalArgs = ['x', ...ARGS];
72
+ } else {
73
+ console.error("BVM Error: Both 'bunx.exe' and 'bun.exe' are missing in Bun " + version);
74
+ process.exit(127);
75
+ }
76
+ } else {
77
+ console.error("BVM Error: Command '" + CMD + "' not found in Bun " + version + " at " + realExecutable);
78
+ process.exit(127);
79
+ }
67
80
  }
68
81
 
69
82
  process.env.BUN_INSTALL = versionDir;
70
83
  process.env.PATH = binDir + path.delimiter + process.env.PATH;
71
84
 
72
- const child = spawn(realExecutable, ARGS, { stdio: 'inherit', shell: false });
85
+ const child = spawn(realExecutable, finalArgs, { stdio: 'inherit', shell: false });
73
86
  child.on('exit', (code) => {
74
87
  if (code === 0 && (CMD === 'bun' || CMD === 'bunx')) {
75
88
  const isGlobal = ARGS.includes('-g') || ARGS.includes('--global');
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var Q6=Object.create;var{getPrototypeOf:J6,defineProperty:T$,getOwnPropertyNames:K6}=Object;var Y6=Object.prototype.hasOwnProperty;var O$=($,b,q)=>{q=$!=null?Q6(J6($)):{};let Q=b||!$||!$.__esModule?T$(q,"default",{value:$,enumerable:!0}):q;for(let K of K6($))if(!Y6.call(Q,K))T$(Q,K,{get:()=>$[K],enumerable:!0});return Q};var q1=($,b)=>{for(var q in b)T$($,q,{get:b[q],enumerable:!0,configurable:!0,set:(Q)=>b[q]=()=>Q})};var k$=($,b)=>()=>($&&(b=$($=0)),b);var X$=import.meta.require;var J1={};q1(J1,{getBvmDir:()=>Q1,getBunAssetName:()=>v$,USER_AGENT:()=>y$,TEST_REMOTE_VERSIONS:()=>U$,REPO_FOR_BVM_CLI:()=>y6,OS_PLATFORM:()=>k,IS_TEST_MODE:()=>M,HAS_AVX2:()=>f$,EXECUTABLE_NAME:()=>R,CPU_ARCH:()=>$$,BVM_VERSIONS_DIR:()=>C,BVM_SRC_DIR:()=>E$,BVM_SHIMS_DIR:()=>E,BVM_FINGERPRINTS_FILE:()=>I$,BVM_DIR:()=>z,BVM_CURRENT_DIR:()=>K$,BVM_COMPONENTS:()=>z6,BVM_CDN_ROOT:()=>L6,BVM_CACHE_DIR:()=>_,BVM_BIN_DIR:()=>j,BVM_ALIAS_DIR:()=>F,BUN_GITHUB_RELEASES_API:()=>U6,ASSET_NAME_FOR_BVM:()=>H6});import{homedir as G6}from"os";import{join as o}from"path";import{spawnSync as R$}from"child_process";function X6(){let $=process.arch;if(k==="darwin"&&$==="x64")try{if(R$("sysctl",["-n","sysctl.proc_translated"],{encoding:"utf-8"}).stdout.trim()==="1")return"arm64"}catch(b){}return $}function W6(){if(k==="win32")return!0;try{if(k==="darwin")return R$("sysctl",["-a"],{encoding:"utf-8"}).stdout.includes("AVX2");else if(k==="linux")return R$("cat",["/proc/cpuinfo"],{encoding:"utf-8"}).stdout.includes("avx2")}catch($){}return!0}function Q1(){let $=process.env.HOME||G6();return o($,".bvm")}function v$($){let b=k==="win32"?"windows":k,q=$$==="arm64"?"aarch64":"x64";return`bun-${b}-${q}${!f$&&q==="x64"?"-baseline":""}.zip`}var k,M,U$,$$,f$,z,E$,C,j,E,K$,F,_,I$,R,U6="https://api.github.com/repos/oven-sh/bun/releases",y6="EricLLLLLL/bvm",H6,y$="bvm (Bun Version Manager)",L6,z6;var f=k$(()=>{k=process.platform,M=process.env.BVM_TEST_MODE==="true",U$=["v1.3.4","v1.2.23","v1.0.0","bun-v1.4.0-canary"];$$=X6(),f$=W6();z=Q1(),E$=o(z,"src"),C=o(z,"versions"),j=o(z,"bin"),E=o(z,"shims"),K$=o(z,"current"),F=o(z,"aliases"),_=o(z,"cache"),I$=o(z,"fingerprints.json"),R=k==="win32"?"bun.exe":"bun",H6=k==="win32"?"bvm.exe":"bvm",L6=process.env.BVM_CDN_URL||"https://cdn.jsdelivr.net/gh/EricLLLLLL/bvm",z6=[{name:"CLI Core",remotePath:"index.js",localPath:"src/index.js"},{name:"Windows Shim",remotePath:"bvm-shim.js",localPath:"bin/bvm-shim.js",platform:"win32"},{name:"Unix Shim",remotePath:"bvm-shim.sh",localPath:"bin/bvm-shim.sh",platform:"posix"}]});function p($){if(!$)return null;return $.match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/)?$:null}function K1($){let b=p($);return b?b.replace(/^v/,""):null}function Y$($){if(!$)return null;let b=$.replace(/^v/,""),Q=b.split(/[-+]/)[0].split(".").map(Number);if(Q.length===0||Q.some((J)=>isNaN(J)))return null;let K=b.includes("-")?b.split("-")[1].split("+")[0]:void 0;return{major:Q[0],minor:Q[1],patch:Q[2],pre:K}}function _$($,b){if(!$||!b)return 0;if($.major!==b.major)return $.major-b.major;if($.minor!==b.minor)return $.minor-b.minor;if($.patch!==b.patch)return $.patch-b.patch;if($.pre&&!b.pre)return-1;if(!$.pre&&b.pre)return 1;if($.pre&&b.pre)return $.pre.localeCompare(b.pre);return 0}function Y1($,b){let q=Y$($),Q=Y$(b);return _$(q,Q)}function Z$($,b){return Y1(b,$)}function A$($,b){return Y1($,b)>0}function Z1($,b){if(b==="*"||b===""||b==="latest")return!0;let q=Y$($);if(!q)return!1;let Q=b;if(b.startsWith("v"))Q=b.substring(1);if(K1($)===K1(b))return!0;let K=Q.split(".");if(K.length===1){let J=Number(K[0]);if(q.major===J)return!0}else if(K.length===2){let J=Number(K[0]),Z=Number(K[1]);if(q.major===J&&q.minor===Z)return!0}if(b.startsWith("~")){let J=Y$(b.substring(1));if(!J)return!1;let Z=J.patch??0;return q.major===J.major&&q.minor===J.minor&&q.patch>=Z}if(b.startsWith("^")){let J=Y$(b.substring(1));if(!J)return!1;let Z=J.patch??0,G=J.minor??0;if(J.major===0){if(q.major!==0)return!1;if(q.minor!==G)return!1;return q.patch>=Z}if(q.major!==J.major)return!1;if(q.minor<G)return!1;if(q.minor===G&&q.patch<Z)return!1;return!0}return!1}import{readdir as O6,mkdir as k6,stat as G1,symlink as C6,unlink as X1,rm as W1,readlink as x6}from"fs/promises";import{join as j$,dirname as N6,basename as F6}from"path";async function T($){try{await k6($,{recursive:!0})}catch(b){if(b.code==="EEXIST")try{if((await G1($)).isDirectory())return}catch{}throw b}}async function X($){try{return await G1($),!0}catch(b){if(b.code==="ENOENT")return!1;throw b}}async function U1($,b){try{await X1(b)}catch(Q){try{await W1(b,{recursive:!0,force:!0})}catch(K){}}let q=process.platform==="win32"?"junction":"dir";await C6($,b,q)}async function y1($){try{return await x6($)}catch(b){if(b.code==="ENOENT"||b.code==="EINVAL")return null;throw b}}async function H$($){await W1($,{recursive:!0,force:!0})}async function l($){try{return await O6($)}catch(b){if(b.code==="ENOENT")return[];throw b}}async function D($){return await Bun.file($).text()}async function d($,b){await Bun.write($,b)}async function C$($,b,q={}){let{backup:Q=!0}=q,K=N6($);await T(K);let J=`${$}.tmp-${Date.now()}`,Z=`${$}.bak`;try{if(await d(J,b),Q&&await X($))try{let{rename:W,unlink:L}=await import("fs/promises");if(await X(Z))await L(Z).catch(()=>{});await W($,Z)}catch(W){}let{rename:G}=await import("fs/promises");try{await G(J,$)}catch(W){await Bun.write($,b),await X1(J).catch(()=>{})}}catch(G){let{unlink:W}=await import("fs/promises");throw await W(J).catch(()=>{}),G}}function H($){let b=$.trim();if(b.startsWith("bun-v"))b=b.substring(4);if(!b.startsWith("v")&&/^\d/.test(b))b=`v${b}`;return b}async function V(){return await T(C),(await l(C)).filter((b)=>p(H(b))).sort(Z$)}async function t(){if(process.env.BVM_ACTIVE_VERSION)return{version:H(process.env.BVM_ACTIVE_VERSION),source:"env"};let $=j$(process.cwd(),".bvmrc");if(await X($)){let Z=(await D($)).trim();return{version:H(Z),source:".bvmrc"}}let{getBvmDir:b}=await Promise.resolve().then(() => (f(),J1)),q=b(),Q=j$(q,"current"),K=j$(q,"aliases");if(await X(Q)){let{realpath:Z}=await import("fs/promises");try{let G=await Z(Q);return{version:H(F6(G)),source:"current"}}catch(G){}}let J=j$(K,"default");if(await X(J)){let Z=(await D(J)).trim();return{version:H(Z),source:"default"}}return{version:null,source:null}}function b$($,b){if(!$||b.length===0)return null;let q=H($);if(b.includes(q))return q;if($.toLowerCase()==="latest")return b[0];if(/^\d+\.\d+\.\d+$/.test($.replace(/^v/,"")))return null;if(!/^[v\d]/.test($))return null;let K=$.startsWith("v")?`~${$.substring(1)}`:`~${$}`,J=b.filter((Z)=>Z1(Z,K));if(J.length>0)return J.sort(Z$)[0];return null}var x=k$(()=>{f()});class S${timer=null;frames=process.platform==="win32"?["-"]:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];frameIndex=0;text;isWindows=process.platform==="win32";constructor($){this.text=$}start($){if($)this.text=$;if(this.timer)return;if(this.isWindows){process.stdout.write(`${Y.cyan(">")} ${this.text}
4
- `);return}this.timer=setInterval(()=>{process.stdout.write(`\r\x1B[K${Y.cyan(this.frames[this.frameIndex])} ${this.text}`),this.frameIndex=(this.frameIndex+1)%this.frames.length},80)}stop(){if(this.isWindows)return;if(this.timer)clearInterval(this.timer),this.timer=null,process.stdout.write("\r\x1B[K");process.stdout.write("\x1B[?25h")}succeed($){this.stop(),console.log(`${Y.green(" \u2713")} ${$||this.text}`)}fail($){this.stop(),console.log(`${Y.red(" \u2716")} ${$||this.text}`)}info($){this.stop(),console.log(`${Y.blue(" \u2139")} ${$||this.text}`)}update($){if(this.text=$,this.isWindows)console.log(Y.dim(` ... ${this.text}`))}}class P${total;current=0;width=20;constructor($){this.total=$}start(){process.stdout.write("\x1B[?25l"),this.render()}update($,b){this.current=$,this.render(b)}stop(){process.stdout.write(`\x1B[?25h
5
- `)}render($){let b=Math.min(1,this.current/this.total),q=Math.round(this.width*b),Q=this.width-q,K=process.platform==="win32",J=K?"=":"\u2588",Z=K?"-":"\u2591",G=Y.green(J.repeat(q))+Y.gray(Z.repeat(Q)),W=(b*100).toFixed(0).padStart(3," "),L=(this.current/1048576).toFixed(1),O=(this.total/1048576).toFixed(1),y=$?` ${$.speed}KB/s`:"";process.stdout.write(`\r\x1B[2K ${G} ${W}% | ${L}/${O}MB${y}`)}}var f6,A6=($)=>$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=($,b,q=$)=>(Q)=>f6?$+Q.replace(new RegExp(A6(b),"g"),q)+b:Q,Y;var N=k$(()=>{f6=!process.env.NO_COLOR,Y={red:a("\x1B[1;31m","\x1B[39m"),green:a("\x1B[1;32m","\x1B[39m"),yellow:a("\x1B[1;33m","\x1B[39m"),blue:a("\x1B[1;34m","\x1B[39m"),magenta:a("\x1B[1;35m","\x1B[39m"),cyan:a("\x1B[1;36m","\x1B[39m"),gray:a("\x1B[90m","\x1B[39m"),bold:a("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:a("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m")}});async function U($,b,q){if(process.platform==="win32"){console.log(Y.cyan(`> ${$}`));let J={start:(Z)=>{if(Z)console.log(Y.cyan(`> ${Z}`))},stop:()=>{},succeed:(Z)=>console.log(Y.green(` \u2713 ${Z}`)),fail:(Z)=>console.log(Y.red(` \u2716 ${Z}`)),info:(Z)=>console.log(Y.cyan(` \u2139 ${Z}`)),update:(Z)=>console.log(Y.dim(` ... ${Z}`)),isSpinning:!1};try{return await b(J)}catch(Z){let G=x1(Z,q?.failMessage);if(console.log(Y.red(` \u2716 ${G}`)),process.env.BVM_DEBUG,console.log(Y.dim(` Details: ${Z.message}`)),Z.code)console.log(Y.dim(` Code: ${Z.code}`));throw Z.reported=!0,Z}}let K=new S$($);K.start();try{let J=await b(K);return K.stop(),J}catch(J){let Z=x1(J,q?.failMessage);throw K.fail(Y.red(Z)),J.reported=!0,J}}function x1($,b){let q=$ instanceof Error?$.message:String($);if(!b)return q;if(typeof b==="function")return b($);return`${b}: ${q}`}var B=k$(()=>{N()});var N1={};q1(N1,{resolveLocalVersion:()=>h,displayVersion:()=>g$});import{join as S6}from"path";async function h($){if($==="current"){let{version:K}=await t();return K}if($==="latest"){let K=await V();if(K.length>0)return K[0];return null}let b=S6(F,$);if(await X(b))try{let K=(await D(b)).trim();return H(K)}catch{return null}let q=H($),Q=await V();return b$($,Q)}async function g$($){await U(`Resolving version '${$}'...`,async()=>{let b=await h($);if(b)console.log(b);else throw Error("N/A")},{failMessage:`Failed to resolve version '${$}'`})}var Q$=k$(()=>{f();x();B()});import{parseArgs as O4}from"util";var W$={name:"bvm-core",version:"1.1.35",description:"The native version manager for Bun. Cross-platform, shell-agnostic, and zero-dependency.",main:"dist/index.js",bin:{bvm:"bin/bvm-npm.js"},publishConfig:{access:"public"},homepage:"https://bvm-core.pages.dev",bugs:{url:"https://github.com/EricLLLLLL/bvm/issues"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --target=bun --outfile dist/index.js --minify && bun run scripts/sync-runtime.ts",test:"bun test",bvm:"bun run src/index.ts","bvm:sandbox":'mkdir -p "$PWD/.sandbox-home" && HOME="$PWD/.sandbox-home" bun run src/index.ts',release:"bun run scripts/check-integrity.ts && bun run build && bun run scripts/release.ts","check-integrity":"bun run scripts/check-integrity.ts","test:e2e:npm":"bun run scripts/verify-e2e-npm.ts","sync-runtime":"bun run scripts/sync-runtime.ts",postinstall:"node scripts/postinstall.js"},repository:{type:"git",url:"git+https://github.com/EricLLLLLL/bvm.git"},keywords:["bun","version-manager","cli","bvm","nvm","nvm-windows","fnm","nodenv","bun-nvm","version-switching"],files:["dist/index.js","dist/bvm-shim.sh","dist/bvm-shim.js","bin/bvm-npm.js","scripts/postinstall.js","install.sh","install.ps1","README.md"],author:"EricLLLLLL",license:"MIT",type:"commonjs",dependencies:{"cli-progress":"^3.12.0"},optionalDependencies:{"@oven/bun-darwin-aarch64":"^1.3.6","@oven/bun-darwin-x64":"^1.3.6","@oven/bun-linux-aarch64":"^1.3.6","@oven/bun-linux-x64":"^1.3.6","@oven/bun-windows-x64":"^1.3.6"},devDependencies:{"@types/bun":"^1.3.4","@types/cli-progress":"^3.11.6","@types/node":"^24.10.2",bun:"^1.3.6",esbuild:"^0.27.2",execa:"^9.6.1",typescript:"^5"},peerDependencies:{typescript:"^5"}};f();x();import{join as i,basename as r6,dirname as e6}from"path";f();x();N();import{join as M6}from"path";function H1($,b){if($==="darwin"){if(b==="arm64")return"@oven/bun-darwin-aarch64";if(b==="x64")return"@oven/bun-darwin-x64"}if($==="linux"){if(b==="arm64")return"@oven/bun-linux-aarch64";if(b==="x64")return"@oven/bun-linux-x64"}if($==="win32"){if(b==="x64")return"@oven/bun-windows-x64"}return null}function L1($,b,q){let Q=q;if(!Q.endsWith("/"))Q+="/";let K=$.startsWith("@"),J=$;if(K){let G=$.split("/");if(G.length===2)J=G[1]}let Z=`${J}-${b}.tgz`;return`${Q}${$}/-/${Z}`}N();async function m($,b={}){let{cwd:q,env:Q,prependPath:K,stdin:J="inherit",stdout:Z="inherit",stderr:G="inherit"}=b,W={...process.env,...Q};if(K){let y=W.PATH||"",A=process.platform==="win32"?";":":";W.PATH=`${K}${A}${y}`}let O=await Bun.spawn({cmd:$,cwd:q,env:W,stdin:J,stdout:Z,stderr:G}).exited;if((O??0)!==0)throw Error(`${Y.red("Command failed")}: ${$.join(" ")} (code ${O})`);return O??0}async function s($,b={}){let{timeout:q=5000,...Q}=b,K=new AbortController,J=setTimeout(()=>K.abort(),q);try{let Z=await fetch($,{...Q,signal:K.signal});return clearTimeout(J),Z}catch(Z){if(clearTimeout(J),Z.name==="AbortError")throw Error(`Request to ${$} timed out after ${q}ms`);throw Z}}async function j6($,b=2000){if($.length===0)throw Error("No URLs to race");if($.length===1)return $[0];return new Promise((q,Q)=>{let K=0,J=!1;$.forEach((Z)=>{s(Z,{method:"HEAD",timeout:b}).then((G)=>{if(G.ok&&!J)J=!0,q(Z);else if(!J){if(K++,K===$.length)Q(Error("All requests failed"))}}).catch(()=>{if(!J){if(K++,K===$.length)Q(Error("All requests failed"))}})})})}async function B6(){try{let $=await s("https://1.1.1.1/cdn-cgi/trace",{timeout:500});if(!$.ok)return null;let q=(await $.text()).match(/loc=([A-Z]{2})/);return q?q[1]:null}catch($){return null}}var u$=null,x$={NPM:"https://registry.npmjs.org",TAOBAO:"https://registry.npmmirror.com",TENCENT:"https://mirrors.cloud.tencent.com/npm/"};async function q$(){if(u$)return u$;let $=await B6(),b=[];if($==="CN")b=[x$.TAOBAO,x$.TENCENT,x$.NPM];else b=[x$.NPM,x$.TAOBAO];try{let q=await j6(b,2000);return u$=q,q}catch(q){return b[0]}}x();var D6="bun-versions.json",T6=3600000;async function R6(){if(M)return[...U$];let $=M6(_,D6);try{if(await X($)){let K=await D($),J=JSON.parse(K);if(Date.now()-J.timestamp<T6&&Array.isArray(J.versions))return J.versions}}catch(K){}let b=await q$(),q=[b];if(b!=="https://registry.npmjs.org")q.push("https://registry.npmjs.org");let Q=null;for(let K of q){let J=`${K.replace(/\/$/,"")}/bun`;try{let Z=await s(J,{headers:{"User-Agent":y$,Accept:"application/vnd.npm.install-v1+json"},timeout:1e4});if(!Z.ok)throw Error(`Status ${Z.status}`);let G=await Z.json();if(!G.versions)throw Error("Invalid response (no versions)");let W=Object.keys(G.versions);try{await T(_),await d($,JSON.stringify({timestamp:Date.now(),versions:W}))}catch(L){}return W}catch(Z){Q=Z}}throw Q||Error("Failed to fetch versions from any registry.")}async function E6(){if(M)return[...U$];return new Promise(($,b)=>{let q=[];try{let Q=Bun.spawn(["git","ls-remote","--tags","https://github.com/oven-sh/bun.git"],{stdout:"pipe",stderr:"pipe"}),K=setTimeout(()=>{Q.kill(),b(Error("Git operation timed out"))},1e4);new Response(Q.stdout).text().then((Z)=>{clearTimeout(K);let G=Z.split(`
6
- `);for(let W of G){let L=W.match(/refs\/tags\/bun-v?(\d+\.\d+\.\d+.*)$/);if(L)q.push(L[1])}$(q)}).catch((Z)=>{clearTimeout(K),b(Z)})}catch(Q){b(Error(`Failed to run git: ${Q.message}`))}})}async function z1(){if(M)return[...U$];try{let b=(await R6()).filter((q)=>p(q)).map((q)=>({v:q,parsed:Y$(q)}));return b.sort((q,Q)=>_$(Q.parsed,q.parsed)),b.map((q)=>q.v)}catch($){try{let b=await E6();if(b.length>0)return Array.from(new Set(b.filter((Q)=>p(Q)))).sort(Z$);throw Error("No versions found via Git")}catch(b){throw Error(`Failed to fetch versions. NPM: ${$.message}. Git: ${b.message}`)}}}async function w1($){if(M)return U$.includes($)||$==="latest";let b=await q$(),q=$.replace(/^v/,""),Q=`${b}/bun/${q}`,K=k==="win32"?"curl.exe":"curl",J=async()=>{try{return await m([K,"-I","-f","-m","5","-s",Q],{stdout:"ignore",stderr:"ignore"}),!0}catch(G){return!1}},Z=new Promise((G)=>setTimeout(()=>G(!1),1e4));return Promise.race([J(),Z])}async function O1(){if(M)return{latest:"1.1.20"};let b=`${await q$()}/-/package/bun/dist-tags`;try{let q=await s(b,{headers:{"User-Agent":y$},timeout:5000});if(q.ok)return await q.json()}catch(q){}return{}}async function k1($){let b=H($);if(!p(b))return console.error(Y.red(`Invalid version provided to findBunDownloadUrl: ${$}`)),null;if(M)return{url:`https://example.com/${v$(b)}`,foundVersion:b};let K=H1(k==="win32"?"win32":k,$$==="arm64"?"arm64":"x64");if(!K)throw Error(`Unsupported platform/arch for NPM download: ${k}-${$$}`);let J="";if(process.env.BVM_REGISTRY)J=process.env.BVM_REGISTRY;else if(process.env.BVM_DOWNLOAD_MIRROR)J=process.env.BVM_DOWNLOAD_MIRROR;else J=await q$();let Z=b.replace(/^v/,"");return{url:L1(K,Z,J),foundVersion:b}}async function B$(){try{let b=(await q$()).replace(/\/$/,""),q=await s(`${b}/-/package/bvm-core/dist-tags`,{headers:{"User-Agent":y$},timeout:5000});if(!q.ok)return null;let K=(await q.json()).latest;if(!K)return null;let J=await s(`${b}/bvm-core/${K}`,{headers:{"User-Agent":y$},timeout:5000});if(J.ok){let Z=await J.json();return{version:K,tarball:Z.dist.tarball,integrity:Z.dist.integrity,shasum:Z.dist.shasum}}}catch($){}return null}N();f();import{spawn as I6}from"child_process";async function C1($,b){if($.endsWith(".zip"))if(k==="win32")await m(["powershell","-Command",`Expand-Archive -Path "${$}" -DestinationPath "${b}" -Force`],{stdout:"ignore",stderr:"inherit"});else await m(["unzip","-o","-q",$,"-d",b],{stdout:"ignore",stderr:"inherit"});else if($.endsWith(".tar.gz")||$.endsWith(".tgz"))await new Promise((q,Q)=>{let K=I6("tar",["-xzf",$,"-C",b],{stdio:"inherit",shell:!1});K.on("close",(J)=>{if(J===0)q();else Q(Error(`tar exited with code ${J}`))}),K.on("error",(J)=>Q(J))});else throw Error(`Unsupported archive format: ${$}`)}import{chmod as i$}from"fs/promises";x();f();N();import{join as w,dirname as F1}from"path";import{homedir as g}from"os";import{mkdir as f1}from"fs/promises";import{chmod as N$}from"fs/promises";f();x();N();import{join as V$}from"path";x();import{join as v6,dirname as _6}from"path";async function M$(){let $=process.cwd();while(!0){let b=v6($,".bvmrc");if(await X(b))try{return(await Bun.file(b).text()).trim()}catch(Q){return null}let q=_6($);if(q===$)break;$=q}return null}Q$();B();async function L$($,b={}){let q=$;if(!q)q=await M$()||void 0;if(!q){if(!b.silent)console.error(Y.red("No version specified. Usage: bvm use <version>"));throw Error("No version specified.")}let Q=async(K)=>{let J=null,Z=await h(q);if(Z)J=Z;else{let O=(await V()).map((y)=>H(y));J=b$(q,O)}if(!J)throw Error(`Bun version '${q}' is not installed.`);let G=H(J),W=V$(C,G),L=V$(W,"bin",R);if(!await X(L))throw Error(`Version ${G} is not properly installed (binary missing).`);await U1(W,K$);try{let O=V$(K$,"bin"),y=O.replace(/\\/g,"/"),A=X$("path").delimiter;if(!(process.env.PATH||"").split(A).some((P)=>{let u=P.replace(/\\/g,"/");return u.includes(y)||u.endsWith("/.bvm/current/bin")})&&!b.silent){if(K)K.stop();if(console.log(Y.yellow(`
7
- \u26A0\uFE0F Warning: Global bin directory is not in your PATH.`)),console.log(Y.yellow(" Global packages (e.g., 'bun install -g') may not be found.")),console.log(Y.gray(" Please add the following to your PATH:")),console.log(Y.white(` ${O}`)),K)K.start()}}catch(O){}if(K)K.succeed(Y.green(`Now using Bun ${G} (immediate effect).`))};if(b.silent)await Q();else await U(`Switching to Bun ${q}...`,(K)=>Q(K),{failMessage:()=>`Failed to switch to Bun ${q}`})}var d$=`#!/bin/bash
3
+ var Q6=Object.create;var{getPrototypeOf:K6,defineProperty:E$,getOwnPropertyNames:Y6}=Object;var Z6=Object.prototype.hasOwnProperty;var O$=($,b,q)=>{q=$!=null?Q6(K6($)):{};let J=b||!$||!$.__esModule?E$(q,"default",{value:$,enumerable:!0}):q;for(let K of Y6($))if(!Z6.call(J,K))E$(J,K,{get:()=>$[K],enumerable:!0});return J};var J1=($,b)=>{for(var q in b)E$($,q,{get:b[q],enumerable:!0,configurable:!0,set:(J)=>b[q]=()=>J})};var x$=($,b)=>()=>($&&(b=$($=0)),b);var X$=import.meta.require;var K1={};J1(K1,{getBvmDir:()=>Q1,getBunAssetName:()=>u$,USER_AGENT:()=>y$,TEST_REMOTE_VERSIONS:()=>U$,REPO_FOR_BVM_CLI:()=>H6,OS_PLATFORM:()=>x,IS_TEST_MODE:()=>B,HAS_AVX2:()=>j$,EXECUTABLE_NAME:()=>M,CPU_ARCH:()=>$$,BVM_VERSIONS_DIR:()=>k,BVM_SRC_DIR:()=>_$,BVM_SHIMS_DIR:()=>R,BVM_FINGERPRINTS_FILE:()=>P$,BVM_DIR:()=>z,BVM_CURRENT_DIR:()=>K$,BVM_COMPONENTS:()=>w6,BVM_CDN_ROOT:()=>z6,BVM_CACHE_DIR:()=>P,BVM_BIN_DIR:()=>j,BVM_ALIAS_DIR:()=>F,BUN_GITHUB_RELEASES_API:()=>y6,ASSET_NAME_FOR_BVM:()=>L6});import{homedir as X6}from"os";import{join as i}from"path";import{spawnSync as S$}from"child_process";function W6(){let $=process.arch;if(x==="darwin"&&$==="x64")try{if(S$("sysctl",["-n","sysctl.proc_translated"],{encoding:"utf-8"}).stdout.trim()==="1")return"arm64"}catch(b){}return $}function U6(){if(x==="win32")return!0;try{if(x==="darwin")return S$("sysctl",["-a"],{encoding:"utf-8"}).stdout.includes("AVX2");else if(x==="linux")return S$("cat",["/proc/cpuinfo"],{encoding:"utf-8"}).stdout.includes("avx2")}catch($){}return!0}function Q1(){let $=process.env.HOME||X6();return i($,".bvm")}function u$($){let b=x==="win32"?"windows":x,q=$$==="arm64"?"aarch64":"x64";return`bun-${b}-${q}${!j$&&q==="x64"?"-baseline":""}.zip`}var x,B,U$,$$,j$,z,_$,k,j,R,K$,F,P,P$,M,y6="https://api.github.com/repos/oven-sh/bun/releases",H6="EricLLLLLL/bvm",L6,y$="bvm (Bun Version Manager)",z6,w6;var N=x$(()=>{x=process.platform,B=process.env.BVM_TEST_MODE==="true",U$=["v1.3.4","v1.2.23","v1.0.0","bun-v1.4.0-canary"];$$=W6(),j$=U6();z=Q1(),_$=i(z,"src"),k=i(z,"versions"),j=i(z,"bin"),R=i(z,"shims"),K$=i(z,"current"),F=i(z,"aliases"),P=i(z,"cache"),P$=i(z,"fingerprints.json"),M=x==="win32"?"bun.exe":"bun",L6=x==="win32"?"bvm.exe":"bvm",z6=process.env.BVM_CDN_URL||"https://cdn.jsdelivr.net/gh/EricLLLLLL/bvm",w6=[{name:"CLI Core",remotePath:"index.js",localPath:"src/index.js"},{name:"Windows Shim",remotePath:"bvm-shim.js",localPath:"bin/bvm-shim.js",platform:"win32"},{name:"Unix Shim",remotePath:"bvm-shim.sh",localPath:"bin/bvm-shim.sh",platform:"posix"}]});function l($){if(!$)return null;return $.match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/)?$:null}function Y1($){let b=l($);return b?b.replace(/^v/,""):null}function Y$($){if(!$)return null;let b=$.replace(/^v/,""),J=b.split(/[-+]/)[0].split(".").map(Number);if(J.length===0||J.some((Q)=>isNaN(Q)))return null;let K=b.includes("-")?b.split("-")[1].split("+")[0]:void 0;return{major:J[0],minor:J[1],patch:J[2],pre:K}}function g$($,b){if(!$||!b)return 0;if($.major!==b.major)return $.major-b.major;if($.minor!==b.minor)return $.minor-b.minor;if($.patch!==b.patch)return $.patch-b.patch;if($.pre&&!b.pre)return-1;if(!$.pre&&b.pre)return 1;if($.pre&&b.pre)return $.pre.localeCompare(b.pre);return 0}function Z1($,b){let q=Y$($),J=Y$(b);return g$(q,J)}function Z$($,b){return Z1(b,$)}function M$($,b){return Z1($,b)>0}function G1($,b){if(b==="*"||b===""||b==="latest")return!0;let q=Y$($);if(!q)return!1;let J=b;if(b.startsWith("v"))J=b.substring(1);if(Y1($)===Y1(b))return!0;let K=J.split(".");if(K.length===1){let Q=Number(K[0]);if(q.major===Q)return!0}else if(K.length===2){let Q=Number(K[0]),Z=Number(K[1]);if(q.major===Q&&q.minor===Z)return!0}if(b.startsWith("~")){let Q=Y$(b.substring(1));if(!Q)return!1;let Z=Q.patch??0;return q.major===Q.major&&q.minor===Q.minor&&q.patch>=Z}if(b.startsWith("^")){let Q=Y$(b.substring(1));if(!Q)return!1;let Z=Q.patch??0,G=Q.minor??0;if(Q.major===0){if(q.major!==0)return!1;if(q.minor!==G)return!1;return q.patch>=Z}if(q.major!==Q.major)return!1;if(q.minor<G)return!1;if(q.minor===G&&q.patch<Z)return!1;return!0}return!1}import{readdir as x6,mkdir as k6,stat as X1,symlink as C6,unlink as W1,rm as U1,readlink as f6}from"fs/promises";import{join as D$,dirname as F6,basename as N6}from"path";async function I($){try{await k6($,{recursive:!0})}catch(b){if(b.code==="EEXIST")try{if((await X1($)).isDirectory())return}catch{}throw b}}async function X($){try{return await X1($),!0}catch(b){if(b.code==="ENOENT")return!1;throw b}}async function y1($,b){try{await W1(b)}catch(J){try{await U1(b,{recursive:!0,force:!0})}catch(K){}}let q=process.platform==="win32"?"junction":"dir";await C6($,b,q)}async function H1($){try{return await f6($)}catch(b){if(b.code==="ENOENT"||b.code==="EINVAL")return null;throw b}}async function H$($){await U1($,{recursive:!0,force:!0})}async function n($){try{return await x6($)}catch(b){if(b.code==="ENOENT")return[];throw b}}async function T($){return await Bun.file($).text()}async function m($,b){await Bun.write($,b)}async function k$($,b,q={}){let{backup:J=!0}=q,K=F6($);await I(K);let Q=`${$}.tmp-${Date.now()}`,Z=`${$}.bak`;try{if(await m(Q,b),J&&await X($))try{let{rename:W,unlink:L}=await import("fs/promises");if(await X(Z))await L(Z).catch(()=>{});await W($,Z)}catch(W){}let{rename:G}=await import("fs/promises");try{await G(Q,$)}catch(W){await Bun.write($,b),await W1(Q).catch(()=>{})}}catch(G){let{unlink:W}=await import("fs/promises");throw await W(Q).catch(()=>{}),G}}function H($){let b=$.trim();if(b.startsWith("bun-v"))b=b.substring(4);if(!b.startsWith("v")&&/^\d/.test(b))b=`v${b}`;return b}async function d(){return await I(k),(await n(k)).filter((b)=>l(H(b))).sort(Z$)}async function o(){if(process.env.BVM_ACTIVE_VERSION)return{version:H(process.env.BVM_ACTIVE_VERSION),source:"env"};let $=D$(process.cwd(),".bvmrc");if(await X($)){let Z=(await T($)).trim();return{version:H(Z),source:".bvmrc"}}let{getBvmDir:b}=await Promise.resolve().then(() => (N(),K1)),q=b(),J=D$(q,"current"),K=D$(q,"aliases");if(await X(J)){let{realpath:Z}=await import("fs/promises");try{let G=await Z(J);return{version:H(N6(G)),source:"current"}}catch(G){}}let Q=D$(K,"default");if(await X(Q)){let Z=(await T(Q)).trim();return{version:H(Z),source:"default"}}return{version:null,source:null}}function b$($,b){if(!$||b.length===0)return null;let q=H($);if(b.includes(q))return q;if($.toLowerCase()==="latest")return b[0];if(/^\d+\.\d+\.\d+$/.test($.replace(/^v/,"")))return null;if(!/^[v\d]/.test($))return null;let K=$.startsWith("v")?`~${$.substring(1)}`:`~${$}`,Q=b.filter((Z)=>G1(Z,K));if(Q.length>0)return Q.sort(Z$)[0];return null}var C=x$(()=>{N()});class V${timer=null;frames=process.platform==="win32"?["-"]:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];frameIndex=0;text;isWindows=process.platform==="win32";constructor($){this.text=$}start($){if($)this.text=$;if(this.timer)return;if(this.isWindows){process.stdout.write(`${Y.cyan(">")} ${this.text}
4
+ `);return}this.timer=setInterval(()=>{process.stdout.write(`\r\x1B[K${Y.cyan(this.frames[this.frameIndex])} ${this.text}`),this.frameIndex=(this.frameIndex+1)%this.frames.length},80)}stop(){if(this.isWindows)return;if(this.timer)clearInterval(this.timer),this.timer=null,process.stdout.write("\r\x1B[K");process.stdout.write("\x1B[?25h")}succeed($){this.stop(),console.log(`${Y.green(" \u2713")} ${$||this.text}`)}fail($){this.stop(),console.log(`${Y.red(" \u2716")} ${$||this.text}`)}info($){this.stop(),console.log(`${Y.blue(" \u2139")} ${$||this.text}`)}update($){if(this.text=$,this.isWindows)console.log(Y.dim(` ... ${this.text}`))}}class d${total;current=0;width=20;constructor($){this.total=$}start(){process.stdout.write("\x1B[?25l"),this.render()}update($,b){this.current=$,this.render(b)}stop(){process.stdout.write(`\x1B[?25h
5
+ `)}render($){let b=Math.min(1,this.current/this.total),q=Math.round(this.width*b),J=this.width-q,K=process.platform==="win32",Q=K?"=":"\u2588",Z=K?"-":"\u2591",G=Y.green(Q.repeat(q))+Y.gray(Z.repeat(J)),W=(b*100).toFixed(0).padStart(3," "),L=(this.current/1048576).toFixed(1),O=(this.total/1048576).toFixed(1),y=$?` ${$.speed}KB/s`:"";process.stdout.write(`\r\x1B[2K ${G} ${W}% | ${L}/${O}MB${y}`)}}var A6,j6=($)=>$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=($,b,q=$)=>(J)=>A6?$+J.replace(new RegExp(j6(b),"g"),q)+b:J,Y;var f=x$(()=>{A6=!process.env.NO_COLOR,Y={red:a("\x1B[1;31m","\x1B[39m"),green:a("\x1B[1;32m","\x1B[39m"),yellow:a("\x1B[1;33m","\x1B[39m"),blue:a("\x1B[1;34m","\x1B[39m"),magenta:a("\x1B[1;35m","\x1B[39m"),cyan:a("\x1B[1;36m","\x1B[39m"),gray:a("\x1B[90m","\x1B[39m"),bold:a("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:a("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m")}});async function U($,b,q){if(process.platform==="win32"){console.log(Y.cyan(`> ${$}`));let Q={start:(Z)=>{if(Z)console.log(Y.cyan(`> ${Z}`))},stop:()=>{},succeed:(Z)=>console.log(Y.green(` \u2713 ${Z}`)),fail:(Z)=>console.log(Y.red(` \u2716 ${Z}`)),info:(Z)=>console.log(Y.cyan(` \u2139 ${Z}`)),update:(Z)=>console.log(Y.dim(` ... ${Z}`)),isSpinning:!1};try{return await b(Q)}catch(Z){let G=f1(Z,q?.failMessage);if(console.log(Y.red(` \u2716 ${G}`)),process.env.BVM_DEBUG,console.log(Y.dim(` Details: ${Z.message}`)),Z.code)console.log(Y.dim(` Code: ${Z.code}`));throw Z.reported=!0,Z}}let K=new V$($);K.start();try{let Q=await b(K);return K.stop(),Q}catch(Q){let Z=f1(Q,q?.failMessage);throw K.fail(Y.red(Z)),Q.reported=!0,Q}}function f1($,b){let q=$ instanceof Error?$.message:String($);if(!b)return q;if(typeof b==="function")return b($);return`${b}: ${q}`}var D=x$(()=>{f()});var F1={};J1(F1,{resolveLocalVersion:()=>c,displayVersion:()=>h$});import{join as P6}from"path";async function c($){if($==="current"){let{version:K}=await o();return K}if($==="latest"){let K=await d();if(K.length>0)return K[0];return null}let b=P6(F,$);if(await X(b))try{let K=(await T(b)).trim();return H(K)}catch{return null}let q=H($),J=await d();return b$($,J)}async function h$($){await U(`Resolving version '${$}'...`,async()=>{let b=await c($);if(b)console.log(b);else throw Error("N/A")},{failMessage:`Failed to resolve version '${$}'`})}var J$=x$(()=>{N();C();D()});import{parseArgs as k4}from"util";var W$={name:"bvm-core",version:"1.1.36",description:"Bun Version Manager (BVM) - Native, fast, and cross-platform.",main:"dist/index.js",bin:{bvm:"bin/bvm-npm.js"},publishConfig:{access:"public"},homepage:"https://bvm-core.pages.dev",bugs:{url:"https://github.com/EricLLLLLL/bvm/issues"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --target=bun --outfile dist/index.js --minify && bun run scripts/sync-runtime.ts",test:"bun test",bvm:"bun run src/index.ts","bvm:sandbox":'mkdir -p "$PWD/.sandbox-home" && HOME="$PWD/.sandbox-home" bun run src/index.ts',release:"bun run scripts/check-integrity.ts && bun run build && bun run scripts/release.ts","check-integrity":"bun run scripts/check-integrity.ts","test:e2e:npm":"bun run scripts/verify-e2e-npm.ts","sync-runtime":"bun run scripts/sync-runtime.ts",postinstall:"node scripts/postinstall.js"},repository:{type:"git",url:"git+https://github.com/EricLLLLLL/bvm.git"},keywords:["bun","version-manager","cli","bvm","nvm","nvm-windows","fnm","nodenv","bun-nvm","version-switching"],files:["dist/index.js","dist/bvm-shim.sh","dist/bvm-shim.js","bin/bvm-npm.js","scripts/postinstall.js","install.sh","install.ps1","README.md"],author:"EricLLLLLL",license:"MIT",type:"commonjs",dependencies:{"cli-progress":"^3.12.0"},optionalDependencies:{"@oven/bun-darwin-aarch64":"^1.3.6","@oven/bun-darwin-x64":"^1.3.6","@oven/bun-linux-aarch64":"^1.3.6","@oven/bun-linux-x64":"^1.3.6","@oven/bun-windows-x64":"^1.3.6"},devDependencies:{"@types/bun":"^1.3.4","@types/cli-progress":"^3.11.6","@types/node":"^24.10.2",bun:"^1.3.6",esbuild:"^0.27.2",execa:"^9.6.1",typescript:"^5"},peerDependencies:{typescript:"^5"}};N();C();import{join as t,basename as e6,dirname as $4}from"path";N();C();f();import{join as B6}from"path";function L1($,b){if($==="darwin"){if(b==="arm64")return"@oven/bun-darwin-aarch64";if(b==="x64")return"@oven/bun-darwin-x64"}if($==="linux"){if(b==="arm64")return"@oven/bun-linux-aarch64";if(b==="x64")return"@oven/bun-linux-x64"}if($==="win32"){if(b==="x64")return"@oven/bun-windows-x64"}return null}function z1($,b,q){let J=q;if(!J.endsWith("/"))J+="/";let K=$.startsWith("@"),Q=$;if(K){let G=$.split("/");if(G.length===2)Q=G[1]}let Z=`${Q}-${b}.tgz`;return`${J}${$}/-/${Z}`}f();async function h($,b={}){let{cwd:q,env:J,prependPath:K,stdin:Q="inherit",stdout:Z="inherit",stderr:G="inherit"}=b,W={...process.env,...J};if(K){let y=W.PATH||"",A=process.platform==="win32"?";":":";W.PATH=`${K}${A}${y}`}let O=await Bun.spawn({cmd:$,cwd:q,env:W,stdin:Q,stdout:Z,stderr:G}).exited;if((O??0)!==0)throw Error(`${Y.red("Command failed")}: ${$.join(" ")} (code ${O})`);return O??0}async function s($,b={}){let{timeout:q=5000,...J}=b,K=new AbortController,Q=setTimeout(()=>K.abort(),q);try{let Z=await fetch($,{...J,signal:K.signal});return clearTimeout(Q),Z}catch(Z){if(clearTimeout(Q),Z.name==="AbortError")throw Error(`Request to ${$} timed out after ${q}ms`);throw Z}}async function M6($,b=2000){if($.length===0)throw Error("No URLs to race");if($.length===1)return $[0];return new Promise((q,J)=>{let K=0,Q=!1;$.forEach((Z)=>{s(Z,{method:"HEAD",timeout:b}).then((G)=>{if(G.ok&&!Q)Q=!0,q(Z);else if(!Q){if(K++,K===$.length)J(Error("All requests failed"))}}).catch(()=>{if(!Q){if(K++,K===$.length)J(Error("All requests failed"))}})})})}async function D6(){try{let $=await s("https://1.1.1.1/cdn-cgi/trace",{timeout:500});if(!$.ok)return null;let q=(await $.text()).match(/loc=([A-Z]{2})/);return q?q[1]:null}catch($){return null}}var m$=null,C$={NPM:"https://registry.npmjs.org",TAOBAO:"https://registry.npmmirror.com",TENCENT:"https://mirrors.cloud.tencent.com/npm/"};async function q$(){if(m$)return m$;let $=await D6(),b=[];if($==="CN")b=[C$.TAOBAO,C$.TENCENT,C$.NPM];else b=[C$.NPM,C$.TAOBAO];try{let q=await M6(b,2000);return m$=q,q}catch(q){return b[0]}}C();var R6="bun-versions.json",T6=3600000;async function I6(){if(B)return[...U$];let $=B6(P,R6);try{if(await X($)){let K=await T($),Q=JSON.parse(K);if(Date.now()-Q.timestamp<T6&&Array.isArray(Q.versions))return Q.versions}}catch(K){}let b=await q$(),q=[b];if(b!=="https://registry.npmjs.org")q.push("https://registry.npmjs.org");let J=null;for(let K of q){let Q=`${K.replace(/\/$/,"")}/bun`;try{let Z=await s(Q,{headers:{"User-Agent":y$,Accept:"application/vnd.npm.install-v1+json"},timeout:1e4});if(!Z.ok)throw Error(`Status ${Z.status}`);let G=await Z.json();if(!G.versions)throw Error("Invalid response (no versions)");let W=Object.keys(G.versions);try{await I(P),await m($,JSON.stringify({timestamp:Date.now(),versions:W}))}catch(L){}return W}catch(Z){J=Z}}throw J||Error("Failed to fetch versions from any registry.")}async function v6(){if(B)return[...U$];return new Promise(($,b)=>{let q=[];try{let J=Bun.spawn(["git","ls-remote","--tags","https://github.com/oven-sh/bun.git"],{stdout:"pipe",stderr:"pipe"}),K=setTimeout(()=>{J.kill(),b(Error("Git operation timed out"))},1e4);new Response(J.stdout).text().then((Z)=>{clearTimeout(K);let G=Z.split(`
6
+ `);for(let W of G){let L=W.match(/refs\/tags\/bun-v?(\d+\.\d+\.\d+.*)$/);if(L)q.push(L[1])}$(q)}).catch((Z)=>{clearTimeout(K),b(Z)})}catch(J){b(Error(`Failed to run git: ${J.message}`))}})}async function w1(){if(B)return[...U$];try{let b=(await I6()).filter((q)=>l(q)).map((q)=>({v:q,parsed:Y$(q)}));return b.sort((q,J)=>g$(J.parsed,q.parsed)),b.map((q)=>q.v)}catch($){try{let b=await v6();if(b.length>0)return Array.from(new Set(b.filter((J)=>l(J)))).sort(Z$);throw Error("No versions found via Git")}catch(b){throw Error(`Failed to fetch versions. NPM: ${$.message}. Git: ${b.message}`)}}}async function O1($){if(B)return U$.includes($)||$==="latest";let b=await q$(),q=$.replace(/^v/,""),J=`${b}/bun/${q}`,K=x==="win32"?"curl.exe":"curl",Q=async()=>{try{return await h([K,"-I","-f","-m","5","-s",J],{stdout:"ignore",stderr:"ignore"}),!0}catch(G){return!1}},Z=new Promise((G)=>setTimeout(()=>G(!1),1e4));return Promise.race([Q(),Z])}async function x1(){if(B)return{latest:"1.1.20"};let b=`${await q$()}/-/package/bun/dist-tags`;try{let q=await s(b,{headers:{"User-Agent":y$},timeout:5000});if(q.ok)return await q.json()}catch(q){}return{}}async function k1($){let b=H($);if(!l(b))return console.error(Y.red(`Invalid version provided to findBunDownloadUrl: ${$}`)),null;if(B)return{url:`https://example.com/${u$(b)}`,foundVersion:b};let K=L1(x==="win32"?"win32":x,$$==="arm64"?"arm64":"x64");if(!K)throw Error(`Unsupported platform/arch for NPM download: ${x}-${$$}`);let Q="";if(process.env.BVM_REGISTRY)Q=process.env.BVM_REGISTRY;else if(process.env.BVM_DOWNLOAD_MIRROR)Q=process.env.BVM_DOWNLOAD_MIRROR;else Q=await q$();let Z=b.replace(/^v/,"");return{url:z1(K,Z,Q),foundVersion:b}}async function B$(){try{let b=(await q$()).replace(/\/$/,""),q=await s(`${b}/-/package/bvm-core/dist-tags`,{headers:{"User-Agent":y$},timeout:5000});if(!q.ok)return null;let K=(await q.json()).latest;if(!K)return null;let Q=await s(`${b}/bvm-core/${K}`,{headers:{"User-Agent":y$},timeout:5000});if(Q.ok){let Z=await Q.json();return{version:K,tarball:Z.dist.tarball,integrity:Z.dist.integrity,shasum:Z.dist.shasum}}}catch($){}return null}f();N();import{spawn as E6}from"child_process";async function C1($,b){if($.endsWith(".zip"))if(x==="win32")await h(["powershell","-Command",`Expand-Archive -Path "${$}" -DestinationPath "${b}" -Force`],{stdout:"ignore",stderr:"inherit"});else await h(["unzip","-o","-q",$,"-d",b],{stdout:"ignore",stderr:"inherit"});else if($.endsWith(".tar.gz")||$.endsWith(".tgz"))await new Promise((q,J)=>{let K=E6("tar",["-xzf",$,"-C",b],{stdio:"inherit",shell:!1});K.on("close",(Q)=>{if(Q===0)q();else J(Error(`tar exited with code ${Q}`))}),K.on("error",(Q)=>J(Q))});else throw Error(`Unsupported archive format: ${$}`)}import{chmod as I$,rename as b4,rm as I1,symlink as q4}from"fs/promises";C();N();f();import{join as w,dirname as N1}from"path";import{homedir as V}from"os";import{mkdir as A1}from"fs/promises";import{chmod as N$}from"fs/promises";N();C();f();import{join as c$}from"path";C();import{join as S6,dirname as _6}from"path";async function R$(){let $=process.cwd();while(!0){let b=S6($,".bvmrc");if(await X(b))try{return(await Bun.file(b).text()).trim()}catch(J){return null}let q=_6($);if(q===$)break;$=q}return null}J$();D();async function L$($,b={}){let q=$;if(!q)q=await R$()||void 0;if(!q){if(!b.silent)console.error(Y.red("No version specified. Usage: bvm use <version>"));throw Error("No version specified.")}let J=async(K)=>{let Q=null,Z=await c(q);if(Z)Q=Z;else{let O=(await d()).map((y)=>H(y));Q=b$(q,O)}if(!Q)throw Error(`Bun version '${q}' is not installed.`);let G=H(Q),W=c$(k,G),L=c$(W,"bin",M);if(!await X(L))throw Error(`Version ${G} is not properly installed (binary missing).`);await y1(W,K$);try{let O=c$(K$,"bin"),y=O.replace(/\\/g,"/"),A=X$("path").delimiter;if(!(process.env.PATH||"").split(A).some((u)=>{let g=u.replace(/\\/g,"/");return g.includes(y)||g.endsWith("/.bvm/current/bin")})&&!b.silent){if(K)K.stop();if(console.log(Y.yellow(`
7
+ \u26A0\uFE0F Warning: Global bin directory is not in your PATH.`)),console.log(Y.yellow(" Global packages (e.g., 'bun install -g') may not be found.")),console.log(Y.gray(" Please add the following to your PATH:")),console.log(Y.white(` ${O}`)),K)K.start()}}catch(O){}if(K)K.succeed(Y.green(`Now using Bun ${G} (immediate effect).`))};if(b.silent)await J();else await U(`Switching to Bun ${q}...`,(K)=>J(K),{failMessage:()=>`Failed to switch to Bun ${q}`})}var p$=`#!/bin/bash
8
8
 
9
9
  # bvm-init.sh: Initializes bvm default version on shell startup
10
10
 
@@ -15,7 +15,7 @@ fi
15
15
 
16
16
  # Try to switch to the 'default' version silently.
17
17
  "\${BVM_DIR}/bin/bvm" use default --silent >/dev/null 2>&1 || true
18
- `;var m$=`# bvm-init.fish: Initializes bvm default version on shell startup
18
+ `;var l$=`# bvm-init.fish: Initializes bvm default version on shell startup
19
19
 
20
20
  # Check if BVM_DIR is set
21
21
  if not set -q BVM_DIR
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  # Try to switch to the 'default' version silently.
26
26
  eval "$BVM_DIR/bin/bvm" use default --silent >/dev/null 2>&1 || true
27
- `;var h$=`#!/bin/bash
27
+ `;var t$=`#!/bin/bash
28
28
  # Shim managed by BVM (Bun Version Manager)
29
29
  # Optimized for performance via Bash-native syntax.
30
30
 
@@ -89,7 +89,7 @@ else
89
89
  echo "BVM Error: Command '$CMD_NAME' not found in Bun $VERSION." >&2
90
90
  exit 127
91
91
  fi
92
- `;var c$=`const path = require('path');
92
+ `;var n$=`const path = require('path');
93
93
  const { spawn } = require('child_process');
94
94
  const os = require('os');
95
95
  const fs = require('fs');
@@ -150,17 +150,30 @@ if (!version) {
150
150
 
151
151
  const versionDir = path.join(BVM_DIR, 'versions', version);
152
152
  const binDir = path.join(versionDir, 'bin');
153
- const realExecutable = path.join(binDir, CMD + '.exe');
153
+ let realExecutable = path.join(binDir, CMD + '.exe');
154
+ let finalArgs = ARGS;
154
155
 
155
156
  if (!fs.existsSync(realExecutable)) {
156
- console.error("BVM Error: Command '" + CMD + "' not found in Bun " + version + " at " + realExecutable);
157
- process.exit(127);
157
+ if (CMD === 'bunx') {
158
+ // Fallback: Use 'bun.exe x' if 'bunx.exe' is missing
159
+ const bunExe = path.join(binDir, 'bun.exe');
160
+ if (fs.existsSync(bunExe)) {
161
+ realExecutable = bunExe;
162
+ finalArgs = ['x', ...ARGS];
163
+ } else {
164
+ console.error("BVM Error: Both 'bunx.exe' and 'bun.exe' are missing in Bun " + version);
165
+ process.exit(127);
166
+ }
167
+ } else {
168
+ console.error("BVM Error: Command '" + CMD + "' not found in Bun " + version + " at " + realExecutable);
169
+ process.exit(127);
170
+ }
158
171
  }
159
172
 
160
173
  process.env.BUN_INSTALL = versionDir;
161
174
  process.env.PATH = binDir + path.delimiter + process.env.PATH;
162
175
 
163
- const child = spawn(realExecutable, ARGS, { stdio: 'inherit', shell: false });
176
+ const child = spawn(realExecutable, finalArgs, { stdio: 'inherit', shell: false });
164
177
  child.on('exit', (code) => {
165
178
  if (code === 0 && (CMD === 'bun' || CMD === 'bunx')) {
166
179
  const isGlobal = ARGS.includes('-g') || ARGS.includes('--global');
@@ -195,7 +208,7 @@ child.on('error', (err) => {
195
208
  console.error("BVM Error: Failed to start child process: " + err.message);
196
209
  process.exit(1);
197
210
  });
198
- `;var p$=`@echo off
211
+ `;var f$=`@echo off
199
212
  set "BVM_DIR=%USERPROFILE%\\.bvm"
200
213
  set "BUN_INSTALL=%BVM_DIR%\\current"
201
214
 
@@ -207,22 +220,25 @@ if not exist ".bvmrc" (
207
220
 
208
221
  :: Slow-path: Hand over to JS shim for version resolution
209
222
  "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\bin\\bvm-shim.js" "bun" %*
210
-
211
- `;var l$=`@echo off
223
+ `;var F$=`@echo off
212
224
  set "BVM_DIR=%USERPROFILE%\\.bvm"
213
225
  set "BUN_INSTALL=%BVM_DIR%\\current"
214
226
 
227
+ :: Fast-path: If no .bvmrc in current directory, run default directly
215
228
  if not exist ".bvmrc" (
216
- "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" %*
229
+ if exist "%BVM_DIR%\\current\\bin\\bunx.exe" (
230
+ "%BVM_DIR%\\current\\bin\\bunx.exe" %*
231
+ ) else (
232
+ "%BVM_DIR%\\current\\bin\\bun.exe" x %*
233
+ )
217
234
  exit /b %errorlevel%
218
235
  )
219
236
 
220
- "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\bin\\bvm-shim.js" "bunx" %*
221
-
222
- `;var t$=`@echo off
237
+ :: Slow-path: Hand over to JS shim for version resolution
238
+ "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\bin\\bvm-shim.js" "bunx" %*`;var o$=`@echo off
223
239
  set "BVM_DIR=%USERPROFILE%\\.bvm"
224
240
  "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\src\\index.js" %*
225
- `;async function z$($=!0){if(await c6($),process.platform==="win32"){await p6($);return}let b=process.env.SHELL||"",q="",Q="";if(b.includes("zsh"))Q="zsh",q=w(g(),".zshrc");else if(b.includes("bash"))if(Q="bash",process.platform==="darwin")if(await X(w(g(),".bashrc")))q=w(g(),".bashrc");else q=w(g(),".bash_profile");else q=w(g(),".bashrc");else if(b.includes("fish"))Q="fish",q=w(g(),".config","fish","config.fish");else if(await X(w(g(),".zshrc")))Q="zsh",q=w(g(),".zshrc");else if(await X(w(g(),".config","fish","config.fish")))Q="fish",q=w(g(),".config","fish","config.fish");else if(await X(w(g(),".bashrc")))Q="bash",q=w(g(),".bashrc");else if(await X(w(g(),".bash_profile")))Q="bash",q=w(g(),".bash_profile");else{if($)console.log(Y.yellow(`Could not detect a supported shell (zsh, bash, fish). Please manually add ${j} to your PATH.`));return}let K=w(j,"bvm-init.sh");await Bun.write(K,d$),await N$(K,493);let J=w(j,"bvm-init.fish");await Bun.write(J,m$),await N$(J,493);let Z="";try{Z=await Bun.file(q).text()}catch(y){if(y.code==="ENOENT")await Bun.write(q,""),Z="";else throw y}let G="# >>> bvm initialize >>>",W="# <<< bvm initialize <<<",L=`${G}
241
+ `;async function z$($=!0){if(await p6($),process.platform==="win32"){await l6($);return}let b=process.env.SHELL||"",q="",J="";if(b.includes("zsh"))J="zsh",q=w(V(),".zshrc");else if(b.includes("bash"))if(J="bash",process.platform==="darwin")if(await X(w(V(),".bashrc")))q=w(V(),".bashrc");else q=w(V(),".bash_profile");else q=w(V(),".bashrc");else if(b.includes("fish"))J="fish",q=w(V(),".config","fish","config.fish");else if(await X(w(V(),".zshrc")))J="zsh",q=w(V(),".zshrc");else if(await X(w(V(),".config","fish","config.fish")))J="fish",q=w(V(),".config","fish","config.fish");else if(await X(w(V(),".bashrc")))J="bash",q=w(V(),".bashrc");else if(await X(w(V(),".bash_profile")))J="bash",q=w(V(),".bash_profile");else{if($)console.log(Y.yellow(`Could not detect a supported shell (zsh, bash, fish). Please manually add ${j} to your PATH.`));return}let K=w(j,"bvm-init.sh");await Bun.write(K,p$),await N$(K,493);let Q=w(j,"bvm-init.fish");await Bun.write(Q,l$),await N$(Q,493);let Z="";try{Z=await Bun.file(q).text()}catch(y){if(y.code==="ENOENT")await Bun.write(q,""),Z="";else throw y}let G="# >>> bvm initialize >>>",W="# <<< bvm initialize <<<",L=`${G}
226
242
  # !! Contents within this block are managed by 'bvm setup' !!
227
243
  export BVM_DIR="${z}"
228
244
  export PATH="$BVM_DIR/shims:$BVM_DIR/bin:$BVM_DIR/current/bin:$PATH"
@@ -242,16 +258,16 @@ if not test -L "$BVM_DIR/current"
242
258
  ln -sf "$BVM_DIR/versions/$(cat "$BVM_DIR/aliases/default")" "$BVM_DIR/current"
243
259
  end
244
260
  end
245
- # <<< bvm initialize <<<`;if($)console.log(Y.cyan(`Configuring ${Q} environment in ${q}...`));try{let y=Z,A=G.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),S=new RegExp(`${A}[\\s\\S]*?${c}`,"g");if(Z.includes(G))y=Z.replace(S,"").trim();let P=Q==="fish"?O:L;if(y=(y?y+`
261
+ # <<< bvm initialize <<<`;if($)console.log(Y.cyan(`Configuring ${J} environment in ${q}...`));try{let y=Z,A=G.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),_=W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),v=new RegExp(`${A}[\\s\\S]*?${_}`,"g");if(Z.includes(G))y=Z.replace(v,"").trim();let u=J==="fish"?O:L;if(y=(y?y+`
246
262
 
247
- `:"")+P+`
248
- `,y!==Z){if(await Bun.write(q,y),$)console.log(Y.green(`\u2713 Successfully updated BVM configuration in ${q}`)),console.log(Y.gray(" (Moved configuration to the end of file to ensure PATH precedence)"))}if($)console.log(Y.yellow(`Please restart your terminal or run "source ${q}" to apply changes.`));try{await L$("default",{silent:!0})}catch(u){}}catch(y){console.error(Y.red(`Failed to write to ${q}: ${y.message}`))}}async function c6($){if($)console.log(Y.cyan("Refreshing shims and wrappers..."));if(!$)console.log(`[DEBUG] BIN_DIR: ${j}`),console.log(`[DEBUG] SHIMS_DIR: ${E}`);if(await f1(j,{recursive:!0}),await f1(E,{recursive:!0}),process.platform==="win32")await Bun.write(w(j,"bvm-shim.js"),c$),await Bun.write(w(j,"bvm.cmd"),t$),await Bun.write(w(E,"bun.cmd"),p$),await Bun.write(w(E,"bunx.cmd"),l$);else{let q=w(j,"bvm-shim.sh");await Bun.write(q,h$),await N$(q,493);let Q="",K=w(z,"runtime","current","bin","bun"),J=w(E$,"index.js");if(process.env.BVM_INSTALL_SOURCE==="npm")Q=`#!/bin/bash
263
+ `:"")+u+`
264
+ `,y!==Z){if(await Bun.write(q,y),$)console.log(Y.green(`\u2713 Successfully updated BVM configuration in ${q}`)),console.log(Y.gray(" (Moved configuration to the end of file to ensure PATH precedence)"))}if($)console.log(Y.yellow(`Please restart your terminal or run "source ${q}" to apply changes.`));try{await L$("default",{silent:!0})}catch(g){}}catch(y){console.error(Y.red(`Failed to write to ${q}: ${y.message}`))}}async function p6($){if($)console.log(Y.cyan("Refreshing shims and wrappers..."));if(!$)console.log(`[DEBUG] BIN_DIR: ${j}`),console.log(`[DEBUG] SHIMS_DIR: ${R}`);if(await A1(j,{recursive:!0}),await A1(R,{recursive:!0}),process.platform==="win32")await Bun.write(w(j,"bvm-shim.js"),n$),await Bun.write(w(j,"bvm.cmd"),o$),await Bun.write(w(R,"bun.cmd"),f$),await Bun.write(w(R,"bunx.cmd"),F$);else{let q=w(j,"bvm-shim.sh");await Bun.write(q,t$),await N$(q,493);let J="",K=w(z,"runtime","current","bin","bun"),Q=w(_$,"index.js");if(process.env.BVM_INSTALL_SOURCE==="npm")J=`#!/bin/bash
249
265
  export BVM_DIR="${z}"
250
266
  export BVM_INSTALL_SOURCE="npm"
251
267
  if [ -f "${K}" ]; then
252
- exec "${K}" "${J}" "$@"
268
+ exec "${K}" "${Q}" "$@"
253
269
  elif command -v bun >/dev/null 2>&1; then
254
- exec bun "${J}" "$@"
270
+ exec bun "${Q}" "$@"
255
271
  else
256
272
  # Last resort: use the node entry point if it's an NPM install
257
273
  # This is only possible if we are in the original NPM environment
@@ -259,15 +275,15 @@ else
259
275
  echo "Error: BVM Bunker Runtime not found. Attempting emergency fallback..."
260
276
  node -e "require('child_process').spawnSync('node', [require('path').join(process.env.BVM_DIR, '../', 'bin/bvm-npm.js'), ...process.argv.slice(1)], {stdio:'inherit'})" "$@"
261
277
  fi
262
- `;else Q=`#!/bin/bash
278
+ `;else J=`#!/bin/bash
263
279
  export BVM_DIR="${z}"
264
- exec "${K}" "${J}" "$@"`;let Z=w(j,"bvm");await Bun.write(Z,Q),await N$(Z,493);for(let G of["bun","bunx"]){let W=`#!/bin/bash
280
+ exec "${K}" "${Q}" "$@"`;let Z=w(j,"bvm");await Bun.write(Z,J),await N$(Z,493);for(let G of["bun","bunx"]){let W=`#!/bin/bash
265
281
  export BVM_DIR="${z}"
266
- exec "${z}/bin/bvm-shim.sh" "${G}" "$@"`,L=w(E,G);await Bun.write(L,W),await N$(L,493)}}}async function p6($=!0){let b=w(j),q=w(E),Q=w(z,"current","bin");if($)console.log(Y.cyan("Configuring Windows environment variables (Registry)..."));let K=`
282
+ exec "${z}/bin/bvm-shim.sh" "${G}" "$@"`,L=w(R,G);await Bun.write(L,W),await N$(L,493)}}}async function l6($=!0){let b=w(j),q=w(R),J=w(z,"current","bin");if($)console.log(Y.cyan("Configuring Windows environment variables (Registry)..."));let K=`
267
283
  $targetDir = "${z}";
268
284
  $shimsPath = "${q}";
269
285
  $binPath = "${b}";
270
- $currentBinPath = "${Q}";
286
+ $currentBinPath = "${J}";
271
287
 
272
288
  # Set BVM_DIR
273
289
  [Environment]::SetEnvironmentVariable("BVM_DIR", $targetDir, "User");
@@ -287,7 +303,7 @@ exec "${z}/bin/bvm-shim.sh" "${G}" "$@"`,L=w(E,G);await Bun.write(L,W),await N$(
287
303
  return "SUCCESS"
288
304
  }
289
305
  return "ALREADY_SET"
290
- `;try{let Z=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command",K],stdout:"pipe",stderr:"pipe"}),G=Z.stdout.toString().trim();if(Z.success){if($)if(G==="SUCCESS")console.log(Y.green("\u2713 Successfully updated User PATH and BVM_DIR in Registry."));else console.log(Y.gray("\u2713 Environment variables are already up to date."))}else throw Error(Z.stderr.toString())}catch(Z){console.error(Y.red(`Failed to update environment variables: ${Z.message}`))}let J="";try{if(J=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command","echo $PROFILE.CurrentUserAllHosts"],stdout:"pipe"}).stdout.toString().trim(),J)Bun.spawnSync({cmd:["powershell","-NoProfile","-Command",`if (!(Test-Path "${F1(J)}")) { New-Item -ItemType Directory -Force -Path "${F1(J)}" }`],stderr:"pipe"}),await l6(J,!1)}catch(Z){}if($)console.log(Y.yellow("Please restart your terminal or IDE to apply the new PATH."))}async function l6($,b=!0){let q=`
306
+ `;try{let Z=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command",K],stdout:"pipe",stderr:"pipe"}),G=Z.stdout.toString().trim();if(Z.success){if($)if(G==="SUCCESS")console.log(Y.green("\u2713 Successfully updated User PATH and BVM_DIR in Registry."));else console.log(Y.gray("\u2713 Environment variables are already up to date."))}else throw Error(Z.stderr.toString())}catch(Z){console.error(Y.red(`Failed to update environment variables: ${Z.message}`))}let Q="";try{if(Q=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command","echo $PROFILE.CurrentUserAllHosts"],stdout:"pipe"}).stdout.toString().trim(),Q)Bun.spawnSync({cmd:["powershell","-NoProfile","-Command",`if (!(Test-Path "${N1(Q)}")) { New-Item -ItemType Directory -Force -Path "${N1(Q)}" }`],stderr:"pipe"}),await t6(Q,!1)}catch(Z){}if($)console.log(Y.yellow("Please restart your terminal or IDE to apply the new PATH."))}async function t6($,b=!0){let q=`
291
307
  # BVM Configuration
292
308
  $env:BVM_DIR = "${z}"
293
309
  $env:PATH = "$env:BVM_DIR\\shims;$env:BVM_DIR\\bin;$env:BVM_DIR\\current\\bin;$env:PATH"
@@ -295,9 +311,9 @@ $env:PATH = "$env:BVM_DIR\\shims;$env:BVM_DIR\\bin;$env:BVM_DIR\\current\\bin;$e
295
311
  if (Test-Path "$env:BVM_DIR\\bin\\bvm.cmd") {
296
312
  & "$env:BVM_DIR\\bin\\bvm.cmd" use default --silent *>$null
297
313
  }
298
- `;try{let Q="";if(await X($))Q=await Bun.file($).text();else await Bun.write($,"");if(Q.includes("$env:BVM_DIR")){if(b)console.log(Y.gray("\u2713 Configuration is already up to date."));return}if(b)console.log(Y.cyan(`Configuring PowerShell environment in ${$}...`));if(await Bun.write($,Q+`\r
299
- ${q}`),b)console.log(Y.green(`\u2713 Successfully configured BVM path in ${$}`)),console.log(Y.yellow("Please restart your terminal to apply changes."))}catch(Q){console.error(Y.red(`Failed to write to ${$}: ${Q.message}`))}}N();f();x();Q$();B();import{join as A1}from"path";async function w$($,b,q={}){let Q=async(K)=>{let J=await h(b);if(!J){if(!q.silent)console.log(Y.blue(`Please install Bun ${b} first using: bvm install ${b}`));throw Error(`Bun version '${b}' is not installed. Cannot create alias.`)}let Z=A1(C,J);if(!await X(Z))throw Error(`Internal Error: Resolved Bun version ${J} not found.`);await T(F);let G=A1(F,$);if($!=="default"&&await X(G))throw Error(`Alias '${$}' already exists. Use 'bvm alias ${$} <new-version>' to update or 'bvm unalias ${$}' to remove.`);if(await d(G,`${J}
300
- `),K)K.succeed(Y.green(`Alias '${$}' created for Bun ${J}.`))};if(q.silent)await Q();else await U(`Creating alias '${$}' for Bun ${b}...`,(K)=>Q(K),{failMessage:`Failed to create alias '${$}'`})}B();f();x();N();import{join as n,dirname as j1}from"path";import{chmod as B1,unlink as t6}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",n6=($)=>`@echo off
314
+ `;try{let J="";if(await X($))J=await Bun.file($).text();else await Bun.write($,"");if(J.includes("$env:BVM_DIR")){if(b)console.log(Y.gray("\u2713 Configuration is already up to date."));return}if(b)console.log(Y.cyan(`Configuring PowerShell environment in ${$}...`));if(await Bun.write($,J+`\r
315
+ ${q}`),b)console.log(Y.green(`\u2713 Successfully configured BVM path in ${$}`)),console.log(Y.yellow("Please restart your terminal to apply changes."))}catch(J){console.error(Y.red(`Failed to write to ${$}: ${J.message}`))}}f();N();C();J$();D();import{join as j1}from"path";async function w$($,b,q={}){let J=async(K)=>{let Q=await c(b);if(!Q){if(!q.silent)console.log(Y.blue(`Please install Bun ${b} first using: bvm install ${b}`));throw Error(`Bun version '${b}' is not installed. Cannot create alias.`)}let Z=j1(k,Q);if(!await X(Z))throw Error(`Internal Error: Resolved Bun version ${Q} not found.`);await I(F);let G=j1(F,$);if($!=="default"&&await X(G))throw Error(`Alias '${$}' already exists. Use 'bvm alias ${$} <new-version>' to update or 'bvm unalias ${$}' to remove.`);if(await m(G,`${Q}
316
+ `),K)K.succeed(Y.green(`Alias '${$}' created for Bun ${Q}.`))};if(q.silent)await J();else await U(`Creating alias '${$}' for Bun ${b}...`,(K)=>J(K),{failMessage:`Failed to create alias '${$}'`})}D();N();C();f();import{join as p,dirname as M1}from"path";import{chmod as D1,unlink as n6}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",o6=($)=>`@echo off
301
317
  set "BVM_DIR=%USERPROFILE%.bvm"
302
318
  if exist "%BVM_DIR%\runtimecurrent\bin\bun.exe" (
303
319
  "%BVM_DIR%\runtimecurrent\bin\bun.exe" "%BVM_DIR%\bin\bvm-shim.js" "${$}" %*
@@ -306,46 +322,46 @@ if exist "%BVM_DIR%\runtimecurrent\bin\bun.exe" (
306
322
  exit /b 1
307
323
  )`,i6=($)=>`#!/bin/bash
308
324
  export BVM_DIR="${z}"
309
- exec "${n(j,"bvm-shim.sh")}" "${$}" "$@"`;async function J$(){await T(E),await T(j);let $=k==="win32";try{let q=n(j1(j1(__dirname)),"src","templates");if($){let Q=await Bun.file(n(q,"bvm-shim.js")).text();await Bun.write(n(j,"bvm-shim.js"),Q)}else{let Q=await Bun.file(n(q,"bvm-shim.sh")).text(),K=n(j,"bvm-shim.sh");await Bun.write(K,Q),await B1(K,493)}}catch(q){}let b=new Set(["bun","bunx"]);if(await X(C)){let q=await l(C);for(let Q of q){if(Q.startsWith("."))continue;let K=n(C,Q,"bin");if(await X(K)){let J=await l(K);for(let Z of J){let G=Z.replace(/\.(exe|ps1|cmd)$/i,"");if(G)b.add(G)}}}}for(let q of b)if($){await Bun.write(n(E,`${q}.cmd`),n6(q));let Q=n(E,`${q}.ps1`);if(await X(Q))await t6(Q)}else{let Q=n(E,q);await Bun.write(Q,i6(q)),await B1(Q,493)}console.log(Y.green(`\u2713 Regenerated ${b.size} shims in ${E}`))}import{rename as $4,rm as R1}from"fs/promises";var r={NPM:"https://registry.npmjs.org",NPM_MIRROR:"https://registry.npmmirror.com"};class F${timeoutMs;constructor($=3000){this.timeoutMs=$}async getFastestRegistry(){let $=async(b)=>{let q=Date.now();try{let Q=new AbortController,K=setTimeout(()=>Q.abort(),this.timeoutMs),J=await fetch(b,{method:"HEAD",signal:Q.signal});if(clearTimeout(K),!J.ok)throw Error(`Status ${J.status}`);return b}catch(Q){throw Q}};try{return await Promise.any([$(r.NPM).then(()=>r.NPM),$(r.NPM_MIRROR).then(()=>r.NPM_MIRROR)])}catch(b){return r.NPM}}}import{existsSync as M1,readFileSync as D1,writeFileSync as o6}from"fs";import{homedir as a6}from"os";import{join as s6}from"path";class G${configPath;constructor($){this.configPath=$||s6(a6(),".bunfig.toml")}getPath(){return this.configPath}getRegistry(){if(!M1(this.configPath))return null;let $=D1(this.configPath,"utf-8"),b=$.indexOf("[install]");if(b===-1)return null;let q=$.indexOf("[",b+1),K=$.substring(b,q===-1?void 0:q).match(/registry\s*=\s*\"(.*?)\"/);return K?K[1]:null}setRegistry($){let b="";if(M1(this.configPath))b=D1(this.configPath,"utf-8");let q="[install]",Q=b.indexOf(q);if(Q===-1){let K=b.length>0&&!b.endsWith(`
325
+ exec "${p(j,"bvm-shim.sh")}" "${$}" "$@"`;async function Q$(){await I(R),await I(j);let $=x==="win32";try{let q=p(M1(M1(__dirname)),"src","templates");if($){let J=await Bun.file(p(q,"bvm-shim.js")).text();await Bun.write(p(j,"bvm-shim.js"),J)}else{let J=await Bun.file(p(q,"bvm-shim.sh")).text(),K=p(j,"bvm-shim.sh");await Bun.write(K,J),await D1(K,493)}}catch(q){}let b=new Set(["bun","bunx"]);if(await X(k)){let q=await n(k);for(let J of q){if(J.startsWith("."))continue;let K=p(k,J,"bin");if(await X(K)){let Q=await n(K);for(let Z of Q){let G=Z.replace(/\.(exe|ps1|cmd)$/i,"");if(G)b.add(G)}}}}for(let q of b)if($){if(q==="bun")await Bun.write(p(R,"bun.cmd"),f$);else if(q==="bunx")await Bun.write(p(R,"bunx.cmd"),F$);else await Bun.write(p(R,`${q}.cmd`),o6(q));let J=p(R,`${q}.ps1`);if(await X(J))await n6(J)}else{let J=p(R,q);await Bun.write(J,i6(q)),await D1(J,493)}console.log(Y.green(`\u2713 Regenerated ${b.size} shims in ${R}`))}var r={NPM:"https://registry.npmjs.org",NPM_MIRROR:"https://registry.npmmirror.com"};class A${timeoutMs;constructor($=3000){this.timeoutMs=$}async getFastestRegistry(){let $=async(b)=>{let q=Date.now();try{let J=new AbortController,K=setTimeout(()=>J.abort(),this.timeoutMs),Q=await fetch(b,{method:"HEAD",signal:J.signal});if(clearTimeout(K),!Q.ok)throw Error(`Status ${Q.status}`);return b}catch(J){throw J}};try{return await Promise.any([$(r.NPM).then(()=>r.NPM),$(r.NPM_MIRROR).then(()=>r.NPM_MIRROR)])}catch(b){return r.NPM}}}import{existsSync as B1,readFileSync as R1,writeFileSync as a6}from"fs";import{homedir as s6}from"os";import{join as r6}from"path";class G${configPath;constructor($){this.configPath=$||r6(s6(),".bunfig.toml")}getPath(){return this.configPath}getRegistry(){if(!B1(this.configPath))return null;let $=R1(this.configPath,"utf-8"),b=$.indexOf("[install]");if(b===-1)return null;let q=$.indexOf("[",b+1),K=$.substring(b,q===-1?void 0:q).match(/registry\s*=\s*\"(.*?)\"/);return K?K[1]:null}setRegistry($){let b="";if(B1(this.configPath))b=R1(this.configPath,"utf-8");let q="[install]",J=b.indexOf(q);if(J===-1){let K=b.length>0&&!b.endsWith(`
310
326
  `)?`
311
327
  `:"";b+=`${K}${q}
312
328
  registry = "${$}"
313
- `}else{let K=b.indexOf("[",Q+1),J=K===-1?b.length:K,Z=b.substring(0,Q),G=b.substring(Q,J),W=b.substring(J);if(G.match(/registry\s*=/)){let L=G.replace(/registry\s*=\s*".*?"/,`registry = "${$}"`);b=Z+L+W}else{let L=G.replace(q,`${q}
314
- registry = "${$}"`);b=Z+L+W}}o6(this.configPath,b,"utf-8")}}async function n$($,b){try{await $4($,b)}catch(q){await Bun.write(Bun.file(b),Bun.file($)),await R1($,{force:!0})}}async function T1($,b,q,Q){let K=await fetch($);if(!K.ok)throw Error(`Status ${K.status}`);let J=+(K.headers.get("Content-Length")||0),Z=0,G=K.body?.getReader();if(!G)throw Error("No response body");let W=Bun.file(b).writer(),L=k==="win32";q.stop();let O=null,y=-1;if(!L)O=new P$(J||41943040),O.start();else console.log(`Downloading Bun ${Q}...`);try{let A=Date.now();while(!0){let{done:c,value:S}=await G.read();if(c)break;if(W.write(S),Z+=S.length,!L&&O){let P=(Date.now()-A)/1000,u=P>0?(Z/1024/P).toFixed(0):"0";O.update(Z,{speed:u})}else if(L&&J){let P=Math.floor(Z/J*10);if(P>y)console.log(` > ${P*10}%`),y=P}}if(await W.end(),!L&&O)O.stop();else console.log(" > 100% [Done]")}catch(A){try{W.end()}catch(c){}if(!L&&O)O.stop();else console.log(" > Download Failed");throw q.start(),A}q.start()}async function o$($,b={}){let q=$,Q=null,K=!1;if(!q)q=await M$()||void 0;if(!q){console.error(Y.red("No version specified and no .bvmrc found. Usage: bvm install <version>"));return}try{await U(`Finding Bun ${q} release...`,async(J)=>{let Z=null,G=H(q);if(/^v?\d+\.\d+\.\d+$/.test(q)&&!q.includes("canary"))if(J.update(`Checking if Bun ${G} exists...`),await w1(G))Z=G;else throw J.fail(Y.red(`Bun version ${G} not found on registry.`)),Error(`Bun version ${G} not found on registry.`);else if(q==="latest"){J.update("Checking latest version...");let P=await O1();if(P.latest)Z=H(P.latest);else throw Error('Could not resolve "latest" version.')}else throw J.fail(Y.yellow('Fuzzy matching (e.g. "1.1") is disabled for stability.')),console.log(Y.dim(' Please specify the exact version (e.g. "1.1.20") or "latest".')),console.log(Y.dim(" To see available versions, run: bvm ls-remote")),Error("Fuzzy matching disabled");if(!Z)throw J.fail(Y.red(`Could not find a Bun release for '${q}' compatible with your system.`)),Error(`Could not find a Bun release for '${q}' compatible with your system.`);let W=await k1(Z);if(!W)throw Error(`Could not find a Bun release for ${Z} compatible with your system.`);let{url:L,mirrorUrl:O,foundVersion:y}=W,A=i(C,y),c=i(A,"bin"),S=i(c,R);if(await X(S))J.succeed(Y.green(`Bun ${y} is already installed.`)),Q=y,K=!0;else if(H(Bun.version)===y&&!M){J.info(Y.cyan(`Requested version ${y} matches current BVM runtime. Creating symlink...`)),await T(c);let u=process.execPath;try{let{symlink:e}=await import("fs/promises");await e(u,S)}catch(e){await Bun.write(Bun.file(S),Bun.file(u)),await i$(S,493)}J.succeed(Y.green(`Bun ${y} linked from local runtime.`)),Q=y,K=!0}else if(M)await T(c),await b4(S,y),Q=y,K=!0;else{J.update(`Downloading Bun ${y} to cache...`),await T(_);let u=i(_,`${y}-${r6(L)}`);if(await X(u))J.succeed(Y.green(`Using cached Bun ${y} archive.`));else{let I=`${u}.${Date.now()}.tmp`;try{await T1(L,I,J,y),await n$(I,u)}catch(b1){try{await R1(I,{force:!0})}catch{}if(J.update("Download failed, trying mirror..."),console.log(Y.dim(`
315
- Debug: ${b1.message}`)),O){let q6=new URL(O).hostname;J.update(`Downloading from mirror (${q6})...`),await T1(O,I,J,y),await n$(I,u)}else throw b1}}J.update(`Extracting Bun ${y}...`),await T(A),await C1(u,A);let e="",D$=[i(A,R),i(A,"bin",R),i(A,"package","bin",R)],b6=await l(A);for(let I of b6)if(I.startsWith("bun-"))D$.push(i(A,I,R)),D$.push(i(A,I,"bin",R));for(let I of D$)if(await X(I)){e=I;break}if(!e)throw Error(`Could not find bun executable in ${A}`);if(await T(c),e!==S){await n$(e,S);let I=e6(e);if(I!==A&&I!==c)await H$(I)}await i$(S,493),J.succeed(Y.green(`Bun ${y} installed successfully.`)),Q=y,K=!0}},{failMessage:`Failed to install Bun ${q}`})}catch(J){throw Error(`Failed to install Bun: ${J.message}`)}if(K)await z$(!1);if(Q)try{await L$(Q,{silent:!0});let J=i(F,"default");if(!await X(J))await w$("default",Q,{silent:!0})}catch(J){}if(await J$(),Q&&!M)try{let J=new G$;if(!J.getRegistry())await U("Checking network speed for registry optimization...",async(Z)=>{if(await new F$(3000).getFastestRegistry()===r.NPM_MIRROR)J.setRegistry(r.NPM_MIRROR),Z.succeed(Y.green("\u26A1 Auto-configured global bunfig.toml to use npmmirror.com for faster installs."));else Z.stop()},{failMessage:"Registry check failed (harmless)"})}catch(J){}if(Q)console.log(Y.cyan(`
316
- \u2713 Bun ${Q} installed and active.`)),console.log(Y.dim(" To verify, run: bun --version or bvm ls"))}async function b4($,b){let q=b.replace(/^v/,""),Q=`#!/usr/bin/env bash
329
+ `}else{let K=b.indexOf("[",J+1),Q=K===-1?b.length:K,Z=b.substring(0,J),G=b.substring(J,Q),W=b.substring(Q);if(G.match(/registry\s*=/)){let L=G.replace(/registry\s*=\s*".*?"/,`registry = "${$}"`);b=Z+L+W}else{let L=G.replace(q,`${q}
330
+ registry = "${$}"`);b=Z+L+W}}a6(this.configPath,b,"utf-8")}}async function T$($,b){let q=M.replace("bun","bunx"),J=t($,q);if(await X(J))return;try{await q4(M,J)}catch(K){await Bun.write(Bun.file(J),Bun.file(b)),await I$(J,493)}}async function i$($,b){try{await b4($,b)}catch(q){await Bun.write(Bun.file(b),Bun.file($)),await I1($,{force:!0})}}async function T1($,b,q,J){let K=await fetch($);if(!K.ok)throw Error(`Status ${K.status}`);let Q=+(K.headers.get("Content-Length")||0),Z=0,G=K.body?.getReader();if(!G)throw Error("No response body");let W=Bun.file(b).writer(),L=x==="win32";q.stop();let O=null,y=-1;if(!L)O=new d$(Q||41943040),O.start();else console.log(`Downloading Bun ${J}...`);try{let A=Date.now();while(!0){let{done:_,value:v}=await G.read();if(_)break;if(W.write(v),Z+=v.length,!L&&O){let u=(Date.now()-A)/1000,g=u>0?(Z/1024/u).toFixed(0):"0";O.update(Z,{speed:g})}else if(L&&Q){let u=Math.floor(Z/Q*10);if(u>y)console.log(` > ${u*10}%`),y=u}}if(await W.end(),!L&&O)O.stop();else console.log(" > 100% [Done]")}catch(A){try{W.end()}catch(_){}if(!L&&O)O.stop();else console.log(" > Download Failed");throw q.start(),A}q.start()}async function a$($,b={}){let q=$,J=null,K=!1;if(!q)q=await R$()||void 0;if(!q){console.error(Y.red("No version specified and no .bvmrc found. Usage: bvm install <version>"));return}try{await U(`Finding Bun ${q} release...`,async(Q)=>{let Z=null,G=H(q);if(/^v?\d+\.\d+\.\d+$/.test(q)&&!q.includes("canary"))if(Q.update(`Checking if Bun ${G} exists...`),await O1(G))Z=G;else throw Q.fail(Y.red(`Bun version ${G} not found on registry.`)),Error(`Bun version ${G} not found on registry.`);else if(q==="latest"){Q.update("Checking latest version...");let u=await x1();if(u.latest)Z=H(u.latest);else throw Error('Could not resolve "latest" version.')}else throw Q.fail(Y.yellow('Fuzzy matching (e.g. "1.1") is disabled for stability.')),console.log(Y.dim(' Please specify the exact version (e.g. "1.1.20") or "latest".')),console.log(Y.dim(" To see available versions, run: bvm ls-remote")),Error("Fuzzy matching disabled");if(!Z)throw Q.fail(Y.red(`Could not find a Bun release for '${q}' compatible with your system.`)),Error(`Could not find a Bun release for '${q}' compatible with your system.`);let W=await k1(Z);if(!W)throw Error(`Could not find a Bun release for ${Z} compatible with your system.`);let{url:L,mirrorUrl:O,foundVersion:y}=W,A=t(k,y),_=t(A,"bin"),v=t(_,M);if(await X(v))Q.succeed(Y.green(`Bun ${y} is already installed.`)),await T$(_,v),J=y,K=!0;else if(H(Bun.version)===y&&!B){Q.info(Y.cyan(`Requested version ${y} matches current BVM runtime. Creating symlink...`)),await I(_);let g=process.execPath;try{let{symlink:e}=await import("fs/promises");await e(g,v)}catch(e){await Bun.write(Bun.file(v),Bun.file(g)),await I$(v,493)}Q.succeed(Y.green(`Bun ${y} linked from local runtime.`)),await T$(_,v),J=y,K=!0}else if(B)await I(_),await J4(v,y),await T$(_,v),J=y,K=!0;else{Q.update(`Downloading Bun ${y} to cache...`),await I(P);let g=t(P,`${y}-${e6(L)}`);if(await X(g))Q.succeed(Y.green(`Using cached Bun ${y} archive.`));else{let E=`${g}.${Date.now()}.tmp`;try{await T1(L,E,Q,y),await i$(E,g)}catch(q1){try{await I1(E,{force:!0})}catch{}if(Q.update("Download failed, trying mirror..."),console.log(Y.dim(`
331
+ Debug: ${q1.message}`)),O){let J6=new URL(O).hostname;Q.update(`Downloading from mirror (${J6})...`),await T1(O,E,Q,y),await i$(E,g)}else throw q1}}Q.update(`Extracting Bun ${y}...`),await I(A),await C1(g,A);let e="",v$=[t(A,M),t(A,"bin",M),t(A,"package","bin",M)],q6=await n(A);for(let E of q6)if(E.startsWith("bun-"))v$.push(t(A,E,M)),v$.push(t(A,E,"bin",M));for(let E of v$)if(await X(E)){e=E;break}if(!e)throw Error(`Could not find bun executable in ${A}`);if(await I(_),e!==v){await i$(e,v);let E=$4(e);if(E!==A&&E!==_)await H$(E)}await I$(v,493),Q.succeed(Y.green(`Bun ${y} installed successfully.`)),await T$(_,v),J=y,K=!0}},{failMessage:`Failed to install Bun ${q}`})}catch(Q){throw Error(`Failed to install Bun: ${Q.message}`)}if(K)await z$(!1);if(J)try{await L$(J,{silent:!0});let Q=t(F,"default");if(!await X(Q))await w$("default",J,{silent:!0})}catch(Q){}if(await Q$(),J&&!B)try{let Q=new G$;if(!Q.getRegistry())await U("Checking network speed for registry optimization...",async(Z)=>{if(await new A$(3000).getFastestRegistry()===r.NPM_MIRROR)Q.setRegistry(r.NPM_MIRROR),Z.succeed(Y.green("\u26A1 Auto-configured global bunfig.toml to use npmmirror.com for faster installs."));else Z.stop()},{failMessage:"Registry check failed (harmless)"})}catch(Q){}if(J)console.log(Y.cyan(`
332
+ \u2713 Bun ${J} installed and active.`)),console.log(Y.dim(" To verify, run: bun --version or bvm ls"))}async function J4($,b){let q=b.replace(/^v/,""),J=`#!/usr/bin/env bash
317
333
  set -euo pipefail
318
334
  if [[ $# -gt 0 && "$1" == "--version" ]]; then echo "${q}"; exit 0; fi
319
335
  echo "Bun ${q} stub invoked with: $@"
320
336
  exit 0
321
- `;await Bun.write($,Q),await i$($,493)}N();x();B();async function E1(){await U("Fetching remote Bun versions...",async($)=>{let q=(await z1()).filter((Q)=>p(Q)).filter((Q)=>!Q.includes("canary")).sort(Z$);if(q.length===0)throw Error("No remote Bun versions found.");$.succeed(Y.green("Available remote Bun versions:")),q.forEach((Q)=>{console.log(` ${H(Q)}`)})},{failMessage:"Failed to fetch remote Bun versions"})}N();x();f();B();import{join as q4}from"path";async function I1(){await U("Fetching locally installed Bun versions...",async($)=>{let b=await V(),Q=(await t()).version;if($.succeed(Y.green("Locally installed Bun versions:")),b.length===0)console.log(" (No versions installed yet)");else b.forEach((J)=>{if(J===Q)console.log(`* ${Y.green(J)} ${Y.dim("(current)")}`);else console.log(` ${J}`)});if(await X(F)){let J=await l(F);if(J.length>0){console.log(Y.green(`
322
- Aliases:`));for(let Z of J)try{let G=(await D(q4(F,Z))).trim(),W=H(G),L=`-> ${Y.cyan(W)}`;if(W===Q)L+=` ${Y.dim("(current)")}`;console.log(` ${Z} ${Y.gray(L)}`)}catch(G){}}}},{failMessage:"Failed to list local Bun versions"})}N();x();B();async function v1(){await U("Checking current Bun version...",async($)=>{let{version:b,source:q}=await t();if(b)$.stop(),console.log(`${Y.green("\u2713")} Current Bun version: ${Y.green(b)} ${Y.dim(`(${q})`)}`);else $.info(Y.blue("No Bun version is currently active.")),console.log(Y.yellow("Use 'bvm install <version>' to set a default, or create a .bvmrc file."))},{failMessage:"Failed to determine current Bun version"})}N();f();x();B();import{join as a$,basename as Q4}from"path";import{unlink as J4}from"fs/promises";async function _1($){await U(`Attempting to uninstall Bun ${$}...`,async(b)=>{let q=H($),Q=a$(C,q),K=a$(Q,"bin",R);if(!await X(K))throw Error(`Bun ${$} is not installed.`);let J=!1;try{let Z=a$(F,"default");if(await X(Z)){let G=(await D(Z)).trim();if(H(G)===q)J=!0}}catch(Z){}if(J)throw console.log(Y.yellow("Hint: Set a new default using 'bvm default <new_version>'")),Error(`Bun ${$} is currently set as default. Please set another default before uninstalling.`);try{let Z=await y1(K$);if(Z){if(H(Q4(Z))===q)await J4(K$)}}catch(Z){}await H$(Q),b.succeed(Y.green(`Bun ${q} uninstalled successfully.`)),await J$()},{failMessage:`Failed to uninstall Bun ${$}`})}N();f();x();B();import{join as K4}from"path";import{unlink as Y4}from"fs/promises";async function S1($){await U(`Removing alias '${$}'...`,async(b)=>{let q=K4(F,$);if(!await X(q))throw Error(`Alias '${$}' does not exist.`);await Y4(q),b.succeed(Y.green(`Alias '${$}' removed successfully.`))},{failMessage:`Failed to remove alias '${$}'`})}N();f();x();Q$();B();import{join as s$}from"path";async function P1($,b){await U(`Preparing to run with Bun ${$}...`,async(q)=>{let Q=await h($);if(!Q)Q=H($);let K=s$(C,Q),J=s$(K,"bin"),Z=s$(J,R);if(!await X(Z)){q.fail(Y.red(`Bun ${$} (resolved: ${Q}) is not installed.`)),console.log(Y.yellow(`You can install it using: bvm install ${$}`));return}q.stop();try{await m([Z,...b],{cwd:process.cwd(),prependPath:J}),process.exit(0)}catch(G){console.error(G.message),process.exit(1)}},{failMessage:`Failed to run command with Bun ${$}`})}N();f();x();Q$();B();import{join as r$}from"path";async function u1($,b,q){await U(`Preparing environment for Bun ${$} to execute '${b}'...`,async(Q)=>{let K=await h($);if(!K)K=H($);let J=r$(C,K),Z=r$(J,"bin"),G=r$(Z,R);if(!await X(G)){Q.fail(Y.red(`Bun ${$} (resolved: ${K}) is not installed.`)),console.log(Y.yellow(`You can install it using: bvm install ${$}`));return}Q.stop();try{await m([b,...q],{cwd:process.cwd(),prependPath:Z}),process.exit(0)}catch(W){console.error(W.message),process.exit(1)}},{failMessage:`Failed to execute command with Bun ${$}'s environment`})}f();x();B();import{join as Z4}from"path";async function g1($){await U("Resolving path...",async()=>{let b=null,q="bun",{version:Q}=await t();if(!$||$==="current"){if(b=Q,!b)throw Error("No active Bun version found.")}else{let{resolveLocalVersion:J}=await Promise.resolve().then(() => (Q$(),N1));if(b=await J($),!b)if(Q)b=Q,q=$;else throw Error(`Bun version or command '${$}' not found.`)}let K=Z4(C,b,"bin",q==="bun"?R:q);if(await X(K))console.log(K);else throw Error(`Command '${q}' not found in Bun ${b}.`)},{failMessage:"Failed to resolve path"})}N();x();B();Q$();async function V1($){await U(`Resolving session version for Bun ${$}...`,async(b)=>{let q=null,Q=await h($);if(Q)q=Q;else{let J=(await V()).map((Z)=>H(Z));q=b$($,J)}if(!q)throw Error(`Bun version '${$}' is not installed or cannot be resolved.`);let K=H(q);b.succeed(Y.green(`Bun ${K} will be active in this session.`)),console.log(`export BVM_ACTIVE_VERSION=${K}`),console.log(Y.dim("Run `eval $(bvm shell <version>)` or `export BVM_ACTIVE_VERSION=...` to activate."))},{failMessage:`Failed to set session version for Bun ${$}`})}N();f();x();B();import{join as G4}from"path";async function d1($){let b=G4(F,"default");if(!$)await U("Checking current default Bun version...",async(q)=>{if(await X(b)){let Q=await D(b);q.succeed(Y.green(`Default Bun version: ${H(Q.trim())}`))}else q.info(Y.blue("No global default Bun version is set.")),console.log(Y.yellow("Use 'bvm default <version>' to set one."))},{failMessage:"Failed to retrieve default Bun version"});else await U(`Setting global default to Bun ${$}...`,async(q)=>{let Q=(await V()).map((J)=>H(J)),K=b$($,Q);if(!K)throw Error(`Bun version '${$}' is not installed.`);await w$("default",K,{silent:!0}),q.succeed(Y.green(`\u2713 Default set to ${K}. New terminals will now start with this version.`))},{failMessage:`Failed to set global default to Bun ${$}`})}f();x();N();B();import{unlink as X4}from"fs/promises";import{join as W4}from"path";async function m1(){await U("Deactivating current Bun version...",async($)=>{let b=W4(F,"default");if(await X(b))await X4(b),$.succeed(Y.green("Default Bun version deactivated.")),console.log(Y.gray("Run `bvm use <version>` to reactivate.")),await J$();else $.info("No default Bun version is currently active.")},{failMessage:"Failed to deactivate"})}Q$();f();x();N();B();async function h1($){if($==="dir"){console.log(_);return}if($==="clear"){await U("Clearing cache...",async(b)=>{await H$(_),await T(_),b.succeed(Y.green("Cache cleared."))},{failMessage:"Failed to clear cache"});return}console.error(Y.red(`Unknown cache command: ${$}`)),console.log("Usage: bvm cache dir | bvm cache clear")}N();f();B();x();import{join as v}from"path";import{tmpdir as U4}from"os";import{rm as c1,mkdir as p1}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",e$=W$.version;async function l1(){let $=process.env.BVM_INSTALL_SOURCE;if($==="npm"||$==="bun"||__dirname.includes("node_modules")){await U(`Upgrading BVM via ${$||"package manager"}...`,async(q)=>{let Q=await q$(),K=$==="bun"?"bun":"npm";q.text=`Upgrading BVM via ${K} using ${Q}...`;try{await m([K,"install","-g","bvm-core","--registry",Q]),q.succeed(Y.green(`BVM upgraded via ${K} successfully.`))}catch(J){throw Error(`${K} upgrade failed: ${J.message}`)}});return}try{await U("Checking for BVM updates...",async(q)=>{let Q=M?{version:process.env.BVM_TEST_LATEST_VERSION?.replace("v","")||e$,tarball:"https://example.com/bvm-test.tgz",shasum:"mock",integrity:"mock"}:await B$();if(!Q)throw Error("Unable to determine the latest BVM version from NPM Registry.");let K=Q.version;if(!p(K))throw Error(`Unrecognized version received: ${K}`);if(!A$(K,e$)){q.succeed(Y.green(`BVM is already up to date (v${e$}).`)),console.log(Y.blue("You are using the latest version."));return}if(q.text=`Updating BVM to v${K}...`,M&&!process.env.BVM_TEST_REAL_UPGRADE){q.succeed(Y.green("BVM updated successfully (test mode)."));return}q.update("Downloading update package...");let J=v(U4(),`bvm-upgrade-${Date.now()}`);await p1(J,{recursive:!0});let Z=v(J,"bvm-core.tgz");if(M){await d(Z,"mock-tarball");let W=v(J,"package","dist");await p1(W,{recursive:!0}),await d(v(W,"index.js"),"// new cli"),await d(v(W,"bvm-shim.sh"),"# new shim"),await d(v(W,"bvm-shim.js"),"// new shim")}else{let W=await s(Q.tarball,{timeout:30000});if(!W.ok)throw Error(`Failed to download tarball: ${W.statusText}`);let L=await W.arrayBuffer();await C$(Z,new Uint8Array(L)),q.update("Extracting update...");try{await m(["tar","-xzf",Z,"-C",J])}catch(O){throw Error('Failed to extract update package. Ensure "tar" is available.')}}q.update("Applying updates...");let G=v(J,"package","dist");if(await X(v(G,"index.js")))await C$(v(z,"src","index.js"),await D(v(G,"index.js")));if(k!=="win32"&&await X(v(G,"bvm-shim.sh")))await C$(v(z,"bin","bvm-shim.sh"),await D(v(G,"bvm-shim.sh")));if(k==="win32"&&await X(v(G,"bvm-shim.js")))await C$(v(z,"bin","bvm-shim.js"),await D(v(G,"bvm-shim.js")));try{await c1(J,{recursive:!0,force:!0})}catch(W){}try{await c1(I$,{force:!0})}catch(W){}q.update("Finalizing environment..."),await z$(!1),q.succeed(Y.green(`BVM updated to v${K} successfully.`)),console.log(Y.yellow("Please restart your terminal to apply changes."))},{failMessage:"Failed to upgrade BVM"})}catch(q){throw Error(`Failed to upgrade BVM: ${q.message}`)}}N();f();x();B();import{homedir as y4}from"os";import{join as H4}from"path";async function t1(){await U("Gathering BVM diagnostics...",async()=>{let $=new G$,b={currentVersion:(await t()).version,installedVersions:await V(),aliases:await L4(),env:{BVM_DIR:z,BVM_BIN_DIR:j,BVM_SHIMS_DIR:E,BVM_VERSIONS_DIR:C,BVM_TEST_MODE:process.env.BVM_TEST_MODE,HOME:process.env.HOME||y4()},bunfig:{path:$.getPath(),registry:$.getRegistry()}};z4(b)})}async function L4(){if(!await X(F))return[];let $=await l(F),b=[];for(let q of $){let Q=H4(F,q);if(await X(Q)){let K=await Bun.file(Q).text();b.push({name:q,target:H(K.trim())})}}return b}function z4($){if(console.log(Y.bold(`
323
- System`)),console.log(` OS: ${Y.cyan(k)}`),console.log(` Arch: ${Y.cyan($$)} ${process.arch!==$$?Y.yellow(`(Process: ${process.arch})`):""}`),console.log(` AVX2: ${f$?Y.green("Supported"):Y.yellow("Not Supported (Baseline fallback enabled)")}`),console.log(Y.bold(`
324
- Directories`)),console.log(` BVM_DIR: ${Y.cyan($.env.BVM_DIR||"")}`),console.log(` BIN_DIR: ${Y.cyan(j)}`),console.log(` SHIMS_DIR: ${Y.cyan(E)}`),console.log(` VERSIONS_DIR: ${Y.cyan(C)}`),console.log(Y.bold(`
337
+ `;await Bun.write($,J),await I$($,493)}f();C();D();async function v1(){await U("Fetching remote Bun versions...",async($)=>{let q=(await w1()).filter((J)=>l(J)).filter((J)=>!J.includes("canary")).sort(Z$);if(q.length===0)throw Error("No remote Bun versions found.");$.succeed(Y.green("Available remote Bun versions:")),q.forEach((J)=>{console.log(` ${H(J)}`)})},{failMessage:"Failed to fetch remote Bun versions"})}f();C();N();D();import{join as Q4}from"path";async function E1(){await U("Fetching locally installed Bun versions...",async($)=>{let b=await d(),J=(await o()).version;if($.succeed(Y.green("Locally installed Bun versions:")),b.length===0)console.log(" (No versions installed yet)");else b.forEach((Q)=>{if(Q===J)console.log(`* ${Y.green(Q)} ${Y.dim("(current)")}`);else console.log(` ${Q}`)});if(await X(F)){let Q=await n(F);if(Q.length>0){console.log(Y.green(`
338
+ Aliases:`));for(let Z of Q)try{let G=(await T(Q4(F,Z))).trim(),W=H(G),L=`-> ${Y.cyan(W)}`;if(W===J)L+=` ${Y.dim("(current)")}`;console.log(` ${Z} ${Y.gray(L)}`)}catch(G){}}}},{failMessage:"Failed to list local Bun versions"})}f();C();D();async function S1(){await U("Checking current Bun version...",async($)=>{let{version:b,source:q}=await o();if(b)$.stop(),console.log(`${Y.green("\u2713")} Current Bun version: ${Y.green(b)} ${Y.dim(`(${q})`)}`);else $.info(Y.blue("No Bun version is currently active.")),console.log(Y.yellow("Use 'bvm install <version>' to set a default, or create a .bvmrc file."))},{failMessage:"Failed to determine current Bun version"})}f();N();C();D();import{join as s$,basename as K4}from"path";import{unlink as Y4}from"fs/promises";async function _1($){await U(`Attempting to uninstall Bun ${$}...`,async(b)=>{let q=H($),J=s$(k,q),K=s$(J,"bin",M);if(!await X(K))throw Error(`Bun ${$} is not installed.`);let Q=!1;try{let Z=s$(F,"default");if(await X(Z)){let G=(await T(Z)).trim();if(H(G)===q)Q=!0}}catch(Z){}if(Q)throw console.log(Y.yellow("Hint: Set a new default using 'bvm default <new_version>'")),Error(`Bun ${$} is currently set as default. Please set another default before uninstalling.`);try{let Z=await H1(K$);if(Z){if(H(K4(Z))===q)await Y4(K$)}}catch(Z){}await H$(J),b.succeed(Y.green(`Bun ${q} uninstalled successfully.`)),await Q$()},{failMessage:`Failed to uninstall Bun ${$}`})}f();N();C();D();import{join as Z4}from"path";import{unlink as G4}from"fs/promises";async function P1($){await U(`Removing alias '${$}'...`,async(b)=>{let q=Z4(F,$);if(!await X(q))throw Error(`Alias '${$}' does not exist.`);await G4(q),b.succeed(Y.green(`Alias '${$}' removed successfully.`))},{failMessage:`Failed to remove alias '${$}'`})}f();N();C();J$();D();import{join as r$}from"path";async function u1($,b){await U(`Preparing to run with Bun ${$}...`,async(q)=>{let J=await c($);if(!J)J=H($);let K=r$(k,J),Q=r$(K,"bin"),Z=r$(Q,M);if(!await X(Z)){q.fail(Y.red(`Bun ${$} (resolved: ${J}) is not installed.`)),console.log(Y.yellow(`You can install it using: bvm install ${$}`));return}q.stop();try{await h([Z,...b],{cwd:process.cwd(),prependPath:Q}),process.exit(0)}catch(G){console.error(G.message),process.exit(1)}},{failMessage:`Failed to run command with Bun ${$}`})}f();N();C();J$();D();import{join as e$}from"path";async function g1($,b,q){await U(`Preparing environment for Bun ${$} to execute '${b}'...`,async(J)=>{let K=await c($);if(!K)K=H($);let Q=e$(k,K),Z=e$(Q,"bin"),G=e$(Z,M);if(!await X(G)){J.fail(Y.red(`Bun ${$} (resolved: ${K}) is not installed.`)),console.log(Y.yellow(`You can install it using: bvm install ${$}`));return}J.stop();try{await h([b,...q],{cwd:process.cwd(),prependPath:Z}),process.exit(0)}catch(W){console.error(W.message),process.exit(1)}},{failMessage:`Failed to execute command with Bun ${$}'s environment`})}N();C();D();import{join as X4}from"path";async function V1($){await U("Resolving path...",async()=>{let b=null,q="bun",{version:J}=await o();if(!$||$==="current"){if(b=J,!b)throw Error("No active Bun version found.")}else{let{resolveLocalVersion:Q}=await Promise.resolve().then(() => (J$(),F1));if(b=await Q($),!b)if(J)b=J,q=$;else throw Error(`Bun version or command '${$}' not found.`)}let K=X4(k,b,"bin",q==="bun"?M:q);if(await X(K))console.log(K);else throw Error(`Command '${q}' not found in Bun ${b}.`)},{failMessage:"Failed to resolve path"})}f();C();D();J$();async function d1($){await U(`Resolving session version for Bun ${$}...`,async(b)=>{let q=null,J=await c($);if(J)q=J;else{let Q=(await d()).map((Z)=>H(Z));q=b$($,Q)}if(!q)throw Error(`Bun version '${$}' is not installed or cannot be resolved.`);let K=H(q);b.succeed(Y.green(`Bun ${K} will be active in this session.`)),console.log(`export BVM_ACTIVE_VERSION=${K}`),console.log(Y.dim("Run `eval $(bvm shell <version>)` or `export BVM_ACTIVE_VERSION=...` to activate."))},{failMessage:`Failed to set session version for Bun ${$}`})}f();N();C();D();import{join as W4}from"path";async function m1($){let b=W4(F,"default");if(!$)await U("Checking current default Bun version...",async(q)=>{if(await X(b)){let J=await T(b);q.succeed(Y.green(`Default Bun version: ${H(J.trim())}`))}else q.info(Y.blue("No global default Bun version is set.")),console.log(Y.yellow("Use 'bvm default <version>' to set one."))},{failMessage:"Failed to retrieve default Bun version"});else await U(`Setting global default to Bun ${$}...`,async(q)=>{let J=(await d()).map((Q)=>H(Q)),K=b$($,J);if(!K)throw Error(`Bun version '${$}' is not installed.`);await w$("default",K,{silent:!0}),q.succeed(Y.green(`\u2713 Default set to ${K}. New terminals will now start with this version.`))},{failMessage:`Failed to set global default to Bun ${$}`})}N();C();f();D();import{unlink as U4}from"fs/promises";import{join as y4}from"path";async function h1(){await U("Deactivating current Bun version...",async($)=>{let b=y4(F,"default");if(await X(b))await U4(b),$.succeed(Y.green("Default Bun version deactivated.")),console.log(Y.gray("Run `bvm use <version>` to reactivate.")),await Q$();else $.info("No default Bun version is currently active.")},{failMessage:"Failed to deactivate"})}J$();N();C();f();D();async function c1($){if($==="dir"){console.log(P);return}if($==="clear"){await U("Clearing cache...",async(b)=>{await H$(P),await I(P),b.succeed(Y.green("Cache cleared."))},{failMessage:"Failed to clear cache"});return}console.error(Y.red(`Unknown cache command: ${$}`)),console.log("Usage: bvm cache dir | bvm cache clear")}f();N();D();C();import{join as S}from"path";import{tmpdir as H4}from"os";import{rm as p1,mkdir as l1}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",$1=W$.version;async function t1(){let $=process.env.BVM_INSTALL_SOURCE;if($==="npm"||$==="bun"||__dirname.includes("node_modules")){await U(`Upgrading BVM via ${$||"package manager"}...`,async(q)=>{let J=await q$(),K=$==="bun"?"bun":"npm";q.text=`Upgrading BVM via ${K} using ${J}...`;try{await h([K,"install","-g","bvm-core","--registry",J]),q.succeed(Y.green(`BVM upgraded via ${K} successfully.`))}catch(Q){throw Error(`${K} upgrade failed: ${Q.message}`)}});return}try{await U("Checking for BVM updates...",async(q)=>{let J=B?{version:process.env.BVM_TEST_LATEST_VERSION?.replace("v","")||$1,tarball:"https://example.com/bvm-test.tgz",shasum:"mock",integrity:"mock"}:await B$();if(!J)throw Error("Unable to determine the latest BVM version from NPM Registry.");let K=J.version;if(!l(K))throw Error(`Unrecognized version received: ${K}`);if(!M$(K,$1)){q.succeed(Y.green(`BVM is already up to date (v${$1}).`)),console.log(Y.blue("You are using the latest version."));return}if(q.text=`Updating BVM to v${K}...`,B&&!process.env.BVM_TEST_REAL_UPGRADE){q.succeed(Y.green("BVM updated successfully (test mode)."));return}q.update("Downloading update package...");let Q=S(H4(),`bvm-upgrade-${Date.now()}`);await l1(Q,{recursive:!0});let Z=S(Q,"bvm-core.tgz");if(B){await m(Z,"mock-tarball");let W=S(Q,"package","dist");await l1(W,{recursive:!0}),await m(S(W,"index.js"),"// new cli"),await m(S(W,"bvm-shim.sh"),"# new shim"),await m(S(W,"bvm-shim.js"),"// new shim")}else{let W=await s(J.tarball,{timeout:30000});if(!W.ok)throw Error(`Failed to download tarball: ${W.statusText}`);let L=await W.arrayBuffer();await k$(Z,new Uint8Array(L)),q.update("Extracting update...");try{await h(["tar","-xzf",Z,"-C",Q])}catch(O){throw Error('Failed to extract update package. Ensure "tar" is available.')}}q.update("Applying updates...");let G=S(Q,"package","dist");if(await X(S(G,"index.js")))await k$(S(z,"src","index.js"),await T(S(G,"index.js")));if(x!=="win32"&&await X(S(G,"bvm-shim.sh")))await k$(S(z,"bin","bvm-shim.sh"),await T(S(G,"bvm-shim.sh")));if(x==="win32"&&await X(S(G,"bvm-shim.js")))await k$(S(z,"bin","bvm-shim.js"),await T(S(G,"bvm-shim.js")));try{await p1(Q,{recursive:!0,force:!0})}catch(W){}try{await p1(P$,{force:!0})}catch(W){}q.update("Finalizing environment..."),await z$(!1),q.succeed(Y.green(`BVM updated to v${K} successfully.`)),console.log(Y.yellow("Please restart your terminal to apply changes."))},{failMessage:"Failed to upgrade BVM"})}catch(q){throw Error(`Failed to upgrade BVM: ${q.message}`)}}f();N();C();D();import{homedir as L4}from"os";import{join as z4}from"path";async function n1(){await U("Gathering BVM diagnostics...",async()=>{let $=new G$,b={currentVersion:(await o()).version,installedVersions:await d(),aliases:await w4(),env:{BVM_DIR:z,BVM_BIN_DIR:j,BVM_SHIMS_DIR:R,BVM_VERSIONS_DIR:k,BVM_TEST_MODE:process.env.BVM_TEST_MODE,HOME:process.env.HOME||L4()},bunfig:{path:$.getPath(),registry:$.getRegistry()}};O4(b)})}async function w4(){if(!await X(F))return[];let $=await n(F),b=[];for(let q of $){let J=z4(F,q);if(await X(J)){let K=await Bun.file(J).text();b.push({name:q,target:H(K.trim())})}}return b}function O4($){if(console.log(Y.bold(`
339
+ System`)),console.log(` OS: ${Y.cyan(x)}`),console.log(` Arch: ${Y.cyan($$)} ${process.arch!==$$?Y.yellow(`(Process: ${process.arch})`):""}`),console.log(` AVX2: ${j$?Y.green("Supported"):Y.yellow("Not Supported (Baseline fallback enabled)")}`),console.log(Y.bold(`
340
+ Directories`)),console.log(` BVM_DIR: ${Y.cyan($.env.BVM_DIR||"")}`),console.log(` BIN_DIR: ${Y.cyan(j)}`),console.log(` SHIMS_DIR: ${Y.cyan(R)}`),console.log(` VERSIONS_DIR: ${Y.cyan(k)}`),console.log(Y.bold(`
325
341
  Environment`)),console.log(` HOME: ${$.env.HOME||"n/a"}`),console.log(` BVM_TEST_MODE: ${$.env.BVM_TEST_MODE||"false"}`),console.log(Y.bold(`
326
- Installed Versions`)),$.installedVersions.length===0)console.log(" (none installed)");else $.installedVersions.forEach((b)=>{let q=b===$.currentVersion,Q=q?Y.green("*"):" ",K=q?Y.green(b):b,J=q?Y.green(" (current)"):"";console.log(` ${Q} ${K}${J}`)});if(console.log(Y.bold(`
342
+ Installed Versions`)),$.installedVersions.length===0)console.log(" (none installed)");else $.installedVersions.forEach((b)=>{let q=b===$.currentVersion,J=q?Y.green("*"):" ",K=q?Y.green(b):b,Q=q?Y.green(" (current)"):"";console.log(` ${J} ${K}${Q}`)});if(console.log(Y.bold(`
327
343
  Configuration`)),console.log(` Bunfig: ${Y.cyan($.bunfig.path)}`),console.log(` Registry: ${$.bunfig.registry?Y.green($.bunfig.registry):Y.dim("default")}`),console.log(Y.bold(`
328
344
  Aliases`)),$.aliases.length===0)console.log(" (no aliases configured)");else $.aliases.forEach((b)=>{console.log(` ${b.name} ${Y.gray("->")} ${Y.cyan(b.target)}`)});console.log(`
329
- `+Y.green("Diagnostics complete."))}N();B();async function n1($){let[b,q,Q]=$,K=new G$;if(b==="ls"||!b){console.log(Y.bold(`
330
- BVM Configuration (via ~/.bunfig.toml)`)),console.log(`Path: ${Y.dim(K.getPath())}`);let J=K.getRegistry();console.log(`Registry: ${J?Y.green(J):Y.yellow("(not set, using Bun default)")}`);return}if(b==="registry"){if(q==="auto")await U("Racing registries for optimal speed...",async(J)=>{let G=await new F$().getFastestRegistry();K.setRegistry(G),J.succeed(Y.green(`\u2713 Set registry to ${G}`))});else if(q)K.setRegistry(q),console.log(Y.green(`\u2713 Registry set to ${q}`));else{let J=K.getRegistry();console.log(`Current registry: ${J||"default"}`)}return}console.log(Y.red(`Unknown config command: ${b}`)),console.log("Usage:"),console.log(" bvm config ls"),console.log(" bvm config registry <url|auto>")}var $1=["install","uninstall","use","ls","ls-remote","current","alias","unalias","run","exec","which","cache","setup","upgrade","doctor","completion","deactivate","help"],i1={bash:`#!/usr/bin/env bash
345
+ `+Y.green("Diagnostics complete."))}f();D();async function o1($){let[b,q,J]=$,K=new G$;if(b==="ls"||!b){console.log(Y.bold(`
346
+ BVM Configuration (via ~/.bunfig.toml)`)),console.log(`Path: ${Y.dim(K.getPath())}`);let Q=K.getRegistry();console.log(`Registry: ${Q?Y.green(Q):Y.yellow("(not set, using Bun default)")}`);return}if(b==="registry"){if(q==="auto")await U("Racing registries for optimal speed...",async(Q)=>{let G=await new A$().getFastestRegistry();K.setRegistry(G),Q.succeed(Y.green(`\u2713 Set registry to ${G}`))});else if(q)K.setRegistry(q),console.log(Y.green(`\u2713 Registry set to ${q}`));else{let Q=K.getRegistry();console.log(`Current registry: ${Q||"default"}`)}return}console.log(Y.red(`Unknown config command: ${b}`)),console.log("Usage:"),console.log(" bvm config ls"),console.log(" bvm config registry <url|auto>")}var b1=["install","uninstall","use","ls","ls-remote","current","alias","unalias","run","exec","which","cache","setup","upgrade","doctor","completion","deactivate","help"],i1={bash:`#!/usr/bin/env bash
331
347
  _bvm_completions() {
332
- COMPREPLY=( $(compgen -W "${$1.join(" ")}" -- "\${COMP_WORDS[COMP_CWORD]}") )
348
+ COMPREPLY=( $(compgen -W "${b1.join(" ")}" -- "\${COMP_WORDS[COMP_CWORD]}") )
333
349
  }
334
350
  complete -F _bvm_completions bvm
335
351
  `,zsh:`#compdef bvm
336
352
  _bvm() {
337
353
  local -a commands
338
- commands=( ${$1.join(" ")} )
354
+ commands=( ${b1.join(" ")} )
339
355
  _describe 'command' commands
340
356
  }
341
357
  compdef _bvm bvm
342
- `,fish:`complete -c bvm -f -a "${$1.join(" ")}"
343
- `};function o1($){let b=i1[$];if(!b)throw Error(`Unsupported shell '${$}'. Supported shells: ${Object.keys(i1).join(", ")}`);console.log(b)}N();f();x();import{join as a1}from"path";N();var s1="update-check.json",w4=86400000;async function r1(){if(process.env.CI||M)return;let $=a1(_,s1);try{if(await X($)){let b=await D($),q=JSON.parse(b);if(Date.now()-q.lastCheck<w4)return}}catch(b){}try{let b=await B$();if(b){let q=b.tagName.startsWith("v")?b.tagName.slice(1):b.tagName;await T(_),await d($,JSON.stringify({lastCheck:Date.now(),latestVersion:q}))}}catch(b){}}async function e1(){if(process.env.CI||M)return null;let $=W$.version,b=a1(_,s1);try{if(await X(b)){let q=await D(b),Q=JSON.parse(q);if(Q.latestVersion&&A$(Q.latestVersion,$))return`
344
- ${Y.gray("Update available:")} ${Y.green(`v${Q.latestVersion}`)} ${Y.dim(`(current: v${$})`)}
345
- ${Y.gray("Run")} ${Y.cyan("bvm upgrade")} ${Y.gray("to update.")}`}}catch(q){}return null}class $6{commands={};helpEntries=[];name;versionStr;constructor($){this.name=$,this.versionStr=W$.version}command($,b,q={}){let Q=$.split(" ")[0],K={description:b,usage:`${this.name} ${$}`,action:async()=>{},aliases:q.aliases};if(this.commands[Q]=K,this.helpEntries.push(` ${$.padEnd(35)} ${b}`),q.aliases)q.aliases.forEach((Z)=>{this.commands[Z]=K});let J={action:(Z)=>{return K.action=Z,J},option:(Z,G)=>J};return J}async run(){try{r1().catch(()=>{})}catch(Z){}let{values:$,positionals:b}=O4({args:Bun.argv.slice(2),strict:!1,allowPositionals:!0,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},silent:{type:"boolean",short:"s"}}}),q=b[0],Q=!!($.silent||$.s),K=!!($.version||$.v||$.help||$.h);if(!q){if($.version||$.v)console.log(this.versionStr),process.exit(0);if($.help||$.h)this.showHelp(),process.exit(0);this.showHelp(),process.exit(1)}if($.help||$.h)this.showHelp(),process.exit(0);let J=this.commands[q];if(!J)console.error(Y.yellow(`Unknown command '${q}'`)),this.showHelp(),process.exit(0);try{if(await J.action(b.slice(1),$),!K&&!Q&&["ls","current","doctor","default"].includes(q)){let Z=await e1();if(Z)console.log(Z)}}catch(Z){if(!Z.reported)console.error(Y.red(`\u2716 ${Z.message}`));process.exit(1)}}showHelp(){console.log(`Bun Version Manager (bvm) v${this.versionStr}`),console.log(`Built with Bun \xB7 Runs with Bun \xB7 Tested on Bun
358
+ `,fish:`complete -c bvm -f -a "${b1.join(" ")}"
359
+ `};function a1($){let b=i1[$];if(!b)throw Error(`Unsupported shell '${$}'. Supported shells: ${Object.keys(i1).join(", ")}`);console.log(b)}f();N();C();import{join as s1}from"path";f();var r1="update-check.json",x4=86400000;async function e1(){if(process.env.CI||B)return;let $=s1(P,r1);try{if(await X($)){let b=await T($),q=JSON.parse(b);if(Date.now()-q.lastCheck<x4)return}}catch(b){}try{let b=await B$();if(b){let q=b.tagName.startsWith("v")?b.tagName.slice(1):b.tagName;await I(P),await m($,JSON.stringify({lastCheck:Date.now(),latestVersion:q}))}}catch(b){}}async function $6(){if(process.env.CI||B)return null;let $=W$.version,b=s1(P,r1);try{if(await X(b)){let q=await T(b),J=JSON.parse(q);if(J.latestVersion&&M$(J.latestVersion,$))return`
360
+ ${Y.gray("Update available:")} ${Y.green(`v${J.latestVersion}`)} ${Y.dim(`(current: v${$})`)}
361
+ ${Y.gray("Run")} ${Y.cyan("bvm upgrade")} ${Y.gray("to update.")}`}}catch(q){}return null}class b6{commands={};helpEntries=[];name;versionStr;constructor($){this.name=$,this.versionStr=W$.version}command($,b,q={}){let J=$.split(" ")[0],K={description:b,usage:`${this.name} ${$}`,action:async()=>{},aliases:q.aliases};if(this.commands[J]=K,this.helpEntries.push(` ${$.padEnd(35)} ${b}`),q.aliases)q.aliases.forEach((Z)=>{this.commands[Z]=K});let Q={action:(Z)=>{return K.action=Z,Q},option:(Z,G)=>Q};return Q}async run(){try{e1().catch(()=>{})}catch(Z){}let{values:$,positionals:b}=k4({args:Bun.argv.slice(2),strict:!1,allowPositionals:!0,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},silent:{type:"boolean",short:"s"}}}),q=b[0],J=!!($.silent||$.s),K=!!($.version||$.v||$.help||$.h);if(!q){if($.version||$.v)console.log(this.versionStr),process.exit(0);if($.help||$.h)this.showHelp(),process.exit(0);this.showHelp(),process.exit(1)}if($.help||$.h)this.showHelp(),process.exit(0);let Q=this.commands[q];if(!Q)console.error(Y.yellow(`Unknown command '${q}'`)),this.showHelp(),process.exit(0);try{if(await Q.action(b.slice(1),$),!K&&!J&&["ls","current","doctor","default"].includes(q)){let Z=await $6();if(Z)console.log(Z)}}catch(Z){if(!Z.reported)console.error(Y.red(`\u2716 ${Z.message}`));process.exit(1)}}showHelp(){console.log(`Bun Version Manager (bvm) v${this.versionStr}`),console.log(`Built with Bun \xB7 Runs with Bun \xB7 Tested on Bun
346
362
  `),console.log("Usage:"),console.log(` ${this.name} <command> [flags]
347
363
  `),console.log("Commands:"),console.log(this.helpEntries.join(`
348
364
  `)),console.log(`
349
365
  Global Flags:`),console.log(" --help, -h Show this help message"),console.log(" --version, -v Show version number"),console.log(`
350
- Examples:`),console.log(" bvm install 1.0.0"),console.log(" bvm use 1.0.0"),console.log(" bvm run 1.0.0 index.ts")}}async function k4(){let $=new $6("bvm");$.command("rehash","Regenerate shims for all installed binaries").action(async()=>{await J$()}),$.command("install [version]","Install a Bun version and set as current").option("--global, -g","Install as a global tool (not just default)").action(async(b,q)=>{await o$(b[0],{global:q.global||q.g})}),$.command("i [version]","Alias for install").action(async(b,q)=>{await o$(b[0],{global:q.global||q.g})}),$.command("ls","List installed Bun versions",{aliases:["list"]}).action(async()=>{await I1()}),$.command("ls-remote","List all available remote Bun versions").action(async()=>{await E1()}),$.command("use <version>","Switch the active Bun version immediately (all terminals)").action(async(b)=>{if(!b[0])throw Error("Version is required");await L$(b[0])}),$.command("shell <version>","Switch Bun version for the current shell session").action(async(b)=>{if(!b[0])throw Error("Version is required");await V1(b[0])}),$.command("default [version]","Display or set the global default Bun version").action(async(b)=>{await d1(b[0])}),$.command("current","Display the currently active Bun version").action(async()=>{await v1()}),$.command("uninstall <version>","Uninstall a Bun version").action(async(b)=>{if(!b[0])throw Error("Version is required");await _1(b[0])}),$.command("alias <name> <version>","Create an alias for a Bun version").action(async(b)=>{if(!b[0]||!b[1])throw Error("Name and version are required");await w$(b[0],b[1])}),$.command("unalias <name>","Remove an existing alias").action(async(b)=>{if(!b[0])throw Error("Alias name is required");await S1(b[0])}),$.command("run <version> [...args]","Run a command with a specific Bun version").action(async(b)=>{let q=b[0];if(!q)throw Error("Version is required");let Q=process.argv.indexOf("run"),K=Q!==-1?process.argv.slice(Q+2):[];await P1(q,K)}),$.command("exec <version> <cmd> [...args]","Execute a command with a specific Bun version's environment").action(async(b)=>{let q=b[0],Q=b[1];if(!q||!Q)throw Error("Version and command are required");let K=process.argv.indexOf("exec"),J=K!==-1?process.argv.slice(K+3):[];await u1(q,Q,J)}),$.command("which [version]","Display path to installed bun version").action(async(b)=>{await g1(b[0])}),$.command("deactivate","Undo effects of bvm on current shell").action(async()=>{await m1()}),$.command("version <spec>","Resolve the given description to a single local version").action(async(b)=>{if(!b[0])throw Error("Version specifier is required");await g$(b[0])}),$.command("cache <action>","Manage bvm cache").action(async(b)=>{if(!b[0])throw Error("Action is required");await h1(b[0])}),$.command("setup","Configure shell environment automatically").option("--silent, -s","Suppress output").action(async(b,q)=>{await z$(!(q.silent||q.s))}),$.command("upgrade","Upgrade bvm to the latest version",{aliases:["self-update"]}).action(async()=>{await l1()}),$.command("config <subcommand>","Manage BVM configuration (registry)").action(async(b)=>{await n1(b)}),$.command("doctor","Show diagnostics for Bun/BVM setup").action(async()=>{await t1()}),$.command("completion <shell>","Generate shell completion script (bash|zsh|fish)").action(async(b)=>{if(!b[0])throw Error("Shell name is required");o1(b[0])}),await $.run(),process.exit(0)}k4().catch(($)=>{console.error(Y.red(`
366
+ Examples:`),console.log(" bvm install 1.0.0"),console.log(" bvm use 1.0.0"),console.log(" bvm run 1.0.0 index.ts")}}async function C4(){let $=new b6("bvm");$.command("rehash","Regenerate shims for all installed binaries").action(async()=>{await Q$()}),$.command("install [version]","Install a Bun version and set as current").option("--global, -g","Install as a global tool (not just default)").action(async(b,q)=>{await a$(b[0],{global:q.global||q.g})}),$.command("i [version]","Alias for install").action(async(b,q)=>{await a$(b[0],{global:q.global||q.g})}),$.command("ls","List installed Bun versions",{aliases:["list"]}).action(async()=>{await E1()}),$.command("ls-remote","List all available remote Bun versions").action(async()=>{await v1()}),$.command("use <version>","Switch the active Bun version immediately (all terminals)").action(async(b)=>{if(!b[0])throw Error("Version is required");await L$(b[0])}),$.command("shell <version>","Switch Bun version for the current shell session").action(async(b)=>{if(!b[0])throw Error("Version is required");await d1(b[0])}),$.command("default [version]","Display or set the global default Bun version").action(async(b)=>{await m1(b[0])}),$.command("current","Display the currently active Bun version").action(async()=>{await S1()}),$.command("uninstall <version>","Uninstall a Bun version").action(async(b)=>{if(!b[0])throw Error("Version is required");await _1(b[0])}),$.command("alias <name> <version>","Create an alias for a Bun version").action(async(b)=>{if(!b[0]||!b[1])throw Error("Name and version are required");await w$(b[0],b[1])}),$.command("unalias <name>","Remove an existing alias").action(async(b)=>{if(!b[0])throw Error("Alias name is required");await P1(b[0])}),$.command("run <version> [...args]","Run a command with a specific Bun version").action(async(b)=>{let q=b[0];if(!q)throw Error("Version is required");let J=process.argv.indexOf("run"),K=J!==-1?process.argv.slice(J+2):[];await u1(q,K)}),$.command("exec <version> <cmd> [...args]","Execute a command with a specific Bun version's environment").action(async(b)=>{let q=b[0],J=b[1];if(!q||!J)throw Error("Version and command are required");let K=process.argv.indexOf("exec"),Q=K!==-1?process.argv.slice(K+3):[];await g1(q,J,Q)}),$.command("which [version]","Display path to installed bun version").action(async(b)=>{await V1(b[0])}),$.command("deactivate","Undo effects of bvm on current shell").action(async()=>{await h1()}),$.command("version <spec>","Resolve the given description to a single local version").action(async(b)=>{if(!b[0])throw Error("Version specifier is required");await h$(b[0])}),$.command("cache <action>","Manage bvm cache").action(async(b)=>{if(!b[0])throw Error("Action is required");await c1(b[0])}),$.command("setup","Configure shell environment automatically").option("--silent, -s","Suppress output").action(async(b,q)=>{await z$(!(q.silent||q.s))}),$.command("upgrade","Upgrade bvm to the latest version",{aliases:["self-update"]}).action(async()=>{await t1()}),$.command("config <subcommand>","Manage BVM configuration (registry)").action(async(b)=>{await o1(b)}),$.command("doctor","Show diagnostics for Bun/BVM setup").action(async()=>{await n1()}),$.command("completion <shell>","Generate shell completion script (bash|zsh|fish)").action(async(b)=>{if(!b[0])throw Error("Shell name is required");a1(b[0])}),await $.run(),process.exit(0)}C4().catch(($)=>{console.error(Y.red(`
351
367
  [FATAL ERROR] Unexpected Crash:`)),console.error($),process.exit(1)});
package/install.ps1 CHANGED
@@ -39,7 +39,7 @@ function Detect-NetworkZone {
39
39
  $BVM_REGION = Detect-NetworkZone
40
40
  $REGISTRY = if ($BVM_REGION -eq "cn") { "registry.npmmirror.com" } else { "registry.npmjs.org" }
41
41
 
42
- $DEFAULT_BVM_VER = "v1.1.35"
42
+ $DEFAULT_BVM_VER = "v1.1.36"
43
43
  $BVM_VER = if ($env:BVM_INSTALL_VERSION) { $env:BVM_INSTALL_VERSION } else { "" }
44
44
  if (-not $BVM_VER) {
45
45
  try {
@@ -97,6 +97,7 @@ if ($SYSTEM_BUN_BIN) {
97
97
  $SYS_BIN_DIR = Join-Path $SYS_VER_DIR "bin"
98
98
  if (-not (Test-Path $SYS_BIN_DIR)) { New-Item -ItemType Directory -Path $SYS_BIN_DIR -Force | Out-Null }
99
99
  Copy-Item $SYSTEM_BUN_BIN (Join-Path $SYS_BIN_DIR "bun.exe") -Force
100
+ Copy-Item $SYSTEM_BUN_BIN (Join-Path $SYS_BIN_DIR "bunx.exe") -Force
100
101
 
101
102
  # Smoke Test
102
103
  $BvmIndex = Join-Path $BVM_SRC_DIR "index.js"
@@ -129,6 +130,7 @@ if ($USE_SYSTEM_AS_RUNTIME) {
129
130
  $BIN_DEST = Join-Path $TARGET_DIR "bin"
130
131
  if (-not (Test-Path $BIN_DEST)) { New-Item -ItemType Directory -Path $BIN_DEST -Force | Out-Null }
131
132
  Move-Item -Path $FoundBun.FullName -Destination (Join-Path $BIN_DEST "bun.exe") -Force
133
+ Copy-Item (Join-Path $BIN_DEST "bun.exe") (Join-Path $BIN_DEST "bunx.exe") -Force
132
134
  Remove-Item $TMP -Force
133
135
  Remove-Item $EXT -Recurse -Force
134
136
  }
@@ -163,7 +165,7 @@ set "BVM_DIR=$WinBvmDir"
163
165
  set "BUN_INSTALL=%BVM_DIR%\current"
164
166
 
165
167
  if not exist ".bvmrc" (
166
- "%BVM_DIR%\runtime\current\bin\bun.exe" %*
168
+ "%BVM_DIR%\runtime\current\bin\%~n0.exe" %*
167
169
  exit /b %errorlevel%
168
170
  )
169
171
 
package/install.sh CHANGED
@@ -3,7 +3,7 @@
3
3
  set -e
4
4
 
5
5
  # --- Configuration ---
6
- DEFAULT_BVM_VERSION="v1.1.35" # Fallback
6
+ DEFAULT_BVM_VERSION="v1.1.36" # Fallback
7
7
  FALLBACK_BUN_VERSION="1.3.6"
8
8
  BVM_SRC_VERSION="${BVM_INSTALL_VERSION}" # If empty, will resolve dynamically
9
9
 
@@ -153,6 +153,7 @@ if [ -n "$SYSTEM_BUN_BIN" ]; then
153
153
  cp "$SYSTEM_BUN_BIN" "${SYS_VER_DIR}/bin/bun"
154
154
  fi
155
155
  chmod +x "${SYS_VER_DIR}/bin/bun"
156
+ ln -sf "./bun" "${SYS_VER_DIR}/bin/bunx"
156
157
 
157
158
  # Smoke Test
158
159
  if "${SYS_VER_DIR}/bin/bun" "${BVM_SRC_DIR}/index.js" --version >/dev/null 2>&1; then
@@ -206,6 +207,7 @@ else
206
207
  mkdir -p "${TARGET_RUNTIME_DIR}/bin"
207
208
  mv "$(find "$TEMP_DIR_BUN" -type f -name "bun" | head -n 1)" "${TARGET_RUNTIME_DIR}/bin/bun"
208
209
  chmod +x "${TARGET_RUNTIME_DIR}/bin/bun"
210
+ ln -sf "./bun" "${TARGET_RUNTIME_DIR}/bin/bunx"
209
211
  rm -rf "$TEMP_DIR_BUN"
210
212
  fi
211
213
  fi
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bvm-core",
3
- "version": "1.1.35",
4
- "description": "The native version manager for Bun. Cross-platform, shell-agnostic, and zero-dependency.",
3
+ "version": "1.1.36",
4
+ "description": "Bun Version Manager (BVM) - Native, fast, and cross-platform.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "bvm": "bin/bvm-npm.js"
@@ -77,10 +77,10 @@
77
77
  "typescript": "^5"
78
78
  },
79
79
  "bvm_fingerprints": {
80
- "cli": "b9cc047cc5f8b0f79becbedce8ea9ef8",
81
- "shim_win": "413506e6934869b9cbe832ba9cefaf2b",
80
+ "cli": "afc3ebb88789e98b6bee9795054895e3",
81
+ "shim_win": "668c9132a42fe8c71afa61b82ccba3fe",
82
82
  "shim_unix": "8aa89a0324b52c9c81b96c0c03afe36c",
83
- "install_sh": "e27f903105154a8b5513fdb8146de134",
84
- "install_ps1": "951a53850905e567b4a1dd3f6ea025e3"
83
+ "install_sh": "26a94b75b38b4aeed3c30c9250660ade",
84
+ "install_ps1": "17cab779ac8d079a5527791153bd5002"
85
85
  }
86
86
  }