Skip to content

Commit c77e79f

Browse files
jahoomaclaude
andcommitted
Smoke handler: also fall back to sibling-of-execPath lookup
Round 10 still failed Windows because the smoke handler in main() doesn't go through init-node's locateFile callback at all — it calls Parser.init directly, so my init-node sibling fallback (rounds 9-10) never runs during the smoke step. Diagnostic confirmed: at main() time, process.execPath is the disk path on Windows AND the sibling tree-sitter.wasm exists right next to it. Pre-init couldn't reach the file (execPath was bunfs at that phase), so wasmBinary and wasmPath were both empty when smoke ran. Add the sibling lookup directly to the smoke handler, gated on those being empty. By main() time the disk path is reliable, so fs.existsSync(dirname(execPath) + 'tree-sitter.wasm') resolves correctly and we have something to feed Parser.init. Real users (no --smoke-tree-sitter flag) still go through the init-node sibling fallback in the SDK's eager Parser.init — that's unaffected by this change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 633cddd commit c77e79f

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

cli/src/index.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,34 @@ async function main(): Promise<void> {
222222

223223
try {
224224
const { Parser } = await import('web-tree-sitter')
225-
if (wasmBinary) {
226-
await Parser.init({ wasmBinary })
225+
// Pick the best wasm source available, falling back to the
226+
// sibling-of-execPath lookup if pre-init couldn't reach it. By
227+
// main() time process.execPath has stabilized to the disk path
228+
// even on Windows, where it was the bunfs path during pre-init.
229+
let effectiveBinary = wasmBinary
230+
let effectivePath = wasmPath
231+
if (!effectiveBinary && !effectivePath && fs.existsSync(siblingPath)) {
232+
effectivePath = siblingPath
233+
effectiveBinary = new Uint8Array(fs.readFileSync(siblingPath))
234+
}
235+
236+
if (effectiveBinary) {
237+
await Parser.init({ wasmBinary: effectiveBinary })
227238
// Marker grepped by cli/scripts/smoke-binary.ts — keep this exact text.
228239
console.log(
229-
`tree-sitter smoke ok (wasmBinary, ${wasmBinary.byteLength} bytes)`,
240+
`tree-sitter smoke ok (wasmBinary, ${effectiveBinary.byteLength} bytes)`,
230241
)
231-
} else if (wasmPath) {
242+
} else if (effectivePath) {
232243
await Parser.init({
233244
locateFile: (name: string) =>
234-
name === 'tree-sitter.wasm' ? wasmPath : name,
245+
name === 'tree-sitter.wasm' ? effectivePath! : name,
235246
})
236-
console.log(`tree-sitter smoke ok (locateFile, path=${wasmPath})`)
247+
console.log(`tree-sitter smoke ok (locateFile, path=${effectivePath})`)
237248
} else {
238249
console.error(
239-
'tree-sitter smoke FAIL: pre-init published neither globalThis bytes ' +
240-
'nor an env path. Sibling tree-sitter.wasm not found relative to ' +
241-
'process.execPath. See diag above for the actual paths.',
250+
'tree-sitter smoke FAIL: no wasm available — pre-init published ' +
251+
'nothing and the sibling-of-execPath fallback also missed. See ' +
252+
'the diag above for paths.',
242253
)
243254
process.exit(1)
244255
}

0 commit comments

Comments
 (0)