@@ -158,6 +158,58 @@ export function copyWasms(srcDir: string, distDir: string): void {
158158 } )
159159
160160 console . log ( `[copyWasms] Copied ${ wasmFiles . length } tree-sitter language wasms to ${ distDir } ` )
161+
162+ // Copy esbuild-wasm files for custom tool transpilation (cross-platform).
163+ copyEsbuildWasmFiles ( nodeModulesDir , distDir )
164+ }
165+
166+ /**
167+ * Copy esbuild-wasm files to the dist/bin directory.
168+ *
169+ * This function copies the esbuild-wasm CLI and WASM binary, which provides
170+ * a cross-platform esbuild implementation that works on all platforms.
171+ *
172+ * Files copied:
173+ * - bin/esbuild (Node.js CLI script)
174+ * - esbuild.wasm (WASM binary)
175+ * - wasm_exec_node.js (Go WASM runtime for Node.js)
176+ * - wasm_exec.js (Go WASM runtime dependency)
177+ */
178+ function copyEsbuildWasmFiles ( nodeModulesDir : string , distDir : string ) : void {
179+ const esbuildWasmDir = path . join ( nodeModulesDir , "esbuild-wasm" )
180+
181+ if ( ! fs . existsSync ( esbuildWasmDir ) ) {
182+ throw new Error ( `Directory does not exist: ${ esbuildWasmDir } ` )
183+ }
184+
185+ // Create bin directory in dist.
186+ const binDir = path . join ( distDir , "bin" )
187+ fs . mkdirSync ( binDir , { recursive : true } )
188+
189+ // Files to copy - the esbuild CLI script expects wasm_exec_node.js and esbuild.wasm
190+ // to be one directory level up from the bin directory (i.e., in distDir directly).
191+ // wasm_exec_node.js requires wasm_exec.js, so we need to copy that too.
192+ const filesToCopy = [
193+ { src : path . join ( esbuildWasmDir , "bin" , "esbuild" ) , dest : path . join ( binDir , "esbuild" ) } ,
194+ { src : path . join ( esbuildWasmDir , "esbuild.wasm" ) , dest : path . join ( distDir , "esbuild.wasm" ) } ,
195+ { src : path . join ( esbuildWasmDir , "wasm_exec_node.js" ) , dest : path . join ( distDir , "wasm_exec_node.js" ) } ,
196+ { src : path . join ( esbuildWasmDir , "wasm_exec.js" ) , dest : path . join ( distDir , "wasm_exec.js" ) } ,
197+ ]
198+
199+ for ( const { src, dest } of filesToCopy ) {
200+ fs . copyFileSync ( src , dest )
201+
202+ // Make CLI executable.
203+ if ( src . endsWith ( "esbuild" ) ) {
204+ try {
205+ fs . chmodSync ( dest , 0o755 )
206+ } catch {
207+ // Ignore chmod errors on Windows.
208+ }
209+ }
210+ }
211+
212+ console . log ( `[copyWasms] Copied ${ filesToCopy . length } esbuild-wasm files to ${ distDir } ` )
161213}
162214
163215export function copyLocales ( srcDir : string , distDir : string ) : void {
0 commit comments