Skip to content

Commit 97cd103

Browse files
committed
Convert from Bun to Node.js
- Replace bun-pty with node-pty - Update all shebangs from bun to node - Replace Bun.build() with esbuild - Add bun-compat.ts for Bun API compatibility layer - Update all package.json files to remove catalog: references - Change package manager from bun to pnpm - Update GitHub Actions to use Node.js instead of Bun - Add tsx for TypeScript execution - Update tsconfig to use @tsconfig/node22 - Add Windows Server setup and cleanup scripts This migration is necessary because Bun has memory alignment bugs in virtualized Windows environments that cause crashes.
1 parent 479cca2 commit 97cd103

52 files changed

Lines changed: 1092 additions & 208 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Setup Node"
2+
description: "Setup Node.js with pnpm and install dependencies"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Setup Node.js
7+
uses: actions/setup-node@v4
8+
with:
9+
node-version: '22'
10+
11+
- name: Setup pnpm
12+
uses: pnpm/action-setup@v4
13+
with:
14+
version: 9
15+
16+
- name: Get pnpm store directory
17+
id: pnpm-cache
18+
shell: bash
19+
run: |
20+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
21+
22+
- name: Cache pnpm store
23+
uses: actions/cache@v4
24+
with:
25+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
26+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
27+
restore-keys: |
28+
${{ runner.os }}-pnpm-store-
29+
30+
- name: Install dependencies
31+
run: pnpm install
32+
shell: bash

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
with:
1818
token: ${{ secrets.GITHUB_TOKEN }}
1919

20-
- name: Setup Bun
21-
uses: ./.github/actions/setup-bun
20+
- name: Setup Node.js
21+
uses: ./.github/actions/setup-node
2222

2323
- name: run
2424
run: |
2525
git config --global user.email "bot@opencode.ai"
2626
git config --global user.name "opencode"
27-
bun turbo typecheck
28-
bun turbo test
27+
pnpm turbo typecheck
28+
pnpm turbo test
2929
env:
3030
CI: true

.github/workflows/typecheck.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
- name: Checkout repository
1313
uses: actions/checkout@v4
1414

15-
- name: Setup Bun
16-
uses: ./.github/actions/setup-bun
15+
- name: Setup Node.js
16+
uses: ./.github/actions/setup-node
1717

1818
- name: Run typecheck
19-
run: bun typecheck
19+
run: pnpm typecheck

WINDOWS_SERVER_SETUP.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Running OpenCode on Windows Server 2022 with Node.js
2+
3+
Since Bun has memory alignment issues in virtualized environments, you can run OpenCode directly with Node.js instead.
4+
5+
## Prerequisites
6+
7+
1. **Install Node.js 20 or later** on your Windows Server:
8+
```powershell
9+
# Download and install Node.js LTS
10+
winget install OpenJS.NodeJS.LTS
11+
# Or download from: https://nodejs.org/
12+
```
13+
14+
2. **Install pnpm** (package manager):
15+
```powershell
16+
npm install -g pnpm
17+
```
18+
19+
## Installation
20+
21+
1. **Clone the repository**:
22+
```powershell
23+
git clone https://github.com/mattbaylor/opencode.git
24+
cd opencode
25+
```
26+
27+
2. **Install dependencies**:
28+
```powershell
29+
pnpm install
30+
```
31+
32+
3. **Run OpenCode**:
33+
```powershell
34+
# Run directly with tsx (TypeScript executor)
35+
pnpm --filter opencode exec tsx src/index.ts
36+
37+
# Or create an alias/function in your PowerShell profile
38+
```
39+
40+
## Creating a PowerShell Function (Optional)
41+
42+
Add this to your PowerShell profile (`$PROFILE`):
43+
44+
```powershell
45+
function opencode {
46+
$OpencodeDir = "C:\path\to\opencode" # Update this path
47+
Push-Location $OpencodeDir
48+
pnpm --filter opencode exec tsx packages/opencode/src/index.ts $args
49+
Pop-Location
50+
}
51+
```
52+
53+
Then you can just run `opencode` from anywhere.
54+
55+
## Alternative: Use WSL2
56+
57+
If you have WSL2 enabled on Windows Server 2022, you can run the Linux version of OpenCode which doesn't have these virtualization issues:
58+
59+
```bash
60+
# In WSL2
61+
git clone https://github.com/mattbaylor/opencode.git
62+
cd opencode
63+
# Use the original bun-based build or Node.js
64+
```
65+
66+
## Why This Works
67+
68+
- Node.js doesn't have the memory alignment issues that Bun has in VMs
69+
- You're running from source with TypeScript execution (tsx)
70+
- No need to create standalone binaries
71+
- Easier to update and debug

bun.lock

Lines changed: 85 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bunfig.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

