bvm-core 1.1.13 → 1.1.15
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/README.md +9 -3
- package/README.zh-CN.md +9 -3
- package/dist/index.js +33 -32
- package/install.ps1 +103 -218
- package/install.sh +105 -282
- package/package.json +5 -5
- package/scripts/postinstall.js +238 -143
package/install.ps1
CHANGED
|
@@ -1,67 +1,23 @@
|
|
|
1
1
|
# BVM Installer for Windows (PowerShell)
|
|
2
2
|
$ErrorActionPreference = "Stop"
|
|
3
3
|
|
|
4
|
-
# --- Fix: Enforce TLS 1.2
|
|
5
|
-
try {
|
|
6
|
-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
7
|
-
} catch {
|
|
8
|
-
# If TLS1.2 isn't available, we can't download anyway, but let's not crash here.
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
# --- Platform Detection (Compatible with PS 5.1 & Core - Robust Version) ---
|
|
12
|
-
$bvmIsWindows = $false
|
|
13
|
-
$bvmIsMac = $false
|
|
14
|
-
$bvmIsLinux = $false
|
|
4
|
+
# --- Fix: Enforce TLS 1.2 ---
|
|
5
|
+
try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {}
|
|
15
6
|
|
|
16
|
-
#
|
|
7
|
+
# --- Platform Detection ---
|
|
17
8
|
if ($PSVersionTable.ContainsKey('OS')) {
|
|
18
9
|
$osName = $PSVersionTable.OS.ToString()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
# Fallback for older PS versions or where $PSVersionTable.OS is not descriptive enough
|
|
25
|
-
if (-not ($bvmIsWindows -or $bvmIsMac -or $bvmIsLinux)) {
|
|
26
|
-
try {
|
|
27
|
-
$osCaption = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption
|
|
28
|
-
if ($osCaption -like "*macOS*") {
|
|
29
|
-
$bvmIsMac = $true
|
|
30
|
-
} elseif ($osCaption -like "*Linux*") {
|
|
31
|
-
$bvmIsLinux = $true
|
|
32
|
-
} elseif ($osCaption -like "*Windows*") {
|
|
33
|
-
$bvmIsWindows = $true
|
|
34
|
-
}
|
|
35
|
-
} catch {
|
|
36
|
-
# If CimInstance also fails, assume Windows (most common PS environment for this script)
|
|
37
|
-
$bvmIsWindows = $true
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# Allow forcing Windows mode for testing purposes (e.g. running this script on macOS/Linux CI)
|
|
42
|
-
if ($env:BVM_FORCE_WINDOWS) {
|
|
43
|
-
$bvmIsWindows = $true
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
# The rest of the script should now use $bvmIsWindows, $bvmIsMac, $bvmIsLinux
|
|
47
|
-
if (-not $bvmIsWindows) {
|
|
48
|
-
Write-Error "BVM install.ps1 is intended for Windows. For Unix-like systems, please use install.sh."
|
|
49
|
-
exit 1
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# --- Dependency Check: tar ---
|
|
54
|
-
if (-not (Get-Command "tar" -ErrorAction SilentlyContinue)) {
|
|
55
|
-
Write-Error "Error: 'tar' command not found.`nBVM requires a modern Windows version (1809+) or a third-party 'tar' tool (e.g., Git Bash).`nPlease upgrade Windows or install Git."
|
|
56
|
-
exit 1
|
|
10
|
+
$bvmIsWindows = $osName -like '*Windows*'
|
|
11
|
+
} else {
|
|
12
|
+
try { $bvmIsWindows = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption -like "*Windows*" } catch { $bvmIsWindows = $true }
|
|
57
13
|
}
|
|
14
|
+
if (-not $bvmIsWindows) { Write-Error "BVM install.ps1 is intended for Windows."; exit 1 }
|
|
58
15
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
16
|
+
# --- Dependency Check ---
|
|
17
|
+
if (-not (Get-Command "tar" -ErrorAction SilentlyContinue)) { Write-Error "Error: 'tar' command not found."; exit 1 }
|
|
18
|
+
if (-not [Environment]::Is64BitOperatingSystem) { Write-Error "BVM requires a 64-bit version of Windows."; exit 1 }
|
|
63
19
|
|
|
64
|
-
# ---
|
|
20
|
+
# --- Path Configuration ---
|
|
65
21
|
$BVM_DIR = if ($env:BVM_DIR) { $env:BVM_DIR } else { Join-Path $HOME ".bvm" }
|
|
66
22
|
$BVM_BIN_DIR = Join-Path $BVM_DIR "bin"
|
|
67
23
|
$BVM_SHIMS_DIR = Join-Path $BVM_DIR "shims"
|
|
@@ -71,221 +27,150 @@ $BVM_ALIAS_DIR = Join-Path $BVM_DIR "aliases"
|
|
|
71
27
|
$BVM_VERSIONS_DIR = Join-Path $BVM_DIR "versions"
|
|
72
28
|
|
|
73
29
|
# --- 0. Conflict Detection ---
|
|
74
|
-
$BVM_BIN_PATH = Join-Path $
|
|
30
|
+
$BVM_BIN_PATH = Join-Path $BVM_BIN_DIR "bvm.cmd"
|
|
75
31
|
if (Test-Path $BVM_BIN_PATH) {
|
|
76
32
|
$content = Get-Content $BVM_BIN_PATH -Raw
|
|
77
|
-
if ($content -like '*BVM_INSTALL_SOURCE="npm"*') {
|
|
78
|
-
|
|
79
|
-
Write-Error "If you want to switch to native installation, uninstall the npm version first."
|
|
80
|
-
exit 1
|
|
81
|
-
}
|
|
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 }
|
|
82
35
|
}
|
|
83
36
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# --- 0. Smart Network Detection (CN vs Global) ---
|
|
37
|
+
# --- 1. Resolve Network & BVM Version ---
|
|
87
38
|
function Detect-NetworkZone {
|
|
88
39
|
if ($env:BVM_REGION) { return $env:BVM_REGION }
|
|
89
|
-
if ($env:BVM_TEST_FORCE_CN) { return "cn" }
|
|
90
|
-
if ($env:BVM_TEST_FORCE_GLOBAL) { return "global" }
|
|
91
|
-
|
|
92
|
-
$Mirror = "npm.elemecdn.com"
|
|
93
40
|
try {
|
|
94
|
-
$Test = Invoke-WebRequest -Uri "https
|
|
41
|
+
$Test = Invoke-WebRequest -Uri "https://registry.npmmirror.com" -Method Head -TimeoutSec 1.5 -UseBasicParsing -ErrorAction SilentlyContinue
|
|
95
42
|
if ($Test.StatusCode -eq 200) { return "cn" }
|
|
96
43
|
} catch {}
|
|
97
44
|
return "global"
|
|
98
45
|
}
|
|
99
|
-
|
|
100
46
|
$BVM_REGION = Detect-NetworkZone
|
|
101
|
-
if ($BVM_REGION -eq "cn") {
|
|
102
|
-
$REGISTRY = "registry.npmmirror.com"
|
|
103
|
-
$NPM_CDN = "https://npm.elemecdn.com"
|
|
104
|
-
} else {
|
|
105
|
-
$REGISTRY = "registry.npmjs.org"
|
|
106
|
-
$NPM_CDN = "https://unpkg.com"
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
# --- Setup Curl Command ---
|
|
110
|
-
$CURL_CMD = "curl.exe"
|
|
111
|
-
if (-not (Get-Command $CURL_CMD -ErrorAction SilentlyContinue)) { $CURL_CMD = "curl" }
|
|
47
|
+
$REGISTRY = if ($BVM_REGION -eq "cn") { "registry.npmmirror.com" } else { "registry.npmjs.org" }
|
|
112
48
|
|
|
113
|
-
|
|
114
|
-
$DEFAULT_BVM_VER = "v1.1.13"
|
|
49
|
+
$DEFAULT_BVM_VER = "v1.1.15"
|
|
115
50
|
$BVM_VER = if ($env:BVM_INSTALL_VERSION) { $env:BVM_INSTALL_VERSION } else { "" }
|
|
116
|
-
|
|
117
|
-
# Resolve BVM Version dynamically if not provided
|
|
118
51
|
if (-not $BVM_VER) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
$
|
|
122
|
-
|
|
123
|
-
Write-Host "Using local version from package.json: $BVM_VER" -ForegroundColor Gray
|
|
124
|
-
} else {
|
|
125
|
-
try {
|
|
126
|
-
$Resp = Invoke-RestMethod -Uri "https://$REGISTRY/bvm-core" -TimeoutSec 5
|
|
127
|
-
$BVM_VER = "v" + $Resp."dist-tags".latest
|
|
128
|
-
} catch {
|
|
129
|
-
$BVM_VER = $DEFAULT_BVM_VER
|
|
130
|
-
}
|
|
131
|
-
}
|
|
52
|
+
try {
|
|
53
|
+
$Resp = Invoke-RestMethod -Uri "https://$REGISTRY/bvm-core" -TimeoutSec 5
|
|
54
|
+
$BVM_VER = "v" + $Resp."dist-tags".latest
|
|
55
|
+
} catch { $BVM_VER = $DEFAULT_BVM_VER }
|
|
132
56
|
}
|
|
57
|
+
Write-Host "BVM Installer ($BVM_REGION) - Resolving $BVM_VER..." -ForegroundColor Cyan
|
|
133
58
|
|
|
134
|
-
|
|
135
|
-
$BUN_MAJOR = $BVM_MAJOR
|
|
136
|
-
$BUN_VER = "1.3.5" # Fallback
|
|
137
|
-
|
|
138
|
-
Write-Host "BVM Installer ($BVM_REGION) - Resolving Bun v$BUN_MAJOR runtime..." -ForegroundColor Gray
|
|
139
|
-
try {
|
|
140
|
-
$BunLatest = (Invoke-RestMethod -Uri "https://$REGISTRY/-/package/bun/dist-tags" -TimeoutSec 5).latest
|
|
141
|
-
if ($BunLatest -and $BunLatest.StartsWith("$BUN_MAJOR.")) { $BUN_VER = $BunLatest }
|
|
142
|
-
} catch {}
|
|
143
|
-
|
|
144
|
-
# --- 3. Setup Directories ---
|
|
59
|
+
# --- 2. Setup Directories ---
|
|
145
60
|
$Dirs = @($BVM_DIR, $BVM_SRC_DIR, $BVM_RUNTIME_DIR, $BVM_BIN_DIR, $BVM_SHIMS_DIR, $BVM_ALIAS_DIR, $BVM_VERSIONS_DIR)
|
|
146
61
|
foreach ($d in $Dirs) { if (-not (Test-Path $d)) { New-Item -ItemType Directory -Force -Path $d | Out-Null } }
|
|
147
62
|
|
|
148
|
-
# ---
|
|
149
|
-
# Note: In bootstrap, we install directly to versions/ and then link to runtime/
|
|
150
|
-
$TARGET_DIR = Join-Path $BVM_VERSIONS_DIR "v$BUN_VER"
|
|
151
|
-
$BUN_EXE_NAME = if ($bvmIsWindows) { "bun.exe" } else { "bun" }
|
|
152
|
-
|
|
153
|
-
if (-not (Test-Path (Join-Path $TARGET_DIR "bin\$BUN_EXE_NAME"))) {
|
|
154
|
-
Write-Host "Downloading Bun v$BUN_VER..."
|
|
155
|
-
$URL = "https://$REGISTRY/@oven/bun-windows-x64/-/bun-windows-x64-$BUN_VER.tgz"
|
|
156
|
-
$TMP = Join-Path $BVM_DIR "bun-runtime.tgz"
|
|
157
|
-
& $CURL_CMD "-#SfLo" "$TMP" "$URL"
|
|
158
|
-
|
|
159
|
-
$EXT = Join-Path $BVM_DIR "temp_extract"
|
|
160
|
-
if (Test-Path $EXT) { Remove-Item $EXT -Recurse -Force | Out-Null }
|
|
161
|
-
New-Item -ItemType Directory -Path $EXT | Out-Null
|
|
162
|
-
|
|
163
|
-
Write-Host "Extracting..."
|
|
164
|
-
& tar -xf "$TMP" -C "$EXT"
|
|
165
|
-
|
|
166
|
-
$FoundBun = Get-ChildItem -Path $EXT -Filter $BUN_EXE_NAME -Recurse | Select-Object -First 1
|
|
167
|
-
if ($null -eq $FoundBun) {
|
|
168
|
-
# Fallback for different archive structures
|
|
169
|
-
$FoundBun = Get-ChildItem -Path $EXT -Filter "bun*" -Recurse | Where-Object { $_.Name -match "^bun(\.exe)?$" } | Select-Object -First 1
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
$BIN_DEST = Join-Path $TARGET_DIR "bin"
|
|
173
|
-
New-Item -ItemType Directory -Path $BIN_DEST -Force | Out-Null
|
|
174
|
-
Move-Item -Path $FoundBun.FullName -Destination (Join-Path $BIN_DEST $BUN_EXE_NAME) -Force
|
|
175
|
-
|
|
176
|
-
Remove-Item $TMP -Force
|
|
177
|
-
Remove-Item $EXT -Recurse -Force
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
# Sync to runtime for BVM execution
|
|
181
|
-
$RUNTIME_VER_DIR = Join-Path $BVM_RUNTIME_DIR "v$BUN_VER"
|
|
182
|
-
if (-not (Test-Path $RUNTIME_VER_DIR)) {
|
|
183
|
-
# Windows Junction (no admin req) or Unix Symlink
|
|
184
|
-
if ($bvmIsWindows) {
|
|
185
|
-
New-Item -ItemType Junction -Path $RUNTIME_VER_DIR -Value $TARGET_DIR | Out-Null
|
|
186
|
-
} else {
|
|
187
|
-
New-Item -ItemType SymbolicLink -Path $RUNTIME_VER_DIR -Value $TARGET_DIR | Out-Null
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
$CURRENT_LINK = Join-Path $BVM_RUNTIME_DIR "current"
|
|
191
|
-
if (Test-Path $CURRENT_LINK) {
|
|
192
|
-
Remove-Item -Recurse -Force $CURRENT_LINK | Out-Null
|
|
193
|
-
}
|
|
194
|
-
if ($bvmIsWindows) {
|
|
195
|
-
New-Item -ItemType Junction -Path $CURRENT_LINK -Value $RUNTIME_VER_DIR -Force | Out-Null
|
|
196
|
-
} else {
|
|
197
|
-
New-Item -ItemType SymbolicLink -Path $CURRENT_LINK -Value $RUNTIME_VER_DIR -Force | Out-Null
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
# --- 5. Download BVM Source & Shim (Tarball Strategy) ---
|
|
63
|
+
# --- 3. Download BVM Source (Needed for Smoke Test) ---
|
|
201
64
|
$BVM_PLAIN_VER = $BVM_VER.TrimStart('v')
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
} else {
|
|
205
|
-
$TARBALL_URL = "https://registry.npmjs.org/bvm-core/-/bvm-core-$BVM_PLAIN_VER.tgz"
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if ($PSScriptRoot) {
|
|
209
|
-
$LOCAL_DIST = Join-Path $PSScriptRoot "dist"
|
|
210
|
-
} else {
|
|
211
|
-
$LOCAL_DIST = ""
|
|
212
|
-
}
|
|
65
|
+
$TARBALL_URL = "https://$REGISTRY/bvm-core/-/bvm-core-$BVM_PLAIN_VER.tgz"
|
|
66
|
+
$CURL_CMD = if (Get-Command "curl.exe" -ErrorAction SilentlyContinue) { "curl.exe" } else { "curl" }
|
|
213
67
|
|
|
214
|
-
if (
|
|
215
|
-
Copy-Item
|
|
216
|
-
|
|
68
|
+
if (Test-Path "dist\index.js") {
|
|
69
|
+
Copy-Item "dist\index.js" (Join-Path $BVM_SRC_DIR "index.js") -Force
|
|
70
|
+
Copy-Item "dist\bvm-shim.js" (Join-Path $BVM_BIN_DIR "bvm-shim.js") -Force
|
|
217
71
|
} else {
|
|
218
|
-
Write-Host "Downloading BVM Tarball $BVM_VER..."
|
|
219
72
|
$TMP_TGZ = Join-Path $BVM_DIR "bvm-core.tgz"
|
|
220
73
|
& $CURL_CMD "-#SfLo" "$TMP_TGZ" "$TARBALL_URL"
|
|
221
|
-
|
|
222
74
|
$EXT_DIR = Join-Path $BVM_DIR "temp_bvm_extract"
|
|
223
75
|
if (Test-Path $EXT_DIR) { Remove-Item $EXT_DIR -Recurse -Force }
|
|
224
76
|
New-Item -ItemType Directory -Path $EXT_DIR | Out-Null
|
|
225
|
-
|
|
226
|
-
Write-Host "Extracting BVM assets..."
|
|
227
77
|
& tar -xf "$TMP_TGZ" -C "$EXT_DIR"
|
|
228
|
-
|
|
229
|
-
# NPM tarballs put everything in 'package/'
|
|
230
78
|
Copy-Item (Join-Path $EXT_DIR "package\dist\index.js") (Join-Path $BVM_SRC_DIR "index.js") -Force
|
|
231
79
|
Copy-Item (Join-Path $EXT_DIR "package\dist\bvm-shim.js") (Join-Path $BVM_BIN_DIR "bvm-shim.js") -Force
|
|
232
|
-
|
|
233
80
|
Remove-Item $TMP_TGZ -Force
|
|
234
81
|
Remove-Item $EXT_DIR -Recurse -Force
|
|
235
82
|
}
|
|
236
83
|
|
|
237
|
-
# ---
|
|
238
|
-
|
|
84
|
+
# --- 4. Detect System Bun & Runtime Selection ---
|
|
85
|
+
$SYSTEM_BUN_BIN = Get-Command "bun" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
|
|
86
|
+
$SYSTEM_BUN_VER = ""
|
|
87
|
+
if ($SYSTEM_BUN_BIN) { try { $SYSTEM_BUN_VER = (bun --version) -replace "^v", "" } catch {} }
|
|
239
88
|
|
|
240
|
-
$
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
$
|
|
246
|
-
$
|
|
247
|
-
$
|
|
248
|
-
$
|
|
249
|
-
$tpl += ":: Slow-path: Hand over to JS shim for version resolution`r`n"
|
|
250
|
-
$tpl += "`"%BVM_DIR%\runtime\current\bin\bun.exe`" `"%BVM_DIR%\bin\bvm-shim.js`" `"$name`" %*"
|
|
89
|
+
$USE_SYSTEM_AS_RUNTIME = $false
|
|
90
|
+
$BUN_VER = ""
|
|
91
|
+
|
|
92
|
+
if ($SYSTEM_BUN_BIN) {
|
|
93
|
+
Write-Host "Found system Bun v$SYSTEM_BUN_VER at $SYSTEM_BUN_BIN" -ForegroundColor Gray
|
|
94
|
+
$SYS_VER_DIR = Join-Path $BVM_VERSIONS_DIR "v$SYSTEM_BUN_VER"
|
|
95
|
+
$SYS_BIN_DIR = Join-Path $SYS_VER_DIR "bin"
|
|
96
|
+
if (-not (Test-Path $SYS_BIN_DIR)) { New-Item -ItemType Directory -Path $SYS_BIN_DIR -Force | Out-Null }
|
|
97
|
+
Copy-Item $SYSTEM_BUN_BIN (Join-Path $SYS_BIN_DIR "bun.exe") -Force
|
|
251
98
|
|
|
252
|
-
|
|
253
|
-
|
|
99
|
+
# Smoke Test
|
|
100
|
+
Write-Host "Running Smoke Test..." -ForegroundColor Gray
|
|
101
|
+
$BvmIndex = Join-Path $BVM_SRC_DIR "index.js"
|
|
102
|
+
& $SYSTEM_BUN_BIN $BvmIndex --version | Out-Null
|
|
103
|
+
if ($LASTEXITCODE -eq 0) {
|
|
104
|
+
Write-Host "[OK] Smoke Test passed." -ForegroundColor Green
|
|
105
|
+
$USE_SYSTEM_AS_RUNTIME = $true
|
|
106
|
+
$BUN_VER = "v$SYSTEM_BUN_VER"
|
|
107
|
+
} else {
|
|
108
|
+
Write-Host "[!] Smoke Test failed." -ForegroundColor Yellow
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if ($USE_SYSTEM_AS_RUNTIME) {
|
|
113
|
+
$TARGET_DIR = Join-Path $BVM_VERSIONS_DIR $BUN_VER
|
|
114
|
+
} else {
|
|
115
|
+
try {
|
|
116
|
+
$BunLatest = (Invoke-RestMethod -Uri "https://$REGISTRY/-/package/bun/dist-tags" -TimeoutSec 5).latest
|
|
117
|
+
$BUN_VER = "v$BunLatest"
|
|
118
|
+
} catch { $BUN_VER = "v1.3.5" }
|
|
119
|
+
$TARGET_DIR = Join-Path $BVM_VERSIONS_DIR $BUN_VER
|
|
254
120
|
|
|
255
|
-
|
|
256
|
-
|
|
121
|
+
if (-not (Test-Path (Join-Path $TARGET_DIR "bin\bun.exe"))) {
|
|
122
|
+
Write-Host "Downloading Compatible Runtime (bun@$($BUN_VER.TrimStart('v')))..."
|
|
123
|
+
$URL = "https://$REGISTRY/@oven/bun-windows-x64/-/bun-windows-x64-$($BUN_VER.TrimStart('v')).tgz"
|
|
124
|
+
$TMP = Join-Path $BVM_DIR "bun-runtime.tgz"
|
|
125
|
+
& $CURL_CMD "-#SfLo" "$TMP" "$URL"
|
|
126
|
+
$EXT = Join-Path $BVM_DIR "temp_extract"
|
|
127
|
+
if (Test-Path $EXT) { Remove-Item $EXT -Recurse -Force | Out-Null }
|
|
128
|
+
New-Item -ItemType Directory -Path $EXT | Out-Null
|
|
129
|
+
& tar -xf "$TMP" -C "$EXT"
|
|
130
|
+
$FoundBun = Get-ChildItem -Path $EXT -Filter "bun.exe" -Recurse | Select-Object -First 1
|
|
131
|
+
$BIN_DEST = Join-Path $TARGET_DIR "bin"
|
|
132
|
+
if (-not (Test-Path $BIN_DEST)) { New-Item -ItemType Directory -Path $BIN_DEST -Force | Out-Null }
|
|
133
|
+
Move-Item -Path $FoundBun.FullName -Destination (Join-Path $BIN_DEST "bun.exe") -Force
|
|
134
|
+
Remove-Item $TMP -Force
|
|
135
|
+
Remove-Item $EXT -Recurse -Force
|
|
136
|
+
}
|
|
257
137
|
}
|
|
258
138
|
|
|
259
|
-
#
|
|
139
|
+
# --- 5. Configure Runtime & Aliases ---
|
|
140
|
+
$PRIVATE_RUNTIME_LINK = Join-Path $BVM_RUNTIME_DIR "current"
|
|
141
|
+
if (Test-Path $PRIVATE_RUNTIME_LINK) { Remove-Item -Recurse -Force $PRIVATE_RUNTIME_LINK | Out-Null }
|
|
142
|
+
New-Item -ItemType Junction -Path $PRIVATE_RUNTIME_LINK -Value $TARGET_DIR | Out-Null
|
|
143
|
+
|
|
144
|
+
$USER_CURRENT_LINK = Join-Path $BVM_DIR "current"
|
|
145
|
+
if (Test-Path $USER_CURRENT_LINK) { Remove-Item -Recurse -Force $USER_CURRENT_LINK | Out-Null }
|
|
146
|
+
New-Item -ItemType Junction -Path $USER_CURRENT_LINK -Value $TARGET_DIR | Out-Null
|
|
147
|
+
|
|
148
|
+
Set-Content -Path (Join-Path $BVM_ALIAS_DIR "default") -Value $BUN_VER -Encoding Ascii
|
|
149
|
+
|
|
150
|
+
# --- 6. Create Shims & Wrappers ---
|
|
151
|
+
Write-Host "Initializing shims..." -ForegroundColor Gray
|
|
260
152
|
$WinBvmDir = $BVM_DIR.Replace('/', '\')
|
|
261
153
|
$BvmWrapper = "@echo off`r`nset `"BVM_DIR=$WinBvmDir`"`r`n`"%BVM_DIR%\runtime\current\bin\bun.exe`" `"%BVM_DIR%\src\index.js`" %*"
|
|
262
154
|
Set-Content -Path (Join-Path $BVM_BIN_DIR "bvm.cmd") -Value $BvmWrapper -Encoding Ascii
|
|
263
155
|
|
|
264
|
-
|
|
265
|
-
$
|
|
266
|
-
|
|
267
|
-
|
|
156
|
+
$CMD_NAMES = @("bun", "bunx")
|
|
157
|
+
foreach ($name in $CMD_NAMES) {
|
|
158
|
+
$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`" %*"
|
|
161
|
+
Set-Content -Path (Join-Path $BVM_SHIMS_DIR "$name.cmd") -Value $tpl -Encoding Ascii
|
|
268
162
|
}
|
|
269
163
|
|
|
270
164
|
# --- 7. Finalize Environment ---
|
|
271
165
|
$RawPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
|
272
|
-
if ($
|
|
273
|
-
$PathList = $RawPath.Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
|
|
166
|
+
$PathList = if ($RawPath) { $RawPath.Split(';') } else { @() }
|
|
274
167
|
$NewPathList = @()
|
|
275
|
-
foreach ($p in $PathList) {
|
|
276
|
-
if ($p -notlike "*\.bvm\shims*" -and $p -notlike "*\.bvm\bin*") {
|
|
277
|
-
$NewPathList += $p
|
|
278
|
-
}
|
|
279
|
-
}
|
|
168
|
+
foreach ($p in $PathList) { if ($p -notlike "*\.bvm\shims*" -and $p -notlike "*\.bvm\bin*" -and [string]::IsNotNullOrEmpty($p)) { $NewPathList += $p } }
|
|
280
169
|
$FinalPath = "$BVM_SHIMS_DIR;$BVM_BIN_DIR;" + ($NewPathList -join ';')
|
|
281
170
|
[Environment]::SetEnvironmentVariable("Path", $FinalPath, "User")
|
|
282
|
-
|
|
283
|
-
# Update Current Session
|
|
284
171
|
$env:Path = "$BVM_SHIMS_DIR;$BVM_BIN_DIR;$env:Path"
|
|
285
172
|
|
|
286
|
-
|
|
287
|
-
& (Join-Path (Join-Path $BVM_RUNTIME_DIR "current\bin") "bun.exe") (Join-Path $BVM_SRC_DIR "index.js") setup --silent
|
|
288
|
-
}
|
|
173
|
+
& (Join-Path $TARGET_DIR "bin\bun.exe") (Join-Path $BVM_SRC_DIR "index.js") setup --silent
|
|
289
174
|
|
|
290
175
|
Write-Host "`n[OK] BVM installed successfully!" -ForegroundColor Green
|
|
291
|
-
Write-Host "IMPORTANT: Please close this terminal and open a NEW one." -ForegroundColor Yellow
|
|
176
|
+
Write-Host "IMPORTANT: Please close this terminal and open a NEW one." -ForegroundColor Yellow
|