|
1 | 1 | #!/usr/bin/env bun |
2 | 2 |
|
3 | 3 | 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' |
5 | 12 | import { dirname, join } from 'path' |
6 | 13 | import { fileURLToPath } from 'url' |
7 | 14 |
|
@@ -120,6 +127,8 @@ async function main() { |
120 | 127 | log('Building SDK dependencies...') |
121 | 128 | runCommand('bun', ['run', 'build:sdk'], { cwd: cliRoot }) |
122 | 129 |
|
| 130 | + patchOpenTuiAssetPaths() |
| 131 | + |
123 | 132 | const outputFilename = |
124 | 133 | targetInfo.platform === 'win32' ? `${binaryName}.exe` : binaryName |
125 | 134 | const outputFile = join(binDir, outputFilename) |
@@ -167,3 +176,37 @@ main().catch((error: unknown) => { |
167 | 176 | } |
168 | 177 | process.exit(1) |
169 | 178 | }) |
| 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