From 5ae891a8a01587ea4080d01185707c932b5bc724 Mon Sep 17 00:00:00 2001 From: Justin Watts Date: Fri, 16 Jan 2026 20:44:47 -0800 Subject: [PATCH] fix: patch __dirname for ESM environments Adds a post-processing sed to handle __dirname in ESM environments where it's not defined (Cloudflare Workers, Node ESM, Deno, Bun). Follows the same approach as the existing document.currentScript fix. Fixes #216 --- scripts/update-emscripten.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/update-emscripten.sh b/scripts/update-emscripten.sh index 3d3b00b..461f176 100755 --- a/scripts/update-emscripten.sh +++ b/scripts/update-emscripten.sh @@ -59,8 +59,11 @@ emcc -O3 -I ../include *.c -DH3_HAVE_VLA --memory-init-file 0 \ for file in *.js ; do # Patch libh3 bundle to contain a fix to allow h3-js to be imported in a web worker and react-native # See #117 and #163 for more details. + # Also patch __dirname for ESM environments (Cloudflare Workers, Node ESM, Deno, Bun) + # See #216 for more details. cat ../../../../build/pre.js "$file" \ | sed 's/if(document.currentScript)/if(typeof document!=="undefined" \&\& document.currentScript)/g' \ + | sed 's/scriptDirectory=__dirname+"\/"/scriptDirectory=typeof __dirname!=="undefined"?__dirname+"\/":""/g' \ > ../../../../out/"$file" done