Skip to content

Commit f67e003

Browse files
committed
fix: copy tree-sitter WASM files to out dir in build
The listCodeDefinitionNamesTool was hanging because the tree-sitter language parsers could not load the required WASM files at runtime. The esbuild script was only copying these files to the 'dist' directory, but the extension runs from the 'out' directory. This commit updates the 'copyWasmFiles' plugin in esbuild.js to copy the WASM files to both 'dist' and 'out' directories, ensuring they are available at runtime.
1 parent 664d5b1 commit f67e003

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

esbuild.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,28 @@ const copyWasmFiles = {
3131
build.onEnd(() => {
3232
const nodeModulesDir = path.join(__dirname, "node_modules")
3333
const distDir = path.join(__dirname, "dist")
34+
const outDir = path.join(__dirname, "out") // Define outDir
35+
36+
// Ensure destination directories exist
37+
fs.mkdirSync(distDir, { recursive: true })
38+
try {
39+
fs.mkdirSync(outDir, { recursive: true })
40+
} catch (e) {}
3441

3542
// tiktoken
3643
fs.copyFileSync(
3744
path.join(nodeModulesDir, "tiktoken", "tiktoken_bg.wasm"),
3845
path.join(distDir, "tiktoken_bg.wasm"),
3946
)
47+
// Also copy tiktoken wasm to outDir
48+
try {
49+
fs.copyFileSync(
50+
path.join(nodeModulesDir, "tiktoken", "tiktoken_bg.wasm"),
51+
path.join(outDir, "tiktoken_bg.wasm"),
52+
)
53+
} catch (e) {
54+
console.warn("Could not copy tiktoken wasm to out directory:", e.message)
55+
}
4056

4157
// Copy language-specific WASM files
4258
const languageWasmDir = path.join(__dirname, "node_modules", "tree-sitter-wasms", "out")
@@ -48,8 +64,16 @@ const copyWasmFiles = {
4864
console.log(`Copying ${wasmFiles.length} tree-sitter WASM files to dist directory`)
4965

5066
wasmFiles.forEach((filename) => {
67+
// Copy to dist
5168
fs.copyFileSync(path.join(languageWasmDir, filename), path.join(distDir, filename))
69+
// Also copy to out
70+
try {
71+
fs.copyFileSync(path.join(languageWasmDir, filename), path.join(outDir, filename))
72+
} catch (e) {
73+
console.warn(`Could not copy ${filename} to out directory:`, e.message)
74+
}
5275
})
76+
console.log(`Copied tree-sitter WASM files to dist and out directories`)
5377
} else {
5478
console.warn(`Tree-sitter WASM directory not found: ${languageWasmDir}`)
5579
}

0 commit comments

Comments
 (0)