Skip to content

Commit 82a511c

Browse files
jahoomaclaude
andcommitted
Drop isBunEmbeddedPath shortcut — emscripten can't read those paths anyway
Round 9 logs showed our locateFile fallback was returning the bunfs path (`B:\~BUN\root\tree-sitter.wasm`), and emscripten then ENOENT'd on it. The sibling-of-execPath fallback I added in the previous commit never ran because the scriptDir branch above it took the `isBunEmbeddedPath` shortcut and returned early. The shortcut was based on a wrong assumption: that emscripten could read bunfs paths. It can't — emscripten's `readAsync` calls `fs.readFile` under the hood, and `fs.readFile('B:\~BUN\root\...')` fails the same way `fs.existsSync` does on those paths. Remove the shortcut. Now resolveTreeSitterWasm only returns paths that `fs.existsSync` confirms — which on Windows means we skip the bunfs scriptDir fallback and fall through to the `dirname(process.execPath)` sibling, where the build script copied tree-sitter.wasm next to the binary. Verified locally: build copies wasm to bin/, --smoke-tree-sitter exits 0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9ba251b commit 82a511c

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

packages/code-map/src/init-node.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ function getEmbeddedWasmBinary(): Uint8Array | undefined {
3030
)[WASM_BINARY_GLOBAL_KEY]
3131
}
3232

33-
function isBunEmbeddedPath(filePath: string): boolean {
34-
return filePath.replace(/\\/g, '/').includes('/~BUN/root/')
35-
}
36-
3733
function resolveTreeSitterWasm(scriptDir: string): string {
34+
// Only return paths that fs.existsSync confirms — emscripten will
35+
// fs.readFile whatever we hand it, and bunfs internal paths (the
36+
// `B:\~BUN\root\...` form on Windows) ENOENT under that read even
37+
// though they look right. An earlier `isBunEmbeddedPath` shortcut
38+
// assumed those paths were readable; they aren't.
39+
3840
const override = process.env[TREE_SITTER_WASM_ENV_VAR]
39-
if (override) {
40-
if (fs.existsSync(override) || isBunEmbeddedPath(override)) {
41-
return override
42-
}
41+
if (override && fs.existsSync(override)) {
42+
return override
4343
}
4444

45-
const fallback = path.join(scriptDir, 'tree-sitter.wasm')
46-
if (fs.existsSync(fallback) || isBunEmbeddedPath(fallback)) {
47-
return fallback
45+
const scriptDirFallback = path.join(scriptDir, 'tree-sitter.wasm')
46+
if (fs.existsSync(scriptDirFallback)) {
47+
return scriptDirFallback
4848
}
4949

5050
// Sibling file next to the running binary. The CLI ships
@@ -56,7 +56,10 @@ function resolveTreeSitterWasm(scriptDir: string): string {
5656
// path later. emscripten calls this locateFile callback during
5757
// Parser.init's async work, by which time execPath has stabilized.
5858
try {
59-
const sibling = path.join(path.dirname(process.execPath), 'tree-sitter.wasm')
59+
const sibling = path.join(
60+
path.dirname(process.execPath),
61+
'tree-sitter.wasm',
62+
)
6063
if (fs.existsSync(sibling)) {
6164
return sibling
6265
}

0 commit comments

Comments
 (0)