Skip to content

Commit ca60f0e

Browse files
committed
fix(cli): patch OpenTUI asset paths for bundled builds
1 parent cf5f179 commit ca60f0e

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

cli/scripts/build-binary.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env bun
22

33
import { spawnSync, type SpawnSyncOptions } from 'child_process'
4-
import { chmodSync, existsSync, mkdirSync } from 'fs'
4+
import {
5+
chmodSync,
6+
existsSync,
7+
mkdirSync,
8+
readdirSync,
9+
readFileSync,
10+
writeFileSync,
11+
} from 'fs'
512
import { dirname, join } from 'path'
613
import { fileURLToPath } from 'url'
714

@@ -120,6 +127,8 @@ async function main() {
120127
log('Building SDK dependencies...')
121128
runCommand('bun', ['run', 'build:sdk'], { cwd: cliRoot })
122129

130+
patchOpenTuiAssetPaths()
131+
123132
const outputFilename =
124133
targetInfo.platform === 'win32' ? `${binaryName}.exe` : binaryName
125134
const outputFile = join(binDir, outputFilename)
@@ -167,3 +176,37 @@ main().catch((error: unknown) => {
167176
}
168177
process.exit(1)
169178
})
179+
180+
function patchOpenTuiAssetPaths() {
181+
const coreDir = join(cliRoot, 'node_modules', '@opentui', 'core')
182+
if (!existsSync(coreDir)) {
183+
log('OpenTUI core package not found; skipping asset patch')
184+
return
185+
}
186+
187+
const indexFile = readdirSync(coreDir).find(
188+
(file) => file.startsWith('index') && file.endsWith('.js'),
189+
)
190+
191+
if (!indexFile) {
192+
log('OpenTUI core index bundle not found; skipping asset patch')
193+
return
194+
}
195+
196+
const indexPath = join(coreDir, indexFile)
197+
const content = readFileSync(indexPath, 'utf8')
198+
199+
const absolutePathPattern =
200+
/var __dirname = ".*?packages\/core\/src\/lib\/tree-sitter\/assets";/
201+
if (!absolutePathPattern.test(content)) {
202+
log('OpenTUI core bundle already has relative asset paths')
203+
return
204+
}
205+
206+
const replacement =
207+
'var __dirname = path3.join(path3.dirname(fileURLToPath(new URL(".", import.meta.url))), "lib/tree-sitter/assets");'
208+
209+
const patched = content.replace(absolutePathPattern, replacement)
210+
writeFileSync(indexPath, patched)
211+
logAlways('Patched OpenTUI core tree-sitter asset paths')
212+
}

0 commit comments

Comments
 (0)