bvm-core 1.1.18 → 1.1.19

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/bin/bvm-npm.js CHANGED
File without changes
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var t1=Object.create;var{getPrototypeOf:n1,defineProperty:B$,getOwnPropertyNames:o1}=Object;var i1=Object.prototype.hasOwnProperty;var U$=($,q,Q)=>{Q=$!=null?t1(n1($)):{};let J=q||!$||!$.__esModule?B$(Q,"default",{value:$,enumerable:!0}):Q;for(let Y of o1($))if(!i1.call(J,Y))B$(J,Y,{get:()=>$[Y],enumerable:!0});return J};var i$=($,q)=>{for(var Q in q)B$($,Q,{get:q[Q],enumerable:!0,configurable:!0,set:(J)=>q[Q]=()=>J})};var y$=($,q)=>()=>($&&(q=$($=0)),q);var O$=import.meta.require;var s$={};i$(s$,{getBvmDir:()=>a$,getBunAssetName:()=>f$,USER_AGENT:()=>X$,TEST_REMOTE_VERSIONS:()=>Z$,REPO_FOR_BVM_CLI:()=>$6,OS_PLATFORM:()=>B,IS_TEST_MODE:()=>D,EXECUTABLE_NAME:()=>j,CPU_ARCH:()=>z$,BVM_VERSIONS_DIR:()=>L,BVM_SRC_DIR:()=>r1,BVM_SHIMS_DIR:()=>S,BVM_FINGERPRINTS_FILE:()=>M$,BVM_DIR:()=>O,BVM_CURRENT_DIR:()=>b$,BVM_COMPONENTS:()=>J6,BVM_CDN_ROOT:()=>Q6,BVM_CACHE_DIR:()=>_,BVM_BIN_DIR:()=>M,BVM_ALIAS_DIR:()=>x,BUN_GITHUB_RELEASES_API:()=>e1,ASSET_NAME_FOR_BVM:()=>q6});import{homedir as s1}from"os";import{join as o}from"path";function a$(){let $=process.env.HOME||s1();return o($,".bvm")}function f$($){return`bun-${B==="win32"?"windows":B}-${z$==="arm64"?"aarch64":"x64"}.zip`}var B,z$,D,Z$,O,r1,L,M,S,b$,x,_,M$,j,e1="https://api.github.com/repos/oven-sh/bun/releases",$6="EricLLLLLL/bvm",q6,X$="bvm (Bun Version Manager)",Q6,J6;var F=y$(()=>{B=process.platform,z$=process.arch,D=process.env.BVM_TEST_MODE==="true",Z$=["v1.3.4","v1.2.23","v1.0.0","bun-v1.4.0-canary"];O=a$(),r1=o(O,"src"),L=o(O,"versions"),M=o(O,"bin"),S=o(O,"shims"),b$=o(O,"current"),x=o(O,"aliases"),_=o(O,"cache"),M$=o(O,"fingerprints.json"),j=B==="win32"?"bun.exe":"bun",q6=B==="win32"?"bvm.exe":"bvm",Q6=process.env.BVM_CDN_URL||"https://cdn.jsdelivr.net/gh/EricLLLLLL/bvm",J6=[{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 m($){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 r$($){let q=m($);return q?q.replace(/^v/,""):null}function J$($){if(!$)return null;let q=$.replace(/^v/,""),J=q.split(/[-+]/)[0].split(".").map(Number);if(J.length===0||J.some((K)=>isNaN(K)))return null;let Y=q.includes("-")?q.split("-")[1].split("+")[0]:void 0;return{major:J[0],minor:J[1],patch:J[2],pre:Y}}function T$($,q){if(!$||!q)return 0;if($.major!==q.major)return $.major-q.major;if($.minor!==q.minor)return $.minor-q.minor;if($.patch!==q.patch)return $.patch-q.patch;if($.pre&&!q.pre)return-1;if(!$.pre&&q.pre)return 1;if($.pre&&q.pre)return $.pre.localeCompare(q.pre);return 0}function e$($,q){let Q=J$($),J=J$(q);return T$(Q,J)}function K$($,q){return e$(q,$)}function k$($,q){return e$($,q)>0}function $1($,q){if(q==="*"||q===""||q==="latest")return!0;let Q=J$($);if(!Q)return!1;let J=q;if(q.startsWith("v"))J=q.substring(1);if(r$($)===r$(q))return!0;let Y=J.split(".");if(Y.length===1){let K=Number(Y[0]);if(Q.major===K)return!0}else if(Y.length===2){let K=Number(Y[0]),b=Number(Y[1]);if(Q.major===K&&Q.minor===b)return!0}if(q.startsWith("~")){let K=J$(q.substring(1));if(!K)return!1;let b=K.patch??0;return Q.major===K.major&&Q.minor===K.minor&&Q.patch>=b}if(q.startsWith("^")){let K=J$(q.substring(1));if(!K)return!1;let b=K.patch??0,X=K.minor??0;if(K.major===0){if(Q.major!==0)return!1;if(Q.minor!==X)return!1;return Q.patch>=b}if(Q.major!==K.major)return!1;if(Q.minor<X)return!1;if(Q.minor===X&&Q.patch<b)return!1;return!0}return!1}import{readdir as Y6,mkdir as Z6,stat as b6,symlink as X6,unlink as q1,rm as Q1,readlink as G6}from"fs/promises";import{join as C$,dirname as H6,basename as W6}from"path";async function N($){await Z6($,{recursive:!0})}async function G($){try{return await b6($),!0}catch(q){if(q.code==="ENOENT")return!1;throw q}}async function J1($,q){try{await q1(q)}catch(J){try{await Q1(q,{recursive:!0,force:!0})}catch(Y){}}let Q=process.platform==="win32"?"junction":"dir";await X6($,q,Q)}async function K1($){try{return await G6($)}catch(q){if(q.code==="ENOENT"||q.code==="EINVAL")return null;throw q}}async function G$($){await Q1($,{recursive:!0,force:!0})}async function p($){try{return await Y6($)}catch(q){if(q.code==="ENOENT")return[];throw q}}async function f($){return await Bun.file($).text()}async function V($,q){await Bun.write($,q)}async function L$($,q,Q={}){let{backup:J=!0}=Q,Y=H6($);await N(Y);let K=`${$}.tmp-${Date.now()}`,b=`${$}.bak`;try{if(await V(K,q),J&&await G($))try{let{rename:H,unlink:z}=await import("fs/promises");if(await G(b))await z(b).catch(()=>{});await H($,b)}catch(H){}let{rename:X}=await import("fs/promises");try{await X(K,$)}catch(H){await Bun.write($,q),await q1(K).catch(()=>{})}}catch(X){let{unlink:H}=await import("fs/promises");throw await H(K).catch(()=>{}),X}}function U($){let q=$.trim();if(q.startsWith("bun-v"))q=q.substring(4);if(!q.startsWith("v")&&/^\d/.test(q))q=`v${q}`;return q}async function P(){return await N(L),(await p(L)).filter((q)=>m(U(q))).sort(K$)}async function l(){if(process.env.BVM_ACTIVE_VERSION)return{version:U(process.env.BVM_ACTIVE_VERSION),source:"env"};let $=C$(process.cwd(),".bvmrc");if(await G($)){let b=(await f($)).trim();return{version:U(b),source:".bvmrc"}}let{getBvmDir:q}=await Promise.resolve().then(() => (F(),s$)),Q=q(),J=C$(Q,"current"),Y=C$(Q,"aliases");if(await G(J)){let{realpath:b}=await import("fs/promises");try{let X=await b(J);return{version:U(W6(X)),source:"current"}}catch(X){}}let K=C$(Y,"default");if(await G(K)){let b=(await f(K)).trim();return{version:U(b),source:"default"}}return{version:null,source:null}}function r($,q){if(!$||q.length===0)return null;let Q=U($);if(q.includes(Q))return Q;if($.toLowerCase()==="latest")return q[0];if(/^\d+\.\d+\.\d+$/.test($.replace(/^v/,"")))return null;if(!/^[v\d]/.test($))return null;let Y=$.startsWith("v")?`~${$.substring(1)}`:`~${$}`,K=q.filter((b)=>$1(b,Y));if(K.length>0)return K.sort(K$)[0];return null}var w=y$(()=>{F()});class R${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(`${Z.cyan(">")} ${this.text}
4
- `);return}this.timer=setInterval(()=>{process.stdout.write(`\r\x1B[K${Z.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(`${Z.green(" \u2713")} ${$||this.text}`)}fail($){this.stop(),console.log(`${Z.red(" \u2716")} ${$||this.text}`)}info($){this.stop(),console.log(`${Z.blue(" \u2139")} ${$||this.text}`)}update($){if(this.text=$,this.isWindows)console.log(Z.dim(` ... ${this.text}`))}}class D${total;current=0;width=20;constructor($){this.total=$}start(){process.stdout.write("\x1B[?25l"),this.render()}update($,q){this.current=$,this.render(q)}stop(){process.stdout.write(`\x1B[?25h
5
- `)}render($){let q=Math.min(1,this.current/this.total),Q=Math.round(this.width*q),J=this.width-Q,Y=process.platform==="win32",K=Y?"=":"\u2588",b=Y?"-":"\u2591",X=Z.green(K.repeat(Q))+Z.gray(b.repeat(J)),H=(q*100).toFixed(0).padStart(3," "),z=(this.current/1048576).toFixed(1),C=(this.total/1048576).toFixed(1),W=$?` ${$.speed}KB/s`:"";process.stdout.write(`\r\x1B[2K ${X} ${H}% | ${z}/${C}MB${W}`)}}var U6,y6=($)=>$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=($,q,Q=$)=>(J)=>U6?$+J.replace(new RegExp(y6(q),"g"),Q)+q:J,Z;var k=y$(()=>{U6=!process.env.NO_COLOR,Z={red:i("\x1B[1;31m","\x1B[39m"),green:i("\x1B[1;32m","\x1B[39m"),yellow:i("\x1B[1;33m","\x1B[39m"),blue:i("\x1B[1;34m","\x1B[39m"),magenta:i("\x1B[1;35m","\x1B[39m"),cyan:i("\x1B[1;36m","\x1B[39m"),gray:i("\x1B[90m","\x1B[39m"),bold:i("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:i("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m")}});async function y($,q,Q){if(process.platform==="win32"){console.log(Z.cyan(`> ${$}`));let K={start:(b)=>{if(b)console.log(Z.cyan(`> ${b}`))},stop:()=>{},succeed:(b)=>console.log(Z.green(` \u2713 ${b}`)),fail:(b)=>console.log(Z.red(` \u2716 ${b}`)),info:(b)=>console.log(Z.cyan(` \u2139 ${b}`)),update:(b)=>console.log(Z.dim(` ... ${b}`)),isSpinning:!1};try{return await q(K)}catch(b){let X=y1(b,Q?.failMessage);if(console.log(Z.red(` \u2716 ${X}`)),process.env.BVM_DEBUG,console.log(Z.dim(` Details: ${b.message}`)),b.code)console.log(Z.dim(` Code: ${b.code}`));throw b.reported=!0,b}}let Y=new R$($);Y.start();try{let K=await q(Y);return Y.stop(),K}catch(K){let b=y1(K,Q?.failMessage);throw Y.fail(Z.red(b)),K.reported=!0,K}}function y1($,q){let Q=$ instanceof Error?$.message:String($);if(!q)return Q;if(typeof q==="function")return q($);return`${q}: ${Q}`}var R=y$(()=>{k()});var O1={};i$(O1,{resolveLocalVersion:()=>g,displayVersion:()=>d$});import{join as P6}from"path";async function g($){if($==="current"){let{version:Y}=await l();return Y}if($==="latest"){let Y=await P();if(Y.length>0)return Y[0];return null}let q=P6(x,$);if(await G(q))try{let Y=(await f(q)).trim();return U(Y)}catch{return null}let Q=U($),J=await P();return r($,J)}async function d$($){await y(`Resolving version '${$}'...`,async()=>{let q=await g($);if(q)console.log(q);else throw Error("N/A")},{failMessage:`Failed to resolve version '${$}'`})}var q$=y$(()=>{F();w();R()});import{parseArgs as Y4}from"util";var Y$={name:"bvm-core",version:"1.1.18",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"},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/release.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();w();import{join as n,basename as g6,dirname as m6}from"path";F();w();k();import{join as L6}from"path";function Y1($,q){if($==="darwin"){if(q==="arm64")return"@oven/bun-darwin-aarch64";if(q==="x64")return"@oven/bun-darwin-x64"}if($==="linux"){if(q==="arm64")return"@oven/bun-linux-aarch64";if(q==="x64")return"@oven/bun-linux-x64"}if($==="win32"){if(q==="x64")return"@oven/bun-windows-x64"}return null}function Z1($,q,Q){let J=Q;if(!J.endsWith("/"))J+="/";let Y=$.startsWith("@"),K=$;if(Y){let X=$.split("/");if(X.length===2)K=X[1]}let b=`${K}-${q}.tgz`;return`${J}${$}/-/${b}`}k();async function d($,q={}){let{cwd:Q,env:J,prependPath:Y,stdin:K="inherit",stdout:b="inherit",stderr:X="inherit"}=q,H={...process.env,...J};if(Y){let W=H.PATH||"",A=process.platform==="win32"?";":":";H.PATH=`${Y}${A}${W}`}let C=await Bun.spawn({cmd:$,cwd:Q,env:H,stdin:K,stdout:b,stderr:X}).exited;if((C??0)!==0)throw Error(`${Z.red("Command failed")}: ${$.join(" ")} (code ${C})`);return C??0}async function a($,q={}){let{timeout:Q=5000,...J}=q,Y=new AbortController,K=setTimeout(()=>Y.abort(),Q);try{let b=await fetch($,{...J,signal:Y.signal});return clearTimeout(K),b}catch(b){if(clearTimeout(K),b.name==="AbortError")throw Error(`Request to ${$} timed out after ${Q}ms`);throw b}}async function O6($,q=2000){if($.length===0)throw Error("No URLs to race");if($.length===1)return $[0];return new Promise((Q,J)=>{let Y=0,K=!1;$.forEach((b)=>{a(b,{method:"HEAD",timeout:q}).then((X)=>{if(X.ok&&!K)K=!0,Q(b);else if(!K){if(Y++,Y===$.length)J(Error("All requests failed"))}}).catch(()=>{if(!K){if(Y++,Y===$.length)J(Error("All requests failed"))}})})})}async function z6(){try{let $=await a("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 I$=null,w$={NPM:"https://registry.npmjs.org",TAOBAO:"https://registry.npmmirror.com",TENCENT:"https://mirrors.cloud.tencent.com/npm/"};async function e(){if(I$)return I$;let $=await z6(),q=[];if($==="CN")q=[w$.TAOBAO,w$.TENCENT,w$.NPM];else q=[w$.NPM,w$.TAOBAO];try{let Q=await O6(q,2000);return I$=Q,Q}catch(Q){return q[0]}}w();var w6="bun-versions.json",x6=3600000;async function k6(){if(D)return[...Z$];let $=L6(_,w6);try{if(await G($)){let Y=await f($),K=JSON.parse(Y);if(Date.now()-K.timestamp<x6&&Array.isArray(K.versions))return K.versions}}catch(Y){}let q=await e(),Q=[q];if(q!=="https://registry.npmjs.org")Q.push("https://registry.npmjs.org");let J=null;for(let Y of Q){let K=`${Y.replace(/\/$/,"")}/bun`;try{let b=await a(K,{headers:{"User-Agent":X$,Accept:"application/vnd.npm.install-v1+json"},timeout:1e4});if(!b.ok)throw Error(`Status ${b.status}`);let X=await b.json();if(!X.versions)throw Error("Invalid response (no versions)");let H=Object.keys(X.versions);try{await N(_),await V($,JSON.stringify({timestamp:Date.now(),versions:H}))}catch(z){}return H}catch(b){J=b}}throw J||Error("Failed to fetch versions from any registry.")}async function C6(){if(D)return[...Z$];return new Promise(($,q)=>{let Q=[];try{let J=Bun.spawn(["git","ls-remote","--tags","https://github.com/oven-sh/bun.git"],{stdout:"pipe",stderr:"pipe"}),Y=setTimeout(()=>{J.kill(),q(Error("Git operation timed out"))},1e4);new Response(J.stdout).text().then((b)=>{clearTimeout(Y);let X=b.split(`
6
- `);for(let H of X){let z=H.match(/refs\/tags\/bun-v?(\d+\.\d+\.\d+.*)$/);if(z)Q.push(z[1])}$(Q)}).catch((b)=>{clearTimeout(Y),q(b)})}catch(J){q(Error(`Failed to run git: ${J.message}`))}})}async function b1(){if(D)return[...Z$];try{let q=(await k6()).filter((Q)=>m(Q)).map((Q)=>({v:Q,parsed:J$(Q)}));return q.sort((Q,J)=>T$(J.parsed,Q.parsed)),q.map((Q)=>Q.v)}catch($){try{let q=await C6();if(q.length>0)return Array.from(new Set(q.filter((J)=>m(J)))).sort(K$);throw Error("No versions found via Git")}catch(q){throw Error(`Failed to fetch versions. NPM: ${$.message}. Git: ${q.message}`)}}}async function X1($){if(D)return Z$.includes($)||$==="latest";let q=await e(),Q=$.replace(/^v/,""),J=`${q}/bun/${Q}`,Y=B==="win32"?"curl.exe":"curl",K=async()=>{try{return await d([Y,"-I","-f","-m","5","-s",J],{stdout:"ignore",stderr:"ignore"}),!0}catch(X){return!1}},b=new Promise((X)=>setTimeout(()=>X(!1),1e4));return Promise.race([K(),b])}async function G1(){if(D)return{latest:"1.1.20"};let q=`${await e()}/-/package/bun/dist-tags`;try{let Q=await a(q,{headers:{"User-Agent":X$},timeout:5000});if(Q.ok)return await Q.json()}catch(Q){}return{}}async function H1($){let q=U($);if(!m(q))return console.error(Z.red(`Invalid version provided to findBunDownloadUrl: ${$}`)),null;if(D)return{url:`https://example.com/${f$(q)}`,foundVersion:q};let Y=Y1(B==="win32"?"win32":B,z$==="arm64"?"arm64":"x64");if(!Y)throw Error(`Unsupported platform/arch for NPM download: ${B}-${z$}`);let K="";if(process.env.BVM_REGISTRY)K=process.env.BVM_REGISTRY;else if(process.env.BVM_DOWNLOAD_MIRROR)K=process.env.BVM_DOWNLOAD_MIRROR;else K=await e();let b=q.replace(/^v/,"");return{url:Z1(Y,b,K),foundVersion:q}}async function F$(){try{let q=(await e()).replace(/\/$/,""),Q=await a(`${q}/-/package/bvm-core/dist-tags`,{headers:{"User-Agent":X$},timeout:5000});if(!Q.ok)return null;let Y=(await Q.json()).latest;if(!Y)return null;let K=await a(`${q}/bvm-core/${Y}`,{headers:{"User-Agent":X$},timeout:5000});if(K.ok){let b=await K.json();return{version:Y,tarball:b.dist.tarball,integrity:b.dist.integrity,shasum:b.dist.shasum}}}catch($){}return null}k();F();import{spawn as F6}from"child_process";async function W1($,q){if($.endsWith(".zip"))if(B==="win32")await d(["powershell","-Command",`Expand-Archive -Path "${$}" -DestinationPath "${q}" -Force`],{stdout:"ignore",stderr:"inherit"});else await d(["unzip","-o","-q",$,"-d",q],{stdout:"ignore",stderr:"inherit"});else if($.endsWith(".tar.gz")||$.endsWith(".tgz"))await new Promise((Q,J)=>{let Y=F6("tar",["-xzf",$,"-C",q],{stdio:"inherit",shell:!1});Y.on("close",(K)=>{if(K===0)Q();else J(Error(`tar exited with code ${K}`))}),Y.on("error",(K)=>J(K))});else throw Error(`Unsupported archive format: ${$}`)}import{chmod as m$}from"fs/promises";w();F();k();import{join as T,dirname as R6,delimiter as D6}from"path";import{homedir as $$}from"os";import{chmod as x$}from"fs/promises";var E$=`#!/bin/bash
3
+ var i1=Object.create;var{getPrototypeOf:a1,defineProperty:B$,getOwnPropertyNames:s1}=Object;var r1=Object.prototype.hasOwnProperty;var U$=($,q,Q)=>{Q=$!=null?i1(a1($)):{};let J=q||!$||!$.__esModule?B$(Q,"default",{value:$,enumerable:!0}):Q;for(let Y of s1($))if(!r1.call(J,Y))B$(J,Y,{get:()=>$[Y],enumerable:!0});return J};var a$=($,q)=>{for(var Q in q)B$($,Q,{get:q[Q],enumerable:!0,configurable:!0,set:(J)=>q[Q]=()=>J})};var O$=($,q)=>()=>($&&(q=$($=0)),q);var y$=import.meta.require;var r$={};a$(r$,{getBvmDir:()=>s$,getBunAssetName:()=>T$,USER_AGENT:()=>X$,TEST_REMOTE_VERSIONS:()=>Z$,REPO_FOR_BVM_CLI:()=>Q6,OS_PLATFORM:()=>B,IS_TEST_MODE:()=>D,EXECUTABLE_NAME:()=>R,CPU_ARCH:()=>z$,BVM_VERSIONS_DIR:()=>w,BVM_SRC_DIR:()=>f$,BVM_SHIMS_DIR:()=>I,BVM_FINGERPRINTS_FILE:()=>M$,BVM_DIR:()=>z,BVM_CURRENT_DIR:()=>b$,BVM_COMPONENTS:()=>Y6,BVM_CDN_ROOT:()=>K6,BVM_CACHE_DIR:()=>_,BVM_BIN_DIR:()=>A,BVM_ALIAS_DIR:()=>C,BUN_GITHUB_RELEASES_API:()=>q6,ASSET_NAME_FOR_BVM:()=>J6});import{homedir as $6}from"os";import{join as i}from"path";function s$(){let $=process.env.HOME||$6();return i($,".bvm")}function T$($){return`bun-${B==="win32"?"windows":B}-${z$==="arm64"?"aarch64":"x64"}.zip`}var B,z$,D,Z$,z,f$,w,A,I,b$,C,_,M$,R,q6="https://api.github.com/repos/oven-sh/bun/releases",Q6="EricLLLLLL/bvm",J6,X$="bvm (Bun Version Manager)",K6,Y6;var N=O$(()=>{B=process.platform,z$=process.arch,D=process.env.BVM_TEST_MODE==="true",Z$=["v1.3.4","v1.2.23","v1.0.0","bun-v1.4.0-canary"];z=s$(),f$=i(z,"src"),w=i(z,"versions"),A=i(z,"bin"),I=i(z,"shims"),b$=i(z,"current"),C=i(z,"aliases"),_=i(z,"cache"),M$=i(z,"fingerprints.json"),R=B==="win32"?"bun.exe":"bun",J6=B==="win32"?"bvm.exe":"bvm",K6=process.env.BVM_CDN_URL||"https://cdn.jsdelivr.net/gh/EricLLLLLL/bvm",Y6=[{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 c($){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 e$($){let q=c($);return q?q.replace(/^v/,""):null}function J$($){if(!$)return null;let q=$.replace(/^v/,""),J=q.split(/[-+]/)[0].split(".").map(Number);if(J.length===0||J.some((K)=>isNaN(K)))return null;let Y=q.includes("-")?q.split("-")[1].split("+")[0]:void 0;return{major:J[0],minor:J[1],patch:J[2],pre:Y}}function D$($,q){if(!$||!q)return 0;if($.major!==q.major)return $.major-q.major;if($.minor!==q.minor)return $.minor-q.minor;if($.patch!==q.patch)return $.patch-q.patch;if($.pre&&!q.pre)return-1;if(!$.pre&&q.pre)return 1;if($.pre&&q.pre)return $.pre.localeCompare(q.pre);return 0}function $1($,q){let Q=J$($),J=J$(q);return D$(Q,J)}function K$($,q){return $1(q,$)}function C$($,q){return $1($,q)>0}function q1($,q){if(q==="*"||q===""||q==="latest")return!0;let Q=J$($);if(!Q)return!1;let J=q;if(q.startsWith("v"))J=q.substring(1);if(e$($)===e$(q))return!0;let Y=J.split(".");if(Y.length===1){let K=Number(Y[0]);if(Q.major===K)return!0}else if(Y.length===2){let K=Number(Y[0]),b=Number(Y[1]);if(Q.major===K&&Q.minor===b)return!0}if(q.startsWith("~")){let K=J$(q.substring(1));if(!K)return!1;let b=K.patch??0;return Q.major===K.major&&Q.minor===K.minor&&Q.patch>=b}if(q.startsWith("^")){let K=J$(q.substring(1));if(!K)return!1;let b=K.patch??0,X=K.minor??0;if(K.major===0){if(Q.major!==0)return!1;if(Q.minor!==X)return!1;return Q.patch>=b}if(Q.major!==K.major)return!1;if(Q.minor<X)return!1;if(Q.minor===X&&Q.patch<b)return!1;return!0}return!1}import{readdir as b6,mkdir as X6,stat as Q1,symlink as G6,unlink as J1,rm as K1,readlink as W6}from"fs/promises";import{join as k$,dirname as H6,basename as U6}from"path";async function M($){try{await X6($,{recursive:!0})}catch(q){if(q.code==="EEXIST")try{if((await Q1($)).isDirectory())return}catch{}throw q}}async function G($){try{return await Q1($),!0}catch(q){if(q.code==="ENOENT")return!1;throw q}}async function Y1($,q){try{await J1(q)}catch(J){try{await K1(q,{recursive:!0,force:!0})}catch(Y){}}let Q=process.platform==="win32"?"junction":"dir";await G6($,q,Q)}async function Z1($){try{return await W6($)}catch(q){if(q.code==="ENOENT"||q.code==="EINVAL")return null;throw q}}async function G$($){await K1($,{recursive:!0,force:!0})}async function l($){try{return await b6($)}catch(q){if(q.code==="ENOENT")return[];throw q}}async function f($){return await Bun.file($).text()}async function g($,q){await Bun.write($,q)}async function L$($,q,Q={}){let{backup:J=!0}=Q,Y=H6($);await M(Y);let K=`${$}.tmp-${Date.now()}`,b=`${$}.bak`;try{if(await g(K,q),J&&await G($))try{let{rename:W,unlink:y}=await import("fs/promises");if(await G(b))await y(b).catch(()=>{});await W($,b)}catch(W){}let{rename:X}=await import("fs/promises");try{await X(K,$)}catch(W){await Bun.write($,q),await J1(K).catch(()=>{})}}catch(X){let{unlink:W}=await import("fs/promises");throw await W(K).catch(()=>{}),X}}function U($){let q=$.trim();if(q.startsWith("bun-v"))q=q.substring(4);if(!q.startsWith("v")&&/^\d/.test(q))q=`v${q}`;return q}async function u(){return await M(w),(await l(w)).filter((q)=>c(U(q))).sort(K$)}async function t(){if(process.env.BVM_ACTIVE_VERSION)return{version:U(process.env.BVM_ACTIVE_VERSION),source:"env"};let $=k$(process.cwd(),".bvmrc");if(await G($)){let b=(await f($)).trim();return{version:U(b),source:".bvmrc"}}let{getBvmDir:q}=await Promise.resolve().then(() => (N(),r$)),Q=q(),J=k$(Q,"current"),Y=k$(Q,"aliases");if(await G(J)){let{realpath:b}=await import("fs/promises");try{let X=await b(J);return{version:U(U6(X)),source:"current"}}catch(X){}}let K=k$(Y,"default");if(await G(K)){let b=(await f(K)).trim();return{version:U(b),source:"default"}}return{version:null,source:null}}function e($,q){if(!$||q.length===0)return null;let Q=U($);if(q.includes(Q))return Q;if($.toLowerCase()==="latest")return q[0];if(/^\d+\.\d+\.\d+$/.test($.replace(/^v/,"")))return null;if(!/^[v\d]/.test($))return null;let Y=$.startsWith("v")?`~${$.substring(1)}`:`~${$}`,K=q.filter((b)=>q1(b,Y));if(K.length>0)return K.sort(K$)[0];return null}var x=O$(()=>{N()});class R${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(`${Z.cyan(">")} ${this.text}
4
+ `);return}this.timer=setInterval(()=>{process.stdout.write(`\r\x1B[K${Z.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(`${Z.green(" \u2713")} ${$||this.text}`)}fail($){this.stop(),console.log(`${Z.red(" \u2716")} ${$||this.text}`)}info($){this.stop(),console.log(`${Z.blue(" \u2139")} ${$||this.text}`)}update($){if(this.text=$,this.isWindows)console.log(Z.dim(` ... ${this.text}`))}}class I${total;current=0;width=20;constructor($){this.total=$}start(){process.stdout.write("\x1B[?25l"),this.render()}update($,q){this.current=$,this.render(q)}stop(){process.stdout.write(`\x1B[?25h
5
+ `)}render($){let q=Math.min(1,this.current/this.total),Q=Math.round(this.width*q),J=this.width-Q,Y=process.platform==="win32",K=Y?"=":"\u2588",b=Y?"-":"\u2591",X=Z.green(K.repeat(Q))+Z.gray(b.repeat(J)),W=(q*100).toFixed(0).padStart(3," "),y=(this.current/1048576).toFixed(1),F=(this.total/1048576).toFixed(1),H=$?` ${$.speed}KB/s`:"";process.stdout.write(`\r\x1B[2K ${X} ${W}% | ${y}/${F}MB${H}`)}}var O6,y6=($)=>$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=($,q,Q=$)=>(J)=>O6?$+J.replace(new RegExp(y6(q),"g"),Q)+q:J,Z;var k=O$(()=>{O6=!process.env.NO_COLOR,Z={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 O($,q,Q){if(process.platform==="win32"){console.log(Z.cyan(`> ${$}`));let K={start:(b)=>{if(b)console.log(Z.cyan(`> ${b}`))},stop:()=>{},succeed:(b)=>console.log(Z.green(` \u2713 ${b}`)),fail:(b)=>console.log(Z.red(` \u2716 ${b}`)),info:(b)=>console.log(Z.cyan(` \u2139 ${b}`)),update:(b)=>console.log(Z.dim(` ... ${b}`)),isSpinning:!1};try{return await q(K)}catch(b){let X=L1(b,Q?.failMessage);if(console.log(Z.red(` \u2716 ${X}`)),process.env.BVM_DEBUG,console.log(Z.dim(` Details: ${b.message}`)),b.code)console.log(Z.dim(` Code: ${b.code}`));throw b.reported=!0,b}}let Y=new R$($);Y.start();try{let K=await q(Y);return Y.stop(),K}catch(K){let b=L1(K,Q?.failMessage);throw Y.fail(Z.red(b)),K.reported=!0,K}}function L1($,q){let Q=$ instanceof Error?$.message:String($);if(!q)return Q;if(typeof q==="function")return q($);return`${q}: ${Q}`}var T=O$(()=>{k()});var w1={};a$(w1,{resolveLocalVersion:()=>h,displayVersion:()=>d$});import{join as v6}from"path";async function h($){if($==="current"){let{version:Y}=await t();return Y}if($==="latest"){let Y=await u();if(Y.length>0)return Y[0];return null}let q=v6(C,$);if(await G(q))try{let Y=(await f(q)).trim();return U(Y)}catch{return null}let Q=U($),J=await u();return e($,J)}async function d$($){await O(`Resolving version '${$}'...`,async()=>{let q=await h($);if(q)console.log(q);else throw Error("N/A")},{failMessage:`Failed to resolve version '${$}'`})}var q$=O$(()=>{N();x();T()});import{parseArgs as K4}from"util";var Y$={name:"bvm-core",version:"1.1.19",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"},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/release.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();x();import{join as o,basename as g6,dirname as d6}from"path";N();x();k();import{join as w6}from"path";function b1($,q){if($==="darwin"){if(q==="arm64")return"@oven/bun-darwin-aarch64";if(q==="x64")return"@oven/bun-darwin-x64"}if($==="linux"){if(q==="arm64")return"@oven/bun-linux-aarch64";if(q==="x64")return"@oven/bun-linux-x64"}if($==="win32"){if(q==="x64")return"@oven/bun-windows-x64"}return null}function X1($,q,Q){let J=Q;if(!J.endsWith("/"))J+="/";let Y=$.startsWith("@"),K=$;if(Y){let X=$.split("/");if(X.length===2)K=X[1]}let b=`${K}-${q}.tgz`;return`${J}${$}/-/${b}`}k();async function d($,q={}){let{cwd:Q,env:J,prependPath:Y,stdin:K="inherit",stdout:b="inherit",stderr:X="inherit"}=q,W={...process.env,...J};if(Y){let H=W.PATH||"",j=process.platform==="win32"?";":":";W.PATH=`${Y}${j}${H}`}let F=await Bun.spawn({cmd:$,cwd:Q,env:W,stdin:K,stdout:b,stderr:X}).exited;if((F??0)!==0)throw Error(`${Z.red("Command failed")}: ${$.join(" ")} (code ${F})`);return F??0}async function s($,q={}){let{timeout:Q=5000,...J}=q,Y=new AbortController,K=setTimeout(()=>Y.abort(),Q);try{let b=await fetch($,{...J,signal:Y.signal});return clearTimeout(K),b}catch(b){if(clearTimeout(K),b.name==="AbortError")throw Error(`Request to ${$} timed out after ${Q}ms`);throw b}}async function z6($,q=2000){if($.length===0)throw Error("No URLs to race");if($.length===1)return $[0];return new Promise((Q,J)=>{let Y=0,K=!1;$.forEach((b)=>{s(b,{method:"HEAD",timeout:q}).then((X)=>{if(X.ok&&!K)K=!0,Q(b);else if(!K){if(Y++,Y===$.length)J(Error("All requests failed"))}}).catch(()=>{if(!K){if(Y++,Y===$.length)J(Error("All requests failed"))}})})})}async function L6(){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 E$=null,w$={NPM:"https://registry.npmjs.org",TAOBAO:"https://registry.npmmirror.com",TENCENT:"https://mirrors.cloud.tencent.com/npm/"};async function $$(){if(E$)return E$;let $=await L6(),q=[];if($==="CN")q=[w$.TAOBAO,w$.TENCENT,w$.NPM];else q=[w$.NPM,w$.TAOBAO];try{let Q=await z6(q,2000);return E$=Q,Q}catch(Q){return q[0]}}x();var x6="bun-versions.json",C6=3600000;async function k6(){if(D)return[...Z$];let $=w6(_,x6);try{if(await G($)){let Y=await f($),K=JSON.parse(Y);if(Date.now()-K.timestamp<C6&&Array.isArray(K.versions))return K.versions}}catch(Y){}let q=await $$(),Q=[q];if(q!=="https://registry.npmjs.org")Q.push("https://registry.npmjs.org");let J=null;for(let Y of Q){let K=`${Y.replace(/\/$/,"")}/bun`;try{let b=await s(K,{headers:{"User-Agent":X$,Accept:"application/vnd.npm.install-v1+json"},timeout:1e4});if(!b.ok)throw Error(`Status ${b.status}`);let X=await b.json();if(!X.versions)throw Error("Invalid response (no versions)");let W=Object.keys(X.versions);try{await M(_),await g($,JSON.stringify({timestamp:Date.now(),versions:W}))}catch(y){}return W}catch(b){J=b}}throw J||Error("Failed to fetch versions from any registry.")}async function F6(){if(D)return[...Z$];return new Promise(($,q)=>{let Q=[];try{let J=Bun.spawn(["git","ls-remote","--tags","https://github.com/oven-sh/bun.git"],{stdout:"pipe",stderr:"pipe"}),Y=setTimeout(()=>{J.kill(),q(Error("Git operation timed out"))},1e4);new Response(J.stdout).text().then((b)=>{clearTimeout(Y);let X=b.split(`
6
+ `);for(let W of X){let y=W.match(/refs\/tags\/bun-v?(\d+\.\d+\.\d+.*)$/);if(y)Q.push(y[1])}$(Q)}).catch((b)=>{clearTimeout(Y),q(b)})}catch(J){q(Error(`Failed to run git: ${J.message}`))}})}async function G1(){if(D)return[...Z$];try{let q=(await k6()).filter((Q)=>c(Q)).map((Q)=>({v:Q,parsed:J$(Q)}));return q.sort((Q,J)=>D$(J.parsed,Q.parsed)),q.map((Q)=>Q.v)}catch($){try{let q=await F6();if(q.length>0)return Array.from(new Set(q.filter((J)=>c(J)))).sort(K$);throw Error("No versions found via Git")}catch(q){throw Error(`Failed to fetch versions. NPM: ${$.message}. Git: ${q.message}`)}}}async function W1($){if(D)return Z$.includes($)||$==="latest";let q=await $$(),Q=$.replace(/^v/,""),J=`${q}/bun/${Q}`,Y=B==="win32"?"curl.exe":"curl",K=async()=>{try{return await d([Y,"-I","-f","-m","5","-s",J],{stdout:"ignore",stderr:"ignore"}),!0}catch(X){return!1}},b=new Promise((X)=>setTimeout(()=>X(!1),1e4));return Promise.race([K(),b])}async function H1(){if(D)return{latest:"1.1.20"};let q=`${await $$()}/-/package/bun/dist-tags`;try{let Q=await s(q,{headers:{"User-Agent":X$},timeout:5000});if(Q.ok)return await Q.json()}catch(Q){}return{}}async function U1($){let q=U($);if(!c(q))return console.error(Z.red(`Invalid version provided to findBunDownloadUrl: ${$}`)),null;if(D)return{url:`https://example.com/${T$(q)}`,foundVersion:q};let Y=b1(B==="win32"?"win32":B,z$==="arm64"?"arm64":"x64");if(!Y)throw Error(`Unsupported platform/arch for NPM download: ${B}-${z$}`);let K="";if(process.env.BVM_REGISTRY)K=process.env.BVM_REGISTRY;else if(process.env.BVM_DOWNLOAD_MIRROR)K=process.env.BVM_DOWNLOAD_MIRROR;else K=await $$();let b=q.replace(/^v/,"");return{url:X1(Y,b,K),foundVersion:q}}async function F$(){try{let q=(await $$()).replace(/\/$/,""),Q=await s(`${q}/-/package/bvm-core/dist-tags`,{headers:{"User-Agent":X$},timeout:5000});if(!Q.ok)return null;let Y=(await Q.json()).latest;if(!Y)return null;let K=await s(`${q}/bvm-core/${Y}`,{headers:{"User-Agent":X$},timeout:5000});if(K.ok){let b=await K.json();return{version:Y,tarball:b.dist.tarball,integrity:b.dist.integrity,shasum:b.dist.shasum}}}catch($){}return null}k();N();import{spawn as N6}from"child_process";async function O1($,q){if($.endsWith(".zip"))if(B==="win32")await d(["powershell","-Command",`Expand-Archive -Path "${$}" -DestinationPath "${q}" -Force`],{stdout:"ignore",stderr:"inherit"});else await d(["unzip","-o","-q",$,"-d",q],{stdout:"ignore",stderr:"inherit"});else if($.endsWith(".tar.gz")||$.endsWith(".tgz"))await new Promise((Q,J)=>{let Y=N6("tar",["-xzf",$,"-C",q],{stdio:"inherit",shell:!1});Y.on("close",(K)=>{if(K===0)Q();else J(Error(`tar exited with code ${K}`))}),Y.on("error",(K)=>J(K))});else throw Error(`Unsupported archive format: ${$}`)}import{chmod as c$}from"fs/promises";x();N();k();import{join as L,dirname as y1}from"path";import{homedir as v}from"os";import{mkdir as z1}from"fs/promises";import{chmod as x$}from"fs/promises";var S$=`#!/bin/bash
7
7
 
8
8
  # bvm-init.sh: Initializes bvm default version on shell startup
9
9
 
@@ -14,7 +14,7 @@ fi
14
14
 
15
15
  # Try to switch to the 'default' version silently.
16
16
  "\${BVM_DIR}/bin/bvm" use default --silent >/dev/null 2>&1 || true
17
- `;var S$=`# bvm-init.fish: Initializes bvm default version on shell startup
17
+ `;var _$=`# bvm-init.fish: Initializes bvm default version on shell startup
18
18
 
19
19
  # Check if BVM_DIR is set
20
20
  if not set -q BVM_DIR
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  # Try to switch to the 'default' version silently.
25
25
  eval "$BVM_DIR/bin/bvm" use default --silent >/dev/null 2>&1 || true
26
- `;var _$=`#!/bin/bash
26
+ `;var v$=`#!/bin/bash
27
27
  # Shim managed by BVM (Bun Version Manager)
28
28
  # Optimized for performance via Bash-native syntax.
29
29
 
@@ -88,7 +88,7 @@ else
88
88
  echo "BVM Error: Command '$CMD_NAME' not found in Bun $VERSION." >&2
89
89
  exit 127
90
90
  fi
91
- `;var v$=`const path = require('path');
91
+ `;var P$=`const path = require('path');
92
92
  const { spawn } = require('child_process');
93
93
  const os = require('os');
94
94
  const fs = require('fs');
@@ -165,7 +165,7 @@ child.on('error', (err) => {
165
165
  console.error("BVM Error: Failed to start child process: " + err.message);
166
166
  process.exit(1);
167
167
  });
168
- `;var P$=`@echo off
168
+ `;var u$=`@echo off
169
169
  set "BVM_DIR=%USERPROFILE%\\.bvm"
170
170
 
171
171
  :: Fast-path: If no .bvmrc in current directory, run default directly
@@ -177,7 +177,7 @@ if not exist ".bvmrc" (
177
177
  :: Slow-path: Hand over to JS shim for version resolution
178
178
  "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\bin\\bvm-shim.js" "bun" %*
179
179
 
180
- `;var u$=`@echo off
180
+ `;var V$=`@echo off
181
181
  set "BVM_DIR=%USERPROFILE%\\.bvm"
182
182
 
183
183
  if not exist ".bvmrc" (
@@ -187,95 +187,118 @@ if not exist ".bvmrc" (
187
187
 
188
188
  "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\bin\\bvm-shim.js" "bunx" %*
189
189
 
190
- `;var V$=`@echo off
190
+ `;var g$=`@echo off
191
191
  set "BVM_DIR=%USERPROFILE%\\.bvm"
192
192
  "%BVM_DIR%\\runtime\\current\\bin\\bun.exe" "%BVM_DIR%\\src\\index.js" %*
193
- `;async function H$($=!0){if(await I6($),process.platform==="win32"){await E6($);return}if(!process.env.BVM_TEST_MODE)await U1();let q=process.env.SHELL||"",Q="",J="";if(q.includes("zsh"))J="zsh",Q=T($$(),".zshrc");else if(q.includes("bash"))if(J="bash",process.platform==="darwin")if(await G(T($$(),".bashrc")))Q=T($$(),".bashrc");else Q=T($$(),".bash_profile");else Q=T($$(),".bashrc");else if(q.includes("fish"))J="fish",Q=T($$(),".config","fish","config.fish");else{if($)console.log(Z.yellow(`Could not detect a supported shell (zsh, bash, fish). Please manually add ${M} to your PATH.`));return}let Y=T(M,"bvm-init.sh");await Bun.write(Y,E$),await x$(Y,493);let K=T(M,"bvm-init.fish");await Bun.write(K,S$),await x$(K,493);let b="";try{b=await Bun.file(Q).text()}catch(W){if(W.code==="ENOENT")await Bun.write(Q,""),b="";else throw W}let X="# >>> bvm initialize >>>",H="# <<< bvm initialize <<<",z=`${X}
193
+ `;async function W$($=!0){if(await R6($),process.platform==="win32"){await I6($);return}let q=process.env.SHELL||"",Q="",J="";if(q.includes("zsh"))J="zsh",Q=L(v(),".zshrc");else if(q.includes("bash"))if(J="bash",process.platform==="darwin")if(await G(L(v(),".bashrc")))Q=L(v(),".bashrc");else Q=L(v(),".bash_profile");else Q=L(v(),".bashrc");else if(q.includes("fish"))J="fish",Q=L(v(),".config","fish","config.fish");else if(await G(L(v(),".zshrc")))J="zsh",Q=L(v(),".zshrc");else if(await G(L(v(),".config","fish","config.fish")))J="fish",Q=L(v(),".config","fish","config.fish");else if(await G(L(v(),".bashrc")))J="bash",Q=L(v(),".bashrc");else if(await G(L(v(),".bash_profile")))J="bash",Q=L(v(),".bash_profile");else{if($)console.log(Z.yellow(`Could not detect a supported shell (zsh, bash, fish). Please manually add ${A} to your PATH.`));return}let Y=L(A,"bvm-init.sh");await Bun.write(Y,S$),await x$(Y,493);let K=L(A,"bvm-init.fish");await Bun.write(K,_$),await x$(K,493);let b="";try{b=await Bun.file(Q).text()}catch(H){if(H.code==="ENOENT")await Bun.write(Q,""),b="";else throw H}let X="# >>> bvm initialize >>>",W="# <<< bvm initialize <<<",y=`${X}
194
194
  # !! Contents within this block are managed by 'bvm setup' !!
195
- export BVM_DIR="${O}"
195
+ export BVM_DIR="${z}"
196
196
  export PATH="$BVM_DIR/shims:$BVM_DIR/bin:$PATH"
197
197
  # Reset current version to default for new terminal sessions
198
198
  [ -L "$BVM_DIR/current" ] && rm "$BVM_DIR/current"
199
- ${H}`,C=`# >>> bvm initialize >>>
199
+ ${W}`,F=`# >>> bvm initialize >>>
200
200
  # !! Contents within this block are managed by 'bvm setup' !!
201
- set -Ux BVM_DIR "${O}"
201
+ set -Ux BVM_DIR "${z}"
202
202
  fish_add_path "$BVM_DIR/shims"
203
203
  fish_add_path "$BVM_DIR/bin"
204
204
  # Reset current version to default
205
205
  if test -L "$BVM_DIR/current"
206
206
  rm "$BVM_DIR/current"
207
207
  end
208
- # <<< bvm initialize <<<`;if($)console.log(Z.cyan(`Configuring ${J} environment in ${Q}...`));try{let W=b,A=X.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=H.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),v=new RegExp(`${A}[\\s\\S]*?${h}`,"g");if(b.includes(X))W=b.replace(v,"").trim();let u=J==="fish"?C:z;if(W=(W?W+`
208
+ # <<< bvm initialize <<<`;if($)console.log(Z.cyan(`Configuring ${J} environment in ${Q}...`));try{let H=b,j=X.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),m=W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),P=new RegExp(`${j}[\\s\\S]*?${m}`,"g");if(b.includes(X))H=b.replace(P,"").trim();let V=J==="fish"?F:y;if(H=(H?H+`
209
209
 
210
- `:"")+u+`
211
- `,W!==b){if(await Bun.write(Q,W),$)console.log(Z.green(`\u2713 Successfully updated BVM configuration in ${Q}`)),console.log(Z.gray(" (Moved configuration to the end of file to ensure PATH precedence)"))}if($)console.log(Z.yellow(`Please restart your terminal or run "source ${Q}" to apply changes.`))}catch(W){console.error(Z.red(`Failed to write to ${Q}: ${W.message}`))}}async function I6($){if($)console.log(Z.cyan("Refreshing shims and wrappers..."));if(await N(M),await N(S),process.platform==="win32")await Bun.write(T(M,"bvm-shim.js"),v$),await Bun.write(T(M,"bvm.cmd"),V$),await Bun.write(T(S,"bun.cmd"),P$),await Bun.write(T(S,"bunx.cmd"),u$);else{let Q=T(M,"bvm-shim.sh");await Bun.write(Q,_$),await x$(Q,493);let J="";if(process.env.BVM_INSTALL_SOURCE==="npm")J=`#!/bin/bash
212
- export BVM_DIR="${O}"
210
+ `:"")+V+`
211
+ `,H!==b){if(await Bun.write(Q,H),$)console.log(Z.green(`\u2713 Successfully updated BVM configuration in ${Q}`)),console.log(Z.gray(" (Moved configuration to the end of file to ensure PATH precedence)"))}if($)console.log(Z.yellow(`Please restart your terminal or run "source ${Q}" to apply changes.`))}catch(H){console.error(Z.red(`Failed to write to ${Q}: ${H.message}`))}}async function R6($){if($)console.log(Z.cyan("Refreshing shims and wrappers..."));if(!$)console.log(`[DEBUG] BIN_DIR: ${A}`),console.log(`[DEBUG] SHIMS_DIR: ${I}`);if(await z1(A,{recursive:!0}),await z1(I,{recursive:!0}),process.platform==="win32")await Bun.write(L(A,"bvm-shim.js"),P$),await Bun.write(L(A,"bvm.cmd"),g$),await Bun.write(L(I,"bun.cmd"),u$),await Bun.write(L(I,"bunx.cmd"),V$);else{let Q=L(A,"bvm-shim.sh");await Bun.write(Q,v$),await x$(Q,493);let J="",Y=L(z,"runtime","current","bin","bun"),K=L(f$,"index.js");if(process.env.BVM_INSTALL_SOURCE==="npm")J=`#!/bin/bash
212
+ export BVM_DIR="${z}"
213
213
  export BVM_INSTALL_SOURCE="npm"
214
- # 1. Try internal runtime
215
- if [ -x "${O}/current/bin/bun" ]; then
216
- exec "${O}/current/bin/bun" "${O}/src/index.js" "$@"
217
- # 2. Try global/system bun (fallback)
214
+ if [ -f "${Y}" ]; then
215
+ exec "${Y}" "${K}" "$@"
218
216
  elif command -v bun >/dev/null 2>&1; then
219
- exec bun "${O}/src/index.js" "$@"
217
+ exec bun "${K}" "$@"
220
218
  else
221
- echo "Error: BVM requires Bun. Please install Bun or ensure it is in your PATH."
222
- exit 1
219
+ # Last resort: use the node entry point if it's an NPM install
220
+ # This is only possible if we are in the original NPM environment
221
+ # We'll leave this as a hint or a very specific fallback
222
+ echo "Error: BVM Bunker Runtime not found. Attempting emergency fallback..."
223
+ node -e "require('child_process').spawnSync('node', [require('path').join(process.env.BVM_DIR, '../', 'bin/bvm-npm.js'), ...process.argv.slice(1)], {stdio:'inherit'})" "$@"
223
224
  fi
224
225
  `;else J=`#!/bin/bash
225
- export BVM_DIR="${O}"
226
- exec "${O}/current/bin/bun" "${O}/src/index.js" "$@"`;let Y=T(M,"bvm");await Bun.write(Y,J),await x$(Y,493);for(let K of["bun","bunx"]){let b=`#!/bin/bash
227
- export BVM_DIR="${O}"
228
- exec "${O}/bin/bvm-shim.sh" "${K}" "$@"`,X=T(S,K);await Bun.write(X,b),await x$(X,493)}}}async function E6($=!0){await U1();let q="";try{q=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command","echo $PROFILE.CurrentUserAllHosts"],stdout:"pipe"}).stdout.toString().trim()}catch(Q){q=T($$(),"Documents","WindowsPowerShell","Microsoft.PowerShell_profile.ps1")}if(!q)return;await N(R6(q)),await S6(q,$)}async function S6($,q=!0){let Q=`
226
+ export BVM_DIR="${z}"
227
+ exec "${Y}" "${K}" "$@"`;let b=L(A,"bvm");await Bun.write(b,J),await x$(b,493);for(let X of["bun","bunx"]){let W=`#!/bin/bash
228
+ export BVM_DIR="${z}"
229
+ exec "${z}/bin/bvm-shim.sh" "${X}" "$@"`,y=L(I,X);await Bun.write(y,W),await x$(y,493)}}}async function I6($=!0){let q=L(A),Q=L(I);if($)console.log(Z.cyan("Configuring Windows environment variables (Registry)..."));let J=`
230
+ $targetDir = "${z}";
231
+ $shimsPath = "${Q}";
232
+ $binPath = "${q}";
233
+
234
+ # Set BVM_DIR
235
+ [Environment]::SetEnvironmentVariable("BVM_DIR", $targetDir, "User");
236
+
237
+ # Get current PATH
238
+ $oldPath = [Environment]::GetEnvironmentVariable("PATH", "User");
239
+ $paths = $oldPath -split ";"
240
+
241
+ $newPaths = @()
242
+ if ($paths -notcontains $shimsPath) { $newPaths += $shimsPath }
243
+ if ($paths -notcontains $binPath) { $newPaths += $binPath }
244
+
245
+ if ($newPaths.Count -gt 0) {
246
+ $newPathString = (($newPaths + $paths) -join ";").Trim(";")
247
+ [Environment]::SetEnvironmentVariable("PATH", $newPathString, "User");
248
+ return "SUCCESS"
249
+ }
250
+ return "ALREADY_SET"
251
+ `;try{let K=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command",J],stdout:"pipe",stderr:"pipe"}),b=K.stdout.toString().trim();if(K.success){if($)if(b==="SUCCESS")console.log(Z.green("\u2713 Successfully updated User PATH and BVM_DIR in Registry."));else console.log(Z.gray("\u2713 Environment variables are already up to date."))}else throw Error(K.stderr.toString())}catch(K){console.error(Z.red(`Failed to update environment variables: ${K.message}`))}let Y="";try{if(Y=Bun.spawnSync({cmd:["powershell","-NoProfile","-Command","echo $PROFILE.CurrentUserAllHosts"],stdout:"pipe"}).stdout.toString().trim(),Y)Bun.spawnSync({cmd:["powershell","-NoProfile","-Command",`if (!(Test-Path "${y1(Y)}")) { New-Item -ItemType Directory -Force -Path "${y1(Y)}" }`],stderr:"pipe"}),await E6(Y,!1)}catch(K){}if($)console.log(Z.yellow("Please restart your terminal or IDE to apply the new PATH."))}async function E6($,q=!0){let Q=`
229
252
  # BVM Configuration
230
- $env:BVM_DIR = "${O}"
253
+ $env:BVM_DIR = "${z}"
231
254
  $env:PATH = "$env:BVM_DIRshims;$env:BVM_DIR\bin;$env:PATH"
232
255
  # Auto-activate default version
233
256
  if (Test-Path "$env:BVM_DIR\bin\bvm.cmd") {
234
257
  & "$env:BVM_DIR\bin\bvm.cmd" use default --silent *>$null
235
258
  }
236
259
  `;try{let J="";if(await G($))J=await Bun.file($).text();else await Bun.write($,"");if(J.includes("$env:BVM_DIR")){if(q)console.log(Z.gray("\u2713 Configuration is already up to date."));return}if(q)console.log(Z.cyan(`Configuring PowerShell environment in ${$}...`));if(await Bun.write($,J+`\r
237
- ${Q}`),q)console.log(Z.green(`\u2713 Successfully configured BVM path in ${$}`)),console.log(Z.yellow("Please restart your terminal to apply changes."))}catch(J){console.error(Z.red(`Failed to write to ${$}: ${J.message}`))}}async function U1(){if(process.env.BVM_TEST_MODE)return;if(process.env.BVM_SUPPRESS_CONFLICT_WARNING==="true")return;let $=(process.env.PATH||"").split(D6),q=T($$(),".bun"),Q=T(q,"bin");for(let J of $){if(!J||J===M||J.includes(".bvm"))continue;let Y=T(J,j);if(await G(Y)){if(J.includes("node_modules"))continue;if(J===Q||J===q){console.log(),console.log(Z.yellow(" NOTE: OFFICIAL BUN DETECTED ")),console.log(Z.yellow(`Found existing official Bun installation at: ${Y}`)),console.log(Z.yellow("BVM will coexist by taking precedence in your PATH.")),console.log(Z.dim("No files will be deleted. BVM shims will handle version switching."));return}else{console.log(),console.log(Z.yellow(" NOTE: ANOTHER BUN DETECTED ")),console.log(Z.yellow(`Found another Bun installation at: ${Y}`)),console.log(Z.yellow("BVM will take precedence. To avoid confusion, you may manually manage the other version.")),console.log();return}}}}w();import{join as _6,dirname as v6}from"path";async function N$(){let $=process.cwd();while(!0){let q=_6($,".bvmrc");if(await G(q))try{return(await Bun.file(q).text()).trim()}catch(J){return null}let Q=v6($);if(Q===$)break;$=Q}return null}k();F();w();q$();R();import{join as z1}from"path";async function W$($,q,Q={}){let J=async(Y)=>{let K=await g(q);if(!K){if(!Q.silent)console.log(Z.blue(`Please install Bun ${q} first using: bvm install ${q}`));throw Error(`Bun version '${q}' is not installed. Cannot create alias.`)}let b=z1(L,K);if(!await G(b))throw Error(`Internal Error: Resolved Bun version ${K} not found.`);await N(x);let X=z1(x,$);if($!=="default"&&await G(X))throw Error(`Alias '${$}' already exists. Use 'bvm alias ${$} <new-version>' to update or 'bvm unalias ${$}' to remove.`);if(await V(X,`${K}
238
- `),Y)Y.succeed(Z.green(`Alias '${$}' created for Bun ${K}.`))};if(Q.silent)await J();else await y(`Creating alias '${$}' for Bun ${q}...`,(Y)=>J(Y),{failMessage:`Failed to create alias '${$}'`})}R();F();w();k();import{join as L1}from"path";q$();R();async function j$($,q={}){let Q=$;if(!Q)Q=await N$()||void 0;if(!Q){if(!q.silent)console.error(Z.red("No version specified. Usage: bvm use <version>"));throw Error("No version specified.")}let J=async(Y)=>{let K=null,b=await g(Q);if(b)K=b;else{let C=(await P()).map((W)=>U(W));K=r(Q,C)}if(!K)throw Error(`Bun version '${Q}' is not installed.`);let X=U(K),H=L1(L,X),z=L1(H,"bin",j);if(!await G(z))throw Error(`Version ${X} is not properly installed (binary missing).`);if(await J1(H,b$),Y)Y.succeed(Z.green(`Now using Bun ${X} (immediate effect).`))};if(q.silent)await J();else await y(`Switching to Bun ${Q}...`,(Y)=>J(Y),{failMessage:()=>`Failed to switch to Bun ${Q}`})}F();w();k();import{join as t,dirname as w1}from"path";import{chmod as x1,unlink as u6}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",V6=($)=>`@echo off
260
+ ${Q}`),q)console.log(Z.green(`\u2713 Successfully configured BVM path in ${$}`)),console.log(Z.yellow("Please restart your terminal to apply changes."))}catch(J){console.error(Z.red(`Failed to write to ${$}: ${J.message}`))}}x();import{join as S6,dirname as _6}from"path";async function N$(){let $=process.cwd();while(!0){let q=S6($,".bvmrc");if(await G(q))try{return(await Bun.file(q).text()).trim()}catch(J){return null}let Q=_6($);if(Q===$)break;$=Q}return null}k();N();x();q$();T();import{join as x1}from"path";async function H$($,q,Q={}){let J=async(Y)=>{let K=await h(q);if(!K){if(!Q.silent)console.log(Z.blue(`Please install Bun ${q} first using: bvm install ${q}`));throw Error(`Bun version '${q}' is not installed. Cannot create alias.`)}let b=x1(w,K);if(!await G(b))throw Error(`Internal Error: Resolved Bun version ${K} not found.`);await M(C);let X=x1(C,$);if($!=="default"&&await G(X))throw Error(`Alias '${$}' already exists. Use 'bvm alias ${$} <new-version>' to update or 'bvm unalias ${$}' to remove.`);if(await g(X,`${K}
261
+ `),Y)Y.succeed(Z.green(`Alias '${$}' created for Bun ${K}.`))};if(Q.silent)await J();else await O(`Creating alias '${$}' for Bun ${q}...`,(Y)=>J(Y),{failMessage:`Failed to create alias '${$}'`})}T();N();x();k();import{join as C1}from"path";q$();T();async function A$($,q={}){let Q=$;if(!Q)Q=await N$()||void 0;if(!Q){if(!q.silent)console.error(Z.red("No version specified. Usage: bvm use <version>"));throw Error("No version specified.")}let J=async(Y)=>{let K=null,b=await h(Q);if(b)K=b;else{let F=(await u()).map((H)=>U(H));K=e(Q,F)}if(!K)throw Error(`Bun version '${Q}' is not installed.`);let X=U(K),W=C1(w,X),y=C1(W,"bin",R);if(!await G(y))throw Error(`Version ${X} is not properly installed (binary missing).`);if(await Y1(W,b$),Y)Y.succeed(Z.green(`Now using Bun ${X} (immediate effect).`))};if(q.silent)await J();else await O(`Switching to Bun ${Q}...`,(Y)=>J(Y),{failMessage:()=>`Failed to switch to Bun ${Q}`})}N();x();k();import{join as n,dirname as k1}from"path";import{chmod as F1,unlink as P6}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",u6=($)=>`@echo off
239
262
  set "BVM_DIR=%USERPROFILE%.bvm"
240
263
  if exist "%BVM_DIR%\runtimecurrent\bin\bun.exe" (
241
264
  "%BVM_DIR%\runtimecurrent\bin\bun.exe" "%BVM_DIR%\bin\bvm-shim.js" "${$}" %*
242
265
  ) else (
243
266
  echo BVM Error: Bun runtime not found.
244
267
  exit /b 1
245
- )`,d6=($)=>`#!/bin/bash
246
- export BVM_DIR="${O}"
247
- exec "${t(M,"bvm-shim.sh")}" "${$}" "$@"`;async function Q$(){await N(S),await N(M);let $=B==="win32";try{let Q=t(w1(w1(__dirname)),"src","templates");if($){let J=await Bun.file(t(Q,"bvm-shim.js")).text();await Bun.write(t(M,"bvm-shim.js"),J)}else{let J=await Bun.file(t(Q,"bvm-shim.sh")).text(),Y=t(M,"bvm-shim.sh");await Bun.write(Y,J),await x1(Y,493)}}catch(Q){}let q=new Set(["bun","bunx"]);if(await G(L)){let Q=await p(L);for(let J of Q){if(J.startsWith("."))continue;let Y=t(L,J,"bin");if(await G(Y)){let K=await p(Y);for(let b of K){let X=b.replace(/\.(exe|ps1|cmd)$/i,"");if(X)q.add(X)}}}}for(let Q of q)if($){await Bun.write(t(S,`${Q}.cmd`),V6(Q));let J=t(S,`${Q}.ps1`);if(await G(J))await u6(J)}else{let J=t(S,Q);await Bun.write(J,d6(Q)),await x1(J,493)}console.log(Z.green(`\u2713 Regenerated ${q.size} shims in ${S}`))}import{rename as h6,rm as C1}from"fs/promises";async function g$($,q){try{await h6($,q)}catch(Q){await Bun.write(Bun.file(q),Bun.file($)),await C1($,{force:!0})}}async function k1($,q,Q,J){let Y=await fetch($);if(!Y.ok)throw Error(`Status ${Y.status}`);let K=+(Y.headers.get("Content-Length")||0),b=0,X=Y.body?.getReader();if(!X)throw Error("No response body");let H=Bun.file(q).writer(),z=B==="win32";Q.stop();let C=null,W=-1;if(!z)C=new D$(K||41943040),C.start();else console.log(`Downloading Bun ${J}...`);try{let A=Date.now();while(!0){let{done:h,value:v}=await X.read();if(h)break;if(H.write(v),b+=v.length,!z&&C){let u=(Date.now()-A)/1000,c=u>0?(b/1024/u).toFixed(0):"0";C.update(b,{speed:c})}else if(z&&K){let u=Math.floor(b/K*10);if(u>W)console.log(` > ${u*10}%`),W=u}}if(await H.end(),!z&&C)C.stop();else console.log(" > 100% [Done]")}catch(A){try{H.end()}catch(h){}if(!z&&C)C.stop();else console.log(" > Download Failed");throw Q.start(),A}Q.start()}async function h$($,q={}){let Q=$,J=null,Y=!1;if(!Q)Q=await N$()||void 0;if(!Q){console.error(Z.red("No version specified and no .bvmrc found. Usage: bvm install <version>"));return}try{await y(`Finding Bun ${Q} release...`,async(K)=>{let b=null,X=U(Q);if(/^v?\d+\.\d+\.\d+$/.test(Q)&&!Q.includes("canary"))if(K.update(`Checking if Bun ${X} exists...`),await X1(X))b=X;else throw K.fail(Z.red(`Bun version ${X} not found on registry.`)),Error(`Bun version ${X} not found on registry.`);else if(Q==="latest"){K.update("Checking latest version...");let u=await G1();if(u.latest)b=U(u.latest);else throw Error('Could not resolve "latest" version.')}else throw K.fail(Z.yellow('Fuzzy matching (e.g. "1.1") is disabled for stability.')),console.log(Z.dim(' Please specify the exact version (e.g. "1.1.20") or "latest".')),console.log(Z.dim(" To see available versions, run: bvm ls-remote")),Error("Fuzzy matching disabled");if(!b)throw K.fail(Z.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 H=await H1(b);if(!H)throw Error(`Could not find a Bun release for ${b} compatible with your system.`);let{url:z,mirrorUrl:C,foundVersion:W}=H,A=n(L,W),h=n(A,"bin"),v=n(h,j);if(await G(v))K.succeed(Z.green(`Bun ${W} is already installed.`)),J=W,Y=!0;else if(U(Bun.version)===W&&!D){K.info(Z.cyan(`Requested version ${W} matches current BVM runtime. Creating symlink...`)),await N(h);let c=process.execPath;try{let{symlink:s}=await import("fs/promises");await s(c,v)}catch(s){await Bun.write(Bun.file(v),Bun.file(c)),await m$(v,493)}K.succeed(Z.green(`Bun ${W} linked from local runtime.`)),J=W,Y=!0}else if(D)await N(h),await c6(v,W),J=W,Y=!0;else{K.update(`Downloading Bun ${W} to cache...`),await N(_);let c=n(_,`${W}-${g6(z)}`);if(await G(c))K.succeed(Z.green(`Using cached Bun ${W} archive.`));else{let I=`${c}.${Date.now()}.tmp`;try{await k1(z,I,K,W),await g$(I,c)}catch(o$){try{await C1(I,{force:!0})}catch{}if(K.update("Download failed, trying mirror..."),console.log(Z.dim(`
248
- Debug: ${o$.message}`)),C){let l1=new URL(C).hostname;K.update(`Downloading from mirror (${l1})...`),await k1(C,I,K,W),await g$(I,c)}else throw o$}}K.update(`Extracting Bun ${W}...`),await N(A),await W1(c,A);let s="",A$=[n(A,j),n(A,"bin",j),n(A,"package","bin",j)],p1=await p(A);for(let I of p1)if(I.startsWith("bun-"))A$.push(n(A,I,j)),A$.push(n(A,I,"bin",j));for(let I of A$)if(await G(I)){s=I;break}if(!s)throw Error(`Could not find bun executable in ${A}`);if(await N(h),s!==v){await g$(s,v);let I=m6(s);if(I!==A&&I!==h)await G$(I)}await m$(v,493),K.succeed(Z.green(`Bun ${W} installed successfully.`)),J=W,Y=!0}},{failMessage:`Failed to install Bun ${Q}`})}catch(K){throw Error(`Failed to install Bun: ${K.message}`)}if(Y)await H$(!1);if(J)try{await j$(J,{silent:!0});let K=n(x,"default");if(!await G(K))await W$("default",J,{silent:!0})}catch(K){}if(await Q$(),J)console.log(Z.cyan(`
268
+ )`,V6=($)=>`#!/bin/bash
269
+ export BVM_DIR="${z}"
270
+ exec "${n(A,"bvm-shim.sh")}" "${$}" "$@"`;async function Q$(){await M(I),await M(A);let $=B==="win32";try{let Q=n(k1(k1(__dirname)),"src","templates");if($){let J=await Bun.file(n(Q,"bvm-shim.js")).text();await Bun.write(n(A,"bvm-shim.js"),J)}else{let J=await Bun.file(n(Q,"bvm-shim.sh")).text(),Y=n(A,"bvm-shim.sh");await Bun.write(Y,J),await F1(Y,493)}}catch(Q){}let q=new Set(["bun","bunx"]);if(await G(w)){let Q=await l(w);for(let J of Q){if(J.startsWith("."))continue;let Y=n(w,J,"bin");if(await G(Y)){let K=await l(Y);for(let b of K){let X=b.replace(/\.(exe|ps1|cmd)$/i,"");if(X)q.add(X)}}}}for(let Q of q)if($){await Bun.write(n(I,`${Q}.cmd`),u6(Q));let J=n(I,`${Q}.ps1`);if(await G(J))await P6(J)}else{let J=n(I,Q);await Bun.write(J,V6(Q)),await F1(J,493)}console.log(Z.green(`\u2713 Regenerated ${q.size} shims in ${I}`))}import{rename as h6,rm as A1}from"fs/promises";async function h$($,q){try{await h6($,q)}catch(Q){await Bun.write(Bun.file(q),Bun.file($)),await A1($,{force:!0})}}async function N1($,q,Q,J){let Y=await fetch($);if(!Y.ok)throw Error(`Status ${Y.status}`);let K=+(Y.headers.get("Content-Length")||0),b=0,X=Y.body?.getReader();if(!X)throw Error("No response body");let W=Bun.file(q).writer(),y=B==="win32";Q.stop();let F=null,H=-1;if(!y)F=new I$(K||41943040),F.start();else console.log(`Downloading Bun ${J}...`);try{let j=Date.now();while(!0){let{done:m,value:P}=await X.read();if(m)break;if(W.write(P),b+=P.length,!y&&F){let V=(Date.now()-j)/1000,p=V>0?(b/1024/V).toFixed(0):"0";F.update(b,{speed:p})}else if(y&&K){let V=Math.floor(b/K*10);if(V>H)console.log(` > ${V*10}%`),H=V}}if(await W.end(),!y&&F)F.stop();else console.log(" > 100% [Done]")}catch(j){try{W.end()}catch(m){}if(!y&&F)F.stop();else console.log(" > Download Failed");throw Q.start(),j}Q.start()}async function m$($,q={}){let Q=$,J=null,Y=!1;if(!Q)Q=await N$()||void 0;if(!Q){console.error(Z.red("No version specified and no .bvmrc found. Usage: bvm install <version>"));return}try{await O(`Finding Bun ${Q} release...`,async(K)=>{let b=null,X=U(Q);if(/^v?\d+\.\d+\.\d+$/.test(Q)&&!Q.includes("canary"))if(K.update(`Checking if Bun ${X} exists...`),await W1(X))b=X;else throw K.fail(Z.red(`Bun version ${X} not found on registry.`)),Error(`Bun version ${X} not found on registry.`);else if(Q==="latest"){K.update("Checking latest version...");let V=await H1();if(V.latest)b=U(V.latest);else throw Error('Could not resolve "latest" version.')}else throw K.fail(Z.yellow('Fuzzy matching (e.g. "1.1") is disabled for stability.')),console.log(Z.dim(' Please specify the exact version (e.g. "1.1.20") or "latest".')),console.log(Z.dim(" To see available versions, run: bvm ls-remote")),Error("Fuzzy matching disabled");if(!b)throw K.fail(Z.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 U1(b);if(!W)throw Error(`Could not find a Bun release for ${b} compatible with your system.`);let{url:y,mirrorUrl:F,foundVersion:H}=W,j=o(w,H),m=o(j,"bin"),P=o(m,R);if(await G(P))K.succeed(Z.green(`Bun ${H} is already installed.`)),J=H,Y=!0;else if(U(Bun.version)===H&&!D){K.info(Z.cyan(`Requested version ${H} matches current BVM runtime. Creating symlink...`)),await M(m);let p=process.execPath;try{let{symlink:r}=await import("fs/promises");await r(p,P)}catch(r){await Bun.write(Bun.file(P),Bun.file(p)),await c$(P,493)}K.succeed(Z.green(`Bun ${H} linked from local runtime.`)),J=H,Y=!0}else if(D)await M(m),await c6(P,H),J=H,Y=!0;else{K.update(`Downloading Bun ${H} to cache...`),await M(_);let p=o(_,`${H}-${g6(y)}`);if(await G(p))K.succeed(Z.green(`Using cached Bun ${H} archive.`));else{let E=`${p}.${Date.now()}.tmp`;try{await N1(y,E,K,H),await h$(E,p)}catch(i$){try{await A1(E,{force:!0})}catch{}if(K.update("Download failed, trying mirror..."),console.log(Z.dim(`
271
+ Debug: ${i$.message}`)),F){let o1=new URL(F).hostname;K.update(`Downloading from mirror (${o1})...`),await N1(F,E,K,H),await h$(E,p)}else throw i$}}K.update(`Extracting Bun ${H}...`),await M(j),await O1(p,j);let r="",j$=[o(j,R),o(j,"bin",R),o(j,"package","bin",R)],n1=await l(j);for(let E of n1)if(E.startsWith("bun-"))j$.push(o(j,E,R)),j$.push(o(j,E,"bin",R));for(let E of j$)if(await G(E)){r=E;break}if(!r)throw Error(`Could not find bun executable in ${j}`);if(await M(m),r!==P){await h$(r,P);let E=d6(r);if(E!==j&&E!==m)await G$(E)}await c$(P,493),K.succeed(Z.green(`Bun ${H} installed successfully.`)),J=H,Y=!0}},{failMessage:`Failed to install Bun ${Q}`})}catch(K){throw Error(`Failed to install Bun: ${K.message}`)}if(Y)await W$(!1);if(J)try{await A$(J,{silent:!0});let K=o(C,"default");if(!await G(K))await H$("default",J,{silent:!0})}catch(K){}if(await Q$(),J)console.log(Z.cyan(`
249
272
  \u2713 Bun ${J} installed and active.`)),console.log(Z.dim(" To verify, run: bun --version or bvm ls"))}async function c6($,q){let Q=q.replace(/^v/,""),J=`#!/usr/bin/env bash
250
273
  set -euo pipefail
251
274
  if [[ $# -gt 0 && "$1" == "--version" ]]; then echo "${Q}"; exit 0; fi
252
275
  echo "Bun ${Q} stub invoked with: $@"
253
276
  exit 0
254
- `;await Bun.write($,J),await m$($,493)}k();w();R();async function F1(){await y("Fetching remote Bun versions...",async($)=>{let Q=(await b1()).filter((J)=>m(J)).filter((J)=>!J.includes("canary")).sort(K$);if(Q.length===0)throw Error("No remote Bun versions found.");$.succeed(Z.green("Available remote Bun versions:")),Q.forEach((J)=>{console.log(` ${U(J)}`)})},{failMessage:"Failed to fetch remote Bun versions"})}k();w();F();R();import{join as p6}from"path";async function N1(){await y("Fetching locally installed Bun versions...",async($)=>{let q=await P(),J=(await l()).version;if($.succeed(Z.green("Locally installed Bun versions:")),q.length===0)console.log(" (No versions installed yet)");else q.forEach((K)=>{if(K===J)console.log(`* ${Z.green(K)} ${Z.dim("(current)")}`);else console.log(` ${K}`)});if(await G(x)){let K=await p(x);if(K.length>0){console.log(Z.green(`
255
- Aliases:`));for(let b of K)try{let X=(await f(p6(x,b))).trim(),H=U(X),z=`-> ${Z.cyan(H)}`;if(H===J)z+=` ${Z.dim("(current)")}`;console.log(` ${b} ${Z.gray(z)}`)}catch(X){}}}},{failMessage:"Failed to list local Bun versions"})}k();w();R();async function j1(){await y("Checking current Bun version...",async($)=>{let{version:q,source:Q}=await l();if(q)$.stop(),console.log(`${Z.green("\u2713")} Current Bun version: ${Z.green(q)} ${Z.dim(`(${Q})`)}`);else $.info(Z.blue("No Bun version is currently active.")),console.log(Z.yellow("Use 'bvm install <version>' to set a default, or create a .bvmrc file."))},{failMessage:"Failed to determine current Bun version"})}k();F();w();R();import{join as c$,basename as l6}from"path";import{unlink as t6}from"fs/promises";async function A1($){await y(`Attempting to uninstall Bun ${$}...`,async(q)=>{let Q=U($),J=c$(L,Q),Y=c$(J,"bin",j);if(!await G(Y))throw Error(`Bun ${$} is not installed.`);let K=!1;try{let b=c$(x,"default");if(await G(b)){let X=(await f(b)).trim();if(U(X)===Q)K=!0}}catch(b){}if(K)throw console.log(Z.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 b=await K1(b$);if(b){if(U(l6(b))===Q)await t6(b$)}}catch(b){}await G$(J),q.succeed(Z.green(`Bun ${Q} uninstalled successfully.`)),await Q$()},{failMessage:`Failed to uninstall Bun ${$}`})}k();F();w();R();import{join as n6}from"path";import{unlink as o6}from"fs/promises";async function B1($){await y(`Removing alias '${$}'...`,async(q)=>{let Q=n6(x,$);if(!await G(Q))throw Error(`Alias '${$}' does not exist.`);await o6(Q),q.succeed(Z.green(`Alias '${$}' removed successfully.`))},{failMessage:`Failed to remove alias '${$}'`})}k();F();w();q$();R();import{join as p$}from"path";async function M1($,q){await y(`Preparing to run with Bun ${$}...`,async(Q)=>{let J=await g($);if(!J)J=U($);let Y=p$(L,J),K=p$(Y,"bin"),b=p$(K,j);if(!await G(b)){Q.fail(Z.red(`Bun ${$} (resolved: ${J}) is not installed.`)),console.log(Z.yellow(`You can install it using: bvm install ${$}`));return}Q.stop();try{await d([b,...q],{cwd:process.cwd(),prependPath:K}),process.exit(0)}catch(X){console.error(X.message),process.exit(1)}},{failMessage:`Failed to run command with Bun ${$}`})}k();F();w();q$();R();import{join as l$}from"path";async function f1($,q,Q){await y(`Preparing environment for Bun ${$} to execute '${q}'...`,async(J)=>{let Y=await g($);if(!Y)Y=U($);let K=l$(L,Y),b=l$(K,"bin"),X=l$(b,j);if(!await G(X)){J.fail(Z.red(`Bun ${$} (resolved: ${Y}) is not installed.`)),console.log(Z.yellow(`You can install it using: bvm install ${$}`));return}J.stop();try{await d([q,...Q],{cwd:process.cwd(),prependPath:b}),process.exit(0)}catch(H){console.error(H.message),process.exit(1)}},{failMessage:`Failed to execute command with Bun ${$}'s environment`})}F();w();R();import{join as i6}from"path";async function T1($){await y("Resolving path...",async()=>{let q=null,Q="bun",{version:J}=await l();if(!$||$==="current"){if(q=J,!q)throw Error("No active Bun version found.")}else{let{resolveLocalVersion:K}=await Promise.resolve().then(() => (q$(),O1));if(q=await K($),!q)if(J)q=J,Q=$;else throw Error(`Bun version or command '${$}' not found.`)}let Y=i6(L,q,"bin",Q==="bun"?j:Q);if(await G(Y))console.log(Y);else throw Error(`Command '${Q}' not found in Bun ${q}.`)},{failMessage:"Failed to resolve path"})}k();w();R();q$();async function R1($){await y(`Resolving session version for Bun ${$}...`,async(q)=>{let Q=null,J=await g($);if(J)Q=J;else{let K=(await P()).map((b)=>U(b));Q=r($,K)}if(!Q)throw Error(`Bun version '${$}' is not installed or cannot be resolved.`);let Y=U(Q);q.succeed(Z.green(`Bun ${Y} will be active in this session.`)),console.log(`export BVM_ACTIVE_VERSION=${Y}`),console.log(Z.dim("Run `eval $(bvm shell <version>)` or `export BVM_ACTIVE_VERSION=...` to activate."))},{failMessage:`Failed to set session version for Bun ${$}`})}k();F();w();R();import{join as a6}from"path";async function D1($){let q=a6(x,"default");if(!$)await y("Checking current default Bun version...",async(Q)=>{if(await G(q)){let J=await f(q);Q.succeed(Z.green(`Default Bun version: ${U(J.trim())}`))}else Q.info(Z.blue("No global default Bun version is set.")),console.log(Z.yellow("Use 'bvm default <version>' to set one."))},{failMessage:"Failed to retrieve default Bun version"});else await y(`Setting global default to Bun ${$}...`,async(Q)=>{let J=(await P()).map((K)=>U(K)),Y=r($,J);if(!Y)throw Error(`Bun version '${$}' is not installed.`);await W$("default",Y,{silent:!0}),Q.succeed(Z.green(`\u2713 Default set to ${Y}. New terminals will now start with this version.`))},{failMessage:`Failed to set global default to Bun ${$}`})}F();w();k();R();import{unlink as s6}from"fs/promises";import{join as r6}from"path";async function I1(){await y("Deactivating current Bun version...",async($)=>{let q=r6(x,"default");if(await G(q))await s6(q),$.succeed(Z.green("Default Bun version deactivated.")),console.log(Z.gray("Run `bvm use <version>` to reactivate.")),await Q$();else $.info("No default Bun version is currently active.")},{failMessage:"Failed to deactivate"})}q$();F();w();k();R();async function E1($){if($==="dir"){console.log(_);return}if($==="clear"){await y("Clearing cache...",async(q)=>{await G$(_),await N(_),q.succeed(Z.green("Cache cleared."))},{failMessage:"Failed to clear cache"});return}console.error(Z.red(`Unknown cache command: ${$}`)),console.log("Usage: bvm cache dir | bvm cache clear")}k();F();R();w();import{join as E}from"path";import{tmpdir as e6}from"os";import{rm as S1,mkdir as _1}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",t$=Y$.version;async function v1(){let $=process.env.BVM_INSTALL_SOURCE;if($==="npm"||$==="bun"||__dirname.includes("node_modules")){await y(`Upgrading BVM via ${$||"package manager"}...`,async(Q)=>{let J=await e(),Y=$==="bun"?"bun":"npm";Q.text=`Upgrading BVM via ${Y} using ${J}...`;try{await d([Y,"install","-g","bvm-core","--registry",J]),Q.succeed(Z.green(`BVM upgraded via ${Y} successfully.`))}catch(K){throw Error(`${Y} upgrade failed: ${K.message}`)}});return}try{await y("Checking for BVM updates...",async(Q)=>{let J=D?{version:process.env.BVM_TEST_LATEST_VERSION?.replace("v","")||t$,tarball:"https://example.com/bvm-test.tgz",shasum:"mock",integrity:"mock"}:await F$();if(!J)throw Error("Unable to determine the latest BVM version from NPM Registry.");let Y=J.version;if(!m(Y))throw Error(`Unrecognized version received: ${Y}`);if(!k$(Y,t$)){Q.succeed(Z.green(`BVM is already up to date (v${t$}).`)),console.log(Z.blue("You are using the latest version."));return}if(Q.text=`Updating BVM to v${Y}...`,D&&!process.env.BVM_TEST_REAL_UPGRADE){Q.succeed(Z.green("BVM updated successfully (test mode)."));return}Q.update("Downloading update package...");let K=E(e6(),`bvm-upgrade-${Date.now()}`);await _1(K,{recursive:!0});let b=E(K,"bvm-core.tgz");if(D){await V(b,"mock-tarball");let H=E(K,"package","dist");await _1(H,{recursive:!0}),await V(E(H,"index.js"),"// new cli"),await V(E(H,"bvm-shim.sh"),"# new shim"),await V(E(H,"bvm-shim.js"),"// new shim")}else{let H=await a(J.tarball,{timeout:30000});if(!H.ok)throw Error(`Failed to download tarball: ${H.statusText}`);let z=await H.arrayBuffer();await L$(b,new Uint8Array(z)),Q.update("Extracting update...");try{await d(["tar","-xzf",b,"-C",K])}catch(C){throw Error('Failed to extract update package. Ensure "tar" is available.')}}Q.update("Applying updates...");let X=E(K,"package","dist");if(await G(E(X,"index.js")))await L$(E(O,"src","index.js"),await f(E(X,"index.js")));if(B!=="win32"&&await G(E(X,"bvm-shim.sh")))await L$(E(O,"bin","bvm-shim.sh"),await f(E(X,"bvm-shim.sh")));if(B==="win32"&&await G(E(X,"bvm-shim.js")))await L$(E(O,"bin","bvm-shim.js"),await f(E(X,"bvm-shim.js")));try{await S1(K,{recursive:!0,force:!0})}catch(H){}try{await S1(M$,{force:!0})}catch(H){}Q.update("Finalizing environment..."),await H$(!1),Q.succeed(Z.green(`BVM updated to v${Y} successfully.`)),console.log(Z.yellow("Please restart your terminal to apply changes."))},{failMessage:"Failed to upgrade BVM"})}catch(Q){throw Error(`Failed to upgrade BVM: ${Q.message}`)}}k();F();w();R();import{homedir as $4}from"os";import{join as q4}from"path";async function P1(){await y("Gathering BVM diagnostics...",async()=>{let $={currentVersion:(await l()).version,installedVersions:await P(),aliases:await Q4(),env:{BVM_DIR:O,BVM_BIN_DIR:M,BVM_SHIMS_DIR:S,BVM_VERSIONS_DIR:L,BVM_TEST_MODE:process.env.BVM_TEST_MODE,HOME:process.env.HOME||$4()}};J4($)})}async function Q4(){if(!await G(x))return[];let $=await p(x),q=[];for(let Q of $){let J=q4(x,Q);if(await G(J)){let Y=await Bun.file(J).text();q.push({name:Q,target:U(Y.trim())})}}return q}function J4($){if(console.log(Z.bold(`
256
- Directories`)),console.log(` BVM_DIR: ${Z.cyan($.env.BVM_DIR||"")}`),console.log(` BIN_DIR: ${Z.cyan(M)}`),console.log(` SHIMS_DIR: ${Z.cyan(S)}`),console.log(` VERSIONS_DIR: ${Z.cyan(L)}`),console.log(Z.bold(`
277
+ `;await Bun.write($,J),await c$($,493)}k();x();T();async function j1(){await O("Fetching remote Bun versions...",async($)=>{let Q=(await G1()).filter((J)=>c(J)).filter((J)=>!J.includes("canary")).sort(K$);if(Q.length===0)throw Error("No remote Bun versions found.");$.succeed(Z.green("Available remote Bun versions:")),Q.forEach((J)=>{console.log(` ${U(J)}`)})},{failMessage:"Failed to fetch remote Bun versions"})}k();x();N();T();import{join as m6}from"path";async function B1(){await O("Fetching locally installed Bun versions...",async($)=>{let q=await u(),J=(await t()).version;if($.succeed(Z.green("Locally installed Bun versions:")),q.length===0)console.log(" (No versions installed yet)");else q.forEach((K)=>{if(K===J)console.log(`* ${Z.green(K)} ${Z.dim("(current)")}`);else console.log(` ${K}`)});if(await G(C)){let K=await l(C);if(K.length>0){console.log(Z.green(`
278
+ Aliases:`));for(let b of K)try{let X=(await f(m6(C,b))).trim(),W=U(X),y=`-> ${Z.cyan(W)}`;if(W===J)y+=` ${Z.dim("(current)")}`;console.log(` ${b} ${Z.gray(y)}`)}catch(X){}}}},{failMessage:"Failed to list local Bun versions"})}k();x();T();async function f1(){await O("Checking current Bun version...",async($)=>{let{version:q,source:Q}=await t();if(q)$.stop(),console.log(`${Z.green("\u2713")} Current Bun version: ${Z.green(q)} ${Z.dim(`(${Q})`)}`);else $.info(Z.blue("No Bun version is currently active.")),console.log(Z.yellow("Use 'bvm install <version>' to set a default, or create a .bvmrc file."))},{failMessage:"Failed to determine current Bun version"})}k();N();x();T();import{join as p$,basename as p6}from"path";import{unlink as l6}from"fs/promises";async function M1($){await O(`Attempting to uninstall Bun ${$}...`,async(q)=>{let Q=U($),J=p$(w,Q),Y=p$(J,"bin",R);if(!await G(Y))throw Error(`Bun ${$} is not installed.`);let K=!1;try{let b=p$(C,"default");if(await G(b)){let X=(await f(b)).trim();if(U(X)===Q)K=!0}}catch(b){}if(K)throw console.log(Z.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 b=await Z1(b$);if(b){if(U(p6(b))===Q)await l6(b$)}}catch(b){}await G$(J),q.succeed(Z.green(`Bun ${Q} uninstalled successfully.`)),await Q$()},{failMessage:`Failed to uninstall Bun ${$}`})}k();N();x();T();import{join as t6}from"path";import{unlink as n6}from"fs/promises";async function T1($){await O(`Removing alias '${$}'...`,async(q)=>{let Q=t6(C,$);if(!await G(Q))throw Error(`Alias '${$}' does not exist.`);await n6(Q),q.succeed(Z.green(`Alias '${$}' removed successfully.`))},{failMessage:`Failed to remove alias '${$}'`})}k();N();x();q$();T();import{join as l$}from"path";async function D1($,q){await O(`Preparing to run with Bun ${$}...`,async(Q)=>{let J=await h($);if(!J)J=U($);let Y=l$(w,J),K=l$(Y,"bin"),b=l$(K,R);if(!await G(b)){Q.fail(Z.red(`Bun ${$} (resolved: ${J}) is not installed.`)),console.log(Z.yellow(`You can install it using: bvm install ${$}`));return}Q.stop();try{await d([b,...q],{cwd:process.cwd(),prependPath:K}),process.exit(0)}catch(X){console.error(X.message),process.exit(1)}},{failMessage:`Failed to run command with Bun ${$}`})}k();N();x();q$();T();import{join as t$}from"path";async function R1($,q,Q){await O(`Preparing environment for Bun ${$} to execute '${q}'...`,async(J)=>{let Y=await h($);if(!Y)Y=U($);let K=t$(w,Y),b=t$(K,"bin"),X=t$(b,R);if(!await G(X)){J.fail(Z.red(`Bun ${$} (resolved: ${Y}) is not installed.`)),console.log(Z.yellow(`You can install it using: bvm install ${$}`));return}J.stop();try{await d([q,...Q],{cwd:process.cwd(),prependPath:b}),process.exit(0)}catch(W){console.error(W.message),process.exit(1)}},{failMessage:`Failed to execute command with Bun ${$}'s environment`})}N();x();T();import{join as o6}from"path";async function I1($){await O("Resolving path...",async()=>{let q=null,Q="bun",{version:J}=await t();if(!$||$==="current"){if(q=J,!q)throw Error("No active Bun version found.")}else{let{resolveLocalVersion:K}=await Promise.resolve().then(() => (q$(),w1));if(q=await K($),!q)if(J)q=J,Q=$;else throw Error(`Bun version or command '${$}' not found.`)}let Y=o6(w,q,"bin",Q==="bun"?R:Q);if(await G(Y))console.log(Y);else throw Error(`Command '${Q}' not found in Bun ${q}.`)},{failMessage:"Failed to resolve path"})}k();x();T();q$();async function E1($){await O(`Resolving session version for Bun ${$}...`,async(q)=>{let Q=null,J=await h($);if(J)Q=J;else{let K=(await u()).map((b)=>U(b));Q=e($,K)}if(!Q)throw Error(`Bun version '${$}' is not installed or cannot be resolved.`);let Y=U(Q);q.succeed(Z.green(`Bun ${Y} will be active in this session.`)),console.log(`export BVM_ACTIVE_VERSION=${Y}`),console.log(Z.dim("Run `eval $(bvm shell <version>)` or `export BVM_ACTIVE_VERSION=...` to activate."))},{failMessage:`Failed to set session version for Bun ${$}`})}k();N();x();T();import{join as i6}from"path";async function S1($){let q=i6(C,"default");if(!$)await O("Checking current default Bun version...",async(Q)=>{if(await G(q)){let J=await f(q);Q.succeed(Z.green(`Default Bun version: ${U(J.trim())}`))}else Q.info(Z.blue("No global default Bun version is set.")),console.log(Z.yellow("Use 'bvm default <version>' to set one."))},{failMessage:"Failed to retrieve default Bun version"});else await O(`Setting global default to Bun ${$}...`,async(Q)=>{let J=(await u()).map((K)=>U(K)),Y=e($,J);if(!Y)throw Error(`Bun version '${$}' is not installed.`);await H$("default",Y,{silent:!0}),Q.succeed(Z.green(`\u2713 Default set to ${Y}. New terminals will now start with this version.`))},{failMessage:`Failed to set global default to Bun ${$}`})}N();x();k();T();import{unlink as a6}from"fs/promises";import{join as s6}from"path";async function _1(){await O("Deactivating current Bun version...",async($)=>{let q=s6(C,"default");if(await G(q))await a6(q),$.succeed(Z.green("Default Bun version deactivated.")),console.log(Z.gray("Run `bvm use <version>` to reactivate.")),await Q$();else $.info("No default Bun version is currently active.")},{failMessage:"Failed to deactivate"})}q$();N();x();k();T();async function v1($){if($==="dir"){console.log(_);return}if($==="clear"){await O("Clearing cache...",async(q)=>{await G$(_),await M(_),q.succeed(Z.green("Cache cleared."))},{failMessage:"Failed to clear cache"});return}console.error(Z.red(`Unknown cache command: ${$}`)),console.log("Usage: bvm cache dir | bvm cache clear")}k();N();T();x();import{join as S}from"path";import{tmpdir as r6}from"os";import{rm as P1,mkdir as u1}from"fs/promises";var __dirname="/home/runner/work/bvm/bvm/src/commands",n$=Y$.version;async function V1(){let $=process.env.BVM_INSTALL_SOURCE;if($==="npm"||$==="bun"||__dirname.includes("node_modules")){await O(`Upgrading BVM via ${$||"package manager"}...`,async(Q)=>{let J=await $$(),Y=$==="bun"?"bun":"npm";Q.text=`Upgrading BVM via ${Y} using ${J}...`;try{await d([Y,"install","-g","bvm-core","--registry",J]),Q.succeed(Z.green(`BVM upgraded via ${Y} successfully.`))}catch(K){throw Error(`${Y} upgrade failed: ${K.message}`)}});return}try{await O("Checking for BVM updates...",async(Q)=>{let J=D?{version:process.env.BVM_TEST_LATEST_VERSION?.replace("v","")||n$,tarball:"https://example.com/bvm-test.tgz",shasum:"mock",integrity:"mock"}:await F$();if(!J)throw Error("Unable to determine the latest BVM version from NPM Registry.");let Y=J.version;if(!c(Y))throw Error(`Unrecognized version received: ${Y}`);if(!C$(Y,n$)){Q.succeed(Z.green(`BVM is already up to date (v${n$}).`)),console.log(Z.blue("You are using the latest version."));return}if(Q.text=`Updating BVM to v${Y}...`,D&&!process.env.BVM_TEST_REAL_UPGRADE){Q.succeed(Z.green("BVM updated successfully (test mode)."));return}Q.update("Downloading update package...");let K=S(r6(),`bvm-upgrade-${Date.now()}`);await u1(K,{recursive:!0});let b=S(K,"bvm-core.tgz");if(D){await g(b,"mock-tarball");let W=S(K,"package","dist");await u1(W,{recursive:!0}),await g(S(W,"index.js"),"// new cli"),await g(S(W,"bvm-shim.sh"),"# new shim"),await g(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 y=await W.arrayBuffer();await L$(b,new Uint8Array(y)),Q.update("Extracting update...");try{await d(["tar","-xzf",b,"-C",K])}catch(F){throw Error('Failed to extract update package. Ensure "tar" is available.')}}Q.update("Applying updates...");let X=S(K,"package","dist");if(await G(S(X,"index.js")))await L$(S(z,"src","index.js"),await f(S(X,"index.js")));if(B!=="win32"&&await G(S(X,"bvm-shim.sh")))await L$(S(z,"bin","bvm-shim.sh"),await f(S(X,"bvm-shim.sh")));if(B==="win32"&&await G(S(X,"bvm-shim.js")))await L$(S(z,"bin","bvm-shim.js"),await f(S(X,"bvm-shim.js")));try{await P1(K,{recursive:!0,force:!0})}catch(W){}try{await P1(M$,{force:!0})}catch(W){}Q.update("Finalizing environment..."),await W$(!1),Q.succeed(Z.green(`BVM updated to v${Y} successfully.`)),console.log(Z.yellow("Please restart your terminal to apply changes."))},{failMessage:"Failed to upgrade BVM"})}catch(Q){throw Error(`Failed to upgrade BVM: ${Q.message}`)}}k();N();x();T();import{homedir as e6}from"os";import{join as $4}from"path";async function g1(){await O("Gathering BVM diagnostics...",async()=>{let $={currentVersion:(await t()).version,installedVersions:await u(),aliases:await q4(),env:{BVM_DIR:z,BVM_BIN_DIR:A,BVM_SHIMS_DIR:I,BVM_VERSIONS_DIR:w,BVM_TEST_MODE:process.env.BVM_TEST_MODE,HOME:process.env.HOME||e6()}};Q4($)})}async function q4(){if(!await G(C))return[];let $=await l(C),q=[];for(let Q of $){let J=$4(C,Q);if(await G(J)){let Y=await Bun.file(J).text();q.push({name:Q,target:U(Y.trim())})}}return q}function Q4($){if(console.log(Z.bold(`
279
+ Directories`)),console.log(` BVM_DIR: ${Z.cyan($.env.BVM_DIR||"")}`),console.log(` BIN_DIR: ${Z.cyan(A)}`),console.log(` SHIMS_DIR: ${Z.cyan(I)}`),console.log(` VERSIONS_DIR: ${Z.cyan(w)}`),console.log(Z.bold(`
257
280
  Environment`)),console.log(` HOME: ${$.env.HOME||"n/a"}`),console.log(` BVM_TEST_MODE: ${$.env.BVM_TEST_MODE||"false"}`),console.log(Z.bold(`
258
281
  Installed Versions`)),$.installedVersions.length===0)console.log(" (none installed)");else $.installedVersions.forEach((q)=>{let Q=q===$.currentVersion,J=Q?Z.green("*"):" ",Y=Q?Z.green(q):q,K=Q?Z.green(" (current)"):"";console.log(` ${J} ${Y}${K}`)});if(console.log(Z.bold(`
259
282
  Aliases`)),$.aliases.length===0)console.log(" (no aliases configured)");else $.aliases.forEach((q)=>{console.log(` ${q.name} ${Z.gray("->")} ${Z.cyan(q.target)}`)});console.log(`
260
- `+Z.green("Diagnostics complete."))}var n$=["install","uninstall","use","ls","ls-remote","current","alias","unalias","run","exec","which","cache","setup","upgrade","doctor","completion","deactivate","help"],u1={bash:`#!/usr/bin/env bash
283
+ `+Z.green("Diagnostics complete."))}var o$=["install","uninstall","use","ls","ls-remote","current","alias","unalias","run","exec","which","cache","setup","upgrade","doctor","completion","deactivate","help"],d1={bash:`#!/usr/bin/env bash
261
284
  _bvm_completions() {
262
- COMPREPLY=( $(compgen -W "${n$.join(" ")}" -- "\${COMP_WORDS[COMP_CWORD]}") )
285
+ COMPREPLY=( $(compgen -W "${o$.join(" ")}" -- "\${COMP_WORDS[COMP_CWORD]}") )
263
286
  }
264
287
  complete -F _bvm_completions bvm
265
288
  `,zsh:`#compdef bvm
266
289
  _bvm() {
267
290
  local -a commands
268
- commands=( ${n$.join(" ")} )
291
+ commands=( ${o$.join(" ")} )
269
292
  _describe 'command' commands
270
293
  }
271
294
  compdef _bvm bvm
272
- `,fish:`complete -c bvm -f -a "${n$.join(" ")}"
273
- `};function V1($){let q=u1[$];if(!q)throw Error(`Unsupported shell '${$}'. Supported shells: ${Object.keys(u1).join(", ")}`);console.log(q)}k();F();w();import{join as d1}from"path";k();var g1="update-check.json",K4=86400000;async function m1(){if(process.env.CI||D)return;let $=d1(_,g1);try{if(await G($)){let q=await f($),Q=JSON.parse(q);if(Date.now()-Q.lastCheck<K4)return}}catch(q){}try{let q=await F$();if(q){let Q=q.tagName.startsWith("v")?q.tagName.slice(1):q.tagName;await N(_),await V($,JSON.stringify({lastCheck:Date.now(),latestVersion:Q}))}}catch(q){}}async function h1(){if(process.env.CI||D)return null;let $=Y$.version,q=d1(_,g1);try{if(await G(q)){let Q=await f(q),J=JSON.parse(Q);if(J.latestVersion&&k$(J.latestVersion,$))return`
295
+ `,fish:`complete -c bvm -f -a "${o$.join(" ")}"
296
+ `};function h1($){let q=d1[$];if(!q)throw Error(`Unsupported shell '${$}'. Supported shells: ${Object.keys(d1).join(", ")}`);console.log(q)}k();N();x();import{join as c1}from"path";k();var m1="update-check.json",J4=86400000;async function p1(){if(process.env.CI||D)return;let $=c1(_,m1);try{if(await G($)){let q=await f($),Q=JSON.parse(q);if(Date.now()-Q.lastCheck<J4)return}}catch(q){}try{let q=await F$();if(q){let Q=q.tagName.startsWith("v")?q.tagName.slice(1):q.tagName;await M(_),await g($,JSON.stringify({lastCheck:Date.now(),latestVersion:Q}))}}catch(q){}}async function l1(){if(process.env.CI||D)return null;let $=Y$.version,q=c1(_,m1);try{if(await G(q)){let Q=await f(q),J=JSON.parse(Q);if(J.latestVersion&&C$(J.latestVersion,$))return`
274
297
  ${Z.gray("Update available:")} ${Z.green(`v${J.latestVersion}`)} ${Z.dim(`(current: v${$})`)}
275
- ${Z.gray("Run")} ${Z.cyan("bvm upgrade")} ${Z.gray("to update.")}`}}catch(Q){}return null}class c1{commands={};helpEntries=[];name;versionStr;constructor($){this.name=$,this.versionStr=Y$.version}command($,q,Q={}){let J=$.split(" ")[0],Y={description:q,usage:`${this.name} ${$}`,action:async()=>{},aliases:Q.aliases};if(this.commands[J]=Y,this.helpEntries.push(` ${$.padEnd(35)} ${q}`),Q.aliases)Q.aliases.forEach((b)=>{this.commands[b]=Y});let K={action:(b)=>{return Y.action=b,K},option:(b,X)=>K};return K}async run(){m1().catch(()=>{});let{values:$,positionals:q}=Y4({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=q[0],J=!!($.silent||$.s),Y=!!($.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 K=this.commands[Q];if(!K)console.error(Z.yellow(`Unknown command '${Q}'`)),this.showHelp(),process.exit(0);try{if(await K.action(q.slice(1),$),!Y&&!J&&["ls","current","doctor","default"].includes(Q)){let b=await h1();if(b)console.log(b)}}catch(b){if(!b.reported)console.error(Z.red(`\u2716 ${b.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
298
+ ${Z.gray("Run")} ${Z.cyan("bvm upgrade")} ${Z.gray("to update.")}`}}catch(Q){}return null}class t1{commands={};helpEntries=[];name;versionStr;constructor($){this.name=$,this.versionStr=Y$.version}command($,q,Q={}){let J=$.split(" ")[0],Y={description:q,usage:`${this.name} ${$}`,action:async()=>{},aliases:Q.aliases};if(this.commands[J]=Y,this.helpEntries.push(` ${$.padEnd(35)} ${q}`),Q.aliases)Q.aliases.forEach((b)=>{this.commands[b]=Y});let K={action:(b)=>{return Y.action=b,K},option:(b,X)=>K};return K}async run(){p1().catch(()=>{});let{values:$,positionals:q}=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=q[0],J=!!($.silent||$.s),Y=!!($.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 K=this.commands[Q];if(!K)console.error(Z.yellow(`Unknown command '${Q}'`)),this.showHelp(),process.exit(0);try{if(await K.action(q.slice(1),$),!Y&&!J&&["ls","current","doctor","default"].includes(Q)){let b=await l1();if(b)console.log(b)}}catch(b){if(!b.reported)console.error(Z.red(`\u2716 ${b.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
276
299
  `),console.log("Usage:"),console.log(` ${this.name} <command> [flags]
277
300
  `),console.log("Commands:"),console.log(this.helpEntries.join(`
278
301
  `)),console.log(`
279
302
  Global Flags:`),console.log(" --help, -h Show this help message"),console.log(" --version, -v Show version number"),console.log(`
280
- 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 Z4(){let $=new c1("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(q,Q)=>{await h$(q[0],{global:Q.global||Q.g})}),$.command("i [version]","Alias for install").action(async(q,Q)=>{await h$(q[0],{global:Q.global||Q.g})}),$.command("ls","List installed Bun versions",{aliases:["list"]}).action(async()=>{await N1()}),$.command("ls-remote","List all available remote Bun versions").action(async()=>{await F1()}),$.command("use <version>","Switch the active Bun version immediately (all terminals)").action(async(q)=>{if(!q[0])throw Error("Version is required");await j$(q[0])}),$.command("shell <version>","Switch Bun version for the current shell session").action(async(q)=>{if(!q[0])throw Error("Version is required");await R1(q[0])}),$.command("default [version]","Display or set the global default Bun version").action(async(q)=>{await D1(q[0])}),$.command("current","Display the currently active Bun version").action(async()=>{await j1()}),$.command("uninstall <version>","Uninstall a Bun version").action(async(q)=>{if(!q[0])throw Error("Version is required");await A1(q[0])}),$.command("alias <name> <version>","Create an alias for a Bun version").action(async(q)=>{if(!q[0]||!q[1])throw Error("Name and version are required");await W$(q[0],q[1])}),$.command("unalias <name>","Remove an existing alias").action(async(q)=>{if(!q[0])throw Error("Alias name is required");await B1(q[0])}),$.command("run <version> [...args]","Run a command with a specific Bun version").action(async(q)=>{let Q=q[0];if(!Q)throw Error("Version is required");let J=process.argv.indexOf("run"),Y=J!==-1?process.argv.slice(J+2):[];await M1(Q,Y)}),$.command("exec <version> <cmd> [...args]","Execute a command with a specific Bun version's environment").action(async(q)=>{let Q=q[0],J=q[1];if(!Q||!J)throw Error("Version and command are required");let Y=process.argv.indexOf("exec"),K=Y!==-1?process.argv.slice(Y+3):[];await f1(Q,J,K)}),$.command("which [version]","Display path to installed bun version").action(async(q)=>{await T1(q[0])}),$.command("deactivate","Undo effects of bvm on current shell").action(async()=>{await I1()}),$.command("version <spec>","Resolve the given description to a single local version").action(async(q)=>{if(!q[0])throw Error("Version specifier is required");await d$(q[0])}),$.command("cache <action>","Manage bvm cache").action(async(q)=>{if(!q[0])throw Error("Action is required");await E1(q[0])}),$.command("setup","Configure shell environment automatically").option("--silent, -s","Suppress output").action(async(q,Q)=>{await H$(!(Q.silent||Q.s))}),$.command("upgrade","Upgrade bvm to the latest version",{aliases:["self-update"]}).action(async()=>{await v1()}),$.command("doctor","Show diagnostics for Bun/BVM setup").action(async()=>{await P1()}),$.command("completion <shell>","Generate shell completion script (bash|zsh|fish)").action(async(q)=>{if(!q[0])throw Error("Shell name is required");V1(q[0])}),await $.run(),process.exit(0)}Z4().catch(($)=>{console.error(Z.red(`
303
+ 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 Y4(){let $=new t1("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(q,Q)=>{await m$(q[0],{global:Q.global||Q.g})}),$.command("i [version]","Alias for install").action(async(q,Q)=>{await m$(q[0],{global:Q.global||Q.g})}),$.command("ls","List installed Bun versions",{aliases:["list"]}).action(async()=>{await B1()}),$.command("ls-remote","List all available remote Bun versions").action(async()=>{await j1()}),$.command("use <version>","Switch the active Bun version immediately (all terminals)").action(async(q)=>{if(!q[0])throw Error("Version is required");await A$(q[0])}),$.command("shell <version>","Switch Bun version for the current shell session").action(async(q)=>{if(!q[0])throw Error("Version is required");await E1(q[0])}),$.command("default [version]","Display or set the global default Bun version").action(async(q)=>{await S1(q[0])}),$.command("current","Display the currently active Bun version").action(async()=>{await f1()}),$.command("uninstall <version>","Uninstall a Bun version").action(async(q)=>{if(!q[0])throw Error("Version is required");await M1(q[0])}),$.command("alias <name> <version>","Create an alias for a Bun version").action(async(q)=>{if(!q[0]||!q[1])throw Error("Name and version are required");await H$(q[0],q[1])}),$.command("unalias <name>","Remove an existing alias").action(async(q)=>{if(!q[0])throw Error("Alias name is required");await T1(q[0])}),$.command("run <version> [...args]","Run a command with a specific Bun version").action(async(q)=>{let Q=q[0];if(!Q)throw Error("Version is required");let J=process.argv.indexOf("run"),Y=J!==-1?process.argv.slice(J+2):[];await D1(Q,Y)}),$.command("exec <version> <cmd> [...args]","Execute a command with a specific Bun version's environment").action(async(q)=>{let Q=q[0],J=q[1];if(!Q||!J)throw Error("Version and command are required");let Y=process.argv.indexOf("exec"),K=Y!==-1?process.argv.slice(Y+3):[];await R1(Q,J,K)}),$.command("which [version]","Display path to installed bun version").action(async(q)=>{await I1(q[0])}),$.command("deactivate","Undo effects of bvm on current shell").action(async()=>{await _1()}),$.command("version <spec>","Resolve the given description to a single local version").action(async(q)=>{if(!q[0])throw Error("Version specifier is required");await d$(q[0])}),$.command("cache <action>","Manage bvm cache").action(async(q)=>{if(!q[0])throw Error("Action is required");await v1(q[0])}),$.command("setup","Configure shell environment automatically").option("--silent, -s","Suppress output").action(async(q,Q)=>{await W$(!(Q.silent||Q.s))}),$.command("upgrade","Upgrade bvm to the latest version",{aliases:["self-update"]}).action(async()=>{await V1()}),$.command("doctor","Show diagnostics for Bun/BVM setup").action(async()=>{await g1()}),$.command("completion <shell>","Generate shell completion script (bash|zsh|fish)").action(async(q)=>{if(!q[0])throw Error("Shell name is required");h1(q[0])}),await $.run(),process.exit(0)}Y4().catch(($)=>{console.error(Z.red(`
281
304
  [FATAL ERROR] Unexpected Crash:`)),console.error($),process.exit(1)});
package/install.ps1 CHANGED
@@ -1,4 +1,5 @@
1
1
  # BVM Installer for Windows (PowerShell)
2
+ # Unified Installation Logic: strict isolation, idempotency, and path precedence.
2
3
  $ErrorActionPreference = "Stop"
3
4
 
4
5
  # --- Fix: Enforce TLS 1.2 ---
@@ -26,14 +27,6 @@ $BVM_RUNTIME_DIR = Join-Path $BVM_DIR "runtime"
26
27
  $BVM_ALIAS_DIR = Join-Path $BVM_DIR "aliases"
27
28
  $BVM_VERSIONS_DIR = Join-Path $BVM_DIR "versions"
28
29
 
29
- # --- 0. Conflict Detection ---
30
- $BVM_BIN_PATH = Join-Path $BVM_BIN_DIR "bvm.cmd"
31
- if (Test-Path $BVM_BIN_PATH) {
32
- $content = Get-Content $BVM_BIN_PATH -Raw
33
- if ($content -like '*BVM_INSTALL_SOURCE="npm"*') { Write-Error "BVM was installed via npm."; exit 1 }
34
- elseif ($content -like '*BVM_INSTALL_SOURCE="bun"*') { Write-Error "BVM was installed via bun."; exit 1 }
35
- }
36
-
37
30
  # --- 1. Resolve Network & BVM Version ---
38
31
  function Detect-NetworkZone {
39
32
  if ($env:BVM_REGION) { return $env:BVM_REGION }
@@ -56,11 +49,15 @@ if (-not $BVM_VER) {
56
49
  }
57
50
  Write-Host "BVM Installer ($BVM_REGION) - Resolving $BVM_VER..." -ForegroundColor Cyan
58
51
 
59
- # --- 2. Setup Directories ---
52
+ # --- 2. Setup Directories (Idempotent) ---
60
53
  $Dirs = @($BVM_DIR, $BVM_SRC_DIR, $BVM_RUNTIME_DIR, $BVM_BIN_DIR, $BVM_SHIMS_DIR, $BVM_ALIAS_DIR, $BVM_VERSIONS_DIR)
61
- foreach ($d in $Dirs) { if (-not (Test-Path $d)) { New-Item -ItemType Directory -Force -Path $d | Out-Null } }
54
+ foreach ($d in $Dirs) {
55
+ if (-not (Test-Path $d)) {
56
+ New-Item -ItemType Directory -Force -Path $d | Out-Null
57
+ }
58
+ }
62
59
 
63
- # --- 3. Download BVM Source (Needed for Smoke Test) ---
60
+ # --- 3. Download BVM Source ---
64
61
  $BVM_PLAIN_VER = $BVM_VER.TrimStart('v')
65
62
  $TARBALL_URL = "https://$REGISTRY/bvm-core/-/bvm-core-$BVM_PLAIN_VER.tgz"
66
63
  $CURL_CMD = if (Get-Command "curl.exe" -ErrorAction SilentlyContinue) { "curl.exe" } else { "curl" }
@@ -81,7 +78,7 @@ if (Test-Path "dist\index.js") {
81
78
  Remove-Item $EXT_DIR -Recurse -Force
82
79
  }
83
80
 
84
- # --- 4. Detect System Bun & Runtime Selection ---
81
+ # --- 4. Bootstrap Runtime (Using System Bun if available, READ-ONLY) ---
85
82
  $SYSTEM_BUN_BIN = Get-Command "bun" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
86
83
  $SYSTEM_BUN_VER = ""
87
84
  if ($SYSTEM_BUN_BIN) { try { $SYSTEM_BUN_VER = (bun --version) -replace "^v", "" } catch {} }
@@ -90,22 +87,20 @@ $USE_SYSTEM_AS_RUNTIME = $false
90
87
  $BUN_VER = ""
91
88
 
92
89
  if ($SYSTEM_BUN_BIN) {
93
- Write-Host "Found system Bun v$SYSTEM_BUN_VER at $SYSTEM_BUN_BIN" -ForegroundColor Gray
90
+ # We copy the system bun to BVM's internal version store for bootstrapping.
91
+ # We do NOT touch the system installation.
92
+ Write-Host "Bootstrapping with detected system Bun v$SYSTEM_BUN_VER..." -ForegroundColor Gray
94
93
  $SYS_VER_DIR = Join-Path $BVM_VERSIONS_DIR "v$SYSTEM_BUN_VER"
95
94
  $SYS_BIN_DIR = Join-Path $SYS_VER_DIR "bin"
96
95
  if (-not (Test-Path $SYS_BIN_DIR)) { New-Item -ItemType Directory -Path $SYS_BIN_DIR -Force | Out-Null }
97
96
  Copy-Item $SYSTEM_BUN_BIN (Join-Path $SYS_BIN_DIR "bun.exe") -Force
98
97
 
99
98
  # Smoke Test
100
- Write-Host "Running Smoke Test..." -ForegroundColor Gray
101
99
  $BvmIndex = Join-Path $BVM_SRC_DIR "index.js"
102
100
  & $SYSTEM_BUN_BIN $BvmIndex --version | Out-Null
103
101
  if ($LASTEXITCODE -eq 0) {
104
- Write-Host "[OK] Smoke Test passed." -ForegroundColor Green
105
102
  $USE_SYSTEM_AS_RUNTIME = $true
106
103
  $BUN_VER = "v$SYSTEM_BUN_VER"
107
- } else {
108
- Write-Host "[!] Smoke Test failed." -ForegroundColor Yellow
109
104
  }
110
105
  }
111
106
 
@@ -119,7 +114,7 @@ if ($USE_SYSTEM_AS_RUNTIME) {
119
114
  $TARGET_DIR = Join-Path $BVM_VERSIONS_DIR $BUN_VER
120
115
 
121
116
  if (-not (Test-Path (Join-Path $TARGET_DIR "bin\bun.exe"))) {
122
- Write-Host "Downloading Compatible Runtime (bun@$($BUN_VER.TrimStart('v')))..."
117
+ Write-Host "Downloading Runtime (bun@$($BUN_VER.TrimStart('v')))..."
123
118
  $URL = "https://$REGISTRY/@oven/bun-windows-x64/-/bun-windows-x64-$($BUN_VER.TrimStart('v')).tgz"
124
119
  $TMP = Join-Path $BVM_DIR "bun-runtime.tgz"
125
120
  & $CURL_CMD "-#SfLo" "$TMP" "$URL"
@@ -136,7 +131,7 @@ if ($USE_SYSTEM_AS_RUNTIME) {
136
131
  }
137
132
  }
138
133
 
139
- # --- 5. Configure Runtime & Aliases ---
134
+ # --- 5. Link Runtime ---
140
135
  $PRIVATE_RUNTIME_LINK = Join-Path $BVM_RUNTIME_DIR "current"
141
136
  if (Test-Path $PRIVATE_RUNTIME_LINK) { Remove-Item -Recurse -Force $PRIVATE_RUNTIME_LINK | Out-Null }
142
137
  New-Item -ItemType Junction -Path $PRIVATE_RUNTIME_LINK -Value $TARGET_DIR | Out-Null
@@ -147,21 +142,23 @@ New-Item -ItemType Junction -Path $USER_CURRENT_LINK -Value $TARGET_DIR | Out-Nu
147
142
 
148
143
  Set-Content -Path (Join-Path $BVM_ALIAS_DIR "default") -Value $BUN_VER -Encoding Ascii
149
144
 
150
- # --- 6. Create Shims & Wrappers ---
151
- Write-Host "Initializing shims..." -ForegroundColor Gray
145
+ # --- 6. Create Shims ---
146
+ Write-Host "Updating shims..." -ForegroundColor Gray
152
147
  $WinBvmDir = $BVM_DIR.Replace('/', '\')
153
- $BvmWrapper = "@echo off`r`nset `"BVM_DIR=$WinBvmDir`"`r`n`"%BVM_DIR%\runtime\current\bin\bun.exe`" `"%BVM_DIR%\src\index.js`" %*"
148
+ $BvmWrapper = "@echo off`r`nset `"BVM_DIR=$WinBvmDir`"`r`n`"%BVM_DIR%\runtime\current\bin\bun.exe" `"%BVM_DIR%\src\index.js" %*"
154
149
  Set-Content -Path (Join-Path $BVM_BIN_DIR "bvm.cmd") -Value $BvmWrapper -Encoding Ascii
155
150
 
156
151
  $CMD_NAMES = @("bun", "bunx")
157
152
  foreach ($name in $CMD_NAMES) {
158
153
  $tpl = "@echo off`r`nset `"BVM_DIR=$WinBvmDir`"`r`n`r`n"
159
- $tpl += "if not exist `".bvmrc`" (`r`n `"%BVM_DIR%\runtime\current\bin\bun.exe`" %*`r`n exit /b %errorlevel%`r`n)`r`n"
160
- $tpl += "`"%BVM_DIR%\runtime\current\bin\bun.exe`" `"%BVM_DIR%\bin\bvm-shim.js`" `"$name`" %*"
154
+ # Fast path: use direct runtime if no .bvmrc
155
+ $tpl += "if not exist `".bvmrc`" (`r`n `"%BVM_DIR%\runtime\current\bin\bun.exe" %*`r`n exit /b %errorlevel%`r`n)`r`n"
156
+ # Fallback: use shim
157
+ $tpl += "`"%BVM_DIR%\runtime\current\bin\bun.exe" `"%BVM_DIR%\bin\bvm-shim.js`" `"$name`" %*"
161
158
  Set-Content -Path (Join-Path $BVM_SHIMS_DIR "$name.cmd") -Value $tpl -Encoding Ascii
162
159
  }
163
160
 
164
- # --- 7. Finalize Environment ---
161
+ # --- 7. Configure Path (Prepend for Priority) ---
165
162
  $RawPath = [Environment]::GetEnvironmentVariable("Path", "User")
166
163
  $PathList = if ($RawPath) { $RawPath.Split(';') } else { @() }
167
164
  $NewPathList = @()
@@ -170,7 +167,8 @@ $FinalPath = "$BVM_SHIMS_DIR;$BVM_BIN_DIR;" + ($NewPathList -join ';')
170
167
  [Environment]::SetEnvironmentVariable("Path", $FinalPath, "User")
171
168
  $env:Path = "$BVM_SHIMS_DIR;$BVM_BIN_DIR;$env:Path"
172
169
 
170
+ # --- 8. Initialize BVM (Self-Repair) ---
173
171
  & (Join-Path $TARGET_DIR "bin\bun.exe") (Join-Path $BVM_SRC_DIR "index.js") setup --silent
174
172
 
175
173
  Write-Host "`n[OK] BVM installed successfully!" -ForegroundColor Green
176
- Write-Host "IMPORTANT: Please close this terminal and open a NEW one." -ForegroundColor Yellow
174
+ Write-Host "IMPORTANT: Please close this terminal and open a NEW one to apply changes." -ForegroundColor Cyan
package/install.sh CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/bin/bash
2
+ # Unified Installation Logic: strict isolation, idempotency.
2
3
  set -e
3
4
 
4
5
  # --- Configuration ---
@@ -15,7 +16,7 @@ else
15
16
  fi
16
17
 
17
18
  # --- Directories ---
18
- BVM_DIR="${HOME}/.bvm"
19
+ BVM_DIR="${BVM_DIR:-${HOME}/.bvm}"
19
20
  BVM_SRC_DIR="${BVM_DIR}/src"
20
21
  BVM_RUNTIME_DIR="${BVM_DIR}/runtime"
21
22
  BVM_BIN_DIR="${BVM_DIR}/bin"
@@ -74,6 +75,10 @@ detect_shell() {
74
75
  esac
75
76
  }
76
77
 
78
+ # --- Checks ---
79
+ command -v curl >/dev/null || error "curl is required."
80
+ command -v tar >/dev/null || error "tar is required."
81
+
77
82
  # --- Main Script ---
78
83
  BVM_REGION=$(detect_network_zone)
79
84
  if [ "$BVM_REGION" == "cn" ]; then
@@ -82,12 +87,11 @@ else
82
87
  REGISTRY="registry.npmjs.org"
83
88
  fi
84
89
 
85
- echo -e "${CYAN}__________ \n\______ \__ _______ \n | | _| \/ / \ \n | | \\ / Y Y \ \n |______ / \_/|__|_| / \n \/ \/ ${RESET}
86
- "
90
+ echo -e "${CYAN}__________ \n\______ \__ _______ \n | | _| \/ / \ \n | | \\ / Y Y \ \n |______ / \_/|__|_| / \n \/ \/ ${RESET}"
87
91
  echo -e "${CYAN}${BOLD}BVM Installer${RESET} ${DIM}(${BVM_REGION})${RESET}
88
92
  "
89
93
 
90
- # 1. Conflict Detection
94
+ # 1. Self-Conflict Detection (Ensure consistent install source)
91
95
  BVM_BIN_PATH="${BVM_BIN_DIR}/bvm"
92
96
  if [ -f "$BVM_BIN_PATH" ]; then
93
97
  if grep -q 'BVM_INSTALL_SOURCE="npm"' "$BVM_BIN_PATH"; then
@@ -108,7 +112,7 @@ echo -e "${GREEN}${BVM_SRC_VERSION}${RESET}"
108
112
  # 3. Setup Directories
109
113
  mkdir -p "$BVM_DIR" "$BVM_SRC_DIR" "$BVM_RUNTIME_DIR" "$BVM_BIN_DIR" "$BVM_SHIMS_DIR" "$BVM_ALIAS_DIR" "$BVM_VERSIONS_DIR"
110
114
 
111
- # 4. Download BVM Source (Needed for Smoke Test)
115
+ # 4. Download BVM Source
112
116
  if [ "$BVM_REGION" == "cn" ]; then
113
117
  TARBALL_URL="https://registry.npmmirror.com/bvm-core/-/bvm-core-${BVM_SRC_VERSION#v}.tgz"
114
118
  else
@@ -127,7 +131,7 @@ else
127
131
  fi
128
132
  chmod +x "${BVM_BIN_DIR}/bvm-shim.sh"
129
133
 
130
- # 5. Detect System Bun & Runtime Selection
134
+ # 5. Bootstrapping Runtime (Using system bun if available, READ-ONLY)
131
135
  SYSTEM_BUN_BIN=$(command -v bun || echo "")
132
136
  SYSTEM_BUN_VER=""
133
137
  [ -n "$SYSTEM_BUN_BIN" ] && SYSTEM_BUN_VER=$(bun --version | sed 's/^v//')
@@ -136,20 +140,23 @@ USE_SYSTEM_AS_RUNTIME=false
136
140
  BUN_VER=""
137
141
 
138
142
  if [ -n "$SYSTEM_BUN_BIN" ]; then
139
- info "Found system Bun v${SYSTEM_BUN_VER} at ${SYSTEM_BUN_BIN}"
140
- # Register system bun in versions
143
+ # We copy detected system bun to BVM internal versions for bootstrapping
144
+ # We never modify the system installation.
145
+ info "Bootstrapping with detected system Bun v${SYSTEM_BUN_VER}..."
141
146
  SYS_VER_DIR="${BVM_VERSIONS_DIR}/v${SYSTEM_BUN_VER}"
142
147
  mkdir -p "${SYS_VER_DIR}/bin"
143
- cp "$SYSTEM_BUN_BIN" "${SYS_VER_DIR}/bin/bun"
148
+ if [ "$SYSTEM_BUN_BIN" != "${SYS_VER_DIR}/bin/bun" ]; then
149
+ cp "$SYSTEM_BUN_BIN" "${SYS_VER_DIR}/bin/bun"
150
+ fi
144
151
  chmod +x "${SYS_VER_DIR}/bin/bun"
145
152
 
146
153
  # Smoke Test
147
- if "$SYSTEM_BUN_BIN" "${BVM_SRC_DIR}/index.js" --version >/dev/null 2>&1; then
148
- success "Smoke Test passed: System Bun is compatible."
154
+ if "${SYS_VER_DIR}/bin/bun" "${BVM_SRC_DIR}/index.js" --version >/dev/null 2>&1; then
155
+ success "Smoke Test passed."
149
156
  USE_SYSTEM_AS_RUNTIME=true
150
157
  BUN_VER="v${SYSTEM_BUN_VER}"
151
158
  else
152
- warn "Smoke Test failed: System Bun cannot run BVM core."
159
+ warn "Smoke Test failed. Will download fresh runtime."
153
160
  fi
154
161
  fi
155
162
 
@@ -180,7 +187,7 @@ else
180
187
  fi
181
188
  fi
182
189
 
183
- # 6. Configure Runtime & Aliases
190
+ # 6. Link Runtime
184
191
  rm -rf "${BVM_RUNTIME_DIR}/current"
185
192
  ln -sf "$TARGET_RUNTIME_DIR" "${BVM_RUNTIME_DIR}/current"
186
193
 
@@ -209,7 +216,7 @@ EOF
209
216
  done
210
217
  success "Shims initialized."
211
218
 
212
- # 8. Setup Environment
219
+ # 8. Setup Environment (Self-Repair)
213
220
  if ! "${BVM_BIN_DIR}/bvm" setup --silent >/dev/null 2>&1; then
214
221
  warn "Environment setup failed. You may need to manually add BVM to your PATH."
215
222
  fi
@@ -223,4 +230,4 @@ case "$CURRENT_SHELL" in
223
230
  fish) DP="$HOME/.config/fish/config.fish" ;;
224
231
  *) DP="$HOME/.profile" ;;
225
232
  esac
226
- echo -e "\nTo start using bvm:\n ${YELLOW}1. Refresh your shell:${RESET}\n source $DP\n\n ${YELLOW}2. Verify:${RESET}\n bvm --version"
233
+ echo -e "\nTo start using bvm:\n ${YELLOW}1. Refresh your shell:${RESET}\n source $DP\n\n ${YELLOW}2. Verify:${RESET}\n bvm --version"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bvm-core",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "The native version manager for Bun. Cross-platform, shell-agnostic, and zero-dependency.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -72,10 +72,10 @@
72
72
  "typescript": "^5"
73
73
  },
74
74
  "bvm_fingerprints": {
75
- "cli": "302bb3dee56d88ad9c506d2d3638c07c",
75
+ "cli": "f1506d9f4b767a0dc43b43beed1fcd43",
76
76
  "shim_win": "c6f43afddfb205e130633fe00ee860d8",
77
77
  "shim_unix": "8aa89a0324b52c9c81b96c0c03afe36c",
78
- "install_sh": "2f4a13e4e0837640678c6d5178eae4ed",
79
- "install_ps1": "b9df4fa27f183bcfbb1342bc1f530ded"
78
+ "install_sh": "3cd01dd683bf00b522f9ec33e2e90d8a",
79
+ "install_ps1": "a128340f7b24f3c8733c16b4215243fa"
80
80
  }
81
81
  }
@@ -127,13 +127,17 @@ function createWrappers() {
127
127
  const bvmBin = path.join(BVM_BIN_DIR, IS_WINDOWS ? 'bvm.cmd' : 'bvm');
128
128
  const bvmDirWin = BVM_DIR.replace(/\//g, '\\');
129
129
  const entryPath = path.join(PKG_ROOT, 'bin', 'bvm-npm.js');
130
+ const bvmSrc = path.join(BVM_DIR, 'src', 'index.js');
131
+ const bunkerBun = path.join(BVM_DIR, 'runtime', 'current', 'bin', IS_WINDOWS ? 'bun.exe' : 'bun');
132
+ const bunkerBunWin = bunkerBun.replace(/\//g, '\\');
133
+ const bvmSrcWin = bvmSrc.replace(/\//g, '\\');
130
134
 
131
135
  if (IS_WINDOWS) {
132
- const content = `@echo off\r\nset "BVM_DIR=${bvmDirWin}"\r\nnode "${entryPath}" %*`;
136
+ const content = `@echo off\r\nset "BVM_DIR=${bvmDirWin}"\r\nif exist "${bunkerBunWin}" (\r\n "${bunkerBunWin}" "${bvmSrcWin}" %*\r\n) else (\r\n node "${entryPath}" %*\r\n)`;
133
137
  fs.writeFileSync(bvmBin, content);
134
138
  fs.writeFileSync(path.join(BVM_BIN_DIR, 'bvm'), '# BVM Windows Shim\n');
135
139
  } else {
136
- const content = `#!/bin/bash\nexport BVM_DIR="${BVM_DIR}"\nnode "${entryPath}" "$@"`;
140
+ const content = `#!/bin/bash\nexport BVM_DIR="${BVM_DIR}"\nif [ -f "${bunkerBun}" ]; then\n exec "${bunkerBun}" "${bvmSrc}" "$@"\nelse\n node "${entryPath}" "$@"\nfi`;
137
141
  fs.writeFileSync(bvmBin, content);
138
142
  fs.chmodSync(bvmBin, 0o755);
139
143
  }
@@ -169,9 +173,17 @@ function main() {
169
173
  const verDir = path.join(BVM_DIR, 'versions', ver);
170
174
 
171
175
  // Register anyway to preserve user's version
172
- if (!fs.existsSync(path.join(verDir, 'bin'))) {
173
- fs.mkdirSync(path.join(verDir, 'bin'), { recursive: true });
174
- fs.copyFileSync(binPath, path.join(verDir, 'bin', IS_WINDOWS ? 'bun.exe' : 'bun'));
176
+ const binDir = path.join(verDir, 'bin');
177
+ if (!fs.existsSync(binDir)) {
178
+ fs.mkdirSync(binDir, { recursive: true });
179
+ const destBin = path.join(binDir, IS_WINDOWS ? 'bun.exe' : 'bun');
180
+ try {
181
+ if (path.resolve(binPath) !== path.resolve(destBin)) {
182
+ fs.copyFileSync(binPath, destBin);
183
+ }
184
+ } catch (e) {
185
+ error(`Failed to copy system Bun: ${e.message}`);
186
+ }
175
187
  }
176
188
 
177
189
  const test = run(binPath, [path.join(BVM_SRC_DIR, 'index.js'), '--version'], { env: { BVM_DIR } });
@@ -191,7 +203,12 @@ function main() {
191
203
 
192
204
  createWrappers();
193
205
  const bvmBin = path.join(BVM_BIN_DIR, IS_WINDOWS ? 'bvm.cmd' : 'bvm');
194
- run(bvmBin, ['setup', '--silent'], { env: { BVM_DIR } });
206
+ const setupResult = run(bvmBin, ['setup', '--silent'], { env: { BVM_DIR } });
207
+ if (setupResult.status !== 0) {
208
+ error(`bvm setup failed with exit code ${setupResult.status}`);
209
+ if (setupResult.stderr) console.error(setupResult.stderr);
210
+ process.exit(1);
211
+ }
195
212
  log('🎉 BVM initialized successfully.');
196
213
  }
197
214