cleanup-opencode-windows.ps1

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Remove all OpenCode Chocolatey installations and cleanup
2+
# Run as Administrator
3+
4+
Write-Host "Cleaning up OpenCode installations..." -ForegroundColor Cyan
5+
6+
# 1. Uninstall via Chocolatey if it exists
7+
Write-Host "`n[1/5] Checking for Chocolatey installation..." -ForegroundColor Yellow
8+
try {
9+
$chocoInstalled = Get-Command choco -ErrorAction SilentlyContinue
10+
if ($chocoInstalled) {
11+
Write-Host "Found Chocolatey. Attempting to uninstall opencode..." -ForegroundColor Cyan
12+
choco uninstall opencode -y 2>$null
13+
choco uninstall opencode-ai -y 2>$null
14+
Write-Host "Chocolatey uninstall complete" -ForegroundColor Green
15+
} else {
16+
Write-Host "Chocolatey not found, skipping..." -ForegroundColor Gray
17+
}
18+
} catch {
19+
Write-Host "Chocolatey uninstall skipped: $_" -ForegroundColor Gray
20+
}
21+
22+
# 2. Remove from Program Files
23+
Write-Host "`n[2/5] Removing from Program Files..." -ForegroundColor Yellow
24+
$programFilesPaths = @(
25+
"$env:ProgramFiles\opencode",
26+
"${env:ProgramFiles(x86)}\opencode",
27+
"$env:LOCALAPPDATA\opencode"
28+
)
29+
30+
foreach ($path in $programFilesPaths) {
31+
if (Test-Path $path) {
32+
Write-Host "Removing: $path" -ForegroundColor Cyan
33+
Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue
34+
Write-Host "Removed: $path" -ForegroundColor Green
35+
}
36+
}
37+
38+
# 3. Clean up PATH environment variable
39+
Write-Host "`n[3/5] Cleaning PATH environment variable..." -ForegroundColor Yellow
40+
$machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine")
41+
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
42+
43+
# Remove any opencode paths from Machine PATH
44+
if ($machinePath -like "*opencode*") {
45+
$newMachinePath = ($machinePath -split ';' | Where-Object { $_ -notlike '*opencode*' }) -join ';'
46+
[Environment]::SetEnvironmentVariable("Path", $newMachinePath, "Machine")
47+
Write-Host "Cleaned Machine PATH" -ForegroundColor Green
48+
} else {
49+
Write-Host "No opencode entries in Machine PATH" -ForegroundColor Gray
50+
}
51+
52+
# Remove any opencode paths from User PATH
53+
if ($userPath -like "*opencode*") {
54+
$newUserPath = ($userPath -split ';' | Where-Object { $_ -notlike '*opencode*' }) -join ';'
55+
[Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")
56+
Write-Host "Cleaned User PATH" -ForegroundColor Green
57+
} else {
58+
Write-Host "No opencode entries in User PATH" -ForegroundColor Gray
59+
}
60+
61+
# 4. Remove config/data directories
62+
Write-Host "`n[4/5] Removing config and data directories..." -ForegroundColor Yellow
63+
$configPaths = @(
64+
"$env:APPDATA\opencode",
65+
"$env:LOCALAPPDATA\opencode",
66+
"$env:USERPROFILE\.opencode"
67+
)
68+
69+
foreach ($path in $configPaths) {
70+
if (Test-Path $path) {
71+
Write-Host "Removing config: $path" -ForegroundColor Cyan
72+
Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue
73+
Write-Host "Removed: $path" -ForegroundColor Green
74+
}
75+
}
76+
77+
# 5. Check for any remaining opencode.exe processes
78+
Write-Host "`n[5/5] Checking for running processes..." -ForegroundColor Yellow
79+
$processes = Get-Process -Name "opencode" -ErrorAction SilentlyContinue
80+
if ($processes) {
81+
Write-Host "Found running opencode processes. Stopping..." -ForegroundColor Cyan
82+
$processes | Stop-Process -Force
83+
Write-Host "Stopped all opencode processes" -ForegroundColor Green
84+
} else {
85+
Write-Host "No running opencode processes found" -ForegroundColor Gray
86+
}
87+
88+
# Summary
89+
Write-Host "`n" + ("="*60) -ForegroundColor Cyan
90+
Write-Host "CLEANUP COMPLETE!" -ForegroundColor Green
91+
Write-Host ("="*60) -ForegroundColor Cyan
92+
Write-Host "`nAll OpenCode installations have been removed." -ForegroundColor White
93+
Write-Host "You may need to restart your terminal for PATH changes to take effect.`n" -ForegroundColor Yellow
94+
95+
# Optional: Search for any remaining files
96+
Write-Host "Searching for any remaining opencode files..." -ForegroundColor Cyan
97+
$remainingFiles = @()
98+
$searchPaths = @("C:\Program Files", "C:\Program Files (x86)", $env:LOCALAPPDATA, $env:APPDATA)
99+
100+
foreach ($searchPath in $searchPaths) {
101+
if (Test-Path $searchPath) {
102+
$found = Get-ChildItem -Path $searchPath -Filter "*opencode*" -Recurse -ErrorAction SilentlyContinue -Depth 2
103+
if ($found) {
104+
$remainingFiles += $found
105+
}
106+
}
107+
}
108+
109+
if ($remainingFiles.Count -gt 0) {
110+
Write-Host "`nFound remaining files:" -ForegroundColor Yellow
111+
$remainingFiles | ForEach-Object { Write-Host " - $($_.FullName)" -ForegroundColor Gray }
112+
Write-Host "`nYou may want to manually review and delete these." -ForegroundColor Yellow
113+
} else {
114+
Write-Host "`nNo remaining opencode files found." -ForegroundColor Green
115+
}

0 commit comments

Comments
 (0)