Skip to content

Commit 53ae906

Browse files
author
lei.liao
committed
chore(release): v1.1.34 (Smart Acceleration for Global/Local installs)
1 parent 0376643 commit 53ae906

6 files changed

Lines changed: 74 additions & 4 deletions

File tree

install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function Detect-NetworkZone {
3939
$BVM_REGION = Detect-NetworkZone
4040
$REGISTRY = if ($BVM_REGION -eq "cn") { "registry.npmmirror.com" } else { "registry.npmjs.org" }
4141

42-
$DEFAULT_BVM_VER = "v1.1.33"
42+
$DEFAULT_BVM_VER = "v1.1.34"
4343
$BVM_VER = if ($env:BVM_INSTALL_VERSION) { $env:BVM_INSTALL_VERSION } else { "" }
4444
if (-not $BVM_VER) {
4545
try {

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
# --- Configuration ---
6-
DEFAULT_BVM_VERSION="v1.1.33" # Fallback
6+
DEFAULT_BVM_VERSION="v1.1.34" # Fallback
77
FALLBACK_BUN_VERSION="1.3.6"
88
BVM_SRC_VERSION="${BVM_INSTALL_VERSION}" # If empty, will resolve dynamically
99

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bvm-core",
3-
"version": "1.1.33",
3+
"version": "1.1.34",
44
"description": "The native version manager for Bun. Cross-platform, shell-agnostic, and zero-dependency.",
55
"main": "dist/index.js",
66
"bin": {

src/commands/setup.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { mkdir } from 'fs/promises'; // Import mkdir
55
import { BVM_BIN_DIR, BVM_DIR, EXECUTABLE_NAME, BVM_SHIMS_DIR, BVM_SRC_DIR, BVM_VERSIONS_DIR, BVM_CURRENT_DIR } from '../constants';
66
import { colors, confirm } from '../utils/ui';
77
import { chmod } from 'fs/promises';
8+
import { unlink } from 'fs/promises';
9+
import { getGeoLocation } from '../utils/network-utils';
810
import { useBunVersion } from './use';
911
import {
1012
BVM_INIT_SH_TEMPLATE,
@@ -23,6 +25,9 @@ export async function configureShell(displayPrompt: boolean = true): Promise<voi
2325
// 1. Refresh shims and wrappers (Self-Healing)
2426
await recreateShims(displayPrompt);
2527

28+
// 2. Sync region marker for transparent acceleration
29+
await syncRegionMarker(displayPrompt);
30+
2631
// Windows Support
2732
if (process.platform === 'win32') {
2833
await configureWindows(displayPrompt);
@@ -166,6 +171,19 @@ end
166171
}
167172
}
168173

174+
async function syncRegionMarker(displayPrompt: boolean) {
175+
try {
176+
const loc = await getGeoLocation();
177+
const markerPath = join(BVM_DIR, '.cn');
178+
if (loc === 'CN') {
179+
await Bun.write(markerPath, '');
180+
if (displayPrompt) console.log(colors.gray(' (Region: China detected, enabling transparent acceleration)'));
181+
} else {
182+
try { await unlink(markerPath); } catch(e) {}
183+
}
184+
} catch(e) {}
185+
}
186+
169187
async function recreateShims(displayPrompt: boolean) {
170188
if (displayPrompt) console.log(colors.cyan('Refreshing shims and wrappers...'));
171189

src/templates/unix/bvm-shim.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ REAL_EXECUTABLE="$VERSION_DIR/bin/$CMD_NAME"
5858
if [ -x "$REAL_EXECUTABLE" ]; then
5959
export BUN_INSTALL="$VERSION_DIR"
6060
export PATH="$VERSION_DIR/bin:$PATH"
61+
62+
# --- Transparent Global/Local Install Acceleration ---
63+
if [[ "$CMD_NAME" == "bun" || "$CMD_NAME" == "bunx" ]]; then
64+
IS_INSTALL=false
65+
IS_GLOBAL=false
66+
for arg in "$@"; do
67+
[[ "$arg" == "install" || "$arg" == "i" || "$arg" == "add" || "$arg" == "a" || "$arg" == "upgrade" ]] && IS_INSTALL=true
68+
[[ "$arg" == "-g" || "$arg" == "--global" ]] && IS_GLOBAL=true
69+
done
70+
71+
if [ "$IS_INSTALL" = true ]; then
72+
HAS_REGISTRY=false
73+
for arg in "$@"; do [[ "$arg" == "--registry" ]] && HAS_REGISTRY=true; done
74+
75+
if [ "$HAS_REGISTRY" = false ]; then
76+
# Safe back-off: check local config
77+
if [ "$IS_GLOBAL" = true ] || { [ ! -f ".npmrc" ] && [ ! -f "bunfig.toml" ]; }; then
78+
if [ "$BVM_REGION" == "cn" ] || [ -f "$BVM_DIR/.cn" ]; then
79+
set -- "$@" "--registry" "https://registry.npmmirror.com"
80+
fi
81+
fi
82+
fi
83+
fi
84+
fi
85+
6186
exec "$REAL_EXECUTABLE" "$@"
6287
else
6388
echo "BVM Error: Command '$CMD_NAME' not found in Bun $VERSION." >&2

src/templates/win/bvm-shim.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,38 @@ if (!fs.existsSync(realExecutable)) {
6969
process.env.BUN_INSTALL = versionDir;
7070
process.env.PATH = binDir + path.delimiter + process.env.PATH;
7171

72+
// --- Transparent Global/Local Install Acceleration & Fixes ---
73+
if (CMD === 'bun' || CMD === 'bunx') {
74+
const installCmds = ['install', 'i', 'add', 'a', 'upgrade'];
75+
const isInstall = ARGS.some(arg => installCmds.includes(arg));
76+
77+
if (isInstall) {
78+
const isGlobal = ARGS.includes('-g') || ARGS.includes('--global');
79+
const hasRegistryArg = ARGS.includes('--registry');
80+
81+
// 1. Safe Back-off check: Don't interfere if project has config
82+
let hasLocalConfig = false;
83+
try {
84+
if (fs.existsSync('.npmrc') || fs.existsSync('bunfig.toml')) {
85+
hasLocalConfig = true;
86+
}
87+
} catch(e) {}
88+
89+
// 2. Auto-inject Registry for CN users
90+
if (!hasRegistryArg && (isGlobal || !hasLocalConfig)) {
91+
if (process.env.BVM_REGION === 'cn' || fs.existsSync(path.join(BVM_DIR, '.cn'))) {
92+
ARGS.push('--registry', 'https://registry.npmmirror.com');
93+
}
94+
}
95+
}
96+
}
97+
7298
const child = spawn(realExecutable, ARGS, { stdio: 'inherit', shell: false });
7399
child.on('exit', (code) => {
74100
if (code === 0 && (CMD === 'bun' || CMD === 'bunx')) {
75101
const isGlobal = ARGS.includes('-g') || ARGS.includes('--global');
76-
const isInstall = ARGS.includes('install') || ARGS.includes('add') || ARGS.includes('remove') || ARGS.includes('upgrade');
102+
const installCmds = ['install', 'i', 'add', 'a', 'remove', 'rm', 'upgrade'];
103+
const isInstall = ARGS.some(arg => installCmds.includes(arg));
77104

78105
if (isGlobal && isInstall) {
79106
try {

0 commit comments

Comments
 (0)