From a0ed2ae2f32e1ed9a17f322c6037cfee094c9b37 Mon Sep 17 00:00:00 2001 From: Ruben Hensen Date: Fri, 12 Jun 2026 14:18:04 +0200 Subject: [PATCH] ci: strip dead default-module-path branch from pg-wasm web build wasm-bindgen's `--target web` output emits an unreachable `module_or_path = new URL('index_bg.wasm', import.meta.url)` branch in __wbg_init. Webpack 5 statically resolves it as an asset import at build time even though it never fires for callers that pass module_or_path explicitly (e.g. @e4a/pg-js), producing 'Can't resolve index_bg.wasm' errors in downstream consumers. wasm-pack does not expose wasm-bindgen's --omit-default-module-path flag, so strip the branch from the generated index.js after the build. The strip fails loudly if the pattern is gone so a future wasm-bindgen change can't silently no-op it. The bundler target has no init function and is unaffected. Fixes #153 --- .github/workflows/delivery.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/delivery.yml b/.github/workflows/delivery.yml index 114e269..229da30 100644 --- a/.github/workflows/delivery.yml +++ b/.github/workflows/delivery.yml @@ -324,6 +324,31 @@ jobs: - name: Build pg-wasm (web) run: wasm-pack build --release -d pkg/web --out-name index --scope e4a --target web ./pg-wasm + # wasm-bindgen's `--target web` output emits a default-module-path branch + # (`module_or_path = new URL('index_bg.wasm', import.meta.url)`) that + # webpack 5 statically resolves as an asset import at build time even when + # the branch is unreachable, breaking consumers that always pass + # `module_or_path` explicitly (e.g. @e4a/pg-js). wasm-pack does not expose + # wasm-bindgen's `--omit-default-module-path` flag, so we strip the branch + # from the generated index.js after the build. Fails loudly if the pattern + # is gone so a future wasm-bindgen change can't silently no-op the strip. + # The bundler target is unaffected (no init function). See #153. + - name: Strip default-module-path branch from web target (#153) + run: | + node -e " + const fs = require('fs'); + const p = 'pg-wasm/pkg/web/index.js'; + const re = /\n\s*if \([^)]*module_or_path[^)]*\) \{\s*module_or_path = new URL\('index_bg\.wasm', import\.meta\.url\);\s*\}\n/; + const src = fs.readFileSync(p, 'utf8'); + const out = src.replace(re, '\n'); + if (out === src) { + console.error('Strip pattern not found in ' + p + '; wasm-bindgen output may have changed. See #153.'); + process.exit(1); + } + fs.writeFileSync(p, out); + console.log('Stripped default-module-path branch from ' + p); + " + - name: Assemble package working-directory: pg-wasm/pkg run: |