bvm-core 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  var i1=Object.create;var{getPrototypeOf:o1,defineProperty:M$,getOwnPropertyNames:a1}=Object;var s1=Object.prototype.hasOwnProperty;var W$=($,q,Q)=>{Q=$!=null?i1(o1($)):{};let J=q||!$||!$.__esModule?M$(Q,"default",{value:$,enumerable:!0}):Q;for(let Z of a1($))if(!s1.call(J,Z))M$(J,Z,{get:()=>$[Z],enumerable:!0});return J};var s$=($,q)=>{for(var Q in q)M$($,Q,{get:q[Q],enumerable:!0,configurable:!0,set:(J)=>q[Q]=()=>J})};var y$=($,q)=>()=>($&&(q=$($=0)),q);var U$=import.meta.require;var e$={};s$(e$,{getBvmDir:()=>r$,getBunAssetName:()=>T$,USER_AGENT:()=>J$,TEST_REMOTE_VERSIONS:()=>X$,REPO_FOR_BVM_CLI:()=>s,OS_PLATFORM:()=>D,IS_TEST_MODE:()=>T,EXECUTABLE_NAME:()=>A,CPU_ARCH:()=>x$,BVM_VERSIONS_DIR:()=>L,BVM_SRC_DIR:()=>$4,BVM_SHIMS_DIR:()=>E,BVM_FINGERPRINTS_FILE:()=>z$,BVM_DIR:()=>k,BVM_CURRENT_DIR:()=>b$,BVM_COMPONENTS:()=>f$,BVM_CDN_ROOT:()=>w$,BVM_CACHE_DIR:()=>v,BVM_BIN_DIR:()=>M,BVM_ALIAS_DIR:()=>j,BUN_GITHUB_RELEASES_API:()=>q4,ASSET_NAME_FOR_BVM:()=>B$});import{homedir as e1}from"os";import{join as n}from"path";function r$(){let $=process.env.HOME||e1();return n($,".bvm")}function T$($){return`bun-${D==="win32"?"windows":D}-${x$==="arm64"?"aarch64":"x64"}.zip`}var D,x$,T,X$,k,$4,L,M,E,b$,j,v,z$,A,q4="https://api.github.com/repos/oven-sh/bun/releases",s="EricLLLLLL/bvm",B$,J$="bvm (Bun Version Manager)",w$,f$;var N=y$(()=>{D=process.platform,x$=process.arch,T=process.env.BVM_TEST_MODE==="true",X$=["v1.3.4","v1.2.23","v1.0.0","bun-v1.4.0-canary"];k=r$(),$4=n(k,"src"),L=n(k,"versions"),M=n(k,"bin"),E=n(k,"shims"),b$=n(k,"current"),j=n(k,"aliases"),v=n(k,"cache"),z$=n(k,"fingerprints.json"),A=D==="win32"?"bun.exe":"bun",B$=D==="win32"?"bvm.exe":"bvm",w$=process.env.BVM_CDN_URL||"https://cdn.jsdelivr.net/gh/EricLLLLLL/bvm",f$=[{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 V($){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 $1($){let q=V($);return q?q.replace(/^v/,""):null}function Y$($){if(!$)return null;let q=$.replace(/^v/,""),J=q.split(/[-+]/)[0].split(".").map(Number);if(J.length===0||J.some((Y)=>isNaN(Y)))return null;let Z=q.includes("-")?q.split("-")[1].split("+")[0]:void 0;return{major:J[0],minor:J[1],patch:J[2],pre:Z}}function R$($,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 q1($,q){let Q=Y$($),J=Y$(q);return R$(Q,J)}function Z$($,q){return q1(q,$)}function C$($,q){return q1($,q)>0}function Q1($,q){if(q==="*"||q===""||q==="latest")return!0;let Q=Y$($);if(!Q)return!1;let J=q;if(q.startsWith("v"))J=q.substring(1);if($1($)===$1(q))return!0;let Z=J.split(".");if(Z.length===1){let Y=Number(Z[0]);if(Q.major===Y)return!0}else if(Z.length===2){let Y=Number(Z[0]),X=Number(Z[1]);if(Q.major===Y&&Q.minor===X)return!0}if(q.startsWith("~")){let Y=Y$(q.substring(1));if(!Y)return!1;let X=Y.patch??0;return Q.major===Y.major&&Q.minor===Y.minor&&Q.patch>=X}if(q.startsWith("^")){let Y=Y$(q.substring(1));if(!Y)return!1;let X=Y.patch??0,b=Y.minor??0;if(Y.major===0){if(Q.major!==0)return!1;if(Q.minor!==b)return!1;return Q.patch>=X}if(Q.major!==Y.major)return!1;if(Q.minor<b)return!1;if(Q.minor===b&&Q.patch<X)return!1;return!0}return!1}import{readdir as J4,mkdir as Y4,stat as Z4,symlink as K4,unlink as J1,rm as Y1,readlink as X4}from"fs/promises";import{join as j$,dirname as b4,basename as G4}from"path";async function O($){await Y4($,{recursive:!0})}async function G($){try{return await Z4($),!0}catch(q){if(q.code==="ENOENT")return!1;throw q}}async function Z1($,q){try{await J1(q)}catch(J){try{await Y1(q,{recursive:!0,force:!0})}catch(Z){}}let Q=process.platform==="win32"?"junction":"dir";await K4($,q,Q)}async function K1($){try{return await X4($)}catch(q){if(q.code==="ENOENT"||q.code==="EINVAL")return null;throw q}}async function r($){await Y1($,{recursive:!0,force:!0})}async function c($){try{return await J4($)}catch(q){if(q.code==="ENOENT")return[];throw q}}async function R($){return await Bun.file($).text()}async function i($,q){await Bun.write($,q)}async function X1($,q,Q={}){let{backup:J=!0}=Q,Z=b4($);await O(Z);let Y=`${$}.tmp-${Date.now()}`,X=`${$}.bak`;try{if(await i(Y,q),J&&await G($))try{let{rename:W,unlink:z}=await import("fs/promises");if(await G(X))await z(X).catch(()=>{});await W($,X)}catch(W){}let{rename:b}=await import("fs/promises");try{await b(Y,$)}catch(W){await Bun.write($,q),await J1(Y).catch(()=>{})}}catch(b){let{unlink:W}=await import("fs/promises");throw await W(Y).catch(()=>{}),b}}function y($){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 O(L),(await c(L)).filter((q)=>V(y(q))).sort(Z$)}async function p(){if(process.env.BVM_ACTIVE_VERSION)return{version:y(process.env.BVM_ACTIVE_VERSION),source:"env"};let $=j$(process.cwd(),".bvmrc");if(await G($)){let X=(await R($)).trim();return{version:y(X),source:".bvmrc"}}let{getBvmDir:q}=await Promise.resolve().then(() => (N(),e$)),Q=q(),J=j$(Q,"current"),Z=j$(Q,"aliases");if(await G(J)){let{realpath:X}=await import("fs/promises");try{let b=await X(J);return{version:y(G4(b)),source:"current"}}catch(b){}}let Y=j$(Z,"default");if(await G(Y)){let X=(await R(Y)).trim();return{version:y(X),source:"default"}}return{version:null,source:null}}function e($,q){if(!$||q.length===0)return null;let Q=y($);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 Z=$.startsWith("v")?`~${$.substring(1)}`:`~${$}`,Y=q.filter((X)=>Q1(X,Z));if(Y.length>0)return Y.sort(Z$)[0];return null}var C=y$(()=>{N()});import{createInterface as H4}from"readline";class S${timer=null;frames=process.platform==="win32"?["-"]:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];frameIndex=0;text;isWindows=process.platform==="win32";constructor($){this.text=$}start($){if($)this.text=$;if(this.timer)return;if(this.isWindows){process.stdout.write(`${K.cyan(">")} ${this.text}
3
3
  `);return}this.timer=setInterval(()=>{process.stdout.write(`\r\x1B[K${K.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(`${K.green(" \u2713")} ${$||this.text}`)}fail($){this.stop(),console.log(`${K.red(" \u2716")} ${$||this.text}`)}info($){this.stop(),console.log(`${K.blue(" \u2139")} ${$||this.text}`)}update($){if(this.text=$,this.isWindows)console.log(K.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
4
- `)}render($){let q=Math.min(1,this.current/this.total),Q=Math.round(this.width*q),J=this.width-Q,Z=process.platform==="win32",Y=Z?"=":"\u2588",X=Z?"-":"\u2591",b=K.green(Y.repeat(Q))+K.gray(X.repeat(J)),W=(q*100).toFixed(0).padStart(3," "),z=(this.current/1048576).toFixed(1),w=(this.total/1048576).toFixed(1),H=$?` ${$.speed}KB/s`:"";process.stdout.write(`\r\x1B[2K ${b} ${W}% | ${z}/${w}MB${H}`)}}async function b1($){let q=H4({input:process.stdin,output:process.stdout});return new Promise((Q)=>{q.question(`${K.yellow("?")} ${$} (Y/n) `,(J)=>{q.close(),Q(J.toLowerCase()!=="n")})})}var W4,y4=($)=>$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=($,q,Q=$)=>(J)=>W4?$+J.replace(new RegExp(y4(q),"g"),Q)+q:J,K;var F=y$(()=>{W4=!process.env.NO_COLOR,K={red:o("\x1B[1;31m","\x1B[39m"),green:o("\x1B[1;32m","\x1B[39m"),yellow:o("\x1B[1;33m","\x1B[39m"),blue:o("\x1B[1;34m","\x1B[39m"),magenta:o("\x1B[1;35m","\x1B[39m"),cyan:o("\x1B[1;36m","\x1B[39m"),gray:o("\x1B[90m","\x1B[39m"),bold:o("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:o("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m")}});async function U($,q,Q){if(process.platform==="win32"){console.log(K.cyan(`> ${$}`));let Y={start:(X)=>{if(X)console.log(K.cyan(`> ${X}`))},stop:()=>{},succeed:(X)=>console.log(K.green(` \u2713 ${X}`)),fail:(X)=>console.log(K.red(` \u2716 ${X}`)),info:(X)=>console.log(K.cyan(` \u2139 ${X}`)),update:(X)=>console.log(K.dim(` ... ${X}`)),isSpinning:!1};try{return await q(Y)}catch(X){let b=k1(X,Q?.failMessage);if(console.log(K.red(` \u2716 ${b}`)),process.env.BVM_DEBUG,console.log(K.dim(` Details: ${X.message}`)),X.code)console.log(K.dim(` Code: ${X.code}`));throw X.reported=!0,X}}let Z=new S$($);Z.start();try{let Y=await q(Z);return Z.stop(),Y}catch(Y){let X=k1(Y,Q?.failMessage);throw Z.fail(K.red(X)),Y.reported=!0,Y}}function k1($,q){let Q=$ instanceof Error?$.message:String($);if(!q)return Q;if(typeof q==="function")return q($);return`${q}: ${Q}`}var f=y$(()=>{F()});var L1={};s$(L1,{resolveLocalVersion:()=>d,displayVersion:()=>h$});import{join as P4}from"path";async function d($){if($==="current"){let{version:Z}=await p();return Z}if($==="latest"){let Z=await u();if(Z.length>0)return Z[0];return null}let q=P4(j,$);if(await G(q))try{let Z=(await R(q)).trim();return y(Z)}catch{return null}let Q=y($),J=await u();return e($,J)}async function h$($){await U(`Resolving version '${$}'...`,async()=>{let q=await d($);if(q)console.log(q);else throw Error("N/A")},{failMessage:`Failed to resolve version '${$}'`})}var q$=y$(()=>{N();C();f()});import{parseArgs as K6}from"util";var K$={name:"bvm-core",version:"1.1.3",description:"The native version manager for Bun. Cross-platform, shell-agnostic, and zero-dependency.",main:"dist/index.js",bin:{bvm:"dist/index.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","sync-runtime":"bun run scripts/sync-runtime.ts"},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","install.sh","install.ps1","README.md"],author:"EricLLLLLL",license:"MIT",type:"commonjs",dependencies:{"@oven/bun-darwin-aarch64":"^1.3.5","cli-progress":"^3.12.0"},devDependencies:{"@types/bun":"^1.3.4","@types/cli-progress":"^3.11.6","@types/node":"^24.10.2",bun:"^1.3.5",esbuild:"^0.27.2",execa:"^9.6.1",typescript:"^5"},peerDependencies:{typescript:"^5"}};N();C();import{join as t,basename as g4,dirname as h4}from"path";N();C();F();import{join as z4}from"path";function G1($,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 H1($,q,Q){let J=Q;if(!J.endsWith("/"))J+="/";let Z=$.startsWith("@"),Y=$;if(Z){let b=$.split("/");if(b.length===2)Y=b[1]}let X=`${Y}-${q}.tgz`;return`${J}${$}/-/${X}`}F();async function a($,q={}){let{cwd:Q,env:J,prependPath:Z,stdin:Y="inherit",stdout:X="inherit",stderr:b="inherit"}=q,W={...process.env,...J};if(Z){let H=W.PATH||"",x=process.platform==="win32"?";":":";W.PATH=`${Z}${x}${H}`}let w=await Bun.spawn({cmd:$,cwd:Q,env:W,stdin:Y,stdout:X,stderr:b}).exited;if((w??0)!==0)throw Error(`${K.red("Command failed")}: ${$.join(" ")} (code ${w})`);return w??0}async function g($,q={}){let{timeout:Q=5000,...J}=q,Z=new AbortController,Y=setTimeout(()=>Z.abort(),Q);try{let X=await fetch($,{...J,signal:Z.signal});return clearTimeout(Y),X}catch(X){if(clearTimeout(Y),X.name==="AbortError")throw Error(`Request to ${$} timed out after ${Q}ms`);throw X}}async function U4($,q=2000){if($.length===0)throw Error("No URLs to race");if($.length===1)return $[0];return new Promise((Q,J)=>{let Z=0,Y=!1;$.forEach((X)=>{g(X,{method:"HEAD",timeout:q}).then((b)=>{if(b.ok&&!Y)Y=!0,Q(X);else if(!Y){if(Z++,Z===$.length)J(Error("All requests failed"))}}).catch(()=>{if(!Y){if(Z++,Z===$.length)J(Error("All requests failed"))}})})})}async function x4(){try{let $=await g("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,k$={NPM:"https://registry.npmjs.org",TAOBAO:"https://registry.npmmirror.com",TENCENT:"https://mirrors.cloud.tencent.com/npm/"};async function L$(){if(E$)return E$;let $=await x4(),q=[];if($==="CN")q=[k$.TAOBAO,k$.TENCENT,k$.NPM];else q=[k$.NPM,k$.TAOBAO];try{let Q=await U4(q,2000);return E$=Q,Q}catch(Q){return q[0]}}C();var w4="bun-versions.json",k4=3600000;async function L4(){if(T)return[...X$];let $=z4(v,w4);try{if(await G($)){let Z=await R($),Y=JSON.parse(Z);if(Date.now()-Y.timestamp<k4&&Array.isArray(Y.versions))return Y.versions}}catch(Z){}let q=await L$(),Q=[q];if(q!=="https://registry.npmjs.org")Q.push("https://registry.npmjs.org");let J=null;for(let Z of Q){let Y=`${Z.replace(/\/$/,"")}/bun`;try{let X=await g(Y,{headers:{"User-Agent":J$,Accept:"application/vnd.npm.install-v1+json"},timeout:1e4});if(!X.ok)throw Error(`Status ${X.status}`);let b=await X.json();if(!b.versions)throw Error("Invalid response (no versions)");let W=Object.keys(b.versions);try{await O(v),await i($,JSON.stringify({timestamp:Date.now(),versions:W}))}catch(z){}return W}catch(X){J=X}}throw J||Error("Failed to fetch versions from any registry.")}async function O4(){if(T)return[...X$];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"}),Z=setTimeout(()=>{J.kill(),q(Error("Git operation timed out"))},1e4);new Response(J.stdout).text().then((X)=>{clearTimeout(Z);let b=X.split(`
4
+ `)}render($){let q=Math.min(1,this.current/this.total),Q=Math.round(this.width*q),J=this.width-Q,Z=process.platform==="win32",Y=Z?"=":"\u2588",X=Z?"-":"\u2591",b=K.green(Y.repeat(Q))+K.gray(X.repeat(J)),W=(q*100).toFixed(0).padStart(3," "),z=(this.current/1048576).toFixed(1),w=(this.total/1048576).toFixed(1),H=$?` ${$.speed}KB/s`:"";process.stdout.write(`\r\x1B[2K ${b} ${W}% | ${z}/${w}MB${H}`)}}async function b1($){let q=H4({input:process.stdin,output:process.stdout});return new Promise((Q)=>{q.question(`${K.yellow("?")} ${$} (Y/n) `,(J)=>{q.close(),Q(J.toLowerCase()!=="n")})})}var W4,y4=($)=>$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=($,q,Q=$)=>(J)=>W4?$+J.replace(new RegExp(y4(q),"g"),Q)+q:J,K;var F=y$(()=>{W4=!process.env.NO_COLOR,K={red:o("\x1B[1;31m","\x1B[39m"),green:o("\x1B[1;32m","\x1B[39m"),yellow:o("\x1B[1;33m","\x1B[39m"),blue:o("\x1B[1;34m","\x1B[39m"),magenta:o("\x1B[1;35m","\x1B[39m"),cyan:o("\x1B[1;36m","\x1B[39m"),gray:o("\x1B[90m","\x1B[39m"),bold:o("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:o("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m")}});async function U($,q,Q){if(process.platform==="win32"){console.log(K.cyan(`> ${$}`));let Y={start:(X)=>{if(X)console.log(K.cyan(`> ${X}`))},stop:()=>{},succeed:(X)=>console.log(K.green(` \u2713 ${X}`)),fail:(X)=>console.log(K.red(` \u2716 ${X}`)),info:(X)=>console.log(K.cyan(` \u2139 ${X}`)),update:(X)=>console.log(K.dim(` ... ${X}`)),isSpinning:!1};try{return await q(Y)}catch(X){let b=k1(X,Q?.failMessage);if(console.log(K.red(` \u2716 ${b}`)),process.env.BVM_DEBUG,console.log(K.dim(` Details: ${X.message}`)),X.code)console.log(K.dim(` Code: ${X.code}`));throw X.reported=!0,X}}let Z=new S$($);Z.start();try{let Y=await q(Z);return Z.stop(),Y}catch(Y){let X=k1(Y,Q?.failMessage);throw Z.fail(K.red(X)),Y.reported=!0,Y}}function k1($,q){let Q=$ instanceof Error?$.message:String($);if(!q)return Q;if(typeof q==="function")return q($);return`${q}: ${Q}`}var f=y$(()=>{F()});var L1={};s$(L1,{resolveLocalVersion:()=>d,displayVersion:()=>h$});import{join as P4}from"path";async function d($){if($==="current"){let{version:Z}=await p();return Z}if($==="latest"){let Z=await u();if(Z.length>0)return Z[0];return null}let q=P4(j,$);if(await G(q))try{let Z=(await R(q)).trim();return y(Z)}catch{return null}let Q=y($),J=await u();return e($,J)}async function h$($){await U(`Resolving version '${$}'...`,async()=>{let q=await d($);if(q)console.log(q);else throw Error("N/A")},{failMessage:`Failed to resolve version '${$}'`})}var q$=y$(()=>{N();C();f()});import{parseArgs as K6}from"util";var K$={name:"bvm-core",version:"1.1.4",description:"The native version manager for Bun. Cross-platform, shell-agnostic, and zero-dependency.",main:"dist/index.js",bin:{bvm:"dist/index.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","sync-runtime":"bun run scripts/sync-runtime.ts"},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","install.sh","install.ps1","README.md"],author:"EricLLLLLL",license:"MIT",type:"commonjs",dependencies:{"@oven/bun-darwin-aarch64":"^1.3.5","cli-progress":"^3.12.0"},devDependencies:{"@types/bun":"^1.3.4","@types/cli-progress":"^3.11.6","@types/node":"^24.10.2",bun:"^1.3.5",esbuild:"^0.27.2",execa:"^9.6.1",typescript:"^5"},peerDependencies:{typescript:"^5"}};N();C();import{join as t,basename as g4,dirname as h4}from"path";N();C();F();import{join as z4}from"path";function G1($,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 H1($,q,Q){let J=Q;if(!J.endsWith("/"))J+="/";let Z=$.startsWith("@"),Y=$;if(Z){let b=$.split("/");if(b.length===2)Y=b[1]}let X=`${Y}-${q}.tgz`;return`${J}${$}/-/${X}`}F();async function a($,q={}){let{cwd:Q,env:J,prependPath:Z,stdin:Y="inherit",stdout:X="inherit",stderr:b="inherit"}=q,W={...process.env,...J};if(Z){let H=W.PATH||"",x=process.platform==="win32"?";":":";W.PATH=`${Z}${x}${H}`}let w=await Bun.spawn({cmd:$,cwd:Q,env:W,stdin:Y,stdout:X,stderr:b}).exited;if((w??0)!==0)throw Error(`${K.red("Command failed")}: ${$.join(" ")} (code ${w})`);return w??0}async function g($,q={}){let{timeout:Q=5000,...J}=q,Z=new AbortController,Y=setTimeout(()=>Z.abort(),Q);try{let X=await fetch($,{...J,signal:Z.signal});return clearTimeout(Y),X}catch(X){if(clearTimeout(Y),X.name==="AbortError")throw Error(`Request to ${$} timed out after ${Q}ms`);throw X}}async function U4($,q=2000){if($.length===0)throw Error("No URLs to race");if($.length===1)return $[0];return new Promise((Q,J)=>{let Z=0,Y=!1;$.forEach((X)=>{g(X,{method:"HEAD",timeout:q}).then((b)=>{if(b.ok&&!Y)Y=!0,Q(X);else if(!Y){if(Z++,Z===$.length)J(Error("All requests failed"))}}).catch(()=>{if(!Y){if(Z++,Z===$.length)J(Error("All requests failed"))}})})})}async function x4(){try{let $=await g("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,k$={NPM:"https://registry.npmjs.org",TAOBAO:"https://registry.npmmirror.com",TENCENT:"https://mirrors.cloud.tencent.com/npm/"};async function L$(){if(E$)return E$;let $=await x4(),q=[];if($==="CN")q=[k$.TAOBAO,k$.TENCENT,k$.NPM];else q=[k$.NPM,k$.TAOBAO];try{let Q=await U4(q,2000);return E$=Q,Q}catch(Q){return q[0]}}C();var w4="bun-versions.json",k4=3600000;async function L4(){if(T)return[...X$];let $=z4(v,w4);try{if(await G($)){let Z=await R($),Y=JSON.parse(Z);if(Date.now()-Y.timestamp<k4&&Array.isArray(Y.versions))return Y.versions}}catch(Z){}let q=await L$(),Q=[q];if(q!=="https://registry.npmjs.org")Q.push("https://registry.npmjs.org");let J=null;for(let Z of Q){let Y=`${Z.replace(/\/$/,"")}/bun`;try{let X=await g(Y,{headers:{"User-Agent":J$,Accept:"application/vnd.npm.install-v1+json"},timeout:1e4});if(!X.ok)throw Error(`Status ${X.status}`);let b=await X.json();if(!b.versions)throw Error("Invalid response (no versions)");let W=Object.keys(b.versions);try{await O(v),await i($,JSON.stringify({timestamp:Date.now(),versions:W}))}catch(z){}return W}catch(X){J=X}}throw J||Error("Failed to fetch versions from any registry.")}async function O4(){if(T)return[...X$];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"}),Z=setTimeout(()=>{J.kill(),q(Error("Git operation timed out"))},1e4);new Response(J.stdout).text().then((X)=>{clearTimeout(Z);let b=X.split(`
5
5
  `);for(let W of b){let z=W.match(/refs\/tags\/bun-v?(\d+\.\d+\.\d+.*)$/);if(z)Q.push(z[1])}$(Q)}).catch((X)=>{clearTimeout(Z),q(X)})}catch(J){q(Error(`Failed to run git: ${J.message}`))}})}async function W1(){if(T)return[...X$];try{let q=(await L4()).filter((Q)=>V(Q)).map((Q)=>({v:Q,parsed:Y$(Q)}));return q.sort((Q,J)=>R$(J.parsed,Q.parsed)),q.map((Q)=>Q.v)}catch($){try{let q=await O4();if(q.length>0)return Array.from(new Set(q.filter((J)=>V(J)))).sort(Z$);throw Error("No versions found via Git")}catch(q){throw Error(`Failed to fetch versions. NPM: ${$.message}. Git: ${q.message}`)}}}async function y1($){if(T)return X$.includes($)||$==="latest";let q=await L$(),Q=$.replace(/^v/,""),J=`${q}/bun/${Q}`,Z=D==="win32"?"curl.exe":"curl",Y=async()=>{try{return await a([Z,"-I","-f","-m","5","-s",J],{stdout:"ignore",stderr:"ignore"}),!0}catch(b){return!1}},X=new Promise((b)=>setTimeout(()=>b(!1),1e4));return Promise.race([Y(),X])}async function U1(){if(T)return{latest:"1.1.20"};let q=`${await L$()}/-/package/bun/dist-tags`;try{let Q=await g(q,{headers:{"User-Agent":J$},timeout:5000});if(Q.ok)return await Q.json()}catch(Q){}return{}}async function x1($){let q=y($);if(!V(q))return console.error(K.red(`Invalid version provided to findBunDownloadUrl: ${$}`)),null;if(T)return{url:`https://example.com/${T$(q)}`,foundVersion:q};let Z=G1(D==="win32"?"win32":D,x$==="arm64"?"arm64":"x64");if(!Z)throw Error(`Unsupported platform/arch for NPM download: ${D}-${x$}`);let Y="";if(process.env.BVM_REGISTRY)Y=process.env.BVM_REGISTRY;else if(process.env.BVM_DOWNLOAD_MIRROR)Y=process.env.BVM_DOWNLOAD_MIRROR;else Y=await L$();let X=q.replace(/^v/,"");return{url:H1(Z,X,Y),foundVersion:q}}async function F$(){let $=B$;try{let J=await g(`https://cdn.jsdelivr.net/gh/${s}@latest/package.json`,{headers:{"User-Agent":J$},timeout:2000});if(J.ok){let Z=await J.json();if(Z&&Z.version){let Y=`v${Z.version}`;return{tagName:Y,downloadUrl:`https://github.com/${s}/releases/download/${Y}/${$}`}}}}catch(J){}try{let J=`https://github.com/${s}/releases/latest`,Z=await g(J,{method:"HEAD",redirect:"manual",headers:{"User-Agent":J$},timeout:2000});if(Z.status===302||Z.status===301){let Y=Z.headers.get("location");if(Y){let X=Y.split("/"),b=X[X.length-1];if(b&&V(b))return{tagName:b,downloadUrl:`https://github.com/${s}/releases/download/${b}/${$}`}}}}catch(J){}let q={"User-Agent":J$},Q=`https://api.github.com/repos/${s}/releases/latest`;try{let J=await g(Q,{headers:q,timeout:2000});if(!J.ok)return null;let Y=(await J.json()).tag_name,X=`https://github.com/${s}/releases/download/${Y}/${$}`;return{tagName:Y,downloadUrl:X}}catch(J){return null}}F();N();import{spawn as C4}from"child_process";async function z1($,q){if($.endsWith(".zip"))if(D==="win32")await a(["powershell","-Command",`Expand-Archive -Path "${$}" -DestinationPath "${q}" -Force`],{stdout:"ignore",stderr:"inherit"});else await a(["unzip","-o","-q",$,"-d",q],{stdout:"ignore",stderr:"inherit"});else if($.endsWith(".tar.gz")||$.endsWith(".tgz"))await new Promise((Q,J)=>{let Z=C4("tar",["-xzf",$,"-C",q],{stdio:"inherit",shell:!1});Z.on("close",(Y)=>{if(Y===0)Q();else J(Error(`tar exited with code ${Y}`))}),Z.on("error",(Y)=>J(Y))});else throw Error(`Unsupported archive format: ${$}`)}import{chmod as c$}from"fs/promises";C();N();F();import{join as B,dirname as f4,delimiter as T4}from"path";import{homedir as $$}from"os";import{chmod as O$}from"fs/promises";var v$=`#!/bin/bash
6
6
 
7
7
  # bvm-init.sh: Initializes bvm default version on shell startup
package/install.ps1 CHANGED
@@ -44,7 +44,7 @@ $CURL_CMD = "curl.exe"
44
44
  if (-not (Get-Command $CURL_CMD -ErrorAction SilentlyContinue)) { $CURL_CMD = "curl" }
45
45
 
46
46
  # --- 1. Resolve BVM and Bun Versions ---
47
- $DEFAULT_BVM_VER = "v1.1.3"
47
+ $DEFAULT_BVM_VER = "v1.1.4"
48
48
  $BVM_VER = if ($env:BVM_INSTALL_VERSION) { $env:BVM_INSTALL_VERSION } else { "" }
49
49
 
50
50
  # Resolve BVM Version dynamically if not provided
@@ -127,24 +127,36 @@ if ($IsWin) {
127
127
  New-Item -ItemType SymbolicLink -Path $CURRENT_LINK -Target $RUNTIME_VER_DIR -Force | Out-Null
128
128
  }
129
129
 
130
- # --- 5. Download BVM Source & Shim ---
130
+ # --- 5. Download BVM Source & Shim (Tarball Strategy) ---
131
131
  $BVM_PLAIN_VER = $BVM_VER.TrimStart('v')
132
- $BASE_URL = "$NPM_CDN/bvm-core@$BVM_PLAIN_VER"
132
+ if ($BVM_REGION -eq "cn") {
133
+ $TARBALL_URL = "https://registry.npmmirror.com/bvm-core/-/bvm-core-$BVM_PLAIN_VER.tgz"
134
+ } else {
135
+ $TARBALL_URL = "https://registry.npmjs.org/bvm-core/-/bvm-core-$BVM_PLAIN_VER.tgz"
136
+ }
133
137
 
134
138
  $LOCAL_DIST = Join-Path $PSScriptRoot "dist"
135
- $INDEX_JS = Join-Path $LOCAL_DIST "index.js"
136
- if (Test-Path $INDEX_JS) {
137
- Copy-Item $INDEX_JS (Join-Path $BVM_SRC_DIR "index.js") -Force
138
- $SHIM_JS_SRC = Join-Path $LOCAL_DIST "bvm-shim.js"
139
- if (Test-Path $SHIM_JS_SRC) {
140
- Copy-Item $SHIM_JS_SRC (Join-Path $BVM_BIN_DIR "bvm-shim.js") -Force
141
- }
139
+ if (Test-Path $LOCAL_DIST) {
140
+ Copy-Item $LOCAL_DIST\* (Join-Path $BVM_SRC_DIR) -Recurse -Force
141
+ Write-Host "Using local BVM source from dist/." -ForegroundColor Gray
142
142
  } else {
143
- Write-Host "Downloading BVM Source & Shim $BVM_VER..."
144
- $SRC_URL = "$BASE_URL/dist/index.js"
145
- $SHIM_URL = "$BASE_URL/dist/bvm-shim.js"
146
- & $CURL_CMD "-#SfLo" (Join-Path $BVM_SRC_DIR "index.js") "$SRC_URL"
147
- & $CURL_CMD "-#SfLo" (Join-Path $BVM_BIN_DIR "bvm-shim.js") "$SHIM_URL"
143
+ Write-Host "Downloading BVM Tarball $BVM_VER..."
144
+ $TMP_TGZ = Join-Path $BVM_DIR "bvm-core.tgz"
145
+ & $CURL_CMD "-#SfLo" "$TMP_TGZ" "$TARBALL_URL"
146
+
147
+ $EXT_DIR = Join-Path $BVM_DIR "temp_bvm_extract"
148
+ if (Test-Path $EXT_DIR) { Remove-Item $EXT_DIR -Recurse -Force }
149
+ New-Item -ItemType Directory -Path $EXT_DIR | Out-Null
150
+
151
+ Write-Host "Extracting BVM assets..."
152
+ & tar -xf "$TMP_TGZ" -C "$EXT_DIR"
153
+
154
+ # NPM tarballs put everything in 'package/'
155
+ Copy-Item (Join-Path $EXT_DIR "package\dist\index.js") (Join-Path $BVM_SRC_DIR "index.js") -Force
156
+ Copy-Item (Join-Path $EXT_DIR "package\dist\bvm-shim.js") (Join-Path $BVM_BIN_DIR "bvm-shim.js") -Force
157
+
158
+ Remove-Item $TMP_TGZ -Force
159
+ Remove-Item $EXT_DIR -Recurse -Force
148
160
  }
149
161
 
150
162
  # --- 6. Bootstrap Shims (Pure PowerShell, No index.js dependency) ---
package/install.sh CHANGED
@@ -2,7 +2,7 @@
2
2
  set -e
3
3
 
4
4
  # --- Configuration ---
5
- DEFAULT_BVM_VERSION="v1.1.3" # Fallback
5
+ DEFAULT_BVM_VERSION="v1.1.4" # Fallback
6
6
  FALLBACK_BUN_VERSION="1.3.5"
7
7
  BVM_SRC_VERSION="${BVM_INSTALL_VERSION}" # If empty, will resolve dynamically
8
8
 
@@ -264,29 +264,33 @@ fi
264
264
  # Link current runtime
265
265
  ln -sf "$TARGET_RUNTIME_DIR" "${BVM_RUNTIME_DIR}/current"
266
266
 
267
- # 4. Download BVM Source & Shim
268
- # Use the detected NPM CDN
269
- BASE_URL="${NPM_CDN}/bvm-core@${BVM_SRC_VERSION#v}"
270
- SRC_URL="${BASE_URL}/dist/index.js"
271
- SHIM_URL="${BASE_URL}/dist/bvm-shim.sh"
267
+ # 4. Download BVM Source & Shim (Tarball Strategy)
268
+ # Use Registry Tarball to avoid CDN sync delays
269
+ if [ "$BVM_REGION" == "cn" ]; then
270
+ TARBALL_URL="https://registry.npmmirror.com/bvm-core/-/bvm-core-${BVM_SRC_VERSION#v}.tgz"
271
+ else
272
+ TARBALL_URL="https://registry.npmjs.org/bvm-core/-/bvm-core-${BVM_SRC_VERSION#v}.tgz"
273
+ fi
272
274
 
273
275
  # Local fallback for development/testing
274
276
  if [ -f "./dist/index.js" ]; then
275
277
  cp "./dist/index.js" "${BVM_SRC_DIR}/index.js"
276
- info "Using local BVM source from dist/."
277
- else
278
- download_file "$SRC_URL" "${BVM_SRC_DIR}/index.js" "Downloading BVM Source (${BVM_SRC_VERSION})..."
279
- fi
280
-
281
- if [ -f "./dist/bvm-shim.sh" ]; then
282
278
  cp "./dist/bvm-shim.sh" "${BVM_BIN_DIR}/bvm-shim.sh"
283
- info "Using local shim logic from dist/."
279
+ info "Using local BVM source from dist/."
284
280
  else
285
- download_file "$SHIM_URL" "${BVM_BIN_DIR}/bvm-shim.sh" "Downloading Shim Logic..."
281
+ TEMP_TGZ="$(mktemp)"
282
+ download_file "$TARBALL_URL" "$TEMP_TGZ" "Downloading BVM Source (${BVM_SRC_VERSION})..."
283
+
284
+ # Extract specific files from tarball (strip components to handle 'package/' prefix)
285
+ # The tarball structure is package/dist/index.js
286
+ tar -xzf "$TEMP_TGZ" -C "$BVM_SRC_DIR" --strip-components=2 "package/dist/index.js"
287
+ tar -xzf "$TEMP_TGZ" -C "$BVM_BIN_DIR" --strip-components=2 "package/dist/bvm-shim.sh"
288
+
289
+ rm -f "$TEMP_TGZ"
286
290
  fi
287
291
 
288
292
  if [ ! -f "${BVM_SRC_DIR}/index.js" ] || [ ! -f "${BVM_BIN_DIR}/bvm-shim.sh" ]; then
289
- error "Failed to download BVM source or shim."
293
+ error "Failed to extract BVM source or shim from tarball."
290
294
  fi
291
295
  chmod +x "${BVM_BIN_DIR}/bvm-shim.sh"
292
296
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bvm-core",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
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": {
@@ -62,10 +62,10 @@
62
62
  "typescript": "^5"
63
63
  },
64
64
  "bvm_fingerprints": {
65
- "cli": "d5df14db9d48b83f4475d6b5106b35b3",
65
+ "cli": "31d6842e9bd5370075bf1848a1391f6a",
66
66
  "shim_win": "c6f43afddfb205e130633fe00ee860d8",
67
67
  "shim_unix": "8aa89a0324b52c9c81b96c0c03afe36c",
68
- "install_sh": "ffb657ae178818ef4ad730a6b0eba5d9",
69
- "install_ps1": "c98b4e2af524e8e891bcf84561e18bbf"
68
+ "install_sh": "5f94b7e805bfb84c94013fd9fe4cf990",
69
+ "install_ps1": "743188f762854bd0340ddfe9206ee22a"
70
70
  }
71
71
  }