mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 20:48:56 +01:00
[tgui] Replaces node with bun (#91359)
## About The Pull Request Swaps out node & yarn in favor of [bun](https://bun.sh/)  sub tasks - [x] add bun setup script - [x] fix tgui-dev-server (bun glob is different) - [x] set juke to run bun - [x] remove all yarn stuff - [x] convert all tests from vitest to bun - [x] fight with CI/tgs ## Why It's Good For The Game Yarn has served us over the years as our package manager but the method it bundles dependencies has lead to issues and setbacks, notably needing to wait on rspack support, but more recently in trying to switch to biome 1. I can add in packages that do not need these workarounds, like god intended 2. We won't need to [keep around sdks](https://yarnpkg.com/getting-started/editor-sdks) which rely on yarn to even publish 3. We're not committing the yarn cache or .pnp file, which kind of defeats the purpose 4. Native typescript support and testing 5. Because it'd be cool ## Caveats Rspack was throwing errors on TGS while doing this. I needed to switch back to webpack/swc, which seems to work flawlessly. It was too tiring for anyone involved to debug and this was the simplest route. It adds a completely negligible amount of time to build. It might even resolve some issues elsewhere. Making this switch extends that very first setup time! I'm working on cutting it down, but as of right now, it takes about 80 seconds just for TGUI to download all the packages. Afterwards, it's the same. ## Changelog
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
## bootstrap/bun_.ps1
|
||||
## Downloads a Bun version to a cache directory and invokes it.
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Get-VariableFromFile {
|
||||
param([string] $Path, [string] $Key)
|
||||
foreach ($Line in Get-Content $Path) {
|
||||
if ($Line.StartsWith("export $Key=")) {
|
||||
return $Line.Substring(("export $Key=").Length)
|
||||
}
|
||||
}
|
||||
throw "Couldn't find value for $Key in $Path"
|
||||
}
|
||||
|
||||
function Get-Bun {
|
||||
if (Test-Path $BunTarget -PathType Leaf) {
|
||||
# Bun already exists
|
||||
return
|
||||
}
|
||||
|
||||
Write-Output "Downloading Bun v$BunVersion (may take a while)"
|
||||
New-Item $BunTargetDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
|
||||
$WebClient = New-Object Net.WebClient
|
||||
$WebClient.DownloadFile($BunSource, "$BunZip.downloading")
|
||||
Rename-Item "$BunZip.downloading" $BunZip
|
||||
Test-BunHash
|
||||
|
||||
Write-Output "Extracting Bun archive"
|
||||
Expand-Archive -Path $BunZip -DestinationPath $BunTargetDir -Force
|
||||
|
||||
# Move the exe out of the subdirectory
|
||||
if (Test-Path "$BunTargetDir\$BunPlatform\bun.exe") {
|
||||
Move-Item "$BunTargetDir\$BunPlatform\bun.exe" $BunTargetDir -Force
|
||||
}
|
||||
else {
|
||||
Write-Output "Failed to find bun.exe in the extracted directory."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Remove-Item $BunZip -Force
|
||||
Remove-Item "$BunTargetDir\$BunPlatform" -Recurse -Force
|
||||
}
|
||||
|
||||
function Test-BunHash {
|
||||
$Tries = $Tries + 1
|
||||
|
||||
Write-Output "Verifying Bun checksum"
|
||||
$FileHash = Get-FileHash $BunZip -Algorithm SHA256
|
||||
$ActualSha = $FileHash.Hash
|
||||
$LoginResponse = Invoke-WebRequest "https://github.com/oven-sh/bun/releases/download/bun-v$BunVersion/SHASUMS256.txt"
|
||||
$ContentString = [System.Text.Encoding]::UTF8.GetString($LoginResponse.Content)
|
||||
$ShaArray = $ContentString -split "`n"
|
||||
foreach ($ShaArrayEntry in $ShaArray) {
|
||||
$EntrySplit = $ShaArrayEntry -split "\s+"
|
||||
$EntrySha = $EntrySplit[0]
|
||||
$EntryFile = $EntrySplit[1]
|
||||
if ($EntryFile -eq "bun-windows-x64.zip") {
|
||||
$ExpectedSha = $EntrySha
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -eq $ExpectedSha) {
|
||||
Write-Output "Failed to determine the correct checksum value. This is probably fine."
|
||||
return
|
||||
}
|
||||
|
||||
if ($ExpectedSha -ne $ActualSha) {
|
||||
Write-Output "$ExpectedSha != $ActualSha"
|
||||
if ($Tries -gt 3) {
|
||||
Write-Output "Failed to verify Bun checksum three times. Aborting."
|
||||
exit 1
|
||||
}
|
||||
Write-Output "Checksum mismatch on Bun. Retrying."
|
||||
Remove-Item $BunTarget
|
||||
Get-Bun
|
||||
}
|
||||
}
|
||||
|
||||
## Convenience variables
|
||||
$BaseDir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||
$Cache = "$BaseDir\.cache"
|
||||
if ($Env:TG_BOOTSTRAP_CACHE) {
|
||||
$Cache = $Env:TG_BOOTSTRAP_CACHE
|
||||
}
|
||||
|
||||
$BunVersion = Get-VariableFromFile -Path "$BaseDir\..\..\dependencies.sh" -Key "BUN_VERSION"
|
||||
$BunPlatform = "bun-windows-x64"
|
||||
$BunSource = "https://github.com/oven-sh/bun/releases/download/bun-v$BunVersion/$BunPlatform.zip"
|
||||
$BunTargetDir = "$Cache\bun-v$BunVersion-x64"
|
||||
$BunTarget = "$BunTargetDir\bun.exe"
|
||||
$BunZip = "$BunTargetDir\bun.zip"
|
||||
|
||||
## Just print the path and exit
|
||||
if ($Args.length -eq 1 -and $Args[0] -eq "Get-Path") {
|
||||
Write-Output "$BunTargetDir"
|
||||
exit 0
|
||||
}
|
||||
|
||||
## Just download bun and exit
|
||||
if ($Args.length -eq 1 -and $Args[0] -eq "Download-Bun") {
|
||||
Get-Bun
|
||||
exit 0
|
||||
}
|
||||
|
||||
## Download bun
|
||||
Get-Bun
|
||||
|
||||
## Set PATH so that recursive calls find it
|
||||
$Env:PATH = "$BunTargetDir;$ENV:Path"
|
||||
|
||||
## Invoke Bun with all command-line arguments
|
||||
$ErrorActionPreference = "Continue"
|
||||
& "$BunTarget" @Args
|
||||
exit $LastExitCode
|
||||
Reference in New Issue
Block a user