Skip to content

Commit c52b2d7

Browse files
authored
bun: Persist user data (#7697)
1 parent cf2df06 commit c52b2d7

1 file changed

Lines changed: 35 additions & 14 deletions

File tree

bucket/bun.json

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,43 @@
1515
"hash": [
1616
"7a77b3e245e2e26965c93089a4a1332e8a326d3364c89fae1d1fd99cdd3cd73d",
1717
"715709c69b176e20994533d3292bd0b7c32de9c0c5575b916746ec6b2aa38346"
18-
],
19-
"pre_install": [
20-
"$avx2 = Start-Job -ScriptBlock {",
21-
" Add-Type -MemberDefinition '[DllImport(\"kernel32.dll\")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name Kernel32 -Namespace Win32",
22-
" return [Win32.Kernel32]::IsProcessorFeaturePresent(40)",
23-
"} | Receive-Job -Wait -AutoRemoveJob",
24-
"$target = 'bun-windows-x64'",
25-
"if (-not $avx2) {",
26-
" $target += '-baseline'",
27-
"}",
28-
"Move-Item \"$dir\\$target\\bun.exe\" \"$dir\\bun.exe\"",
29-
"Remove-Item \"$dir\\bun-windows-*\" -Recurse"
3018
]
3119
},
3220
"arm64": {
3321
"url": "https://github.com/oven-sh/bun/releases/download/bun-v1.3.10/bun-windows-aarch64.zip",
34-
"hash": "6822f3aa7bd2be40fb94c194a1185aae1c6fade54ca4fc2efdc722e37f3257d2",
35-
"extract_dir": "bun-windows-aarch64"
22+
"hash": "6822f3aa7bd2be40fb94c194a1185aae1c6fade54ca4fc2efdc722e37f3257d2"
3623
}
3724
},
25+
"pre_install": [
26+
"# Migrate legacy Bun data if it exists and the new persist directory doesn't exist",
27+
"$legacy_bun = Join-Path -Path $env:USERPROFILE -ChildPath '.bun'",
28+
"if ((Test-Path $legacy_bun) -and -not (Test-Path $persist_dir)) {",
29+
" Write-Host \"Migrating legacy Bun data from '$legacy_bun' to '$persist_dir'.\" -ForegroundColor Yellow",
30+
" Move-Item $legacy_bun $persist_dir -Force",
31+
"} elseif ((Test-Path $legacy_bun) -and (Test-Path $persist_dir)) {",
32+
" Write-Host \"Found both '$legacy_bun' and '$persist_dir'. Skipping auto-migration; please migrate manually if needed.\" -ForegroundColor Yellow",
33+
"}",
34+
"",
35+
"# Extract the appropriate binary based on architecture and CPU features",
36+
"if ($architecture -eq 'arm64') {",
37+
" $target = 'bun-windows-aarch64'",
38+
"} else {",
39+
" $avx2 = Start-Job -ScriptBlock {",
40+
" Add-Type -MemberDefinition '[DllImport(\"kernel32.dll\")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name Kernel32 -Namespace Win32",
41+
" return [Win32.Kernel32]::IsProcessorFeaturePresent(40)",
42+
" } | Receive-Job -Wait -AutoRemoveJob",
43+
" $target = 'bun-windows-x64'",
44+
" if (-not $avx2) {",
45+
" $target += '-baseline'",
46+
" }",
47+
"}",
48+
"Move-Item \"$dir\\$target\\bun.exe\" \"$dir\\bun.exe\"",
49+
"Remove-Item \"$dir\\bun-windows-*\" -Recurse"
50+
],
51+
"env_add_path": "bin",
52+
"env_set": {
53+
"BUN_INSTALL": "$persist_dir"
54+
},
3855
"bin": [
3956
"bun.exe",
4057
[
@@ -43,6 +60,10 @@
4360
"x"
4461
]
4562
],
63+
"persist": [
64+
"bin",
65+
"install"
66+
],
4667
"checkver": {
4768
"github": "https://github.com/oven-sh/bun",
4869
"re": "bun-v([\\d.]+)"

0 commit comments

Comments
 (0)