@@ -34,23 +34,33 @@ export async function initTreeSitterForNode(): Promise<void> {
3434 const dir = hereDir ( )
3535
3636 // Try shared WASM directory first (new approach to avoid duplication)
37- const sharedWasm = path . join ( dir , '..' , 'wasm' , 'tree-sitter.wasm' )
37+ const sharedWasms = [
38+ path . join ( dir , '..' , 'wasm' , 'tree-sitter.wasm' ) ,
39+ path . join ( dir , 'wasm' , 'tree-sitter.wasm' ) ,
40+ ]
3841
3942 // Use locateFile to override where the runtime looks for tree-sitter.wasm
4043 await Parser . init ( {
4144 locateFile : ( name : string , scriptDir : string ) => {
4245 if ( name === 'tree-sitter.wasm' ) {
43- // First try shared WASM directory (new approach)
44- if ( fs . existsSync ( sharedWasm ) ) {
45- return sharedWasm
46+ for ( const sharedWasm of sharedWasms ) {
47+ // First try shared WASM directory (new approach)
48+ if ( fs . existsSync ( sharedWasm ) ) {
49+ return sharedWasm
50+ }
4651 }
4752 // Fallback to script directory
4853 const fallback = path . join ( scriptDir , name )
4954 if ( fs . existsSync ( fallback ) ) {
5055 return fallback
5156 }
57+ for ( const sharedWasm of sharedWasms ) {
58+ if ( fs . existsSync ( path . dirname ( sharedWasm ) ) ) {
59+ return sharedWasm
60+ }
61+ }
5262 // Return our preferred path and let web-tree-sitter handle the error
53- return sharedWasm
63+ return sharedWasms [ 0 ]
5464 }
5565 // For other files, use default behavior
5666 return path . join ( scriptDir , name )
0 commit comments