Skip to content

Commit 30e9142

Browse files
committed
Update build binary to search multiple packages' node_modules for tui core package
1 parent bb2fadd commit 30e9142

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

cli/scripts/build-binary.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,38 @@ main().catch((error: unknown) => {
203203
process.exit(1)
204204
})
205205

206-
function patchOpenTuiAssetPaths() {
207-
const coreDir = join(cliRoot, 'node_modules', '@opentui', 'core')
208-
if (!existsSync(coreDir)) {
209-
log('OpenTUI core package not found; skipping asset patch')
210-
return
211-
}
206+
function findOpenTuiCoreDir(): string | null {
207+
const candidates = [
208+
join(cliRoot, 'node_modules', '@opentui', 'core'),
209+
join(repoRoot, 'node_modules', '@opentui', 'core'),
210+
]
211+
return candidates.find((dir) => existsSync(dir)) ?? null
212+
}
213+
214+
function findOpenTuiCoreBundlePath(): string | null {
215+
const coreDir = findOpenTuiCoreDir()
216+
if (!coreDir) return null
217+
218+
// Prefer the hashed bundle file (e.g. index-0wbvecnk.js) over index.js
219+
const bundleFile = readdirSync(coreDir).find(
220+
(file) => file.startsWith('index-') && file.endsWith('.js'),
221+
)
222+
if (bundleFile) return join(coreDir, bundleFile)
212223

213224
const indexFile = readdirSync(coreDir).find(
214225
(file) => file.startsWith('index') && file.endsWith('.js'),
215226
)
227+
return indexFile ? join(coreDir, indexFile) : null
228+
}
216229

217-
if (!indexFile) {
218-
log('OpenTUI core index bundle not found; skipping asset patch')
230+
function patchOpenTuiAssetPaths() {
231+
const bundlePath = findOpenTuiCoreBundlePath()
232+
if (!bundlePath) {
233+
log('OpenTUI core bundle not found; skipping asset patch')
219234
return
220235
}
221236

222-
const indexPath = join(coreDir, indexFile)
223-
const content = readFileSync(indexPath, 'utf8')
237+
const content = readFileSync(bundlePath, 'utf8')
224238

225239
const absolutePathPattern =
226240
/var __dirname = ".*?packages\/core\/src\/lib\/tree-sitter\/assets";/
@@ -233,7 +247,7 @@ function patchOpenTuiAssetPaths() {
233247
'var __dirname = path3.join(path3.dirname(fileURLToPath(new URL(".", import.meta.url))), "lib/tree-sitter/assets");'
234248

235249
const patched = content.replace(absolutePathPattern, replacement)
236-
writeFileSync(indexPath, patched)
250+
writeFileSync(bundlePath, patched)
237251
logAlways('Patched OpenTUI core tree-sitter asset paths')
238252
}
239253

0 commit comments

Comments
 (0)